lib9p

Go 9P library.
Log | Files | Refs | LICENSE

stat.go (1412B)


      1 package iofs
      2 
      3 import (
      4 	"io/fs"
      5 
      6 	"git.mtkn.jp/lib9p"
      7 )
      8 
      9 func fiType(fi fs.FileInfo) uint16  { return 0 }
     10 func fiDev(fi fs.FileInfo) uint32   { return 0 }
     11 func fiLength(fi fs.FileInfo) int64 { return fi.Size() }
     12 
     13 // TODO: fix this work around.
     14 // should preserve permission bits
     15 func fiMode(fi fs.FileInfo) lib9p.FileMode { return (fi.Mode() &^ fs.ModePerm) | 0555 }
     16 func fiName(fi fs.FileInfo) string         { return fi.Name() }
     17 func fiAtime(fi fs.FileInfo) uint32        { return uint32(fi.ModTime().Unix()) }
     18 func fiMtime(fi fs.FileInfo) uint32        { return uint32(fi.ModTime().Unix()) }
     19 func fiUid(fi fs.FileInfo) string          { return "" }
     20 func fiGid(fi fs.FileInfo) string          { return "" }
     21 func fiMuid(fi fs.FileInfo) string         { return "" }
     22 
     23 func fiQid(pool *QidPool, id fileID, fi fs.FileInfo) (lib9p.Qid, error) {
     24 	qrec, ok := pool.m[id]
     25 	if ok {
     26 		return *qrec.qid, nil
     27 	}
     28 	qtype := lib9p.FSModeToQidType(fi.Mode())
     29 	qid := &lib9p.Qid{
     30 		Path: pool.nextQid,
     31 		Type: qtype,
     32 	}
     33 	pool.m[id] = &qidRec{qid: qid, mtime: fi.ModTime()}
     34 	pool.nextQid++
     35 	return *qid, nil
     36 }
     37 
     38 func fiStat(pool *QidPool, id fileID, fi fs.FileInfo) *lib9p.Stat {
     39 	qid, _ := fiQid(pool, id, fi)
     40 	return &lib9p.Stat{
     41 		Qid:    qid,
     42 		Name:   fiName(fi),
     43 		Mode:   fiMode(fi),
     44 		Atime:  fiAtime(fi),
     45 		Mtime:  fiMtime(fi),
     46 		Length: fiLength(fi),
     47 		Uid:    fiUid(fi),
     48 		Gid:    fiGid(fi),
     49 		Muid:   fiMuid(fi),
     50 	}
     51 }