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

fs: add Options.{UID,GID} for setting default owners

parent f302529f
...@@ -462,4 +462,10 @@ type Options struct { ...@@ -462,4 +462,10 @@ type Options struct {
// DefaultPermissions sets null file permissions to 755 (dirs) // DefaultPermissions sets null file permissions to 755 (dirs)
// or 644 (other files.) // or 644 (other files.)
DefaultPermissions bool DefaultPermissions bool
// If nonzero, replace default (zero) UID with the given UID
UID uint32
// If nonzero, replace default (zero) GID with the given GID
GID uint32
} }
...@@ -152,6 +152,12 @@ func (b *rawBridge) setAttr(out *fuse.Attr) { ...@@ -152,6 +152,12 @@ func (b *rawBridge) setAttr(out *fuse.Attr) {
out.Mode |= 0111 out.Mode |= 0111
} }
} }
if b.options.UID != 0 && out.Uid == 0 {
out.Uid = b.options.UID
}
if b.options.GID != 0 && out.Gid == 0 {
out.Gid = b.options.GID
}
} }
func (b *rawBridge) setAttrTimeout(out *fuse.AttrOut) { func (b *rawBridge) setAttrTimeout(out *fuse.AttrOut) {
......
...@@ -38,6 +38,35 @@ func testMount(t *testing.T, root InodeEmbedder, opts *Options) (string, *fuse.S ...@@ -38,6 +38,35 @@ func testMount(t *testing.T, root InodeEmbedder, opts *Options) (string, *fuse.S
} }
} }
func TestDefaultOwner(t *testing.T) {
want := "hello"
root := &Inode{}
mntDir, _, clean := testMount(t, root, &Options{
FirstAutomaticIno: 1,
OnAdd: func(ctx context.Context) {
n := root.EmbeddedInode()
ch := n.NewPersistentInode(
ctx,
&MemRegularFile{
Data: []byte(want),
},
StableAttr{})
n.AddChild("file", ch, false)
},
UID: 42,
GID: 43,
})
defer clean()
var st syscall.Stat_t
if err := syscall.Lstat(mntDir+"/file", &st); err != nil {
t.Fatalf("Lstat: %v", err)
} else if st.Uid != 42 || st.Gid != 43 {
t.Fatalf("Got Lstat %d, %d want 42,43", st.Uid, st.Gid)
}
}
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