blob: e998c030061d30741c85d2738caf31dfec06ca68 [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
Al Viro737bebd2006-07-14 00:24:29 -070010enum { MAX_NESTED_LINKS = 8 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12struct nameidata {
Jan Blunck4ac91372008-02-14 19:34:32 -080013 struct path path;
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 struct qstr last;
Al Viro2a737872009-04-07 11:49:53 -040015 struct path root;
Nick Piggin31e6b012011-01-07 17:49:52 +110016 struct inode *inode; /* path.dentry.d_inode */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 unsigned int flags;
Nick Piggin31e6b012011-01-07 17:49:52 +110018 unsigned seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 int last_type;
20 unsigned depth;
21 char *saved_names[MAX_NESTED_LINKS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070022};
23
24/*
25 * Type of the last component on LOOKUP_PARENT
26 */
27enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
28
29/*
30 * The bitmask for a lookup event:
31 * - follow links at the end
32 * - require a directory
33 * - ending slashes ok even for nonexistent files
Ori Avtalion47a0dfa2009-06-16 12:17:53 +030034 * - internal "there are more path components" flag
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 * - dentry cache is untrusted; force a real lookup
David Howells6f45b652011-01-14 18:45:31 +000036 * - suppress terminal automount
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 */
Nick Piggin31e6b012011-01-07 17:49:52 +110038#define LOOKUP_FOLLOW 0x0001
39#define LOOKUP_DIRECTORY 0x0002
Linus Torvaldsd94c1772011-09-26 17:44:55 -070040#define LOOKUP_AUTOMOUNT 0x0004
Nick Piggin31e6b012011-01-07 17:49:52 +110041
42#define LOOKUP_PARENT 0x0010
43#define LOOKUP_REVAL 0x0020
44#define LOOKUP_RCU 0x0040
Linus Torvaldsb6c80692011-09-27 08:12:33 -070045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/*
47 * Intent data
48 */
Al Viro35165862008-08-05 03:00:49 -040049#define LOOKUP_OPEN 0x0100
50#define LOOKUP_CREATE 0x0200
51#define LOOKUP_EXCL 0x0400
OGAWA Hirofumi4e9ed2f2008-10-16 07:50:29 +090052#define LOOKUP_RENAME_TARGET 0x0800
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Al Viro16c2cd72011-02-22 15:50:10 -050054#define LOOKUP_JUMPED 0x1000
Al Viro5b6ca022011-03-09 23:04:47 -050055#define LOOKUP_ROOT 0x2000
Al Virof52e0c12011-03-14 18:56:51 -040056#define LOOKUP_EMPTY 0x4000
Al Viro16c2cd72011-02-22 15:50:10 -050057
Al Viro2d8f3032008-07-22 09:59:21 -040058extern int user_path_at(int, const char __user *, unsigned, struct path *);
Andy Whitcroft1fa1e7f2011-11-02 09:44:39 +010059extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
Al Viro2d8f3032008-07-22 09:59:21 -040060
61#define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path)
62#define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path)
63#define user_path_dir(name, path) \
64 user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, path)
65
Al Virod1811462008-08-02 00:49:18 -040066extern int kern_path(const char *, unsigned, struct path *);
67
Jeff Layton1ac12b42012-12-11 12:10:06 -050068extern struct dentry *kern_path_create(int, const char *, struct path *, unsigned int);
69extern struct dentry *user_path_create(int, const char __user *, struct path *, unsigned int);
Al Viro921a1652012-07-20 01:15:31 +040070extern void done_path_create(struct path *, struct dentry *);
Al Viro79714f72012-06-15 03:01:42 +040071extern struct dentry *kern_path_locked(const char *, struct path *);
Josef 'Jeff' Sipek16f18202007-07-19 01:48:18 -070072extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
Al Viroe0a01242011-06-27 17:00:37 -040073 const char *, unsigned int, struct path *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Christoph Hellwigeead1912007-10-16 23:25:38 -070075extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
David Howellscc53ce52011-01-14 18:45:26 +000077extern int follow_down_one(struct path *);
Al Viro7cc90cc2011-03-18 09:04:20 -040078extern int follow_down(struct path *);
Al Virobab77eb2009-04-18 03:26:48 -040079extern int follow_up(struct path *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81extern struct dentry *lock_rename(struct dentry *, struct dentry *);
82extern void unlock_rename(struct dentry *, struct dentry *);
83
Christoph Hellwigb5fb63c12012-06-18 10:47:04 -040084extern void nd_jump_link(struct nameidata *nd, struct path *path);
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086static inline void nd_set_link(struct nameidata *nd, char *path)
87{
88 nd->saved_names[nd->depth] = path;
89}
90
91static inline char *nd_get_link(struct nameidata *nd)
92{
93 return nd->saved_names[nd->depth];
94}
95
Duane Griffin03514682008-12-19 20:47:11 +000096static inline void nd_terminate_link(void *name, size_t len, size_t maxlen)
97{
98 ((char *) name)[min(len, maxlen)] = '\0';
99}
100
Jeff Laytonb9d6ba92012-12-20 14:59:40 -0500101/**
102 * retry_estale - determine whether the caller should retry an operation
103 * @error: the error that would currently be returned
104 * @flags: flags being used for next lookup attempt
105 *
106 * Check to see if the error code was -ESTALE, and then determine whether
107 * to retry the call based on whether "flags" already has LOOKUP_REVAL set.
108 *
109 * Returns true if the caller should try the operation again.
110 */
111static inline bool
112retry_estale(const long error, const unsigned int flags)
113{
114 return error == -ESTALE && !(flags & LOOKUP_REVAL);
115}
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#endif /* _LINUX_NAMEI_H */