namei.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_NAMEI_H
  3. #define _LINUX_NAMEI_H
  4. #include <linux/fs.h>
  5. #include <linux/kernel.h>
  6. #include <linux/path.h>
  7. #include <linux/fcntl.h>
  8. #include <linux/errno.h>
  9. enum { MAX_NESTED_LINKS = 8 };
  10. #define MAXSYMLINKS 40
  11. /*
  12. * Type of the last component on LOOKUP_PARENT
  13. */
  14. enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT};
  15. /* pathwalk mode */
  16. #define LOOKUP_FOLLOW 0x0001 /* follow links at the end */
  17. #define LOOKUP_DIRECTORY 0x0002 /* require a directory */
  18. #define LOOKUP_AUTOMOUNT 0x0004 /* force terminal automount */
  19. #define LOOKUP_EMPTY 0x4000 /* accept empty path [user_... only] */
  20. #define LOOKUP_DOWN 0x8000 /* follow mounts in the starting point */
  21. #define LOOKUP_MOUNTPOINT 0x0080 /* follow mounts in the end */
  22. #define LOOKUP_REVAL 0x0020 /* tell ->d_revalidate() to trust no cache */
  23. #define LOOKUP_RCU 0x0040 /* RCU pathwalk mode; semi-internal */
  24. /* These tell filesystem methods that we are dealing with the final component... */
  25. #define LOOKUP_OPEN 0x0100 /* ... in open */
  26. #define LOOKUP_CREATE 0x0200 /* ... in object creation */
  27. #define LOOKUP_EXCL 0x0400 /* ... in exclusive creation */
  28. #define LOOKUP_RENAME_TARGET 0x0800 /* ... in destination of rename() */
  29. /* internal use only */
  30. #define LOOKUP_PARENT 0x0010
  31. /* Scoping flags for lookup. */
  32. #define LOOKUP_NO_SYMLINKS 0x010000 /* No symlink crossing. */
  33. #define LOOKUP_NO_MAGICLINKS 0x020000 /* No nd_jump_link() crossing. */
  34. #define LOOKUP_NO_XDEV 0x040000 /* No mountpoint crossing. */
  35. #define LOOKUP_BENEATH 0x080000 /* No escaping from starting point. */
  36. #define LOOKUP_IN_ROOT 0x100000 /* Treat dirfd as fs root. */
  37. #define LOOKUP_CACHED 0x200000 /* Only do cached lookup */
  38. /* LOOKUP_* flags which do scope-related checks based on the dirfd. */
  39. #define LOOKUP_IS_SCOPED (LOOKUP_BENEATH | LOOKUP_IN_ROOT)
  40. extern int path_pts(struct path *path);
  41. extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
  42. static inline int user_path_at(int dfd, const char __user *name, unsigned flags,
  43. struct path *path)
  44. {
  45. return user_path_at_empty(dfd, name, flags, path, NULL);
  46. }
  47. extern int kern_path(const char *, unsigned, struct path *);
  48. extern struct dentry *kern_path_create(int, const char *, struct path *, unsigned int);
  49. extern struct dentry *user_path_create(int, const char __user *, struct path *, unsigned int);
  50. extern void done_path_create(struct path *, struct dentry *);
  51. extern struct dentry *kern_path_locked(const char *, struct path *);
  52. extern struct dentry *try_lookup_one_len(const char *, struct dentry *, int);
  53. extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
  54. extern struct dentry *lookup_one_len_unlocked(const char *, struct dentry *, int);
  55. extern struct dentry *lookup_positive_unlocked(const char *, struct dentry *, int);
  56. struct dentry *lookup_one(struct user_namespace *, const char *, struct dentry *, int);
  57. struct dentry *lookup_one_unlocked(struct user_namespace *mnt_userns,
  58. const char *name, struct dentry *base,
  59. int len);
  60. struct dentry *lookup_one_positive_unlocked(struct user_namespace *mnt_userns,
  61. const char *name,
  62. struct dentry *base, int len);
  63. extern int follow_down_one(struct path *);
  64. extern int follow_down(struct path *);
  65. extern int follow_up(struct path *);
  66. extern struct dentry *lock_rename(struct dentry *, struct dentry *);
  67. extern void unlock_rename(struct dentry *, struct dentry *);
  68. extern int __must_check nd_jump_link(const struct path *path);
  69. static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
  70. {
  71. ((char *) name)[min(len, maxlen)] = '\0';
  72. }
  73. /**
  74. * retry_estale - determine whether the caller should retry an operation
  75. * @error: the error that would currently be returned
  76. * @flags: flags being used for next lookup attempt
  77. *
  78. * Check to see if the error code was -ESTALE, and then determine whether
  79. * to retry the call based on whether "flags" already has LOOKUP_REVAL set.
  80. *
  81. * Returns true if the caller should try the operation again.
  82. */
  83. static inline bool
  84. retry_estale(const long error, const unsigned int flags)
  85. {
  86. return error == -ESTALE && !(flags & LOOKUP_REVAL);
  87. }
  88. #endif /* _LINUX_NAMEI_H */