overlayfs.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry);
  134. struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
  135. unsigned int flags);
  136. struct file *ovl_path_open(struct path *path, int flags);
  137. struct dentry *ovl_upper_create(struct dentry *upperdir, struct dentry *dentry,
  138. struct kstat *stat, const char *link);
  139. /* readdir.c */
  140. extern const struct file_operations ovl_dir_operations;
  141. int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
  142. void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list);
  143. void ovl_cache_free(struct list_head *list);
  144. /* inode.c */
  145. int ovl_setattr(struct dentry *dentry, struct iattr *attr);
  146. int ovl_permission(struct inode *inode, int mask);
  147. int ovl_setxattr(struct dentry *dentry, const char *name,
  148. const void *value, size_t size, int flags);
  149. ssize_t ovl_getxattr(struct dentry *dentry, const char *name,
  150. void *value, size_t size);
  151. ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
  152. int ovl_removexattr(struct dentry *dentry, const char *name);
  153. struct inode *ovl_d_select_inode(struct dentry *dentry, unsigned file_flags);
  154. struct inode *ovl_new_inode(struct super_block *sb, umode_t mode,
  155. struct ovl_entry *oe);
  156. static inline void ovl_copyattr(struct inode *from, struct inode *to)
  157. {
  158. to->i_uid = from->i_uid;
  159. to->i_gid = from->i_gid;
  160. }
  161. /* dir.c */
  162. extern const struct inode_operations ovl_dir_inode_operations;
  163. struct dentry *ovl_lookup_temp(struct dentry *workdir, struct dentry *dentry);
  164. int ovl_create_real(struct inode *dir, struct dentry *newdentry,
  165. struct kstat *stat, const char *link,
  166. struct dentry *hardlink, bool debug);
  167. void ovl_cleanup(struct inode *dir, struct dentry *dentry);
  168. /* copy_up.c */
  169. int ovl_copy_up(struct dentry *dentry);
  170. int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
  171. struct path *lowerpath, struct kstat *stat,
  172. struct iattr *attr);
  173. int ovl_copy_xattr(struct dentry *old, struct dentry *new);
  174. int ovl_set_attr(struct dentry *upper, struct kstat *stat);