github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/fs/sys/fs.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package sys 16 17 import ( 18 "github.com/SagerNet/gvisor/pkg/context" 19 "github.com/SagerNet/gvisor/pkg/sentry/fs" 20 ) 21 22 // filesystem is a sysfs. 23 // 24 // +stateify savable 25 type filesystem struct{} 26 27 var _ fs.Filesystem = (*filesystem)(nil) 28 29 func init() { 30 fs.RegisterFilesystem(&filesystem{}) 31 } 32 33 // FilesystemName is the name under which the filesystem is registered. 34 // Name matches fs/sysfs/mount.c:sysfs_fs_type.name. 35 const FilesystemName = "sysfs" 36 37 // Name is the name of the file system. 38 func (*filesystem) Name() string { 39 return FilesystemName 40 } 41 42 // AllowUserMount allows users to mount(2) this file system. 43 func (*filesystem) AllowUserMount() bool { 44 return true 45 } 46 47 // AllowUserList allows this filesystem to be listed in /proc/filesystems. 48 func (*filesystem) AllowUserList() bool { 49 return true 50 } 51 52 // Flags returns that there is nothing special about this file system. 53 // 54 // In Linux, sysfs returns FS_USERNS_VISIBLE | FS_USERNS_MOUNT, see fs/sysfs/mount.c. 55 func (*filesystem) Flags() fs.FilesystemFlags { 56 return 0 57 } 58 59 // Mount returns a sysfs root which can be positioned in the vfs. 60 func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ interface{}) (*fs.Inode, error) { 61 // device is always ignored. 62 // sysfs ignores data, see fs/sysfs/mount.c:sysfs_mount. 63 64 return New(ctx, fs.NewNonCachingMountSource(ctx, f, flags)), nil 65 }