namei.h 3.1 KB

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