namei.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. unsigned int flags;
  18. int last_type;
  19. unsigned depth;
  20. char *saved_names[MAX_NESTED_LINKS + 1];
  21. /* Intent data */
  22. union {
  23. struct open_intent open;
  24. } intent;
  25. };
  26. /*
  27. * Type of the last component on LOOKUP_PARENT
  28. */
  29. enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
  30. /*
  31. * The bitmask for a lookup event:
  32. * - follow links at the end
  33. * - require a directory
  34. * - ending slashes ok even for nonexistent files
  35. * - internal "there are more path components" flag
  36. * - locked when lookup done with dcache_lock held
  37. * - dentry cache is untrusted; force a real lookup
  38. */
  39. #define LOOKUP_FOLLOW 1
  40. #define LOOKUP_DIRECTORY 2
  41. #define LOOKUP_CONTINUE 4
  42. #define LOOKUP_PARENT 16
  43. #define LOOKUP_REVAL 64
  44. /*
  45. * Intent data
  46. */
  47. #define LOOKUP_OPEN 0x0100
  48. #define LOOKUP_CREATE 0x0200
  49. #define LOOKUP_EXCL 0x0400
  50. #define LOOKUP_RENAME_TARGET 0x0800
  51. extern int user_path_at(int, const char __user *, unsigned, struct path *);
  52. #define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path)
  53. #define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path)
  54. #define user_path_dir(name, path) \
  55. user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, path)
  56. extern int kern_path(const char *, unsigned, struct path *);
  57. extern int path_lookup(const char *, unsigned, struct nameidata *);
  58. extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
  59. const char *, unsigned int, struct nameidata *);
  60. extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
  61. int (*open)(struct inode *, struct file *));
  62. extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
  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. static inline void nd_set_link(struct nameidata *nd, char *path)
  68. {
  69. nd->saved_names[nd->depth] = path;
  70. }
  71. static inline char *nd_get_link(struct nameidata *nd)
  72. {
  73. return nd->saved_names[nd->depth];
  74. }
  75. static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
  76. {
  77. ((char *) name)[min(len, maxlen)] = '\0';
  78. }
  79. #endif /* _LINUX_NAMEI_H */