Lines Matching +full:2 +full:nd
567 #define EMBEDDED_LEVELS 2
593 #define ND_ROOT_GRABBED 2
632 static bool nd_alloc_stack(struct nameidata *nd) in nd_alloc_stack() argument
637 nd->flags & LOOKUP_RCU ? GFP_ATOMIC : GFP_KERNEL); in nd_alloc_stack()
640 memcpy(p, nd->internal, sizeof(nd->internal)); in nd_alloc_stack()
641 nd->stack = p; in nd_alloc_stack()
664 static void drop_links(struct nameidata *nd) in drop_links() argument
666 int i = nd->depth; in drop_links()
668 struct saved *last = nd->stack + i; in drop_links()
674 static void leave_rcu(struct nameidata *nd) in leave_rcu() argument
676 nd->flags &= ~LOOKUP_RCU; in leave_rcu()
677 nd->seq = nd->next_seq = 0; in leave_rcu()
681 static void terminate_walk(struct nameidata *nd) in terminate_walk() argument
683 drop_links(nd); in terminate_walk()
684 if (!(nd->flags & LOOKUP_RCU)) { in terminate_walk()
686 path_put(&nd->path); in terminate_walk()
687 for (i = 0; i < nd->depth; i++) in terminate_walk()
688 path_put(&nd->stack[i].link); in terminate_walk()
689 if (nd->state & ND_ROOT_GRABBED) { in terminate_walk()
690 path_put(&nd->root); in terminate_walk()
691 nd->state &= ~ND_ROOT_GRABBED; in terminate_walk()
694 leave_rcu(nd); in terminate_walk()
696 nd->depth = 0; in terminate_walk()
697 nd->path.mnt = NULL; in terminate_walk()
698 nd->path.dentry = NULL; in terminate_walk()
718 static inline bool legitimize_path(struct nameidata *nd, in legitimize_path() argument
721 return __legitimize_path(path, seq, nd->m_seq); in legitimize_path()
724 static bool legitimize_links(struct nameidata *nd) in legitimize_links() argument
727 if (unlikely(nd->flags & LOOKUP_CACHED)) { in legitimize_links()
728 drop_links(nd); in legitimize_links()
729 nd->depth = 0; in legitimize_links()
732 for (i = 0; i < nd->depth; i++) { in legitimize_links()
733 struct saved *last = nd->stack + i; in legitimize_links()
734 if (unlikely(!legitimize_path(nd, &last->link, last->seq))) { in legitimize_links()
735 drop_links(nd); in legitimize_links()
736 nd->depth = i + 1; in legitimize_links()
743 static bool legitimize_root(struct nameidata *nd) in legitimize_root() argument
745 /* Nothing to do if nd->root is zero or is managed by the VFS user. */ in legitimize_root()
746 if (!nd->root.mnt || (nd->state & ND_ROOT_PRESET)) in legitimize_root()
748 nd->state |= ND_ROOT_GRABBED; in legitimize_root()
749 return legitimize_path(nd, &nd->root, nd->root_seq); in legitimize_root()
753 * Path walking has 2 modes, rcu-walk and ref-walk (see
765 * @nd: nameidata pathwalk data
768 * try_to_unlazy attempts to legitimize the current nd->path and nd->root
774 static bool try_to_unlazy(struct nameidata *nd) in try_to_unlazy() argument
776 struct dentry *parent = nd->path.dentry; in try_to_unlazy()
778 BUG_ON(!(nd->flags & LOOKUP_RCU)); in try_to_unlazy()
780 if (unlikely(!legitimize_links(nd))) in try_to_unlazy()
782 if (unlikely(!legitimize_path(nd, &nd->path, nd->seq))) in try_to_unlazy()
784 if (unlikely(!legitimize_root(nd))) in try_to_unlazy()
786 leave_rcu(nd); in try_to_unlazy()
787 BUG_ON(nd->inode != parent->d_inode); in try_to_unlazy()
791 nd->path.mnt = NULL; in try_to_unlazy()
792 nd->path.dentry = NULL; in try_to_unlazy()
794 leave_rcu(nd); in try_to_unlazy()
800 * @nd: nameidata pathwalk data
806 * nd->path and nd->root for ref-walk mode. Must be called from rcu-walk context.
810 static bool try_to_unlazy_next(struct nameidata *nd, struct dentry *dentry) in try_to_unlazy_next() argument
813 BUG_ON(!(nd->flags & LOOKUP_RCU)); in try_to_unlazy_next()
815 if (unlikely(!legitimize_links(nd))) in try_to_unlazy_next()
817 res = __legitimize_mnt(nd->path.mnt, nd->m_seq); in try_to_unlazy_next()
823 if (unlikely(!lockref_get_not_dead(&nd->path.dentry->d_lockref))) in try_to_unlazy_next()
835 if (read_seqcount_retry(&dentry->d_seq, nd->next_seq)) in try_to_unlazy_next()
841 if (unlikely(!legitimize_root(nd))) in try_to_unlazy_next()
843 leave_rcu(nd); in try_to_unlazy_next()
847 nd->path.mnt = NULL; in try_to_unlazy_next()
849 nd->path.dentry = NULL; in try_to_unlazy_next()
851 leave_rcu(nd); in try_to_unlazy_next()
854 leave_rcu(nd); in try_to_unlazy_next()
869 * @nd: pointer nameidata
871 * If we had been in RCU mode, drop out of it and legitimize nd->path.
875 * need to drop nd->path.
877 static int complete_walk(struct nameidata *nd) in complete_walk() argument
879 struct dentry *dentry = nd->path.dentry; in complete_walk()
882 if (nd->flags & LOOKUP_RCU) { in complete_walk()
884 * We don't want to zero nd->root for scoped-lookups or in complete_walk()
885 * externally-managed nd->root. in complete_walk()
887 if (!(nd->state & ND_ROOT_PRESET)) in complete_walk()
888 if (!(nd->flags & LOOKUP_IS_SCOPED)) in complete_walk()
889 nd->root.mnt = NULL; in complete_walk()
890 nd->flags &= ~LOOKUP_CACHED; in complete_walk()
891 if (!try_to_unlazy(nd)) in complete_walk()
895 if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) { in complete_walk()
912 if (!path_is_under(&nd->path, &nd->root)) in complete_walk()
916 if (likely(!(nd->state & ND_JUMPED))) in complete_walk()
922 status = dentry->d_op->d_weak_revalidate(dentry, nd->flags); in complete_walk()
932 static int set_root(struct nameidata *nd) in set_root() argument
941 if (WARN_ON(nd->flags & LOOKUP_IS_SCOPED)) in set_root()
944 if (nd->flags & LOOKUP_RCU) { in set_root()
949 nd->root = fs->root; in set_root()
950 nd->root_seq = __read_seqcount_begin(&nd->root.dentry->d_seq); in set_root()
953 get_fs_root(fs, &nd->root); in set_root()
954 nd->state |= ND_ROOT_GRABBED; in set_root()
959 static int nd_jump_root(struct nameidata *nd) in nd_jump_root() argument
961 if (unlikely(nd->flags & LOOKUP_BENEATH)) in nd_jump_root()
963 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) { in nd_jump_root()
965 if (nd->path.mnt != NULL && nd->path.mnt != nd->root.mnt) in nd_jump_root()
968 if (!nd->root.mnt) { in nd_jump_root()
969 int error = set_root(nd); in nd_jump_root()
973 if (nd->flags & LOOKUP_RCU) { in nd_jump_root()
975 nd->path = nd->root; in nd_jump_root()
976 d = nd->path.dentry; in nd_jump_root()
977 nd->inode = d->d_inode; in nd_jump_root()
978 nd->seq = nd->root_seq; in nd_jump_root()
979 if (read_seqcount_retry(&d->d_seq, nd->seq)) in nd_jump_root()
982 path_put(&nd->path); in nd_jump_root()
983 nd->path = nd->root; in nd_jump_root()
984 path_get(&nd->path); in nd_jump_root()
985 nd->inode = nd->path.dentry->d_inode; in nd_jump_root()
987 nd->state |= ND_JUMPED; in nd_jump_root()
998 struct nameidata *nd = current->nameidata; in nd_jump_link() local
1000 if (unlikely(nd->flags & LOOKUP_NO_MAGICLINKS)) in nd_jump_link()
1004 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) { in nd_jump_link()
1005 if (nd->path.mnt != path->mnt) in nd_jump_link()
1009 if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) in nd_jump_link()
1012 path_put(&nd->path); in nd_jump_link()
1013 nd->path = *path; in nd_jump_link()
1014 nd->inode = nd->path.dentry->d_inode; in nd_jump_link()
1015 nd->state |= ND_JUMPED; in nd_jump_link()
1023 static inline void put_link(struct nameidata *nd) in put_link() argument
1025 struct saved *last = nd->stack + --nd->depth; in put_link()
1027 if (!(nd->flags & LOOKUP_RCU)) in put_link()
1088 * @nd: nameidata pathwalk data
1102 static inline int may_follow_link(struct nameidata *nd, const struct inode *inode) in may_follow_link() argument
1110 idmap = mnt_idmap(nd->path.mnt); in may_follow_link()
1117 if ((nd->dir_mode & (S_ISVTX|S_IWOTH)) != (S_ISVTX|S_IWOTH)) in may_follow_link()
1121 if (vfsuid_valid(nd->dir_vfsuid) && vfsuid_eq(nd->dir_vfsuid, vfsuid)) in may_follow_link()
1124 if (nd->flags & LOOKUP_RCU) in may_follow_link()
1127 audit_inode(nd->name, nd->stack[0].link.dentry, 0); in may_follow_link()
1216 * @nd: nameidata pathwalk data
1226 * If the sysctl_protected_fifos (or sysctl_protected_regular) is set to 2
1239 struct nameidata *nd, struct inode *const inode) in may_create_in_sticky() argument
1241 umode_t dir_mode = nd->dir_mode; in may_create_in_sticky()
1242 vfsuid_t dir_vfsuid = nd->dir_vfsuid; in may_create_in_sticky()
1253 ((sysctl_protected_fifos >= 2 && S_ISFIFO(inode->i_mode)) || in may_create_in_sticky()
1254 (sysctl_protected_regular >= 2 && S_ISREG(inode->i_mode))))) { in may_create_in_sticky()
1484 static bool __follow_mount_rcu(struct nameidata *nd, struct path *path) in __follow_mount_rcu() argument
1492 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) in __follow_mount_rcu()
1512 nd->state |= ND_JUMPED; in __follow_mount_rcu()
1513 nd->next_seq = read_seqcount_begin(&dentry->d_seq); in __follow_mount_rcu()
1517 if (read_seqretry(&mount_lock, nd->m_seq)) in __follow_mount_rcu()
1521 if (read_seqretry(&mount_lock, nd->m_seq)) in __follow_mount_rcu()
1528 static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry, in handle_mounts() argument
1534 path->mnt = nd->path.mnt; in handle_mounts()
1536 if (nd->flags & LOOKUP_RCU) { in handle_mounts()
1537 unsigned int seq = nd->next_seq; in handle_mounts()
1538 if (likely(__follow_mount_rcu(nd, path))) in handle_mounts()
1540 // *path and nd->next_seq might've been clobbered in handle_mounts()
1541 path->mnt = nd->path.mnt; in handle_mounts()
1543 nd->next_seq = seq; in handle_mounts()
1544 if (!try_to_unlazy_next(nd, dentry)) in handle_mounts()
1547 ret = traverse_mounts(path, &jumped, &nd->total_link_count, nd->flags); in handle_mounts()
1549 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) in handle_mounts()
1552 nd->state |= ND_JUMPED; in handle_mounts()
1556 if (path->mnt != nd->path.mnt) in handle_mounts()
1618 static struct dentry *lookup_fast(struct nameidata *nd) in lookup_fast() argument
1620 struct dentry *dentry, *parent = nd->path.dentry; in lookup_fast()
1628 if (nd->flags & LOOKUP_RCU) { in lookup_fast()
1629 dentry = __d_lookup_rcu(parent, &nd->last, &nd->next_seq); in lookup_fast()
1631 if (!try_to_unlazy(nd)) in lookup_fast()
1640 if (read_seqcount_retry(&parent->d_seq, nd->seq)) in lookup_fast()
1643 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1646 if (!try_to_unlazy_next(nd, dentry)) in lookup_fast()
1650 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1652 dentry = __d_lookup(parent, &nd->last); in lookup_fast()
1655 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1717 struct nameidata *nd) in may_lookup() argument
1719 if (nd->flags & LOOKUP_RCU) { in may_lookup()
1720 int err = inode_permission(idmap, nd->inode, MAY_EXEC|MAY_NOT_BLOCK); in may_lookup()
1721 if (err != -ECHILD || !try_to_unlazy(nd)) in may_lookup()
1724 return inode_permission(idmap, nd->inode, MAY_EXEC); in may_lookup()
1727 static int reserve_stack(struct nameidata *nd, struct path *link) in reserve_stack() argument
1729 if (unlikely(nd->total_link_count++ >= MAXSYMLINKS)) in reserve_stack()
1732 if (likely(nd->depth != EMBEDDED_LEVELS)) in reserve_stack()
1734 if (likely(nd->stack != nd->internal)) in reserve_stack()
1736 if (likely(nd_alloc_stack(nd))) in reserve_stack()
1739 if (nd->flags & LOOKUP_RCU) { in reserve_stack()
1742 bool grabbed_link = legitimize_path(nd, link, nd->next_seq); in reserve_stack()
1744 if (!try_to_unlazy(nd) || !grabbed_link) in reserve_stack()
1747 if (nd_alloc_stack(nd)) in reserve_stack()
1753 enum {WALK_TRAILING = 1, WALK_MORE = 2, WALK_NOFOLLOW = 4};
1755 static const char *pick_link(struct nameidata *nd, struct path *link, in pick_link() argument
1760 int error = reserve_stack(nd, link); in pick_link()
1763 if (!(nd->flags & LOOKUP_RCU)) in pick_link()
1767 last = nd->stack + nd->depth++; in pick_link()
1770 last->seq = nd->next_seq; in pick_link()
1773 error = may_follow_link(nd, inode); in pick_link()
1778 if (unlikely(nd->flags & LOOKUP_NO_SYMLINKS) || in pick_link()
1782 if (!(nd->flags & LOOKUP_RCU)) { in pick_link()
1786 if (!try_to_unlazy(nd)) in pick_link()
1792 nd->flags & LOOKUP_RCU); in pick_link()
1801 if (nd->flags & LOOKUP_RCU) { in pick_link()
1803 if (res == ERR_PTR(-ECHILD) && try_to_unlazy(nd)) in pick_link()
1814 error = nd_jump_root(nd); in pick_link()
1823 put_link(nd); in pick_link()
1833 * NOTE: dentry must be what nd->next_seq had been sampled from.
1835 static const char *step_into(struct nameidata *nd, int flags, in step_into() argument
1840 int err = handle_mounts(nd, dentry, &path); in step_into()
1846 ((flags & WALK_TRAILING) && !(nd->flags & LOOKUP_FOLLOW)) || in step_into()
1849 if (nd->flags & LOOKUP_RCU) { in step_into()
1850 if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq)) in step_into()
1855 dput(nd->path.dentry); in step_into()
1856 if (nd->path.mnt != path.mnt) in step_into()
1857 mntput(nd->path.mnt); in step_into()
1859 nd->path = path; in step_into()
1860 nd->inode = inode; in step_into()
1861 nd->seq = nd->next_seq; in step_into()
1864 if (nd->flags & LOOKUP_RCU) { in step_into()
1866 if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq)) in step_into()
1869 if (path.mnt == nd->path.mnt) in step_into()
1872 return pick_link(nd, &path, inode, flags); in step_into()
1875 static struct dentry *follow_dotdot_rcu(struct nameidata *nd) in follow_dotdot_rcu() argument
1879 if (path_equal(&nd->path, &nd->root)) in follow_dotdot_rcu()
1881 if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) { in follow_dotdot_rcu()
1884 if (!choose_mountpoint_rcu(real_mount(nd->path.mnt), in follow_dotdot_rcu()
1885 &nd->root, &path, &seq)) in follow_dotdot_rcu()
1887 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) in follow_dotdot_rcu()
1889 nd->path = path; in follow_dotdot_rcu()
1890 nd->inode = path.dentry->d_inode; in follow_dotdot_rcu()
1891 nd->seq = seq; in follow_dotdot_rcu()
1893 if (read_seqretry(&mount_lock, nd->m_seq)) in follow_dotdot_rcu()
1897 old = nd->path.dentry; in follow_dotdot_rcu()
1899 nd->next_seq = read_seqcount_begin(&parent->d_seq); in follow_dotdot_rcu()
1901 if (read_seqcount_retry(&old->d_seq, nd->seq)) in follow_dotdot_rcu()
1903 if (unlikely(!path_connected(nd->path.mnt, parent))) in follow_dotdot_rcu()
1907 if (read_seqretry(&mount_lock, nd->m_seq)) in follow_dotdot_rcu()
1909 if (unlikely(nd->flags & LOOKUP_BENEATH)) in follow_dotdot_rcu()
1911 nd->next_seq = nd->seq; in follow_dotdot_rcu()
1912 return nd->path.dentry; in follow_dotdot_rcu()
1915 static struct dentry *follow_dotdot(struct nameidata *nd) in follow_dotdot() argument
1919 if (path_equal(&nd->path, &nd->root)) in follow_dotdot()
1921 if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) { in follow_dotdot()
1924 if (!choose_mountpoint(real_mount(nd->path.mnt), in follow_dotdot()
1925 &nd->root, &path)) in follow_dotdot()
1927 path_put(&nd->path); in follow_dotdot()
1928 nd->path = path; in follow_dotdot()
1929 nd->inode = path.dentry->d_inode; in follow_dotdot()
1930 if (unlikely(nd->flags & LOOKUP_NO_XDEV)) in follow_dotdot()
1934 parent = dget_parent(nd->path.dentry); in follow_dotdot()
1935 if (unlikely(!path_connected(nd->path.mnt, parent))) { in follow_dotdot()
1942 if (unlikely(nd->flags & LOOKUP_BENEATH)) in follow_dotdot()
1944 return dget(nd->path.dentry); in follow_dotdot()
1947 static const char *handle_dots(struct nameidata *nd, int type) in handle_dots() argument
1953 if (!nd->root.mnt) { in handle_dots()
1954 error = ERR_PTR(set_root(nd)); in handle_dots()
1958 if (nd->flags & LOOKUP_RCU) in handle_dots()
1959 parent = follow_dotdot_rcu(nd); in handle_dots()
1961 parent = follow_dotdot(nd); in handle_dots()
1964 error = step_into(nd, WALK_NOFOLLOW, parent); in handle_dots()
1968 if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) { in handle_dots()
1972 * above nd->root (and so userspace should retry or use in handle_dots()
1976 if (__read_seqcount_retry(&mount_lock.seqcount, nd->m_seq)) in handle_dots()
1978 if (__read_seqcount_retry(&rename_lock.seqcount, nd->r_seq)) in handle_dots()
1985 static const char *walk_component(struct nameidata *nd, int flags) in walk_component() argument
1993 if (unlikely(nd->last_type != LAST_NORM)) { in walk_component()
1994 if (!(flags & WALK_MORE) && nd->depth) in walk_component()
1995 put_link(nd); in walk_component()
1996 return handle_dots(nd, nd->last_type); in walk_component()
1998 dentry = lookup_fast(nd); in walk_component()
2002 dentry = lookup_slow(&nd->last, nd->path.dentry, nd->flags); in walk_component()
2006 if (!(flags & WALK_MORE) && nd->depth) in walk_component()
2007 put_link(nd); in walk_component()
2008 return step_into(nd, flags, dentry); in walk_component()
2046 * influence out to 2^6 = 64 state bits.
2049 * deltas or 64*63/2 = 2016 two-bit input deltas, and finding the
2058 * Input delta: 1-bit 2-bit
2060 * 2 rounds: 2753.7 140389.8
2064 * (64*128) (64*63/2 * 128)
2088 * Input delta: 1-bit 2-bit
2090 * 2 rounds: 1246.4 25475.4
2094 * (32*64) (32*31/2 * 64)
2244 * Returns 0 and nd will have valid dentry and mnt on success.
2247 static int link_path_walk(const char *name, struct nameidata *nd) in link_path_walk() argument
2249 int depth = 0; // depth <= nd->depth in link_path_walk()
2252 nd->last_type = LAST_ROOT; in link_path_walk()
2253 nd->flags |= LOOKUP_PARENT; in link_path_walk()
2259 nd->dir_mode = 0; // short-circuit the 'hardening' idiocy in link_path_walk()
2270 idmap = mnt_idmap(nd->path.mnt); in link_path_walk()
2271 err = may_lookup(idmap, nd); in link_path_walk()
2275 hash_len = hash_name(nd->path.dentry, name); in link_path_walk()
2279 case 2: in link_path_walk()
2282 nd->state |= ND_JUMPED; in link_path_walk()
2289 struct dentry *parent = nd->path.dentry; in link_path_walk()
2290 nd->state &= ~ND_JUMPED; in link_path_walk()
2301 nd->last.hash_len = hash_len; in link_path_walk()
2302 nd->last.name = name; in link_path_walk()
2303 nd->last_type = type; in link_path_walk()
2319 nd->dir_vfsuid = i_uid_into_vfsuid(idmap, nd->inode); in link_path_walk()
2320 nd->dir_mode = nd->inode->i_mode; in link_path_walk()
2321 nd->flags &= ~LOOKUP_PARENT; in link_path_walk()
2325 name = nd->stack[--depth].name; in link_path_walk()
2326 link = walk_component(nd, 0); in link_path_walk()
2329 link = walk_component(nd, WALK_MORE); in link_path_walk()
2335 nd->stack[depth++].name = name; in link_path_walk()
2339 if (unlikely(!d_can_lookup(nd->path.dentry))) { in link_path_walk()
2340 if (nd->flags & LOOKUP_RCU) { in link_path_walk()
2341 if (!try_to_unlazy(nd)) in link_path_walk()
2350 static const char *path_init(struct nameidata *nd, unsigned flags) in path_init() argument
2353 const char *s = nd->name->name; in path_init()
2364 nd->seq = nd->next_seq = 0; in path_init()
2366 nd->flags = flags; in path_init()
2367 nd->state |= ND_JUMPED; in path_init()
2369 nd->m_seq = __read_seqcount_begin(&mount_lock.seqcount); in path_init()
2370 nd->r_seq = __read_seqcount_begin(&rename_lock.seqcount); in path_init()
2373 if (nd->state & ND_ROOT_PRESET) { in path_init()
2374 struct dentry *root = nd->root.dentry; in path_init()
2378 nd->path = nd->root; in path_init()
2379 nd->inode = inode; in path_init()
2381 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2382 nd->root_seq = nd->seq; in path_init()
2384 path_get(&nd->path); in path_init()
2389 nd->root.mnt = NULL; in path_init()
2391 /* Absolute pathname -- fetch the root (LOOKUP_IN_ROOT uses nd->dfd). */ in path_init()
2393 error = nd_jump_root(nd); in path_init()
2400 if (nd->dfd == AT_FDCWD) { in path_init()
2407 nd->path = fs->pwd; in path_init()
2408 nd->inode = nd->path.dentry->d_inode; in path_init()
2409 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2412 get_fs_pwd(current->fs, &nd->path); in path_init()
2413 nd->inode = nd->path.dentry->d_inode; in path_init()
2417 struct fd f = fdget_raw(nd->dfd); in path_init()
2430 nd->path = f.file->f_path; in path_init()
2432 nd->inode = nd->path.dentry->d_inode; in path_init()
2433 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2435 path_get(&nd->path); in path_init()
2436 nd->inode = nd->path.dentry->d_inode; in path_init()
2443 nd->root = nd->path; in path_init()
2445 nd->root_seq = nd->seq; in path_init()
2447 path_get(&nd->root); in path_init()
2448 nd->state |= ND_ROOT_GRABBED; in path_init()
2454 static inline const char *lookup_last(struct nameidata *nd) in lookup_last() argument
2456 if (nd->last_type == LAST_NORM && nd->last.name[nd->last.len]) in lookup_last()
2457 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; in lookup_last()
2459 return walk_component(nd, WALK_TRAILING); in lookup_last()
2462 static int handle_lookup_down(struct nameidata *nd) in handle_lookup_down() argument
2464 if (!(nd->flags & LOOKUP_RCU)) in handle_lookup_down()
2465 dget(nd->path.dentry); in handle_lookup_down()
2466 nd->next_seq = nd->seq; in handle_lookup_down()
2467 return PTR_ERR(step_into(nd, WALK_NOFOLLOW, nd->path.dentry)); in handle_lookup_down()
2470 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
2471 static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path) in path_lookupat() argument
2473 const char *s = path_init(nd, flags); in path_lookupat()
2477 err = handle_lookup_down(nd); in path_lookupat()
2482 while (!(err = link_path_walk(s, nd)) && in path_lookupat()
2483 (s = lookup_last(nd)) != NULL) in path_lookupat()
2485 if (!err && unlikely(nd->flags & LOOKUP_MOUNTPOINT)) { in path_lookupat()
2486 err = handle_lookup_down(nd); in path_lookupat()
2487 nd->state &= ~ND_JUMPED; // no d_weak_revalidate(), please... in path_lookupat()
2490 err = complete_walk(nd); in path_lookupat()
2492 if (!err && nd->flags & LOOKUP_DIRECTORY) in path_lookupat()
2493 if (!d_can_lookup(nd->path.dentry)) in path_lookupat()
2496 *path = nd->path; in path_lookupat()
2497 nd->path.mnt = NULL; in path_lookupat()
2498 nd->path.dentry = NULL; in path_lookupat()
2500 terminate_walk(nd); in path_lookupat()
2508 struct nameidata nd; in filename_lookup() local
2511 set_nameidata(&nd, dfd, name, root); in filename_lookup()
2512 retval = path_lookupat(&nd, flags | LOOKUP_RCU, path); in filename_lookup()
2514 retval = path_lookupat(&nd, flags, path); in filename_lookup()
2516 retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path); in filename_lookup()
2525 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
2526 static int path_parentat(struct nameidata *nd, unsigned flags, in path_parentat() argument
2529 const char *s = path_init(nd, flags); in path_parentat()
2530 int err = link_path_walk(s, nd); in path_parentat()
2532 err = complete_walk(nd); in path_parentat()
2534 *parent = nd->path; in path_parentat()
2535 nd->path.mnt = NULL; in path_parentat()
2536 nd->path.dentry = NULL; in path_parentat()
2538 terminate_walk(nd); in path_parentat()
2549 struct nameidata nd; in __filename_parentat() local
2553 set_nameidata(&nd, dfd, name, root); in __filename_parentat()
2554 retval = path_parentat(&nd, flags | LOOKUP_RCU, parent); in __filename_parentat()
2556 retval = path_parentat(&nd, flags, parent); in __filename_parentat()
2558 retval = path_parentat(&nd, flags | LOOKUP_REVAL, parent); in __filename_parentat()
2560 *last = nd.last; in __filename_parentat()
2561 *type = nd.last_type; in __filename_parentat()
2933 * 2. We should have write and exec permissions on dir
2996 * 2. We can't do it if dir is read-only (done in permission())
3338 static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry, in atomic_open() argument
3343 struct inode *dir = nd->path.dentry->d_inode; in atomic_open()
3346 if (nd->flags & LOOKUP_DIRECTORY) in atomic_open()
3350 file->f_path.mnt = nd->path.mnt; in atomic_open()
3393 static struct dentry *lookup_open(struct nameidata *nd, struct file *file, in lookup_open() argument
3398 struct dentry *dir = nd->path.dentry; in lookup_open()
3410 dentry = d_lookup(dir, &nd->last); in lookup_open()
3413 dentry = d_alloc_parallel(dir, &nd->last, &wq); in lookup_open()
3420 error = d_revalidate(dentry, nd->flags); in lookup_open()
3445 idmap = mnt_idmap(nd->path.mnt); in lookup_open()
3451 create_error = may_o_create(idmap, &nd->path, in lookup_open()
3459 dentry = atomic_open(nd, dentry, file, open_flag, mode); in lookup_open()
3467 nd->flags); in lookup_open()
3504 static const char *open_last_lookups(struct nameidata *nd, in open_last_lookups() argument
3507 struct dentry *dir = nd->path.dentry; in open_last_lookups()
3513 nd->flags |= op->intent; in open_last_lookups()
3515 if (nd->last_type != LAST_NORM) { in open_last_lookups()
3516 if (nd->depth) in open_last_lookups()
3517 put_link(nd); in open_last_lookups()
3518 return handle_dots(nd, nd->last_type); in open_last_lookups()
3522 if (nd->last.name[nd->last.len]) in open_last_lookups()
3523 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; in open_last_lookups()
3525 dentry = lookup_fast(nd); in open_last_lookups()
3531 BUG_ON(nd->flags & LOOKUP_RCU); in open_last_lookups()
3534 if (nd->flags & LOOKUP_RCU) { in open_last_lookups()
3535 if (!try_to_unlazy(nd)) in open_last_lookups()
3538 audit_inode(nd->name, dir, AUDIT_INODE_PARENT); in open_last_lookups()
3540 if (unlikely(nd->last.name[nd->last.len])) in open_last_lookups()
3545 got_write = !mnt_want_write(nd->path.mnt); in open_last_lookups()
3556 dentry = lookup_open(nd, file, op, got_write); in open_last_lookups()
3565 mnt_drop_write(nd->path.mnt); in open_last_lookups()
3571 dput(nd->path.dentry); in open_last_lookups()
3572 nd->path.dentry = dentry; in open_last_lookups()
3577 if (nd->depth) in open_last_lookups()
3578 put_link(nd); in open_last_lookups()
3579 res = step_into(nd, WALK_TRAILING, dentry); in open_last_lookups()
3581 nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL); in open_last_lookups()
3588 static int do_open(struct nameidata *nd, in do_open() argument
3598 error = complete_walk(nd); in do_open()
3603 audit_inode(nd->name, nd->path.dentry, 0); in do_open()
3604 idmap = mnt_idmap(nd->path.mnt); in do_open()
3608 if (d_is_dir(nd->path.dentry)) in do_open()
3610 error = may_create_in_sticky(idmap, nd, in do_open()
3611 d_backing_inode(nd->path.dentry)); in do_open()
3615 if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry)) in do_open()
3624 } else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) { in do_open()
3625 error = mnt_want_write(nd->path.mnt); in do_open()
3630 error = may_open(idmap, &nd->path, acc_mode, open_flag); in do_open()
3632 error = vfs_open(&nd->path, file); in do_open()
3642 mnt_drop_write(nd->path.mnt); in do_open()
3734 static int do_tmpfile(struct nameidata *nd, unsigned flags, in do_tmpfile() argument
3739 int error = path_lookupat(nd, flags | LOOKUP_DIRECTORY, &path); in do_tmpfile()
3749 audit_inode(nd->name, file->f_path.dentry, 0); in do_tmpfile()
3757 static int do_o_path(struct nameidata *nd, unsigned flags, struct file *file) in do_o_path() argument
3760 int error = path_lookupat(nd, flags, &path); in do_o_path()
3762 audit_inode(nd->name, path.dentry, 0); in do_o_path()
3769 static struct file *path_openat(struct nameidata *nd, in path_openat() argument
3780 error = do_tmpfile(nd, flags, op, file); in path_openat()
3782 error = do_o_path(nd, flags, file); in path_openat()
3784 const char *s = path_init(nd, flags); in path_openat()
3785 while (!(error = link_path_walk(s, nd)) && in path_openat()
3786 (s = open_last_lookups(nd, file, op)) != NULL) in path_openat()
3789 error = do_open(nd, file, op); in path_openat()
3790 terminate_walk(nd); in path_openat()
3811 struct nameidata nd; in do_filp_open() local
3815 set_nameidata(&nd, dfd, pathname, NULL); in do_filp_open()
3816 filp = path_openat(&nd, op, flags | LOOKUP_RCU); in do_filp_open()
3818 filp = path_openat(&nd, op, flags); in do_filp_open()
3820 filp = path_openat(&nd, op, flags | LOOKUP_REVAL); in do_filp_open()
3828 struct nameidata nd; in do_file_open_root() local
3840 set_nameidata(&nd, -1, filename, root); in do_file_open_root()
3841 file = path_openat(&nd, op, flags | LOOKUP_RCU); in do_file_open_root()
3843 file = path_openat(&nd, op, flags); in do_file_open_root()
3845 file = path_openat(&nd, op, flags | LOOKUP_REVAL); in do_file_open_root()
4744 * we'd better make sure that there's no link(2) for them.