Lines Matching refs:nd
535 static int __nd_alloc_stack(struct nameidata *nd) in __nd_alloc_stack() argument
539 if (nd->flags & LOOKUP_RCU) { in __nd_alloc_stack()
550 memcpy(p, nd->internal, sizeof(nd->internal)); in __nd_alloc_stack()
551 nd->stack = p; in __nd_alloc_stack()
574 static inline int nd_alloc_stack(struct nameidata *nd) in nd_alloc_stack() argument
576 if (likely(nd->depth != EMBEDDED_LEVELS)) in nd_alloc_stack()
578 if (likely(nd->stack != nd->internal)) in nd_alloc_stack()
580 return __nd_alloc_stack(nd); in nd_alloc_stack()
583 static void drop_links(struct nameidata *nd) in drop_links() argument
585 int i = nd->depth; in drop_links()
587 struct saved *last = nd->stack + i; in drop_links()
593 static void terminate_walk(struct nameidata *nd) in terminate_walk() argument
595 drop_links(nd); in terminate_walk()
596 if (!(nd->flags & LOOKUP_RCU)) { in terminate_walk()
598 path_put(&nd->path); in terminate_walk()
599 for (i = 0; i < nd->depth; i++) in terminate_walk()
600 path_put(&nd->stack[i].link); in terminate_walk()
601 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT)) { in terminate_walk()
602 path_put(&nd->root); in terminate_walk()
603 nd->root.mnt = NULL; in terminate_walk()
606 nd->flags &= ~LOOKUP_RCU; in terminate_walk()
607 if (!(nd->flags & LOOKUP_ROOT)) in terminate_walk()
608 nd->root.mnt = NULL; in terminate_walk()
611 nd->depth = 0; in terminate_walk()
615 static bool legitimize_path(struct nameidata *nd, in legitimize_path() argument
618 int res = __legitimize_mnt(path->mnt, nd->m_seq); in legitimize_path()
632 static bool legitimize_links(struct nameidata *nd) in legitimize_links() argument
635 for (i = 0; i < nd->depth; i++) { in legitimize_links()
636 struct saved *last = nd->stack + i; in legitimize_links()
637 if (unlikely(!legitimize_path(nd, &last->link, last->seq))) { in legitimize_links()
638 drop_links(nd); in legitimize_links()
639 nd->depth = i + 1; in legitimize_links()
668 static int unlazy_walk(struct nameidata *nd) in unlazy_walk() argument
670 struct dentry *parent = nd->path.dentry; in unlazy_walk()
672 BUG_ON(!(nd->flags & LOOKUP_RCU)); in unlazy_walk()
674 nd->flags &= ~LOOKUP_RCU; in unlazy_walk()
675 if (unlikely(!legitimize_links(nd))) in unlazy_walk()
677 if (unlikely(!legitimize_path(nd, &nd->path, nd->seq))) in unlazy_walk()
679 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT)) { in unlazy_walk()
680 if (unlikely(!legitimize_path(nd, &nd->root, nd->root_seq))) in unlazy_walk()
684 BUG_ON(nd->inode != parent->d_inode); in unlazy_walk()
688 nd->path.mnt = NULL; in unlazy_walk()
689 nd->path.dentry = NULL; in unlazy_walk()
691 if (!(nd->flags & LOOKUP_ROOT)) in unlazy_walk()
692 nd->root.mnt = NULL; in unlazy_walk()
711 static int unlazy_child(struct nameidata *nd, struct dentry *dentry, unsigned seq) in unlazy_child() argument
713 BUG_ON(!(nd->flags & LOOKUP_RCU)); in unlazy_child()
715 nd->flags &= ~LOOKUP_RCU; in unlazy_child()
716 if (unlikely(!legitimize_links(nd))) in unlazy_child()
718 if (unlikely(!legitimize_mnt(nd->path.mnt, nd->m_seq))) in unlazy_child()
720 if (unlikely(!lockref_get_not_dead(&nd->path.dentry->d_lockref))) in unlazy_child()
741 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT)) { in unlazy_child()
742 if (unlikely(!legitimize_path(nd, &nd->root, nd->root_seq))) { in unlazy_child()
753 nd->path.mnt = NULL; in unlazy_child()
755 nd->path.dentry = NULL; in unlazy_child()
759 if (!(nd->flags & LOOKUP_ROOT)) in unlazy_child()
760 nd->root.mnt = NULL; in unlazy_child()
782 static int complete_walk(struct nameidata *nd) in complete_walk() argument
784 struct dentry *dentry = nd->path.dentry; in complete_walk()
787 if (nd->flags & LOOKUP_RCU) { in complete_walk()
788 if (!(nd->flags & LOOKUP_ROOT)) in complete_walk()
789 nd->root.mnt = NULL; in complete_walk()
790 if (unlikely(unlazy_walk(nd))) in complete_walk()
794 if (likely(!(nd->flags & LOOKUP_JUMPED))) in complete_walk()
800 status = dentry->d_op->d_weak_revalidate(dentry, nd->flags); in complete_walk()
810 static void set_root(struct nameidata *nd) in set_root() argument
814 if (nd->flags & LOOKUP_RCU) { in set_root()
819 nd->root = fs->root; in set_root()
820 nd->root_seq = __read_seqcount_begin(&nd->root.dentry->d_seq); in set_root()
823 get_fs_root(fs, &nd->root); in set_root()
827 static void path_put_conditional(struct path *path, struct nameidata *nd) in path_put_conditional() argument
830 if (path->mnt != nd->path.mnt) in path_put_conditional()
835 struct nameidata *nd) in path_to_nameidata() argument
837 if (!(nd->flags & LOOKUP_RCU)) { in path_to_nameidata()
838 dput(nd->path.dentry); in path_to_nameidata()
839 if (nd->path.mnt != path->mnt) in path_to_nameidata()
840 mntput(nd->path.mnt); in path_to_nameidata()
842 nd->path.mnt = path->mnt; in path_to_nameidata()
843 nd->path.dentry = path->dentry; in path_to_nameidata()
846 static int nd_jump_root(struct nameidata *nd) in nd_jump_root() argument
848 if (nd->flags & LOOKUP_RCU) { in nd_jump_root()
850 nd->path = nd->root; in nd_jump_root()
851 d = nd->path.dentry; in nd_jump_root()
852 nd->inode = d->d_inode; in nd_jump_root()
853 nd->seq = nd->root_seq; in nd_jump_root()
854 if (unlikely(read_seqcount_retry(&d->d_seq, nd->seq))) in nd_jump_root()
857 path_put(&nd->path); in nd_jump_root()
858 nd->path = nd->root; in nd_jump_root()
859 path_get(&nd->path); in nd_jump_root()
860 nd->inode = nd->path.dentry->d_inode; in nd_jump_root()
862 nd->flags |= LOOKUP_JUMPED; in nd_jump_root()
872 struct nameidata *nd = current->nameidata; in nd_jump_link() local
873 path_put(&nd->path); in nd_jump_link()
875 nd->path = *path; in nd_jump_link()
876 nd->inode = nd->path.dentry->d_inode; in nd_jump_link()
877 nd->flags |= LOOKUP_JUMPED; in nd_jump_link()
880 static inline void put_link(struct nameidata *nd) in put_link() argument
882 struct saved *last = nd->stack + --nd->depth; in put_link()
884 if (!(nd->flags & LOOKUP_RCU)) in put_link()
908 static inline int may_follow_link(struct nameidata *nd) in may_follow_link() argument
918 inode = nd->link_inode; in may_follow_link()
923 parent = nd->inode; in may_follow_link()
932 if (nd->flags & LOOKUP_RCU) in may_follow_link()
935 audit_inode(nd->name, nd->stack[0].link.dentry, 0); in may_follow_link()
1048 const char *get_link(struct nameidata *nd) in get_link() argument
1050 struct saved *last = nd->stack + nd->depth - 1; in get_link()
1052 struct inode *inode = nd->link_inode; in get_link()
1056 if (!(nd->flags & LOOKUP_RCU)) { in get_link()
1060 if (unlikely(unlazy_walk(nd))) in get_link()
1066 nd->flags & LOOKUP_RCU); in get_link()
1070 nd->last_type = LAST_BIND; in get_link()
1076 if (nd->flags & LOOKUP_RCU) { in get_link()
1079 if (unlikely(unlazy_walk(nd))) in get_link()
1090 if (!nd->root.mnt) in get_link()
1091 set_root(nd); in get_link()
1092 if (unlikely(nd_jump_root(nd))) in get_link()
1140 static int follow_automount(struct path *path, struct nameidata *nd, in follow_automount() argument
1160 if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY | in follow_automount()
1165 nd->total_link_count++; in follow_automount()
1166 if (nd->total_link_count >= 40) in follow_automount()
1180 if (PTR_ERR(mnt) == -EISDIR && (nd->flags & LOOKUP_PARENT)) in follow_automount()
1220 static int follow_managed(struct path *path, struct nameidata *nd) in follow_managed() argument
1264 ret = follow_automount(path, nd, &need_mntput); in follow_managed()
1279 nd->flags |= LOOKUP_JUMPED; in follow_managed()
1281 path_put_conditional(path, nd); in follow_managed()
1311 static bool __follow_mount_rcu(struct nameidata *nd, struct path *path, in __follow_mount_rcu() argument
1338 nd->flags |= LOOKUP_JUMPED; in __follow_mount_rcu()
1347 return !read_seqretry(&mount_lock, nd->m_seq) && in __follow_mount_rcu()
1351 static int follow_dotdot_rcu(struct nameidata *nd) in follow_dotdot_rcu() argument
1353 struct inode *inode = nd->inode; in follow_dotdot_rcu()
1356 if (path_equal(&nd->path, &nd->root)) in follow_dotdot_rcu()
1358 if (nd->path.dentry != nd->path.mnt->mnt_root) { in follow_dotdot_rcu()
1359 struct dentry *old = nd->path.dentry; in follow_dotdot_rcu()
1365 if (unlikely(read_seqcount_retry(&old->d_seq, nd->seq))) in follow_dotdot_rcu()
1367 nd->path.dentry = parent; in follow_dotdot_rcu()
1368 nd->seq = seq; in follow_dotdot_rcu()
1369 if (unlikely(!path_connected(&nd->path))) in follow_dotdot_rcu()
1373 struct mount *mnt = real_mount(nd->path.mnt); in follow_dotdot_rcu()
1378 if (unlikely(read_seqretry(&mount_lock, nd->m_seq))) in follow_dotdot_rcu()
1380 if (&mparent->mnt == nd->path.mnt) in follow_dotdot_rcu()
1383 nd->path.dentry = mountpoint; in follow_dotdot_rcu()
1384 nd->path.mnt = &mparent->mnt; in follow_dotdot_rcu()
1386 nd->seq = seq; in follow_dotdot_rcu()
1389 while (unlikely(d_mountpoint(nd->path.dentry))) { in follow_dotdot_rcu()
1391 mounted = __lookup_mnt(nd->path.mnt, nd->path.dentry); in follow_dotdot_rcu()
1392 if (unlikely(read_seqretry(&mount_lock, nd->m_seq))) in follow_dotdot_rcu()
1396 nd->path.mnt = &mounted->mnt; in follow_dotdot_rcu()
1397 nd->path.dentry = mounted->mnt.mnt_root; in follow_dotdot_rcu()
1398 inode = nd->path.dentry->d_inode; in follow_dotdot_rcu()
1399 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); in follow_dotdot_rcu()
1401 nd->inode = inode; in follow_dotdot_rcu()
1481 static int follow_dotdot(struct nameidata *nd) in follow_dotdot() argument
1484 if (path_equal(&nd->path, &nd->root)) in follow_dotdot()
1486 if (nd->path.dentry != nd->path.mnt->mnt_root) { in follow_dotdot()
1487 int ret = path_parent_directory(&nd->path); in follow_dotdot()
1492 if (!follow_up(&nd->path)) in follow_dotdot()
1495 follow_mount(&nd->path); in follow_dotdot()
1496 nd->inode = nd->path.dentry->d_inode; in follow_dotdot()
1554 static int lookup_fast(struct nameidata *nd, in lookup_fast() argument
1558 struct vfsmount *mnt = nd->path.mnt; in lookup_fast()
1559 struct dentry *dentry, *parent = nd->path.dentry; in lookup_fast()
1568 if (nd->flags & LOOKUP_RCU) { in lookup_fast()
1571 dentry = __d_lookup_rcu(parent, &nd->last, &seq); in lookup_fast()
1573 if (unlazy_walk(nd)) in lookup_fast()
1594 if (unlikely(__read_seqcount_retry(&parent->d_seq, nd->seq))) in lookup_fast()
1598 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1608 if (likely(__follow_mount_rcu(nd, path, inode, seqp))) in lookup_fast()
1611 if (unlazy_child(nd, dentry, seq)) in lookup_fast()
1615 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1617 dentry = __d_lookup(parent, &nd->last); in lookup_fast()
1620 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1635 err = follow_managed(path, nd); in lookup_fast()
1693 static inline int may_lookup(struct nameidata *nd) in may_lookup() argument
1695 if (nd->flags & LOOKUP_RCU) { in may_lookup()
1696 int err = inode_permission(nd->inode, MAY_EXEC|MAY_NOT_BLOCK); in may_lookup()
1699 if (unlazy_walk(nd)) in may_lookup()
1702 return inode_permission(nd->inode, MAY_EXEC); in may_lookup()
1705 static inline int handle_dots(struct nameidata *nd, int type) in handle_dots() argument
1708 if (!nd->root.mnt) in handle_dots()
1709 set_root(nd); in handle_dots()
1710 if (nd->flags & LOOKUP_RCU) { in handle_dots()
1711 return follow_dotdot_rcu(nd); in handle_dots()
1713 return follow_dotdot(nd); in handle_dots()
1718 static int pick_link(struct nameidata *nd, struct path *link, in pick_link() argument
1723 if (unlikely(nd->total_link_count++ >= MAXSYMLINKS)) { in pick_link()
1724 path_to_nameidata(link, nd); in pick_link()
1727 if (!(nd->flags & LOOKUP_RCU)) { in pick_link()
1728 if (link->mnt == nd->path.mnt) in pick_link()
1731 error = nd_alloc_stack(nd); in pick_link()
1734 if (unlikely(!legitimize_path(nd, link, seq))) { in pick_link()
1735 drop_links(nd); in pick_link()
1736 nd->depth = 0; in pick_link()
1737 nd->flags &= ~LOOKUP_RCU; in pick_link()
1738 nd->path.mnt = NULL; in pick_link()
1739 nd->path.dentry = NULL; in pick_link()
1740 if (!(nd->flags & LOOKUP_ROOT)) in pick_link()
1741 nd->root.mnt = NULL; in pick_link()
1743 } else if (likely(unlazy_walk(nd)) == 0) in pick_link()
1744 error = nd_alloc_stack(nd); in pick_link()
1752 last = nd->stack + nd->depth++; in pick_link()
1755 nd->link_inode = inode; in pick_link()
1768 static inline int step_into(struct nameidata *nd, struct path *path, in step_into() argument
1771 if (!(flags & WALK_MORE) && nd->depth) in step_into()
1772 put_link(nd); in step_into()
1774 !(flags & WALK_FOLLOW || nd->flags & LOOKUP_FOLLOW)) { in step_into()
1776 path_to_nameidata(path, nd); in step_into()
1777 nd->inode = inode; in step_into()
1778 nd->seq = seq; in step_into()
1782 if (nd->flags & LOOKUP_RCU) { in step_into()
1786 return pick_link(nd, path, inode, seq); in step_into()
1789 static int walk_component(struct nameidata *nd, int flags) in walk_component() argument
1800 if (unlikely(nd->last_type != LAST_NORM)) { in walk_component()
1801 err = handle_dots(nd, nd->last_type); in walk_component()
1802 if (!(flags & WALK_MORE) && nd->depth) in walk_component()
1803 put_link(nd); in walk_component()
1806 err = lookup_fast(nd, &path, &inode, &seq); in walk_component()
1810 path.dentry = lookup_slow(&nd->last, nd->path.dentry, in walk_component()
1811 nd->flags); in walk_component()
1815 path.mnt = nd->path.mnt; in walk_component()
1816 err = follow_managed(&path, nd); in walk_component()
1821 path_to_nameidata(&path, nd); in walk_component()
1829 return step_into(nd, &path, flags, inode, seq); in walk_component()
2068 static int link_path_walk(const char *name, struct nameidata *nd) in link_path_walk() argument
2084 err = may_lookup(nd); in link_path_walk()
2088 hash_len = hash_name(nd->path.dentry, name); in link_path_walk()
2095 nd->flags |= LOOKUP_JUMPED; in link_path_walk()
2102 struct dentry *parent = nd->path.dentry; in link_path_walk()
2103 nd->flags &= ~LOOKUP_JUMPED; in link_path_walk()
2114 nd->last.hash_len = hash_len; in link_path_walk()
2115 nd->last.name = name; in link_path_walk()
2116 nd->last_type = type; in link_path_walk()
2131 if (!nd->depth) in link_path_walk()
2133 name = nd->stack[nd->depth - 1].name; in link_path_walk()
2138 err = walk_component(nd, WALK_FOLLOW); in link_path_walk()
2141 err = walk_component(nd, WALK_FOLLOW | WALK_MORE); in link_path_walk()
2147 const char *s = get_link(nd); in link_path_walk()
2154 put_link(nd); in link_path_walk()
2156 nd->stack[nd->depth - 1].name = name; in link_path_walk()
2161 if (unlikely(!d_can_lookup(nd->path.dentry))) { in link_path_walk()
2162 if (nd->flags & LOOKUP_RCU) { in link_path_walk()
2163 if (unlazy_walk(nd)) in link_path_walk()
2172 static const char *path_init(struct nameidata *nd, unsigned flags) in path_init() argument
2174 const char *s = nd->name->name; in path_init()
2181 nd->last_type = LAST_ROOT; /* if there are only slashes... */ in path_init()
2182 nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT; in path_init()
2183 nd->depth = 0; in path_init()
2185 struct dentry *root = nd->root.dentry; in path_init()
2189 nd->path = nd->root; in path_init()
2190 nd->inode = inode; in path_init()
2192 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2193 nd->root_seq = nd->seq; in path_init()
2194 nd->m_seq = read_seqbegin(&mount_lock); in path_init()
2196 path_get(&nd->path); in path_init()
2201 nd->root.mnt = NULL; in path_init()
2202 nd->path.mnt = NULL; in path_init()
2203 nd->path.dentry = NULL; in path_init()
2205 nd->m_seq = read_seqbegin(&mount_lock); in path_init()
2207 set_root(nd); in path_init()
2208 if (likely(!nd_jump_root(nd))) in path_init()
2211 } else if (nd->dfd == AT_FDCWD) { in path_init()
2218 nd->path = fs->pwd; in path_init()
2219 nd->inode = nd->path.dentry->d_inode; in path_init()
2220 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2223 get_fs_pwd(current->fs, &nd->path); in path_init()
2224 nd->inode = nd->path.dentry->d_inode; in path_init()
2229 struct fd f = fdget_raw(nd->dfd); in path_init()
2242 nd->path = f.file->f_path; in path_init()
2244 nd->inode = nd->path.dentry->d_inode; in path_init()
2245 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2247 path_get(&nd->path); in path_init()
2248 nd->inode = nd->path.dentry->d_inode; in path_init()
2255 static const char *trailing_symlink(struct nameidata *nd) in trailing_symlink() argument
2258 int error = may_follow_link(nd); in trailing_symlink()
2261 nd->flags |= LOOKUP_PARENT; in trailing_symlink()
2262 nd->stack[0].name = NULL; in trailing_symlink()
2263 s = get_link(nd); in trailing_symlink()
2267 static inline int lookup_last(struct nameidata *nd) in lookup_last() argument
2269 if (nd->last_type == LAST_NORM && nd->last.name[nd->last.len]) in lookup_last()
2270 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; in lookup_last()
2272 nd->flags &= ~LOOKUP_PARENT; in lookup_last()
2273 return walk_component(nd, 0); in lookup_last()
2276 static int handle_lookup_down(struct nameidata *nd) in handle_lookup_down() argument
2278 struct path path = nd->path; in handle_lookup_down()
2279 struct inode *inode = nd->inode; in handle_lookup_down()
2280 unsigned seq = nd->seq; in handle_lookup_down()
2283 if (nd->flags & LOOKUP_RCU) { in handle_lookup_down()
2289 if (unlikely(!__follow_mount_rcu(nd, &path, &inode, &seq))) in handle_lookup_down()
2293 err = follow_managed(&path, nd); in handle_lookup_down()
2299 path_to_nameidata(&path, nd); in handle_lookup_down()
2300 nd->inode = inode; in handle_lookup_down()
2301 nd->seq = seq; in handle_lookup_down()
2306 static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path) in path_lookupat() argument
2308 const char *s = path_init(nd, flags); in path_lookupat()
2312 err = handle_lookup_down(nd); in path_lookupat()
2317 while (!(err = link_path_walk(s, nd)) in path_lookupat()
2318 && ((err = lookup_last(nd)) > 0)) { in path_lookupat()
2319 s = trailing_symlink(nd); in path_lookupat()
2322 err = complete_walk(nd); in path_lookupat()
2324 if (!err && nd->flags & LOOKUP_DIRECTORY) in path_lookupat()
2325 if (!d_can_lookup(nd->path.dentry)) in path_lookupat()
2328 *path = nd->path; in path_lookupat()
2329 nd->path.mnt = NULL; in path_lookupat()
2330 nd->path.dentry = NULL; in path_lookupat()
2332 terminate_walk(nd); in path_lookupat()
2340 struct nameidata nd; in filename_lookup() local
2344 nd.root = *root; in filename_lookup()
2347 set_nameidata(&nd, dfd, name); in filename_lookup()
2348 retval = path_lookupat(&nd, flags | LOOKUP_RCU, path); in filename_lookup()
2350 retval = path_lookupat(&nd, flags, path); in filename_lookup()
2352 retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path); in filename_lookup()
2362 static int path_parentat(struct nameidata *nd, unsigned flags, in path_parentat() argument
2365 const char *s = path_init(nd, flags); in path_parentat()
2366 int err = link_path_walk(s, nd); in path_parentat()
2368 err = complete_walk(nd); in path_parentat()
2370 *parent = nd->path; in path_parentat()
2371 nd->path.mnt = NULL; in path_parentat()
2372 nd->path.dentry = NULL; in path_parentat()
2374 terminate_walk(nd); in path_parentat()
2383 struct nameidata nd; in filename_parentat() local
2387 set_nameidata(&nd, dfd, name); in filename_parentat()
2388 retval = path_parentat(&nd, flags | LOOKUP_RCU, parent); in filename_parentat()
2390 retval = path_parentat(&nd, flags, parent); in filename_parentat()
2392 retval = path_parentat(&nd, flags | LOOKUP_REVAL, parent); in filename_parentat()
2394 *last = nd.last; in filename_parentat()
2395 *type = nd.last_type; in filename_parentat()
2637 mountpoint_last(struct nameidata *nd) in mountpoint_last() argument
2640 struct dentry *dir = nd->path.dentry; in mountpoint_last()
2644 if (nd->flags & LOOKUP_RCU) { in mountpoint_last()
2645 if (unlazy_walk(nd)) in mountpoint_last()
2649 nd->flags &= ~LOOKUP_PARENT; in mountpoint_last()
2651 if (unlikely(nd->last_type != LAST_NORM)) { in mountpoint_last()
2652 error = handle_dots(nd, nd->last_type); in mountpoint_last()
2655 path.dentry = dget(nd->path.dentry); in mountpoint_last()
2657 path.dentry = d_lookup(dir, &nd->last); in mountpoint_last()
2665 path.dentry = lookup_slow(&nd->last, dir, in mountpoint_last()
2666 nd->flags | LOOKUP_NO_REVAL); in mountpoint_last()
2675 path.mnt = nd->path.mnt; in mountpoint_last()
2676 return step_into(nd, &path, 0, d_backing_inode(path.dentry), 0); in mountpoint_last()
2689 path_mountpoint(struct nameidata *nd, unsigned flags, struct path *path) in path_mountpoint() argument
2691 const char *s = path_init(nd, flags); in path_mountpoint()
2694 while (!(err = link_path_walk(s, nd)) && in path_mountpoint()
2695 (err = mountpoint_last(nd)) > 0) { in path_mountpoint()
2696 s = trailing_symlink(nd); in path_mountpoint()
2699 *path = nd->path; in path_mountpoint()
2700 nd->path.mnt = NULL; in path_mountpoint()
2701 nd->path.dentry = NULL; in path_mountpoint()
2704 terminate_walk(nd); in path_mountpoint()
2712 struct nameidata nd; in filename_mountpoint() local
2716 set_nameidata(&nd, dfd, name); in filename_mountpoint()
2717 error = path_mountpoint(&nd, flags | LOOKUP_RCU, path); in filename_mountpoint()
2719 error = path_mountpoint(&nd, flags, path); in filename_mountpoint()
2721 error = path_mountpoint(&nd, flags | LOOKUP_REVAL, path); in filename_mountpoint()
3055 static int atomic_open(struct nameidata *nd, struct dentry *dentry, in atomic_open() argument
3061 struct inode *dir = nd->path.dentry->d_inode; in atomic_open()
3067 if (nd->flags & LOOKUP_DIRECTORY) in atomic_open()
3071 file->f_path.mnt = nd->path.mnt; in atomic_open()
3103 path->mnt = nd->path.mnt; in atomic_open()
3127 static int lookup_open(struct nameidata *nd, struct path *path, in lookup_open() argument
3132 struct dentry *dir = nd->path.dentry; in lookup_open()
3144 dentry = d_lookup(dir, &nd->last); in lookup_open()
3147 dentry = d_alloc_parallel(dir, &nd->last, &wq); in lookup_open()
3154 error = d_revalidate(dentry, nd->flags); in lookup_open()
3187 create_error = may_o_create(&nd->path, dentry, mode); in lookup_open()
3204 error = atomic_open(nd, dentry, path, file, op, open_flag, in lookup_open()
3214 nd->flags); in lookup_open()
3246 path->mnt = nd->path.mnt; in lookup_open()
3257 static int do_last(struct nameidata *nd, in do_last() argument
3260 struct dentry *dir = nd->path.dentry; in do_last()
3270 nd->flags &= ~LOOKUP_PARENT; in do_last()
3271 nd->flags |= op->intent; in do_last()
3273 if (nd->last_type != LAST_NORM) { in do_last()
3274 error = handle_dots(nd, nd->last_type); in do_last()
3281 if (nd->last.name[nd->last.len]) in do_last()
3282 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; in do_last()
3284 error = lookup_fast(nd, &path, &inode, &seq); in do_last()
3291 BUG_ON(nd->inode != dir->d_inode); in do_last()
3292 BUG_ON(nd->flags & LOOKUP_RCU); in do_last()
3300 error = complete_walk(nd); in do_last()
3304 audit_inode(nd->name, dir, LOOKUP_PARENT); in do_last()
3306 if (unlikely(nd->last.name[nd->last.len])) in do_last()
3311 error = mnt_want_write(nd->path.mnt); in do_last()
3324 error = lookup_open(nd, &path, file, op, got_write); in do_last()
3338 audit_inode(nd->name, file->f_path.dentry, 0); in do_last()
3347 path_to_nameidata(&path, nd); in do_last()
3357 mnt_drop_write(nd->path.mnt); in do_last()
3361 error = follow_managed(&path, nd); in do_last()
3366 path_to_nameidata(&path, nd); in do_last()
3373 audit_inode(nd->name, path.dentry, 0); in do_last()
3376 path_to_nameidata(&path, nd); in do_last()
3383 error = step_into(nd, &path, 0, inode, seq); in do_last()
3388 error = complete_walk(nd); in do_last()
3391 audit_inode(nd->name, nd->path.dentry, 0); in do_last()
3394 if (d_is_dir(nd->path.dentry)) in do_last()
3397 d_backing_inode(nd->path.dentry)); in do_last()
3402 if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry)) in do_last()
3404 if (!d_is_reg(nd->path.dentry)) in do_last()
3408 error = mnt_want_write(nd->path.mnt); in do_last()
3414 error = may_open(&nd->path, acc_mode, open_flag); in do_last()
3418 error = vfs_open(&nd->path, file); in do_last()
3431 mnt_drop_write(nd->path.mnt); in do_last()
3473 static int do_tmpfile(struct nameidata *nd, unsigned flags, in do_tmpfile() argument
3479 int error = path_lookupat(nd, flags | LOOKUP_DIRECTORY, &path); in do_tmpfile()
3491 audit_inode(nd->name, child, 0); in do_tmpfile()
3505 static int do_o_path(struct nameidata *nd, unsigned flags, struct file *file) in do_o_path() argument
3508 int error = path_lookupat(nd, flags, &path); in do_o_path()
3510 audit_inode(nd->name, path.dentry, 0); in do_o_path()
3517 static struct file *path_openat(struct nameidata *nd, in path_openat() argument
3528 error = do_tmpfile(nd, flags, op, file); in path_openat()
3530 error = do_o_path(nd, flags, file); in path_openat()
3532 const char *s = path_init(nd, flags); in path_openat()
3533 while (!(error = link_path_walk(s, nd)) && in path_openat()
3534 (error = do_last(nd, file, op)) > 0) { in path_openat()
3535 nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL); in path_openat()
3536 s = trailing_symlink(nd); in path_openat()
3538 terminate_walk(nd); in path_openat()
3559 struct nameidata nd; in do_filp_open() local
3563 set_nameidata(&nd, dfd, pathname); in do_filp_open()
3564 filp = path_openat(&nd, op, flags | LOOKUP_RCU); in do_filp_open()
3566 filp = path_openat(&nd, op, flags); in do_filp_open()
3568 filp = path_openat(&nd, op, flags | LOOKUP_REVAL); in do_filp_open()
3576 struct nameidata nd; in do_file_open_root() local
3581 nd.root.mnt = mnt; in do_file_open_root()
3582 nd.root.dentry = dentry; in do_file_open_root()
3591 set_nameidata(&nd, -1, filename); in do_file_open_root()
3592 file = path_openat(&nd, op, flags | LOOKUP_RCU); in do_file_open_root()
3594 file = path_openat(&nd, op, flags); in do_file_open_root()
3596 file = path_openat(&nd, op, flags | LOOKUP_REVAL); in do_file_open_root()