internal.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 const struct fs_context_operations legacy_fs_context_ops;
  43. extern int parse_monolithic_mount_data(struct fs_context *, void *);
  44. extern void vfs_clean_context(struct fs_context *fc);
  45. extern int finish_clean_context(struct fs_context *fc);
  46. /*
  47. * namei.c
  48. */
  49. extern int filename_lookup(int dfd, struct filename *name, unsigned flags,
  50. struct path *path, struct path *root);
  51. int do_rmdir(int dfd, struct filename *name);
  52. int do_unlinkat(int dfd, struct filename *name);
  53. int may_linkat(struct mnt_idmap *idmap, const struct path *link);
  54. int do_renameat2(int olddfd, struct filename *oldname, int newdfd,
  55. struct filename *newname, unsigned int flags);
  56. int do_mkdirat(int dfd, struct filename *name, umode_t mode);
  57. int do_symlinkat(struct filename *from, int newdfd, struct filename *to);
  58. int do_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. /*
  64. * namespace.c
  65. */
  66. extern struct vfsmount *lookup_mnt(const struct path *);
  67. extern int finish_automount(struct vfsmount *, const struct path *);
  68. extern int sb_prepare_remount_readonly(struct super_block *);
  69. extern void __init mnt_init(void);
  70. int mnt_get_write_access_file(struct file *file);
  71. void mnt_put_write_access_file(struct file *file);
  72. extern void dissolve_on_fput(struct vfsmount *);
  73. extern bool may_mount(void);
  74. int path_mount(const char *dev_name, struct path *path,
  75. const char *type_page, unsigned long flags, void *data_page);
  76. int path_umount(struct path *path, int flags);
  77. int show_path(struct seq_file *m, struct dentry *root);
  78. /*
  79. * fs_struct.c
  80. */
  81. extern void chroot_fs_refs(const struct path *, const struct path *);
  82. /*
  83. * file_table.c
  84. */
  85. struct file *alloc_empty_file(int flags, const struct cred *cred);
  86. struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred);
  87. struct file *alloc_empty_backing_file(int flags, const struct cred *cred);
  88. static inline void file_put_write_access(struct file *file)
  89. {
  90. put_write_access(file->f_inode);
  91. mnt_put_write_access(file->f_path.mnt);
  92. if (unlikely(file->f_mode & FMODE_BACKING))
  93. mnt_put_write_access(backing_file_user_path(file)->mnt);
  94. }
  95. static inline void put_file_access(struct file *file)
  96. {
  97. if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
  98. i_readcount_dec(file->f_inode);
  99. } else if (file->f_mode & FMODE_WRITER) {
  100. file_put_write_access(file);
  101. }
  102. }
  103. /*
  104. * super.c
  105. */
  106. extern int reconfigure_super(struct fs_context *);
  107. extern bool super_trylock_shared(struct super_block *sb);
  108. struct super_block *user_get_super(dev_t, bool excl);
  109. void put_super(struct super_block *sb);
  110. extern bool mount_capable(struct fs_context *);
  111. int sb_init_dio_done_wq(struct super_block *sb);
  112. /*
  113. * Prepare superblock for changing its read-only state (i.e., either remount
  114. * read-write superblock read-only or vice versa). After this function returns
  115. * mnt_is_readonly() will return true for any mount of the superblock if its
  116. * caller is able to observe any changes done by the remount. This holds until
  117. * sb_end_ro_state_change() is called.
  118. */
  119. static inline void sb_start_ro_state_change(struct super_block *sb)
  120. {
  121. WRITE_ONCE(sb->s_readonly_remount, 1);
  122. /*
  123. * For RO->RW transition, the barrier pairs with the barrier in
  124. * mnt_is_readonly() making sure if mnt_is_readonly() sees SB_RDONLY
  125. * cleared, it will see s_readonly_remount set.
  126. * For RW->RO transition, the barrier pairs with the barrier in
  127. * mnt_get_write_access() before the mnt_is_readonly() check.
  128. * The barrier makes sure if mnt_get_write_access() sees MNT_WRITE_HOLD
  129. * already cleared, it will see s_readonly_remount set.
  130. */
  131. smp_wmb();
  132. }
  133. /*
  134. * Ends section changing read-only state of the superblock. After this function
  135. * returns if mnt_is_readonly() returns false, the caller will be able to
  136. * observe all the changes remount did to the superblock.
  137. */
  138. static inline void sb_end_ro_state_change(struct super_block *sb)
  139. {
  140. /*
  141. * This barrier provides release semantics that pairs with
  142. * the smp_rmb() acquire semantics in mnt_is_readonly().
  143. * This barrier pair ensure that when mnt_is_readonly() sees
  144. * 0 for sb->s_readonly_remount, it will also see all the
  145. * preceding flag changes that were made during the RO state
  146. * change.
  147. */
  148. smp_wmb();
  149. WRITE_ONCE(sb->s_readonly_remount, 0);
  150. }
  151. /*
  152. * open.c
  153. */
  154. struct open_flags {
  155. int open_flag;
  156. umode_t mode;
  157. int acc_mode;
  158. int intent;
  159. int lookup_flags;
  160. };
  161. extern struct file *do_filp_open(int dfd, struct filename *pathname,
  162. const struct open_flags *op);
  163. extern struct file *do_file_open_root(const struct path *,
  164. const char *, const struct open_flags *);
  165. extern struct open_how build_open_how(int flags, umode_t mode);
  166. extern int build_open_flags(const struct open_how *how, struct open_flags *op);
  167. struct file *file_close_fd_locked(struct files_struct *files, unsigned fd);
  168. long do_ftruncate(struct file *file, loff_t length, int small);
  169. long do_sys_ftruncate(unsigned int fd, loff_t length, int small);
  170. int chmod_common(const struct path *path, umode_t mode);
  171. int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
  172. int flag);
  173. int chown_common(const struct path *path, uid_t user, gid_t group);
  174. extern int vfs_open(const struct path *, struct file *);
  175. /*
  176. * inode.c
  177. */
  178. extern long prune_icache_sb(struct super_block *sb, struct shrink_control *sc);
  179. int dentry_needs_remove_privs(struct mnt_idmap *, struct dentry *dentry);
  180. bool in_group_or_capable(struct mnt_idmap *idmap,
  181. const struct inode *inode, vfsgid_t vfsgid);
  182. /*
  183. * fs-writeback.c
  184. */
  185. extern long get_nr_dirty_inodes(void);
  186. void invalidate_inodes(struct super_block *sb);
  187. /*
  188. * dcache.c
  189. */
  190. extern int d_set_mounted(struct dentry *dentry);
  191. extern long prune_dcache_sb(struct super_block *sb, struct shrink_control *sc);
  192. extern struct dentry *d_alloc_cursor(struct dentry *);
  193. extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
  194. extern char *simple_dname(struct dentry *, char *, int);
  195. extern void dput_to_list(struct dentry *, struct list_head *);
  196. extern void shrink_dentry_list(struct list_head *);
  197. extern void shrink_dcache_for_umount(struct super_block *);
  198. extern struct dentry *__d_lookup(const struct dentry *, const struct qstr *);
  199. extern struct dentry *__d_lookup_rcu(const struct dentry *parent,
  200. const struct qstr *name, unsigned *seq);
  201. extern void d_genocide(struct dentry *);
  202. /*
  203. * pipe.c
  204. */
  205. extern const struct file_operations pipefifo_fops;
  206. /*
  207. * fs_pin.c
  208. */
  209. extern void group_pin_kill(struct hlist_head *p);
  210. extern void mnt_pin_kill(struct mount *m);
  211. /*
  212. * fs/nsfs.c
  213. */
  214. extern const struct dentry_operations ns_dentry_operations;
  215. int open_namespace(struct ns_common *ns);
  216. /*
  217. * fs/stat.c:
  218. */
  219. int getname_statx_lookup_flags(int flags);
  220. int do_statx(int dfd, struct filename *filename, unsigned int flags,
  221. unsigned int mask, struct statx __user *buffer);
  222. int do_statx_fd(int fd, unsigned int flags, unsigned int mask,
  223. struct statx __user *buffer);
  224. /*
  225. * fs/splice.c:
  226. */
  227. ssize_t splice_file_to_pipe(struct file *in,
  228. struct pipe_inode_info *opipe,
  229. loff_t *offset,
  230. size_t len, unsigned int flags);
  231. /*
  232. * fs/xattr.c:
  233. */
  234. struct xattr_name {
  235. char name[XATTR_NAME_MAX + 1];
  236. };
  237. struct xattr_ctx {
  238. /* Value of attribute */
  239. union {
  240. const void __user *cvalue;
  241. void __user *value;
  242. };
  243. void *kvalue;
  244. size_t size;
  245. /* Attribute name */
  246. struct xattr_name *kname;
  247. unsigned int flags;
  248. };
  249. ssize_t do_getxattr(struct mnt_idmap *idmap,
  250. struct dentry *d,
  251. struct xattr_ctx *ctx);
  252. int setxattr_copy(const char __user *name, struct xattr_ctx *ctx);
  253. int do_setxattr(struct mnt_idmap *idmap, struct dentry *dentry,
  254. struct xattr_ctx *ctx);
  255. int may_write_xattr(struct mnt_idmap *idmap, struct inode *inode);
  256. #ifdef CONFIG_FS_POSIX_ACL
  257. int do_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
  258. const char *acl_name, const void *kvalue, size_t size);
  259. ssize_t do_get_acl(struct mnt_idmap *idmap, struct dentry *dentry,
  260. const char *acl_name, void *kvalue, size_t size);
  261. #else
  262. static inline int do_set_acl(struct mnt_idmap *idmap,
  263. struct dentry *dentry, const char *acl_name,
  264. const void *kvalue, size_t size)
  265. {
  266. return -EOPNOTSUPP;
  267. }
  268. static inline ssize_t do_get_acl(struct mnt_idmap *idmap,
  269. struct dentry *dentry, const char *acl_name,
  270. void *kvalue, size_t size)
  271. {
  272. return -EOPNOTSUPP;
  273. }
  274. #endif
  275. ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *pos);
  276. /*
  277. * fs/attr.c
  278. */
  279. struct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns);
  280. struct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap);
  281. void mnt_idmap_put(struct mnt_idmap *idmap);
  282. struct stashed_operations {
  283. void (*put_data)(void *data);
  284. int (*init_inode)(struct inode *inode, void *data);
  285. };
  286. int path_from_stashed(struct dentry **stashed, struct vfsmount *mnt, void *data,
  287. struct path *path);
  288. void stashed_dentry_prune(struct dentry *dentry);
  289. /**
  290. * path_mounted - check whether path is mounted
  291. * @path: path to check
  292. *
  293. * Determine whether @path refers to the root of a mount.
  294. *
  295. * Return: true if @path is the root of a mount, false if not.
  296. */
  297. static inline bool path_mounted(const struct path *path)
  298. {
  299. return path->mnt->mnt_root == path->dentry;
  300. }
  301. void file_f_owner_release(struct file *file);