Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_NAMEI_H
3#define _LINUX_NAMEI_H
4
5#include <linux/fs.h>
6#include <linux/kernel.h>
7#include <linux/path.h>
8#include <linux/fcntl.h>
9#include <linux/errno.h>
10#include <linux/fs_struct.h>
11
12enum { MAX_NESTED_LINKS = 8 };
13
14#define MAXSYMLINKS 40
15
16/*
17 * Type of the last component on LOOKUP_PARENT
18 */
19enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT};
20
21/* pathwalk mode */
22#define LOOKUP_FOLLOW BIT(0) /* follow links at the end */
23#define LOOKUP_DIRECTORY BIT(1) /* require a directory */
24#define LOOKUP_AUTOMOUNT BIT(2) /* force terminal automount */
25#define LOOKUP_EMPTY BIT(3) /* accept empty path [user_... only] */
26#define LOOKUP_LINKAT_EMPTY BIT(4) /* Linkat request with empty path. */
27#define LOOKUP_DOWN BIT(5) /* follow mounts in the starting point */
28#define LOOKUP_MOUNTPOINT BIT(6) /* follow mounts in the end */
29#define LOOKUP_REVAL BIT(7) /* tell ->d_revalidate() to trust no cache */
30#define LOOKUP_RCU BIT(8) /* RCU pathwalk mode; semi-internal */
31#define LOOKUP_CACHED BIT(9) /* Only do cached lookup */
32#define LOOKUP_PARENT BIT(10) /* Looking up final parent in path */
33/* 5 spare bits for pathwalk */
34
35/* These tell filesystem methods that we are dealing with the final component... */
36#define LOOKUP_OPEN BIT(16) /* ... in open */
37#define LOOKUP_CREATE BIT(17) /* ... in object creation */
38#define LOOKUP_EXCL BIT(18) /* ... in target must not exist */
39#define LOOKUP_RENAME_TARGET BIT(19) /* ... in destination of rename() */
40
41/* 4 spare bits for intent */
42
43/* Scoping flags for lookup. */
44#define LOOKUP_NO_SYMLINKS BIT(24) /* No symlink crossing. */
45#define LOOKUP_NO_MAGICLINKS BIT(25) /* No nd_jump_link() crossing. */
46#define LOOKUP_NO_XDEV BIT(26) /* No mountpoint crossing. */
47#define LOOKUP_BENEATH BIT(27) /* No escaping from starting point. */
48#define LOOKUP_IN_ROOT BIT(28) /* Treat dirfd as fs root. */
49/* LOOKUP_* flags which do scope-related checks based on the dirfd. */
50#define LOOKUP_IS_SCOPED (LOOKUP_BENEATH | LOOKUP_IN_ROOT)
51/* 3 spare bits for scoping */
52
53extern int path_pts(struct path *path);
54
55extern int user_path_at(int, const char __user *, unsigned, struct path *);
56
57extern int kern_path(const char *, unsigned, struct path *);
58struct dentry *kern_path_parent(const char *name, struct path *parent);
59
60extern struct dentry *start_creating_path(int, const char *, struct path *, unsigned int);
61extern struct dentry *start_creating_user_path(int, const char __user *, struct path *, unsigned int);
62extern void end_creating_path(const struct path *, struct dentry *);
63extern struct dentry *start_removing_path(const char *, struct path *);
64extern struct dentry *start_removing_user_path_at(int , const char __user *, struct path *);
65static inline void end_removing_path(const struct path *path , struct dentry *dentry)
66{
67 end_creating_path(path, dentry);
68}
69int vfs_path_parent_lookup(struct filename *filename, unsigned int flags,
70 struct path *parent, struct qstr *last, int *type,
71 const struct path *root);
72int vfs_path_lookup(struct dentry *, struct vfsmount *, const char *,
73 unsigned int, struct path *);
74
75extern struct dentry *try_lookup_noperm(struct qstr *, struct dentry *);
76extern struct dentry *lookup_noperm(struct qstr *, struct dentry *);
77extern struct dentry *lookup_noperm_unlocked(struct qstr *, struct dentry *);
78extern struct dentry *lookup_noperm_positive_unlocked(struct qstr *, struct dentry *);
79struct dentry *lookup_one(struct mnt_idmap *, struct qstr *, struct dentry *);
80struct dentry *lookup_one_unlocked(struct mnt_idmap *idmap,
81 struct qstr *name, struct dentry *base);
82struct dentry *lookup_one_positive_unlocked(struct mnt_idmap *idmap,
83 struct qstr *name,
84 struct dentry *base);
85struct dentry *lookup_one_positive_killable(struct mnt_idmap *idmap,
86 struct qstr *name,
87 struct dentry *base);
88
89struct dentry *start_creating(struct mnt_idmap *idmap, struct dentry *parent,
90 struct qstr *name);
91struct dentry *start_removing(struct mnt_idmap *idmap, struct dentry *parent,
92 struct qstr *name);
93struct dentry *start_creating_killable(struct mnt_idmap *idmap,
94 struct dentry *parent,
95 struct qstr *name);
96struct dentry *start_removing_killable(struct mnt_idmap *idmap,
97 struct dentry *parent,
98 struct qstr *name);
99struct dentry *start_creating_noperm(struct dentry *parent, struct qstr *name);
100struct dentry *start_removing_noperm(struct dentry *parent, struct qstr *name);
101struct dentry *start_creating_dentry(struct dentry *parent,
102 struct dentry *child);
103struct dentry *start_removing_dentry(struct dentry *parent,
104 struct dentry *child);
105
106/* end_creating - finish action started with start_creating
107 * @child: dentry returned by start_creating() or vfs_mkdir()
108 *
109 * Unlock and release the child. This can be called after
110 * start_creating() whether that function succeeded or not,
111 * but it is not needed on failure.
112 *
113 * If vfs_mkdir() was called then the value returned from that function
114 * should be given for @child rather than the original dentry, as vfs_mkdir()
115 * may have provided a new dentry.
116 *
117 *
118 * If vfs_mkdir() was not called, then @child will be a valid dentry and
119 * @parent will be ignored.
120 */
121static inline void end_creating(struct dentry *child)
122{
123 end_dirop(child);
124}
125
126/* end_creating_keep - finish action started with start_creating() and return result
127 * @child: dentry returned by start_creating() or vfs_mkdir()
128 *
129 * Unlock and return the child. This can be called after
130 * start_creating() whether that function succeeded or not,
131 * but it is not needed on failure.
132 *
133 * If vfs_mkdir() was called then the value returned from that function
134 * should be given for @child rather than the original dentry, as vfs_mkdir()
135 * may have provided a new dentry.
136 *
137 * Returns: @child, which may be a dentry or an error.
138 *
139 */
140static inline struct dentry *end_creating_keep(struct dentry *child)
141{
142 if (!IS_ERR(child))
143 dget(child);
144 end_dirop(child);
145 return child;
146}
147
148/**
149 * end_removing - finish action started with start_removing
150 * @child: dentry returned by start_removing()
151 * @parent: dentry given to start_removing()
152 *
153 * Unlock and release the child.
154 *
155 * This is identical to end_dirop(). It can be passed the result of
156 * start_removing() whether that was successful or not, but it not needed
157 * if start_removing() failed.
158 */
159static inline void end_removing(struct dentry *child)
160{
161 end_dirop(child);
162}
163
164extern int follow_down_one(struct path *);
165extern int follow_down(struct path *path, unsigned int flags);
166extern int follow_up(struct path *);
167
168int start_renaming(struct renamedata *rd, int lookup_flags,
169 struct qstr *old_last, struct qstr *new_last);
170int start_renaming_dentry(struct renamedata *rd, int lookup_flags,
171 struct dentry *old_dentry, struct qstr *new_last);
172int start_renaming_two_dentries(struct renamedata *rd,
173 struct dentry *old_dentry, struct dentry *new_dentry);
174void end_renaming(struct renamedata *rd);
175
176/**
177 * mode_strip_umask - handle vfs umask stripping
178 * @dir: parent directory of the new inode
179 * @mode: mode of the new inode to be created in @dir
180 *
181 * In most filesystems, umask stripping depends on whether or not the
182 * filesystem supports POSIX ACLs. If the filesystem doesn't support it umask
183 * stripping is done directly in here. If the filesystem does support POSIX
184 * ACLs umask stripping is deferred until the filesystem calls
185 * posix_acl_create().
186 *
187 * Some filesystems (like NFSv4) also want to avoid umask stripping by the
188 * VFS, but don't support POSIX ACLs. Those filesystems can set SB_I_NOUMASK
189 * to get this effect without declaring that they support POSIX ACLs.
190 *
191 * Returns: mode
192 */
193static inline umode_t __must_check mode_strip_umask(const struct inode *dir, umode_t mode)
194{
195 if (!IS_POSIXACL(dir) && !(dir->i_sb->s_iflags & SB_I_NOUMASK))
196 mode &= ~current_umask();
197 return mode;
198}
199
200extern int __must_check nd_jump_link(const struct path *path);
201
202static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
203{
204 ((char *) name)[min(len, maxlen)] = '\0';
205}
206
207/**
208 * retry_estale - determine whether the caller should retry an operation
209 * @error: the error that would currently be returned
210 * @flags: flags being used for next lookup attempt
211 *
212 * Check to see if the error code was -ESTALE, and then determine whether
213 * to retry the call based on whether "flags" already has LOOKUP_REVAL set.
214 *
215 * Returns true if the caller should try the operation again.
216 */
217static inline bool
218retry_estale(const long error, const unsigned int flags)
219{
220 return unlikely(error == -ESTALE && !(flags & LOOKUP_REVAL));
221}
222
223#endif /* _LINUX_NAMEI_H */