2019-12-16 05:07:01 +00:00
|
|
|
package filesys
|
|
|
|
|
|
|
|
import (
|
2020-04-22 01:50:30 +00:00
|
|
|
"context"
|
|
|
|
|
2020-06-11 08:50:00 +00:00
|
|
|
"github.com/seaweedfs/fuse"
|
|
|
|
|
2019-12-16 05:07:01 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2020-03-23 07:01:34 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2019-12-16 05:07:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getxattr(entry *filer_pb.Entry, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error {
|
|
|
|
|
|
|
|
if entry == nil {
|
|
|
|
return fuse.ErrNoXattr
|
|
|
|
}
|
|
|
|
if entry.Extended == nil {
|
|
|
|
return fuse.ErrNoXattr
|
|
|
|
}
|
|
|
|
data, found := entry.Extended[req.Name]
|
|
|
|
if !found {
|
|
|
|
return fuse.ErrNoXattr
|
|
|
|
}
|
|
|
|
if req.Position < uint32(len(data)) {
|
|
|
|
size := req.Size
|
|
|
|
if req.Position+size >= uint32(len(data)) {
|
|
|
|
size = uint32(len(data)) - req.Position
|
|
|
|
}
|
2019-12-18 05:45:32 +00:00
|
|
|
if size == 0 {
|
|
|
|
resp.Xattr = data[req.Position:]
|
|
|
|
} else {
|
|
|
|
resp.Xattr = data[req.Position : req.Position+size]
|
|
|
|
}
|
2019-12-16 05:07:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func setxattr(entry *filer_pb.Entry, req *fuse.SetxattrRequest) error {
|
|
|
|
|
|
|
|
if entry == nil {
|
|
|
|
return fuse.EIO
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry.Extended == nil {
|
|
|
|
entry.Extended = make(map[string][]byte)
|
|
|
|
}
|
|
|
|
data, _ := entry.Extended[req.Name]
|
|
|
|
|
|
|
|
newData := make([]byte, int(req.Position)+len(req.Xattr))
|
|
|
|
|
|
|
|
copy(newData, data)
|
|
|
|
|
|
|
|
copy(newData[int(req.Position):], req.Xattr)
|
|
|
|
|
|
|
|
entry.Extended[req.Name] = newData
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func removexattr(entry *filer_pb.Entry, req *fuse.RemovexattrRequest) error {
|
|
|
|
|
|
|
|
if entry == nil {
|
|
|
|
return fuse.ErrNoXattr
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry.Extended == nil {
|
|
|
|
return fuse.ErrNoXattr
|
|
|
|
}
|
|
|
|
|
|
|
|
_, found := entry.Extended[req.Name]
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
return fuse.ErrNoXattr
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(entry.Extended, req.Name)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func listxattr(entry *filer_pb.Entry, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error {
|
|
|
|
|
|
|
|
if entry == nil {
|
|
|
|
return fuse.EIO
|
|
|
|
}
|
|
|
|
|
|
|
|
for k := range entry.Extended {
|
|
|
|
resp.Append(k)
|
|
|
|
}
|
|
|
|
|
|
|
|
size := req.Size
|
|
|
|
if req.Position+size >= uint32(len(resp.Xattr)) {
|
|
|
|
size = uint32(len(resp.Xattr)) - req.Position
|
|
|
|
}
|
|
|
|
|
2019-12-18 05:45:32 +00:00
|
|
|
if size == 0 {
|
|
|
|
resp.Xattr = resp.Xattr[req.Position:]
|
|
|
|
} else {
|
|
|
|
resp.Xattr = resp.Xattr[req.Position : req.Position+size]
|
|
|
|
}
|
2019-12-16 05:07:01 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
func (wfs *WFS) maybeLoadEntry(dir, name string) (entry *filer_pb.Entry, err error) {
|
2019-12-16 05:07:01 +00:00
|
|
|
|
2020-03-23 07:01:34 +00:00
|
|
|
fullpath := util.NewFullPath(dir, name)
|
2020-01-25 08:31:53 +00:00
|
|
|
// glog.V(3).Infof("read entry cache miss %s", fullpath)
|
2019-12-16 05:07:01 +00:00
|
|
|
|
2020-04-22 01:50:30 +00:00
|
|
|
// read from async meta cache
|
2020-06-11 08:50:00 +00:00
|
|
|
cachedEntry, cacheErr := wfs.metaCache.FindEntry(context.Background(), fullpath)
|
|
|
|
if cacheErr == filer_pb.ErrNotFound {
|
|
|
|
return nil, fuse.ENOENT
|
2020-04-22 01:02:08 +00:00
|
|
|
}
|
2020-06-11 08:50:00 +00:00
|
|
|
return cachedEntry.ToProtoEntry(), nil
|
2020-04-22 01:02:08 +00:00
|
|
|
|
2019-12-16 05:07:01 +00:00
|
|
|
}
|