stub all fuse/fs methods
This commit is contained in:
99
fs.go
99
fs.go
@@ -2,17 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"bazil.org/fuse"
|
||||
"bazil.org/fuse/fs"
|
||||
)
|
||||
|
||||
var _ fs.FS = (*FS)(nil)
|
||||
var _ fs.FSDestroyer = (*FS)(nil)
|
||||
var _ fs.FSStatfser = (*FS)(nil)
|
||||
|
||||
// var _ fs.FSInodeGenerator = (*FS)(nil)
|
||||
|
||||
type FS struct {
|
||||
SourcePath string
|
||||
@@ -20,68 +19,40 @@ type FS struct {
|
||||
|
||||
// Root returns the file system root.
|
||||
func (f *FS) Root() (fs.Node, error) {
|
||||
return &File{fs: f}, nil
|
||||
return &Node{fs: f}, nil
|
||||
}
|
||||
|
||||
var _ fs.Node = (*File)(nil)
|
||||
|
||||
type File struct {
|
||||
fs *FS // base filesystem
|
||||
path string // path within file system
|
||||
// Destroy is called when the file system is shutting down.
|
||||
//
|
||||
// Linux only sends this request for block device backed (fuseblk)
|
||||
// filesystems, to allow them to flush writes to disk before the
|
||||
// unmount completes.
|
||||
func (f *FS) Destroy() {
|
||||
// TODO: Flush writes?
|
||||
}
|
||||
|
||||
func (f *File) srcpath() string {
|
||||
return filepath.Join(f.fs.SourcePath, f.path)
|
||||
// Statfs is called to obtain file system metadata.
|
||||
// It should write that data to resp.
|
||||
func (f *FS) Statfs(ctx context.Context, req *fuse.StatfsRequest, resp *fuse.StatfsResponse) error {
|
||||
panic("TODO")
|
||||
}
|
||||
|
||||
func (f *File) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||
fi, err := os.Stat(f.srcpath())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
statt := fi.Sys().(*syscall.Stat_t)
|
||||
|
||||
// TODO: Cache attr w/ a.Valid?
|
||||
|
||||
if f.path == "" {
|
||||
a.Inode = 1
|
||||
} else {
|
||||
a.Inode = statt.Ino
|
||||
}
|
||||
a.Size = uint64(fi.Size())
|
||||
a.Blocks = uint64(statt.Blocks)
|
||||
a.Atime = time.Unix(statt.Atim.Sec, statt.Atim.Nsec).UTC()
|
||||
a.Mtime = time.Unix(statt.Mtim.Sec, statt.Mtim.Nsec).UTC()
|
||||
a.Ctime = time.Unix(statt.Ctim.Sec, statt.Ctim.Nsec).UTC()
|
||||
a.Mode = fi.Mode()
|
||||
a.Nlink = uint32(statt.Nlink)
|
||||
a.Uid = uint32(statt.Uid)
|
||||
a.Gid = uint32(statt.Gid)
|
||||
a.Rdev = uint32(statt.Rdev)
|
||||
a.BlockSize = uint32(statt.Blksize)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
||||
path := filepath.Join(f.path, name)
|
||||
srcpath := filepath.Join(f.fs.SourcePath, path)
|
||||
if _, err := os.Stat(srcpath); os.IsNotExist(err) {
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
return &File{fs: f.fs, path: path}, nil
|
||||
}
|
||||
|
||||
func (f *File) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||
fis, err := ioutil.ReadDir(f.srcpath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ents := make([]fuse.Dirent, len(fis))
|
||||
for i, fi := range fis {
|
||||
statt := fi.Sys().(*syscall.Stat_t)
|
||||
ents[i] = fuse.Dirent{Inode: statt.Ino, Name: fi.Name()}
|
||||
}
|
||||
return ents, nil
|
||||
}
|
||||
// GenerateInode is called to pick a dynamic inode number when it
|
||||
// would otherwise be 0.
|
||||
//
|
||||
// Not all filesystems bother tracking inodes, but FUSE requires
|
||||
// the inode to be set, and fewer duplicates in general makes UNIX
|
||||
// tools work better.
|
||||
//
|
||||
// Operations where the nodes may return 0 inodes include Getattr,
|
||||
// Setattr and ReadDir.
|
||||
//
|
||||
// If FS does not implement FSInodeGenerator, GenerateDynamicInode
|
||||
// is used.
|
||||
//
|
||||
// Implementing this is useful to e.g. constrain the range of
|
||||
// inode values used for dynamic inodes.
|
||||
//
|
||||
// Non-zero return values should be greater than 1, as that is
|
||||
// always used for the root inode.
|
||||
// func (f *FS) GenerateInode(parentInode uint64, name string) uint64 {}
|
||||
|
||||
Reference in New Issue
Block a user