github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/abi/linux/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 linux
    16  
    17  // Filesystem types used in statfs(2).
    18  //
    19  // See linux/magic.h.
    20  const (
    21  	ANON_INODE_FS_MAGIC   = 0x09041934
    22  	CGROUP_SUPER_MAGIC    = 0x27e0eb
    23  	DEVPTS_SUPER_MAGIC    = 0x00001cd1
    24  	EXT_SUPER_MAGIC       = 0xef53
    25  	FUSE_SUPER_MAGIC      = 0x65735546
    26  	MQUEUE_MAGIC          = 0x19800202
    27  	NSFS_MAGIC            = 0x6e736673
    28  	OVERLAYFS_SUPER_MAGIC = 0x794c7630
    29  	PIPEFS_MAGIC          = 0x50495045
    30  	PROC_SUPER_MAGIC      = 0x9fa0
    31  	RAMFS_MAGIC           = 0x09041934
    32  	SOCKFS_MAGIC          = 0x534F434B
    33  	SYSFS_MAGIC           = 0x62656572
    34  	TMPFS_MAGIC           = 0x01021994
    35  	V9FS_MAGIC            = 0x01021997
    36  )
    37  
    38  // Filesystem path limits, from uapi/linux/limits.h.
    39  const (
    40  	NAME_MAX = 255
    41  	PATH_MAX = 4096
    42  )
    43  
    44  // The bit mask f_flags in struct statfs, from include/linux/statfs.h
    45  const (
    46  	ST_RDONLY      = 0x0001
    47  	ST_NOSUID      = 0x0002
    48  	ST_NODEV       = 0x0004
    49  	ST_NOEXEC      = 0x0008
    50  	ST_SYNCHRONOUS = 0x0010
    51  	ST_VALID       = 0x0020
    52  	ST_MANDLOCK    = 0x0040
    53  	ST_NOATIME     = 0x0400
    54  	ST_NODIRATIME  = 0x0800
    55  	ST_RELATIME    = 0x1000
    56  	ST_NOSYMFOLLOW = 0x2000
    57  )
    58  
    59  // Statfs is struct statfs, from uapi/asm-generic/statfs.h.
    60  //
    61  // +marshal
    62  type Statfs struct {
    63  	// Type is one of the filesystem magic values, defined above.
    64  	Type uint64
    65  
    66  	// BlockSize is the optimal transfer block size in bytes.
    67  	BlockSize int64
    68  
    69  	// Blocks is the maximum number of data blocks the filesystem may store, in
    70  	// units of BlockSize.
    71  	Blocks uint64
    72  
    73  	// BlocksFree is the number of free data blocks, in units of BlockSize.
    74  	BlocksFree uint64
    75  
    76  	// BlocksAvailable is the number of data blocks free for use by
    77  	// unprivileged users, in units of BlockSize.
    78  	BlocksAvailable uint64
    79  
    80  	// Files is the number of used file nodes on the filesystem.
    81  	Files uint64
    82  
    83  	// FileFress is the number of free file nodes on the filesystem.
    84  	FilesFree uint64
    85  
    86  	// FSID is the filesystem ID.
    87  	FSID [2]int32
    88  
    89  	// NameLength is the maximum file name length.
    90  	NameLength uint64
    91  
    92  	// FragmentSize is equivalent to BlockSize.
    93  	FragmentSize int64
    94  
    95  	// Flags is the set of filesystem mount flags.
    96  	Flags uint64
    97  
    98  	// Spare is unused.
    99  	Spare [4]uint64
   100  }
   101  
   102  // Whence argument to lseek(2), from include/uapi/linux/fs.h.
   103  const (
   104  	SEEK_SET  = 0
   105  	SEEK_CUR  = 1
   106  	SEEK_END  = 2
   107  	SEEK_DATA = 3
   108  	SEEK_HOLE = 4
   109  )
   110  
   111  // Sync_file_range flags, from include/uapi/linux/fs.h
   112  const (
   113  	SYNC_FILE_RANGE_WAIT_BEFORE = 1
   114  	SYNC_FILE_RANGE_WRITE       = 2
   115  	SYNC_FILE_RANGE_WAIT_AFTER  = 4
   116  )
   117  
   118  // Flag argument to renameat2(2), from include/uapi/linux/fs.h.
   119  const (
   120  	RENAME_NOREPLACE = (1 << 0) // Don't overwrite target.
   121  	RENAME_EXCHANGE  = (1 << 1) // Exchange src and dst.
   122  	RENAME_WHITEOUT  = (1 << 2) // Whiteout src.
   123  )