Commit 32303528 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Implement StatFs.

parent 88b161f9
......@@ -63,6 +63,8 @@ type FileSystem interface {
// Symlinks.
Symlink(value string, linkName string) (code Status)
Readlink(name string) (string, Status)
StatFs() *StatfsOut
}
// A File object should be returned from FileSystem.Open and
......@@ -163,6 +165,7 @@ type RawFileSystem interface {
//
Ioctl(header *InHeader, input *IoctlIn) (output *IoctlOut, data []byte, code Status)
StatFs() *StatfsOut
// Provide callbacks for pushing notifications to the kernel.
Init(params *RawFsInit)
......
......@@ -12,6 +12,11 @@ var _ = fmt.Println
func (me *DefaultRawFileSystem) Init(init *RawFsInit) {
}
func (me *DefaultRawFileSystem) StatFs() *StatfsOut {
return nil
}
func (me *DefaultRawFileSystem) Lookup(h *InHeader, name string) (out *EntryOut, code Status) {
return nil, ENOSYS
}
......@@ -280,3 +285,7 @@ func (me *DefaultFileSystem) Utimens(name string, AtimeNs uint64, CtimeNs uint64
func (me *DefaultFileSystem) Name() string {
return "DefaultFileSystem"
}
func (me *DefaultFileSystem) StatFs() *StatfsOut {
return nil
}
......@@ -163,3 +163,24 @@ func (me *LoopbackFileSystem) Name() string {
return fmt.Sprintf("LoopbackFileSystem(%s)", me.Root)
}
func (me *LoopbackFileSystem) StatFs() *StatfsOut {
s := syscall.Statfs_t{}
errNo := syscall.Statfs(me.Root, &s)
if errNo == 0 {
return &StatfsOut{
Kstatfs{
Blocks: s.Blocks,
Bsize: uint32(s.Bsize),
Bfree: s.Bfree,
Bavail: s.Bavail,
Files: s.Files,
Ffree: s.Ffree,
Frsize: uint32(s.Frsize),
NameLen: uint32(s.Namelen),
},
}
}
return nil
}
......@@ -635,3 +635,31 @@ func TestIoctl(t *testing.T) {
v, e := ioctl(f.Fd(), 0x5401, 42)
fmt.Println("ioctl", v, e)
}
func TestStatFs(t *testing.T) {
ts := NewTestCase(t)
defer ts.Cleanup()
s1 := syscall.Statfs_t{}
err := syscall.Statfs(ts.orig, &s1)
if err != 0 {
t.Fatal("statfs orig", err)
}
s2 := syscall.Statfs_t{}
err = syscall.Statfs(ts.mnt, &s2)
s1.Type = 0
s2.Type = 0
s1.Fsid = [8]byte{0, 0, 0, 0, 0, 0, 0, 0}
s2.Fsid = [8]byte{0, 0, 0, 0, 0, 0, 0, 0}
if err != 0 {
t.Fatal("statfs mnt", err)
}
if fmt.Sprintf("%v", s2) != fmt.Sprintf("%v", s1) {
t.Error("Mismatch", s1, s2)
}
}
......@@ -279,6 +279,16 @@ func doRename(state *MountState, req *request) {
req.status = state.fileSystem.Rename(req.inHeader, (*RenameIn)(req.inData), req.filenames[0], req.filenames[1])
}
func doStatFs(state *MountState, req *request) {
stat := state.fileSystem.StatFs()
if stat != nil {
req.outData = unsafe.Pointer(stat)
req.status = OK
} else {
req.status = ENOSYS
}
}
func doIoctl(state *MountState, req *request) {
out, data, stat := state.fileSystem.Ioctl(req.inHeader, (*IoctlIn)(req.inData))
req.outData = unsafe.Pointer(out)
......@@ -460,6 +470,7 @@ func init() {
_OP_ACCESS: doAccess,
_OP_SYMLINK: doSymlink,
_OP_RENAME: doRename,
_OP_STATFS: doStatFs,
} {
operationHandlers[op].Func = v
}
......
......@@ -519,3 +519,8 @@ func (me *FileSystemConnector) Ioctl(header *InHeader, input *IoctlIn) (out *Ioc
}
return opened.file.Ioctl(input)
}
func (me *FileSystemConnector) StatFs() *StatfsOut {
return me.rootNode.mountPoint.fs.StatFs()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment