1b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds#ifndef _LINUX_FS_H
31da177e4SLinus Torvalds#define _LINUX_FS_H
41da177e4SLinus Torvalds
51da177e4SLinus Torvalds#include <linux/linkage.h>
65dd43ce2SIngo Molnar#include <linux/wait_bit.h>
71da177e4SLinus Torvalds#include <linux/kdev_t.h>
81da177e4SLinus Torvalds#include <linux/dcache.h>
93f8206d4SAl Viro#include <linux/path.h>
101da177e4SLinus Torvalds#include <linux/stat.h>
111da177e4SLinus Torvalds#include <linux/cache.h>
121da177e4SLinus Torvalds#include <linux/list.h>
13bc3b14cbSDave Chinner#include <linux/list_lru.h>
144f5e65a1SOleg Nesterov#include <linux/llist.h>
151da177e4SLinus Torvalds#include <linux/radix-tree.h>
16b93b0163SMatthew Wilcox#include <linux/xarray.h>
176b2dbba8SMichel Lespinasse#include <linux/rbtree.h>
181da177e4SLinus Torvalds#include <linux/init.h>
19914e2637SAl Viro#include <linux/pid.h>
20187f1882SPaul Gortmaker#include <linux/bug.h>
211b1dcc1bSJes Sorensen#include <linux/mutex.h>
22c8c06efaSDavidlohr Bueso#include <linux/rwsem.h>
23baabda26SDan Williams#include <linux/mm_types.h>
243bd858abSSatyam Sharma#include <linux/capability.h>
256188e10dSMatthew Wilcox#include <linux/semaphore.h>
26c75b1d94SJens Axboe#include <linux/fcntl.h>
27ceb5bdc2SNicholas Piggin#include <linux/rculist_bl.h>
2807b8ce1eSAl Viro#include <linux/atomic.h>
2983aeeadaSKonstantin Khlebnikov#include <linux/shrinker.h>
30c1aab02dSStephen Rothwell#include <linux/migrate_mode.h>
3192361636SEric W. Biederman#include <linux/uidgid.h>
325accdf82SJan Kara#include <linux/lockdep.h>
33c2b1ad80SJens Axboe#include <linux/percpu-rwsem.h>
34853b39a7SOleg Nesterov#include <linux/workqueue.h>
35fceef393SAl Viro#include <linux/delayed_call.h>
3685787090SChristoph Hellwig#include <linux/uuid.h>
375660e13dSJeff Layton#include <linux/errseq.h>
38d9a08a9eSAdam Manzanares#include <linux/ioprio.h>
39bbe7449eSPhillip Potter#include <linux/fs_types.h>
40f1fffbd4SRasmus Villemoes#include <linux/build_bug.h>
41f1fffbd4SRasmus Villemoes#include <linux/stddef.h>
42a6435940SChristian Brauner#include <linux/mount.h>
43e6c9a714SChristian Brauner#include <linux/cred.h>
44a793d79eSChristian Brauner#include <linux/mnt_idmapping.h>
451da177e4SLinus Torvalds
461da177e4SLinus Torvalds#include <asm/byteorder.h>
47607ca46eSDavid Howells#include <uapi/linux/fs.h>
481da177e4SLinus Torvalds
49b83ae6d4SChristoph Hellwigstruct backing_dev_info;
5052ebea74STejun Heostruct bdi_writeback;
512f8b5444SChristoph Hellwigstruct bio;
525a72e899SJens Axboestruct io_comp_batch;
53a5694255SChristoph Hellwigstruct export_operations;
5410c5db28SChristoph Hellwigstruct fiemap_extent_info;
55a885c8c4SChristoph Hellwigstruct hd_geometry;
561da177e4SLinus Torvaldsstruct iovec;
5792198f7eSChristoph Hellwigstruct kiocb;
5857cc7215SAlexey Dobriyanstruct kobject;
591da177e4SLinus Torvaldsstruct pipe_inode_info;
601da177e4SLinus Torvaldsstruct poll_table_struct;
611da177e4SLinus Torvaldsstruct kstatfs;
621da177e4SLinus Torvaldsstruct vm_area_struct;
631da177e4SLinus Torvaldsstruct vfsmount;
64745ca247SDavid Howellsstruct cred;
65a509bc1aSMel Gormanstruct swap_info_struct;
6655985dd7SCyrill Gorcunovstruct seq_file;
677b7a8665SChristoph Hellwigstruct workqueue_struct;
683b93f911SAl Virostruct iov_iter;
690b81d077SJaegeuk Kimstruct fscrypt_info;
700b81d077SJaegeuk Kimstruct fscrypt_operations;
715585f2afSEric Biggersstruct fsverity_info;
725585f2afSEric Biggersstruct fsverity_operations;
73f3a09c92SAl Virostruct fs_context;
74d7167b14SAl Virostruct fs_parameter_spec;
754c5b4799SMiklos Szeredistruct fileattr;
761da177e4SLinus Torvalds
7774bf17cfSDenis Chengextern void __init inode_init(void);
781da177e4SLinus Torvaldsextern void __init inode_init_early(void);
794248b0daSMel Gormanextern void __init files_init(void);
804248b0daSMel Gormanextern void __init files_maxfiles_init(void);
811da177e4SLinus Torvalds
82518de9b3SEric Dumazetextern unsigned long get_max_files(void);
839b80a184SAlexey Dobriyanextern unsigned int sysctl_nr_open;
84dded4f4dSJan Engelhardt
85ddef7ed2SChristoph Hellwigtypedef __kernel_rwf_t rwf_t;
86ddef7ed2SChristoph Hellwig
871da177e4SLinus Torvaldsstruct buffer_head;
881da177e4SLinus Torvaldstypedef int (get_block_t)(struct inode *inode, sector_t iblock,
891da177e4SLinus Torvalds			struct buffer_head *bh_result, int create);
90187372a3SChristoph Hellwigtypedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
917b7a8665SChristoph Hellwig			ssize_t bytes, void *private);
921da177e4SLinus Torvalds
93bbc1096aSDavid Howells#define MAY_EXEC		0x00000001
94bbc1096aSDavid Howells#define MAY_WRITE		0x00000002
95bbc1096aSDavid Howells#define MAY_READ		0x00000004
96bbc1096aSDavid Howells#define MAY_APPEND		0x00000008
97bbc1096aSDavid Howells#define MAY_ACCESS		0x00000010
98bbc1096aSDavid Howells#define MAY_OPEN		0x00000020
99bbc1096aSDavid Howells#define MAY_CHDIR		0x00000040
100bbc1096aSDavid Howells/* called from RCU mode, don't block */
101bbc1096aSDavid Howells#define MAY_NOT_BLOCK		0x00000080
102bbc1096aSDavid Howells
103bbc1096aSDavid Howells/*
104bbc1096aSDavid Howells * flags in file.f_mode.  Note that FMODE_READ and FMODE_WRITE must correspond
10575abe329SLi Qiang * to O_WRONLY and O_RDWR via the strange trick in do_dentry_open()
106bbc1096aSDavid Howells */
107bbc1096aSDavid Howells
108bbc1096aSDavid Howells/* file is open for reading */
109bbc1096aSDavid Howells#define FMODE_READ		((__force fmode_t)0x1)
110bbc1096aSDavid Howells/* file is open for writing */
111bbc1096aSDavid Howells#define FMODE_WRITE		((__force fmode_t)0x2)
112bbc1096aSDavid Howells/* file is seekable */
113bbc1096aSDavid Howells#define FMODE_LSEEK		((__force fmode_t)0x4)
114bbc1096aSDavid Howells/* file can be accessed using pread */
115bbc1096aSDavid Howells#define FMODE_PREAD		((__force fmode_t)0x8)
116bbc1096aSDavid Howells/* file can be accessed using pwrite */
117bbc1096aSDavid Howells#define FMODE_PWRITE		((__force fmode_t)0x10)
118bbc1096aSDavid Howells/* File is opened for execution with sys_execve / sys_uselib */
119bbc1096aSDavid Howells#define FMODE_EXEC		((__force fmode_t)0x20)
120bbc1096aSDavid Howells/* File is opened with O_NDELAY (only set for block devices) */
121bbc1096aSDavid Howells#define FMODE_NDELAY		((__force fmode_t)0x40)
122bbc1096aSDavid Howells/* File is opened with O_EXCL (only set for block devices) */
123bbc1096aSDavid Howells#define FMODE_EXCL		((__force fmode_t)0x80)
124bbc1096aSDavid Howells/* File is opened using open(.., 3, ..) and is writeable only for ioctls
125bbc1096aSDavid Howells   (specialy hack for floppy.c) */
126bbc1096aSDavid Howells#define FMODE_WRITE_IOCTL	((__force fmode_t)0x100)
127bbc1096aSDavid Howells/* 32bit hashes as llseek() offset (for directories) */
128bbc1096aSDavid Howells#define FMODE_32BITHASH         ((__force fmode_t)0x200)
129bbc1096aSDavid Howells/* 64bit hashes as llseek() offset (for directories) */
130bbc1096aSDavid Howells#define FMODE_64BITHASH         ((__force fmode_t)0x400)
131bbc1096aSDavid Howells
132bbc1096aSDavid Howells/*
133bbc1096aSDavid Howells * Don't update ctime and mtime.
134bbc1096aSDavid Howells *
135bbc1096aSDavid Howells * Currently a special hack for the XFS open_by_handle ioctl, but we'll
136bbc1096aSDavid Howells * hopefully graduate it to a proper O_CMTIME flag supported by open(2) soon.
137bbc1096aSDavid Howells */
138bbc1096aSDavid Howells#define FMODE_NOCMTIME		((__force fmode_t)0x800)
139bbc1096aSDavid Howells
140bbc1096aSDavid Howells/* Expect random access pattern */
141bbc1096aSDavid Howells#define FMODE_RANDOM		((__force fmode_t)0x1000)
142bbc1096aSDavid Howells
143bbcd53c9SDavid Hildenbrand/* File is huge (eg. /dev/mem): treat loff_t as unsigned */
144bbc1096aSDavid Howells#define FMODE_UNSIGNED_OFFSET	((__force fmode_t)0x2000)
145bbc1096aSDavid Howells
146bbc1096aSDavid Howells/* File is opened with O_PATH; almost nothing can be done with it */
147bbc1096aSDavid Howells#define FMODE_PATH		((__force fmode_t)0x4000)
148bbc1096aSDavid Howells
1492be7d348SLinus Torvalds/* File needs atomic accesses to f_pos */
1502be7d348SLinus Torvalds#define FMODE_ATOMIC_POS	((__force fmode_t)0x8000)
15183f936c7SAl Viro/* Write access to underlying fs */
15283f936c7SAl Viro#define FMODE_WRITER		((__force fmode_t)0x10000)
1537f7f25e8SAl Viro/* Has read method(s) */
1547f7f25e8SAl Viro#define FMODE_CAN_READ          ((__force fmode_t)0x20000)
1557f7f25e8SAl Viro/* Has write method(s) */
1567f7f25e8SAl Viro#define FMODE_CAN_WRITE         ((__force fmode_t)0x40000)
1579c225f26SLinus Torvalds
158f5d11409SAl Viro#define FMODE_OPENED		((__force fmode_t)0x80000)
15973a09dd9SAl Viro#define FMODE_CREATED		((__force fmode_t)0x100000)
160f5d11409SAl Viro
16110dce8afSKirill Smelkov/* File is stream-like */
16210dce8afSKirill Smelkov#define FMODE_STREAM		((__force fmode_t)0x200000)
16310dce8afSKirill Smelkov
164bbc1096aSDavid Howells/* File was opened by fanotify and shouldn't generate fanotify events */
16575069f2bSDavid Drysdale#define FMODE_NONOTIFY		((__force fmode_t)0x4000000)
166bbc1096aSDavid Howells
16791f9943eSChristoph Hellwig/* File is capable of returning -EAGAIN if I/O will block */
168a07b2000SAl Viro#define FMODE_NOWAIT		((__force fmode_t)0x8000000)
169a07b2000SAl Viro
170a07b2000SAl Viro/* File represents mount that needs unmounting */
171a07b2000SAl Viro#define FMODE_NEED_UNMOUNT	((__force fmode_t)0x10000000)
172b745fafaSGoldwyn Rodrigues
173d3b1084dSMiklos Szeredi/* File does not contribute to nr_files count */
174a07b2000SAl Viro#define FMODE_NOACCOUNT		((__force fmode_t)0x20000000)
175d3b1084dSMiklos Szeredi
176c2a25ec0SJens Axboe/* File supports async buffered reads */
177c2a25ec0SJens Axboe#define FMODE_BUF_RASYNC	((__force fmode_t)0x40000000)
178c2a25ec0SJens Axboe
1791da177e4SLinus Torvalds/*
1801da177e4SLinus Torvalds * Attribute flags.  These should be or-ed together to figure out what
1811da177e4SLinus Torvalds * has been changed!
1821da177e4SLinus Torvalds */
1839767d749SMiklos Szeredi#define ATTR_MODE	(1 << 0)
1849767d749SMiklos Szeredi#define ATTR_UID	(1 << 1)
1859767d749SMiklos Szeredi#define ATTR_GID	(1 << 2)
1869767d749SMiklos Szeredi#define ATTR_SIZE	(1 << 3)
1879767d749SMiklos Szeredi#define ATTR_ATIME	(1 << 4)
1889767d749SMiklos Szeredi#define ATTR_MTIME	(1 << 5)
1899767d749SMiklos Szeredi#define ATTR_CTIME	(1 << 6)
1909767d749SMiklos Szeredi#define ATTR_ATIME_SET	(1 << 7)
1919767d749SMiklos Szeredi#define ATTR_MTIME_SET	(1 << 8)
1929767d749SMiklos Szeredi#define ATTR_FORCE	(1 << 9) /* Not a change, but a change it */
1939767d749SMiklos Szeredi#define ATTR_KILL_SUID	(1 << 11)
1949767d749SMiklos Szeredi#define ATTR_KILL_SGID	(1 << 12)
1959767d749SMiklos Szeredi#define ATTR_FILE	(1 << 13)
1969767d749SMiklos Szeredi#define ATTR_KILL_PRIV	(1 << 14)
1979767d749SMiklos Szeredi#define ATTR_OPEN	(1 << 15) /* Truncating from open(O_TRUNC) */
1989767d749SMiklos Szeredi#define ATTR_TIMES_SET	(1 << 16)
199f2b20f6eSMiklos Szeredi#define ATTR_TOUCH	(1 << 17)
2001da177e4SLinus Torvalds
201787fb6bcSMiklos Szeredi/*
202787fb6bcSMiklos Szeredi * Whiteout is represented by a char device.  The following constants define the
203787fb6bcSMiklos Szeredi * mode and device number to use.
204787fb6bcSMiklos Szeredi */
205787fb6bcSMiklos Szeredi#define WHITEOUT_MODE 0
206787fb6bcSMiklos Szeredi#define WHITEOUT_DEV 0
207787fb6bcSMiklos Szeredi
2081da177e4SLinus Torvalds/*
2091da177e4SLinus Torvalds * This is the Inode Attributes structure, used for notify_change().  It
2101da177e4SLinus Torvalds * uses the above definitions as flags, to know which values have changed.
2111da177e4SLinus Torvalds * Also, in this manner, a Filesystem can look at only the values it cares
2121da177e4SLinus Torvalds * about.  Basically, these are the attributes that the VFS layer can
2131da177e4SLinus Torvalds * request to change from the FS layer.
2141da177e4SLinus Torvalds *
2151da177e4SLinus Torvalds * Derek Atkins <warlord@MIT.EDU> 94-10-20
2161da177e4SLinus Torvalds */
2171da177e4SLinus Torvaldsstruct iattr {
2181da177e4SLinus Torvalds	unsigned int	ia_valid;
2191da177e4SLinus Torvalds	umode_t		ia_mode;
22092361636SEric W. Biederman	kuid_t		ia_uid;
22192361636SEric W. Biederman	kgid_t		ia_gid;
2221da177e4SLinus Torvalds	loff_t		ia_size;
22395582b00SDeepa Dinamani	struct timespec64 ia_atime;
22495582b00SDeepa Dinamani	struct timespec64 ia_mtime;
22595582b00SDeepa Dinamani	struct timespec64 ia_ctime;
226cc4e69deSMiklos Szeredi
227cc4e69deSMiklos Szeredi	/*
22825985edcSLucas De Marchi	 * Not an attribute, but an auxiliary info for filesystems wanting to
229cc4e69deSMiklos Szeredi	 * implement an ftruncate() like method.  NOTE: filesystem should
230cc4e69deSMiklos Szeredi	 * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
231cc4e69deSMiklos Szeredi	 */
232cc4e69deSMiklos Szeredi	struct file	*ia_file;
2331da177e4SLinus Torvalds};
2341da177e4SLinus Torvalds
2351da177e4SLinus Torvalds/*
2361da177e4SLinus Torvalds * Includes for diskquotas.
2371da177e4SLinus Torvalds */
2381da177e4SLinus Torvalds#include <linux/quota.h>
2391da177e4SLinus Torvalds
24069c433edSMiklos Szeredi/*
24169c433edSMiklos Szeredi * Maximum number of layers of fs stack.  Needs to be limited to
24269c433edSMiklos Szeredi * prevent kernel stack overflow
24369c433edSMiklos Szeredi */
24469c433edSMiklos Szeredi#define FILESYSTEM_MAX_STACK_DEPTH 2
24569c433edSMiklos Szeredi
246994fc28cSZach Brown/**
247994fc28cSZach Brown * enum positive_aop_returns - aop return codes with specific semantics
248994fc28cSZach Brown *
249994fc28cSZach Brown * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has
250994fc28cSZach Brown * 			    completed, that the page is still locked, and
251994fc28cSZach Brown * 			    should be considered active.  The VM uses this hint
252994fc28cSZach Brown * 			    to return the page to the active list -- it won't
253994fc28cSZach Brown * 			    be a candidate for writeback again in the near
254994fc28cSZach Brown * 			    future.  Other callers must be careful to unlock
255994fc28cSZach Brown * 			    the page if they get this return.  Returned by
256994fc28cSZach Brown * 			    writepage();
257994fc28cSZach Brown *
258994fc28cSZach Brown * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has
259994fc28cSZach Brown *  			unlocked it and the page might have been truncated.
260994fc28cSZach Brown *  			The caller should back up to acquiring a new page and
261994fc28cSZach Brown *  			trying again.  The aop will be taking reasonable
262994fc28cSZach Brown *  			precautions not to livelock.  If the caller held a page
263994fc28cSZach Brown *  			reference, it should drop it before retrying.  Returned
26455144768SNicholas Piggin *  			by readpage().
265994fc28cSZach Brown *
266994fc28cSZach Brown * address_space_operation functions return these large constants to indicate
267994fc28cSZach Brown * special semantics to the caller.  These are much larger than the bytes in a
268994fc28cSZach Brown * page to allow for functions that return the number of bytes operated on in a
269994fc28cSZach Brown * given page.
270994fc28cSZach Brown */
271994fc28cSZach Brown
272994fc28cSZach Brownenum positive_aop_returns {
273994fc28cSZach Brown	AOP_WRITEPAGE_ACTIVATE	= 0x80000,
274994fc28cSZach Brown	AOP_TRUNCATED_PAGE	= 0x80001,
275994fc28cSZach Brown};
276994fc28cSZach Brown
277c718a975STetsuo Handa#define AOP_FLAG_CONT_EXPAND		0x0001 /* called from cont_expand */
278c718a975STetsuo Handa#define AOP_FLAG_NOFS			0x0002 /* used by filesystem to direct
27954566b2cSNicholas Piggin						* helper code (eg buffer layer)
28054566b2cSNicholas Piggin						* to clear GFP_FS from alloc */
281afddba49SNicholas Piggin
2821da177e4SLinus Torvalds/*
2831da177e4SLinus Torvalds * oh the beauties of C type declarations.
2841da177e4SLinus Torvalds */
2851da177e4SLinus Torvaldsstruct page;
2861da177e4SLinus Torvaldsstruct address_space;
2871da177e4SLinus Torvaldsstruct writeback_control;
2888151b4c8SMatthew Wilcox (Oracle)struct readahead_control;
2891da177e4SLinus Torvalds
290c75b1d94SJens Axboe/*
291c75b1d94SJens Axboe * Write life time hint values.
29269448867SAmir Goldstein * Stored in struct inode as u8.
293c75b1d94SJens Axboe */
294c75b1d94SJens Axboeenum rw_hint {
295c75b1d94SJens Axboe	WRITE_LIFE_NOT_SET	= 0,
301c75b1d94SJens Axboe};
302c75b1d94SJens Axboe
303ce71bfeaSJens Axboe/* Match RWF_* bits to IOCB bits */
304ce71bfeaSJens Axboe#define IOCB_HIPRI		(__force int) RWF_HIPRI
305ce71bfeaSJens Axboe#define IOCB_DSYNC		(__force int) RWF_DSYNC
306ce71bfeaSJens Axboe#define IOCB_SYNC		(__force int) RWF_SYNC
307ce71bfeaSJens Axboe#define IOCB_NOWAIT		(__force int) RWF_NOWAIT
308ce71bfeaSJens Axboe#define IOCB_APPEND		(__force int) RWF_APPEND
309ce71bfeaSJens Axboe
310ce71bfeaSJens Axboe/* non-RWF related bits - start at 16 */
311ce71bfeaSJens Axboe#define IOCB_EVENTFD		(1 << 16)
312ce71bfeaSJens Axboe#define IOCB_DIRECT		(1 << 17)
313ce71bfeaSJens Axboe#define IOCB_WRITE		(1 << 18)
314dd3e6d50SJens Axboe/* iocb->ki_waitq is valid */
315ce71bfeaSJens Axboe#define IOCB_WAITQ		(1 << 19)
316ce71bfeaSJens Axboe#define IOCB_NOIO		(1 << 20)
3176c7ef543SJens Axboe/* can use bio alloc cache */
3186c7ef543SJens Axboe#define IOCB_ALLOC_CACHE	(1 << 21)
319e2e40f2cSChristoph Hellwig
320e2e40f2cSChristoph Hellwigstruct kiocb {
321e2e40f2cSChristoph Hellwig	struct file		*ki_filp;
32284c4e1f8SLinus Torvalds
32384c4e1f8SLinus Torvalds	/* The 'ki_filp' pointer is shared in a union for aio */
32484c4e1f8SLinus Torvalds	randomized_struct_fields_start
32584c4e1f8SLinus Torvalds
326e2e40f2cSChristoph Hellwig	loff_t			ki_pos;
3276b19b766SJens Axboe	void (*ki_complete)(struct kiocb *iocb, long ret);
328e2e40f2cSChristoph Hellwig	void			*private;
329e2e40f2cSChristoph Hellwig	int			ki_flags;
330fc28724dSAdam Manzanares	u16			ki_hint;
331d9a08a9eSAdam Manzanares	u16			ki_ioprio; /* See linux/ioprio.h */
3323e08773cSChristoph Hellwig	struct wait_page_queue	*ki_waitq; /* for async buffered IO */
33384c4e1f8SLinus Torvalds	randomized_struct_fields_end
33484c4e1f8SLinus Torvalds};
335e2e40f2cSChristoph Hellwig
336e2e40f2cSChristoph Hellwigstatic inline bool is_sync_kiocb(struct kiocb *kiocb)
337e2e40f2cSChristoph Hellwig{
338e2e40f2cSChristoph Hellwig	return kiocb->ki_complete == NULL;
339e2e40f2cSChristoph Hellwig}
340e2e40f2cSChristoph Hellwig