Commit caca93f6 authored by Aaron Jacobs's avatar Aaron Jacobs

Added ReadSymlinkOp.

parents 589723ca 3086e28f
......@@ -226,6 +226,13 @@ func Convert(
io = to
co = &to.commonOp
case *bazilfuse.ReadlinkRequest:
to := &ReadSymlinkOp{
Inode: InodeID(typed.Header.Node),
}
io = to
co = &to.commonOp
default:
to := &unknownOp{}
io = to
......
......@@ -886,3 +886,23 @@ type unknownOp struct {
func (o *unknownOp) toBazilfuseResponse() (bfResp interface{}) {
panic(fmt.Sprintf("Should never get here for unknown op: %s", o.ShortDesc()))
}
////////////////////////////////////////////////////////////////////////
// Reading symlinks
////////////////////////////////////////////////////////////////////////
// Read the target of a symlink inode.
type ReadSymlinkOp struct {
commonOp
// The symlink inode that we are reading.
Inode InodeID
// Set by the file system: the target of the symlink.
Target string
}
func (o *ReadSymlinkOp) toBazilfuseResponse() (bfResp interface{}) {
bfResp = o.Target
return
}
......@@ -57,6 +57,7 @@ type FileSystem interface {
SyncFile(*fuseops.SyncFileOp)
FlushFile(*fuseops.FlushFileOp)
ReleaseFileHandle(*fuseops.ReleaseFileHandleOp)
ReadSymlink(*fuseops.ReadSymlinkOp)
}
// Create a fuse.Server that handles ops by calling the associated FileSystem
......@@ -185,5 +186,8 @@ func (s fileSystemServer) handleOp(op fuseops.Op) {
case *fuseops.ReleaseFileHandleOp:
s.fs.ReleaseFileHandle(typed)
case *fuseops.ReadSymlinkOp:
s.fs.ReadSymlink(typed)
}
}
......@@ -122,3 +122,8 @@ func (fs *NotImplementedFileSystem) ReleaseFileHandle(
op *fuseops.ReleaseFileHandleOp) {
op.Respond(fuse.ENOSYS)
}
func (fs *NotImplementedFileSystem) ReadSymlink(
op *fuseops.ReadSymlinkOp) {
op.Respond(fuse.ENOSYS)
}
......@@ -406,6 +406,9 @@ func (fs *memFS) CreateSymlink(
childID, child := fs.allocateInode(childAttrs)
defer child.mu.Unlock()
// Set up its target.
child.target = op.Target
// Add an entry in the parent.
parent.AddChild(childID, op.Name, fuseutil.DT_Link)
......@@ -597,3 +600,21 @@ func (fs *memFS) WriteFile(
return
}
func (fs *memFS) ReadSymlink(
op *fuseops.ReadSymlinkOp) {
var err error
defer fuseutil.RespondToOp(op, &err)
fs.mu.Lock()
defer fs.mu.Unlock()
// Find the inode in question.
inode := fs.getInodeForReadingOrDie(op.Inode)
defer inode.mu.Unlock()
// Serve the request.
op.Target = inode.target
return
}
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