blob: 1cd15dad2469fa937543a778c88aac8fcfb4461f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_NAMEI_H
2#define _LINUX_NAMEI_H
3
Alexey Dobriyan82b05472006-09-30 23:27:22 -07004#include <linux/dcache.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/linkage.h>
Jan Blunckc5e725f2008-02-14 19:34:31 -08006#include <linux/path.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8struct vfsmount;
9
10struct open_intent {
11 int flags;
12 int create_mode;
Trond Myklebust834f2a42005-10-18 14:20:16 -070013 struct file *file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070014};
15
Al Viro737bebd2006-07-14 00:24:29 -070016enum { MAX_NESTED_LINKS = 8 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18struct nameidata {
19 struct dentry *dentry;
20 struct vfsmount *mnt;
21 struct qstr last;
22 unsigned int flags;
23 int last_type;
24 unsigned depth;
25 char *saved_names[MAX_NESTED_LINKS + 1];
26
27 /* Intent data */
28 union {
29 struct open_intent open;
30 } intent;
31};
32
33/*
34 * Type of the last component on LOOKUP_PARENT
35 */
36enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
37
38/*
39 * The bitmask for a lookup event:
40 * - follow links at the end
41 * - require a directory
42 * - ending slashes ok even for nonexistent files
43 * - internal "there are more path compnents" flag
44 * - locked when lookup done with dcache_lock held
45 * - dentry cache is untrusted; force a real lookup
46 */
47#define LOOKUP_FOLLOW 1
48#define LOOKUP_DIRECTORY 2
49#define LOOKUP_CONTINUE 4
50#define LOOKUP_PARENT 16
51#define LOOKUP_NOALT 32
52#define LOOKUP_REVAL 64
53/*
54 * Intent data
55 */
56#define LOOKUP_OPEN (0x0100)
57#define LOOKUP_CREATE (0x0200)
58#define LOOKUP_ACCESS (0x0400)
Miklos Szeredi650a8982006-09-29 01:59:35 -070059#define LOOKUP_CHDIR (0x0800)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Harvey Harrisonb3c97522008-02-13 15:03:15 -080061extern int __user_walk(const char __user *, unsigned, struct nameidata *);
62extern int __user_walk_fd(int dfd, const char __user *, unsigned, struct nameidata *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define user_path_walk(name,nd) \
Ulrich Drepper5590ff02006-01-18 17:43:53 -080064 __user_walk_fd(AT_FDCWD, name, LOOKUP_FOLLOW, nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define user_path_walk_link(name,nd) \
Ulrich Drepper5590ff02006-01-18 17:43:53 -080066 __user_walk_fd(AT_FDCWD, name, 0, nd)
Harvey Harrisonb3c97522008-02-13 15:03:15 -080067extern int path_lookup(const char *, unsigned, struct nameidata *);
Josef 'Jeff' Sipek16f18202007-07-19 01:48:18 -070068extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
69 const char *, unsigned int, struct nameidata *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern void path_release(struct nameidata *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Trond Myklebust834f2a42005-10-18 14:20:16 -070072extern int __user_path_lookup_open(const char __user *, unsigned lookup_flags, struct nameidata *nd, int open_flags);
Ulrich Drepper5590ff02006-01-18 17:43:53 -080073extern int path_lookup_open(int dfd, const char *name, unsigned lookup_flags, struct nameidata *, int open_flags);
Trond Myklebust834f2a42005-10-18 14:20:16 -070074extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
75 int (*open)(struct inode *, struct file *));
76extern struct file *nameidata_to_filp(struct nameidata *nd, int flags);
77extern void release_open_intent(struct nameidata *);
78
Christoph Hellwigeead1912007-10-16 23:25:38 -070079extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
80extern struct dentry *lookup_one_noperm(const char *, struct dentry *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82extern int follow_down(struct vfsmount **, struct dentry **);
83extern int follow_up(struct vfsmount **, struct dentry **);
84
85extern struct dentry *lock_rename(struct dentry *, struct dentry *);
86extern void unlock_rename(struct dentry *, struct dentry *);
87
88static inline void nd_set_link(struct nameidata *nd, char *path)
89{
90 nd->saved_names[nd->depth] = path;
91}
92
93static inline char *nd_get_link(struct nameidata *nd)
94{
95 return nd->saved_names[nd->depth];
96}
97
98#endif /* _LINUX_NAMEI_H */