namei.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #ifndef _LINUX_NAMEI_H
  2. #define _LINUX_NAMEI_H
  3. #include <linux/dcache.h>
  4. #include <linux/errno.h>
  5. #include <linux/linkage.h>
  6. #include <linux/path.h>
  7. struct vfsmount;
  8. enum { MAX_NESTED_LINKS = 8 };
  9. struct nameidata {
  10. struct path path;
  11. struct qstr last;
  12. struct path root;
  13. struct inode *inode; /* path.dentry.d_inode */
  14. unsigned int flags;
  15. unsigned seq;
  16. int last_type;
  17. unsigned depth;
  18. char *saved_names[MAX_NESTED_LINKS + 1];
  19. };
  20. /*
  21. * Type of the last component on LOOKUP_PARENT
  22. */
  23. enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
  24. /*
  25. * The bitmask for a lookup event:
  26. * - follow links at the end
  27. * - require a directory
  28. * - ending slashes ok even for nonexistent files
  29. * - internal "there are more path components" flag
  30. * - dentry cache is untrusted; force a real lookup
  31. * - suppress terminal automount
  32. */
  33. #define LOOKUP_FOLLOW 0x0001
  34. #define LOOKUP_DIRECTORY 0x0002
  35. #define LOOKUP_AUTOMOUNT 0x0004
  36. #define LOOKUP_PARENT 0x0010
  37. #define LOOKUP_REVAL 0x0020
  38. #define LOOKUP_RCU 0x0040
  39. /*
  40. * Intent data
  41. */
  42. #define LOOKUP_OPEN 0x0100
  43. #define LOOKUP_CREATE 0x0200
  44. #define LOOKUP_EXCL 0x0400
  45. #define LOOKUP_RENAME_TARGET 0x0800
  46. #define LOOKUP_JUMPED 0x1000
  47. #define LOOKUP_ROOT 0x2000
  48. #define LOOKUP_EMPTY 0x4000
  49. extern int user_path_at(int, const char __user *, unsigned, struct path *);
  50. extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
  51. #define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path)
  52. #define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path)
  53. #define user_path_dir(name, path) \
  54. user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, path)
  55. extern int kern_path(const char *, unsigned, struct path *);
  56. extern struct dentry *kern_path_create(int, const char *, struct path *, unsigned int);
  57. extern struct dentry *user_path_create(int, const char __user *, struct path *, unsigned int);
  58. extern void done_path_create(struct path *, struct dentry *);
  59. extern struct dentry *kern_path_locked(const char *, struct path *);
  60. extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
  61. const char *, unsigned int, struct path *);
  62. extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
  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 void nd_jump_link(struct nameidata *nd, struct path *path);
  69. static inline void nd_set_link(struct nameidata *nd, char *path)
  70. {
  71. nd->saved_names[nd->depth] = path;
  72. }
  73. static inline char *nd_get_link(struct nameidata *nd)
  74. {
  75. return nd->saved_names[nd->depth];
  76. }
  77. static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
  78. {
  79. ((char *) name)[min(len, maxlen)] = '\0';
  80. }
  81. /**
  82. * retry_estale - determine whether the caller should retry an operation
  83. * @error: the error that would currently be returned
  84. * @flags: flags being used for next lookup attempt
  85. *
  86. * Check to see if the error code was -ESTALE, and then determine whether
  87. * to retry the call based on whether "flags" already has LOOKUP_REVAL set.
  88. *
  89. * Returns true if the caller should try the operation again.
  90. */
  91. static inline bool
  92. retry_estale(const long error, const unsigned int flags)
  93. {
  94. return error == -ESTALE && !(flags & LOOKUP_REVAL);
  95. }
  96. #endif /* _LINUX_NAMEI_H */