namei.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef _LINUX_NAMEI_H
  2. #define _LINUX_NAMEI_H
  3. #include <linux/dcache.h>
  4. #include <linux/linkage.h>
  5. #include <linux/path.h>
  6. struct vfsmount;
  7. enum { MAX_NESTED_LINKS = 8 };
  8. struct nameidata {
  9. struct path path;
  10. struct qstr last;
  11. struct path root;
  12. struct inode *inode; /* path.dentry.d_inode */
  13. unsigned int flags;
  14. unsigned seq;
  15. int last_type;
  16. unsigned depth;
  17. char *saved_names[MAX_NESTED_LINKS + 1];
  18. };
  19. /*
  20. * Type of the last component on LOOKUP_PARENT
  21. */
  22. enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
  23. /*
  24. * The bitmask for a lookup event:
  25. * - follow links at the end
  26. * - require a directory
  27. * - ending slashes ok even for nonexistent files
  28. * - internal "there are more path components" flag
  29. * - dentry cache is untrusted; force a real lookup
  30. * - suppress terminal automount
  31. */
  32. #define LOOKUP_FOLLOW 0x0001
  33. #define LOOKUP_DIRECTORY 0x0002
  34. #define LOOKUP_AUTOMOUNT 0x0004
  35. #define LOOKUP_PARENT 0x0010
  36. #define LOOKUP_REVAL 0x0020
  37. #define LOOKUP_RCU 0x0040
  38. /*
  39. * Intent data
  40. */
  41. #define LOOKUP_OPEN 0x0100
  42. #define LOOKUP_CREATE 0x0200
  43. #define LOOKUP_EXCL 0x0400
  44. #define LOOKUP_RENAME_TARGET 0x0800
  45. #define LOOKUP_JUMPED 0x1000
  46. #define LOOKUP_ROOT 0x2000
  47. #define LOOKUP_EMPTY 0x4000
  48. extern int user_path_at(int, const char __user *, unsigned, struct path *);
  49. extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
  50. #define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path)
  51. #define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path)
  52. #define user_path_dir(name, path) \
  53. user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, path)
  54. extern int kern_path(const char *, unsigned, struct path *);
  55. extern struct dentry *kern_path_create(int, const char *, struct path *, int);
  56. extern struct dentry *user_path_create(int, const char __user *, struct path *, int);
  57. extern void done_path_create(struct path *, struct dentry *);
  58. extern struct dentry *kern_path_locked(const char *, struct path *);
  59. extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
  60. const char *, unsigned int, struct path *);
  61. extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
  62. extern int follow_down_one(struct path *);
  63. extern int follow_down(struct path *);
  64. extern int follow_up(struct path *);
  65. extern struct dentry *lock_rename(struct dentry *, struct dentry *);
  66. extern void unlock_rename(struct dentry *, struct dentry *);
  67. extern void nd_jump_link(struct nameidata *nd, struct path *path);
  68. static inline void nd_set_link(struct nameidata *nd, char *path)
  69. {
  70. nd->saved_names[nd->depth] = path;
  71. }
  72. static inline char *nd_get_link(struct nameidata *nd)
  73. {
  74. return nd->saved_names[nd->depth];
  75. }
  76. static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
  77. {
  78. ((char *) name)[min(len, maxlen)] = '\0';
  79. }
  80. #endif /* _LINUX_NAMEI_H */