internal.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* fs/ internal definitions
  3. *
  4. * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. struct super_block;
  8. struct file_system_type;
  9. struct iomap;
  10. struct iomap_ops;
  11. struct linux_binprm;
  12. struct path;
  13. struct mount;
  14. struct shrink_control;
  15. struct fs_context;
  16. struct pipe_inode_info;
  17. struct iov_iter;
  18. struct mnt_idmap;
  19. struct ns_common;
  20. /*
  21. * block/bdev.c
  22. */
  23. #ifdef CONFIG_BLOCK
  24. extern void __init bdev_cache_init(void);
  25. #else
  26. static inline void bdev_cache_init(void)
  27. {
  28. }
  29. #endif /* CONFIG_BLOCK */
  30. /*
  31. * buffer.c
  32. */
  33. int __block_write_begin_int(struct folio *folio, loff_t pos, unsigned len,
  34. get_block_t *get_block, const struct iomap *iomap);
  35. /*
  36. * char_dev.c
  37. */
  38. extern void __init chrdev_init(void);
  39. /*
  40. * fs_context.c
  41. */
  42. extern int parse_monolithic_mount_data(struct fs_context *, void *);
  43. extern void vfs_clean_context(struct fs_context *fc);
  44. extern int finish_clean_context(struct fs_context *fc);
  45. /*
  46. * namei.c
  47. */
  48. extern int filename_lookup(int dfd, struct filename *name, unsigned flags,
  49. struct path *path, const struct path *root);
  50. int filename_rmdir(int dfd, struct filename *name);
  51. int filename_unlinkat(int dfd, struct filename *name);
  52. int may_linkat(struct mnt_idmap *idmap, const struct path *link);
  53. int filename_renameat2(int olddfd, struct filename *oldname, int newdfd,
  54. struct filename *newname, unsigned int flags);
  55. int filename_mkdirat(int dfd, struct filename *name, umode_t mode);
  56. int filename_mknodat(int dfd, struct filename *name, umode_t mode, unsigned int dev);
  57. int filename_symlinkat(struct filename *from, int newdfd, struct filename *to);
  58. int filename_linkat(int olddfd, struct filename *old, int newdfd,
  59. struct filename *new, int flags);
  60. int vfs_tmpfile(struct mnt_idmap *idmap,
  61. const struct path *parentpath,
  62. struct file *file, umode_t mode);
  63. struct dentry *d_hash_and_lookup(struct dentry *, struct qstr *);
  64. struct dentry *start_dirop(struct dentry *parent, struct qstr *name,
  65. unsigned int lookup_flags);
  66. int lookup_noperm_common(struct qstr *qname, struct dentry *base);
  67. void __init filename_init(void);
  68. /*
  69. * namespace.c
  70. */
  71. extern struct vfsmount *lookup_mnt(const struct path *);
  72. extern int finish_automount(struct vfsmount *, const struct path *);
  73. extern int sb_prepare_remount_readonly(struct super_block *);
  74. extern void __init mnt_init(void);
  75. int mnt_get_write_access_file(struct file *file);
  76. void mnt_put_write_access_file(struct file *file);
  77. extern void dissolve_on_fput(struct vfsmount *);
  78. extern bool may_mount(void);
  79. int path_mount(const char *dev_name, const struct path *path,
  80. const char *type_page, unsigned long flags, void *data_page);
  81. int path_umount(const struct path *path, int flags);
  82. int path_pivot_root(struct path *new, struct path *old);
  83. int show_path(struct seq_file *m, struct dentry *root);
  84. /*
  85. * fs_struct.c
  86. */
  87. extern void chroot_fs_refs(const struct path *, const struct path *);
  88. /*
  89. * file_table.c
  90. */
  91. struct file *alloc_empty_file(int flags, const struct cred *cred);
  92. struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred);
  93. struct file *alloc_empty_backing_file(int flags, const struct cred *cred);
  94. void backing_file_set_user_path(struct file *f, const struct path *path);
  95. static inline void file_put_write_access(struct file *file)
  96. {
  97. put_write_access(file->f_inode);
  98. mnt_put_write_access(file->f_path.mnt);
  99. if (unlikely(file->f_mode & FMODE_BACKING))
  100. mnt_put_write_access(backing_file_user_path(file)->mnt);
  101. }
  102. static inline void put_file_access(struct file *file)
  103. {
  104. if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
  105. i_readcount_dec(file->f_inode);
  106. } else if (file->f_mode & FMODE_WRITER) {
  107. file_put_write_access(file);
  108. }
  109. }
  110. void fput_close_sync(struct file *);
  111. void fput_close(struct file *);
  112. /*
  113. * super.c
  114. */
  115. extern int reconfigure_super(struct fs_context *);
  116. extern bool super_trylock_shared(struct super_block *sb);
  117. struct super_block *user_get_super(dev_t, bool excl);
  118. void put_super(struct super_block *sb);
  119. extern bool mount_capable(struct fs_context *);
  120. int sb_init_dio_done_wq(struct super_block *sb);
  121. /*
  122. * Prepare superblock for changing its read-only state (i.e., either remount
  123. * read-write superblock read-only or vice versa). After this function returns
  124. * mnt_is_readonly() will return true for any mount of the superblock if its
  125. * caller is able to observe any changes done by the remount. This holds until
  126. * sb_end_ro_state_change() is called.
  127. */
  128. static inline void sb_start_ro_state_change(struct super_block *sb)
  129. {
  130. WRITE_ONCE(sb->s_readonly_remount, 1);
  131. /*
  132. * For RO->RW transition, the barrier pairs with the barrier in
  133. * mnt_is_readonly() making sure if mnt_is_readonly() sees SB_RDONLY
  134. * cleared, it will see s_readonly_remount set.
  135. * For RW->RO transition, the barrier pairs with the barrier in
  136. * mnt_get_write_access() before the mnt_is_readonly() check.
  137. * The barrier makes sure if mnt_get_write_access() sees MNT_WRITE_HOLD
  138. * already cleared, it will see s_readonly_remount set.
  139. */
  140. smp_wmb();
  141. }
  142. /*
  143. * Ends section changing read-only state of the superblock. After this function
  144. * returns if mnt_is_readonly() returns false, the caller will be able to
  145. * observe all the changes remount did to the superblock.
  146. */
  147. static inline void sb_end_ro_state_change(struct super_block *sb)
  148. {
  149. /*
  150. * This barrier provides release semantics that pairs with
  151. * the smp_rmb() acquire semantics in mnt_is_readonly().
  152. * This barrier pair ensure that when mnt_is_readonly() sees
  153. * 0 for sb->s_readonly_remount, it will also see all the
  154. * preceding flag changes that were made during the RO state
  155. * change.
  156. */
  157. smp_wmb();
  158. WRITE_ONCE(sb->s_readonly_remount, 0);
  159. }
  160. /*
  161. * open.c
  162. */
  163. struct open_flags {
  164. int open_flag;
  165. umode_t mode;
  166. int acc_mode;
  167. int intent;
  168. int lookup_flags;
  169. };
  170. extern struct file *do_file_open(int dfd, struct filename *pathname,
  171. const struct open_flags *op);
  172. extern struct file *do_file_open_root(const struct path *,
  173. const char *, const struct open_flags *);
  174. extern struct open_how build_open_how(int flags, umode_t mode);
  175. extern int build_open_flags(const struct open_how *how, struct open_flags *op);
  176. struct file *file_close_fd_locked(struct files_struct *files, unsigned fd);
  177. int do_ftruncate(struct file *file, loff_t length, int small);
  178. int do_sys_ftruncate(unsigned int fd, loff_t length, int small);
  179. int chmod_common(const struct path *path, umode_t mode);
  180. int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
  181. int flag);
  182. int chown_common(const struct path *path, uid_t user, gid_t group);
  183. extern int vfs_open(const struct path *, struct file *);
  184. /*
  185. * inode.c
  186. */
  187. extern long prune_icache_sb(struct super_block *sb, struct shrink_control *sc);
  188. int dentry_needs_remove_privs(struct mnt_idmap *, struct dentry *dentry);
  189. bool in_group_or_capable(struct mnt_idmap *idmap,
  190. const struct inode *inode, vfsgid_t vfsgid);
  191. /*
  192. * fs-writeback.c
  193. */
  194. long get_nr_dirty_inodes(void);
  195. bool sync_lazytime(struct inode *inode);
  196. /*
  197. * dcache.c
  198. */
  199. extern int d_set_mounted(struct dentry *dentry);
  200. extern long prune_dcache_sb(struct super_block *sb, struct shrink_control *sc);
  201. extern struct dentry *d_alloc_cursor(struct dentry *);
  202. extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
  203. extern char *simple_dname(struct dentry *, char *, int);
  204. extern void dput_to_list(struct dentry *, struct list_head *);
  205. extern void shrink_dentry_list(struct list_head *);
  206. extern void shrink_dcache_for_umount(struct super_block *);
  207. extern struct dentry *__d_lookup(const struct dentry *, const struct qstr *);
  208. extern struct dentry *__d_lookup_rcu(const struct dentry *parent,
  209. const struct qstr *name, unsigned *seq);
  210. /*
  211. * pipe.c
  212. */
  213. extern const struct file_operations pipefifo_fops;
  214. /*
  215. * fs_pin.c
  216. */
  217. extern void group_pin_kill(struct hlist_head *p);
  218. extern void mnt_pin_kill(struct mount *m);
  219. /*
  220. * fs/nsfs.c
  221. */
  222. extern const struct dentry_operations ns_dentry_operations;
  223. int open_namespace(struct ns_common *ns);
  224. struct file *open_namespace_file(struct ns_common *ns);
  225. /*
  226. * fs/stat.c:
  227. */
  228. int do_statx(int dfd, struct filename *filename, unsigned int flags,
  229. unsigned int mask, struct statx __user *buffer);
  230. int do_statx_fd(int fd, unsigned int flags, unsigned int mask,
  231. struct statx __user *buffer);
  232. /*
  233. * fs/splice.c:
  234. */
  235. ssize_t splice_file_to_pipe(struct file *in,
  236. struct pipe_inode_info *opipe,
  237. loff_t *offset,
  238. size_t len, unsigned int flags);
  239. /*
  240. * fs/xattr.c:
  241. */
  242. struct xattr_name {
  243. char name[XATTR_NAME_MAX + 1];
  244. };
  245. struct kernel_xattr_ctx {
  246. /* Value of attribute */
  247. union {
  248. const void __user *cvalue;
  249. void __user *value;
  250. };
  251. void *kvalue;
  252. size_t size;
  253. /* Attribute name */
  254. struct xattr_name *kname;
  255. unsigned int flags;
  256. };
  257. ssize_t file_getxattr(struct file *file, struct kernel_xattr_ctx *ctx);
  258. ssize_t filename_getxattr(int dfd, struct filename *filename,
  259. unsigned int lookup_flags, struct kernel_xattr_ctx *ctx);
  260. int file_setxattr(struct file *file, struct kernel_xattr_ctx *ctx);
  261. int filename_setxattr(int dfd, struct filename *filename,
  262. unsigned int lookup_flags, struct kernel_xattr_ctx *ctx);
  263. int setxattr_copy(const char __user *name, struct kernel_xattr_ctx *ctx);
  264. int import_xattr_name(struct xattr_name *kname, const char __user *name);
  265. int may_write_xattr(struct mnt_idmap *idmap, struct inode *inode);
  266. #ifdef CONFIG_FS_POSIX_ACL
  267. int do_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
  268. const char *acl_name, const void *kvalue, size_t size);
  269. ssize_t do_get_acl(struct mnt_idmap *idmap, struct dentry *dentry,
  270. const char *acl_name, void *kvalue, size_t size);
  271. #else
  272. static inline int do_set_acl(struct mnt_idmap *idmap,
  273. struct dentry *dentry, const char *acl_name,
  274. const void *kvalue, size_t size)
  275. {
  276. return -EOPNOTSUPP;
  277. }
  278. static inline ssize_t do_get_acl(struct mnt_idmap *idmap,
  279. struct dentry *dentry, const char *acl_name,
  280. void *kvalue, size_t size)
  281. {
  282. return -EOPNOTSUPP;
  283. }
  284. #endif
  285. ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *pos);
  286. /*
  287. * fs/attr.c
  288. */
  289. struct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns);
  290. struct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap);
  291. void mnt_idmap_put(struct mnt_idmap *idmap);
  292. struct stashed_operations {
  293. struct dentry *(*stash_dentry)(struct dentry **stashed,
  294. struct dentry *dentry);
  295. void (*put_data)(void *data);
  296. int (*init_inode)(struct inode *inode, void *data);
  297. };
  298. int path_from_stashed(struct dentry **stashed, struct vfsmount *mnt, void *data,
  299. struct path *path);
  300. void stashed_dentry_prune(struct dentry *dentry);
  301. struct dentry *stash_dentry(struct dentry **stashed, struct dentry *dentry);
  302. struct dentry *stashed_dentry_get(struct dentry **stashed);
  303. /**
  304. * path_mounted - check whether path is mounted
  305. * @path: path to check
  306. *
  307. * Determine whether @path refers to the root of a mount.
  308. *
  309. * Return: true if @path is the root of a mount, false if not.
  310. */
  311. static inline bool path_mounted(const struct path *path)
  312. {
  313. return path->mnt->mnt_root == path->dentry;
  314. }
  315. void file_f_owner_release(struct file *file);
  316. bool file_seek_cur_needs_f_lock(struct file *file);
  317. int statmount_mnt_idmap(struct mnt_idmap *idmap, struct seq_file *seq, bool uid_map);
  318. struct dentry *find_next_child(struct dentry *parent, struct dentry *prev);
  319. int anon_inode_getattr(struct mnt_idmap *idmap, const struct path *path,
  320. struct kstat *stat, u32 request_mask,
  321. unsigned int query_flags);
  322. int anon_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
  323. struct iattr *attr);
  324. void pidfs_get_root(struct path *path);
  325. void nsfs_get_root(struct path *path);