1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * Copyright (C) 2011 Novell Inc.
5 * Copyright (C) 2016 Red Hat, Inc.
12 bool default_permissions
;
25 struct super_block
*sb
;
27 /* Unusable (conflicting) uuid */
29 /* Used as a lower layer (but maybe also as upper) */
34 /* ovl_free_fs() relies on @mnt being the first member! */
36 /* Trap in ovl inode cache */
39 /* Index of this layer in fs root (upper idx == 0) */
41 /* One fsid per unique underlying sb (upper fsid == 0) */
43 /* xwhiteouts were found on this layer */
48 const struct ovl_layer
*layer
;
49 struct dentry
*dentry
;
53 unsigned int __numlower
;
54 struct ovl_path __lowerstack
[];
57 /* private information held for overlayfs's superblock */
59 unsigned int numlayer
;
60 /* Number of unique fs among layers including upper fs */
62 /* Number of data-only lower layers */
63 unsigned int numdatalayer
;
64 struct ovl_layer
*layers
;
66 /* workbasedir is the path at workdir= mount option */
67 struct dentry
*workbasedir
;
68 /* workdir is the 'work' or 'index' directory under workbasedir */
69 struct dentry
*workdir
;
71 /* pathnames of lower and upper dirs, for show_options */
72 struct ovl_config config
;
73 /* creds of process who forced instantiation of super block */
74 const struct cred
*creator_cred
;
78 /* Did we take the inuse lock? */
81 /* Traps in ovl inode cache */
82 struct inode
*workbasedir_trap
;
83 struct inode
*workdir_trap
;
84 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
86 /* For allocation of non-persistent inode numbers */
87 atomic_long_t last_ino
;
88 /* Shared whiteout cache */
89 struct dentry
*whiteout
;
90 bool no_shared_whiteout
;
91 /* r/o snapshot of upperdir sb's only taken on volatile mounts */
95 /* Number of lower layers, not including data-only layers */
96 static inline unsigned int ovl_numlowerlayer(struct ovl_fs
*ofs
)
98 return ofs
->numlayer
- ofs
->numdatalayer
- 1;
101 static inline struct vfsmount
*ovl_upper_mnt(struct ovl_fs
*ofs
)
103 return ofs
->layers
[0].mnt
;
106 static inline struct mnt_idmap
*ovl_upper_mnt_idmap(struct ovl_fs
*ofs
)
108 return mnt_idmap(ovl_upper_mnt(ofs
));
111 extern struct file_system_type ovl_fs_type
;
113 static inline struct ovl_fs
*OVL_FS(struct super_block
*sb
)
115 if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG
))
116 WARN_ON_ONCE(sb
->s_type
!= &ovl_fs_type
);
118 return (struct ovl_fs
*)sb
->s_fs_info
;
121 static inline bool ovl_should_sync(struct ovl_fs
*ofs
)
123 return !ofs
->config
.ovl_volatile
;
126 static inline unsigned int ovl_numlower(struct ovl_entry
*oe
)
128 return oe
? oe
->__numlower
: 0;
131 static inline struct ovl_path
*ovl_lowerstack(struct ovl_entry
*oe
)
133 return ovl_numlower(oe
) ? oe
->__lowerstack
: NULL
;
136 static inline struct ovl_path
*ovl_lowerpath(struct ovl_entry
*oe
)
138 return ovl_lowerstack(oe
);
141 static inline struct ovl_path
*ovl_lowerdata(struct ovl_entry
*oe
)
143 struct ovl_path
*lowerstack
= ovl_lowerstack(oe
);
145 return lowerstack
? &lowerstack
[oe
->__numlower
- 1] : NULL
;
148 /* May return NULL if lazy lookup of lowerdata is needed */
149 static inline struct dentry
*ovl_lowerdata_dentry(struct ovl_entry
*oe
)
151 struct ovl_path
*lowerdata
= ovl_lowerdata(oe
);
153 return lowerdata
? READ_ONCE(lowerdata
->dentry
) : NULL
;
156 /* private information held for every overlayfs dentry */
157 static inline unsigned long *OVL_E_FLAGS(struct dentry
*dentry
)
159 return (unsigned long *) &dentry
->d_fsdata
;
164 struct ovl_dir_cache
*cache
; /* directory */
165 const char *lowerdata_redirect
; /* regular file */
167 const char *redirect
;
170 struct inode vfs_inode
;
171 struct dentry
*__upperdentry
;
172 struct ovl_entry
*oe
;
174 /* synchronize copy up and more */
178 static inline struct ovl_inode
*OVL_I(struct inode
*inode
)
180 return container_of(inode
, struct ovl_inode
, vfs_inode
);
183 static inline struct ovl_entry
*OVL_I_E(struct inode
*inode
)
185 return inode
? OVL_I(inode
)->oe
: NULL
;
188 static inline struct ovl_entry
*OVL_E(struct dentry
*dentry
)
190 return OVL_I_E(d_inode(dentry
));
193 static inline struct dentry
*ovl_upperdentry_dereference(struct ovl_inode
*oi
)
195 return READ_ONCE(oi
->__upperdentry
);