162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef _LINUX_FS_H 362306a36Sopenharmony_ci#define _LINUX_FS_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/linkage.h> 662306a36Sopenharmony_ci#include <linux/wait_bit.h> 762306a36Sopenharmony_ci#include <linux/kdev_t.h> 862306a36Sopenharmony_ci#include <linux/dcache.h> 962306a36Sopenharmony_ci#include <linux/path.h> 1062306a36Sopenharmony_ci#include <linux/stat.h> 1162306a36Sopenharmony_ci#include <linux/cache.h> 1262306a36Sopenharmony_ci#include <linux/list.h> 1362306a36Sopenharmony_ci#include <linux/list_lru.h> 1462306a36Sopenharmony_ci#include <linux/llist.h> 1562306a36Sopenharmony_ci#include <linux/radix-tree.h> 1662306a36Sopenharmony_ci#include <linux/xarray.h> 1762306a36Sopenharmony_ci#include <linux/rbtree.h> 1862306a36Sopenharmony_ci#include <linux/init.h> 1962306a36Sopenharmony_ci#include <linux/pid.h> 2062306a36Sopenharmony_ci#include <linux/bug.h> 2162306a36Sopenharmony_ci#include <linux/mutex.h> 2262306a36Sopenharmony_ci#include <linux/rwsem.h> 2362306a36Sopenharmony_ci#include <linux/mm_types.h> 2462306a36Sopenharmony_ci#include <linux/capability.h> 2562306a36Sopenharmony_ci#include <linux/semaphore.h> 2662306a36Sopenharmony_ci#include <linux/fcntl.h> 2762306a36Sopenharmony_ci#include <linux/rculist_bl.h> 2862306a36Sopenharmony_ci#include <linux/atomic.h> 2962306a36Sopenharmony_ci#include <linux/shrinker.h> 3062306a36Sopenharmony_ci#include <linux/migrate_mode.h> 3162306a36Sopenharmony_ci#include <linux/uidgid.h> 3262306a36Sopenharmony_ci#include <linux/lockdep.h> 3362306a36Sopenharmony_ci#include <linux/percpu-rwsem.h> 3462306a36Sopenharmony_ci#include <linux/workqueue.h> 3562306a36Sopenharmony_ci#include <linux/delayed_call.h> 3662306a36Sopenharmony_ci#include <linux/uuid.h> 3762306a36Sopenharmony_ci#include <linux/errseq.h> 3862306a36Sopenharmony_ci#include <linux/ioprio.h> 3962306a36Sopenharmony_ci#include <linux/fs_types.h> 4062306a36Sopenharmony_ci#include <linux/build_bug.h> 4162306a36Sopenharmony_ci#include <linux/stddef.h> 4262306a36Sopenharmony_ci#include <linux/mount.h> 4362306a36Sopenharmony_ci#include <linux/cred.h> 4462306a36Sopenharmony_ci#include <linux/mnt_idmapping.h> 4562306a36Sopenharmony_ci#include <linux/slab.h> 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci#include <asm/byteorder.h> 4862306a36Sopenharmony_ci#include <uapi/linux/fs.h> 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_cistruct backing_dev_info; 5162306a36Sopenharmony_cistruct bdi_writeback; 5262306a36Sopenharmony_cistruct bio; 5362306a36Sopenharmony_cistruct io_comp_batch; 5462306a36Sopenharmony_cistruct export_operations; 5562306a36Sopenharmony_cistruct fiemap_extent_info; 5662306a36Sopenharmony_cistruct hd_geometry; 5762306a36Sopenharmony_cistruct iovec; 5862306a36Sopenharmony_cistruct kiocb; 5962306a36Sopenharmony_cistruct kobject; 6062306a36Sopenharmony_cistruct pipe_inode_info; 6162306a36Sopenharmony_cistruct poll_table_struct; 6262306a36Sopenharmony_cistruct kstatfs; 6362306a36Sopenharmony_cistruct vm_area_struct; 6462306a36Sopenharmony_cistruct vfsmount; 6562306a36Sopenharmony_cistruct cred; 6662306a36Sopenharmony_cistruct swap_info_struct; 6762306a36Sopenharmony_cistruct seq_file; 6862306a36Sopenharmony_cistruct workqueue_struct; 6962306a36Sopenharmony_cistruct iov_iter; 7062306a36Sopenharmony_cistruct fscrypt_info; 7162306a36Sopenharmony_cistruct fscrypt_operations; 7262306a36Sopenharmony_cistruct fsverity_info; 7362306a36Sopenharmony_cistruct fsverity_operations; 7462306a36Sopenharmony_cistruct fs_context; 7562306a36Sopenharmony_cistruct fs_parameter_spec; 7662306a36Sopenharmony_cistruct fileattr; 7762306a36Sopenharmony_cistruct iomap_ops; 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciextern void __init inode_init(void); 8062306a36Sopenharmony_ciextern void __init inode_init_early(void); 8162306a36Sopenharmony_ciextern void __init files_init(void); 8262306a36Sopenharmony_ciextern void __init files_maxfiles_init(void); 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ciextern unsigned long get_max_files(void); 8562306a36Sopenharmony_ciextern unsigned int sysctl_nr_open; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_citypedef __kernel_rwf_t rwf_t; 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_cistruct buffer_head; 9062306a36Sopenharmony_citypedef int (get_block_t)(struct inode *inode, sector_t iblock, 9162306a36Sopenharmony_ci struct buffer_head *bh_result, int create); 9262306a36Sopenharmony_citypedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, 9362306a36Sopenharmony_ci ssize_t bytes, void *private); 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci#define MAY_EXEC 0x00000001 9662306a36Sopenharmony_ci#define MAY_WRITE 0x00000002 9762306a36Sopenharmony_ci#define MAY_READ 0x00000004 9862306a36Sopenharmony_ci#define MAY_APPEND 0x00000008 9962306a36Sopenharmony_ci#define MAY_ACCESS 0x00000010 10062306a36Sopenharmony_ci#define MAY_OPEN 0x00000020 10162306a36Sopenharmony_ci#define MAY_CHDIR 0x00000040 10262306a36Sopenharmony_ci/* called from RCU mode, don't block */ 10362306a36Sopenharmony_ci#define MAY_NOT_BLOCK 0x00000080 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/* 10662306a36Sopenharmony_ci * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond 10762306a36Sopenharmony_ci * to O_WRONLY and O_RDWR via the strange trick in do_dentry_open() 10862306a36Sopenharmony_ci */ 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci/* file is open for reading */ 11162306a36Sopenharmony_ci#define FMODE_READ ((__force fmode_t)0x1) 11262306a36Sopenharmony_ci/* file is open for writing */ 11362306a36Sopenharmony_ci#define FMODE_WRITE ((__force fmode_t)0x2) 11462306a36Sopenharmony_ci/* file is seekable */ 11562306a36Sopenharmony_ci#define FMODE_LSEEK ((__force fmode_t)0x4) 11662306a36Sopenharmony_ci/* file can be accessed using pread */ 11762306a36Sopenharmony_ci#define FMODE_PREAD ((__force fmode_t)0x8) 11862306a36Sopenharmony_ci/* file can be accessed using pwrite */ 11962306a36Sopenharmony_ci#define FMODE_PWRITE ((__force fmode_t)0x10) 12062306a36Sopenharmony_ci/* File is opened for execution with sys_execve / sys_uselib */ 12162306a36Sopenharmony_ci#define FMODE_EXEC ((__force fmode_t)0x20) 12262306a36Sopenharmony_ci/* 32bit hashes as llseek() offset (for directories) */ 12362306a36Sopenharmony_ci#define FMODE_32BITHASH ((__force fmode_t)0x200) 12462306a36Sopenharmony_ci/* 64bit hashes as llseek() offset (for directories) */ 12562306a36Sopenharmony_ci#define FMODE_64BITHASH ((__force fmode_t)0x400) 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci/* 12862306a36Sopenharmony_ci * Don't update ctime and mtime. 12962306a36Sopenharmony_ci * 13062306a36Sopenharmony_ci * Currently a special hack for the XFS open_by_handle ioctl, but we'll 13162306a36Sopenharmony_ci * hopefully graduate it to a proper O_CMTIME flag supported by open(2) soon. 13262306a36Sopenharmony_ci */ 13362306a36Sopenharmony_ci#define FMODE_NOCMTIME ((__force fmode_t)0x800) 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/* Expect random access pattern */ 13662306a36Sopenharmony_ci#define FMODE_RANDOM ((__force fmode_t)0x1000) 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci/* File is huge (eg. /dev/mem): treat loff_t as unsigned */ 13962306a36Sopenharmony_ci#define FMODE_UNSIGNED_OFFSET ((__force fmode_t)0x2000) 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci/* File is opened with O_PATH; almost nothing can be done with it */ 14262306a36Sopenharmony_ci#define FMODE_PATH ((__force fmode_t)0x4000) 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci/* File needs atomic accesses to f_pos */ 14562306a36Sopenharmony_ci#define FMODE_ATOMIC_POS ((__force fmode_t)0x8000) 14662306a36Sopenharmony_ci/* Write access to underlying fs */ 14762306a36Sopenharmony_ci#define FMODE_WRITER ((__force fmode_t)0x10000) 14862306a36Sopenharmony_ci/* Has read method(s) */ 14962306a36Sopenharmony_ci#define FMODE_CAN_READ ((__force fmode_t)0x20000) 15062306a36Sopenharmony_ci/* Has write method(s) */ 15162306a36Sopenharmony_ci#define FMODE_CAN_WRITE ((__force fmode_t)0x40000) 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci#define FMODE_OPENED ((__force fmode_t)0x80000) 15462306a36Sopenharmony_ci#define FMODE_CREATED ((__force fmode_t)0x100000) 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci/* File is stream-like */ 15762306a36Sopenharmony_ci#define FMODE_STREAM ((__force fmode_t)0x200000) 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci/* File supports DIRECT IO */ 16062306a36Sopenharmony_ci#define FMODE_CAN_ODIRECT ((__force fmode_t)0x400000) 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#define FMODE_NOREUSE ((__force fmode_t)0x800000) 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci/* File supports non-exclusive O_DIRECT writes from multiple threads */ 16562306a36Sopenharmony_ci#define FMODE_DIO_PARALLEL_WRITE ((__force fmode_t)0x1000000) 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci/* File is embedded in backing_file object */ 16862306a36Sopenharmony_ci#define FMODE_BACKING ((__force fmode_t)0x2000000) 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci/* File was opened by fanotify and shouldn't generate fanotify events */ 17162306a36Sopenharmony_ci#define FMODE_NONOTIFY ((__force fmode_t)0x4000000) 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci/* File is capable of returning -EAGAIN if I/O will block */ 17462306a36Sopenharmony_ci#define FMODE_NOWAIT ((__force fmode_t)0x8000000) 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci/* File represents mount that needs unmounting */ 17762306a36Sopenharmony_ci#define FMODE_NEED_UNMOUNT ((__force fmode_t)0x10000000) 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci/* File does not contribute to nr_files count */ 18062306a36Sopenharmony_ci#define FMODE_NOACCOUNT ((__force fmode_t)0x20000000) 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci/* File supports async buffered reads */ 18362306a36Sopenharmony_ci#define FMODE_BUF_RASYNC ((__force fmode_t)0x40000000) 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci/* File supports async nowait buffered writes */ 18662306a36Sopenharmony_ci#define FMODE_BUF_WASYNC ((__force fmode_t)0x80000000) 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci/* 18962306a36Sopenharmony_ci * Attribute flags. These should be or-ed together to figure out what 19062306a36Sopenharmony_ci * has been changed! 19162306a36Sopenharmony_ci */ 19262306a36Sopenharmony_ci#define ATTR_MODE (1 << 0) 19362306a36Sopenharmony_ci#define ATTR_UID (1 << 1) 19462306a36Sopenharmony_ci#define ATTR_GID (1 << 2) 19562306a36Sopenharmony_ci#define ATTR_SIZE (1 << 3) 19662306a36Sopenharmony_ci#define ATTR_ATIME (1 << 4) 19762306a36Sopenharmony_ci#define ATTR_MTIME (1 << 5) 19862306a36Sopenharmony_ci#define ATTR_CTIME (1 << 6) 19962306a36Sopenharmony_ci#define ATTR_ATIME_SET (1 << 7) 20062306a36Sopenharmony_ci#define ATTR_MTIME_SET (1 << 8) 20162306a36Sopenharmony_ci#define ATTR_FORCE (1 << 9) /* Not a change, but a change it */ 20262306a36Sopenharmony_ci#define ATTR_KILL_SUID (1 << 11) 20362306a36Sopenharmony_ci#define ATTR_KILL_SGID (1 << 12) 20462306a36Sopenharmony_ci#define ATTR_FILE (1 << 13) 20562306a36Sopenharmony_ci#define ATTR_KILL_PRIV (1 << 14) 20662306a36Sopenharmony_ci#define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */ 20762306a36Sopenharmony_ci#define ATTR_TIMES_SET (1 << 16) 20862306a36Sopenharmony_ci#define ATTR_TOUCH (1 << 17) 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci/* 21162306a36Sopenharmony_ci * Whiteout is represented by a char device. The following constants define the 21262306a36Sopenharmony_ci * mode and device number to use. 21362306a36Sopenharmony_ci */ 21462306a36Sopenharmony_ci#define WHITEOUT_MODE 0 21562306a36Sopenharmony_ci#define WHITEOUT_DEV 0 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci/* 21862306a36Sopenharmony_ci * This is the Inode Attributes structure, used for notify_change(). It 21962306a36Sopenharmony_ci * uses the above definitions as flags, to know which values have changed. 22062306a36Sopenharmony_ci * Also, in this manner, a Filesystem can look at only the values it cares 22162306a36Sopenharmony_ci * about. Basically, these are the attributes that the VFS layer can 22262306a36Sopenharmony_ci * request to change from the FS layer. 22362306a36Sopenharmony_ci * 22462306a36Sopenharmony_ci * Derek Atkins <warlord@MIT.EDU> 94-10-20 22562306a36Sopenharmony_ci */ 22662306a36Sopenharmony_cistruct iattr { 22762306a36Sopenharmony_ci unsigned int ia_valid; 22862306a36Sopenharmony_ci umode_t ia_mode; 22962306a36Sopenharmony_ci /* 23062306a36Sopenharmony_ci * The two anonymous unions wrap structures with the same member. 23162306a36Sopenharmony_ci * 23262306a36Sopenharmony_ci * Filesystems raising FS_ALLOW_IDMAP need to use ia_vfs{g,u}id which 23362306a36Sopenharmony_ci * are a dedicated type requiring the filesystem to use the dedicated 23462306a36Sopenharmony_ci * helpers. Other filesystem can continue to use ia_{g,u}id until they 23562306a36Sopenharmony_ci * have been ported. 23662306a36Sopenharmony_ci * 23762306a36Sopenharmony_ci * They always contain the same value. In other words FS_ALLOW_IDMAP 23862306a36Sopenharmony_ci * pass down the same value on idmapped mounts as they would on regular 23962306a36Sopenharmony_ci * mounts. 24062306a36Sopenharmony_ci */ 24162306a36Sopenharmony_ci union { 24262306a36Sopenharmony_ci kuid_t ia_uid; 24362306a36Sopenharmony_ci vfsuid_t ia_vfsuid; 24462306a36Sopenharmony_ci }; 24562306a36Sopenharmony_ci union { 24662306a36Sopenharmony_ci kgid_t ia_gid; 24762306a36Sopenharmony_ci vfsgid_t ia_vfsgid; 24862306a36Sopenharmony_ci }; 24962306a36Sopenharmony_ci loff_t ia_size; 25062306a36Sopenharmony_ci struct timespec64 ia_atime; 25162306a36Sopenharmony_ci struct timespec64 ia_mtime; 25262306a36Sopenharmony_ci struct timespec64 ia_ctime; 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci /* 25562306a36Sopenharmony_ci * Not an attribute, but an auxiliary info for filesystems wanting to 25662306a36Sopenharmony_ci * implement an ftruncate() like method. NOTE: filesystem should 25762306a36Sopenharmony_ci * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL). 25862306a36Sopenharmony_ci */ 25962306a36Sopenharmony_ci struct file *ia_file; 26062306a36Sopenharmony_ci}; 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ci/* 26362306a36Sopenharmony_ci * Includes for diskquotas. 26462306a36Sopenharmony_ci */ 26562306a36Sopenharmony_ci#include <linux/quota.h> 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci/* 26862306a36Sopenharmony_ci * Maximum number of layers of fs stack. Needs to be limited to 26962306a36Sopenharmony_ci * prevent kernel stack overflow 27062306a36Sopenharmony_ci */ 27162306a36Sopenharmony_ci#define FILESYSTEM_MAX_STACK_DEPTH 2 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci/** 27462306a36Sopenharmony_ci * enum positive_aop_returns - aop return codes with specific semantics 27562306a36Sopenharmony_ci * 27662306a36Sopenharmony_ci * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has 27762306a36Sopenharmony_ci * completed, that the page is still locked, and 27862306a36Sopenharmony_ci * should be considered active. The VM uses this hint 27962306a36Sopenharmony_ci * to return the page to the active list -- it won't 28062306a36Sopenharmony_ci * be a candidate for writeback again in the near 28162306a36Sopenharmony_ci * future. Other callers must be careful to unlock 28262306a36Sopenharmony_ci * the page if they get this return. Returned by 28362306a36Sopenharmony_ci * writepage(); 28462306a36Sopenharmony_ci * 28562306a36Sopenharmony_ci * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has 28662306a36Sopenharmony_ci * unlocked it and the page might have been truncated. 28762306a36Sopenharmony_ci * The caller should back up to acquiring a new page and 28862306a36Sopenharmony_ci * trying again. The aop will be taking reasonable 28962306a36Sopenharmony_ci * precautions not to livelock. If the caller held a page 29062306a36Sopenharmony_ci * reference, it should drop it before retrying. Returned 29162306a36Sopenharmony_ci * by read_folio(). 29262306a36Sopenharmony_ci * 29362306a36Sopenharmony_ci * address_space_operation functions return these large constants to indicate 29462306a36Sopenharmony_ci * special semantics to the caller. These are much larger than the bytes in a 29562306a36Sopenharmony_ci * page to allow for functions that return the number of bytes operated on in a 29662306a36Sopenharmony_ci * given page. 29762306a36Sopenharmony_ci */ 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_cienum positive_aop_returns { 30062306a36Sopenharmony_ci AOP_WRITEPAGE_ACTIVATE = 0x80000, 30162306a36Sopenharmony_ci AOP_TRUNCATED_PAGE = 0x80001, 30262306a36Sopenharmony_ci}; 30362306a36Sopenharmony_ci 30462306a36Sopenharmony_ci/* 30562306a36Sopenharmony_ci * oh the beauties of C type declarations. 30662306a36Sopenharmony_ci */ 30762306a36Sopenharmony_cistruct page; 30862306a36Sopenharmony_cistruct address_space; 30962306a36Sopenharmony_cistruct writeback_control; 31062306a36Sopenharmony_cistruct readahead_control; 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ci/* 31362306a36Sopenharmony_ci * Write life time hint values. 31462306a36Sopenharmony_ci * Stored in struct inode as u8. 31562306a36Sopenharmony_ci */ 31662306a36Sopenharmony_cienum rw_hint { 31762306a36Sopenharmony_ci WRITE_LIFE_NOT_SET = 0, 31862306a36Sopenharmony_ci WRITE_LIFE_NONE = RWH_WRITE_LIFE_NONE, 31962306a36Sopenharmony_ci WRITE_LIFE_SHORT = RWH_WRITE_LIFE_SHORT, 32062306a36Sopenharmony_ci WRITE_LIFE_MEDIUM = RWH_WRITE_LIFE_MEDIUM, 32162306a36Sopenharmony_ci WRITE_LIFE_LONG = RWH_WRITE_LIFE_LONG, 32262306a36Sopenharmony_ci WRITE_LIFE_EXTREME = RWH_WRITE_LIFE_EXTREME, 32362306a36Sopenharmony_ci}; 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci/* Match RWF_* bits to IOCB bits */ 32662306a36Sopenharmony_ci#define IOCB_HIPRI (__force int) RWF_HIPRI 32762306a36Sopenharmony_ci#define IOCB_DSYNC (__force int) RWF_DSYNC 32862306a36Sopenharmony_ci#define IOCB_SYNC (__force int) RWF_SYNC 32962306a36Sopenharmony_ci#define IOCB_NOWAIT (__force int) RWF_NOWAIT 33062306a36Sopenharmony_ci#define IOCB_APPEND (__force int) RWF_APPEND 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ci/* non-RWF related bits - start at 16 */ 33362306a36Sopenharmony_ci#define IOCB_EVENTFD (1 << 16) 33462306a36Sopenharmony_ci#define IOCB_DIRECT (1 << 17) 33562306a36Sopenharmony_ci#define IOCB_WRITE (1 << 18) 33662306a36Sopenharmony_ci/* iocb->ki_waitq is valid */ 33762306a36Sopenharmony_ci#define IOCB_WAITQ (1 << 19) 33862306a36Sopenharmony_ci#define IOCB_NOIO (1 << 20) 33962306a36Sopenharmony_ci/* can use bio alloc cache */ 34062306a36Sopenharmony_ci#define IOCB_ALLOC_CACHE (1 << 21) 34162306a36Sopenharmony_ci/* 34262306a36Sopenharmony_ci * IOCB_DIO_CALLER_COMP can be set by the iocb owner, to indicate that the 34362306a36Sopenharmony_ci * iocb completion can be passed back to the owner for execution from a safe 34462306a36Sopenharmony_ci * context rather than needing to be punted through a workqueue. If this 34562306a36Sopenharmony_ci * flag is set, the bio completion handling may set iocb->dio_complete to a 34662306a36Sopenharmony_ci * handler function and iocb->private to context information for that handler. 34762306a36Sopenharmony_ci * The issuer should call the handler with that context information from task 34862306a36Sopenharmony_ci * context to complete the processing of the iocb. Note that while this 34962306a36Sopenharmony_ci * provides a task context for the dio_complete() callback, it should only be 35062306a36Sopenharmony_ci * used on the completion side for non-IO generating completions. It's fine to 35162306a36Sopenharmony_ci * call blocking functions from this callback, but they should not wait for 35262306a36Sopenharmony_ci * unrelated IO (like cache flushing, new IO generation, etc). 35362306a36Sopenharmony_ci */ 35462306a36Sopenharmony_ci#define IOCB_DIO_CALLER_COMP (1 << 22) 35562306a36Sopenharmony_ci/* kiocb is a read or write operation submitted by fs/aio.c. */ 35662306a36Sopenharmony_ci#define IOCB_AIO_RW (1 << 23) 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci/* for use in trace events */ 35962306a36Sopenharmony_ci#define TRACE_IOCB_STRINGS \ 36062306a36Sopenharmony_ci { IOCB_HIPRI, "HIPRI" }, \ 36162306a36Sopenharmony_ci { IOCB_DSYNC, "DSYNC" }, \ 36262306a36Sopenharmony_ci { IOCB_SYNC, "SYNC" }, \ 36362306a36Sopenharmony_ci { IOCB_NOWAIT, "NOWAIT" }, \ 36462306a36Sopenharmony_ci { IOCB_APPEND, "APPEND" }, \ 36562306a36Sopenharmony_ci { IOCB_EVENTFD, "EVENTFD"}, \ 36662306a36Sopenharmony_ci { IOCB_DIRECT, "DIRECT" }, \ 36762306a36Sopenharmony_ci { IOCB_WRITE, "WRITE" }, \ 36862306a36Sopenharmony_ci { IOCB_WAITQ, "WAITQ" }, \ 36962306a36Sopenharmony_ci { IOCB_NOIO, "NOIO" }, \ 37062306a36Sopenharmony_ci { IOCB_ALLOC_CACHE, "ALLOC_CACHE" }, \ 37162306a36Sopenharmony_ci { IOCB_DIO_CALLER_COMP, "CALLER_COMP" } 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_cistruct kiocb { 37462306a36Sopenharmony_ci struct file *ki_filp; 37562306a36Sopenharmony_ci loff_t ki_pos; 37662306a36Sopenharmony_ci void (*ki_complete)(struct kiocb *iocb, long ret); 37762306a36Sopenharmony_ci void *private; 37862306a36Sopenharmony_ci int ki_flags; 37962306a36Sopenharmony_ci u16 ki_ioprio; /* See linux/ioprio.h */ 38062306a36Sopenharmony_ci union { 38162306a36Sopenharmony_ci /* 38262306a36Sopenharmony_ci * Only used for async buffered reads, where it denotes the 38362306a36Sopenharmony_ci * page waitqueue associated with completing the read. Valid 38462306a36Sopenharmony_ci * IFF IOCB_WAITQ is set. 38562306a36Sopenharmony_ci */ 38662306a36Sopenharmony_ci struct wait_page_queue *ki_waitq; 38762306a36Sopenharmony_ci /* 38862306a36Sopenharmony_ci * Can be used for O_DIRECT IO, where the completion handling 38962306a36Sopenharmony_ci * is punted back to the issuer of the IO. May only be set 39062306a36Sopenharmony_ci * if IOCB_DIO_CALLER_COMP is set by the issuer, and the issuer 39162306a36Sopenharmony_ci * must then check for presence of this handler when ki_complete 39262306a36Sopenharmony_ci * is invoked. The data passed in to this handler must be 39362306a36Sopenharmony_ci * assigned to ->private when dio_complete is assigned. 39462306a36Sopenharmony_ci */ 39562306a36Sopenharmony_ci ssize_t (*dio_complete)(void *data); 39662306a36Sopenharmony_ci }; 39762306a36Sopenharmony_ci}; 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_cistatic inline bool is_sync_kiocb(struct kiocb *kiocb) 40062306a36Sopenharmony_ci{ 40162306a36Sopenharmony_ci return kiocb->ki_complete == NULL; 40262306a36Sopenharmony_ci} 40362306a36Sopenharmony_ci 40462306a36Sopenharmony_cistruct address_space_operations { 40562306a36Sopenharmony_ci int (*writepage)(struct page *page, struct writeback_control *wbc); 40662306a36Sopenharmony_ci int (*read_folio)(struct file *, struct folio *); 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ci /* Write back some dirty pages from this mapping. */ 40962306a36Sopenharmony_ci int (*writepages)(struct address_space *, struct writeback_control *); 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci /* Mark a folio dirty. Return true if this dirtied it */ 41262306a36Sopenharmony_ci bool (*dirty_folio)(struct address_space *, struct folio *); 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci void (*readahead)(struct readahead_control *); 41562306a36Sopenharmony_ci 41662306a36Sopenharmony_ci int (*write_begin)(struct file *, struct address_space *mapping, 41762306a36Sopenharmony_ci loff_t pos, unsigned len, 41862306a36Sopenharmony_ci struct page **pagep, void **fsdata); 41962306a36Sopenharmony_ci int (*write_end)(struct file *, struct address_space *mapping, 42062306a36Sopenharmony_ci loff_t pos, unsigned len, unsigned copied, 42162306a36Sopenharmony_ci struct page *page, void *fsdata); 42262306a36Sopenharmony_ci 42362306a36Sopenharmony_ci /* Unfortunately this kludge is needed for FIBMAP. Don't use it */ 42462306a36Sopenharmony_ci sector_t (*bmap)(struct address_space *, sector_t); 42562306a36Sopenharmony_ci void (*invalidate_folio) (struct folio *, size_t offset, size_t len); 42662306a36Sopenharmony_ci bool (*release_folio)(struct folio *, gfp_t); 42762306a36Sopenharmony_ci void (*free_folio)(struct folio *folio); 42862306a36Sopenharmony_ci ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter); 42962306a36Sopenharmony_ci /* 43062306a36Sopenharmony_ci * migrate the contents of a folio to the specified target. If 43162306a36Sopenharmony_ci * migrate_mode is MIGRATE_ASYNC, it must not block. 43262306a36Sopenharmony_ci */ 43362306a36Sopenharmony_ci int (*migrate_folio)(struct address_space *, struct folio *dst, 43462306a36Sopenharmony_ci struct folio *src, enum migrate_mode); 43562306a36Sopenharmony_ci int (*launder_folio)(struct folio *); 43662306a36Sopenharmony_ci bool (*is_partially_uptodate) (struct folio *, size_t from, 43762306a36Sopenharmony_ci size_t count); 43862306a36Sopenharmony_ci void (*is_dirty_writeback) (struct folio *, bool *dirty, bool *wb); 43962306a36Sopenharmony_ci int (*error_remove_page)(struct address_space *, struct page *); 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci /* swapfile support */ 44262306a36Sopenharmony_ci int (*swap_activate)(struct swap_info_struct *sis, struct file *file, 44362306a36Sopenharmony_ci sector_t *span); 44462306a36Sopenharmony_ci void (*swap_deactivate)(struct file *file); 44562306a36Sopenharmony_ci int (*swap_rw)(struct kiocb *iocb, struct iov_iter *iter); 44662306a36Sopenharmony_ci}; 44762306a36Sopenharmony_ci 44862306a36Sopenharmony_ciextern const struct address_space_operations empty_aops; 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci/** 45162306a36Sopenharmony_ci * struct address_space - Contents of a cacheable, mappable object. 45262306a36Sopenharmony_ci * @host: Owner, either the inode or the block_device. 45362306a36Sopenharmony_ci * @i_pages: Cached pages. 45462306a36Sopenharmony_ci * @invalidate_lock: Guards coherency between page cache contents and 45562306a36Sopenharmony_ci * file offset->disk block mappings in the filesystem during invalidates. 45662306a36Sopenharmony_ci * It is also used to block modification of page cache contents through 45762306a36Sopenharmony_ci * memory mappings. 45862306a36Sopenharmony_ci * @gfp_mask: Memory allocation flags to use for allocating pages. 45962306a36Sopenharmony_ci * @i_mmap_writable: Number of VM_SHARED mappings. 46062306a36Sopenharmony_ci * @nr_thps: Number of THPs in the pagecache (non-shmem only). 46162306a36Sopenharmony_ci * @i_mmap: Tree of private and shared mappings. 46262306a36Sopenharmony_ci * @i_mmap_rwsem: Protects @i_mmap and @i_mmap_writable. 46362306a36Sopenharmony_ci * @nrpages: Number of page entries, protected by the i_pages lock. 46462306a36Sopenharmony_ci * @writeback_index: Writeback starts here. 46562306a36Sopenharmony_ci * @a_ops: Methods. 46662306a36Sopenharmony_ci * @flags: Error bits and flags (AS_*). 46762306a36Sopenharmony_ci * @wb_err: The most recent error which has occurred. 46862306a36Sopenharmony_ci * @private_lock: For use by the owner of the address_space. 46962306a36Sopenharmony_ci * @private_list: For use by the owner of the address_space. 47062306a36Sopenharmony_ci * @private_data: For use by the owner of the address_space. 47162306a36Sopenharmony_ci */ 47262306a36Sopenharmony_cistruct address_space { 47362306a36Sopenharmony_ci struct inode *host; 47462306a36Sopenharmony_ci struct xarray i_pages; 47562306a36Sopenharmony_ci struct rw_semaphore invalidate_lock; 47662306a36Sopenharmony_ci gfp_t gfp_mask; 47762306a36Sopenharmony_ci atomic_t i_mmap_writable; 47862306a36Sopenharmony_ci#ifdef CONFIG_READ_ONLY_THP_FOR_FS 47962306a36Sopenharmony_ci /* number of thp, only for non-shmem files */ 48062306a36Sopenharmony_ci atomic_t nr_thps; 48162306a36Sopenharmony_ci#endif 48262306a36Sopenharmony_ci struct rb_root_cached i_mmap; 48362306a36Sopenharmony_ci unsigned long nrpages; 48462306a36Sopenharmony_ci pgoff_t writeback_index; 48562306a36Sopenharmony_ci const struct address_space_operations *a_ops; 48662306a36Sopenharmony_ci unsigned long flags; 48762306a36Sopenharmony_ci struct rw_semaphore i_mmap_rwsem; 48862306a36Sopenharmony_ci errseq_t wb_err; 48962306a36Sopenharmony_ci spinlock_t private_lock; 49062306a36Sopenharmony_ci struct list_head private_list; 49162306a36Sopenharmony_ci void *private_data; 49262306a36Sopenharmony_ci} __attribute__((aligned(sizeof(long)))) __randomize_layout; 49362306a36Sopenharmony_ci /* 49462306a36Sopenharmony_ci * On most architectures that alignment is already the case; but 49562306a36Sopenharmony_ci * must be enforced here for CRIS, to let the least significant bit 49662306a36Sopenharmony_ci * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. 49762306a36Sopenharmony_ci */ 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci/* XArray tags, for tagging dirty and writeback pages in the pagecache. */ 50062306a36Sopenharmony_ci#define PAGECACHE_TAG_DIRTY XA_MARK_0 50162306a36Sopenharmony_ci#define PAGECACHE_TAG_WRITEBACK XA_MARK_1 50262306a36Sopenharmony_ci#define PAGECACHE_TAG_TOWRITE XA_MARK_2 50362306a36Sopenharmony_ci 50462306a36Sopenharmony_ci/* 50562306a36Sopenharmony_ci * Returns true if any of the pages in the mapping are marked with the tag. 50662306a36Sopenharmony_ci */ 50762306a36Sopenharmony_cistatic inline bool mapping_tagged(struct address_space *mapping, xa_mark_t tag) 50862306a36Sopenharmony_ci{ 50962306a36Sopenharmony_ci return xa_marked(&mapping->i_pages, tag); 51062306a36Sopenharmony_ci} 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_cistatic inline void i_mmap_lock_write(struct address_space *mapping) 51362306a36Sopenharmony_ci{ 51462306a36Sopenharmony_ci down_write(&mapping->i_mmap_rwsem); 51562306a36Sopenharmony_ci} 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_cistatic inline int i_mmap_trylock_write(struct address_space *mapping) 51862306a36Sopenharmony_ci{ 51962306a36Sopenharmony_ci return down_write_trylock(&mapping->i_mmap_rwsem); 52062306a36Sopenharmony_ci} 52162306a36Sopenharmony_ci 52262306a36Sopenharmony_cistatic inline void i_mmap_unlock_write(struct address_space *mapping) 52362306a36Sopenharmony_ci{ 52462306a36Sopenharmony_ci up_write(&mapping->i_mmap_rwsem); 52562306a36Sopenharmony_ci} 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_cistatic inline int i_mmap_trylock_read(struct address_space *mapping) 52862306a36Sopenharmony_ci{ 52962306a36Sopenharmony_ci return down_read_trylock(&mapping->i_mmap_rwsem); 53062306a36Sopenharmony_ci} 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_cistatic inline void i_mmap_lock_read(struct address_space *mapping) 53362306a36Sopenharmony_ci{ 53462306a36Sopenharmony_ci down_read(&mapping->i_mmap_rwsem); 53562306a36Sopenharmony_ci} 53662306a36Sopenharmony_ci 53762306a36Sopenharmony_cistatic inline void i_mmap_unlock_read(struct address_space *mapping) 53862306a36Sopenharmony_ci{ 53962306a36Sopenharmony_ci up_read(&mapping->i_mmap_rwsem); 54062306a36Sopenharmony_ci} 54162306a36Sopenharmony_ci 54262306a36Sopenharmony_cistatic inline void i_mmap_assert_locked(struct address_space *mapping) 54362306a36Sopenharmony_ci{ 54462306a36Sopenharmony_ci lockdep_assert_held(&mapping->i_mmap_rwsem); 54562306a36Sopenharmony_ci} 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_cistatic inline void i_mmap_assert_write_locked(struct address_space *mapping) 54862306a36Sopenharmony_ci{ 54962306a36Sopenharmony_ci lockdep_assert_held_write(&mapping->i_mmap_rwsem); 55062306a36Sopenharmony_ci} 55162306a36Sopenharmony_ci 55262306a36Sopenharmony_ci/* 55362306a36Sopenharmony_ci * Might pages of this file be mapped into userspace? 55462306a36Sopenharmony_ci */ 55562306a36Sopenharmony_cistatic inline int mapping_mapped(struct address_space *mapping) 55662306a36Sopenharmony_ci{ 55762306a36Sopenharmony_ci return !RB_EMPTY_ROOT(&mapping->i_mmap.rb_root); 55862306a36Sopenharmony_ci} 55962306a36Sopenharmony_ci 56062306a36Sopenharmony_ci/* 56162306a36Sopenharmony_ci * Might pages of this file have been modified in userspace? 56262306a36Sopenharmony_ci * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap 56362306a36Sopenharmony_ci * marks vma as VM_SHARED if it is shared, and the file was opened for 56462306a36Sopenharmony_ci * writing i.e. vma may be mprotected writable even if now readonly. 56562306a36Sopenharmony_ci * 56662306a36Sopenharmony_ci * If i_mmap_writable is negative, no new writable mappings are allowed. You 56762306a36Sopenharmony_ci * can only deny writable mappings, if none exists right now. 56862306a36Sopenharmony_ci */ 56962306a36Sopenharmony_cistatic inline int mapping_writably_mapped(struct address_space *mapping) 57062306a36Sopenharmony_ci{ 57162306a36Sopenharmony_ci return atomic_read(&mapping->i_mmap_writable) > 0; 57262306a36Sopenharmony_ci} 57362306a36Sopenharmony_ci 57462306a36Sopenharmony_cistatic inline int mapping_map_writable(struct address_space *mapping) 57562306a36Sopenharmony_ci{ 57662306a36Sopenharmony_ci return atomic_inc_unless_negative(&mapping->i_mmap_writable) ? 57762306a36Sopenharmony_ci 0 : -EPERM; 57862306a36Sopenharmony_ci} 57962306a36Sopenharmony_ci 58062306a36Sopenharmony_cistatic inline void mapping_unmap_writable(struct address_space *mapping) 58162306a36Sopenharmony_ci{ 58262306a36Sopenharmony_ci atomic_dec(&mapping->i_mmap_writable); 58362306a36Sopenharmony_ci} 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_cistatic inline int mapping_deny_writable(struct address_space *mapping) 58662306a36Sopenharmony_ci{ 58762306a36Sopenharmony_ci return atomic_dec_unless_positive(&mapping->i_mmap_writable) ? 58862306a36Sopenharmony_ci 0 : -EBUSY; 58962306a36Sopenharmony_ci} 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_cistatic inline void mapping_allow_writable(struct address_space *mapping) 59262306a36Sopenharmony_ci{ 59362306a36Sopenharmony_ci atomic_inc(&mapping->i_mmap_writable); 59462306a36Sopenharmony_ci} 59562306a36Sopenharmony_ci 59662306a36Sopenharmony_ci/* 59762306a36Sopenharmony_ci * Use sequence counter to get consistent i_size on 32-bit processors. 59862306a36Sopenharmony_ci */ 59962306a36Sopenharmony_ci#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 60062306a36Sopenharmony_ci#include <linux/seqlock.h> 60162306a36Sopenharmony_ci#define __NEED_I_SIZE_ORDERED 60262306a36Sopenharmony_ci#define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount) 60362306a36Sopenharmony_ci#else 60462306a36Sopenharmony_ci#define i_size_ordered_init(inode) do { } while (0) 60562306a36Sopenharmony_ci#endif 60662306a36Sopenharmony_ci 60762306a36Sopenharmony_cistruct posix_acl; 60862306a36Sopenharmony_ci#define ACL_NOT_CACHED ((void *)(-1)) 60962306a36Sopenharmony_ci/* 61062306a36Sopenharmony_ci * ACL_DONT_CACHE is for stacked filesystems, that rely on underlying fs to 61162306a36Sopenharmony_ci * cache the ACL. This also means that ->get_inode_acl() can be called in RCU 61262306a36Sopenharmony_ci * mode with the LOOKUP_RCU flag. 61362306a36Sopenharmony_ci */ 61462306a36Sopenharmony_ci#define ACL_DONT_CACHE ((void *)(-3)) 61562306a36Sopenharmony_ci 61662306a36Sopenharmony_cistatic inline struct posix_acl * 61762306a36Sopenharmony_ciuncached_acl_sentinel(struct task_struct *task) 61862306a36Sopenharmony_ci{ 61962306a36Sopenharmony_ci return (void *)task + 1; 62062306a36Sopenharmony_ci} 62162306a36Sopenharmony_ci 62262306a36Sopenharmony_cistatic inline bool 62362306a36Sopenharmony_ciis_uncached_acl(struct posix_acl *acl) 62462306a36Sopenharmony_ci{ 62562306a36Sopenharmony_ci return (long)acl & 1; 62662306a36Sopenharmony_ci} 62762306a36Sopenharmony_ci 62862306a36Sopenharmony_ci#define IOP_FASTPERM 0x0001 62962306a36Sopenharmony_ci#define IOP_LOOKUP 0x0002 63062306a36Sopenharmony_ci#define IOP_NOFOLLOW 0x0004 63162306a36Sopenharmony_ci#define IOP_XATTR 0x0008 63262306a36Sopenharmony_ci#define IOP_DEFAULT_READLINK 0x0010 63362306a36Sopenharmony_ci 63462306a36Sopenharmony_cistruct fsnotify_mark_connector; 63562306a36Sopenharmony_ci 63662306a36Sopenharmony_ci/* 63762306a36Sopenharmony_ci * Keep mostly read-only and often accessed (especially for 63862306a36Sopenharmony_ci * the RCU path lookup and 'stat' data) fields at the beginning 63962306a36Sopenharmony_ci * of the 'struct inode' 64062306a36Sopenharmony_ci */ 64162306a36Sopenharmony_cistruct inode { 64262306a36Sopenharmony_ci umode_t i_mode; 64362306a36Sopenharmony_ci unsigned short i_opflags; 64462306a36Sopenharmony_ci kuid_t i_uid; 64562306a36Sopenharmony_ci kgid_t i_gid; 64662306a36Sopenharmony_ci unsigned int i_flags; 64762306a36Sopenharmony_ci 64862306a36Sopenharmony_ci#ifdef CONFIG_FS_POSIX_ACL 64962306a36Sopenharmony_ci struct posix_acl *i_acl; 65062306a36Sopenharmony_ci struct posix_acl *i_default_acl; 65162306a36Sopenharmony_ci#endif 65262306a36Sopenharmony_ci 65362306a36Sopenharmony_ci const struct inode_operations *i_op; 65462306a36Sopenharmony_ci struct super_block *i_sb; 65562306a36Sopenharmony_ci struct address_space *i_mapping; 65662306a36Sopenharmony_ci 65762306a36Sopenharmony_ci#ifdef CONFIG_SECURITY 65862306a36Sopenharmony_ci void *i_security; 65962306a36Sopenharmony_ci#endif 66062306a36Sopenharmony_ci 66162306a36Sopenharmony_ci /* Stat data, not accessed from path walking */ 66262306a36Sopenharmony_ci unsigned long i_ino; 66362306a36Sopenharmony_ci /* 66462306a36Sopenharmony_ci * Filesystems may only read i_nlink directly. They shall use the 66562306a36Sopenharmony_ci * following functions for modification: 66662306a36Sopenharmony_ci * 66762306a36Sopenharmony_ci * (set|clear|inc|drop)_nlink 66862306a36Sopenharmony_ci * inode_(inc|dec)_link_count 66962306a36Sopenharmony_ci */ 67062306a36Sopenharmony_ci union { 67162306a36Sopenharmony_ci const unsigned int i_nlink; 67262306a36Sopenharmony_ci unsigned int __i_nlink; 67362306a36Sopenharmony_ci }; 67462306a36Sopenharmony_ci dev_t i_rdev; 67562306a36Sopenharmony_ci loff_t i_size; 67662306a36Sopenharmony_ci struct timespec64 i_atime; 67762306a36Sopenharmony_ci struct timespec64 i_mtime; 67862306a36Sopenharmony_ci struct timespec64 __i_ctime; /* use inode_*_ctime accessors! */ 67962306a36Sopenharmony_ci spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ 68062306a36Sopenharmony_ci unsigned short i_bytes; 68162306a36Sopenharmony_ci u8 i_blkbits; 68262306a36Sopenharmony_ci u8 i_write_hint; 68362306a36Sopenharmony_ci blkcnt_t i_blocks; 68462306a36Sopenharmony_ci 68562306a36Sopenharmony_ci#ifdef __NEED_I_SIZE_ORDERED 68662306a36Sopenharmony_ci seqcount_t i_size_seqcount; 68762306a36Sopenharmony_ci#endif 68862306a36Sopenharmony_ci 68962306a36Sopenharmony_ci /* Misc */ 69062306a36Sopenharmony_ci unsigned long i_state; 69162306a36Sopenharmony_ci struct rw_semaphore i_rwsem; 69262306a36Sopenharmony_ci 69362306a36Sopenharmony_ci unsigned long dirtied_when; /* jiffies of first dirtying */ 69462306a36Sopenharmony_ci unsigned long dirtied_time_when; 69562306a36Sopenharmony_ci 69662306a36Sopenharmony_ci struct hlist_node i_hash; 69762306a36Sopenharmony_ci struct list_head i_io_list; /* backing dev IO list */ 69862306a36Sopenharmony_ci#ifdef CONFIG_CGROUP_WRITEBACK 69962306a36Sopenharmony_ci struct bdi_writeback *i_wb; /* the associated cgroup wb */ 70062306a36Sopenharmony_ci 70162306a36Sopenharmony_ci /* foreign inode detection, see wbc_detach_inode() */ 70262306a36Sopenharmony_ci int i_wb_frn_winner; 70362306a36Sopenharmony_ci u16 i_wb_frn_avg_time; 70462306a36Sopenharmony_ci u16 i_wb_frn_history; 70562306a36Sopenharmony_ci#endif 70662306a36Sopenharmony_ci struct list_head i_lru; /* inode LRU list */ 70762306a36Sopenharmony_ci struct list_head i_sb_list; 70862306a36Sopenharmony_ci struct list_head i_wb_list; /* backing dev writeback list */ 70962306a36Sopenharmony_ci union { 71062306a36Sopenharmony_ci struct hlist_head i_dentry; 71162306a36Sopenharmony_ci struct rcu_head i_rcu; 71262306a36Sopenharmony_ci }; 71362306a36Sopenharmony_ci atomic64_t i_version; 71462306a36Sopenharmony_ci atomic64_t i_sequence; /* see futex */ 71562306a36Sopenharmony_ci atomic_t i_count; 71662306a36Sopenharmony_ci atomic_t i_dio_count; 71762306a36Sopenharmony_ci atomic_t i_writecount; 71862306a36Sopenharmony_ci#if defined(CONFIG_IMA) || defined(CONFIG_FILE_LOCKING) 71962306a36Sopenharmony_ci atomic_t i_readcount; /* struct files open RO */ 72062306a36Sopenharmony_ci#endif 72162306a36Sopenharmony_ci union { 72262306a36Sopenharmony_ci const struct file_operations *i_fop; /* former ->i_op->default_file_ops */ 72362306a36Sopenharmony_ci void (*free_inode)(struct inode *); 72462306a36Sopenharmony_ci }; 72562306a36Sopenharmony_ci struct file_lock_context *i_flctx; 72662306a36Sopenharmony_ci struct address_space i_data; 72762306a36Sopenharmony_ci struct list_head i_devices; 72862306a36Sopenharmony_ci union { 72962306a36Sopenharmony_ci struct pipe_inode_info *i_pipe; 73062306a36Sopenharmony_ci struct cdev *i_cdev; 73162306a36Sopenharmony_ci char *i_link; 73262306a36Sopenharmony_ci unsigned i_dir_seq; 73362306a36Sopenharmony_ci }; 73462306a36Sopenharmony_ci 73562306a36Sopenharmony_ci __u32 i_generation; 73662306a36Sopenharmony_ci 73762306a36Sopenharmony_ci#ifdef CONFIG_FSNOTIFY 73862306a36Sopenharmony_ci __u32 i_fsnotify_mask; /* all events this inode cares about */ 73962306a36Sopenharmony_ci struct fsnotify_mark_connector __rcu *i_fsnotify_marks; 74062306a36Sopenharmony_ci#endif 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci#ifdef CONFIG_FS_ENCRYPTION 74362306a36Sopenharmony_ci struct fscrypt_info *i_crypt_info; 74462306a36Sopenharmony_ci#endif 74562306a36Sopenharmony_ci 74662306a36Sopenharmony_ci#ifdef CONFIG_FS_VERITY 74762306a36Sopenharmony_ci struct fsverity_info *i_verity_info; 74862306a36Sopenharmony_ci#endif 74962306a36Sopenharmony_ci 75062306a36Sopenharmony_ci void *i_private; /* fs or device private pointer */ 75162306a36Sopenharmony_ci} __randomize_layout; 75262306a36Sopenharmony_ci 75362306a36Sopenharmony_cistruct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode); 75462306a36Sopenharmony_ci 75562306a36Sopenharmony_cistatic inline unsigned int i_blocksize(const struct inode *node) 75662306a36Sopenharmony_ci{ 75762306a36Sopenharmony_ci return (1 << node->i_blkbits); 75862306a36Sopenharmony_ci} 75962306a36Sopenharmony_ci 76062306a36Sopenharmony_cistatic inline int inode_unhashed(struct inode *inode) 76162306a36Sopenharmony_ci{ 76262306a36Sopenharmony_ci return hlist_unhashed(&inode->i_hash); 76362306a36Sopenharmony_ci} 76462306a36Sopenharmony_ci 76562306a36Sopenharmony_ci/* 76662306a36Sopenharmony_ci * __mark_inode_dirty expects inodes to be hashed. Since we don't 76762306a36Sopenharmony_ci * want special inodes in the fileset inode space, we make them 76862306a36Sopenharmony_ci * appear hashed, but do not put on any lists. hlist_del() 76962306a36Sopenharmony_ci * will work fine and require no locking. 77062306a36Sopenharmony_ci */ 77162306a36Sopenharmony_cistatic inline void inode_fake_hash(struct inode *inode) 77262306a36Sopenharmony_ci{ 77362306a36Sopenharmony_ci hlist_add_fake(&inode->i_hash); 77462306a36Sopenharmony_ci} 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_ci/* 77762306a36Sopenharmony_ci * inode->i_mutex nesting subclasses for the lock validator: 77862306a36Sopenharmony_ci * 77962306a36Sopenharmony_ci * 0: the object of the current VFS operation 78062306a36Sopenharmony_ci * 1: parent 78162306a36Sopenharmony_ci * 2: child/target 78262306a36Sopenharmony_ci * 3: xattr 78362306a36Sopenharmony_ci * 4: second non-directory 78462306a36Sopenharmony_ci * 5: second parent (when locking independent directories in rename) 78562306a36Sopenharmony_ci * 78662306a36Sopenharmony_ci * I_MUTEX_NONDIR2 is for certain operations (such as rename) which lock two 78762306a36Sopenharmony_ci * non-directories at once. 78862306a36Sopenharmony_ci * 78962306a36Sopenharmony_ci * The locking order between these classes is 79062306a36Sopenharmony_ci * parent[2] -> child -> grandchild -> normal -> xattr -> second non-directory 79162306a36Sopenharmony_ci */ 79262306a36Sopenharmony_cienum inode_i_mutex_lock_class 79362306a36Sopenharmony_ci{ 79462306a36Sopenharmony_ci I_MUTEX_NORMAL, 79562306a36Sopenharmony_ci I_MUTEX_PARENT, 79662306a36Sopenharmony_ci I_MUTEX_CHILD, 79762306a36Sopenharmony_ci I_MUTEX_XATTR, 79862306a36Sopenharmony_ci I_MUTEX_NONDIR2, 79962306a36Sopenharmony_ci I_MUTEX_PARENT2, 80062306a36Sopenharmony_ci}; 80162306a36Sopenharmony_ci 80262306a36Sopenharmony_cistatic inline void inode_lock(struct inode *inode) 80362306a36Sopenharmony_ci{ 80462306a36Sopenharmony_ci down_write(&inode->i_rwsem); 80562306a36Sopenharmony_ci} 80662306a36Sopenharmony_ci 80762306a36Sopenharmony_cistatic inline void inode_unlock(struct inode *inode) 80862306a36Sopenharmony_ci{ 80962306a36Sopenharmony_ci up_write(&inode->i_rwsem); 81062306a36Sopenharmony_ci} 81162306a36Sopenharmony_ci 81262306a36Sopenharmony_cistatic inline void inode_lock_shared(struct inode *inode) 81362306a36Sopenharmony_ci{ 81462306a36Sopenharmony_ci down_read(&inode->i_rwsem); 81562306a36Sopenharmony_ci} 81662306a36Sopenharmony_ci 81762306a36Sopenharmony_cistatic inline void inode_unlock_shared(struct inode *inode) 81862306a36Sopenharmony_ci{ 81962306a36Sopenharmony_ci up_read(&inode->i_rwsem); 82062306a36Sopenharmony_ci} 82162306a36Sopenharmony_ci 82262306a36Sopenharmony_cistatic inline int inode_trylock(struct inode *inode) 82362306a36Sopenharmony_ci{ 82462306a36Sopenharmony_ci return down_write_trylock(&inode->i_rwsem); 82562306a36Sopenharmony_ci} 82662306a36Sopenharmony_ci 82762306a36Sopenharmony_cistatic inline int inode_trylock_shared(struct inode *inode) 82862306a36Sopenharmony_ci{ 82962306a36Sopenharmony_ci return down_read_trylock(&inode->i_rwsem); 83062306a36Sopenharmony_ci} 83162306a36Sopenharmony_ci 83262306a36Sopenharmony_cistatic inline int inode_is_locked(struct inode *inode) 83362306a36Sopenharmony_ci{ 83462306a36Sopenharmony_ci return rwsem_is_locked(&inode->i_rwsem); 83562306a36Sopenharmony_ci} 83662306a36Sopenharmony_ci 83762306a36Sopenharmony_cistatic inline void inode_lock_nested(struct inode *inode, unsigned subclass) 83862306a36Sopenharmony_ci{ 83962306a36Sopenharmony_ci down_write_nested(&inode->i_rwsem, subclass); 84062306a36Sopenharmony_ci} 84162306a36Sopenharmony_ci 84262306a36Sopenharmony_cistatic inline void inode_lock_shared_nested(struct inode *inode, unsigned subclass) 84362306a36Sopenharmony_ci{ 84462306a36Sopenharmony_ci down_read_nested(&inode->i_rwsem, subclass); 84562306a36Sopenharmony_ci} 84662306a36Sopenharmony_ci 84762306a36Sopenharmony_cistatic inline void filemap_invalidate_lock(struct address_space *mapping) 84862306a36Sopenharmony_ci{ 84962306a36Sopenharmony_ci down_write(&mapping->invalidate_lock); 85062306a36Sopenharmony_ci} 85162306a36Sopenharmony_ci 85262306a36Sopenharmony_cistatic inline void filemap_invalidate_unlock(struct address_space *mapping) 85362306a36Sopenharmony_ci{ 85462306a36Sopenharmony_ci up_write(&mapping->invalidate_lock); 85562306a36Sopenharmony_ci} 85662306a36Sopenharmony_ci 85762306a36Sopenharmony_cistatic inline void filemap_invalidate_lock_shared(struct address_space *mapping) 85862306a36Sopenharmony_ci{ 85962306a36Sopenharmony_ci down_read(&mapping->invalidate_lock); 86062306a36Sopenharmony_ci} 86162306a36Sopenharmony_ci 86262306a36Sopenharmony_cistatic inline int filemap_invalidate_trylock_shared( 86362306a36Sopenharmony_ci struct address_space *mapping) 86462306a36Sopenharmony_ci{ 86562306a36Sopenharmony_ci return down_read_trylock(&mapping->invalidate_lock); 86662306a36Sopenharmony_ci} 86762306a36Sopenharmony_ci 86862306a36Sopenharmony_cistatic inline void filemap_invalidate_unlock_shared( 86962306a36Sopenharmony_ci struct address_space *mapping) 87062306a36Sopenharmony_ci{ 87162306a36Sopenharmony_ci up_read(&mapping->invalidate_lock); 87262306a36Sopenharmony_ci} 87362306a36Sopenharmony_ci 87462306a36Sopenharmony_civoid lock_two_nondirectories(struct inode *, struct inode*); 87562306a36Sopenharmony_civoid unlock_two_nondirectories(struct inode *, struct inode*); 87662306a36Sopenharmony_ci 87762306a36Sopenharmony_civoid filemap_invalidate_lock_two(struct address_space *mapping1, 87862306a36Sopenharmony_ci struct address_space *mapping2); 87962306a36Sopenharmony_civoid filemap_invalidate_unlock_two(struct address_space *mapping1, 88062306a36Sopenharmony_ci struct address_space *mapping2); 88162306a36Sopenharmony_ci 88262306a36Sopenharmony_ci 88362306a36Sopenharmony_ci/* 88462306a36Sopenharmony_ci * NOTE: in a 32bit arch with a preemptable kernel and 88562306a36Sopenharmony_ci * an UP compile the i_size_read/write must be atomic 88662306a36Sopenharmony_ci * with respect to the local cpu (unlike with preempt disabled), 88762306a36Sopenharmony_ci * but they don't need to be atomic with respect to other cpus like in 88862306a36Sopenharmony_ci * true SMP (so they need either to either locally disable irq around 88962306a36Sopenharmony_ci * the read or for example on x86 they can be still implemented as a 89062306a36Sopenharmony_ci * cmpxchg8b without the need of the lock prefix). For SMP compiles 89162306a36Sopenharmony_ci * and 64bit archs it makes no difference if preempt is enabled or not. 89262306a36Sopenharmony_ci */ 89362306a36Sopenharmony_cistatic inline loff_t i_size_read(const struct inode *inode) 89462306a36Sopenharmony_ci{ 89562306a36Sopenharmony_ci#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 89662306a36Sopenharmony_ci loff_t i_size; 89762306a36Sopenharmony_ci unsigned int seq; 89862306a36Sopenharmony_ci 89962306a36Sopenharmony_ci do { 90062306a36Sopenharmony_ci seq = read_seqcount_begin(&inode->i_size_seqcount); 90162306a36Sopenharmony_ci i_size = inode->i_size; 90262306a36Sopenharmony_ci } while (read_seqcount_retry(&inode->i_size_seqcount, seq)); 90362306a36Sopenharmony_ci return i_size; 90462306a36Sopenharmony_ci#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION) 90562306a36Sopenharmony_ci loff_t i_size; 90662306a36Sopenharmony_ci 90762306a36Sopenharmony_ci preempt_disable(); 90862306a36Sopenharmony_ci i_size = inode->i_size; 90962306a36Sopenharmony_ci preempt_enable(); 91062306a36Sopenharmony_ci return i_size; 91162306a36Sopenharmony_ci#else 91262306a36Sopenharmony_ci return inode->i_size; 91362306a36Sopenharmony_ci#endif 91462306a36Sopenharmony_ci} 91562306a36Sopenharmony_ci 91662306a36Sopenharmony_ci/* 91762306a36Sopenharmony_ci * NOTE: unlike i_size_read(), i_size_write() does need locking around it 91862306a36Sopenharmony_ci * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount 91962306a36Sopenharmony_ci * can be lost, resulting in subsequent i_size_read() calls spinning forever. 92062306a36Sopenharmony_ci */ 92162306a36Sopenharmony_cistatic inline void i_size_write(struct inode *inode, loff_t i_size) 92262306a36Sopenharmony_ci{ 92362306a36Sopenharmony_ci#if BITS_PER_LONG==32 && defined(CONFIG_SMP) 92462306a36Sopenharmony_ci preempt_disable(); 92562306a36Sopenharmony_ci write_seqcount_begin(&inode->i_size_seqcount); 92662306a36Sopenharmony_ci inode->i_size = i_size; 92762306a36Sopenharmony_ci write_seqcount_end(&inode->i_size_seqcount); 92862306a36Sopenharmony_ci preempt_enable(); 92962306a36Sopenharmony_ci#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION) 93062306a36Sopenharmony_ci preempt_disable(); 93162306a36Sopenharmony_ci inode->i_size = i_size; 93262306a36Sopenharmony_ci preempt_enable(); 93362306a36Sopenharmony_ci#else 93462306a36Sopenharmony_ci inode->i_size = i_size; 93562306a36Sopenharmony_ci#endif 93662306a36Sopenharmony_ci} 93762306a36Sopenharmony_ci 93862306a36Sopenharmony_cistatic inline unsigned iminor(const struct inode *inode) 93962306a36Sopenharmony_ci{ 94062306a36Sopenharmony_ci return MINOR(inode->i_rdev); 94162306a36Sopenharmony_ci} 94262306a36Sopenharmony_ci 94362306a36Sopenharmony_cistatic inline unsigned imajor(const struct inode *inode) 94462306a36Sopenharmony_ci{ 94562306a36Sopenharmony_ci return MAJOR(inode->i_rdev); 94662306a36Sopenharmony_ci} 94762306a36Sopenharmony_ci 94862306a36Sopenharmony_cistruct fown_struct { 94962306a36Sopenharmony_ci rwlock_t lock; /* protects pid, uid, euid fields */ 95062306a36Sopenharmony_ci struct pid *pid; /* pid or -pgrp where SIGIO should be sent */ 95162306a36Sopenharmony_ci enum pid_type pid_type; /* Kind of process group SIGIO should be sent to */ 95262306a36Sopenharmony_ci kuid_t uid, euid; /* uid/euid of process setting the owner */ 95362306a36Sopenharmony_ci int signum; /* posix.1b rt signal to be delivered on IO */ 95462306a36Sopenharmony_ci}; 95562306a36Sopenharmony_ci 95662306a36Sopenharmony_ci/** 95762306a36Sopenharmony_ci * struct file_ra_state - Track a file's readahead state. 95862306a36Sopenharmony_ci * @start: Where the most recent readahead started. 95962306a36Sopenharmony_ci * @size: Number of pages read in the most recent readahead. 96062306a36Sopenharmony_ci * @async_size: Numer of pages that were/are not needed immediately 96162306a36Sopenharmony_ci * and so were/are genuinely "ahead". Start next readahead when 96262306a36Sopenharmony_ci * the first of these pages is accessed. 96362306a36Sopenharmony_ci * @ra_pages: Maximum size of a readahead request, copied from the bdi. 96462306a36Sopenharmony_ci * @mmap_miss: How many mmap accesses missed in the page cache. 96562306a36Sopenharmony_ci * @prev_pos: The last byte in the most recent read request. 96662306a36Sopenharmony_ci * 96762306a36Sopenharmony_ci * When this structure is passed to ->readahead(), the "most recent" 96862306a36Sopenharmony_ci * readahead means the current readahead. 96962306a36Sopenharmony_ci */ 97062306a36Sopenharmony_cistruct file_ra_state { 97162306a36Sopenharmony_ci pgoff_t start; 97262306a36Sopenharmony_ci unsigned int size; 97362306a36Sopenharmony_ci unsigned int async_size; 97462306a36Sopenharmony_ci unsigned int ra_pages; 97562306a36Sopenharmony_ci unsigned int mmap_miss; 97662306a36Sopenharmony_ci loff_t prev_pos; 97762306a36Sopenharmony_ci}; 97862306a36Sopenharmony_ci 97962306a36Sopenharmony_ci/* 98062306a36Sopenharmony_ci * Check if @index falls in the readahead windows. 98162306a36Sopenharmony_ci */ 98262306a36Sopenharmony_cistatic inline int ra_has_index(struct file_ra_state *ra, pgoff_t index) 98362306a36Sopenharmony_ci{ 98462306a36Sopenharmony_ci return (index >= ra->start && 98562306a36Sopenharmony_ci index < ra->start + ra->size); 98662306a36Sopenharmony_ci} 98762306a36Sopenharmony_ci 98862306a36Sopenharmony_ci/* 98962306a36Sopenharmony_ci * f_{lock,count,pos_lock} members can be highly contended and share 99062306a36Sopenharmony_ci * the same cacheline. f_{lock,mode} are very frequently used together 99162306a36Sopenharmony_ci * and so share the same cacheline as well. The read-mostly 99262306a36Sopenharmony_ci * f_{path,inode,op} are kept on a separate cacheline. 99362306a36Sopenharmony_ci */ 99462306a36Sopenharmony_cistruct file { 99562306a36Sopenharmony_ci union { 99662306a36Sopenharmony_ci struct llist_node f_llist; 99762306a36Sopenharmony_ci struct rcu_head f_rcuhead; 99862306a36Sopenharmony_ci unsigned int f_iocb_flags; 99962306a36Sopenharmony_ci }; 100062306a36Sopenharmony_ci 100162306a36Sopenharmony_ci /* 100262306a36Sopenharmony_ci * Protects f_ep, f_flags. 100362306a36Sopenharmony_ci * Must not be taken from IRQ context. 100462306a36Sopenharmony_ci */ 100562306a36Sopenharmony_ci spinlock_t f_lock; 100662306a36Sopenharmony_ci fmode_t f_mode; 100762306a36Sopenharmony_ci atomic_long_t f_count; 100862306a36Sopenharmony_ci struct mutex f_pos_lock; 100962306a36Sopenharmony_ci loff_t f_pos; 101062306a36Sopenharmony_ci unsigned int f_flags; 101162306a36Sopenharmony_ci struct fown_struct f_owner; 101262306a36Sopenharmony_ci const struct cred *f_cred; 101362306a36Sopenharmony_ci struct file_ra_state f_ra; 101462306a36Sopenharmony_ci struct path f_path; 101562306a36Sopenharmony_ci struct inode *f_inode; /* cached value */ 101662306a36Sopenharmony_ci const struct file_operations *f_op; 101762306a36Sopenharmony_ci 101862306a36Sopenharmony_ci u64 f_version; 101962306a36Sopenharmony_ci#ifdef CONFIG_SECURITY 102062306a36Sopenharmony_ci void *f_security; 102162306a36Sopenharmony_ci#endif 102262306a36Sopenharmony_ci /* needed for tty driver, and maybe others */ 102362306a36Sopenharmony_ci void *private_data; 102462306a36Sopenharmony_ci 102562306a36Sopenharmony_ci#ifdef CONFIG_EPOLL 102662306a36Sopenharmony_ci /* Used by fs/eventpoll.c to link all the hooks to this file */ 102762306a36Sopenharmony_ci struct hlist_head *f_ep; 102862306a36Sopenharmony_ci#endif /* #ifdef CONFIG_EPOLL */ 102962306a36Sopenharmony_ci struct address_space *f_mapping; 103062306a36Sopenharmony_ci errseq_t f_wb_err; 103162306a36Sopenharmony_ci errseq_t f_sb_err; /* for syncfs */ 103262306a36Sopenharmony_ci} __randomize_layout 103362306a36Sopenharmony_ci __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */ 103462306a36Sopenharmony_ci 103562306a36Sopenharmony_cistruct file_handle { 103662306a36Sopenharmony_ci __u32 handle_bytes; 103762306a36Sopenharmony_ci int handle_type; 103862306a36Sopenharmony_ci /* file identifier */ 103962306a36Sopenharmony_ci unsigned char f_handle[]; 104062306a36Sopenharmony_ci}; 104162306a36Sopenharmony_ci 104262306a36Sopenharmony_cistatic inline struct file *get_file(struct file *f) 104362306a36Sopenharmony_ci{ 104462306a36Sopenharmony_ci atomic_long_inc(&f->f_count); 104562306a36Sopenharmony_ci return f; 104662306a36Sopenharmony_ci} 104762306a36Sopenharmony_ci#define get_file_rcu(x) atomic_long_inc_not_zero(&(x)->f_count) 104862306a36Sopenharmony_ci#define file_count(x) atomic_long_read(&(x)->f_count) 104962306a36Sopenharmony_ci 105062306a36Sopenharmony_ci#define MAX_NON_LFS ((1UL<<31) - 1) 105162306a36Sopenharmony_ci 105262306a36Sopenharmony_ci/* Page cache limit. The filesystems should put that into their s_maxbytes 105362306a36Sopenharmony_ci limits, otherwise bad things can happen in VM. */ 105462306a36Sopenharmony_ci#if BITS_PER_LONG==32 105562306a36Sopenharmony_ci#define MAX_LFS_FILESIZE ((loff_t)ULONG_MAX << PAGE_SHIFT) 105662306a36Sopenharmony_ci#elif BITS_PER_LONG==64 105762306a36Sopenharmony_ci#define MAX_LFS_FILESIZE ((loff_t)LLONG_MAX) 105862306a36Sopenharmony_ci#endif 105962306a36Sopenharmony_ci 106062306a36Sopenharmony_ci/* legacy typedef, should eventually be removed */ 106162306a36Sopenharmony_citypedef void *fl_owner_t; 106262306a36Sopenharmony_ci 106362306a36Sopenharmony_cistruct file_lock; 106462306a36Sopenharmony_ci 106562306a36Sopenharmony_ci/* The following constant reflects the upper bound of the file/locking space */ 106662306a36Sopenharmony_ci#ifndef OFFSET_MAX 106762306a36Sopenharmony_ci#define OFFSET_MAX type_max(loff_t) 106862306a36Sopenharmony_ci#define OFFT_OFFSET_MAX type_max(off_t) 106962306a36Sopenharmony_ci#endif 107062306a36Sopenharmony_ci 107162306a36Sopenharmony_ciextern void send_sigio(struct fown_struct *fown, int fd, int band); 107262306a36Sopenharmony_ci 107362306a36Sopenharmony_cistatic inline struct inode *file_inode(const struct file *f) 107462306a36Sopenharmony_ci{ 107562306a36Sopenharmony_ci return f->f_inode; 107662306a36Sopenharmony_ci} 107762306a36Sopenharmony_ci 107862306a36Sopenharmony_cistatic inline struct dentry *file_dentry(const struct file *file) 107962306a36Sopenharmony_ci{ 108062306a36Sopenharmony_ci return d_real(file->f_path.dentry, file_inode(file)); 108162306a36Sopenharmony_ci} 108262306a36Sopenharmony_ci 108362306a36Sopenharmony_cistruct fasync_struct { 108462306a36Sopenharmony_ci rwlock_t fa_lock; 108562306a36Sopenharmony_ci int magic; 108662306a36Sopenharmony_ci int fa_fd; 108762306a36Sopenharmony_ci struct fasync_struct *fa_next; /* singly linked list */ 108862306a36Sopenharmony_ci struct file *fa_file; 108962306a36Sopenharmony_ci struct rcu_head fa_rcu; 109062306a36Sopenharmony_ci}; 109162306a36Sopenharmony_ci 109262306a36Sopenharmony_ci#define FASYNC_MAGIC 0x4601 109362306a36Sopenharmony_ci 109462306a36Sopenharmony_ci/* SMP safe fasync helpers: */ 109562306a36Sopenharmony_ciextern int fasync_helper(int, struct file *, int, struct fasync_struct **); 109662306a36Sopenharmony_ciextern struct fasync_struct *fasync_insert_entry(int, struct file *, struct fasync_struct **, struct fasync_struct *); 109762306a36Sopenharmony_ciextern int fasync_remove_entry(struct file *, struct fasync_struct **); 109862306a36Sopenharmony_ciextern struct fasync_struct *fasync_alloc(void); 109962306a36Sopenharmony_ciextern void fasync_free(struct fasync_struct *); 110062306a36Sopenharmony_ci 110162306a36Sopenharmony_ci/* can be called from interrupts */ 110262306a36Sopenharmony_ciextern void kill_fasync(struct fasync_struct **, int, int); 110362306a36Sopenharmony_ci 110462306a36Sopenharmony_ciextern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force); 110562306a36Sopenharmony_ciextern int f_setown(struct file *filp, int who, int force); 110662306a36Sopenharmony_ciextern void f_delown(struct file *filp); 110762306a36Sopenharmony_ciextern pid_t f_getown(struct file *filp); 110862306a36Sopenharmony_ciextern int send_sigurg(struct fown_struct *fown); 110962306a36Sopenharmony_ci 111062306a36Sopenharmony_ci/* 111162306a36Sopenharmony_ci * sb->s_flags. Note that these mirror the equivalent MS_* flags where 111262306a36Sopenharmony_ci * represented in both. 111362306a36Sopenharmony_ci */ 111462306a36Sopenharmony_ci#define SB_RDONLY BIT(0) /* Mount read-only */ 111562306a36Sopenharmony_ci#define SB_NOSUID BIT(1) /* Ignore suid and sgid bits */ 111662306a36Sopenharmony_ci#define SB_NODEV BIT(2) /* Disallow access to device special files */ 111762306a36Sopenharmony_ci#define SB_NOEXEC BIT(3) /* Disallow program execution */ 111862306a36Sopenharmony_ci#define SB_SYNCHRONOUS BIT(4) /* Writes are synced at once */ 111962306a36Sopenharmony_ci#define SB_MANDLOCK BIT(6) /* Allow mandatory locks on an FS */ 112062306a36Sopenharmony_ci#define SB_DIRSYNC BIT(7) /* Directory modifications are synchronous */ 112162306a36Sopenharmony_ci#define SB_NOATIME BIT(10) /* Do not update access times. */ 112262306a36Sopenharmony_ci#define SB_NODIRATIME BIT(11) /* Do not update directory access times */ 112362306a36Sopenharmony_ci#define SB_SILENT BIT(15) 112462306a36Sopenharmony_ci#define SB_POSIXACL BIT(16) /* VFS does not apply the umask */ 112562306a36Sopenharmony_ci#define SB_INLINECRYPT BIT(17) /* Use blk-crypto for encrypted files */ 112662306a36Sopenharmony_ci#define SB_KERNMOUNT BIT(22) /* this is a kern_mount call */ 112762306a36Sopenharmony_ci#define SB_I_VERSION BIT(23) /* Update inode I_version field */ 112862306a36Sopenharmony_ci#define SB_LAZYTIME BIT(25) /* Update the on-disk [acm]times lazily */ 112962306a36Sopenharmony_ci 113062306a36Sopenharmony_ci/* These sb flags are internal to the kernel */ 113162306a36Sopenharmony_ci#define SB_DEAD BIT(21) 113262306a36Sopenharmony_ci#define SB_DYING BIT(24) 113362306a36Sopenharmony_ci#define SB_SUBMOUNT BIT(26) 113462306a36Sopenharmony_ci#define SB_FORCE BIT(27) 113562306a36Sopenharmony_ci#define SB_NOSEC BIT(28) 113662306a36Sopenharmony_ci#define SB_BORN BIT(29) 113762306a36Sopenharmony_ci#define SB_ACTIVE BIT(30) 113862306a36Sopenharmony_ci#define SB_NOUSER BIT(31) 113962306a36Sopenharmony_ci 114062306a36Sopenharmony_ci/* These flags relate to encoding and casefolding */ 114162306a36Sopenharmony_ci#define SB_ENC_STRICT_MODE_FL (1 << 0) 114262306a36Sopenharmony_ci 114362306a36Sopenharmony_ci#define sb_has_strict_encoding(sb) \ 114462306a36Sopenharmony_ci (sb->s_encoding_flags & SB_ENC_STRICT_MODE_FL) 114562306a36Sopenharmony_ci 114662306a36Sopenharmony_ci/* 114762306a36Sopenharmony_ci * Umount options 114862306a36Sopenharmony_ci */ 114962306a36Sopenharmony_ci 115062306a36Sopenharmony_ci#define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */ 115162306a36Sopenharmony_ci#define MNT_DETACH 0x00000002 /* Just detach from the tree */ 115262306a36Sopenharmony_ci#define MNT_EXPIRE 0x00000004 /* Mark for expiry */ 115362306a36Sopenharmony_ci#define UMOUNT_NOFOLLOW 0x00000008 /* Don't follow symlink on umount */ 115462306a36Sopenharmony_ci#define UMOUNT_UNUSED 0x80000000 /* Flag guaranteed to be unused */ 115562306a36Sopenharmony_ci 115662306a36Sopenharmony_ci/* sb->s_iflags */ 115762306a36Sopenharmony_ci#define SB_I_CGROUPWB 0x00000001 /* cgroup-aware writeback enabled */ 115862306a36Sopenharmony_ci#define SB_I_NOEXEC 0x00000002 /* Ignore executables on this fs */ 115962306a36Sopenharmony_ci#define SB_I_NODEV 0x00000004 /* Ignore devices on this fs */ 116062306a36Sopenharmony_ci#define SB_I_STABLE_WRITES 0x00000008 /* don't modify blks until WB is done */ 116162306a36Sopenharmony_ci 116262306a36Sopenharmony_ci/* sb->s_iflags to limit user namespace mounts */ 116362306a36Sopenharmony_ci#define SB_I_USERNS_VISIBLE 0x00000010 /* fstype already mounted */ 116462306a36Sopenharmony_ci#define SB_I_IMA_UNVERIFIABLE_SIGNATURE 0x00000020 116562306a36Sopenharmony_ci#define SB_I_UNTRUSTED_MOUNTER 0x00000040 116662306a36Sopenharmony_ci 116762306a36Sopenharmony_ci#define SB_I_SKIP_SYNC 0x00000100 /* Skip superblock at global sync */ 116862306a36Sopenharmony_ci#define SB_I_PERSB_BDI 0x00000200 /* has a per-sb bdi */ 116962306a36Sopenharmony_ci#define SB_I_TS_EXPIRY_WARNED 0x00000400 /* warned about timestamp range expiry */ 117062306a36Sopenharmony_ci#define SB_I_RETIRED 0x00000800 /* superblock shouldn't be reused */ 117162306a36Sopenharmony_ci 117262306a36Sopenharmony_ci/* Possible states of 'frozen' field */ 117362306a36Sopenharmony_cienum { 117462306a36Sopenharmony_ci SB_UNFROZEN = 0, /* FS is unfrozen */ 117562306a36Sopenharmony_ci SB_FREEZE_WRITE = 1, /* Writes, dir ops, ioctls frozen */ 117662306a36Sopenharmony_ci SB_FREEZE_PAGEFAULT = 2, /* Page faults stopped as well */ 117762306a36Sopenharmony_ci SB_FREEZE_FS = 3, /* For internal FS use (e.g. to stop 117862306a36Sopenharmony_ci * internal threads if needed) */ 117962306a36Sopenharmony_ci SB_FREEZE_COMPLETE = 4, /* ->freeze_fs finished successfully */ 118062306a36Sopenharmony_ci}; 118162306a36Sopenharmony_ci 118262306a36Sopenharmony_ci#define SB_FREEZE_LEVELS (SB_FREEZE_COMPLETE - 1) 118362306a36Sopenharmony_ci 118462306a36Sopenharmony_cistruct sb_writers { 118562306a36Sopenharmony_ci unsigned short frozen; /* Is sb frozen? */ 118662306a36Sopenharmony_ci unsigned short freeze_holders; /* Who froze fs? */ 118762306a36Sopenharmony_ci struct percpu_rw_semaphore rw_sem[SB_FREEZE_LEVELS]; 118862306a36Sopenharmony_ci}; 118962306a36Sopenharmony_ci 119062306a36Sopenharmony_cistruct super_block { 119162306a36Sopenharmony_ci struct list_head s_list; /* Keep this first */ 119262306a36Sopenharmony_ci dev_t s_dev; /* search index; _not_ kdev_t */ 119362306a36Sopenharmony_ci unsigned char s_blocksize_bits; 119462306a36Sopenharmony_ci unsigned long s_blocksize; 119562306a36Sopenharmony_ci loff_t s_maxbytes; /* Max file size */ 119662306a36Sopenharmony_ci struct file_system_type *s_type; 119762306a36Sopenharmony_ci const struct super_operations *s_op; 119862306a36Sopenharmony_ci const struct dquot_operations *dq_op; 119962306a36Sopenharmony_ci const struct quotactl_ops *s_qcop; 120062306a36Sopenharmony_ci const struct export_operations *s_export_op; 120162306a36Sopenharmony_ci unsigned long s_flags; 120262306a36Sopenharmony_ci unsigned long s_iflags; /* internal SB_I_* flags */ 120362306a36Sopenharmony_ci unsigned long s_magic; 120462306a36Sopenharmony_ci struct dentry *s_root; 120562306a36Sopenharmony_ci struct rw_semaphore s_umount; 120662306a36Sopenharmony_ci int s_count; 120762306a36Sopenharmony_ci atomic_t s_active; 120862306a36Sopenharmony_ci#ifdef CONFIG_SECURITY 120962306a36Sopenharmony_ci void *s_security; 121062306a36Sopenharmony_ci#endif 121162306a36Sopenharmony_ci const struct xattr_handler **s_xattr; 121262306a36Sopenharmony_ci#ifdef CONFIG_FS_ENCRYPTION 121362306a36Sopenharmony_ci const struct fscrypt_operations *s_cop; 121462306a36Sopenharmony_ci struct fscrypt_keyring *s_master_keys; /* master crypto keys in use */ 121562306a36Sopenharmony_ci#endif 121662306a36Sopenharmony_ci#ifdef CONFIG_FS_VERITY 121762306a36Sopenharmony_ci const struct fsverity_operations *s_vop; 121862306a36Sopenharmony_ci#endif 121962306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_UNICODE) 122062306a36Sopenharmony_ci struct unicode_map *s_encoding; 122162306a36Sopenharmony_ci __u16 s_encoding_flags; 122262306a36Sopenharmony_ci#endif 122362306a36Sopenharmony_ci struct hlist_bl_head s_roots; /* alternate root dentries for NFS */ 122462306a36Sopenharmony_ci struct list_head s_mounts; /* list of mounts; _not_ for fs use */ 122562306a36Sopenharmony_ci struct block_device *s_bdev; 122662306a36Sopenharmony_ci struct backing_dev_info *s_bdi; 122762306a36Sopenharmony_ci struct mtd_info *s_mtd; 122862306a36Sopenharmony_ci struct hlist_node s_instances; 122962306a36Sopenharmony_ci unsigned int s_quota_types; /* Bitmask of supported quota types */ 123062306a36Sopenharmony_ci struct quota_info s_dquot; /* Diskquota specific options */ 123162306a36Sopenharmony_ci 123262306a36Sopenharmony_ci struct sb_writers s_writers; 123362306a36Sopenharmony_ci 123462306a36Sopenharmony_ci /* 123562306a36Sopenharmony_ci * Keep s_fs_info, s_time_gran, s_fsnotify_mask, and 123662306a36Sopenharmony_ci * s_fsnotify_marks together for cache efficiency. They are frequently 123762306a36Sopenharmony_ci * accessed and rarely modified. 123862306a36Sopenharmony_ci */ 123962306a36Sopenharmony_ci void *s_fs_info; /* Filesystem private info */ 124062306a36Sopenharmony_ci 124162306a36Sopenharmony_ci /* Granularity of c/m/atime in ns (cannot be worse than a second) */ 124262306a36Sopenharmony_ci u32 s_time_gran; 124362306a36Sopenharmony_ci /* Time limits for c/m/atime in seconds */ 124462306a36Sopenharmony_ci time64_t s_time_min; 124562306a36Sopenharmony_ci time64_t s_time_max; 124662306a36Sopenharmony_ci#ifdef CONFIG_FSNOTIFY 124762306a36Sopenharmony_ci __u32 s_fsnotify_mask; 124862306a36Sopenharmony_ci struct fsnotify_mark_connector __rcu *s_fsnotify_marks; 124962306a36Sopenharmony_ci#endif 125062306a36Sopenharmony_ci 125162306a36Sopenharmony_ci char s_id[32]; /* Informational name */ 125262306a36Sopenharmony_ci uuid_t s_uuid; /* UUID */ 125362306a36Sopenharmony_ci 125462306a36Sopenharmony_ci unsigned int s_max_links; 125562306a36Sopenharmony_ci 125662306a36Sopenharmony_ci /* 125762306a36Sopenharmony_ci * The next field is for VFS *only*. No filesystems have any business 125862306a36Sopenharmony_ci * even looking at it. You had been warned. 125962306a36Sopenharmony_ci */ 126062306a36Sopenharmony_ci struct mutex s_vfs_rename_mutex; /* Kludge */ 126162306a36Sopenharmony_ci 126262306a36Sopenharmony_ci /* 126362306a36Sopenharmony_ci * Filesystem subtype. If non-empty the filesystem type field 126462306a36Sopenharmony_ci * in /proc/mounts will be "type.subtype" 126562306a36Sopenharmony_ci */ 126662306a36Sopenharmony_ci const char *s_subtype; 126762306a36Sopenharmony_ci 126862306a36Sopenharmony_ci const struct dentry_operations *s_d_op; /* default d_op for dentries */ 126962306a36Sopenharmony_ci 127062306a36Sopenharmony_ci struct shrinker s_shrink; /* per-sb shrinker handle */ 127162306a36Sopenharmony_ci 127262306a36Sopenharmony_ci /* Number of inodes with nlink == 0 but still referenced */ 127362306a36Sopenharmony_ci atomic_long_t s_remove_count; 127462306a36Sopenharmony_ci 127562306a36Sopenharmony_ci /* 127662306a36Sopenharmony_ci * Number of inode/mount/sb objects that are being watched, note that 127762306a36Sopenharmony_ci * inodes objects are currently double-accounted. 127862306a36Sopenharmony_ci */ 127962306a36Sopenharmony_ci atomic_long_t s_fsnotify_connectors; 128062306a36Sopenharmony_ci 128162306a36Sopenharmony_ci /* Read-only state of the superblock is being changed */ 128262306a36Sopenharmony_ci int s_readonly_remount; 128362306a36Sopenharmony_ci 128462306a36Sopenharmony_ci /* per-sb errseq_t for reporting writeback errors via syncfs */ 128562306a36Sopenharmony_ci errseq_t s_wb_err; 128662306a36Sopenharmony_ci 128762306a36Sopenharmony_ci /* AIO completions deferred from interrupt context */ 128862306a36Sopenharmony_ci struct workqueue_struct *s_dio_done_wq; 128962306a36Sopenharmony_ci struct hlist_head s_pins; 129062306a36Sopenharmony_ci 129162306a36Sopenharmony_ci /* 129262306a36Sopenharmony_ci * Owning user namespace and default context in which to 129362306a36Sopenharmony_ci * interpret filesystem uids, gids, quotas, device nodes, 129462306a36Sopenharmony_ci * xattrs and security labels. 129562306a36Sopenharmony_ci */ 129662306a36Sopenharmony_ci struct user_namespace *s_user_ns; 129762306a36Sopenharmony_ci 129862306a36Sopenharmony_ci /* 129962306a36Sopenharmony_ci * The list_lru structure is essentially just a pointer to a table 130062306a36Sopenharmony_ci * of per-node lru lists, each of which has its own spinlock. 130162306a36Sopenharmony_ci * There is no need to put them into separate cachelines. 130262306a36Sopenharmony_ci */ 130362306a36Sopenharmony_ci struct list_lru s_dentry_lru; 130462306a36Sopenharmony_ci struct list_lru s_inode_lru; 130562306a36Sopenharmony_ci struct rcu_head rcu; 130662306a36Sopenharmony_ci struct work_struct destroy_work; 130762306a36Sopenharmony_ci 130862306a36Sopenharmony_ci struct mutex s_sync_lock; /* sync serialisation lock */ 130962306a36Sopenharmony_ci 131062306a36Sopenharmony_ci /* 131162306a36Sopenharmony_ci * Indicates how deep in a filesystem stack this SB is 131262306a36Sopenharmony_ci */ 131362306a36Sopenharmony_ci int s_stack_depth; 131462306a36Sopenharmony_ci 131562306a36Sopenharmony_ci /* s_inode_list_lock protects s_inodes */ 131662306a36Sopenharmony_ci spinlock_t s_inode_list_lock ____cacheline_aligned_in_smp; 131762306a36Sopenharmony_ci struct list_head s_inodes; /* all inodes */ 131862306a36Sopenharmony_ci 131962306a36Sopenharmony_ci spinlock_t s_inode_wblist_lock; 132062306a36Sopenharmony_ci struct list_head s_inodes_wb; /* writeback inodes */ 132162306a36Sopenharmony_ci} __randomize_layout; 132262306a36Sopenharmony_ci 132362306a36Sopenharmony_cistatic inline struct user_namespace *i_user_ns(const struct inode *inode) 132462306a36Sopenharmony_ci{ 132562306a36Sopenharmony_ci return inode->i_sb->s_user_ns; 132662306a36Sopenharmony_ci} 132762306a36Sopenharmony_ci 132862306a36Sopenharmony_ci/* Helper functions so that in most cases filesystems will 132962306a36Sopenharmony_ci * not need to deal directly with kuid_t and kgid_t and can 133062306a36Sopenharmony_ci * instead deal with the raw numeric values that are stored 133162306a36Sopenharmony_ci * in the filesystem. 133262306a36Sopenharmony_ci */ 133362306a36Sopenharmony_cistatic inline uid_t i_uid_read(const struct inode *inode) 133462306a36Sopenharmony_ci{ 133562306a36Sopenharmony_ci return from_kuid(i_user_ns(inode), inode->i_uid); 133662306a36Sopenharmony_ci} 133762306a36Sopenharmony_ci 133862306a36Sopenharmony_cistatic inline gid_t i_gid_read(const struct inode *inode) 133962306a36Sopenharmony_ci{ 134062306a36Sopenharmony_ci return from_kgid(i_user_ns(inode), inode->i_gid); 134162306a36Sopenharmony_ci} 134262306a36Sopenharmony_ci 134362306a36Sopenharmony_cistatic inline void i_uid_write(struct inode *inode, uid_t uid) 134462306a36Sopenharmony_ci{ 134562306a36Sopenharmony_ci inode->i_uid = make_kuid(i_user_ns(inode), uid); 134662306a36Sopenharmony_ci} 134762306a36Sopenharmony_ci 134862306a36Sopenharmony_cistatic inline void i_gid_write(struct inode *inode, gid_t gid) 134962306a36Sopenharmony_ci{ 135062306a36Sopenharmony_ci inode->i_gid = make_kgid(i_user_ns(inode), gid); 135162306a36Sopenharmony_ci} 135262306a36Sopenharmony_ci 135362306a36Sopenharmony_ci/** 135462306a36Sopenharmony_ci * i_uid_into_vfsuid - map an inode's i_uid down according to an idmapping 135562306a36Sopenharmony_ci * @idmap: idmap of the mount the inode was found from 135662306a36Sopenharmony_ci * @inode: inode to map 135762306a36Sopenharmony_ci * 135862306a36Sopenharmony_ci * Return: whe inode's i_uid mapped down according to @idmap. 135962306a36Sopenharmony_ci * If the inode's i_uid has no mapping INVALID_VFSUID is returned. 136062306a36Sopenharmony_ci */ 136162306a36Sopenharmony_cistatic inline vfsuid_t i_uid_into_vfsuid(struct mnt_idmap *idmap, 136262306a36Sopenharmony_ci const struct inode *inode) 136362306a36Sopenharmony_ci{ 136462306a36Sopenharmony_ci return make_vfsuid(idmap, i_user_ns(inode), inode->i_uid); 136562306a36Sopenharmony_ci} 136662306a36Sopenharmony_ci 136762306a36Sopenharmony_ci/** 136862306a36Sopenharmony_ci * i_uid_needs_update - check whether inode's i_uid needs to be updated 136962306a36Sopenharmony_ci * @idmap: idmap of the mount the inode was found from 137062306a36Sopenharmony_ci * @attr: the new attributes of @inode 137162306a36Sopenharmony_ci * @inode: the inode to update 137262306a36Sopenharmony_ci * 137362306a36Sopenharmony_ci * Check whether the $inode's i_uid field needs to be updated taking idmapped 137462306a36Sopenharmony_ci * mounts into account if the filesystem supports it. 137562306a36Sopenharmony_ci * 137662306a36Sopenharmony_ci * Return: true if @inode's i_uid field needs to be updated, false if not. 137762306a36Sopenharmony_ci */ 137862306a36Sopenharmony_cistatic inline bool i_uid_needs_update(struct mnt_idmap *idmap, 137962306a36Sopenharmony_ci const struct iattr *attr, 138062306a36Sopenharmony_ci const struct inode *inode) 138162306a36Sopenharmony_ci{ 138262306a36Sopenharmony_ci return ((attr->ia_valid & ATTR_UID) && 138362306a36Sopenharmony_ci !vfsuid_eq(attr->ia_vfsuid, 138462306a36Sopenharmony_ci i_uid_into_vfsuid(idmap, inode))); 138562306a36Sopenharmony_ci} 138662306a36Sopenharmony_ci 138762306a36Sopenharmony_ci/** 138862306a36Sopenharmony_ci * i_uid_update - update @inode's i_uid field 138962306a36Sopenharmony_ci * @idmap: idmap of the mount the inode was found from 139062306a36Sopenharmony_ci * @attr: the new attributes of @inode 139162306a36Sopenharmony_ci * @inode: the inode to update 139262306a36Sopenharmony_ci * 139362306a36Sopenharmony_ci * Safely update @inode's i_uid field translating the vfsuid of any idmapped 139462306a36Sopenharmony_ci * mount into the filesystem kuid. 139562306a36Sopenharmony_ci */ 139662306a36Sopenharmony_cistatic inline void i_uid_update(struct mnt_idmap *idmap, 139762306a36Sopenharmony_ci const struct iattr *attr, 139862306a36Sopenharmony_ci struct inode *inode) 139962306a36Sopenharmony_ci{ 140062306a36Sopenharmony_ci if (attr->ia_valid & ATTR_UID) 140162306a36Sopenharmony_ci inode->i_uid = from_vfsuid(idmap, i_user_ns(inode), 140262306a36Sopenharmony_ci attr->ia_vfsuid); 140362306a36Sopenharmony_ci} 140462306a36Sopenharmony_ci 140562306a36Sopenharmony_ci/** 140662306a36Sopenharmony_ci * i_gid_into_vfsgid - map an inode's i_gid down according to an idmapping 140762306a36Sopenharmony_ci * @idmap: idmap of the mount the inode was found from 140862306a36Sopenharmony_ci * @inode: inode to map 140962306a36Sopenharmony_ci * 141062306a36Sopenharmony_ci * Return: the inode's i_gid mapped down according to @idmap. 141162306a36Sopenharmony_ci * If the inode's i_gid has no mapping INVALID_VFSGID is returned. 141262306a36Sopenharmony_ci */ 141362306a36Sopenharmony_cistatic inline vfsgid_t i_gid_into_vfsgid(struct mnt_idmap *idmap, 141462306a36Sopenharmony_ci const struct inode *inode) 141562306a36Sopenharmony_ci{ 141662306a36Sopenharmony_ci return make_vfsgid(idmap, i_user_ns(inode), inode->i_gid); 141762306a36Sopenharmony_ci} 141862306a36Sopenharmony_ci 141962306a36Sopenharmony_ci/** 142062306a36Sopenharmony_ci * i_gid_needs_update - check whether inode's i_gid needs to be updated 142162306a36Sopenharmony_ci * @idmap: idmap of the mount the inode was found from 142262306a36Sopenharmony_ci * @attr: the new attributes of @inode 142362306a36Sopenharmony_ci * @inode: the inode to update 142462306a36Sopenharmony_ci * 142562306a36Sopenharmony_ci * Check whether the $inode's i_gid field needs to be updated taking idmapped 142662306a36Sopenharmony_ci * mounts into account if the filesystem supports it. 142762306a36Sopenharmony_ci * 142862306a36Sopenharmony_ci * Return: true if @inode's i_gid field needs to be updated, false if not. 142962306a36Sopenharmony_ci */ 143062306a36Sopenharmony_cistatic inline bool i_gid_needs_update(struct mnt_idmap *idmap, 143162306a36Sopenharmony_ci const struct iattr *attr, 143262306a36Sopenharmony_ci const struct inode *inode) 143362306a36Sopenharmony_ci{ 143462306a36Sopenharmony_ci return ((attr->ia_valid & ATTR_GID) && 143562306a36Sopenharmony_ci !vfsgid_eq(attr->ia_vfsgid, 143662306a36Sopenharmony_ci i_gid_into_vfsgid(idmap, inode))); 143762306a36Sopenharmony_ci} 143862306a36Sopenharmony_ci 143962306a36Sopenharmony_ci/** 144062306a36Sopenharmony_ci * i_gid_update - update @inode's i_gid field 144162306a36Sopenharmony_ci * @idmap: idmap of the mount the inode was found from 144262306a36Sopenharmony_ci * @attr: the new attributes of @inode 144362306a36Sopenharmony_ci * @inode: the inode to update 144462306a36Sopenharmony_ci * 144562306a36Sopenharmony_ci * Safely update @inode's i_gid field translating the vfsgid of any idmapped 144662306a36Sopenharmony_ci * mount into the filesystem kgid. 144762306a36Sopenharmony_ci */ 144862306a36Sopenharmony_cistatic inline void i_gid_update(struct mnt_idmap *idmap, 144962306a36Sopenharmony_ci const struct iattr *attr, 145062306a36Sopenharmony_ci struct inode *inode) 145162306a36Sopenharmony_ci{ 145262306a36Sopenharmony_ci if (attr->ia_valid & ATTR_GID) 145362306a36Sopenharmony_ci inode->i_gid = from_vfsgid(idmap, i_user_ns(inode), 145462306a36Sopenharmony_ci attr->ia_vfsgid); 145562306a36Sopenharmony_ci} 145662306a36Sopenharmony_ci 145762306a36Sopenharmony_ci/** 145862306a36Sopenharmony_ci * inode_fsuid_set - initialize inode's i_uid field with callers fsuid 145962306a36Sopenharmony_ci * @inode: inode to initialize 146062306a36Sopenharmony_ci * @idmap: idmap of the mount the inode was found from 146162306a36Sopenharmony_ci * 146262306a36Sopenharmony_ci * Initialize the i_uid field of @inode. If the inode was found/created via 146362306a36Sopenharmony_ci * an idmapped mount map the caller's fsuid according to @idmap. 146462306a36Sopenharmony_ci */ 146562306a36Sopenharmony_cistatic inline void inode_fsuid_set(struct inode *inode, 146662306a36Sopenharmony_ci struct mnt_idmap *idmap) 146762306a36Sopenharmony_ci{ 146862306a36Sopenharmony_ci inode->i_uid = mapped_fsuid(idmap, i_user_ns(inode)); 146962306a36Sopenharmony_ci} 147062306a36Sopenharmony_ci 147162306a36Sopenharmony_ci/** 147262306a36Sopenharmony_ci * inode_fsgid_set - initialize inode's i_gid field with callers fsgid 147362306a36Sopenharmony_ci * @inode: inode to initialize 147462306a36Sopenharmony_ci * @idmap: idmap of the mount the inode was found from 147562306a36Sopenharmony_ci * 147662306a36Sopenharmony_ci * Initialize the i_gid field of @inode. If the inode was found/created via 147762306a36Sopenharmony_ci * an idmapped mount map the caller's fsgid according to @idmap. 147862306a36Sopenharmony_ci */ 147962306a36Sopenharmony_cistatic inline void inode_fsgid_set(struct inode *inode, 148062306a36Sopenharmony_ci struct mnt_idmap *idmap) 148162306a36Sopenharmony_ci{ 148262306a36Sopenharmony_ci inode->i_gid = mapped_fsgid(idmap, i_user_ns(inode)); 148362306a36Sopenharmony_ci} 148462306a36Sopenharmony_ci 148562306a36Sopenharmony_ci/** 148662306a36Sopenharmony_ci * fsuidgid_has_mapping() - check whether caller's fsuid/fsgid is mapped 148762306a36Sopenharmony_ci * @sb: the superblock we want a mapping in 148862306a36Sopenharmony_ci * @idmap: idmap of the relevant mount 148962306a36Sopenharmony_ci * 149062306a36Sopenharmony_ci * Check whether the caller's fsuid and fsgid have a valid mapping in the 149162306a36Sopenharmony_ci * s_user_ns of the superblock @sb. If the caller is on an idmapped mount map 149262306a36Sopenharmony_ci * the caller's fsuid and fsgid according to the @idmap first. 149362306a36Sopenharmony_ci * 149462306a36Sopenharmony_ci * Return: true if fsuid and fsgid is mapped, false if not. 149562306a36Sopenharmony_ci */ 149662306a36Sopenharmony_cistatic inline bool fsuidgid_has_mapping(struct super_block *sb, 149762306a36Sopenharmony_ci struct mnt_idmap *idmap) 149862306a36Sopenharmony_ci{ 149962306a36Sopenharmony_ci struct user_namespace *fs_userns = sb->s_user_ns; 150062306a36Sopenharmony_ci kuid_t kuid; 150162306a36Sopenharmony_ci kgid_t kgid; 150262306a36Sopenharmony_ci 150362306a36Sopenharmony_ci kuid = mapped_fsuid(idmap, fs_userns); 150462306a36Sopenharmony_ci if (!uid_valid(kuid)) 150562306a36Sopenharmony_ci return false; 150662306a36Sopenharmony_ci kgid = mapped_fsgid(idmap, fs_userns); 150762306a36Sopenharmony_ci if (!gid_valid(kgid)) 150862306a36Sopenharmony_ci return false; 150962306a36Sopenharmony_ci return kuid_has_mapping(fs_userns, kuid) && 151062306a36Sopenharmony_ci kgid_has_mapping(fs_userns, kgid); 151162306a36Sopenharmony_ci} 151262306a36Sopenharmony_ci 151362306a36Sopenharmony_cistruct timespec64 current_time(struct inode *inode); 151462306a36Sopenharmony_cistruct timespec64 inode_set_ctime_current(struct inode *inode); 151562306a36Sopenharmony_ci 151662306a36Sopenharmony_cistatic inline time64_t inode_get_atime_sec(const struct inode *inode) 151762306a36Sopenharmony_ci{ 151862306a36Sopenharmony_ci return inode->i_atime.tv_sec; 151962306a36Sopenharmony_ci} 152062306a36Sopenharmony_ci 152162306a36Sopenharmony_cistatic inline long inode_get_atime_nsec(const struct inode *inode) 152262306a36Sopenharmony_ci{ 152362306a36Sopenharmony_ci return inode->i_atime.tv_nsec; 152462306a36Sopenharmony_ci} 152562306a36Sopenharmony_ci 152662306a36Sopenharmony_cistatic inline struct timespec64 inode_get_atime(const struct inode *inode) 152762306a36Sopenharmony_ci{ 152862306a36Sopenharmony_ci return inode->i_atime; 152962306a36Sopenharmony_ci} 153062306a36Sopenharmony_ci 153162306a36Sopenharmony_cistatic inline struct timespec64 inode_set_atime_to_ts(struct inode *inode, 153262306a36Sopenharmony_ci struct timespec64 ts) 153362306a36Sopenharmony_ci{ 153462306a36Sopenharmony_ci inode->i_atime = ts; 153562306a36Sopenharmony_ci return ts; 153662306a36Sopenharmony_ci} 153762306a36Sopenharmony_ci 153862306a36Sopenharmony_cistatic inline struct timespec64 inode_set_atime(struct inode *inode, 153962306a36Sopenharmony_ci time64_t sec, long nsec) 154062306a36Sopenharmony_ci{ 154162306a36Sopenharmony_ci struct timespec64 ts = { .tv_sec = sec, 154262306a36Sopenharmony_ci .tv_nsec = nsec }; 154362306a36Sopenharmony_ci return inode_set_atime_to_ts(inode, ts); 154462306a36Sopenharmony_ci} 154562306a36Sopenharmony_ci 154662306a36Sopenharmony_cistatic inline time64_t inode_get_mtime_sec(const struct inode *inode) 154762306a36Sopenharmony_ci{ 154862306a36Sopenharmony_ci return inode->i_mtime.tv_sec; 154962306a36Sopenharmony_ci} 155062306a36Sopenharmony_ci 155162306a36Sopenharmony_cistatic inline long inode_get_mtime_nsec(const struct inode *inode) 155262306a36Sopenharmony_ci{ 155362306a36Sopenharmony_ci return inode->i_mtime.tv_nsec; 155462306a36Sopenharmony_ci} 155562306a36Sopenharmony_ci 155662306a36Sopenharmony_cistatic inline struct timespec64 inode_get_mtime(const struct inode *inode) 155762306a36Sopenharmony_ci{ 155862306a36Sopenharmony_ci return inode->i_mtime; 155962306a36Sopenharmony_ci} 156062306a36Sopenharmony_ci 156162306a36Sopenharmony_cistatic inline struct timespec64 inode_set_mtime_to_ts(struct inode *inode, 156262306a36Sopenharmony_ci struct timespec64 ts) 156362306a36Sopenharmony_ci{ 156462306a36Sopenharmony_ci inode->i_mtime = ts; 156562306a36Sopenharmony_ci return ts; 156662306a36Sopenharmony_ci} 156762306a36Sopenharmony_ci 156862306a36Sopenharmony_cistatic inline struct timespec64 inode_set_mtime(struct inode *inode, 156962306a36Sopenharmony_ci time64_t sec, long nsec) 157062306a36Sopenharmony_ci{ 157162306a36Sopenharmony_ci struct timespec64 ts = { .tv_sec = sec, 157262306a36Sopenharmony_ci .tv_nsec = nsec }; 157362306a36Sopenharmony_ci return inode_set_mtime_to_ts(inode, ts); 157462306a36Sopenharmony_ci} 157562306a36Sopenharmony_ci 157662306a36Sopenharmony_cistatic inline time64_t inode_get_ctime_sec(const struct inode *inode) 157762306a36Sopenharmony_ci{ 157862306a36Sopenharmony_ci return inode->__i_ctime.tv_sec; 157962306a36Sopenharmony_ci} 158062306a36Sopenharmony_ci 158162306a36Sopenharmony_cistatic inline long inode_get_ctime_nsec(const struct inode *inode) 158262306a36Sopenharmony_ci{ 158362306a36Sopenharmony_ci return inode->__i_ctime.tv_nsec; 158462306a36Sopenharmony_ci} 158562306a36Sopenharmony_ci 158662306a36Sopenharmony_cistatic inline struct timespec64 inode_get_ctime(const struct inode *inode) 158762306a36Sopenharmony_ci{ 158862306a36Sopenharmony_ci return inode->__i_ctime; 158962306a36Sopenharmony_ci} 159062306a36Sopenharmony_ci 159162306a36Sopenharmony_cistatic inline struct timespec64 inode_set_ctime_to_ts(struct inode *inode, 159262306a36Sopenharmony_ci struct timespec64 ts) 159362306a36Sopenharmony_ci{ 159462306a36Sopenharmony_ci inode->__i_ctime = ts; 159562306a36Sopenharmony_ci return ts; 159662306a36Sopenharmony_ci} 159762306a36Sopenharmony_ci 159862306a36Sopenharmony_ci/** 159962306a36Sopenharmony_ci * inode_set_ctime - set the ctime in the inode 160062306a36Sopenharmony_ci * @inode: inode in which to set the ctime 160162306a36Sopenharmony_ci * @sec: tv_sec value to set 160262306a36Sopenharmony_ci * @nsec: tv_nsec value to set 160362306a36Sopenharmony_ci * 160462306a36Sopenharmony_ci * Set the ctime in @inode to { @sec, @nsec } 160562306a36Sopenharmony_ci */ 160662306a36Sopenharmony_cistatic inline struct timespec64 inode_set_ctime(struct inode *inode, 160762306a36Sopenharmony_ci time64_t sec, long nsec) 160862306a36Sopenharmony_ci{ 160962306a36Sopenharmony_ci struct timespec64 ts = { .tv_sec = sec, 161062306a36Sopenharmony_ci .tv_nsec = nsec }; 161162306a36Sopenharmony_ci 161262306a36Sopenharmony_ci return inode_set_ctime_to_ts(inode, ts); 161362306a36Sopenharmony_ci} 161462306a36Sopenharmony_ci 161562306a36Sopenharmony_cistruct timespec64 simple_inode_init_ts(struct inode *inode); 161662306a36Sopenharmony_ci 161762306a36Sopenharmony_ci/* 161862306a36Sopenharmony_ci * Snapshotting support. 161962306a36Sopenharmony_ci */ 162062306a36Sopenharmony_ci 162162306a36Sopenharmony_ci/* 162262306a36Sopenharmony_ci * These are internal functions, please use sb_start_{write,pagefault,intwrite} 162362306a36Sopenharmony_ci * instead. 162462306a36Sopenharmony_ci */ 162562306a36Sopenharmony_cistatic inline void __sb_end_write(struct super_block *sb, int level) 162662306a36Sopenharmony_ci{ 162762306a36Sopenharmony_ci percpu_up_read(sb->s_writers.rw_sem + level-1); 162862306a36Sopenharmony_ci} 162962306a36Sopenharmony_ci 163062306a36Sopenharmony_cistatic inline void __sb_start_write(struct super_block *sb, int level) 163162306a36Sopenharmony_ci{ 163262306a36Sopenharmony_ci percpu_down_read(sb->s_writers.rw_sem + level - 1); 163362306a36Sopenharmony_ci} 163462306a36Sopenharmony_ci 163562306a36Sopenharmony_cistatic inline bool __sb_start_write_trylock(struct super_block *sb, int level) 163662306a36Sopenharmony_ci{ 163762306a36Sopenharmony_ci return percpu_down_read_trylock(sb->s_writers.rw_sem + level - 1); 163862306a36Sopenharmony_ci} 163962306a36Sopenharmony_ci 164062306a36Sopenharmony_ci#define __sb_writers_acquired(sb, lev) \ 164162306a36Sopenharmony_ci percpu_rwsem_acquire(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_) 164262306a36Sopenharmony_ci#define __sb_writers_release(sb, lev) \ 164362306a36Sopenharmony_ci percpu_rwsem_release(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_) 164462306a36Sopenharmony_ci 164562306a36Sopenharmony_cistatic inline bool sb_write_started(const struct super_block *sb) 164662306a36Sopenharmony_ci{ 164762306a36Sopenharmony_ci return lockdep_is_held_type(sb->s_writers.rw_sem + SB_FREEZE_WRITE - 1, 1); 164862306a36Sopenharmony_ci} 164962306a36Sopenharmony_ci 165062306a36Sopenharmony_ci/** 165162306a36Sopenharmony_ci * sb_end_write - drop write access to a superblock 165262306a36Sopenharmony_ci * @sb: the super we wrote to 165362306a36Sopenharmony_ci * 165462306a36Sopenharmony_ci * Decrement number of writers to the filesystem. Wake up possible waiters 165562306a36Sopenharmony_ci * wanting to freeze the filesystem. 165662306a36Sopenharmony_ci */ 165762306a36Sopenharmony_cistatic inline void sb_end_write(struct super_block *sb) 165862306a36Sopenharmony_ci{ 165962306a36Sopenharmony_ci __sb_end_write(sb, SB_FREEZE_WRITE); 166062306a36Sopenharmony_ci} 166162306a36Sopenharmony_ci 166262306a36Sopenharmony_ci/** 166362306a36Sopenharmony_ci * sb_end_pagefault - drop write access to a superblock from a page fault 166462306a36Sopenharmony_ci * @sb: the super we wrote to 166562306a36Sopenharmony_ci * 166662306a36Sopenharmony_ci * Decrement number of processes handling write page fault to the filesystem. 166762306a36Sopenharmony_ci * Wake up possible waiters wanting to freeze the filesystem. 166862306a36Sopenharmony_ci */ 166962306a36Sopenharmony_cistatic inline void sb_end_pagefault(struct super_block *sb) 167062306a36Sopenharmony_ci{ 167162306a36Sopenharmony_ci __sb_end_write(sb, SB_FREEZE_PAGEFAULT); 167262306a36Sopenharmony_ci} 167362306a36Sopenharmony_ci 167462306a36Sopenharmony_ci/** 167562306a36Sopenharmony_ci * sb_end_intwrite - drop write access to a superblock for internal fs purposes 167662306a36Sopenharmony_ci * @sb: the super we wrote to 167762306a36Sopenharmony_ci * 167862306a36Sopenharmony_ci * Decrement fs-internal number of writers to the filesystem. Wake up possible 167962306a36Sopenharmony_ci * waiters wanting to freeze the filesystem. 168062306a36Sopenharmony_ci */ 168162306a36Sopenharmony_cistatic inline void sb_end_intwrite(struct super_block *sb) 168262306a36Sopenharmony_ci{ 168362306a36Sopenharmony_ci __sb_end_write(sb, SB_FREEZE_FS); 168462306a36Sopenharmony_ci} 168562306a36Sopenharmony_ci 168662306a36Sopenharmony_ci/** 168762306a36Sopenharmony_ci * sb_start_write - get write access to a superblock 168862306a36Sopenharmony_ci * @sb: the super we write to 168962306a36Sopenharmony_ci * 169062306a36Sopenharmony_ci * When a process wants to write data or metadata to a file system (i.e. dirty 169162306a36Sopenharmony_ci * a page or an inode), it should embed the operation in a sb_start_write() - 169262306a36Sopenharmony_ci * sb_end_write() pair to get exclusion against file system freezing. This 169362306a36Sopenharmony_ci * function increments number of writers preventing freezing. If the file 169462306a36Sopenharmony_ci * system is already frozen, the function waits until the file system is 169562306a36Sopenharmony_ci * thawed. 169662306a36Sopenharmony_ci * 169762306a36Sopenharmony_ci * Since freeze protection behaves as a lock, users have to preserve 169862306a36Sopenharmony_ci * ordering of freeze protection and other filesystem locks. Generally, 169962306a36Sopenharmony_ci * freeze protection should be the outermost lock. In particular, we have: 170062306a36Sopenharmony_ci * 170162306a36Sopenharmony_ci * sb_start_write 170262306a36Sopenharmony_ci * -> i_mutex (write path, truncate, directory ops, ...) 170362306a36Sopenharmony_ci * -> s_umount (freeze_super, thaw_super) 170462306a36Sopenharmony_ci */ 170562306a36Sopenharmony_cistatic inline void sb_start_write(struct super_block *sb) 170662306a36Sopenharmony_ci{ 170762306a36Sopenharmony_ci __sb_start_write(sb, SB_FREEZE_WRITE); 170862306a36Sopenharmony_ci} 170962306a36Sopenharmony_ci 171062306a36Sopenharmony_cistatic inline bool sb_start_write_trylock(struct super_block *sb) 171162306a36Sopenharmony_ci{ 171262306a36Sopenharmony_ci return __sb_start_write_trylock(sb, SB_FREEZE_WRITE); 171362306a36Sopenharmony_ci} 171462306a36Sopenharmony_ci 171562306a36Sopenharmony_ci/** 171662306a36Sopenharmony_ci * sb_start_pagefault - get write access to a superblock from a page fault 171762306a36Sopenharmony_ci * @sb: the super we write to 171862306a36Sopenharmony_ci * 171962306a36Sopenharmony_ci * When a process starts handling write page fault, it should embed the 172062306a36Sopenharmony_ci * operation into sb_start_pagefault() - sb_end_pagefault() pair to get 172162306a36Sopenharmony_ci * exclusion against file system freezing. This is needed since the page fault 172262306a36Sopenharmony_ci * is going to dirty a page. This function increments number of running page 172362306a36Sopenharmony_ci * faults preventing freezing. If the file system is already frozen, the 172462306a36Sopenharmony_ci * function waits until the file system is thawed. 172562306a36Sopenharmony_ci * 172662306a36Sopenharmony_ci * Since page fault freeze protection behaves as a lock, users have to preserve 172762306a36Sopenharmony_ci * ordering of freeze protection and other filesystem locks. It is advised to 172862306a36Sopenharmony_ci * put sb_start_pagefault() close to mmap_lock in lock ordering. Page fault 172962306a36Sopenharmony_ci * handling code implies lock dependency: 173062306a36Sopenharmony_ci * 173162306a36Sopenharmony_ci * mmap_lock 173262306a36Sopenharmony_ci * -> sb_start_pagefault 173362306a36Sopenharmony_ci */ 173462306a36Sopenharmony_cistatic inline void sb_start_pagefault(struct super_block *sb) 173562306a36Sopenharmony_ci{ 173662306a36Sopenharmony_ci __sb_start_write(sb, SB_FREEZE_PAGEFAULT); 173762306a36Sopenharmony_ci} 173862306a36Sopenharmony_ci 173962306a36Sopenharmony_ci/** 174062306a36Sopenharmony_ci * sb_start_intwrite - get write access to a superblock for internal fs purposes 174162306a36Sopenharmony_ci * @sb: the super we write to 174262306a36Sopenharmony_ci * 174362306a36Sopenharmony_ci * This is the third level of protection against filesystem freezing. It is 174462306a36Sopenharmony_ci * free for use by a filesystem. The only requirement is that it must rank 174562306a36Sopenharmony_ci * below sb_start_pagefault. 174662306a36Sopenharmony_ci * 174762306a36Sopenharmony_ci * For example filesystem can call sb_start_intwrite() when starting a 174862306a36Sopenharmony_ci * transaction which somewhat eases handling of freezing for internal sources 174962306a36Sopenharmony_ci * of filesystem changes (internal fs threads, discarding preallocation on file 175062306a36Sopenharmony_ci * close, etc.). 175162306a36Sopenharmony_ci */ 175262306a36Sopenharmony_cistatic inline void sb_start_intwrite(struct super_block *sb) 175362306a36Sopenharmony_ci{ 175462306a36Sopenharmony_ci __sb_start_write(sb, SB_FREEZE_FS); 175562306a36Sopenharmony_ci} 175662306a36Sopenharmony_ci 175762306a36Sopenharmony_cistatic inline bool sb_start_intwrite_trylock(struct super_block *sb) 175862306a36Sopenharmony_ci{ 175962306a36Sopenharmony_ci return __sb_start_write_trylock(sb, SB_FREEZE_FS); 176062306a36Sopenharmony_ci} 176162306a36Sopenharmony_ci 176262306a36Sopenharmony_cibool inode_owner_or_capable(struct mnt_idmap *idmap, 176362306a36Sopenharmony_ci const struct inode *inode); 176462306a36Sopenharmony_ci 176562306a36Sopenharmony_ci/* 176662306a36Sopenharmony_ci * VFS helper functions.. 176762306a36Sopenharmony_ci */ 176862306a36Sopenharmony_ciint vfs_create(struct mnt_idmap *, struct inode *, 176962306a36Sopenharmony_ci struct dentry *, umode_t, bool); 177062306a36Sopenharmony_ciint vfs_mkdir(struct mnt_idmap *, struct inode *, 177162306a36Sopenharmony_ci struct dentry *, umode_t); 177262306a36Sopenharmony_ciint vfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *, 177362306a36Sopenharmony_ci umode_t, dev_t); 177462306a36Sopenharmony_ciint vfs_symlink(struct mnt_idmap *, struct inode *, 177562306a36Sopenharmony_ci struct dentry *, const char *); 177662306a36Sopenharmony_ciint vfs_link(struct dentry *, struct mnt_idmap *, struct inode *, 177762306a36Sopenharmony_ci struct dentry *, struct inode **); 177862306a36Sopenharmony_ciint vfs_rmdir(struct mnt_idmap *, struct inode *, struct dentry *); 177962306a36Sopenharmony_ciint vfs_unlink(struct mnt_idmap *, struct inode *, struct dentry *, 178062306a36Sopenharmony_ci struct inode **); 178162306a36Sopenharmony_ci 178262306a36Sopenharmony_ci/** 178362306a36Sopenharmony_ci * struct renamedata - contains all information required for renaming 178462306a36Sopenharmony_ci * @old_mnt_idmap: idmap of the old mount the inode was found from 178562306a36Sopenharmony_ci * @old_dir: parent of source 178662306a36Sopenharmony_ci * @old_dentry: source 178762306a36Sopenharmony_ci * @new_mnt_idmap: idmap of the new mount the inode was found from 178862306a36Sopenharmony_ci * @new_dir: parent of destination 178962306a36Sopenharmony_ci * @new_dentry: destination 179062306a36Sopenharmony_ci * @delegated_inode: returns an inode needing a delegation break 179162306a36Sopenharmony_ci * @flags: rename flags 179262306a36Sopenharmony_ci */ 179362306a36Sopenharmony_cistruct renamedata { 179462306a36Sopenharmony_ci struct mnt_idmap *old_mnt_idmap; 179562306a36Sopenharmony_ci struct inode *old_dir; 179662306a36Sopenharmony_ci struct dentry *old_dentry; 179762306a36Sopenharmony_ci struct mnt_idmap *new_mnt_idmap; 179862306a36Sopenharmony_ci struct inode *new_dir; 179962306a36Sopenharmony_ci struct dentry *new_dentry; 180062306a36Sopenharmony_ci struct inode **delegated_inode; 180162306a36Sopenharmony_ci unsigned int flags; 180262306a36Sopenharmony_ci} __randomize_layout; 180362306a36Sopenharmony_ci 180462306a36Sopenharmony_ciint vfs_rename(struct renamedata *); 180562306a36Sopenharmony_ci 180662306a36Sopenharmony_cistatic inline int vfs_whiteout(struct mnt_idmap *idmap, 180762306a36Sopenharmony_ci struct inode *dir, struct dentry *dentry) 180862306a36Sopenharmony_ci{ 180962306a36Sopenharmony_ci return vfs_mknod(idmap, dir, dentry, S_IFCHR | WHITEOUT_MODE, 181062306a36Sopenharmony_ci WHITEOUT_DEV); 181162306a36Sopenharmony_ci} 181262306a36Sopenharmony_ci 181362306a36Sopenharmony_cistruct file *kernel_tmpfile_open(struct mnt_idmap *idmap, 181462306a36Sopenharmony_ci const struct path *parentpath, 181562306a36Sopenharmony_ci umode_t mode, int open_flag, 181662306a36Sopenharmony_ci const struct cred *cred); 181762306a36Sopenharmony_cistruct file *kernel_file_open(const struct path *path, int flags, 181862306a36Sopenharmony_ci struct inode *inode, const struct cred *cred); 181962306a36Sopenharmony_ci 182062306a36Sopenharmony_ciint vfs_mkobj(struct dentry *, umode_t, 182162306a36Sopenharmony_ci int (*f)(struct dentry *, umode_t, void *), 182262306a36Sopenharmony_ci void *); 182362306a36Sopenharmony_ci 182462306a36Sopenharmony_ciint vfs_fchown(struct file *file, uid_t user, gid_t group); 182562306a36Sopenharmony_ciint vfs_fchmod(struct file *file, umode_t mode); 182662306a36Sopenharmony_ciint vfs_utimes(const struct path *path, struct timespec64 *times); 182762306a36Sopenharmony_ci 182862306a36Sopenharmony_ciextern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 182962306a36Sopenharmony_ci 183062306a36Sopenharmony_ci#ifdef CONFIG_COMPAT 183162306a36Sopenharmony_ciextern long compat_ptr_ioctl(struct file *file, unsigned int cmd, 183262306a36Sopenharmony_ci unsigned long arg); 183362306a36Sopenharmony_ci#else 183462306a36Sopenharmony_ci#define compat_ptr_ioctl NULL 183562306a36Sopenharmony_ci#endif 183662306a36Sopenharmony_ci 183762306a36Sopenharmony_ci/* 183862306a36Sopenharmony_ci * VFS file helper functions. 183962306a36Sopenharmony_ci */ 184062306a36Sopenharmony_civoid inode_init_owner(struct mnt_idmap *idmap, struct inode *inode, 184162306a36Sopenharmony_ci const struct inode *dir, umode_t mode); 184262306a36Sopenharmony_ciextern bool may_open_dev(const struct path *path); 184362306a36Sopenharmony_ciumode_t mode_strip_sgid(struct mnt_idmap *idmap, 184462306a36Sopenharmony_ci const struct inode *dir, umode_t mode); 184562306a36Sopenharmony_ci 184662306a36Sopenharmony_ci/* 184762306a36Sopenharmony_ci * This is the "filldir" function type, used by readdir() to let 184862306a36Sopenharmony_ci * the kernel specify what kind of dirent layout it wants to have. 184962306a36Sopenharmony_ci * This allows the kernel to read directories into kernel space or 185062306a36Sopenharmony_ci * to have different dirent layouts depending on the binary type. 185162306a36Sopenharmony_ci * Return 'true' to keep going and 'false' if there are no more entries. 185262306a36Sopenharmony_ci */ 185362306a36Sopenharmony_cistruct dir_context; 185462306a36Sopenharmony_citypedef bool (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64, 185562306a36Sopenharmony_ci unsigned); 185662306a36Sopenharmony_ci 185762306a36Sopenharmony_cistruct dir_context { 185862306a36Sopenharmony_ci filldir_t actor; 185962306a36Sopenharmony_ci loff_t pos; 186062306a36Sopenharmony_ci}; 186162306a36Sopenharmony_ci 186262306a36Sopenharmony_ci/* 186362306a36Sopenharmony_ci * These flags let !MMU mmap() govern direct device mapping vs immediate 186462306a36Sopenharmony_ci * copying more easily for MAP_PRIVATE, especially for ROM filesystems. 186562306a36Sopenharmony_ci * 186662306a36Sopenharmony_ci * NOMMU_MAP_COPY: Copy can be mapped (MAP_PRIVATE) 186762306a36Sopenharmony_ci * NOMMU_MAP_DIRECT: Can be mapped directly (MAP_SHARED) 186862306a36Sopenharmony_ci * NOMMU_MAP_READ: Can be mapped for reading 186962306a36Sopenharmony_ci * NOMMU_MAP_WRITE: Can be mapped for writing 187062306a36Sopenharmony_ci * NOMMU_MAP_EXEC: Can be mapped for execution 187162306a36Sopenharmony_ci */ 187262306a36Sopenharmony_ci#define NOMMU_MAP_COPY 0x00000001 187362306a36Sopenharmony_ci#define NOMMU_MAP_DIRECT 0x00000008 187462306a36Sopenharmony_ci#define NOMMU_MAP_READ VM_MAYREAD 187562306a36Sopenharmony_ci#define NOMMU_MAP_WRITE VM_MAYWRITE 187662306a36Sopenharmony_ci#define NOMMU_MAP_EXEC VM_MAYEXEC 187762306a36Sopenharmony_ci 187862306a36Sopenharmony_ci#define NOMMU_VMFLAGS \ 187962306a36Sopenharmony_ci (NOMMU_MAP_READ | NOMMU_MAP_WRITE | NOMMU_MAP_EXEC) 188062306a36Sopenharmony_ci 188162306a36Sopenharmony_ci/* 188262306a36Sopenharmony_ci * These flags control the behavior of the remap_file_range function pointer. 188362306a36Sopenharmony_ci * If it is called with len == 0 that means "remap to end of source file". 188462306a36Sopenharmony_ci * See Documentation/filesystems/vfs.rst for more details about this call. 188562306a36Sopenharmony_ci * 188662306a36Sopenharmony_ci * REMAP_FILE_DEDUP: only remap if contents identical (i.e. deduplicate) 188762306a36Sopenharmony_ci * REMAP_FILE_CAN_SHORTEN: caller can handle a shortened request 188862306a36Sopenharmony_ci */ 188962306a36Sopenharmony_ci#define REMAP_FILE_DEDUP (1 << 0) 189062306a36Sopenharmony_ci#define REMAP_FILE_CAN_SHORTEN (1 << 1) 189162306a36Sopenharmony_ci 189262306a36Sopenharmony_ci/* 189362306a36Sopenharmony_ci * These flags signal that the caller is ok with altering various aspects of 189462306a36Sopenharmony_ci * the behavior of the remap operation. The changes must be made by the 189562306a36Sopenharmony_ci * implementation; the vfs remap helper functions can take advantage of them. 189662306a36Sopenharmony_ci * Flags in this category exist to preserve the quirky behavior of the hoisted 189762306a36Sopenharmony_ci * btrfs clone/dedupe ioctls. 189862306a36Sopenharmony_ci */ 189962306a36Sopenharmony_ci#define REMAP_FILE_ADVISORY (REMAP_FILE_CAN_SHORTEN) 190062306a36Sopenharmony_ci 190162306a36Sopenharmony_ci/* 190262306a36Sopenharmony_ci * These flags control the behavior of vfs_copy_file_range(). 190362306a36Sopenharmony_ci * They are not available to the user via syscall. 190462306a36Sopenharmony_ci * 190562306a36Sopenharmony_ci * COPY_FILE_SPLICE: call splice direct instead of fs clone/copy ops 190662306a36Sopenharmony_ci */ 190762306a36Sopenharmony_ci#define COPY_FILE_SPLICE (1 << 0) 190862306a36Sopenharmony_ci 190962306a36Sopenharmony_cistruct iov_iter; 191062306a36Sopenharmony_cistruct io_uring_cmd; 191162306a36Sopenharmony_cistruct offset_ctx; 191262306a36Sopenharmony_ci 191362306a36Sopenharmony_cistruct file_operations { 191462306a36Sopenharmony_ci struct module *owner; 191562306a36Sopenharmony_ci loff_t (*llseek) (struct file *, loff_t, int); 191662306a36Sopenharmony_ci ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); 191762306a36Sopenharmony_ci ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); 191862306a36Sopenharmony_ci ssize_t (*read_iter) (struct kiocb *, struct iov_iter *); 191962306a36Sopenharmony_ci ssize_t (*write_iter) (struct kiocb *, struct iov_iter *); 192062306a36Sopenharmony_ci int (*iopoll)(struct kiocb *kiocb, struct io_comp_batch *, 192162306a36Sopenharmony_ci unsigned int flags); 192262306a36Sopenharmony_ci int (*iterate_shared) (struct file *, struct dir_context *); 192362306a36Sopenharmony_ci __poll_t (*poll) (struct file *, struct poll_table_struct *); 192462306a36Sopenharmony_ci long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); 192562306a36Sopenharmony_ci long (*compat_ioctl) (struct file *, unsigned int, unsigned long); 192662306a36Sopenharmony_ci int (*mmap) (struct file *, struct vm_area_struct *); 192762306a36Sopenharmony_ci unsigned long mmap_supported_flags; 192862306a36Sopenharmony_ci int (*open) (struct inode *, struct file *); 192962306a36Sopenharmony_ci int (*flush) (struct file *, fl_owner_t id); 193062306a36Sopenharmony_ci int (*release) (struct inode *, struct file *); 193162306a36Sopenharmony_ci int (*fsync) (struct file *, loff_t, loff_t, int datasync); 193262306a36Sopenharmony_ci int (*fasync) (int, struct file *, int); 193362306a36Sopenharmony_ci int (*lock) (struct file *, int, struct file_lock *); 193462306a36Sopenharmony_ci unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); 193562306a36Sopenharmony_ci int (*check_flags)(int); 193662306a36Sopenharmony_ci int (*flock) (struct file *, int, struct file_lock *); 193762306a36Sopenharmony_ci ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); 193862306a36Sopenharmony_ci ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); 193962306a36Sopenharmony_ci void (*splice_eof)(struct file *file); 194062306a36Sopenharmony_ci int (*setlease)(struct file *, int, struct file_lock **, void **); 194162306a36Sopenharmony_ci long (*fallocate)(struct file *file, int mode, loff_t offset, 194262306a36Sopenharmony_ci loff_t len); 194362306a36Sopenharmony_ci void (*show_fdinfo)(struct seq_file *m, struct file *f); 194462306a36Sopenharmony_ci#ifndef CONFIG_MMU 194562306a36Sopenharmony_ci unsigned (*mmap_capabilities)(struct file *); 194662306a36Sopenharmony_ci#endif 194762306a36Sopenharmony_ci ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, 194862306a36Sopenharmony_ci loff_t, size_t, unsigned int); 194962306a36Sopenharmony_ci loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in, 195062306a36Sopenharmony_ci struct file *file_out, loff_t pos_out, 195162306a36Sopenharmony_ci loff_t len, unsigned int remap_flags); 195262306a36Sopenharmony_ci int (*fadvise)(struct file *, loff_t, loff_t, int); 195362306a36Sopenharmony_ci int (*uring_cmd)(struct io_uring_cmd *ioucmd, unsigned int issue_flags); 195462306a36Sopenharmony_ci int (*uring_cmd_iopoll)(struct io_uring_cmd *, struct io_comp_batch *, 195562306a36Sopenharmony_ci unsigned int poll_flags); 195662306a36Sopenharmony_ci} __randomize_layout; 195762306a36Sopenharmony_ci 195862306a36Sopenharmony_ci/* Wrap a directory iterator that needs exclusive inode access */ 195962306a36Sopenharmony_ciint wrap_directory_iterator(struct file *, struct dir_context *, 196062306a36Sopenharmony_ci int (*) (struct file *, struct dir_context *)); 196162306a36Sopenharmony_ci#define WRAP_DIR_ITER(x) \ 196262306a36Sopenharmony_ci static int shared_##x(struct file *file , struct dir_context *ctx) \ 196362306a36Sopenharmony_ci { return wrap_directory_iterator(file, ctx, x); } 196462306a36Sopenharmony_ci 196562306a36Sopenharmony_cistruct inode_operations { 196662306a36Sopenharmony_ci struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int); 196762306a36Sopenharmony_ci const char * (*get_link) (struct dentry *, struct inode *, struct delayed_call *); 196862306a36Sopenharmony_ci int (*permission) (struct mnt_idmap *, struct inode *, int); 196962306a36Sopenharmony_ci struct posix_acl * (*get_inode_acl)(struct inode *, int, bool); 197062306a36Sopenharmony_ci 197162306a36Sopenharmony_ci int (*readlink) (struct dentry *, char __user *,int); 197262306a36Sopenharmony_ci 197362306a36Sopenharmony_ci int (*create) (struct mnt_idmap *, struct inode *,struct dentry *, 197462306a36Sopenharmony_ci umode_t, bool); 197562306a36Sopenharmony_ci int (*link) (struct dentry *,struct inode *,struct dentry *); 197662306a36Sopenharmony_ci int (*unlink) (struct inode *,struct dentry *); 197762306a36Sopenharmony_ci int (*symlink) (struct mnt_idmap *, struct inode *,struct dentry *, 197862306a36Sopenharmony_ci const char *); 197962306a36Sopenharmony_ci int (*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *, 198062306a36Sopenharmony_ci umode_t); 198162306a36Sopenharmony_ci int (*rmdir) (struct inode *,struct dentry *); 198262306a36Sopenharmony_ci int (*mknod) (struct mnt_idmap *, struct inode *,struct dentry *, 198362306a36Sopenharmony_ci umode_t,dev_t); 198462306a36Sopenharmony_ci int (*rename) (struct mnt_idmap *, struct inode *, struct dentry *, 198562306a36Sopenharmony_ci struct inode *, struct dentry *, unsigned int); 198662306a36Sopenharmony_ci int (*setattr) (struct mnt_idmap *, struct dentry *, struct iattr *); 198762306a36Sopenharmony_ci int (*getattr) (struct mnt_idmap *, const struct path *, 198862306a36Sopenharmony_ci struct kstat *, u32, unsigned int); 198962306a36Sopenharmony_ci ssize_t (*listxattr) (struct dentry *, char *, size_t); 199062306a36Sopenharmony_ci int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, 199162306a36Sopenharmony_ci u64 len); 199262306a36Sopenharmony_ci int (*update_time)(struct inode *, int); 199362306a36Sopenharmony_ci int (*atomic_open)(struct inode *, struct dentry *, 199462306a36Sopenharmony_ci struct file *, unsigned open_flag, 199562306a36Sopenharmony_ci umode_t create_mode); 199662306a36Sopenharmony_ci int (*tmpfile) (struct mnt_idmap *, struct inode *, 199762306a36Sopenharmony_ci struct file *, umode_t); 199862306a36Sopenharmony_ci struct posix_acl *(*get_acl)(struct mnt_idmap *, struct dentry *, 199962306a36Sopenharmony_ci int); 200062306a36Sopenharmony_ci int (*set_acl)(struct mnt_idmap *, struct dentry *, 200162306a36Sopenharmony_ci struct posix_acl *, int); 200262306a36Sopenharmony_ci int (*fileattr_set)(struct mnt_idmap *idmap, 200362306a36Sopenharmony_ci struct dentry *dentry, struct fileattr *fa); 200462306a36Sopenharmony_ci int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa); 200562306a36Sopenharmony_ci struct offset_ctx *(*get_offset_ctx)(struct inode *inode); 200662306a36Sopenharmony_ci} ____cacheline_aligned; 200762306a36Sopenharmony_ci 200862306a36Sopenharmony_cistatic inline ssize_t call_read_iter(struct file *file, struct kiocb *kio, 200962306a36Sopenharmony_ci struct iov_iter *iter) 201062306a36Sopenharmony_ci{ 201162306a36Sopenharmony_ci return file->f_op->read_iter(kio, iter); 201262306a36Sopenharmony_ci} 201362306a36Sopenharmony_ci 201462306a36Sopenharmony_cistatic inline ssize_t call_write_iter(struct file *file, struct kiocb *kio, 201562306a36Sopenharmony_ci struct iov_iter *iter) 201662306a36Sopenharmony_ci{ 201762306a36Sopenharmony_ci return file->f_op->write_iter(kio, iter); 201862306a36Sopenharmony_ci} 201962306a36Sopenharmony_ci 202062306a36Sopenharmony_cistatic inline int call_mmap(struct file *file, struct vm_area_struct *vma) 202162306a36Sopenharmony_ci{ 202262306a36Sopenharmony_ci return file->f_op->mmap(file, vma); 202362306a36Sopenharmony_ci} 202462306a36Sopenharmony_ci 202562306a36Sopenharmony_ciextern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); 202662306a36Sopenharmony_ciextern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); 202762306a36Sopenharmony_ciextern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, 202862306a36Sopenharmony_ci loff_t, size_t, unsigned int); 202962306a36Sopenharmony_ciextern ssize_t generic_copy_file_range(struct file *file_in, loff_t pos_in, 203062306a36Sopenharmony_ci struct file *file_out, loff_t pos_out, 203162306a36Sopenharmony_ci size_t len, unsigned int flags); 203262306a36Sopenharmony_ciint __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, 203362306a36Sopenharmony_ci struct file *file_out, loff_t pos_out, 203462306a36Sopenharmony_ci loff_t *len, unsigned int remap_flags, 203562306a36Sopenharmony_ci const struct iomap_ops *dax_read_ops); 203662306a36Sopenharmony_ciint generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, 203762306a36Sopenharmony_ci struct file *file_out, loff_t pos_out, 203862306a36Sopenharmony_ci loff_t *count, unsigned int remap_flags); 203962306a36Sopenharmony_ciextern loff_t do_clone_file_range(struct file *file_in, loff_t pos_in, 204062306a36Sopenharmony_ci struct file *file_out, loff_t pos_out, 204162306a36Sopenharmony_ci loff_t len, unsigned int remap_flags); 204262306a36Sopenharmony_ciextern loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in, 204362306a36Sopenharmony_ci struct file *file_out, loff_t pos_out, 204462306a36Sopenharmony_ci loff_t len, unsigned int remap_flags); 204562306a36Sopenharmony_ciextern int vfs_dedupe_file_range(struct file *file, 204662306a36Sopenharmony_ci struct file_dedupe_range *same); 204762306a36Sopenharmony_ciextern loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, 204862306a36Sopenharmony_ci struct file *dst_file, loff_t dst_pos, 204962306a36Sopenharmony_ci loff_t len, unsigned int remap_flags); 205062306a36Sopenharmony_ci 205162306a36Sopenharmony_cienum freeze_holder { 205262306a36Sopenharmony_ci FREEZE_HOLDER_KERNEL = (1U << 0), 205362306a36Sopenharmony_ci FREEZE_HOLDER_USERSPACE = (1U << 1), 205462306a36Sopenharmony_ci}; 205562306a36Sopenharmony_ci 205662306a36Sopenharmony_cistruct super_operations { 205762306a36Sopenharmony_ci struct inode *(*alloc_inode)(struct super_block *sb); 205862306a36Sopenharmony_ci void (*destroy_inode)(struct inode *); 205962306a36Sopenharmony_ci void (*free_inode)(struct inode *); 206062306a36Sopenharmony_ci 206162306a36Sopenharmony_ci void (*dirty_inode) (struct inode *, int flags); 206262306a36Sopenharmony_ci int (*write_inode) (struct inode *, struct writeback_control *wbc); 206362306a36Sopenharmony_ci int (*drop_inode) (struct inode *); 206462306a36Sopenharmony_ci void (*evict_inode) (struct inode *); 206562306a36Sopenharmony_ci void (*put_super) (struct super_block *); 206662306a36Sopenharmony_ci int (*sync_fs)(struct super_block *sb, int wait); 206762306a36Sopenharmony_ci int (*freeze_super) (struct super_block *, enum freeze_holder who); 206862306a36Sopenharmony_ci int (*freeze_fs) (struct super_block *); 206962306a36Sopenharmony_ci int (*thaw_super) (struct super_block *, enum freeze_holder who); 207062306a36Sopenharmony_ci int (*unfreeze_fs) (struct super_block *); 207162306a36Sopenharmony_ci int (*statfs) (struct dentry *, struct kstatfs *); 207262306a36Sopenharmony_ci int (*remount_fs) (struct super_block *, int *, char *); 207362306a36Sopenharmony_ci void (*umount_begin) (struct super_block *); 207462306a36Sopenharmony_ci 207562306a36Sopenharmony_ci int (*show_options)(struct seq_file *, struct dentry *); 207662306a36Sopenharmony_ci int (*show_devname)(struct seq_file *, struct dentry *); 207762306a36Sopenharmony_ci int (*show_path)(struct seq_file *, struct dentry *); 207862306a36Sopenharmony_ci int (*show_stats)(struct seq_file *, struct dentry *); 207962306a36Sopenharmony_ci#ifdef CONFIG_QUOTA 208062306a36Sopenharmony_ci ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); 208162306a36Sopenharmony_ci ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); 208262306a36Sopenharmony_ci struct dquot __rcu **(*get_dquots)(struct inode *); 208362306a36Sopenharmony_ci#endif 208462306a36Sopenharmony_ci long (*nr_cached_objects)(struct super_block *, 208562306a36Sopenharmony_ci struct shrink_control *); 208662306a36Sopenharmony_ci long (*free_cached_objects)(struct super_block *, 208762306a36Sopenharmony_ci struct shrink_control *); 208862306a36Sopenharmony_ci void (*shutdown)(struct super_block *sb); 208962306a36Sopenharmony_ci}; 209062306a36Sopenharmony_ci 209162306a36Sopenharmony_ci/* 209262306a36Sopenharmony_ci * Inode flags - they have no relation to superblock flags now 209362306a36Sopenharmony_ci */ 209462306a36Sopenharmony_ci#define S_SYNC (1 << 0) /* Writes are synced at once */ 209562306a36Sopenharmony_ci#define S_NOATIME (1 << 1) /* Do not update access times */ 209662306a36Sopenharmony_ci#define S_APPEND (1 << 2) /* Append-only file */ 209762306a36Sopenharmony_ci#define S_IMMUTABLE (1 << 3) /* Immutable file */ 209862306a36Sopenharmony_ci#define S_DEAD (1 << 4) /* removed, but still open directory */ 209962306a36Sopenharmony_ci#define S_NOQUOTA (1 << 5) /* Inode is not counted to quota */ 210062306a36Sopenharmony_ci#define S_DIRSYNC (1 << 6) /* Directory modifications are synchronous */ 210162306a36Sopenharmony_ci#define S_NOCMTIME (1 << 7) /* Do not update file c/mtime */ 210262306a36Sopenharmony_ci#define S_SWAPFILE (1 << 8) /* Do not truncate: swapon got its bmaps */ 210362306a36Sopenharmony_ci#define S_PRIVATE (1 << 9) /* Inode is fs-internal */ 210462306a36Sopenharmony_ci#define S_IMA (1 << 10) /* Inode has an associated IMA struct */ 210562306a36Sopenharmony_ci#define S_AUTOMOUNT (1 << 11) /* Automount/referral quasi-directory */ 210662306a36Sopenharmony_ci#define S_NOSEC (1 << 12) /* no suid or xattr security attributes */ 210762306a36Sopenharmony_ci#ifdef CONFIG_FS_DAX 210862306a36Sopenharmony_ci#define S_DAX (1 << 13) /* Direct Access, avoiding the page cache */ 210962306a36Sopenharmony_ci#else 211062306a36Sopenharmony_ci#define S_DAX 0 /* Make all the DAX code disappear */ 211162306a36Sopenharmony_ci#endif 211262306a36Sopenharmony_ci#define S_ENCRYPTED (1 << 14) /* Encrypted file (using fs/crypto/) */ 211362306a36Sopenharmony_ci#define S_CASEFOLD (1 << 15) /* Casefolded file */ 211462306a36Sopenharmony_ci#define S_VERITY (1 << 16) /* Verity file (using fs/verity/) */ 211562306a36Sopenharmony_ci#define S_KERNEL_FILE (1 << 17) /* File is in use by the kernel (eg. fs/cachefiles) */ 211662306a36Sopenharmony_ci 211762306a36Sopenharmony_ci/* 211862306a36Sopenharmony_ci * Note that nosuid etc flags are inode-specific: setting some file-system 211962306a36Sopenharmony_ci * flags just means all the inodes inherit those flags by default. It might be 212062306a36Sopenharmony_ci * possible to override it selectively if you really wanted to with some 212162306a36Sopenharmony_ci * ioctl() that is not currently implemented. 212262306a36Sopenharmony_ci * 212362306a36Sopenharmony_ci * Exception: SB_RDONLY is always applied to the entire file system. 212462306a36Sopenharmony_ci * 212562306a36Sopenharmony_ci * Unfortunately, it is possible to change a filesystems flags with it mounted 212662306a36Sopenharmony_ci * with files in use. This means that all of the inodes will not have their 212762306a36Sopenharmony_ci * i_flags updated. Hence, i_flags no longer inherit the superblock mount 212862306a36Sopenharmony_ci * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org 212962306a36Sopenharmony_ci */ 213062306a36Sopenharmony_ci#define __IS_FLG(inode, flg) ((inode)->i_sb->s_flags & (flg)) 213162306a36Sopenharmony_ci 213262306a36Sopenharmony_cistatic inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags & SB_RDONLY; } 213362306a36Sopenharmony_ci#define IS_RDONLY(inode) sb_rdonly((inode)->i_sb) 213462306a36Sopenharmony_ci#define IS_SYNC(inode) (__IS_FLG(inode, SB_SYNCHRONOUS) || \ 213562306a36Sopenharmony_ci ((inode)->i_flags & S_SYNC)) 213662306a36Sopenharmony_ci#define IS_DIRSYNC(inode) (__IS_FLG(inode, SB_SYNCHRONOUS|SB_DIRSYNC) || \ 213762306a36Sopenharmony_ci ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) 213862306a36Sopenharmony_ci#define IS_MANDLOCK(inode) __IS_FLG(inode, SB_MANDLOCK) 213962306a36Sopenharmony_ci#define IS_NOATIME(inode) __IS_FLG(inode, SB_RDONLY|SB_NOATIME) 214062306a36Sopenharmony_ci#define IS_I_VERSION(inode) __IS_FLG(inode, SB_I_VERSION) 214162306a36Sopenharmony_ci 214262306a36Sopenharmony_ci#define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA) 214362306a36Sopenharmony_ci#define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) 214462306a36Sopenharmony_ci#define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) 214562306a36Sopenharmony_ci#define IS_POSIXACL(inode) __IS_FLG(inode, SB_POSIXACL) 214662306a36Sopenharmony_ci 214762306a36Sopenharmony_ci#define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD) 214862306a36Sopenharmony_ci#define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME) 214962306a36Sopenharmony_ci#define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE) 215062306a36Sopenharmony_ci#define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE) 215162306a36Sopenharmony_ci#define IS_IMA(inode) ((inode)->i_flags & S_IMA) 215262306a36Sopenharmony_ci#define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT) 215362306a36Sopenharmony_ci#define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC) 215462306a36Sopenharmony_ci#define IS_DAX(inode) ((inode)->i_flags & S_DAX) 215562306a36Sopenharmony_ci#define IS_ENCRYPTED(inode) ((inode)->i_flags & S_ENCRYPTED) 215662306a36Sopenharmony_ci#define IS_CASEFOLDED(inode) ((inode)->i_flags & S_CASEFOLD) 215762306a36Sopenharmony_ci#define IS_VERITY(inode) ((inode)->i_flags & S_VERITY) 215862306a36Sopenharmony_ci 215962306a36Sopenharmony_ci#define IS_WHITEOUT(inode) (S_ISCHR(inode->i_mode) && \ 216062306a36Sopenharmony_ci (inode)->i_rdev == WHITEOUT_DEV) 216162306a36Sopenharmony_ci 216262306a36Sopenharmony_cistatic inline bool HAS_UNMAPPED_ID(struct mnt_idmap *idmap, 216362306a36Sopenharmony_ci struct inode *inode) 216462306a36Sopenharmony_ci{ 216562306a36Sopenharmony_ci return !vfsuid_valid(i_uid_into_vfsuid(idmap, inode)) || 216662306a36Sopenharmony_ci !vfsgid_valid(i_gid_into_vfsgid(idmap, inode)); 216762306a36Sopenharmony_ci} 216862306a36Sopenharmony_ci 216962306a36Sopenharmony_cistatic inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) 217062306a36Sopenharmony_ci{ 217162306a36Sopenharmony_ci *kiocb = (struct kiocb) { 217262306a36Sopenharmony_ci .ki_filp = filp, 217362306a36Sopenharmony_ci .ki_flags = filp->f_iocb_flags, 217462306a36Sopenharmony_ci .ki_ioprio = get_current_ioprio(), 217562306a36Sopenharmony_ci }; 217662306a36Sopenharmony_ci} 217762306a36Sopenharmony_ci 217862306a36Sopenharmony_cistatic inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src, 217962306a36Sopenharmony_ci struct file *filp) 218062306a36Sopenharmony_ci{ 218162306a36Sopenharmony_ci *kiocb = (struct kiocb) { 218262306a36Sopenharmony_ci .ki_filp = filp, 218362306a36Sopenharmony_ci .ki_flags = kiocb_src->ki_flags, 218462306a36Sopenharmony_ci .ki_ioprio = kiocb_src->ki_ioprio, 218562306a36Sopenharmony_ci .ki_pos = kiocb_src->ki_pos, 218662306a36Sopenharmony_ci }; 218762306a36Sopenharmony_ci} 218862306a36Sopenharmony_ci 218962306a36Sopenharmony_ci/* 219062306a36Sopenharmony_ci * Inode state bits. Protected by inode->i_lock 219162306a36Sopenharmony_ci * 219262306a36Sopenharmony_ci * Four bits determine the dirty state of the inode: I_DIRTY_SYNC, 219362306a36Sopenharmony_ci * I_DIRTY_DATASYNC, I_DIRTY_PAGES, and I_DIRTY_TIME. 219462306a36Sopenharmony_ci * 219562306a36Sopenharmony_ci * Four bits define the lifetime of an inode. Initially, inodes are I_NEW, 219662306a36Sopenharmony_ci * until that flag is cleared. I_WILL_FREE, I_FREEING and I_CLEAR are set at 219762306a36Sopenharmony_ci * various stages of removing an inode. 219862306a36Sopenharmony_ci * 219962306a36Sopenharmony_ci * Two bits are used for locking and completion notification, I_NEW and I_SYNC. 220062306a36Sopenharmony_ci * 220162306a36Sopenharmony_ci * I_DIRTY_SYNC Inode is dirty, but doesn't have to be written on 220262306a36Sopenharmony_ci * fdatasync() (unless I_DIRTY_DATASYNC is also set). 220362306a36Sopenharmony_ci * Timestamp updates are the usual cause. 220462306a36Sopenharmony_ci * I_DIRTY_DATASYNC Data-related inode changes pending. We keep track of 220562306a36Sopenharmony_ci * these changes separately from I_DIRTY_SYNC so that we 220662306a36Sopenharmony_ci * don't have to write inode on fdatasync() when only 220762306a36Sopenharmony_ci * e.g. the timestamps have changed. 220862306a36Sopenharmony_ci * I_DIRTY_PAGES Inode has dirty pages. Inode itself may be clean. 220962306a36Sopenharmony_ci * I_DIRTY_TIME The inode itself has dirty timestamps, and the 221062306a36Sopenharmony_ci * lazytime mount option is enabled. We keep track of this 221162306a36Sopenharmony_ci * separately from I_DIRTY_SYNC in order to implement 221262306a36Sopenharmony_ci * lazytime. This gets cleared if I_DIRTY_INODE 221362306a36Sopenharmony_ci * (I_DIRTY_SYNC and/or I_DIRTY_DATASYNC) gets set. But 221462306a36Sopenharmony_ci * I_DIRTY_TIME can still be set if I_DIRTY_SYNC is already 221562306a36Sopenharmony_ci * in place because writeback might already be in progress 221662306a36Sopenharmony_ci * and we don't want to lose the time update 221762306a36Sopenharmony_ci * I_NEW Serves as both a mutex and completion notification. 221862306a36Sopenharmony_ci * New inodes set I_NEW. If two processes both create 221962306a36Sopenharmony_ci * the same inode, one of them will release its inode and 222062306a36Sopenharmony_ci * wait for I_NEW to be released before returning. 222162306a36Sopenharmony_ci * Inodes in I_WILL_FREE, I_FREEING or I_CLEAR state can 222262306a36Sopenharmony_ci * also cause waiting on I_NEW, without I_NEW actually 222362306a36Sopenharmony_ci * being set. find_inode() uses this to prevent returning 222462306a36Sopenharmony_ci * nearly-dead inodes. 222562306a36Sopenharmony_ci * I_WILL_FREE Must be set when calling write_inode_now() if i_count 222662306a36Sopenharmony_ci * is zero. I_FREEING must be set when I_WILL_FREE is 222762306a36Sopenharmony_ci * cleared. 222862306a36Sopenharmony_ci * I_FREEING Set when inode is about to be freed but still has dirty 222962306a36Sopenharmony_ci * pages or buffers attached or the inode itself is still 223062306a36Sopenharmony_ci * dirty. 223162306a36Sopenharmony_ci * I_CLEAR Added by clear_inode(). In this state the inode is 223262306a36Sopenharmony_ci * clean and can be destroyed. Inode keeps I_FREEING. 223362306a36Sopenharmony_ci * 223462306a36Sopenharmony_ci * Inodes that are I_WILL_FREE, I_FREEING or I_CLEAR are 223562306a36Sopenharmony_ci * prohibited for many purposes. iget() must wait for 223662306a36Sopenharmony_ci * the inode to be completely released, then create it 223762306a36Sopenharmony_ci * anew. Other functions will just ignore such inodes, 223862306a36Sopenharmony_ci * if appropriate. I_NEW is used for waiting. 223962306a36Sopenharmony_ci * 224062306a36Sopenharmony_ci * I_SYNC Writeback of inode is running. The bit is set during 224162306a36Sopenharmony_ci * data writeback, and cleared with a wakeup on the bit 224262306a36Sopenharmony_ci * address once it is done. The bit is also used to pin 224362306a36Sopenharmony_ci * the inode in memory for flusher thread. 224462306a36Sopenharmony_ci * 224562306a36Sopenharmony_ci * I_REFERENCED Marks the inode as recently references on the LRU list. 224662306a36Sopenharmony_ci * 224762306a36Sopenharmony_ci * I_DIO_WAKEUP Never set. Only used as a key for wait_on_bit(). 224862306a36Sopenharmony_ci * 224962306a36Sopenharmony_ci * I_WB_SWITCH Cgroup bdi_writeback switching in progress. Used to 225062306a36Sopenharmony_ci * synchronize competing switching instances and to tell 225162306a36Sopenharmony_ci * wb stat updates to grab the i_pages lock. See 225262306a36Sopenharmony_ci * inode_switch_wbs_work_fn() for details. 225362306a36Sopenharmony_ci * 225462306a36Sopenharmony_ci * I_OVL_INUSE Used by overlayfs to get exclusive ownership on upper 225562306a36Sopenharmony_ci * and work dirs among overlayfs mounts. 225662306a36Sopenharmony_ci * 225762306a36Sopenharmony_ci * I_CREATING New object's inode in the middle of setting up. 225862306a36Sopenharmony_ci * 225962306a36Sopenharmony_ci * I_DONTCACHE Evict inode as soon as it is not used anymore. 226062306a36Sopenharmony_ci * 226162306a36Sopenharmony_ci * I_SYNC_QUEUED Inode is queued in b_io or b_more_io writeback lists. 226262306a36Sopenharmony_ci * Used to detect that mark_inode_dirty() should not move 226362306a36Sopenharmony_ci * inode between dirty lists. 226462306a36Sopenharmony_ci * 226562306a36Sopenharmony_ci * I_PINNING_FSCACHE_WB Inode is pinning an fscache object for writeback. 226662306a36Sopenharmony_ci * 226762306a36Sopenharmony_ci * Q: What is the difference between I_WILL_FREE and I_FREEING? 226862306a36Sopenharmony_ci */ 226962306a36Sopenharmony_ci#define I_DIRTY_SYNC (1 << 0) 227062306a36Sopenharmony_ci#define I_DIRTY_DATASYNC (1 << 1) 227162306a36Sopenharmony_ci#define I_DIRTY_PAGES (1 << 2) 227262306a36Sopenharmony_ci#define __I_NEW 3 227362306a36Sopenharmony_ci#define I_NEW (1 << __I_NEW) 227462306a36Sopenharmony_ci#define I_WILL_FREE (1 << 4) 227562306a36Sopenharmony_ci#define I_FREEING (1 << 5) 227662306a36Sopenharmony_ci#define I_CLEAR (1 << 6) 227762306a36Sopenharmony_ci#define __I_SYNC 7 227862306a36Sopenharmony_ci#define I_SYNC (1 << __I_SYNC) 227962306a36Sopenharmony_ci#define I_REFERENCED (1 << 8) 228062306a36Sopenharmony_ci#define __I_DIO_WAKEUP 9 228162306a36Sopenharmony_ci#define I_DIO_WAKEUP (1 << __I_DIO_WAKEUP) 228262306a36Sopenharmony_ci#define I_LINKABLE (1 << 10) 228362306a36Sopenharmony_ci#define I_DIRTY_TIME (1 << 11) 228462306a36Sopenharmony_ci#define I_WB_SWITCH (1 << 13) 228562306a36Sopenharmony_ci#define I_OVL_INUSE (1 << 14) 228662306a36Sopenharmony_ci#define I_CREATING (1 << 15) 228762306a36Sopenharmony_ci#define I_DONTCACHE (1 << 16) 228862306a36Sopenharmony_ci#define I_SYNC_QUEUED (1 << 17) 228962306a36Sopenharmony_ci#define I_PINNING_FSCACHE_WB (1 << 18) 229062306a36Sopenharmony_ci 229162306a36Sopenharmony_ci#define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC) 229262306a36Sopenharmony_ci#define I_DIRTY (I_DIRTY_INODE | I_DIRTY_PAGES) 229362306a36Sopenharmony_ci#define I_DIRTY_ALL (I_DIRTY | I_DIRTY_TIME) 229462306a36Sopenharmony_ci 229562306a36Sopenharmony_ciextern void __mark_inode_dirty(struct inode *, int); 229662306a36Sopenharmony_cistatic inline void mark_inode_dirty(struct inode *inode) 229762306a36Sopenharmony_ci{ 229862306a36Sopenharmony_ci __mark_inode_dirty(inode, I_DIRTY); 229962306a36Sopenharmony_ci} 230062306a36Sopenharmony_ci 230162306a36Sopenharmony_cistatic inline void mark_inode_dirty_sync(struct inode *inode) 230262306a36Sopenharmony_ci{ 230362306a36Sopenharmony_ci __mark_inode_dirty(inode, I_DIRTY_SYNC); 230462306a36Sopenharmony_ci} 230562306a36Sopenharmony_ci 230662306a36Sopenharmony_ci/* 230762306a36Sopenharmony_ci * Returns true if the given inode itself only has dirty timestamps (its pages 230862306a36Sopenharmony_ci * may still be dirty) and isn't currently being allocated or freed. 230962306a36Sopenharmony_ci * Filesystems should call this if when writing an inode when lazytime is 231062306a36Sopenharmony_ci * enabled, they want to opportunistically write the timestamps of other inodes 231162306a36Sopenharmony_ci * located very nearby on-disk, e.g. in the same inode block. This returns true 231262306a36Sopenharmony_ci * if the given inode is in need of such an opportunistic update. Requires 231362306a36Sopenharmony_ci * i_lock, or at least later re-checking under i_lock. 231462306a36Sopenharmony_ci */ 231562306a36Sopenharmony_cistatic inline bool inode_is_dirtytime_only(struct inode *inode) 231662306a36Sopenharmony_ci{ 231762306a36Sopenharmony_ci return (inode->i_state & (I_DIRTY_TIME | I_NEW | 231862306a36Sopenharmony_ci I_FREEING | I_WILL_FREE)) == I_DIRTY_TIME; 231962306a36Sopenharmony_ci} 232062306a36Sopenharmony_ci 232162306a36Sopenharmony_ciextern void inc_nlink(struct inode *inode); 232262306a36Sopenharmony_ciextern void drop_nlink(struct inode *inode); 232362306a36Sopenharmony_ciextern void clear_nlink(struct inode *inode); 232462306a36Sopenharmony_ciextern void set_nlink(struct inode *inode, unsigned int nlink); 232562306a36Sopenharmony_ci 232662306a36Sopenharmony_cistatic inline void inode_inc_link_count(struct inode *inode) 232762306a36Sopenharmony_ci{ 232862306a36Sopenharmony_ci inc_nlink(inode); 232962306a36Sopenharmony_ci mark_inode_dirty(inode); 233062306a36Sopenharmony_ci} 233162306a36Sopenharmony_ci 233262306a36Sopenharmony_cistatic inline void inode_dec_link_count(struct inode *inode) 233362306a36Sopenharmony_ci{ 233462306a36Sopenharmony_ci drop_nlink(inode); 233562306a36Sopenharmony_ci mark_inode_dirty(inode); 233662306a36Sopenharmony_ci} 233762306a36Sopenharmony_ci 233862306a36Sopenharmony_cienum file_time_flags { 233962306a36Sopenharmony_ci S_ATIME = 1, 234062306a36Sopenharmony_ci S_MTIME = 2, 234162306a36Sopenharmony_ci S_CTIME = 4, 234262306a36Sopenharmony_ci S_VERSION = 8, 234362306a36Sopenharmony_ci}; 234462306a36Sopenharmony_ci 234562306a36Sopenharmony_ciextern bool atime_needs_update(const struct path *, struct inode *); 234662306a36Sopenharmony_ciextern void touch_atime(const struct path *); 234762306a36Sopenharmony_ciint inode_update_time(struct inode *inode, int flags); 234862306a36Sopenharmony_ci 234962306a36Sopenharmony_cistatic inline void file_accessed(struct file *file) 235062306a36Sopenharmony_ci{ 235162306a36Sopenharmony_ci if (!(file->f_flags & O_NOATIME)) 235262306a36Sopenharmony_ci touch_atime(&file->f_path); 235362306a36Sopenharmony_ci} 235462306a36Sopenharmony_ci 235562306a36Sopenharmony_ciextern int file_modified(struct file *file); 235662306a36Sopenharmony_ciint kiocb_modified(struct kiocb *iocb); 235762306a36Sopenharmony_ci 235862306a36Sopenharmony_ciint sync_inode_metadata(struct inode *inode, int wait); 235962306a36Sopenharmony_ci 236062306a36Sopenharmony_cistruct file_system_type { 236162306a36Sopenharmony_ci const char *name; 236262306a36Sopenharmony_ci int fs_flags; 236362306a36Sopenharmony_ci#define FS_REQUIRES_DEV 1 236462306a36Sopenharmony_ci#define FS_BINARY_MOUNTDATA 2 236562306a36Sopenharmony_ci#define FS_HAS_SUBTYPE 4 236662306a36Sopenharmony_ci#define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */ 236762306a36Sopenharmony_ci#define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */ 236862306a36Sopenharmony_ci#define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */ 236962306a36Sopenharmony_ci#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ 237062306a36Sopenharmony_ci int (*init_fs_context)(struct fs_context *); 237162306a36Sopenharmony_ci const struct fs_parameter_spec *parameters; 237262306a36Sopenharmony_ci struct dentry *(*mount) (struct file_system_type *, int, 237362306a36Sopenharmony_ci const char *, void *); 237462306a36Sopenharmony_ci void (*kill_sb) (struct super_block *); 237562306a36Sopenharmony_ci struct module *owner; 237662306a36Sopenharmony_ci struct file_system_type * next; 237762306a36Sopenharmony_ci struct hlist_head fs_supers; 237862306a36Sopenharmony_ci 237962306a36Sopenharmony_ci struct lock_class_key s_lock_key; 238062306a36Sopenharmony_ci struct lock_class_key s_umount_key; 238162306a36Sopenharmony_ci struct lock_class_key s_vfs_rename_key; 238262306a36Sopenharmony_ci struct lock_class_key s_writers_key[SB_FREEZE_LEVELS]; 238362306a36Sopenharmony_ci 238462306a36Sopenharmony_ci struct lock_class_key i_lock_key; 238562306a36Sopenharmony_ci struct lock_class_key i_mutex_key; 238662306a36Sopenharmony_ci struct lock_class_key invalidate_lock_key; 238762306a36Sopenharmony_ci struct lock_class_key i_mutex_dir_key; 238862306a36Sopenharmony_ci}; 238962306a36Sopenharmony_ci 239062306a36Sopenharmony_ci#define MODULE_ALIAS_FS(NAME) MODULE_ALIAS("fs-" NAME) 239162306a36Sopenharmony_ci 239262306a36Sopenharmony_ciextern struct dentry *mount_bdev(struct file_system_type *fs_type, 239362306a36Sopenharmony_ci int flags, const char *dev_name, void *data, 239462306a36Sopenharmony_ci int (*fill_super)(struct super_block *, void *, int)); 239562306a36Sopenharmony_ciextern struct dentry *mount_single(struct file_system_type *fs_type, 239662306a36Sopenharmony_ci int flags, void *data, 239762306a36Sopenharmony_ci int (*fill_super)(struct super_block *, void *, int)); 239862306a36Sopenharmony_ciextern struct dentry *mount_nodev(struct file_system_type *fs_type, 239962306a36Sopenharmony_ci int flags, void *data, 240062306a36Sopenharmony_ci int (*fill_super)(struct super_block *, void *, int)); 240162306a36Sopenharmony_ciextern struct dentry *mount_subtree(struct vfsmount *mnt, const char *path); 240262306a36Sopenharmony_civoid retire_super(struct super_block *sb); 240362306a36Sopenharmony_civoid generic_shutdown_super(struct super_block *sb); 240462306a36Sopenharmony_civoid kill_block_super(struct super_block *sb); 240562306a36Sopenharmony_civoid kill_anon_super(struct super_block *sb); 240662306a36Sopenharmony_civoid kill_litter_super(struct super_block *sb); 240762306a36Sopenharmony_civoid deactivate_super(struct super_block *sb); 240862306a36Sopenharmony_civoid deactivate_locked_super(struct super_block *sb); 240962306a36Sopenharmony_ciint set_anon_super(struct super_block *s, void *data); 241062306a36Sopenharmony_ciint set_anon_super_fc(struct super_block *s, struct fs_context *fc); 241162306a36Sopenharmony_ciint get_anon_bdev(dev_t *); 241262306a36Sopenharmony_civoid free_anon_bdev(dev_t); 241362306a36Sopenharmony_cistruct super_block *sget_fc(struct fs_context *fc, 241462306a36Sopenharmony_ci int (*test)(struct super_block *, struct fs_context *), 241562306a36Sopenharmony_ci int (*set)(struct super_block *, struct fs_context *)); 241662306a36Sopenharmony_cistruct super_block *sget(struct file_system_type *type, 241762306a36Sopenharmony_ci int (*test)(struct super_block *,void *), 241862306a36Sopenharmony_ci int (*set)(struct super_block *,void *), 241962306a36Sopenharmony_ci int flags, void *data); 242062306a36Sopenharmony_cistruct super_block *sget_dev(struct fs_context *fc, dev_t dev); 242162306a36Sopenharmony_ci 242262306a36Sopenharmony_ci/* Alas, no aliases. Too much hassle with bringing module.h everywhere */ 242362306a36Sopenharmony_ci#define fops_get(fops) \ 242462306a36Sopenharmony_ci (((fops) && try_module_get((fops)->owner) ? (fops) : NULL)) 242562306a36Sopenharmony_ci#define fops_put(fops) \ 242662306a36Sopenharmony_ci do { if (fops) module_put((fops)->owner); } while(0) 242762306a36Sopenharmony_ci/* 242862306a36Sopenharmony_ci * This one is to be used *ONLY* from ->open() instances. 242962306a36Sopenharmony_ci * fops must be non-NULL, pinned down *and* module dependencies 243062306a36Sopenharmony_ci * should be sufficient to pin the caller down as well. 243162306a36Sopenharmony_ci */ 243262306a36Sopenharmony_ci#define replace_fops(f, fops) \ 243362306a36Sopenharmony_ci do { \ 243462306a36Sopenharmony_ci struct file *__file = (f); \ 243562306a36Sopenharmony_ci fops_put(__file->f_op); \ 243662306a36Sopenharmony_ci BUG_ON(!(__file->f_op = (fops))); \ 243762306a36Sopenharmony_ci } while(0) 243862306a36Sopenharmony_ci 243962306a36Sopenharmony_ciextern int register_filesystem(struct file_system_type *); 244062306a36Sopenharmony_ciextern int unregister_filesystem(struct file_system_type *); 244162306a36Sopenharmony_ciextern int vfs_statfs(const struct path *, struct kstatfs *); 244262306a36Sopenharmony_ciextern int user_statfs(const char __user *, struct kstatfs *); 244362306a36Sopenharmony_ciextern int fd_statfs(int, struct kstatfs *); 244462306a36Sopenharmony_ciint freeze_super(struct super_block *super, enum freeze_holder who); 244562306a36Sopenharmony_ciint thaw_super(struct super_block *super, enum freeze_holder who); 244662306a36Sopenharmony_ciextern __printf(2, 3) 244762306a36Sopenharmony_ciint super_setup_bdi_name(struct super_block *sb, char *fmt, ...); 244862306a36Sopenharmony_ciextern int super_setup_bdi(struct super_block *sb); 244962306a36Sopenharmony_ci 245062306a36Sopenharmony_ciextern int current_umask(void); 245162306a36Sopenharmony_ci 245262306a36Sopenharmony_ciextern void ihold(struct inode * inode); 245362306a36Sopenharmony_ciextern void iput(struct inode *); 245462306a36Sopenharmony_ciint inode_update_timestamps(struct inode *inode, int flags); 245562306a36Sopenharmony_ciint generic_update_time(struct inode *, int); 245662306a36Sopenharmony_ci 245762306a36Sopenharmony_ci/* /sys/fs */ 245862306a36Sopenharmony_ciextern struct kobject *fs_kobj; 245962306a36Sopenharmony_ci 246062306a36Sopenharmony_ci#define MAX_RW_COUNT (INT_MAX & PAGE_MASK) 246162306a36Sopenharmony_ci 246262306a36Sopenharmony_ci/* fs/open.c */ 246362306a36Sopenharmony_cistruct audit_names; 246462306a36Sopenharmony_cistruct filename { 246562306a36Sopenharmony_ci const char *name; /* pointer to actual string */ 246662306a36Sopenharmony_ci const __user char *uptr; /* original userland pointer */ 246762306a36Sopenharmony_ci atomic_t refcnt; 246862306a36Sopenharmony_ci struct audit_names *aname; 246962306a36Sopenharmony_ci const char iname[]; 247062306a36Sopenharmony_ci}; 247162306a36Sopenharmony_cistatic_assert(offsetof(struct filename, iname) % sizeof(long) == 0); 247262306a36Sopenharmony_ci 247362306a36Sopenharmony_cistatic inline struct mnt_idmap *file_mnt_idmap(struct file *file) 247462306a36Sopenharmony_ci{ 247562306a36Sopenharmony_ci return mnt_idmap(file->f_path.mnt); 247662306a36Sopenharmony_ci} 247762306a36Sopenharmony_ci 247862306a36Sopenharmony_ci/** 247962306a36Sopenharmony_ci * is_idmapped_mnt - check whether a mount is mapped 248062306a36Sopenharmony_ci * @mnt: the mount to check 248162306a36Sopenharmony_ci * 248262306a36Sopenharmony_ci * If @mnt has an non @nop_mnt_idmap attached to it then @mnt is mapped. 248362306a36Sopenharmony_ci * 248462306a36Sopenharmony_ci * Return: true if mount is mapped, false if not. 248562306a36Sopenharmony_ci */ 248662306a36Sopenharmony_cistatic inline bool is_idmapped_mnt(const struct vfsmount *mnt) 248762306a36Sopenharmony_ci{ 248862306a36Sopenharmony_ci return mnt_idmap(mnt) != &nop_mnt_idmap; 248962306a36Sopenharmony_ci} 249062306a36Sopenharmony_ci 249162306a36Sopenharmony_ciextern long vfs_truncate(const struct path *, loff_t); 249262306a36Sopenharmony_ciint do_truncate(struct mnt_idmap *, struct dentry *, loff_t start, 249362306a36Sopenharmony_ci unsigned int time_attrs, struct file *filp); 249462306a36Sopenharmony_ciextern int vfs_fallocate(struct file *file, int mode, loff_t offset, 249562306a36Sopenharmony_ci loff_t len); 249662306a36Sopenharmony_ciextern long do_sys_open(int dfd, const char __user *filename, int flags, 249762306a36Sopenharmony_ci umode_t mode); 249862306a36Sopenharmony_ciextern struct file *file_open_name(struct filename *, int, umode_t); 249962306a36Sopenharmony_ciextern struct file *filp_open(const char *, int, umode_t); 250062306a36Sopenharmony_ciextern struct file *file_open_root(const struct path *, 250162306a36Sopenharmony_ci const char *, int, umode_t); 250262306a36Sopenharmony_cistatic inline struct file *file_open_root_mnt(struct vfsmount *mnt, 250362306a36Sopenharmony_ci const char *name, int flags, umode_t mode) 250462306a36Sopenharmony_ci{ 250562306a36Sopenharmony_ci return file_open_root(&(struct path){.mnt = mnt, .dentry = mnt->mnt_root}, 250662306a36Sopenharmony_ci name, flags, mode); 250762306a36Sopenharmony_ci} 250862306a36Sopenharmony_cistruct file *dentry_open(const struct path *path, int flags, 250962306a36Sopenharmony_ci const struct cred *creds); 251062306a36Sopenharmony_cistruct file *dentry_create(const struct path *path, int flags, umode_t mode, 251162306a36Sopenharmony_ci const struct cred *cred); 251262306a36Sopenharmony_cistruct file *backing_file_open(const struct path *path, int flags, 251362306a36Sopenharmony_ci const struct path *real_path, 251462306a36Sopenharmony_ci const struct cred *cred); 251562306a36Sopenharmony_cistruct path *backing_file_real_path(struct file *f); 251662306a36Sopenharmony_ci 251762306a36Sopenharmony_ci/* 251862306a36Sopenharmony_ci * file_real_path - get the path corresponding to f_inode 251962306a36Sopenharmony_ci * 252062306a36Sopenharmony_ci * When opening a backing file for a stackable filesystem (e.g., 252162306a36Sopenharmony_ci * overlayfs) f_path may be on the stackable filesystem and f_inode on 252262306a36Sopenharmony_ci * the underlying filesystem. When the path associated with f_inode is 252362306a36Sopenharmony_ci * needed, this helper should be used instead of accessing f_path 252462306a36Sopenharmony_ci * directly. 252562306a36Sopenharmony_ci*/ 252662306a36Sopenharmony_cistatic inline const struct path *file_real_path(struct file *f) 252762306a36Sopenharmony_ci{ 252862306a36Sopenharmony_ci if (unlikely(f->f_mode & FMODE_BACKING)) 252962306a36Sopenharmony_ci return backing_file_real_path(f); 253062306a36Sopenharmony_ci return &f->f_path; 253162306a36Sopenharmony_ci} 253262306a36Sopenharmony_ci 253362306a36Sopenharmony_cistatic inline struct file *file_clone_open(struct file *file) 253462306a36Sopenharmony_ci{ 253562306a36Sopenharmony_ci return dentry_open(&file->f_path, file->f_flags, file->f_cred); 253662306a36Sopenharmony_ci} 253762306a36Sopenharmony_ciextern int filp_close(struct file *, fl_owner_t id); 253862306a36Sopenharmony_ci 253962306a36Sopenharmony_ciextern struct filename *getname_flags(const char __user *, int, int *); 254062306a36Sopenharmony_ciextern struct filename *getname_uflags(const char __user *, int); 254162306a36Sopenharmony_ciextern struct filename *getname(const char __user *); 254262306a36Sopenharmony_ciextern struct filename *getname_kernel(const char *); 254362306a36Sopenharmony_ciextern void putname(struct filename *name); 254462306a36Sopenharmony_ci 254562306a36Sopenharmony_ciextern int finish_open(struct file *file, struct dentry *dentry, 254662306a36Sopenharmony_ci int (*open)(struct inode *, struct file *)); 254762306a36Sopenharmony_ciextern int finish_no_open(struct file *file, struct dentry *dentry); 254862306a36Sopenharmony_ci 254962306a36Sopenharmony_ci/* Helper for the simple case when original dentry is used */ 255062306a36Sopenharmony_cistatic inline int finish_open_simple(struct file *file, int error) 255162306a36Sopenharmony_ci{ 255262306a36Sopenharmony_ci if (error) 255362306a36Sopenharmony_ci return error; 255462306a36Sopenharmony_ci 255562306a36Sopenharmony_ci return finish_open(file, file->f_path.dentry, NULL); 255662306a36Sopenharmony_ci} 255762306a36Sopenharmony_ci 255862306a36Sopenharmony_ci/* fs/dcache.c */ 255962306a36Sopenharmony_ciextern void __init vfs_caches_init_early(void); 256062306a36Sopenharmony_ciextern void __init vfs_caches_init(void); 256162306a36Sopenharmony_ci 256262306a36Sopenharmony_ciextern struct kmem_cache *names_cachep; 256362306a36Sopenharmony_ci 256462306a36Sopenharmony_ci#define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL) 256562306a36Sopenharmony_ci#define __putname(name) kmem_cache_free(names_cachep, (void *)(name)) 256662306a36Sopenharmony_ci 256762306a36Sopenharmony_ciextern struct super_block *blockdev_superblock; 256862306a36Sopenharmony_cistatic inline bool sb_is_blkdev_sb(struct super_block *sb) 256962306a36Sopenharmony_ci{ 257062306a36Sopenharmony_ci return IS_ENABLED(CONFIG_BLOCK) && sb == blockdev_superblock; 257162306a36Sopenharmony_ci} 257262306a36Sopenharmony_ci 257362306a36Sopenharmony_civoid emergency_thaw_all(void); 257462306a36Sopenharmony_ciextern int sync_filesystem(struct super_block *); 257562306a36Sopenharmony_ciextern const struct file_operations def_blk_fops; 257662306a36Sopenharmony_ciextern const struct file_operations def_chr_fops; 257762306a36Sopenharmony_ci 257862306a36Sopenharmony_ci/* fs/char_dev.c */ 257962306a36Sopenharmony_ci#define CHRDEV_MAJOR_MAX 512 258062306a36Sopenharmony_ci/* Marks the bottom of the first segment of free char majors */ 258162306a36Sopenharmony_ci#define CHRDEV_MAJOR_DYN_END 234 258262306a36Sopenharmony_ci/* Marks the top and bottom of the second segment of free char majors */ 258362306a36Sopenharmony_ci#define CHRDEV_MAJOR_DYN_EXT_START 511 258462306a36Sopenharmony_ci#define CHRDEV_MAJOR_DYN_EXT_END 384 258562306a36Sopenharmony_ci 258662306a36Sopenharmony_ciextern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *); 258762306a36Sopenharmony_ciextern int register_chrdev_region(dev_t, unsigned, const char *); 258862306a36Sopenharmony_ciextern int __register_chrdev(unsigned int major, unsigned int baseminor, 258962306a36Sopenharmony_ci unsigned int count, const char *name, 259062306a36Sopenharmony_ci const struct file_operations *fops); 259162306a36Sopenharmony_ciextern void __unregister_chrdev(unsigned int major, unsigned int baseminor, 259262306a36Sopenharmony_ci unsigned int count, const char *name); 259362306a36Sopenharmony_ciextern void unregister_chrdev_region(dev_t, unsigned); 259462306a36Sopenharmony_ciextern void chrdev_show(struct seq_file *,off_t); 259562306a36Sopenharmony_ci 259662306a36Sopenharmony_cistatic inline int register_chrdev(unsigned int major, const char *name, 259762306a36Sopenharmony_ci const struct file_operations *fops) 259862306a36Sopenharmony_ci{ 259962306a36Sopenharmony_ci return __register_chrdev(major, 0, 256, name, fops); 260062306a36Sopenharmony_ci} 260162306a36Sopenharmony_ci 260262306a36Sopenharmony_cistatic inline void unregister_chrdev(unsigned int major, const char *name) 260362306a36Sopenharmony_ci{ 260462306a36Sopenharmony_ci __unregister_chrdev(major, 0, 256, name); 260562306a36Sopenharmony_ci} 260662306a36Sopenharmony_ci 260762306a36Sopenharmony_ciextern void init_special_inode(struct inode *, umode_t, dev_t); 260862306a36Sopenharmony_ci 260962306a36Sopenharmony_ci/* Invalid inode operations -- fs/bad_inode.c */ 261062306a36Sopenharmony_ciextern void make_bad_inode(struct inode *); 261162306a36Sopenharmony_ciextern bool is_bad_inode(struct inode *); 261262306a36Sopenharmony_ci 261362306a36Sopenharmony_ciextern int __must_check file_fdatawait_range(struct file *file, loff_t lstart, 261462306a36Sopenharmony_ci loff_t lend); 261562306a36Sopenharmony_ciextern int __must_check file_check_and_advance_wb_err(struct file *file); 261662306a36Sopenharmony_ciextern int __must_check file_write_and_wait_range(struct file *file, 261762306a36Sopenharmony_ci loff_t start, loff_t end); 261862306a36Sopenharmony_ci 261962306a36Sopenharmony_cistatic inline int file_write_and_wait(struct file *file) 262062306a36Sopenharmony_ci{ 262162306a36Sopenharmony_ci return file_write_and_wait_range(file, 0, LLONG_MAX); 262262306a36Sopenharmony_ci} 262362306a36Sopenharmony_ci 262462306a36Sopenharmony_ciextern int vfs_fsync_range(struct file *file, loff_t start, loff_t end, 262562306a36Sopenharmony_ci int datasync); 262662306a36Sopenharmony_ciextern int vfs_fsync(struct file *file, int datasync); 262762306a36Sopenharmony_ci 262862306a36Sopenharmony_ciextern int sync_file_range(struct file *file, loff_t offset, loff_t nbytes, 262962306a36Sopenharmony_ci unsigned int flags); 263062306a36Sopenharmony_ci 263162306a36Sopenharmony_cistatic inline bool iocb_is_dsync(const struct kiocb *iocb) 263262306a36Sopenharmony_ci{ 263362306a36Sopenharmony_ci return (iocb->ki_flags & IOCB_DSYNC) || 263462306a36Sopenharmony_ci IS_SYNC(iocb->ki_filp->f_mapping->host); 263562306a36Sopenharmony_ci} 263662306a36Sopenharmony_ci 263762306a36Sopenharmony_ci/* 263862306a36Sopenharmony_ci * Sync the bytes written if this was a synchronous write. Expect ki_pos 263962306a36Sopenharmony_ci * to already be updated for the write, and will return either the amount 264062306a36Sopenharmony_ci * of bytes passed in, or an error if syncing the file failed. 264162306a36Sopenharmony_ci */ 264262306a36Sopenharmony_cistatic inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count) 264362306a36Sopenharmony_ci{ 264462306a36Sopenharmony_ci if (iocb_is_dsync(iocb)) { 264562306a36Sopenharmony_ci int ret = vfs_fsync_range(iocb->ki_filp, 264662306a36Sopenharmony_ci iocb->ki_pos - count, iocb->ki_pos - 1, 264762306a36Sopenharmony_ci (iocb->ki_flags & IOCB_SYNC) ? 0 : 1); 264862306a36Sopenharmony_ci if (ret) 264962306a36Sopenharmony_ci return ret; 265062306a36Sopenharmony_ci } 265162306a36Sopenharmony_ci 265262306a36Sopenharmony_ci return count; 265362306a36Sopenharmony_ci} 265462306a36Sopenharmony_ci 265562306a36Sopenharmony_ciextern void emergency_sync(void); 265662306a36Sopenharmony_ciextern void emergency_remount(void); 265762306a36Sopenharmony_ci 265862306a36Sopenharmony_ci#ifdef CONFIG_BLOCK 265962306a36Sopenharmony_ciextern int bmap(struct inode *inode, sector_t *block); 266062306a36Sopenharmony_ci#else 266162306a36Sopenharmony_cistatic inline int bmap(struct inode *inode, sector_t *block) 266262306a36Sopenharmony_ci{ 266362306a36Sopenharmony_ci return -EINVAL; 266462306a36Sopenharmony_ci} 266562306a36Sopenharmony_ci#endif 266662306a36Sopenharmony_ci 266762306a36Sopenharmony_ciint notify_change(struct mnt_idmap *, struct dentry *, 266862306a36Sopenharmony_ci struct iattr *, struct inode **); 266962306a36Sopenharmony_ciint inode_permission(struct mnt_idmap *, struct inode *, int); 267062306a36Sopenharmony_ciint generic_permission(struct mnt_idmap *, struct inode *, int); 267162306a36Sopenharmony_cistatic inline int file_permission(struct file *file, int mask) 267262306a36Sopenharmony_ci{ 267362306a36Sopenharmony_ci return inode_permission(file_mnt_idmap(file), 267462306a36Sopenharmony_ci file_inode(file), mask); 267562306a36Sopenharmony_ci} 267662306a36Sopenharmony_cistatic inline int path_permission(const struct path *path, int mask) 267762306a36Sopenharmony_ci{ 267862306a36Sopenharmony_ci return inode_permission(mnt_idmap(path->mnt), 267962306a36Sopenharmony_ci d_inode(path->dentry), mask); 268062306a36Sopenharmony_ci} 268162306a36Sopenharmony_ciint __check_sticky(struct mnt_idmap *idmap, struct inode *dir, 268262306a36Sopenharmony_ci struct inode *inode); 268362306a36Sopenharmony_ci 268462306a36Sopenharmony_cistatic inline bool execute_ok(struct inode *inode) 268562306a36Sopenharmony_ci{ 268662306a36Sopenharmony_ci return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode); 268762306a36Sopenharmony_ci} 268862306a36Sopenharmony_ci 268962306a36Sopenharmony_cistatic inline bool inode_wrong_type(const struct inode *inode, umode_t mode) 269062306a36Sopenharmony_ci{ 269162306a36Sopenharmony_ci return (inode->i_mode ^ mode) & S_IFMT; 269262306a36Sopenharmony_ci} 269362306a36Sopenharmony_ci 269462306a36Sopenharmony_ci/** 269562306a36Sopenharmony_ci * file_start_write - get write access to a superblock for regular file io 269662306a36Sopenharmony_ci * @file: the file we want to write to 269762306a36Sopenharmony_ci * 269862306a36Sopenharmony_ci * This is a variant of sb_start_write() which is a noop on non-regualr file. 269962306a36Sopenharmony_ci * Should be matched with a call to file_end_write(). 270062306a36Sopenharmony_ci */ 270162306a36Sopenharmony_cistatic inline void file_start_write(struct file *file) 270262306a36Sopenharmony_ci{ 270362306a36Sopenharmony_ci if (!S_ISREG(file_inode(file)->i_mode)) 270462306a36Sopenharmony_ci return; 270562306a36Sopenharmony_ci sb_start_write(file_inode(file)->i_sb); 270662306a36Sopenharmony_ci} 270762306a36Sopenharmony_ci 270862306a36Sopenharmony_cistatic inline bool file_start_write_trylock(struct file *file) 270962306a36Sopenharmony_ci{ 271062306a36Sopenharmony_ci if (!S_ISREG(file_inode(file)->i_mode)) 271162306a36Sopenharmony_ci return true; 271262306a36Sopenharmony_ci return sb_start_write_trylock(file_inode(file)->i_sb); 271362306a36Sopenharmony_ci} 271462306a36Sopenharmony_ci 271562306a36Sopenharmony_ci/** 271662306a36Sopenharmony_ci * file_end_write - drop write access to a superblock of a regular file 271762306a36Sopenharmony_ci * @file: the file we wrote to 271862306a36Sopenharmony_ci * 271962306a36Sopenharmony_ci * Should be matched with a call to file_start_write(). 272062306a36Sopenharmony_ci */ 272162306a36Sopenharmony_cistatic inline void file_end_write(struct file *file) 272262306a36Sopenharmony_ci{ 272362306a36Sopenharmony_ci if (!S_ISREG(file_inode(file)->i_mode)) 272462306a36Sopenharmony_ci return; 272562306a36Sopenharmony_ci sb_end_write(file_inode(file)->i_sb); 272662306a36Sopenharmony_ci} 272762306a36Sopenharmony_ci 272862306a36Sopenharmony_ci/** 272962306a36Sopenharmony_ci * kiocb_start_write - get write access to a superblock for async file io 273062306a36Sopenharmony_ci * @iocb: the io context we want to submit the write with 273162306a36Sopenharmony_ci * 273262306a36Sopenharmony_ci * This is a variant of sb_start_write() for async io submission. 273362306a36Sopenharmony_ci * Should be matched with a call to kiocb_end_write(). 273462306a36Sopenharmony_ci */ 273562306a36Sopenharmony_cistatic inline void kiocb_start_write(struct kiocb *iocb) 273662306a36Sopenharmony_ci{ 273762306a36Sopenharmony_ci struct inode *inode = file_inode(iocb->ki_filp); 273862306a36Sopenharmony_ci 273962306a36Sopenharmony_ci sb_start_write(inode->i_sb); 274062306a36Sopenharmony_ci /* 274162306a36Sopenharmony_ci * Fool lockdep by telling it the lock got released so that it 274262306a36Sopenharmony_ci * doesn't complain about the held lock when we return to userspace. 274362306a36Sopenharmony_ci */ 274462306a36Sopenharmony_ci __sb_writers_release(inode->i_sb, SB_FREEZE_WRITE); 274562306a36Sopenharmony_ci} 274662306a36Sopenharmony_ci 274762306a36Sopenharmony_ci/** 274862306a36Sopenharmony_ci * kiocb_end_write - drop write access to a superblock after async file io 274962306a36Sopenharmony_ci * @iocb: the io context we sumbitted the write with 275062306a36Sopenharmony_ci * 275162306a36Sopenharmony_ci * Should be matched with a call to kiocb_start_write(). 275262306a36Sopenharmony_ci */ 275362306a36Sopenharmony_cistatic inline void kiocb_end_write(struct kiocb *iocb) 275462306a36Sopenharmony_ci{ 275562306a36Sopenharmony_ci struct inode *inode = file_inode(iocb->ki_filp); 275662306a36Sopenharmony_ci 275762306a36Sopenharmony_ci /* 275862306a36Sopenharmony_ci * Tell lockdep we inherited freeze protection from submission thread. 275962306a36Sopenharmony_ci */ 276062306a36Sopenharmony_ci __sb_writers_acquired(inode->i_sb, SB_FREEZE_WRITE); 276162306a36Sopenharmony_ci sb_end_write(inode->i_sb); 276262306a36Sopenharmony_ci} 276362306a36Sopenharmony_ci 276462306a36Sopenharmony_ci/* 276562306a36Sopenharmony_ci * This is used for regular files where some users -- especially the 276662306a36Sopenharmony_ci * currently executed binary in a process, previously handled via 276762306a36Sopenharmony_ci * VM_DENYWRITE -- cannot handle concurrent write (and maybe mmap 276862306a36Sopenharmony_ci * read-write shared) accesses. 276962306a36Sopenharmony_ci * 277062306a36Sopenharmony_ci * get_write_access() gets write permission for a file. 277162306a36Sopenharmony_ci * put_write_access() releases this write permission. 277262306a36Sopenharmony_ci * deny_write_access() denies write access to a file. 277362306a36Sopenharmony_ci * allow_write_access() re-enables write access to a file. 277462306a36Sopenharmony_ci * 277562306a36Sopenharmony_ci * The i_writecount field of an inode can have the following values: 277662306a36Sopenharmony_ci * 0: no write access, no denied write access 277762306a36Sopenharmony_ci * < 0: (-i_writecount) users that denied write access to the file. 277862306a36Sopenharmony_ci * > 0: (i_writecount) users that have write access to the file. 277962306a36Sopenharmony_ci * 278062306a36Sopenharmony_ci * Normally we operate on that counter with atomic_{inc,dec} and it's safe 278162306a36Sopenharmony_ci * except for the cases where we don't hold i_writecount yet. Then we need to 278262306a36Sopenharmony_ci * use {get,deny}_write_access() - these functions check the sign and refuse 278362306a36Sopenharmony_ci * to do the change if sign is wrong. 278462306a36Sopenharmony_ci */ 278562306a36Sopenharmony_cistatic inline int get_write_access(struct inode *inode) 278662306a36Sopenharmony_ci{ 278762306a36Sopenharmony_ci return atomic_inc_unless_negative(&inode->i_writecount) ? 0 : -ETXTBSY; 278862306a36Sopenharmony_ci} 278962306a36Sopenharmony_cistatic inline int deny_write_access(struct file *file) 279062306a36Sopenharmony_ci{ 279162306a36Sopenharmony_ci struct inode *inode = file_inode(file); 279262306a36Sopenharmony_ci return atomic_dec_unless_positive(&inode->i_writecount) ? 0 : -ETXTBSY; 279362306a36Sopenharmony_ci} 279462306a36Sopenharmony_cistatic inline void put_write_access(struct inode * inode) 279562306a36Sopenharmony_ci{ 279662306a36Sopenharmony_ci atomic_dec(&inode->i_writecount); 279762306a36Sopenharmony_ci} 279862306a36Sopenharmony_cistatic inline void allow_write_access(struct file *file) 279962306a36Sopenharmony_ci{ 280062306a36Sopenharmony_ci if (file) 280162306a36Sopenharmony_ci atomic_inc(&file_inode(file)->i_writecount); 280262306a36Sopenharmony_ci} 280362306a36Sopenharmony_cistatic inline bool inode_is_open_for_write(const struct inode *inode) 280462306a36Sopenharmony_ci{ 280562306a36Sopenharmony_ci return atomic_read(&inode->i_writecount) > 0; 280662306a36Sopenharmony_ci} 280762306a36Sopenharmony_ci 280862306a36Sopenharmony_ci#if defined(CONFIG_IMA) || defined(CONFIG_FILE_LOCKING) 280962306a36Sopenharmony_cistatic inline void i_readcount_dec(struct inode *inode) 281062306a36Sopenharmony_ci{ 281162306a36Sopenharmony_ci BUG_ON(atomic_dec_return(&inode->i_readcount) < 0); 281262306a36Sopenharmony_ci} 281362306a36Sopenharmony_cistatic inline void i_readcount_inc(struct inode *inode) 281462306a36Sopenharmony_ci{ 281562306a36Sopenharmony_ci atomic_inc(&inode->i_readcount); 281662306a36Sopenharmony_ci} 281762306a36Sopenharmony_ci#else 281862306a36Sopenharmony_cistatic inline void i_readcount_dec(struct inode *inode) 281962306a36Sopenharmony_ci{ 282062306a36Sopenharmony_ci return; 282162306a36Sopenharmony_ci} 282262306a36Sopenharmony_cistatic inline void i_readcount_inc(struct inode *inode) 282362306a36Sopenharmony_ci{ 282462306a36Sopenharmony_ci return; 282562306a36Sopenharmony_ci} 282662306a36Sopenharmony_ci#endif 282762306a36Sopenharmony_ciextern int do_pipe_flags(int *, int); 282862306a36Sopenharmony_ci 282962306a36Sopenharmony_ciextern ssize_t kernel_read(struct file *, void *, size_t, loff_t *); 283062306a36Sopenharmony_cissize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos); 283162306a36Sopenharmony_ciextern ssize_t kernel_write(struct file *, const void *, size_t, loff_t *); 283262306a36Sopenharmony_ciextern ssize_t __kernel_write(struct file *, const void *, size_t, loff_t *); 283362306a36Sopenharmony_ciextern struct file * open_exec(const char *); 283462306a36Sopenharmony_ci 283562306a36Sopenharmony_ci/* fs/dcache.c -- generic fs support functions */ 283662306a36Sopenharmony_ciextern bool is_subdir(struct dentry *, struct dentry *); 283762306a36Sopenharmony_ciextern bool path_is_under(const struct path *, const struct path *); 283862306a36Sopenharmony_ci 283962306a36Sopenharmony_ciextern char *file_path(struct file *, char *, int); 284062306a36Sopenharmony_ci 284162306a36Sopenharmony_ci#include <linux/err.h> 284262306a36Sopenharmony_ci 284362306a36Sopenharmony_ci/* needed for stackable file system support */ 284462306a36Sopenharmony_ciextern loff_t default_llseek(struct file *file, loff_t offset, int whence); 284562306a36Sopenharmony_ci 284662306a36Sopenharmony_ciextern loff_t vfs_llseek(struct file *file, loff_t offset, int whence); 284762306a36Sopenharmony_ci 284862306a36Sopenharmony_ciextern int inode_init_always(struct super_block *, struct inode *); 284962306a36Sopenharmony_ciextern void inode_init_once(struct inode *); 285062306a36Sopenharmony_ciextern void address_space_init_once(struct address_space *mapping); 285162306a36Sopenharmony_ciextern struct inode * igrab(struct inode *); 285262306a36Sopenharmony_ciextern ino_t iunique(struct super_block *, ino_t); 285362306a36Sopenharmony_ciextern int inode_needs_sync(struct inode *inode); 285462306a36Sopenharmony_ciextern int generic_delete_inode(struct inode *inode); 285562306a36Sopenharmony_cistatic inline int generic_drop_inode(struct inode *inode) 285662306a36Sopenharmony_ci{ 285762306a36Sopenharmony_ci return !inode->i_nlink || inode_unhashed(inode); 285862306a36Sopenharmony_ci} 285962306a36Sopenharmony_ciextern void d_mark_dontcache(struct inode *inode); 286062306a36Sopenharmony_ci 286162306a36Sopenharmony_ciextern struct inode *ilookup5_nowait(struct super_block *sb, 286262306a36Sopenharmony_ci unsigned long hashval, int (*test)(struct inode *, void *), 286362306a36Sopenharmony_ci void *data); 286462306a36Sopenharmony_ciextern struct inode *ilookup5(struct super_block *sb, unsigned long hashval, 286562306a36Sopenharmony_ci int (*test)(struct inode *, void *), void *data); 286662306a36Sopenharmony_ciextern struct inode *ilookup(struct super_block *sb, unsigned long ino); 286762306a36Sopenharmony_ci 286862306a36Sopenharmony_ciextern struct inode *inode_insert5(struct inode *inode, unsigned long hashval, 286962306a36Sopenharmony_ci int (*test)(struct inode *, void *), 287062306a36Sopenharmony_ci int (*set)(struct inode *, void *), 287162306a36Sopenharmony_ci void *data); 287262306a36Sopenharmony_ciextern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *); 287362306a36Sopenharmony_ciextern struct inode * iget_locked(struct super_block *, unsigned long); 287462306a36Sopenharmony_ciextern struct inode *find_inode_nowait(struct super_block *, 287562306a36Sopenharmony_ci unsigned long, 287662306a36Sopenharmony_ci int (*match)(struct inode *, 287762306a36Sopenharmony_ci unsigned long, void *), 287862306a36Sopenharmony_ci void *data); 287962306a36Sopenharmony_ciextern struct inode *find_inode_rcu(struct super_block *, unsigned long, 288062306a36Sopenharmony_ci int (*)(struct inode *, void *), void *); 288162306a36Sopenharmony_ciextern struct inode *find_inode_by_ino_rcu(struct super_block *, unsigned long); 288262306a36Sopenharmony_ciextern int insert_inode_locked4(struct inode *, unsigned long, int (*test)(struct inode *, void *), void *); 288362306a36Sopenharmony_ciextern int insert_inode_locked(struct inode *); 288462306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_LOCK_ALLOC 288562306a36Sopenharmony_ciextern void lockdep_annotate_inode_mutex_key(struct inode *inode); 288662306a36Sopenharmony_ci#else 288762306a36Sopenharmony_cistatic inline void lockdep_annotate_inode_mutex_key(struct inode *inode) { }; 288862306a36Sopenharmony_ci#endif 288962306a36Sopenharmony_ciextern void unlock_new_inode(struct inode *); 289062306a36Sopenharmony_ciextern void discard_new_inode(struct inode *); 289162306a36Sopenharmony_ciextern unsigned int get_next_ino(void); 289262306a36Sopenharmony_ciextern void evict_inodes(struct super_block *sb); 289362306a36Sopenharmony_civoid dump_mapping(const struct address_space *); 289462306a36Sopenharmony_ci 289562306a36Sopenharmony_ci/* 289662306a36Sopenharmony_ci * Userspace may rely on the inode number being non-zero. For example, glibc 289762306a36Sopenharmony_ci * simply ignores files with zero i_ino in unlink() and other places. 289862306a36Sopenharmony_ci * 289962306a36Sopenharmony_ci * As an additional complication, if userspace was compiled with 290062306a36Sopenharmony_ci * _FILE_OFFSET_BITS=32 on a 64-bit kernel we'll only end up reading out the 290162306a36Sopenharmony_ci * lower 32 bits, so we need to check that those aren't zero explicitly. With 290262306a36Sopenharmony_ci * _FILE_OFFSET_BITS=64, this may cause some harmless false-negatives, but 290362306a36Sopenharmony_ci * better safe than sorry. 290462306a36Sopenharmony_ci */ 290562306a36Sopenharmony_cistatic inline bool is_zero_ino(ino_t ino) 290662306a36Sopenharmony_ci{ 290762306a36Sopenharmony_ci return (u32)ino == 0; 290862306a36Sopenharmony_ci} 290962306a36Sopenharmony_ci 291062306a36Sopenharmony_ciextern void __iget(struct inode * inode); 291162306a36Sopenharmony_ciextern void iget_failed(struct inode *); 291262306a36Sopenharmony_ciextern void clear_inode(struct inode *); 291362306a36Sopenharmony_ciextern void __destroy_inode(struct inode *); 291462306a36Sopenharmony_ciextern struct inode *new_inode_pseudo(struct super_block *sb); 291562306a36Sopenharmony_ciextern struct inode *new_inode(struct super_block *sb); 291662306a36Sopenharmony_ciextern void free_inode_nonrcu(struct inode *inode); 291762306a36Sopenharmony_ciextern int setattr_should_drop_suidgid(struct mnt_idmap *, struct inode *); 291862306a36Sopenharmony_ciextern int file_remove_privs(struct file *); 291962306a36Sopenharmony_ciint setattr_should_drop_sgid(struct mnt_idmap *idmap, 292062306a36Sopenharmony_ci const struct inode *inode); 292162306a36Sopenharmony_ci 292262306a36Sopenharmony_ci/* 292362306a36Sopenharmony_ci * This must be used for allocating filesystems specific inodes to set 292462306a36Sopenharmony_ci * up the inode reclaim context correctly. 292562306a36Sopenharmony_ci */ 292662306a36Sopenharmony_cistatic inline void * 292762306a36Sopenharmony_cialloc_inode_sb(struct super_block *sb, struct kmem_cache *cache, gfp_t gfp) 292862306a36Sopenharmony_ci{ 292962306a36Sopenharmony_ci return kmem_cache_alloc_lru(cache, &sb->s_inode_lru, gfp); 293062306a36Sopenharmony_ci} 293162306a36Sopenharmony_ci 293262306a36Sopenharmony_ciextern void __insert_inode_hash(struct inode *, unsigned long hashval); 293362306a36Sopenharmony_cistatic inline void insert_inode_hash(struct inode *inode) 293462306a36Sopenharmony_ci{ 293562306a36Sopenharmony_ci __insert_inode_hash(inode, inode->i_ino); 293662306a36Sopenharmony_ci} 293762306a36Sopenharmony_ci 293862306a36Sopenharmony_ciextern void __remove_inode_hash(struct inode *); 293962306a36Sopenharmony_cistatic inline void remove_inode_hash(struct inode *inode) 294062306a36Sopenharmony_ci{ 294162306a36Sopenharmony_ci if (!inode_unhashed(inode) && !hlist_fake(&inode->i_hash)) 294262306a36Sopenharmony_ci __remove_inode_hash(inode); 294362306a36Sopenharmony_ci} 294462306a36Sopenharmony_ci 294562306a36Sopenharmony_ciextern void inode_sb_list_add(struct inode *inode); 294662306a36Sopenharmony_ciextern void inode_add_lru(struct inode *inode); 294762306a36Sopenharmony_ci 294862306a36Sopenharmony_ciextern int sb_set_blocksize(struct super_block *, int); 294962306a36Sopenharmony_ciextern int sb_min_blocksize(struct super_block *, int); 295062306a36Sopenharmony_ci 295162306a36Sopenharmony_ciextern int generic_file_mmap(struct file *, struct vm_area_struct *); 295262306a36Sopenharmony_ciextern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); 295362306a36Sopenharmony_ciextern ssize_t generic_write_checks(struct kiocb *, struct iov_iter *); 295462306a36Sopenharmony_ciint generic_write_checks_count(struct kiocb *iocb, loff_t *count); 295562306a36Sopenharmony_ciextern int generic_write_check_limits(struct file *file, loff_t pos, 295662306a36Sopenharmony_ci loff_t *count); 295762306a36Sopenharmony_ciextern int generic_file_rw_checks(struct file *file_in, struct file *file_out); 295862306a36Sopenharmony_cissize_t filemap_read(struct kiocb *iocb, struct iov_iter *to, 295962306a36Sopenharmony_ci ssize_t already_read); 296062306a36Sopenharmony_ciextern ssize_t generic_file_read_iter(struct kiocb *, struct iov_iter *); 296162306a36Sopenharmony_ciextern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *); 296262306a36Sopenharmony_ciextern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); 296362306a36Sopenharmony_ciextern ssize_t generic_file_direct_write(struct kiocb *, struct iov_iter *); 296462306a36Sopenharmony_cissize_t generic_perform_write(struct kiocb *, struct iov_iter *); 296562306a36Sopenharmony_cissize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter, 296662306a36Sopenharmony_ci ssize_t direct_written, ssize_t buffered_written); 296762306a36Sopenharmony_ci 296862306a36Sopenharmony_cissize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos, 296962306a36Sopenharmony_ci rwf_t flags); 297062306a36Sopenharmony_cissize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos, 297162306a36Sopenharmony_ci rwf_t flags); 297262306a36Sopenharmony_cissize_t vfs_iocb_iter_read(struct file *file, struct kiocb *iocb, 297362306a36Sopenharmony_ci struct iov_iter *iter); 297462306a36Sopenharmony_cissize_t vfs_iocb_iter_write(struct file *file, struct kiocb *iocb, 297562306a36Sopenharmony_ci struct iov_iter *iter); 297662306a36Sopenharmony_ci 297762306a36Sopenharmony_ci/* fs/splice.c */ 297862306a36Sopenharmony_cissize_t filemap_splice_read(struct file *in, loff_t *ppos, 297962306a36Sopenharmony_ci struct pipe_inode_info *pipe, 298062306a36Sopenharmony_ci size_t len, unsigned int flags); 298162306a36Sopenharmony_cissize_t copy_splice_read(struct file *in, loff_t *ppos, 298262306a36Sopenharmony_ci struct pipe_inode_info *pipe, 298362306a36Sopenharmony_ci size_t len, unsigned int flags); 298462306a36Sopenharmony_ciextern ssize_t iter_file_splice_write(struct pipe_inode_info *, 298562306a36Sopenharmony_ci struct file *, loff_t *, size_t, unsigned int); 298662306a36Sopenharmony_ciextern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out, 298762306a36Sopenharmony_ci loff_t *opos, size_t len, unsigned int flags); 298862306a36Sopenharmony_ci 298962306a36Sopenharmony_ci 299062306a36Sopenharmony_ciextern void 299162306a36Sopenharmony_cifile_ra_state_init(struct file_ra_state *ra, struct address_space *mapping); 299262306a36Sopenharmony_ciextern loff_t noop_llseek(struct file *file, loff_t offset, int whence); 299362306a36Sopenharmony_ci#define no_llseek NULL 299462306a36Sopenharmony_ciextern loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize); 299562306a36Sopenharmony_ciextern loff_t generic_file_llseek(struct file *file, loff_t offset, int whence); 299662306a36Sopenharmony_ciextern loff_t generic_file_llseek_size(struct file *file, loff_t offset, 299762306a36Sopenharmony_ci int whence, loff_t maxsize, loff_t eof); 299862306a36Sopenharmony_ciextern loff_t fixed_size_llseek(struct file *file, loff_t offset, 299962306a36Sopenharmony_ci int whence, loff_t size); 300062306a36Sopenharmony_ciextern loff_t no_seek_end_llseek_size(struct file *, loff_t, int, loff_t); 300162306a36Sopenharmony_ciextern loff_t no_seek_end_llseek(struct file *, loff_t, int); 300262306a36Sopenharmony_ciint rw_verify_area(int, struct file *, const loff_t *, size_t); 300362306a36Sopenharmony_ciextern int generic_file_open(struct inode * inode, struct file * filp); 300462306a36Sopenharmony_ciextern int nonseekable_open(struct inode * inode, struct file * filp); 300562306a36Sopenharmony_ciextern int stream_open(struct inode * inode, struct file * filp); 300662306a36Sopenharmony_ci 300762306a36Sopenharmony_ci#ifdef CONFIG_BLOCK 300862306a36Sopenharmony_citypedef void (dio_submit_t)(struct bio *bio, struct inode *inode, 300962306a36Sopenharmony_ci loff_t file_offset); 301062306a36Sopenharmony_ci 301162306a36Sopenharmony_cienum { 301262306a36Sopenharmony_ci /* need locking between buffered and direct access */ 301362306a36Sopenharmony_ci DIO_LOCKING = 0x01, 301462306a36Sopenharmony_ci 301562306a36Sopenharmony_ci /* filesystem does not support filling holes */ 301662306a36Sopenharmony_ci DIO_SKIP_HOLES = 0x02, 301762306a36Sopenharmony_ci}; 301862306a36Sopenharmony_ci 301962306a36Sopenharmony_cissize_t __blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, 302062306a36Sopenharmony_ci struct block_device *bdev, struct iov_iter *iter, 302162306a36Sopenharmony_ci get_block_t get_block, 302262306a36Sopenharmony_ci dio_iodone_t end_io, 302362306a36Sopenharmony_ci int flags); 302462306a36Sopenharmony_ci 302562306a36Sopenharmony_cistatic inline ssize_t blockdev_direct_IO(struct kiocb *iocb, 302662306a36Sopenharmony_ci struct inode *inode, 302762306a36Sopenharmony_ci struct iov_iter *iter, 302862306a36Sopenharmony_ci get_block_t get_block) 302962306a36Sopenharmony_ci{ 303062306a36Sopenharmony_ci return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter, 303162306a36Sopenharmony_ci get_block, NULL, DIO_LOCKING | DIO_SKIP_HOLES); 303262306a36Sopenharmony_ci} 303362306a36Sopenharmony_ci#endif 303462306a36Sopenharmony_ci 303562306a36Sopenharmony_civoid inode_dio_wait(struct inode *inode); 303662306a36Sopenharmony_ci 303762306a36Sopenharmony_ci/** 303862306a36Sopenharmony_ci * inode_dio_begin - signal start of a direct I/O requests 303962306a36Sopenharmony_ci * @inode: inode the direct I/O happens on 304062306a36Sopenharmony_ci * 304162306a36Sopenharmony_ci * This is called once we've finished processing a direct I/O request, 304262306a36Sopenharmony_ci * and is used to wake up callers waiting for direct I/O to be quiesced. 304362306a36Sopenharmony_ci */ 304462306a36Sopenharmony_cistatic inline void inode_dio_begin(struct inode *inode) 304562306a36Sopenharmony_ci{ 304662306a36Sopenharmony_ci atomic_inc(&inode->i_dio_count); 304762306a36Sopenharmony_ci} 304862306a36Sopenharmony_ci 304962306a36Sopenharmony_ci/** 305062306a36Sopenharmony_ci * inode_dio_end - signal finish of a direct I/O requests 305162306a36Sopenharmony_ci * @inode: inode the direct I/O happens on 305262306a36Sopenharmony_ci * 305362306a36Sopenharmony_ci * This is called once we've finished processing a direct I/O request, 305462306a36Sopenharmony_ci * and is used to wake up callers waiting for direct I/O to be quiesced. 305562306a36Sopenharmony_ci */ 305662306a36Sopenharmony_cistatic inline void inode_dio_end(struct inode *inode) 305762306a36Sopenharmony_ci{ 305862306a36Sopenharmony_ci if (atomic_dec_and_test(&inode->i_dio_count)) 305962306a36Sopenharmony_ci wake_up_bit(&inode->i_state, __I_DIO_WAKEUP); 306062306a36Sopenharmony_ci} 306162306a36Sopenharmony_ci 306262306a36Sopenharmony_ciextern void inode_set_flags(struct inode *inode, unsigned int flags, 306362306a36Sopenharmony_ci unsigned int mask); 306462306a36Sopenharmony_ci 306562306a36Sopenharmony_ciextern const struct file_operations generic_ro_fops; 306662306a36Sopenharmony_ci 306762306a36Sopenharmony_ci#define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) 306862306a36Sopenharmony_ci 306962306a36Sopenharmony_ciextern int readlink_copy(char __user *, int, const char *); 307062306a36Sopenharmony_ciextern int page_readlink(struct dentry *, char __user *, int); 307162306a36Sopenharmony_ciextern const char *page_get_link(struct dentry *, struct inode *, 307262306a36Sopenharmony_ci struct delayed_call *); 307362306a36Sopenharmony_ciextern void page_put_link(void *); 307462306a36Sopenharmony_ciextern int page_symlink(struct inode *inode, const char *symname, int len); 307562306a36Sopenharmony_ciextern const struct inode_operations page_symlink_inode_operations; 307662306a36Sopenharmony_ciextern void kfree_link(void *); 307762306a36Sopenharmony_civoid generic_fillattr(struct mnt_idmap *, u32, struct inode *, struct kstat *); 307862306a36Sopenharmony_civoid generic_fill_statx_attr(struct inode *inode, struct kstat *stat); 307962306a36Sopenharmony_ciextern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int); 308062306a36Sopenharmony_ciextern int vfs_getattr(const struct path *, struct kstat *, u32, unsigned int); 308162306a36Sopenharmony_civoid __inode_add_bytes(struct inode *inode, loff_t bytes); 308262306a36Sopenharmony_civoid inode_add_bytes(struct inode *inode, loff_t bytes); 308362306a36Sopenharmony_civoid __inode_sub_bytes(struct inode *inode, loff_t bytes); 308462306a36Sopenharmony_civoid inode_sub_bytes(struct inode *inode, loff_t bytes); 308562306a36Sopenharmony_cistatic inline loff_t __inode_get_bytes(struct inode *inode) 308662306a36Sopenharmony_ci{ 308762306a36Sopenharmony_ci return (((loff_t)inode->i_blocks) << 9) + inode->i_bytes; 308862306a36Sopenharmony_ci} 308962306a36Sopenharmony_ciloff_t inode_get_bytes(struct inode *inode); 309062306a36Sopenharmony_civoid inode_set_bytes(struct inode *inode, loff_t bytes); 309162306a36Sopenharmony_ciconst char *simple_get_link(struct dentry *, struct inode *, 309262306a36Sopenharmony_ci struct delayed_call *); 309362306a36Sopenharmony_ciextern const struct inode_operations simple_symlink_inode_operations; 309462306a36Sopenharmony_ci 309562306a36Sopenharmony_ciextern int iterate_dir(struct file *, struct dir_context *); 309662306a36Sopenharmony_ci 309762306a36Sopenharmony_ciint vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, 309862306a36Sopenharmony_ci int flags); 309962306a36Sopenharmony_ciint vfs_fstat(int fd, struct kstat *stat); 310062306a36Sopenharmony_ci 310162306a36Sopenharmony_cistatic inline int vfs_stat(const char __user *filename, struct kstat *stat) 310262306a36Sopenharmony_ci{ 310362306a36Sopenharmony_ci return vfs_fstatat(AT_FDCWD, filename, stat, 0); 310462306a36Sopenharmony_ci} 310562306a36Sopenharmony_cistatic inline int vfs_lstat(const char __user *name, struct kstat *stat) 310662306a36Sopenharmony_ci{ 310762306a36Sopenharmony_ci return vfs_fstatat(AT_FDCWD, name, stat, AT_SYMLINK_NOFOLLOW); 310862306a36Sopenharmony_ci} 310962306a36Sopenharmony_ci 311062306a36Sopenharmony_ciextern const char *vfs_get_link(struct dentry *, struct delayed_call *); 311162306a36Sopenharmony_ciextern int vfs_readlink(struct dentry *, char __user *, int); 311262306a36Sopenharmony_ci 311362306a36Sopenharmony_ciextern struct file_system_type *get_filesystem(struct file_system_type *fs); 311462306a36Sopenharmony_ciextern void put_filesystem(struct file_system_type *fs); 311562306a36Sopenharmony_ciextern struct file_system_type *get_fs_type(const char *name); 311662306a36Sopenharmony_ciextern struct super_block *get_active_super(struct block_device *bdev); 311762306a36Sopenharmony_ciextern void drop_super(struct super_block *sb); 311862306a36Sopenharmony_ciextern void drop_super_exclusive(struct super_block *sb); 311962306a36Sopenharmony_ciextern void iterate_supers(void (*)(struct super_block *, void *), void *); 312062306a36Sopenharmony_ciextern void iterate_supers_type(struct file_system_type *, 312162306a36Sopenharmony_ci void (*)(struct super_block *, void *), void *); 312262306a36Sopenharmony_ci 312362306a36Sopenharmony_ciextern int dcache_dir_open(struct inode *, struct file *); 312462306a36Sopenharmony_ciextern int dcache_dir_close(struct inode *, struct file *); 312562306a36Sopenharmony_ciextern loff_t dcache_dir_lseek(struct file *, loff_t, int); 312662306a36Sopenharmony_ciextern int dcache_readdir(struct file *, struct dir_context *); 312762306a36Sopenharmony_ciextern int simple_setattr(struct mnt_idmap *, struct dentry *, 312862306a36Sopenharmony_ci struct iattr *); 312962306a36Sopenharmony_ciextern int simple_getattr(struct mnt_idmap *, const struct path *, 313062306a36Sopenharmony_ci struct kstat *, u32, unsigned int); 313162306a36Sopenharmony_ciextern int simple_statfs(struct dentry *, struct kstatfs *); 313262306a36Sopenharmony_ciextern int simple_open(struct inode *inode, struct file *file); 313362306a36Sopenharmony_ciextern int simple_link(struct dentry *, struct inode *, struct dentry *); 313462306a36Sopenharmony_ciextern int simple_unlink(struct inode *, struct dentry *); 313562306a36Sopenharmony_ciextern int simple_rmdir(struct inode *, struct dentry *); 313662306a36Sopenharmony_civoid simple_rename_timestamp(struct inode *old_dir, struct dentry *old_dentry, 313762306a36Sopenharmony_ci struct inode *new_dir, struct dentry *new_dentry); 313862306a36Sopenharmony_ciextern int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry, 313962306a36Sopenharmony_ci struct inode *new_dir, struct dentry *new_dentry); 314062306a36Sopenharmony_ciextern int simple_rename(struct mnt_idmap *, struct inode *, 314162306a36Sopenharmony_ci struct dentry *, struct inode *, struct dentry *, 314262306a36Sopenharmony_ci unsigned int); 314362306a36Sopenharmony_ciextern void simple_recursive_removal(struct dentry *, 314462306a36Sopenharmony_ci void (*callback)(struct dentry *)); 314562306a36Sopenharmony_ciextern int noop_fsync(struct file *, loff_t, loff_t, int); 314662306a36Sopenharmony_ciextern ssize_t noop_direct_IO(struct kiocb *iocb, struct iov_iter *iter); 314762306a36Sopenharmony_ciextern int simple_empty(struct dentry *); 314862306a36Sopenharmony_ciextern int simple_write_begin(struct file *file, struct address_space *mapping, 314962306a36Sopenharmony_ci loff_t pos, unsigned len, 315062306a36Sopenharmony_ci struct page **pagep, void **fsdata); 315162306a36Sopenharmony_ciextern const struct address_space_operations ram_aops; 315262306a36Sopenharmony_ciextern int always_delete_dentry(const struct dentry *); 315362306a36Sopenharmony_ciextern struct inode *alloc_anon_inode(struct super_block *); 315462306a36Sopenharmony_ciextern int simple_nosetlease(struct file *, int, struct file_lock **, void **); 315562306a36Sopenharmony_ciextern const struct dentry_operations simple_dentry_operations; 315662306a36Sopenharmony_ci 315762306a36Sopenharmony_ciextern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags); 315862306a36Sopenharmony_ciextern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); 315962306a36Sopenharmony_ciextern const struct file_operations simple_dir_operations; 316062306a36Sopenharmony_ciextern const struct inode_operations simple_dir_inode_operations; 316162306a36Sopenharmony_ciextern void make_empty_dir_inode(struct inode *inode); 316262306a36Sopenharmony_ciextern bool is_empty_dir_inode(struct inode *inode); 316362306a36Sopenharmony_cistruct tree_descr { const char *name; const struct file_operations *ops; int mode; }; 316462306a36Sopenharmony_cistruct dentry *d_alloc_name(struct dentry *, const char *); 316562306a36Sopenharmony_ciextern int simple_fill_super(struct super_block *, unsigned long, 316662306a36Sopenharmony_ci const struct tree_descr *); 316762306a36Sopenharmony_ciextern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); 316862306a36Sopenharmony_ciextern void simple_release_fs(struct vfsmount **mount, int *count); 316962306a36Sopenharmony_ci 317062306a36Sopenharmony_ciextern ssize_t simple_read_from_buffer(void __user *to, size_t count, 317162306a36Sopenharmony_ci loff_t *ppos, const void *from, size_t available); 317262306a36Sopenharmony_ciextern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, 317362306a36Sopenharmony_ci const void __user *from, size_t count); 317462306a36Sopenharmony_ci 317562306a36Sopenharmony_cistruct offset_ctx { 317662306a36Sopenharmony_ci struct xarray xa; 317762306a36Sopenharmony_ci u32 next_offset; 317862306a36Sopenharmony_ci}; 317962306a36Sopenharmony_ci 318062306a36Sopenharmony_civoid simple_offset_init(struct offset_ctx *octx); 318162306a36Sopenharmony_ciint simple_offset_add(struct offset_ctx *octx, struct dentry *dentry); 318262306a36Sopenharmony_civoid simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry); 318362306a36Sopenharmony_ciint simple_offset_rename_exchange(struct inode *old_dir, 318462306a36Sopenharmony_ci struct dentry *old_dentry, 318562306a36Sopenharmony_ci struct inode *new_dir, 318662306a36Sopenharmony_ci struct dentry *new_dentry); 318762306a36Sopenharmony_civoid simple_offset_destroy(struct offset_ctx *octx); 318862306a36Sopenharmony_ci 318962306a36Sopenharmony_ciextern const struct file_operations simple_offset_dir_operations; 319062306a36Sopenharmony_ci 319162306a36Sopenharmony_ciextern int __generic_file_fsync(struct file *, loff_t, loff_t, int); 319262306a36Sopenharmony_ciextern int generic_file_fsync(struct file *, loff_t, loff_t, int); 319362306a36Sopenharmony_ci 319462306a36Sopenharmony_ciextern int generic_check_addressable(unsigned, u64); 319562306a36Sopenharmony_ci 319662306a36Sopenharmony_ciextern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); 319762306a36Sopenharmony_ci 319862306a36Sopenharmony_cistatic inline bool sb_has_encoding(const struct super_block *sb) 319962306a36Sopenharmony_ci{ 320062306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_UNICODE) 320162306a36Sopenharmony_ci return !!sb->s_encoding; 320262306a36Sopenharmony_ci#else 320362306a36Sopenharmony_ci return false; 320462306a36Sopenharmony_ci#endif 320562306a36Sopenharmony_ci} 320662306a36Sopenharmony_ci 320762306a36Sopenharmony_ciint may_setattr(struct mnt_idmap *idmap, struct inode *inode, 320862306a36Sopenharmony_ci unsigned int ia_valid); 320962306a36Sopenharmony_ciint setattr_prepare(struct mnt_idmap *, struct dentry *, struct iattr *); 321062306a36Sopenharmony_ciextern int inode_newsize_ok(const struct inode *, loff_t offset); 321162306a36Sopenharmony_civoid setattr_copy(struct mnt_idmap *, struct inode *inode, 321262306a36Sopenharmony_ci const struct iattr *attr); 321362306a36Sopenharmony_ci 321462306a36Sopenharmony_ciextern int file_update_time(struct file *file); 321562306a36Sopenharmony_ci 321662306a36Sopenharmony_cistatic inline bool vma_is_dax(const struct vm_area_struct *vma) 321762306a36Sopenharmony_ci{ 321862306a36Sopenharmony_ci return vma->vm_file && IS_DAX(vma->vm_file->f_mapping->host); 321962306a36Sopenharmony_ci} 322062306a36Sopenharmony_ci 322162306a36Sopenharmony_cistatic inline bool vma_is_fsdax(struct vm_area_struct *vma) 322262306a36Sopenharmony_ci{ 322362306a36Sopenharmony_ci struct inode *inode; 322462306a36Sopenharmony_ci 322562306a36Sopenharmony_ci if (!IS_ENABLED(CONFIG_FS_DAX) || !vma->vm_file) 322662306a36Sopenharmony_ci return false; 322762306a36Sopenharmony_ci if (!vma_is_dax(vma)) 322862306a36Sopenharmony_ci return false; 322962306a36Sopenharmony_ci inode = file_inode(vma->vm_file); 323062306a36Sopenharmony_ci if (S_ISCHR(inode->i_mode)) 323162306a36Sopenharmony_ci return false; /* device-dax */ 323262306a36Sopenharmony_ci return true; 323362306a36Sopenharmony_ci} 323462306a36Sopenharmony_ci 323562306a36Sopenharmony_cistatic inline int iocb_flags(struct file *file) 323662306a36Sopenharmony_ci{ 323762306a36Sopenharmony_ci int res = 0; 323862306a36Sopenharmony_ci if (file->f_flags & O_APPEND) 323962306a36Sopenharmony_ci res |= IOCB_APPEND; 324062306a36Sopenharmony_ci if (file->f_flags & O_DIRECT) 324162306a36Sopenharmony_ci res |= IOCB_DIRECT; 324262306a36Sopenharmony_ci if (file->f_flags & O_DSYNC) 324362306a36Sopenharmony_ci res |= IOCB_DSYNC; 324462306a36Sopenharmony_ci if (file->f_flags & __O_SYNC) 324562306a36Sopenharmony_ci res |= IOCB_SYNC; 324662306a36Sopenharmony_ci return res; 324762306a36Sopenharmony_ci} 324862306a36Sopenharmony_ci 324962306a36Sopenharmony_cistatic inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags) 325062306a36Sopenharmony_ci{ 325162306a36Sopenharmony_ci int kiocb_flags = 0; 325262306a36Sopenharmony_ci 325362306a36Sopenharmony_ci /* make sure there's no overlap between RWF and private IOCB flags */ 325462306a36Sopenharmony_ci BUILD_BUG_ON((__force int) RWF_SUPPORTED & IOCB_EVENTFD); 325562306a36Sopenharmony_ci 325662306a36Sopenharmony_ci if (!flags) 325762306a36Sopenharmony_ci return 0; 325862306a36Sopenharmony_ci if (unlikely(flags & ~RWF_SUPPORTED)) 325962306a36Sopenharmony_ci return -EOPNOTSUPP; 326062306a36Sopenharmony_ci 326162306a36Sopenharmony_ci if (flags & RWF_NOWAIT) { 326262306a36Sopenharmony_ci if (!(ki->ki_filp->f_mode & FMODE_NOWAIT)) 326362306a36Sopenharmony_ci return -EOPNOTSUPP; 326462306a36Sopenharmony_ci kiocb_flags |= IOCB_NOIO; 326562306a36Sopenharmony_ci } 326662306a36Sopenharmony_ci kiocb_flags |= (__force int) (flags & RWF_SUPPORTED); 326762306a36Sopenharmony_ci if (flags & RWF_SYNC) 326862306a36Sopenharmony_ci kiocb_flags |= IOCB_DSYNC; 326962306a36Sopenharmony_ci 327062306a36Sopenharmony_ci ki->ki_flags |= kiocb_flags; 327162306a36Sopenharmony_ci return 0; 327262306a36Sopenharmony_ci} 327362306a36Sopenharmony_ci 327462306a36Sopenharmony_cistatic inline ino_t parent_ino(struct dentry *dentry) 327562306a36Sopenharmony_ci{ 327662306a36Sopenharmony_ci ino_t res; 327762306a36Sopenharmony_ci 327862306a36Sopenharmony_ci /* 327962306a36Sopenharmony_ci * Don't strictly need d_lock here? If the parent ino could change 328062306a36Sopenharmony_ci * then surely we'd have a deeper race in the caller? 328162306a36Sopenharmony_ci */ 328262306a36Sopenharmony_ci spin_lock(&dentry->d_lock); 328362306a36Sopenharmony_ci res = dentry->d_parent->d_inode->i_ino; 328462306a36Sopenharmony_ci spin_unlock(&dentry->d_lock); 328562306a36Sopenharmony_ci return res; 328662306a36Sopenharmony_ci} 328762306a36Sopenharmony_ci 328862306a36Sopenharmony_ci/* Transaction based IO helpers */ 328962306a36Sopenharmony_ci 329062306a36Sopenharmony_ci/* 329162306a36Sopenharmony_ci * An argresp is stored in an allocated page and holds the 329262306a36Sopenharmony_ci * size of the argument or response, along with its content 329362306a36Sopenharmony_ci */ 329462306a36Sopenharmony_cistruct simple_transaction_argresp { 329562306a36Sopenharmony_ci ssize_t size; 329662306a36Sopenharmony_ci char data[]; 329762306a36Sopenharmony_ci}; 329862306a36Sopenharmony_ci 329962306a36Sopenharmony_ci#define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp)) 330062306a36Sopenharmony_ci 330162306a36Sopenharmony_cichar *simple_transaction_get(struct file *file, const char __user *buf, 330262306a36Sopenharmony_ci size_t size); 330362306a36Sopenharmony_cissize_t simple_transaction_read(struct file *file, char __user *buf, 330462306a36Sopenharmony_ci size_t size, loff_t *pos); 330562306a36Sopenharmony_ciint simple_transaction_release(struct inode *inode, struct file *file); 330662306a36Sopenharmony_ci 330762306a36Sopenharmony_civoid simple_transaction_set(struct file *file, size_t n); 330862306a36Sopenharmony_ci 330962306a36Sopenharmony_ci/* 331062306a36Sopenharmony_ci * simple attribute files 331162306a36Sopenharmony_ci * 331262306a36Sopenharmony_ci * These attributes behave similar to those in sysfs: 331362306a36Sopenharmony_ci * 331462306a36Sopenharmony_ci * Writing to an attribute immediately sets a value, an open file can be 331562306a36Sopenharmony_ci * written to multiple times. 331662306a36Sopenharmony_ci * 331762306a36Sopenharmony_ci * Reading from an attribute creates a buffer from the value that might get 331862306a36Sopenharmony_ci * read with multiple read calls. When the attribute has been read 331962306a36Sopenharmony_ci * completely, no further read calls are possible until the file is opened 332062306a36Sopenharmony_ci * again. 332162306a36Sopenharmony_ci * 332262306a36Sopenharmony_ci * All attributes contain a text representation of a numeric value 332362306a36Sopenharmony_ci * that are accessed with the get() and set() functions. 332462306a36Sopenharmony_ci */ 332562306a36Sopenharmony_ci#define DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed) \ 332662306a36Sopenharmony_cistatic int __fops ## _open(struct inode *inode, struct file *file) \ 332762306a36Sopenharmony_ci{ \ 332862306a36Sopenharmony_ci __simple_attr_check_format(__fmt, 0ull); \ 332962306a36Sopenharmony_ci return simple_attr_open(inode, file, __get, __set, __fmt); \ 333062306a36Sopenharmony_ci} \ 333162306a36Sopenharmony_cistatic const struct file_operations __fops = { \ 333262306a36Sopenharmony_ci .owner = THIS_MODULE, \ 333362306a36Sopenharmony_ci .open = __fops ## _open, \ 333462306a36Sopenharmony_ci .release = simple_attr_release, \ 333562306a36Sopenharmony_ci .read = simple_attr_read, \ 333662306a36Sopenharmony_ci .write = (__is_signed) ? simple_attr_write_signed : simple_attr_write, \ 333762306a36Sopenharmony_ci .llseek = generic_file_llseek, \ 333862306a36Sopenharmony_ci} 333962306a36Sopenharmony_ci 334062306a36Sopenharmony_ci#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ 334162306a36Sopenharmony_ci DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false) 334262306a36Sopenharmony_ci 334362306a36Sopenharmony_ci#define DEFINE_SIMPLE_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \ 334462306a36Sopenharmony_ci DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true) 334562306a36Sopenharmony_ci 334662306a36Sopenharmony_cistatic inline __printf(1, 2) 334762306a36Sopenharmony_civoid __simple_attr_check_format(const char *fmt, ...) 334862306a36Sopenharmony_ci{ 334962306a36Sopenharmony_ci /* don't do anything, just let the compiler check the arguments; */ 335062306a36Sopenharmony_ci} 335162306a36Sopenharmony_ci 335262306a36Sopenharmony_ciint simple_attr_open(struct inode *inode, struct file *file, 335362306a36Sopenharmony_ci int (*get)(void *, u64 *), int (*set)(void *, u64), 335462306a36Sopenharmony_ci const char *fmt); 335562306a36Sopenharmony_ciint simple_attr_release(struct inode *inode, struct file *file); 335662306a36Sopenharmony_cissize_t simple_attr_read(struct file *file, char __user *buf, 335762306a36Sopenharmony_ci size_t len, loff_t *ppos); 335862306a36Sopenharmony_cissize_t simple_attr_write(struct file *file, const char __user *buf, 335962306a36Sopenharmony_ci size_t len, loff_t *ppos); 336062306a36Sopenharmony_cissize_t simple_attr_write_signed(struct file *file, const char __user *buf, 336162306a36Sopenharmony_ci size_t len, loff_t *ppos); 336262306a36Sopenharmony_ci 336362306a36Sopenharmony_cistruct ctl_table; 336462306a36Sopenharmony_ciint __init list_bdev_fs_names(char *buf, size_t size); 336562306a36Sopenharmony_ci 336662306a36Sopenharmony_ci#define __FMODE_EXEC ((__force int) FMODE_EXEC) 336762306a36Sopenharmony_ci#define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY) 336862306a36Sopenharmony_ci 336962306a36Sopenharmony_ci#define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE]) 337062306a36Sopenharmony_ci#define OPEN_FMODE(flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE) | \ 337162306a36Sopenharmony_ci (flag & __FMODE_NONOTIFY))) 337262306a36Sopenharmony_ci 337362306a36Sopenharmony_cistatic inline bool is_sxid(umode_t mode) 337462306a36Sopenharmony_ci{ 337562306a36Sopenharmony_ci return mode & (S_ISUID | S_ISGID); 337662306a36Sopenharmony_ci} 337762306a36Sopenharmony_ci 337862306a36Sopenharmony_cistatic inline int check_sticky(struct mnt_idmap *idmap, 337962306a36Sopenharmony_ci struct inode *dir, struct inode *inode) 338062306a36Sopenharmony_ci{ 338162306a36Sopenharmony_ci if (!(dir->i_mode & S_ISVTX)) 338262306a36Sopenharmony_ci return 0; 338362306a36Sopenharmony_ci 338462306a36Sopenharmony_ci return __check_sticky(idmap, dir, inode); 338562306a36Sopenharmony_ci} 338662306a36Sopenharmony_ci 338762306a36Sopenharmony_cistatic inline void inode_has_no_xattr(struct inode *inode) 338862306a36Sopenharmony_ci{ 338962306a36Sopenharmony_ci if (!is_sxid(inode->i_mode) && (inode->i_sb->s_flags & SB_NOSEC)) 339062306a36Sopenharmony_ci inode->i_flags |= S_NOSEC; 339162306a36Sopenharmony_ci} 339262306a36Sopenharmony_ci 339362306a36Sopenharmony_cistatic inline bool is_root_inode(struct inode *inode) 339462306a36Sopenharmony_ci{ 339562306a36Sopenharmony_ci return inode == inode->i_sb->s_root->d_inode; 339662306a36Sopenharmony_ci} 339762306a36Sopenharmony_ci 339862306a36Sopenharmony_cistatic inline bool dir_emit(struct dir_context *ctx, 339962306a36Sopenharmony_ci const char *name, int namelen, 340062306a36Sopenharmony_ci u64 ino, unsigned type) 340162306a36Sopenharmony_ci{ 340262306a36Sopenharmony_ci return ctx->actor(ctx, name, namelen, ctx->pos, ino, type); 340362306a36Sopenharmony_ci} 340462306a36Sopenharmony_cistatic inline bool dir_emit_dot(struct file *file, struct dir_context *ctx) 340562306a36Sopenharmony_ci{ 340662306a36Sopenharmony_ci return ctx->actor(ctx, ".", 1, ctx->pos, 340762306a36Sopenharmony_ci file->f_path.dentry->d_inode->i_ino, DT_DIR); 340862306a36Sopenharmony_ci} 340962306a36Sopenharmony_cistatic inline bool dir_emit_dotdot(struct file *file, struct dir_context *ctx) 341062306a36Sopenharmony_ci{ 341162306a36Sopenharmony_ci return ctx->actor(ctx, "..", 2, ctx->pos, 341262306a36Sopenharmony_ci parent_ino(file->f_path.dentry), DT_DIR); 341362306a36Sopenharmony_ci} 341462306a36Sopenharmony_cistatic inline bool dir_emit_dots(struct file *file, struct dir_context *ctx) 341562306a36Sopenharmony_ci{ 341662306a36Sopenharmony_ci if (ctx->pos == 0) { 341762306a36Sopenharmony_ci if (!dir_emit_dot(file, ctx)) 341862306a36Sopenharmony_ci return false; 341962306a36Sopenharmony_ci ctx->pos = 1; 342062306a36Sopenharmony_ci } 342162306a36Sopenharmony_ci if (ctx->pos == 1) { 342262306a36Sopenharmony_ci if (!dir_emit_dotdot(file, ctx)) 342362306a36Sopenharmony_ci return false; 342462306a36Sopenharmony_ci ctx->pos = 2; 342562306a36Sopenharmony_ci } 342662306a36Sopenharmony_ci return true; 342762306a36Sopenharmony_ci} 342862306a36Sopenharmony_cistatic inline bool dir_relax(struct inode *inode) 342962306a36Sopenharmony_ci{ 343062306a36Sopenharmony_ci inode_unlock(inode); 343162306a36Sopenharmony_ci inode_lock(inode); 343262306a36Sopenharmony_ci return !IS_DEADDIR(inode); 343362306a36Sopenharmony_ci} 343462306a36Sopenharmony_ci 343562306a36Sopenharmony_cistatic inline bool dir_relax_shared(struct inode *inode) 343662306a36Sopenharmony_ci{ 343762306a36Sopenharmony_ci inode_unlock_shared(inode); 343862306a36Sopenharmony_ci inode_lock_shared(inode); 343962306a36Sopenharmony_ci return !IS_DEADDIR(inode); 344062306a36Sopenharmony_ci} 344162306a36Sopenharmony_ci 344262306a36Sopenharmony_ciextern bool path_noexec(const struct path *path); 344362306a36Sopenharmony_ciextern void inode_nohighmem(struct inode *inode); 344462306a36Sopenharmony_ci 344562306a36Sopenharmony_ci/* mm/fadvise.c */ 344662306a36Sopenharmony_ciextern int vfs_fadvise(struct file *file, loff_t offset, loff_t len, 344762306a36Sopenharmony_ci int advice); 344862306a36Sopenharmony_ciextern int generic_fadvise(struct file *file, loff_t offset, loff_t len, 344962306a36Sopenharmony_ci int advice); 345062306a36Sopenharmony_ci 345162306a36Sopenharmony_ci#endif /* _LINUX_FS_H */ 3452