1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * Copyright (C) 2011 Novell Inc.
5 * Copyright (C) 2016 Red Hat, Inc.
11 bool default_permissions;
24 struct super_block *sb;
26 /* Unusable (conflicting) uuid */
28 /* Used as a lower layer (but maybe also as upper) */
33 /* ovl_free_fs() relies on @mnt being the first member! */
35 /* Trap in ovl inode cache */
38 /* Index of this layer in fs root (upper idx == 0) */
40 /* One fsid per unique underlying sb (upper fsid == 0) */
46 * ovl_free_fs() relies on @mnt being the first member when unmounting
47 * the private mounts created for each layer. Let's check both the
50 static_assert(offsetof(struct ovl_layer, mnt) == 0);
51 static_assert(__same_type(typeof_member(struct ovl_layer, mnt), struct vfsmount *));
54 const struct ovl_layer *layer;
55 struct dentry *dentry;
59 unsigned int __numlower;
60 struct ovl_path __lowerstack[];
63 /* private information held for overlayfs's superblock */
65 unsigned int numlayer;
66 /* Number of unique fs among layers including upper fs */
68 /* Number of data-only lower layers */
69 unsigned int numdatalayer;
70 const struct ovl_layer *layers;
72 /* workbasedir is the path at workdir= mount option */
73 struct dentry *workbasedir;
74 /* workdir is the 'work' directory under workbasedir */
75 struct dentry *workdir;
76 /* index directory listing overlay inodes by origin file handle */
77 struct dentry *indexdir;
79 /* pathnames of lower and upper dirs, for show_options */
80 struct ovl_config config;
81 /* creds of process who forced instantiation of super block */
82 const struct cred *creator_cred;
86 /* Did we take the inuse lock? */
89 /* Traps in ovl inode cache */
90 struct inode *workbasedir_trap;
91 struct inode *workdir_trap;
92 struct inode *indexdir_trap;
93 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
95 /* For allocation of non-persistent inode numbers */
96 atomic_long_t last_ino;
97 /* Shared whiteout cache */
98 struct dentry *whiteout;
99 bool no_shared_whiteout;
100 /* r/o snapshot of upperdir sb's only taken on volatile mounts */
104 /* Number of lower layers, not including data-only layers */
105 static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs)
107 return ofs->numlayer - ofs->numdatalayer - 1;
110 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
112 return ofs->layers[0].mnt;
115 static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
117 return mnt_idmap(ovl_upper_mnt(ofs));
120 extern struct file_system_type ovl_fs_type;
122 static inline struct ovl_fs *OVL_FS(struct super_block *sb)
124 if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG))
125 WARN_ON_ONCE(sb->s_type != &ovl_fs_type);
127 return (struct ovl_fs *)sb->s_fs_info;
130 static inline bool ovl_should_sync(struct ovl_fs *ofs)
132 return !ofs->config.ovl_volatile;
135 static inline unsigned int ovl_numlower(struct ovl_entry *oe)
137 return oe ? oe->__numlower : 0;
140 static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe)
142 return ovl_numlower(oe) ? oe->__lowerstack : NULL;
145 static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe)
147 return ovl_lowerstack(oe);
150 static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe)
152 struct ovl_path *lowerstack = ovl_lowerstack(oe);
154 return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL;
157 /* May return NULL if lazy lookup of lowerdata is needed */
158 static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe)
160 struct ovl_path *lowerdata = ovl_lowerdata(oe);
162 return lowerdata ? READ_ONCE(lowerdata->dentry) : NULL;
165 /* private information held for every overlayfs dentry */
166 static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry)
168 return (unsigned long *) &dentry->d_fsdata;
173 struct ovl_dir_cache *cache; /* directory */
174 const char *lowerdata_redirect; /* regular file */
176 const char *redirect;
179 struct inode vfs_inode;
180 struct dentry *__upperdentry;
181 struct ovl_entry *oe;
183 /* synchronize copy up and more */
187 static inline struct ovl_inode *OVL_I(struct inode *inode)
189 return container_of(inode, struct ovl_inode, vfs_inode);
192 static inline struct ovl_entry *OVL_I_E(struct inode *inode)
194 return inode ? OVL_I(inode)->oe : NULL;
197 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
199 return OVL_I_E(d_inode(dentry));
202 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
204 return READ_ONCE(oi->__upperdentry);