overlayfs.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. *
  3. * Copyright (C) 2011 Novell Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. */
  9. #include <linux/kernel.h>
  10. enum ovl_path_type {
  11. __OVL_PATH_UPPER = (1 << 0),
  12. __OVL_PATH_MERGE = (1 << 1),
  13. };
  14. #define OVL_TYPE_UPPER(type) ((type) & __OVL_PATH_UPPER)
  15. #define OVL_TYPE_MERGE(type) ((type) & __OVL_PATH_MERGE)
  16. #define OVL_XATTR_PREFIX XATTR_TRUSTED_PREFIX "overlay."
  17. #define OVL_XATTR_OPAQUE OVL_XATTR_PREFIX "opaque"
  18. #define OVL_XATTR_REDIRECT OVL_XATTR_PREFIX "redirect"
  19. #define OVL_ISUPPER_MASK 1UL
  20. static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
  21. {
  22. int err = vfs_rmdir(dir, dentry);
  23. pr_debug("rmdir(%pd2) = %i\n", dentry, err);
  24. return err;
  25. }
  26. static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry)
  27. {
  28. int err = vfs_unlink(dir, dentry, NULL);
  29. pr_debug("unlink(%pd2) = %i\n", dentry, err);
  30. return err;
  31. }
  32. static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir,
  33. struct dentry *new_dentry, bool debug)
  34. {
  35. int err = vfs_link(old_dentry, dir, new_dentry, NULL);
  36. if (debug) {
  37. pr_debug("link(%pd2, %pd2) = %i\n",
  38. old_dentry, new_dentry, err);
  39. }
  40. return err;
  41. }
  42. static inline int ovl_do_create(struct inode *dir, struct dentry *dentry,
  43. umode_t mode, bool debug)
  44. {
  45. int err = vfs_create(dir, dentry, mode, true);
  46. if (debug)
  47. pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
  48. return err;
  49. }
  50. static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry,
  51. umode_t mode, bool debug)
  52. {
  53. int err = vfs_mkdir(dir, dentry, mode);
  54. if (debug)
  55. pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
  56. return err;
  57. }
  58. static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry,
  59. umode_t mode, dev_t dev, bool debug)
  60. {
  61. int err = vfs_mknod(dir, dentry, mode, dev);
  62. if (debug) {
  63. pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n",
  64. dentry, mode, dev, err);
  65. }
  66. return err;
  67. }
  68. static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry,
  69. const char *oldname, bool debug)
  70. {
  71. int err = vfs_symlink(dir, dentry, oldname);
  72. if (debug)
  73. pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err);
  74. return err;
  75. }
  76. static inline int ovl_do_setxattr(struct dentry *dentry, const char *name,
  77. const void *value, size_t size, int flags)
  78. {
  79. int err = vfs_setxattr(dentry, name, value, size, flags);
  80. pr_debug("setxattr(%pd2, \"%s\", \"%*s\", 0x%x) = %i\n",
  81. dentry, name, (int) size, (char *) value, flags, err);
  82. return err;
  83. }
  84. static inline int ovl_do_removexattr(struct dentry *dentry, const char *name)
  85. {
  86. int err = vfs_removexattr(dentry, name);
  87. pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
  88. return err;
  89. }
  90. static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry,
  91. struct inode *newdir, struct dentry *newdentry,
  92. unsigned int flags)
  93. {
  94. int err;
  95. pr_debug("rename(%pd2, %pd2, 0x%x)\n",
  96. olddentry, newdentry, flags);
  97. err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags);
  98. if (err) {
  99. pr_debug("...rename(%pd2, %pd2, ...) = %i\n",
  100. olddentry, newdentry, err);
  101. }
  102. return err;
  103. }
  104. static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry)
  105. {
  106. int err = vfs_whiteout(dir, dentry);
  107. pr_debug("whiteout(%pd2) = %i\n", dentry, err);
  108. return err;
  109. }
  110. static inline struct inode *ovl_inode_real(struct inode *inode, bool *is_upper)
  111. {
  112. unsigned long x = (unsigned long) READ_ONCE(inode->i_private);
  113. if (is_upper)
  114. *is_upper = x & OVL_ISUPPER_MASK;
  115. return (struct inode *) (x & ~OVL_ISUPPER_MASK);
  116. }
  117. /* util.c */
  118. int ovl_want_write(struct dentry *dentry);
  119. void ovl_drop_write(struct dentry *dentry);
  120. struct dentry *ovl_workdir(struct dentry *dentry);
  121. const struct cred *ovl_override_creds(struct super_block *sb);
  122. struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
  123. bool ovl_dentry_remote(struct dentry *dentry);
  124. bool ovl_dentry_weird(struct dentry *dentry);
  125. enum ovl_path_type ovl_path_type(struct dentry *dentry);
  126. void ovl_path_upper(struct dentry *dentry, struct path *path);
  127. void ovl_path_lower(struct dentry *dentry, struct path *path);
  128. enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
  129. struct dentry *ovl_dentry_upper(struct dentry *dentry);
  130. struct dentry *ovl_dentry_lower(struct dentry *dentry);
  131. struct dentry *ovl_dentry_real(struct dentry *dentry);
  132. struct ovl_dir_cache *ovl_dir_cache(struct dentry *dentry);
  133. void ovl_set_dir_cache(struct dentry *dentry, struct ovl_dir_cache *cache);
  134. bool ovl_dentry_is_opaque(struct dentry *dentry);
  135. bool ovl_dentry_is_whiteout(struct dentry *dentry);
  136. void ovl_dentry_set_opaque(struct dentry *dentry);
  137. bool ovl_redirect_dir(struct super_block *sb);
  138. void ovl_clear_redirect_dir(struct super_block *sb);
  139. const char *ovl_dentry_get_redirect(struct dentry *dentry);
  140. void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
  141. void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry);
  142. void ovl_inode_init(struct inode *inode, struct inode *realinode,
  143. bool is_upper);
  144. void ovl_inode_update(struct inode *inode, struct inode *upperinode);
  145. void ovl_dentry_version_inc(struct dentry *dentry);
  146. u64 ovl_dentry_version_get(struct dentry *dentry);
  147. bool ovl_is_whiteout(struct dentry *dentry);
  148. struct file *ovl_path_open(struct path *path, int flags);
  149. /* namei.c */
  150. int ovl_path_next(int idx, struct dentry *dentry, struct path *path);
  151. struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags);
  152. bool ovl_lower_positive(struct dentry *dentry);
  153. /* readdir.c */
  154. extern const struct file_operations ovl_dir_operations;
  155. int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
  156. void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list);
  157. void ovl_cache_free(struct list_head *list);
  158. int ovl_check_d_type_supported(struct path *realpath);
  159. void ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt,
  160. struct dentry *dentry, int level);
  161. /* inode.c */
  162. int ovl_setattr(struct dentry *dentry, struct iattr *attr);
  163. int ovl_permission(struct inode *inode, int mask);
  164. int ovl_xattr_set(struct dentry *dentry, const char *name, const void *value,
  165. size_t size, int flags);
  166. int ovl_xattr_get(struct dentry *dentry, const char *name,
  167. void *value, size_t size);
  168. ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
  169. struct posix_acl *ovl_get_acl(struct inode *inode, int type);
  170. int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags);
  171. int ovl_update_time(struct inode *inode, struct timespec *ts, int flags);
  172. bool ovl_is_private_xattr(const char *name);
  173. struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
  174. struct inode *ovl_get_inode(struct super_block *sb, struct inode *realinode);
  175. static inline void ovl_copyattr(struct inode *from, struct inode *to)
  176. {
  177. to->i_uid = from->i_uid;
  178. to->i_gid = from->i_gid;
  179. to->i_mode = from->i_mode;
  180. to->i_atime = from->i_atime;
  181. to->i_mtime = from->i_mtime;
  182. to->i_ctime = from->i_ctime;
  183. }
  184. /* dir.c */
  185. extern const struct inode_operations ovl_dir_inode_operations;
  186. struct dentry *ovl_lookup_temp(struct dentry *workdir, struct dentry *dentry);
  187. struct cattr {
  188. dev_t rdev;
  189. umode_t mode;
  190. const char *link;
  191. };
  192. int ovl_create_real(struct inode *dir, struct dentry *newdentry,
  193. struct cattr *attr,
  194. struct dentry *hardlink, bool debug);
  195. void ovl_cleanup(struct inode *dir, struct dentry *dentry);
  196. /* copy_up.c */
  197. int ovl_copy_up(struct dentry *dentry);
  198. int ovl_copy_up_flags(struct dentry *dentry, int flags);
  199. int ovl_copy_xattr(struct dentry *old, struct dentry *new);
  200. int ovl_set_attr(struct dentry *upper, struct kstat *stat);