Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_NAMEI_H
0003 #define _LINUX_NAMEI_H
0004 
0005 #include <linux/fs.h>
0006 #include <linux/kernel.h>
0007 #include <linux/path.h>
0008 #include <linux/fcntl.h>
0009 #include <linux/errno.h>
0010 
0011 enum { MAX_NESTED_LINKS = 8 };
0012 
0013 #define MAXSYMLINKS 40
0014 
0015 /*
0016  * Type of the last component on LOOKUP_PARENT
0017  */
0018 enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT};
0019 
0020 /* pathwalk mode */
0021 #define LOOKUP_FOLLOW       0x0001  /* follow links at the end */
0022 #define LOOKUP_DIRECTORY    0x0002  /* require a directory */
0023 #define LOOKUP_AUTOMOUNT    0x0004  /* force terminal automount */
0024 #define LOOKUP_EMPTY        0x4000  /* accept empty path [user_... only] */
0025 #define LOOKUP_DOWN     0x8000  /* follow mounts in the starting point */
0026 #define LOOKUP_MOUNTPOINT   0x0080  /* follow mounts in the end */
0027 
0028 #define LOOKUP_REVAL        0x0020  /* tell ->d_revalidate() to trust no cache */
0029 #define LOOKUP_RCU      0x0040  /* RCU pathwalk mode; semi-internal */
0030 
0031 /* These tell filesystem methods that we are dealing with the final component... */
0032 #define LOOKUP_OPEN     0x0100  /* ... in open */
0033 #define LOOKUP_CREATE       0x0200  /* ... in object creation */
0034 #define LOOKUP_EXCL     0x0400  /* ... in exclusive creation */
0035 #define LOOKUP_RENAME_TARGET    0x0800  /* ... in destination of rename() */
0036 
0037 /* internal use only */
0038 #define LOOKUP_PARENT       0x0010
0039 
0040 /* Scoping flags for lookup. */
0041 #define LOOKUP_NO_SYMLINKS  0x010000 /* No symlink crossing. */
0042 #define LOOKUP_NO_MAGICLINKS    0x020000 /* No nd_jump_link() crossing. */
0043 #define LOOKUP_NO_XDEV      0x040000 /* No mountpoint crossing. */
0044 #define LOOKUP_BENEATH      0x080000 /* No escaping from starting point. */
0045 #define LOOKUP_IN_ROOT      0x100000 /* Treat dirfd as fs root. */
0046 #define LOOKUP_CACHED       0x200000 /* Only do cached lookup */
0047 /* LOOKUP_* flags which do scope-related checks based on the dirfd. */
0048 #define LOOKUP_IS_SCOPED (LOOKUP_BENEATH | LOOKUP_IN_ROOT)
0049 
0050 extern int path_pts(struct path *path);
0051 
0052 extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
0053 
0054 static inline int user_path_at(int dfd, const char __user *name, unsigned flags,
0055          struct path *path)
0056 {
0057     return user_path_at_empty(dfd, name, flags, path, NULL);
0058 }
0059 
0060 extern int kern_path(const char *, unsigned, struct path *);
0061 
0062 extern struct dentry *kern_path_create(int, const char *, struct path *, unsigned int);
0063 extern struct dentry *user_path_create(int, const char __user *, struct path *, unsigned int);
0064 extern void done_path_create(struct path *, struct dentry *);
0065 extern struct dentry *kern_path_locked(const char *, struct path *);
0066 
0067 extern struct dentry *try_lookup_one_len(const char *, struct dentry *, int);
0068 extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
0069 extern struct dentry *lookup_one_len_unlocked(const char *, struct dentry *, int);
0070 extern struct dentry *lookup_positive_unlocked(const char *, struct dentry *, int);
0071 struct dentry *lookup_one(struct user_namespace *, const char *, struct dentry *, int);
0072 struct dentry *lookup_one_unlocked(struct user_namespace *mnt_userns,
0073                    const char *name, struct dentry *base,
0074                    int len);
0075 struct dentry *lookup_one_positive_unlocked(struct user_namespace *mnt_userns,
0076                         const char *name,
0077                         struct dentry *base, int len);
0078 
0079 extern int follow_down_one(struct path *);
0080 extern int follow_down(struct path *);
0081 extern int follow_up(struct path *);
0082 
0083 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
0084 extern void unlock_rename(struct dentry *, struct dentry *);
0085 
0086 extern int __must_check nd_jump_link(struct path *path);
0087 
0088 static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
0089 {
0090     ((char *) name)[min(len, maxlen)] = '\0';
0091 }
0092 
0093 /**
0094  * retry_estale - determine whether the caller should retry an operation
0095  * @error: the error that would currently be returned
0096  * @flags: flags being used for next lookup attempt
0097  *
0098  * Check to see if the error code was -ESTALE, and then determine whether
0099  * to retry the call based on whether "flags" already has LOOKUP_REVAL set.
0100  *
0101  * Returns true if the caller should try the operation again.
0102  */
0103 static inline bool
0104 retry_estale(const long error, const unsigned int flags)
0105 {
0106     return error == -ESTALE && !(flags & LOOKUP_REVAL);
0107 }
0108 
0109 #endif /* _LINUX_NAMEI_H */