namei.h 2.86 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
2
3
#ifndef _LINUX_NAMEI_H
#define _LINUX_NAMEI_H

Alexey Dobriyan's avatar
Alexey Dobriyan committed
4
#include <linux/dcache.h>
Linus Torvalds's avatar
Linus Torvalds committed
5
#include <linux/linkage.h>
6
#include <linux/path.h>
Linus Torvalds's avatar
Linus Torvalds committed
7
8
9
10
11
12

struct vfsmount;

struct open_intent {
	int	flags;
	int	create_mode;
13
	struct file *file;
Linus Torvalds's avatar
Linus Torvalds committed
14
15
};

Al Viro's avatar
Al Viro committed
16
enum { MAX_NESTED_LINKS = 8 };
Linus Torvalds's avatar
Linus Torvalds committed
17
18

struct nameidata {
19
	struct path	path;
Linus Torvalds's avatar
Linus Torvalds committed
20
	struct qstr	last;
Al Viro's avatar
Al Viro committed
21
	struct path	root;
Nick Piggin's avatar
Nick Piggin committed
22
	struct inode	*inode; /* path.dentry.d_inode */
Linus Torvalds's avatar
Linus Torvalds committed
23
	unsigned int	flags;
Nick Piggin's avatar
Nick Piggin committed
24
	unsigned	seq;
Linus Torvalds's avatar
Linus Torvalds committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	int		last_type;
	unsigned	depth;
	char *saved_names[MAX_NESTED_LINKS + 1];

	/* Intent data */
	union {
		struct open_intent open;
	} intent;
};

/*
 * Type of the last component on LOOKUP_PARENT
 */
enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};

/*
 * The bitmask for a lookup event:
 *  - follow links at the end
 *  - require a directory
 *  - ending slashes ok even for nonexistent files
45
 *  - internal "there are more path components" flag
Linus Torvalds's avatar
Linus Torvalds committed
46
 *  - dentry cache is untrusted; force a real lookup
47
 *  - suppress terminal automount
Linus Torvalds's avatar
Linus Torvalds committed
48
 */
Nick Piggin's avatar
Nick Piggin committed
49
50
#define LOOKUP_FOLLOW		0x0001
#define LOOKUP_DIRECTORY	0x0002
51
#define LOOKUP_AUTOMOUNT	0x0004
Nick Piggin's avatar
Nick Piggin committed
52
53
54
55

#define LOOKUP_PARENT		0x0010
#define LOOKUP_REVAL		0x0020
#define LOOKUP_RCU		0x0040
56

Linus Torvalds's avatar
Linus Torvalds committed
57
58
59
/*
 * Intent data
 */
60
61
62
#define LOOKUP_OPEN		0x0100
#define LOOKUP_CREATE		0x0200
#define LOOKUP_EXCL		0x0400
63
#define LOOKUP_RENAME_TARGET	0x0800
Linus Torvalds's avatar
Linus Torvalds committed
64

Al Viro's avatar
Al Viro committed
65
#define LOOKUP_JUMPED		0x1000
66
#define LOOKUP_ROOT		0x2000
Al Viro's avatar
Al Viro committed
67
#define LOOKUP_EMPTY		0x4000
Al Viro's avatar
Al Viro committed
68

69
70
71
72
73
74
75
extern int user_path_at(int, const char __user *, unsigned, struct path *);

#define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path)
#define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path)
#define user_path_dir(name, path) \
	user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, path)

Al Viro's avatar
Al Viro committed
76
77
extern int kern_path(const char *, unsigned, struct path *);

78
79
extern struct dentry *kern_path_create(int, const char *, struct path *, int);
extern struct dentry *user_path_create(int, const char __user *, struct path *, int);
Al Viro's avatar
Al Viro committed
80
extern int kern_path_parent(const char *, struct nameidata *);
81
extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
82
			   const char *, unsigned int, struct path *);
Linus Torvalds's avatar
Linus Torvalds committed
83

84
85
86
extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
		int (*open)(struct inode *, struct file *));

87
extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
Linus Torvalds's avatar
Linus Torvalds committed
88

89
extern int follow_down_one(struct path *);
90
extern int follow_down(struct path *);
Al Viro's avatar
Al Viro committed
91
extern int follow_up(struct path *);
Linus Torvalds's avatar
Linus Torvalds committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105

extern struct dentry *lock_rename(struct dentry *, struct dentry *);
extern void unlock_rename(struct dentry *, struct dentry *);

static inline void nd_set_link(struct nameidata *nd, char *path)
{
	nd->saved_names[nd->depth] = path;
}

static inline char *nd_get_link(struct nameidata *nd)
{
	return nd->saved_names[nd->depth];
}

106
107
108
109
110
static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
{
	((char *) name)[min(len, maxlen)] = '\0';
}

Linus Torvalds's avatar
Linus Torvalds committed
111
#endif /* _LINUX_NAMEI_H */