lib9p

Go 9P library.
Log | Files | Refs

commit 008f7f880efbe98d521867c406d968ae04beaa4b
parent 894eac128d474a35c4624557555c33a15ef58c59
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat,  2 Sep 2023 08:47:15 +0900

gofmt

Diffstat:
Mcmd/numfs.go | 12+++++-------
Mdiskfs/file.go | 2+-
Mdiskfs/qid_unix.go | 5++---
Mdiskfs/stat.go | 23+++++++++++------------
Mfcall.go | 22++++++++++------------
Mfid.go | 7+++----
Mfile.go | 6+++---
Miofs/file.go | 6+++---
Miofs/qid.go | 2+-
Miofs/stat.go | 2+-
Mparse.go | 1-
Mpool.go | 1-
Mreq.go | 3+--
Mserver.go | 8++++----
Mstat.go | 20++++++++++----------
15 files changed, 55 insertions(+), 65 deletions(-)

diff --git a/cmd/numfs.go b/cmd/numfs.go @@ -18,7 +18,7 @@ var root *numFile func init() { root = &numFile{ - id: -1, + id: -1, text: "", children: []*numFile{ &numFile{0, "0", nil}, @@ -55,13 +55,13 @@ func (fsys *numFS) Open(name string) (lib9p.File, error) { } type numFile struct { - id int - text string + id int + text string children []*numFile } func (f *numFile) Stat() (fs.FileInfo, error) { - return &FileInfo{Stat:lib9p.StatFromFile(f)}, nil + return &FileInfo{Stat: lib9p.StatFromFile(f)}, nil } func (f *numFile) Read(p []byte) (int, error) { if f.id == -1 { @@ -122,8 +122,6 @@ func (f *numFile) ReadAt(p []byte, off int64) (n int, err error) { return bytes.NewReader([]byte(f.text)).ReadAt(p, off) } - - func (f *numFile) ReadDir(n int) ([]*lib9p.DirEntry, error) { if f.id != -1 { return nil, fmt.Errorf("not a directory") @@ -152,7 +150,7 @@ func (fi *FileInfo) Mode() fs.FileMode { return lib9p.Mode9ToFSMode(fi.Stat.Mod func (fi *FileInfo) ModTime() time.Time { return time.Unix(int64(fi.Stat.Mtime), 0) } func (fi *FileInfo) IsDir() bool { return fi.Stat.Mode&lib9p.DMDIR != 0 } func (fi *FileInfo) Sys() any { return fi.Stat } -func (fi *FileInfo) Qid() lib9p.Qid { return fi.Stat.Qid } +func (fi *FileInfo) Qid() lib9p.Qid { return fi.Stat.Qid } var dFlag = flag.Bool("D", false, "Prints chatty message to the stderr.") diff --git a/diskfs/file.go b/diskfs/file.go @@ -32,7 +32,7 @@ func openFile(fsys *FS, fpath string) (*File, error) { } func (f *File) PathName() string { return f.path } -func (f *File) Type() uint16 { return 0 } +func (f *File) Type() uint16 { return 0 } func (f *File) Dev() uint32 { return 0 } func (f *File) Qid() lib9p.Qid { diff --git a/diskfs/qid_unix.go b/diskfs/qid_unix.go @@ -14,7 +14,7 @@ type fileID struct { } type QidPool struct { - m map[fileID]lib9p.Qid + m map[fileID]lib9p.Qid nextQid uint64 } @@ -84,4 +84,4 @@ func (pool *QidPool) delete(f *File) { return } delete(pool.m, id) -} -\ No newline at end of file +} diff --git a/diskfs/stat.go b/diskfs/stat.go @@ -44,16 +44,16 @@ func fiStat(pool *QidPool, id fileID, info fs.FileInfo) *lib9p.Stat { } return &lib9p.Stat{ - Type: 0, - Dev: 0, - Qid: qid, - Mode: lib9p.FSModeTo9Mode(info.Mode()), - Atime: uint32(stat.Atim.Sec), - Mtime: uint32(stat.Mtim.Sec), + Type: 0, + Dev: 0, + Qid: qid, + Mode: lib9p.FSModeTo9Mode(info.Mode()), + Atime: uint32(stat.Atim.Sec), + Mtime: uint32(stat.Mtim.Sec), Length: stat.Size, - Name: info.Name(), - Uid: usr.Username, - Gid: group.Name, - Muid: "", + Name: info.Name(), + Uid: usr.Username, + Gid: group.Name, + Muid: "", } -} -\ No newline at end of file +} diff --git a/fcall.go b/fcall.go @@ -350,7 +350,7 @@ func newRAttach(buf []byte) *RAttach { panic("not implemented") } func (msg RAttach) Size() uint32 { return 4 + 1 + 2 + 13 } func (msg RAttach) Type() MsgType { return Rattach } func (msg RAttach) Tag() uint16 { return msg.tag } -func (msg RAttach) Qid() Qid { return msg.qid } +func (msg RAttach) Qid() Qid { return msg.qid } func (msg RAttach) marshal() []byte { cur := 0 buf := make([]byte, msg.Size()) @@ -437,7 +437,7 @@ func newTWalk(buf []byte) *TWalk { for i := 0; i < int(nwname); i++ { size := int(gbit16(buf[cur : cur+2])) cur += 2 - msg.wname[i] = string(buf[cur:cur+size]) + msg.wname[i] = string(buf[cur : cur+size]) cur += size } if cur != int(msg.size) { @@ -596,7 +596,7 @@ func (msg *ROpen) Size() uint32 { } func (msg *ROpen) Type() MsgType { return Ropen } func (msg *ROpen) Tag() uint16 { return msg.tag } -func (msg *ROpen) Qid() Qid { return msg.qid } +func (msg *ROpen) Qid() Qid { return msg.qid } func (msg *ROpen) IoUnit() uint32 { return msg.iounit } func (msg *ROpen) marshal() []byte { cur := 0 @@ -726,11 +726,11 @@ func (msg *RRead) String() string { msg.Tag(), msg.Count()) data := msg.Data() i := 0 - for ; i + 4 < len(data) && i < 64; i += 4 { + for ; i+4 < len(data) && i < 64; i += 4 { s += fmt.Sprintf(" %02x%02x%02x%02x", uint8(data[i]), uint8(data[i+1]), uint8(data[i+2]), uint8(data[i+3])) } - if i != len(data) && i != 64 { + if i != len(data) && i != 64 { s += " " } for ; i < len(data) && i < 64; i++ { @@ -742,8 +742,8 @@ func (msg *RRead) String() string { type TClunk struct { size uint32 - tag uint16 - fid uint32 + tag uint16 + fid uint32 } func newTClunk(buf []byte) *TClunk { @@ -776,9 +776,9 @@ type RClunk struct { } func newRClunk(buf []byte) *RClunk { panic("not implemented") } -func (msg *RClunk) Size() uint32 { return 7 } -func (msg *RClunk) Type() MsgType { return Rclunk } -func (msg *RClunk) Tag() uint16 { return msg.tag } +func (msg *RClunk) Size() uint32 { return 7 } +func (msg *RClunk) Type() MsgType { return Rclunk } +func (msg *RClunk) Tag() uint16 { return msg.tag } func (msg *RClunk) marshal() []byte { m := make([]byte, msg.Size()) pbit32(m[0:4], msg.Size()) @@ -790,8 +790,6 @@ func (msg *RClunk) String() string { return fmt.Sprintf("Rclunk tag %d", msg.Tag()) } - - type TStat struct { size uint32 tag uint16 diff --git a/fid.go b/fid.go @@ -12,8 +12,8 @@ const ( // TODO: is the mode should be implemented using interfaces? ORDWR = 2 OEXEC = 3 - OTRUNC = 16 - ORCLOSE = 64 + OTRUNC = 16 + ORCLOSE = 64 ) type Fid struct { @@ -39,4 +39,4 @@ func (f *Fid) String() string { fid = -1 } return fmt.Sprintf("%d", fid) -} -\ No newline at end of file +} diff --git a/file.go b/file.go @@ -30,7 +30,7 @@ type DirEntry struct { FileInfo fs.FileInfo } -func (e *DirEntry) Name() string { return e.FileInfo.Name() } -func (e *DirEntry) IsDir() bool { return e.FileInfo.IsDir() } -func (e *DirEntry) Type() fs.FileMode { return e.FileInfo.Mode().Type() } +func (e *DirEntry) Name() string { return e.FileInfo.Name() } +func (e *DirEntry) IsDir() bool { return e.FileInfo.IsDir() } +func (e *DirEntry) Type() fs.FileMode { return e.FileInfo.Mode().Type() } func (e *DirEntry) Info() (fs.FileInfo, error) { return e.FileInfo, nil } diff --git a/iofs/file.go b/iofs/file.go @@ -11,9 +11,9 @@ import ( ) type File struct { - fs *FS // file system to which this file belongs - file fs.File // underlying file - path string // absolute path from the root of the fs. + fs *FS // file system to which this file belongs + file fs.File // underlying file + path string // absolute path from the root of the fs. } func openFile(fsys *FS, fpath string) (*File, error) { diff --git a/iofs/qid.go b/iofs/qid.go @@ -9,7 +9,7 @@ import ( type fileID string type QidPool struct { - m map[fileID]lib9p.Qid + m map[fileID]lib9p.Qid nextQid uint64 } diff --git a/iofs/stat.go b/iofs/stat.go @@ -17,7 +17,7 @@ func (fi *FileInfo) Mode() fs.FileMode { return lib9p.Mode9ToFSMode(fi.Stat.Mod func (fi *FileInfo) ModTime() time.Time { return time.Unix(int64(fi.Stat.Mtime), 0) } func (fi *FileInfo) IsDir() bool { return fi.Stat.Mode&lib9p.DMDIR != 0 } func (fi *FileInfo) Sys() any { return fi.Stat } -func (fi *FileInfo) Qid() lib9p.Qid { return fi.Sys().(*lib9p.Stat).Qid } +func (fi *FileInfo) Qid() lib9p.Qid { return fi.Sys().(*lib9p.Stat).Qid } func fiType(fi fs.FileInfo) uint16 { return 0 } func fiDev(fi fs.FileInfo) uint32 { return 0 } diff --git a/parse.go b/parse.go @@ -92,4 +92,3 @@ func pbit32(b []byte, n uint32) { binary.LittleEndian.PutUint32(b, n) } // Pbit64 puts into b an 8-byte long little endian unsigned integer n. func pbit64(b []byte, n uint64) { binary.LittleEndian.PutUint64(b, n) } - diff --git a/pool.go b/pool.go @@ -2,7 +2,6 @@ package lib9p import ( "fmt" - ) type FidPool struct { diff --git a/req.go b/req.go @@ -40,4 +40,4 @@ func (rp *ReqPool) deleteReq(tag uint16) error { } delete(rp.m, tag) return nil -} -\ No newline at end of file +} diff --git a/server.go b/server.go @@ -29,10 +29,10 @@ type Server struct { func NewServer(fsys FS, mSize uint32, r io.Reader, w io.Writer) *Server { return &Server{ - fs: fsys, - MSize: mSize, - fPool: allocFidPool(), - rPool: allocReqPool(), + fs: fsys, + MSize: mSize, + fPool: allocFidPool(), + rPool: allocReqPool(), Reader: r, Writer: w, } diff --git a/stat.go b/stat.go @@ -36,17 +36,17 @@ type Stat struct { func StatFromFile(f File) *Stat { return &Stat{ - Type: f.Type(), - Dev: f.Dev(), - Qid: f.Qid(), - Mode: f.Mode(), - Atime: f.Atime(), - Mtime: f.Mtime(), + Type: f.Type(), + Dev: f.Dev(), + Qid: f.Qid(), + Mode: f.Mode(), + Atime: f.Atime(), + Mtime: f.Mtime(), Length: f.Length(), - Name: f.Name(), - Uid: f.Uid(), - Gid: f.Gid(), - Muid: f.Muid(), + Name: f.Name(), + Uid: f.Uid(), + Gid: f.Gid(), + Muid: f.Muid(), } }