From d629102fa6b9c75b3341071fffc17f7f0a9d7d03 Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Wed, 14 Dec 2022 22:14:20 +0100 Subject: [PATCH] mount2: introduce symlink support #2975 --- cmd/mount2/fs.go | 9 +++++++-- cmd/mount2/node.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cmd/mount2/fs.go b/cmd/mount2/fs.go index 03f907ee8..cbd72aad1 100644 --- a/cmd/mount2/fs.go +++ b/cmd/mount2/fs.go @@ -51,9 +51,14 @@ func (f *FS) SetDebug(debug bool) { // get the Mode from a vfs Node func getMode(node os.FileInfo) uint32 { - Mode := node.Mode().Perm() - if node.IsDir() { + vfsMode := node.Mode() + Mode := vfsMode.Perm() + if vfsMode&os.ModeDir != 0 { Mode |= fuse.S_IFDIR + } else if vfsMode&os.ModeSymlink != 0 { + Mode |= fuse.S_IFLNK + } else if vfsMode&os.ModeNamedPipe != 0 { + Mode |= fuse.S_IFIFO } else { Mode |= fuse.S_IFREG } diff --git a/cmd/mount2/node.go b/cmd/mount2/node.go index 74d05c7d9..782e8988b 100644 --- a/cmd/mount2/node.go +++ b/cmd/mount2/node.go @@ -458,3 +458,31 @@ func (n *Node) Listxattr(ctx context.Context, dest []byte) (uint32, syscall.Errn } var _ fusefs.NodeListxattrer = (*Node)(nil) + +var _ fusefs.NodeReadlinker = (*Node)(nil) + +// Readlink read symbolic link target. +func (n *Node) Readlink(ctx context.Context) (ret []byte, err syscall.Errno) { + defer log.Trace(n, "")("ret=%v, err=%v", &ret, &err) + path := n.node.Path() + s, serr := n.node.VFS().Readlink(path) + return []byte(s), translateError(serr) +} + +var _ fusefs.NodeSymlinker = (*Node)(nil) + +// Symlink create symbolic link. +func (n *Node) Symlink(ctx context.Context, target, name string, out *fuse.EntryOut) (node *fusefs.Inode, err syscall.Errno) { + defer log.Trace(n, "name=%v, target=%v", name, target)("node=%v, err=%v", &node, &err) + fullPath := path.Join(n.node.Path(), name) + vfsNode, serr := n.node.VFS().CreateSymlink(target, fullPath) + if serr != nil { + return nil, translateError(serr) + } + + n.fsys.setEntryOut(vfsNode, out) + newNode := newNode(n.fsys, vfsNode) + newInode := n.NewInode(ctx, newNode, fusefs.StableAttr{Mode: out.Attr.Mode}) + + return newInode, 0 +}