Commit 615a0a7e authored by ZheNing Hu's avatar ZheNing Hu

mount: add Options{RootStableAttr} field

- provides an optional way to set e.g. Ino and/or Gen for
  the root directory when calling fs.Mount()
- provides unit test cases
- partial fix for #399

Change-Id: If45a0ec3c0ea06c0419913e34b3415808f9349da
parent de5d9718
...@@ -610,4 +610,8 @@ type Options struct { ...@@ -610,4 +610,8 @@ type Options struct {
// return error, but want to signal something seems off // return error, but want to signal something seems off
// anyway. If unset, no messages are printed. // anyway. If unset, no messages are printed.
Logger *log.Logger Logger *log.Logger
// RootStableAttr is an optional way to set e.g. Ino and/or Gen for
// the root directory when calling fs.Mount(), Mode is ignored.
RootStableAttr *StableAttr
} }
...@@ -283,11 +283,17 @@ func NewNodeFS(root InodeEmbedder, opts *Options) fuse.RawFileSystem { ...@@ -283,11 +283,17 @@ func NewNodeFS(root InodeEmbedder, opts *Options) fuse.RawFileSystem {
bridge.options.AttrTimeout = &oneSec bridge.options.AttrTimeout = &oneSec
} }
initInode(root.embed(), root, stableAttr := StableAttr{
StableAttr{
Ino: root.embed().StableAttr().Ino, Ino: root.embed().StableAttr().Ino,
Mode: fuse.S_IFDIR, Mode: fuse.S_IFDIR,
}, }
if opts.RootStableAttr != nil {
stableAttr.Ino = opts.RootStableAttr.Ino
stableAttr.Gen = opts.RootStableAttr.Gen
}
initInode(root.embed(), root,
stableAttr,
bridge, bridge,
false, false,
1, 1,
......
...@@ -70,6 +70,26 @@ func TestDefaultOwner(t *testing.T) { ...@@ -70,6 +70,26 @@ func TestDefaultOwner(t *testing.T) {
} }
} }
func TestRootInode(t *testing.T) {
var rootIno uint64 = 42
root := &Inode{}
mntDir, _, clean := testMount(t, root, &Options{
RootStableAttr: &StableAttr{
Ino: rootIno,
Gen: 1,
},
})
defer clean()
var st syscall.Stat_t
if err := syscall.Lstat(mntDir, &st); err != nil {
t.Fatalf("Lstat: %v", err)
} else if st.Ino != rootIno {
t.Fatalf("Got Lstat inode %d, want %d", st.Ino, rootIno)
}
}
func TestDataFile(t *testing.T) { func TestDataFile(t *testing.T) {
want := "hello" want := "hello"
root := &Inode{} root := &Inode{}
......
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