2022-03-13 15:42:43 +00:00
|
|
|
//go:build darwin || freebsd || linux
|
2020-05-12 09:30:41 +00:00
|
|
|
// +build darwin freebsd linux
|
2015-08-16 20:27:07 +00:00
|
|
|
|
2015-07-21 19:25:05 +00:00
|
|
|
package fuse
|
|
|
|
|
|
|
|
import (
|
2020-10-05 21:09:52 +00:00
|
|
|
"context"
|
|
|
|
|
2022-11-12 13:52:37 +00:00
|
|
|
"github.com/anacrolix/fuse"
|
|
|
|
"github.com/anacrolix/fuse/fs"
|
2017-07-24 15:42:25 +00:00
|
|
|
"github.com/restic/restic/internal/restic"
|
2015-07-21 19:25:05 +00:00
|
|
|
)
|
|
|
|
|
2017-09-17 15:34:19 +00:00
|
|
|
// Statically ensure that *link implements the given interface
|
2024-09-09 20:37:51 +00:00
|
|
|
var _ = fs.NodeForgetter(&link{})
|
2024-09-09 20:37:08 +00:00
|
|
|
var _ = fs.NodeGetxattrer(&link{})
|
|
|
|
var _ = fs.NodeListxattrer(&link{})
|
2015-07-21 19:25:05 +00:00
|
|
|
var _ = fs.NodeReadlinker(&link{})
|
|
|
|
|
|
|
|
type link struct {
|
2024-09-09 20:37:51 +00:00
|
|
|
root *Root
|
|
|
|
forget forgetFn
|
|
|
|
node *restic.Node
|
|
|
|
inode uint64
|
2015-07-21 19:25:05 +00:00
|
|
|
}
|
|
|
|
|
2024-09-09 20:37:51 +00:00
|
|
|
func newLink(root *Root, forget forgetFn, inode uint64, node *restic.Node) (*link, error) {
|
|
|
|
return &link{root: root, forget: forget, inode: inode, node: node}, nil
|
2015-07-21 19:25:05 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 17:27:38 +00:00
|
|
|
func (l *link) Readlink(_ context.Context, _ *fuse.ReadlinkRequest) (string, error) {
|
2015-07-21 19:25:05 +00:00
|
|
|
return l.node.LinkTarget, nil
|
|
|
|
}
|
|
|
|
|
2023-05-18 17:18:09 +00:00
|
|
|
func (l *link) Attr(_ context.Context, a *fuse.Attr) error {
|
2017-06-18 13:11:32 +00:00
|
|
|
a.Inode = l.inode
|
2015-07-21 19:25:05 +00:00
|
|
|
a.Mode = l.node.Mode
|
2015-07-26 18:41:29 +00:00
|
|
|
|
2017-06-18 13:11:32 +00:00
|
|
|
if !l.root.cfg.OwnerIsRoot {
|
2015-07-26 18:41:29 +00:00
|
|
|
a.Uid = l.node.UID
|
|
|
|
a.Gid = l.node.GID
|
|
|
|
}
|
2015-07-21 20:11:30 +00:00
|
|
|
a.Atime = l.node.AccessTime
|
|
|
|
a.Ctime = l.node.ChangeTime
|
|
|
|
a.Mtime = l.node.ModTime
|
2017-02-11 20:50:03 +00:00
|
|
|
|
|
|
|
a.Nlink = uint32(l.node.Links)
|
2022-03-13 15:42:43 +00:00
|
|
|
a.Size = uint64(len(l.node.LinkTarget))
|
2023-03-07 21:12:08 +00:00
|
|
|
a.Blocks = (a.Size + blockSize - 1) / blockSize
|
2017-02-11 20:50:03 +00:00
|
|
|
|
2015-07-21 19:25:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-06-19 18:24:47 +00:00
|
|
|
|
|
|
|
func (l *link) Listxattr(_ context.Context, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error {
|
2023-07-08 15:41:45 +00:00
|
|
|
nodeToXattrList(l.node, req, resp)
|
2023-06-19 18:24:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *link) Getxattr(_ context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error {
|
2023-07-08 15:41:45 +00:00
|
|
|
return nodeGetXattr(l.node, req, resp)
|
2023-06-19 18:24:47 +00:00
|
|
|
}
|
2024-09-09 20:37:51 +00:00
|
|
|
|
|
|
|
func (l *link) Forget() {
|
|
|
|
l.forget()
|
|
|
|
}
|