162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/* fs/ internal definitions
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
562306a36Sopenharmony_ci * Written by David Howells (dhowells@redhat.com)
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_cistruct super_block;
962306a36Sopenharmony_cistruct file_system_type;
1062306a36Sopenharmony_cistruct iomap;
1162306a36Sopenharmony_cistruct iomap_ops;
1262306a36Sopenharmony_cistruct linux_binprm;
1362306a36Sopenharmony_cistruct path;
1462306a36Sopenharmony_cistruct mount;
1562306a36Sopenharmony_cistruct shrink_control;
1662306a36Sopenharmony_cistruct fs_context;
1762306a36Sopenharmony_cistruct pipe_inode_info;
1862306a36Sopenharmony_cistruct iov_iter;
1962306a36Sopenharmony_cistruct mnt_idmap;
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/*
2262306a36Sopenharmony_ci * block/bdev.c
2362306a36Sopenharmony_ci */
2462306a36Sopenharmony_ci#ifdef CONFIG_BLOCK
2562306a36Sopenharmony_ciextern void __init bdev_cache_init(void);
2662306a36Sopenharmony_ci#else
2762306a36Sopenharmony_cistatic inline void bdev_cache_init(void)
2862306a36Sopenharmony_ci{
2962306a36Sopenharmony_ci}
3062306a36Sopenharmony_ci#endif /* CONFIG_BLOCK */
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci/*
3362306a36Sopenharmony_ci * buffer.c
3462306a36Sopenharmony_ci */
3562306a36Sopenharmony_ciint __block_write_begin_int(struct folio *folio, loff_t pos, unsigned len,
3662306a36Sopenharmony_ci		get_block_t *get_block, const struct iomap *iomap);
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/*
3962306a36Sopenharmony_ci * char_dev.c
4062306a36Sopenharmony_ci */
4162306a36Sopenharmony_ciextern void __init chrdev_init(void);
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/*
4462306a36Sopenharmony_ci * fs_context.c
4562306a36Sopenharmony_ci */
4662306a36Sopenharmony_ciextern const struct fs_context_operations legacy_fs_context_ops;
4762306a36Sopenharmony_ciextern int parse_monolithic_mount_data(struct fs_context *, void *);
4862306a36Sopenharmony_ciextern void vfs_clean_context(struct fs_context *fc);
4962306a36Sopenharmony_ciextern int finish_clean_context(struct fs_context *fc);
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci/*
5262306a36Sopenharmony_ci * namei.c
5362306a36Sopenharmony_ci */
5462306a36Sopenharmony_ciextern int filename_lookup(int dfd, struct filename *name, unsigned flags,
5562306a36Sopenharmony_ci			   struct path *path, struct path *root);
5662306a36Sopenharmony_ciint do_rmdir(int dfd, struct filename *name);
5762306a36Sopenharmony_ciint do_unlinkat(int dfd, struct filename *name);
5862306a36Sopenharmony_ciint may_linkat(struct mnt_idmap *idmap, const struct path *link);
5962306a36Sopenharmony_ciint do_renameat2(int olddfd, struct filename *oldname, int newdfd,
6062306a36Sopenharmony_ci		 struct filename *newname, unsigned int flags);
6162306a36Sopenharmony_ciint do_mkdirat(int dfd, struct filename *name, umode_t mode);
6262306a36Sopenharmony_ciint do_symlinkat(struct filename *from, int newdfd, struct filename *to);
6362306a36Sopenharmony_ciint do_linkat(int olddfd, struct filename *old, int newdfd,
6462306a36Sopenharmony_ci			struct filename *new, int flags);
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci/*
6762306a36Sopenharmony_ci * namespace.c
6862306a36Sopenharmony_ci */
6962306a36Sopenharmony_ciextern struct vfsmount *lookup_mnt(const struct path *);
7062306a36Sopenharmony_ciextern int finish_automount(struct vfsmount *, const struct path *);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ciextern int sb_prepare_remount_readonly(struct super_block *);
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ciextern void __init mnt_init(void);
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ciextern int __mnt_want_write_file(struct file *);
7762306a36Sopenharmony_ciextern void __mnt_drop_write_file(struct file *);
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ciextern void dissolve_on_fput(struct vfsmount *);
8062306a36Sopenharmony_ciextern bool may_mount(void);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ciint path_mount(const char *dev_name, struct path *path,
8362306a36Sopenharmony_ci		const char *type_page, unsigned long flags, void *data_page);
8462306a36Sopenharmony_ciint path_umount(struct path *path, int flags);
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/*
8762306a36Sopenharmony_ci * fs_struct.c
8862306a36Sopenharmony_ci */
8962306a36Sopenharmony_ciextern void chroot_fs_refs(const struct path *, const struct path *);
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci/*
9262306a36Sopenharmony_ci * file_table.c
9362306a36Sopenharmony_ci */
9462306a36Sopenharmony_cistruct file *alloc_empty_file(int flags, const struct cred *cred);
9562306a36Sopenharmony_cistruct file *alloc_empty_file_noaccount(int flags, const struct cred *cred);
9662306a36Sopenharmony_cistruct file *alloc_empty_backing_file(int flags, const struct cred *cred);
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_cistatic inline void put_file_access(struct file *file)
9962306a36Sopenharmony_ci{
10062306a36Sopenharmony_ci	if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
10162306a36Sopenharmony_ci		i_readcount_dec(file->f_inode);
10262306a36Sopenharmony_ci	} else if (file->f_mode & FMODE_WRITER) {
10362306a36Sopenharmony_ci		put_write_access(file->f_inode);
10462306a36Sopenharmony_ci		__mnt_drop_write(file->f_path.mnt);
10562306a36Sopenharmony_ci	}
10662306a36Sopenharmony_ci}
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/*
10962306a36Sopenharmony_ci * super.c
11062306a36Sopenharmony_ci */
11162306a36Sopenharmony_ciextern int reconfigure_super(struct fs_context *);
11262306a36Sopenharmony_ciextern bool super_trylock_shared(struct super_block *sb);
11362306a36Sopenharmony_cistruct super_block *user_get_super(dev_t, bool excl);
11462306a36Sopenharmony_civoid put_super(struct super_block *sb);
11562306a36Sopenharmony_ciextern bool mount_capable(struct fs_context *);
11662306a36Sopenharmony_ciint sb_init_dio_done_wq(struct super_block *sb);
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/*
11962306a36Sopenharmony_ci * Prepare superblock for changing its read-only state (i.e., either remount
12062306a36Sopenharmony_ci * read-write superblock read-only or vice versa). After this function returns
12162306a36Sopenharmony_ci * mnt_is_readonly() will return true for any mount of the superblock if its
12262306a36Sopenharmony_ci * caller is able to observe any changes done by the remount. This holds until
12362306a36Sopenharmony_ci * sb_end_ro_state_change() is called.
12462306a36Sopenharmony_ci */
12562306a36Sopenharmony_cistatic inline void sb_start_ro_state_change(struct super_block *sb)
12662306a36Sopenharmony_ci{
12762306a36Sopenharmony_ci	WRITE_ONCE(sb->s_readonly_remount, 1);
12862306a36Sopenharmony_ci	/*
12962306a36Sopenharmony_ci	 * For RO->RW transition, the barrier pairs with the barrier in
13062306a36Sopenharmony_ci	 * mnt_is_readonly() making sure if mnt_is_readonly() sees SB_RDONLY
13162306a36Sopenharmony_ci	 * cleared, it will see s_readonly_remount set.
13262306a36Sopenharmony_ci	 * For RW->RO transition, the barrier pairs with the barrier in
13362306a36Sopenharmony_ci	 * __mnt_want_write() before the mnt_is_readonly() check. The barrier
13462306a36Sopenharmony_ci	 * makes sure if __mnt_want_write() sees MNT_WRITE_HOLD already
13562306a36Sopenharmony_ci	 * cleared, it will see s_readonly_remount set.
13662306a36Sopenharmony_ci	 */
13762306a36Sopenharmony_ci	smp_wmb();
13862306a36Sopenharmony_ci}
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci/*
14162306a36Sopenharmony_ci * Ends section changing read-only state of the superblock. After this function
14262306a36Sopenharmony_ci * returns if mnt_is_readonly() returns false, the caller will be able to
14362306a36Sopenharmony_ci * observe all the changes remount did to the superblock.
14462306a36Sopenharmony_ci */
14562306a36Sopenharmony_cistatic inline void sb_end_ro_state_change(struct super_block *sb)
14662306a36Sopenharmony_ci{
14762306a36Sopenharmony_ci	/*
14862306a36Sopenharmony_ci	 * This barrier provides release semantics that pairs with
14962306a36Sopenharmony_ci	 * the smp_rmb() acquire semantics in mnt_is_readonly().
15062306a36Sopenharmony_ci	 * This barrier pair ensure that when mnt_is_readonly() sees
15162306a36Sopenharmony_ci	 * 0 for sb->s_readonly_remount, it will also see all the
15262306a36Sopenharmony_ci	 * preceding flag changes that were made during the RO state
15362306a36Sopenharmony_ci	 * change.
15462306a36Sopenharmony_ci	 */
15562306a36Sopenharmony_ci	smp_wmb();
15662306a36Sopenharmony_ci	WRITE_ONCE(sb->s_readonly_remount, 0);
15762306a36Sopenharmony_ci}
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci/*
16062306a36Sopenharmony_ci * open.c
16162306a36Sopenharmony_ci */
16262306a36Sopenharmony_cistruct open_flags {
16362306a36Sopenharmony_ci	int open_flag;
16462306a36Sopenharmony_ci	umode_t mode;
16562306a36Sopenharmony_ci	int acc_mode;
16662306a36Sopenharmony_ci	int intent;
16762306a36Sopenharmony_ci	int lookup_flags;
16862306a36Sopenharmony_ci};
16962306a36Sopenharmony_ciextern struct file *do_filp_open(int dfd, struct filename *pathname,
17062306a36Sopenharmony_ci		const struct open_flags *op);
17162306a36Sopenharmony_ciextern struct file *do_file_open_root(const struct path *,
17262306a36Sopenharmony_ci		const char *, const struct open_flags *);
17362306a36Sopenharmony_ciextern struct open_how build_open_how(int flags, umode_t mode);
17462306a36Sopenharmony_ciextern int build_open_flags(const struct open_how *how, struct open_flags *op);
17562306a36Sopenharmony_ciextern struct file *__close_fd_get_file(unsigned int fd);
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_cilong do_sys_ftruncate(unsigned int fd, loff_t length, int small);
17862306a36Sopenharmony_ciint chmod_common(const struct path *path, umode_t mode);
17962306a36Sopenharmony_ciint do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
18062306a36Sopenharmony_ci		int flag);
18162306a36Sopenharmony_ciint chown_common(const struct path *path, uid_t user, gid_t group);
18262306a36Sopenharmony_ciextern int vfs_open(const struct path *, struct file *);
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci/*
18562306a36Sopenharmony_ci * inode.c
18662306a36Sopenharmony_ci */
18762306a36Sopenharmony_ciextern long prune_icache_sb(struct super_block *sb, struct shrink_control *sc);
18862306a36Sopenharmony_ciint dentry_needs_remove_privs(struct mnt_idmap *, struct dentry *dentry);
18962306a36Sopenharmony_cibool in_group_or_capable(struct mnt_idmap *idmap,
19062306a36Sopenharmony_ci			 const struct inode *inode, vfsgid_t vfsgid);
19162306a36Sopenharmony_civoid lock_two_inodes(struct inode *inode1, struct inode *inode2,
19262306a36Sopenharmony_ci		     unsigned subclass1, unsigned subclass2);
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci/*
19562306a36Sopenharmony_ci * fs-writeback.c
19662306a36Sopenharmony_ci */
19762306a36Sopenharmony_ciextern long get_nr_dirty_inodes(void);
19862306a36Sopenharmony_civoid invalidate_inodes(struct super_block *sb);
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci/*
20162306a36Sopenharmony_ci * dcache.c
20262306a36Sopenharmony_ci */
20362306a36Sopenharmony_ciextern int d_set_mounted(struct dentry *dentry);
20462306a36Sopenharmony_ciextern long prune_dcache_sb(struct super_block *sb, struct shrink_control *sc);
20562306a36Sopenharmony_ciextern struct dentry *d_alloc_cursor(struct dentry *);
20662306a36Sopenharmony_ciextern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
20762306a36Sopenharmony_ciextern char *simple_dname(struct dentry *, char *, int);
20862306a36Sopenharmony_ciextern void dput_to_list(struct dentry *, struct list_head *);
20962306a36Sopenharmony_ciextern void shrink_dentry_list(struct list_head *);
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci/*
21262306a36Sopenharmony_ci * pipe.c
21362306a36Sopenharmony_ci */
21462306a36Sopenharmony_ciextern const struct file_operations pipefifo_fops;
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ci/*
21762306a36Sopenharmony_ci * fs_pin.c
21862306a36Sopenharmony_ci */
21962306a36Sopenharmony_ciextern void group_pin_kill(struct hlist_head *p);
22062306a36Sopenharmony_ciextern void mnt_pin_kill(struct mount *m);
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci/*
22362306a36Sopenharmony_ci * fs/nsfs.c
22462306a36Sopenharmony_ci */
22562306a36Sopenharmony_ciextern const struct dentry_operations ns_dentry_operations;
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci/*
22862306a36Sopenharmony_ci * fs/stat.c:
22962306a36Sopenharmony_ci */
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ciint getname_statx_lookup_flags(int flags);
23262306a36Sopenharmony_ciint do_statx(int dfd, struct filename *filename, unsigned int flags,
23362306a36Sopenharmony_ci	     unsigned int mask, struct statx __user *buffer);
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci/*
23662306a36Sopenharmony_ci * fs/splice.c:
23762306a36Sopenharmony_ci */
23862306a36Sopenharmony_cilong splice_file_to_pipe(struct file *in,
23962306a36Sopenharmony_ci			 struct pipe_inode_info *opipe,
24062306a36Sopenharmony_ci			 loff_t *offset,
24162306a36Sopenharmony_ci			 size_t len, unsigned int flags);
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci/*
24462306a36Sopenharmony_ci * fs/xattr.c:
24562306a36Sopenharmony_ci */
24662306a36Sopenharmony_cistruct xattr_name {
24762306a36Sopenharmony_ci	char name[XATTR_NAME_MAX + 1];
24862306a36Sopenharmony_ci};
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_cistruct xattr_ctx {
25162306a36Sopenharmony_ci	/* Value of attribute */
25262306a36Sopenharmony_ci	union {
25362306a36Sopenharmony_ci		const void __user *cvalue;
25462306a36Sopenharmony_ci		void __user *value;
25562306a36Sopenharmony_ci	};
25662306a36Sopenharmony_ci	void *kvalue;
25762306a36Sopenharmony_ci	size_t size;
25862306a36Sopenharmony_ci	/* Attribute name */
25962306a36Sopenharmony_ci	struct xattr_name *kname;
26062306a36Sopenharmony_ci	unsigned int flags;
26162306a36Sopenharmony_ci};
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_cissize_t do_getxattr(struct mnt_idmap *idmap,
26562306a36Sopenharmony_ci		    struct dentry *d,
26662306a36Sopenharmony_ci		    struct xattr_ctx *ctx);
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ciint setxattr_copy(const char __user *name, struct xattr_ctx *ctx);
26962306a36Sopenharmony_ciint do_setxattr(struct mnt_idmap *idmap, struct dentry *dentry,
27062306a36Sopenharmony_ci		struct xattr_ctx *ctx);
27162306a36Sopenharmony_ciint may_write_xattr(struct mnt_idmap *idmap, struct inode *inode);
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci#ifdef CONFIG_FS_POSIX_ACL
27462306a36Sopenharmony_ciint do_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
27562306a36Sopenharmony_ci	       const char *acl_name, const void *kvalue, size_t size);
27662306a36Sopenharmony_cissize_t do_get_acl(struct mnt_idmap *idmap, struct dentry *dentry,
27762306a36Sopenharmony_ci		   const char *acl_name, void *kvalue, size_t size);
27862306a36Sopenharmony_ci#else
27962306a36Sopenharmony_cistatic inline int do_set_acl(struct mnt_idmap *idmap,
28062306a36Sopenharmony_ci			     struct dentry *dentry, const char *acl_name,
28162306a36Sopenharmony_ci			     const void *kvalue, size_t size)
28262306a36Sopenharmony_ci{
28362306a36Sopenharmony_ci	return -EOPNOTSUPP;
28462306a36Sopenharmony_ci}
28562306a36Sopenharmony_cistatic inline ssize_t do_get_acl(struct mnt_idmap *idmap,
28662306a36Sopenharmony_ci				 struct dentry *dentry, const char *acl_name,
28762306a36Sopenharmony_ci				 void *kvalue, size_t size)
28862306a36Sopenharmony_ci{
28962306a36Sopenharmony_ci	return -EOPNOTSUPP;
29062306a36Sopenharmony_ci}
29162306a36Sopenharmony_ci#endif
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_cissize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *pos);
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci/*
29662306a36Sopenharmony_ci * fs/attr.c
29762306a36Sopenharmony_ci */
29862306a36Sopenharmony_cistruct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns);
29962306a36Sopenharmony_cistruct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap);
30062306a36Sopenharmony_civoid mnt_idmap_put(struct mnt_idmap *idmap);
301