Commit 1cc8b3a4 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add a ReadOnlyFile wrapper type, and use it in UnionFs when applicable.

parent 11e662a2
......@@ -116,3 +116,30 @@ func (me *LoopbackFile) GetAttr() (*os.FileInfo, Status) {
}
return fi, OK
}
////////////////////////////////////////////////////////////////
// ReadOnlyFile is a wrapper that denies writable operations
type ReadOnlyFile struct {
File
}
func (me *ReadOnlyFile) Write(input *WriteIn, data []byte) (uint32, Status) {
return 0, EPERM
}
func (me *ReadOnlyFile) Fsync(*FsyncIn) (code Status) {
return OK
}
func (me *ReadOnlyFile) Truncate(size uint64) Status {
return EPERM
}
func (me *ReadOnlyFile) Chmod(mode uint32) Status {
return EPERM
}
func (me *ReadOnlyFile) Chown(uid uint32, gid uint32) Status {
return EPERM
}
......@@ -61,8 +61,8 @@ func (me *ReadonlyFileSystem) Open(name string, flags uint32, context *Context)
if flags&O_ANYWRITE != 0 {
return nil, EPERM
}
// TODO - wrap the File object inside a R/O wrapper too?
return me.FileSystem.Open(name, flags, context)
file, code = me.FileSystem.Open(name, flags, context)
return &ReadOnlyFile{file}, code
}
func (me *ReadonlyFileSystem) OpenDir(name string, context *Context) (stream chan DirEntry, status Status) {
......
......@@ -917,6 +917,9 @@ func (me *UnionFs) Open(name string, flags uint32, context *fuse.Context) (fuseF
if fuseFile != nil {
fuseFile = &UnionFsFile{fuseFile, r.branch}
}
if r.branch > 0 && fuseFile != nil {
fuseFile = &fuse.ReadOnlyFile{fuseFile}
}
return fuseFile, status
}
......
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