overlayfs.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. struct ovl_entry;
  11. enum ovl_path_type {
  12. __OVL_PATH_PURE = (1 << 0),
  13. __OVL_PATH_UPPER = (1 << 1),
  14. __OVL_PATH_MERGE = (1 << 2),
  15. };
  16. #define OVL_TYPE_UPPER(type) ((type) & __OVL_PATH_UPPER)
  17. #define OVL_TYPE_MERGE(type) ((type) & __OVL_PATH_MERGE)
  18. #define OVL_TYPE_PURE_UPPER(type) ((type) & __OVL_PATH_PURE)
  19. #define OVL_TYPE_MERGE_OR_LOWER(type) \
  20. (OVL_TYPE_MERGE(type) || !OVL_TYPE_UPPER(type))
  21. #define OVL_XATTR_PRE_NAME "trusted.overlay."
  22. #define OVL_XATTR_PRE_LEN 16
  23. #define OVL_XATTR_OPAQUE OVL_XATTR_PRE_NAME"opaque"
  24. static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
  25. {
  26. int err = vfs_rmdir(dir, dentry);
  27. pr_debug("rmdir(%pd2) = %i\n", dentry, err);
  28. return err;
  29. }
  30. static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry)
  31. {
  32. int err = vfs_unlink(dir, dentry, NULL);
  33. pr_debug("unlink(%pd2) = %i\n", dentry, err);
  34. return err;
  35. }
  36. static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir,
  37. struct dentry *new_dentry, bool debug)
  38. {
  39. int err = vfs_link(old_dentry, dir, new_dentry, NULL);
  40. if (debug) {
  41. pr_debug("link(%pd2, %pd2) = %i\n",
  42. old_dentry, new_dentry, err);
  43. }
  44. return err;
  45. }
  46. static inline int ovl_do_create(struct inode *dir, struct dentry *dentry,
  47. umode_t mode, bool debug)
  48. {
  49. int err = vfs_create(dir, dentry, mode, true);
  50. if (debug)
  51. pr_debug("create(%pd2, 0%o) = %i\n", dentry, mode, err);
  52. return err;
  53. }
  54. static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry,
  55. umode_t mode, bool debug)
  56. {
  57. int err = vfs_mkdir(dir, dentry, mode);
  58. if (debug)
  59. pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
  60. return err;
  61. }
  62. static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry,
  63. umode_t mode, dev_t dev, bool debug)
  64. {
  65. int err = vfs_mknod(dir, dentry, mode, dev);
  66. if (debug) {
  67. pr_debug("mknod(%pd2, 0%o, 0%o) = %i\n",
  68. dentry, mode, dev, err);
  69. }
  70. return err;
  71. }
  72. static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry,
  73. const char *oldname, bool debug)
  74. {
  75. int err = vfs_symlink(dir, dentry, oldname);
  76. if (debug)
  77. pr_debug("symlink(\"%s\", %pd2) = %i\n", oldname, dentry, err);
  78. return err;
  79. }
  80. static inline int ovl_do_setxattr(struct dentry *dentry, const char *name,
  81. const void *value, size_t size, int flags)
  82. {
  83. int err = vfs_setxattr(dentry, name, value, size, flags);
  84. pr_debug("setxattr(%pd2, \"%s\", \"%*s\", 0x%x) = %i\n",
  85. dentry, name, (int) size, (char *) value, flags, err);
  86. return err;
  87. }
  88. static inline int ovl_do_removexattr(struct dentry *dentry, const char *name)
  89. {
  90. int err = vfs_removexattr(dentry, name);
  91. pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
  92. return err;
  93. }
  94. static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry,
  95. struct inode *newdir, struct dentry *newdentry,
  96. unsigned int flags)
  97. {
  98. int err;
  99. pr_debug("rename2(%pd2, %pd2, 0x%x)\n",
  100. olddentry, newdentry, flags);
  101. err = vfs_rename(olddir, olddentry, newdir, newdentry, NULL, flags);
  102. if (err) {
  103. pr_debug("...rename2(%pd2, %pd2, ...) = %i\n",
  104. olddentry, newdentry, err);
  105. }
  106. return err;
  107. }
  108. static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry)
  109. {
  110. int err = vfs_whiteout(dir, dentry);
  111. pr_debug("whiteout(%pd2) = %i\n", dentry, err);
  112. return err;
  113. }
  114. enum ovl_path_type ovl_path_type(struct dentry *dentry);
  115. u64 ovl_dentry_version_get(struct dentry *dentry);
  116. void ovl_dentry_version_inc(struct dentry *dentry);
  117. void ovl_path_upper(struct dentry *dentry, struct path *path);
  118. void ovl_path_lower(struct dentry *dentry, struct path *path);
  119. enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
  120. int ovl_path_next(int idx, struct dentry *dentry, struct path *path);
  121. struct dentry *ovl_dentry_upper(struct dentry *dentry);
  122. struct dentry *ovl_dentry_lower(struct dentry *dentry);
  123. struct dentry *ovl_dentry_real(struct dentry *dentry);
  124. struct dentry *ovl_entry_real(struct ovl_entry *oe, bool *is_upper);
  125. struct ovl_dir_cache *ovl_dir_cache(struct dentry *dentry);
  126. void ovl_set_dir_cache(struct dentry *dentry, struct ovl_dir_cache *cache);
  127. struct dentry *ovl_workdir(struct dentry *dentry);
  128. int ovl_want_write(struct dentry *dentry);
  129. void ovl_drop_write(struct dentry *dentry);
  130. bool ovl_dentry_is_opaque(struct dentry *dentry);
  131. void ovl_dentry_set_opaque(struct dentry *dentry, bool opaque);
  132. bool ovl_is_whiteout(struct dentry *dentry);
  133. const struct cred *ovl_override_creds(struct super_block *sb);
  134. void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry);
  135. struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
  136. unsigned int flags);
  137. struct file *ovl_path_open(struct path *path, int flags);
  138. struct dentry *ovl_upper_create(struct dentry *upperdir, struct dentry *dentry,
  139. struct kstat *stat, const char *link);
  140. /* readdir.c */
  141. extern const struct file_operations ovl_dir_operations;
  142. int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
  143. void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list);
  144. void ovl_cache_free(struct list_head *list);
  145. int ovl_check_d_type_supported(struct path *realpath);
  146. void ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt,
  147. struct dentry *dentry, int level);
  148. /* inode.c */
  149. int ovl_setattr(struct dentry *dentry, struct iattr *attr);
  150. int ovl_permission(struct inode *inode, int mask);
  151. int ovl_setxattr(struct dentry *dentry, const char *name,
  152. const void *value, size_t size, int flags);
  153. ssize_t ovl_getxattr(struct dentry *dentry, const char *name,
  154. void *value, size_t size);
  155. ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
  156. int ovl_removexattr(struct dentry *dentry, const char *name);
  157. struct inode *ovl_d_select_inode(struct dentry *dentry, unsigned file_flags);
  158. bool ovl_is_private_xattr(const char *name);
  159. struct inode *ovl_new_inode(struct super_block *sb, umode_t mode,
  160. struct ovl_entry *oe);
  161. static inline void ovl_copyattr(struct inode *from, struct inode *to)
  162. {
  163. to->i_uid = from->i_uid;
  164. to->i_gid = from->i_gid;
  165. to->i_mode = from->i_mode;
  166. }
  167. /* dir.c */
  168. extern const struct inode_operations ovl_dir_inode_operations;
  169. struct dentry *ovl_lookup_temp(struct dentry *workdir, struct dentry *dentry);
  170. int ovl_create_real(struct inode *dir, struct dentry *newdentry,
  171. struct kstat *stat, const char *link,
  172. struct dentry *hardlink, bool debug);
  173. void ovl_cleanup(struct inode *dir, struct dentry *dentry);
  174. /* copy_up.c */
  175. int ovl_copy_up(struct dentry *dentry);
  176. int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
  177. struct path *lowerpath, struct kstat *stat);
  178. int ovl_copy_xattr(struct dentry *old, struct dentry *new);
  179. int ovl_set_attr(struct dentry *upper, struct kstat *stat);