mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
@@ -31,6 +31,7 @@ go_library(
|
||||
srcs = [
|
||||
"connection.go",
|
||||
"dev.go",
|
||||
"directory.go",
|
||||
"file.go",
|
||||
"fusefs.go",
|
||||
"init.go",
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2020 The gVisor Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package fuse
|
||||
|
||||
import (
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/sentry/vfs"
|
||||
"gvisor.dev/gvisor/pkg/syserror"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
)
|
||||
|
||||
type directoryFD struct {
|
||||
fileDescription
|
||||
}
|
||||
|
||||
// Allocate implements directoryFD.Allocate.
|
||||
func (directoryFD) Allocate(ctx context.Context, mode, offset, length uint64) error {
|
||||
return syserror.EISDIR
|
||||
}
|
||||
|
||||
// PRead implements FileDescriptionImpl.PRead.
|
||||
func (directoryFD) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error) {
|
||||
return 0, syserror.EISDIR
|
||||
}
|
||||
|
||||
// Read implements FileDescriptionImpl.Read.
|
||||
func (directoryFD) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error) {
|
||||
return 0, syserror.EISDIR
|
||||
}
|
||||
|
||||
// PWrite implements FileDescriptionImpl.PWrite.
|
||||
func (directoryFD) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error) {
|
||||
return 0, syserror.EISDIR
|
||||
}
|
||||
|
||||
// Write implements FileDescriptionImpl.Write.
|
||||
func (directoryFD) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error) {
|
||||
return 0, syserror.EISDIR
|
||||
}
|
||||
@@ -262,8 +262,17 @@ func (i *inode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentr
|
||||
return nil, syserror.EOVERFLOW
|
||||
}
|
||||
|
||||
// FOPEN_KEEP_CACHE is the defualt flag for noOpen.
|
||||
fd := fileDescription{OpenFlag: linux.FOPEN_KEEP_CACHE}
|
||||
var fd *fileDescription
|
||||
var fdImpl vfs.FileDescriptionImpl
|
||||
if isDir {
|
||||
directoryFD := &directoryFD{}
|
||||
fd = &(directoryFD.fileDescription)
|
||||
fdImpl = directoryFD
|
||||
} else {
|
||||
// FOPEN_KEEP_CACHE is the defualt flag for noOpen.
|
||||
fd = &fileDescription{OpenFlag: linux.FOPEN_KEEP_CACHE}
|
||||
fdImpl = fd
|
||||
}
|
||||
// Only send open request when FUSE server support open or is opening a directory.
|
||||
if !i.fs.conn.noOpen || isDir {
|
||||
kernelTask := kernel.TaskFromContext(ctx)
|
||||
@@ -330,7 +339,7 @@ func (i *inode) Open(ctx context.Context, rp *vfs.ResolvingPath, vfsd *vfs.Dentr
|
||||
i.attributeTime = 0
|
||||
}
|
||||
|
||||
if err := fd.vfsfd.Init(&fd, opts.Flags, rp.Mount(), vfsd, fdOptions); err != nil {
|
||||
if err := fd.vfsfd.Init(fdImpl, opts.Flags, rp.Mount(), vfsd, fdOptions); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fd.vfsfd, nil
|
||||
@@ -374,6 +383,18 @@ func (i *inode) NewSymlink(ctx context.Context, name, target string) (*vfs.Dentr
|
||||
return i.newEntry(ctx, name, linux.S_IFLNK, linux.FUSE_SYMLINK, &in)
|
||||
}
|
||||
|
||||
// NewDir implements kernfs.Inode.NewDir.
|
||||
func (i *inode) NewDir(ctx context.Context, name string, opts vfs.MkdirOptions) (*vfs.Dentry, error) {
|
||||
in := linux.FUSEMkdirIn{
|
||||
MkdirMeta: linux.FUSEMkdirMeta{
|
||||
Mode: uint32(opts.Mode),
|
||||
Umask: uint32(kernel.TaskFromContext(ctx).FSContext().Umask()),
|
||||
},
|
||||
Name: name,
|
||||
}
|
||||
return i.newEntry(ctx, name, linux.S_IFDIR, linux.FUSE_MKDIR, &in)
|
||||
}
|
||||
|
||||
// newEntry calls FUSE server for entry creation and allocates corresponding entry according to response.
|
||||
// Shared by FUSE_MKNOD, FUSE_MKDIR, FUSE_SYMLINK, FUSE_LINK and FUSE_LOOKUP.
|
||||
func (i *inode) newEntry(ctx context.Context, name string, fileType linux.FileMode, opcode linux.FUSEOpcode, payload marshal.Marshallable) (*vfs.Dentry, error) {
|
||||
|
||||
Reference in New Issue
Block a user