Lines Matching refs:nd
543 static int __nd_alloc_stack(struct nameidata *nd) in __nd_alloc_stack() argument
547 if (nd->flags & LOOKUP_RCU) { in __nd_alloc_stack()
558 memcpy(p, nd->internal, sizeof(nd->internal)); in __nd_alloc_stack()
559 nd->stack = p; in __nd_alloc_stack()
581 static inline int nd_alloc_stack(struct nameidata *nd) in nd_alloc_stack() argument
583 if (likely(nd->depth != EMBEDDED_LEVELS)) in nd_alloc_stack()
585 if (likely(nd->stack != nd->internal)) in nd_alloc_stack()
587 return __nd_alloc_stack(nd); in nd_alloc_stack()
590 static void drop_links(struct nameidata *nd) in drop_links() argument
592 int i = nd->depth; in drop_links()
594 struct saved *last = nd->stack + i; in drop_links()
603 static void terminate_walk(struct nameidata *nd) in terminate_walk() argument
605 drop_links(nd); in terminate_walk()
606 if (!(nd->flags & LOOKUP_RCU)) { in terminate_walk()
608 path_put(&nd->path); in terminate_walk()
609 for (i = 0; i < nd->depth; i++) in terminate_walk()
610 path_put(&nd->stack[i].link); in terminate_walk()
611 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT)) { in terminate_walk()
612 path_put(&nd->root); in terminate_walk()
613 nd->root.mnt = NULL; in terminate_walk()
616 nd->flags &= ~LOOKUP_RCU; in terminate_walk()
617 if (!(nd->flags & LOOKUP_ROOT)) in terminate_walk()
618 nd->root.mnt = NULL; in terminate_walk()
621 nd->depth = 0; in terminate_walk()
625 static bool legitimize_path(struct nameidata *nd, in legitimize_path() argument
628 int res = __legitimize_mnt(path->mnt, nd->m_seq); in legitimize_path()
642 static bool legitimize_links(struct nameidata *nd) in legitimize_links() argument
645 for (i = 0; i < nd->depth; i++) { in legitimize_links()
646 struct saved *last = nd->stack + i; in legitimize_links()
647 if (unlikely(!legitimize_path(nd, &last->link, last->seq))) { in legitimize_links()
648 drop_links(nd); in legitimize_links()
649 nd->depth = i + 1; in legitimize_links()
680 static int unlazy_walk(struct nameidata *nd, struct dentry *dentry, unsigned seq) in unlazy_walk() argument
682 struct dentry *parent = nd->path.dentry; in unlazy_walk()
684 BUG_ON(!(nd->flags & LOOKUP_RCU)); in unlazy_walk()
686 nd->flags &= ~LOOKUP_RCU; in unlazy_walk()
687 if (unlikely(!legitimize_links(nd))) in unlazy_walk()
689 if (unlikely(!legitimize_mnt(nd->path.mnt, nd->m_seq))) in unlazy_walk()
706 if (read_seqcount_retry(&parent->d_seq, nd->seq)) in unlazy_walk()
708 BUG_ON(nd->inode != parent->d_inode); in unlazy_walk()
720 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT)) { in unlazy_walk()
721 if (unlikely(!legitimize_path(nd, &nd->root, nd->root_seq))) { in unlazy_walk()
736 nd->path.mnt = NULL; in unlazy_walk()
738 nd->path.dentry = NULL; in unlazy_walk()
742 if (!(nd->flags & LOOKUP_ROOT)) in unlazy_walk()
743 nd->root.mnt = NULL; in unlazy_walk()
747 static int unlazy_link(struct nameidata *nd, struct path *link, unsigned seq) in unlazy_link() argument
749 if (unlikely(!legitimize_path(nd, link, seq))) { in unlazy_link()
750 drop_links(nd); in unlazy_link()
751 nd->depth = 0; in unlazy_link()
752 nd->flags &= ~LOOKUP_RCU; in unlazy_link()
753 nd->path.mnt = NULL; in unlazy_link()
754 nd->path.dentry = NULL; in unlazy_link()
755 if (!(nd->flags & LOOKUP_ROOT)) in unlazy_link()
756 nd->root.mnt = NULL; in unlazy_link()
758 } else if (likely(unlazy_walk(nd, NULL, 0)) == 0) { in unlazy_link()
780 static int complete_walk(struct nameidata *nd) in complete_walk() argument
782 struct dentry *dentry = nd->path.dentry; in complete_walk()
785 if (nd->flags & LOOKUP_RCU) { in complete_walk()
786 if (!(nd->flags & LOOKUP_ROOT)) in complete_walk()
787 nd->root.mnt = NULL; in complete_walk()
788 if (unlikely(unlazy_walk(nd, NULL, 0))) in complete_walk()
792 if (likely(!(nd->flags & LOOKUP_JUMPED))) in complete_walk()
798 status = dentry->d_op->d_weak_revalidate(dentry, nd->flags); in complete_walk()
808 static void set_root(struct nameidata *nd) in set_root() argument
810 get_fs_root(current->fs, &nd->root); in set_root()
813 static void set_root_rcu(struct nameidata *nd) in set_root_rcu() argument
820 nd->root = fs->root; in set_root_rcu()
821 nd->root_seq = __read_seqcount_begin(&nd->root.dentry->d_seq); in set_root_rcu()
825 static void path_put_conditional(struct path *path, struct nameidata *nd) in path_put_conditional() argument
828 if (path->mnt != nd->path.mnt) in path_put_conditional()
833 struct nameidata *nd) in path_to_nameidata() argument
835 if (!(nd->flags & LOOKUP_RCU)) { in path_to_nameidata()
836 dput(nd->path.dentry); in path_to_nameidata()
837 if (nd->path.mnt != path->mnt) in path_to_nameidata()
838 mntput(nd->path.mnt); in path_to_nameidata()
840 nd->path.mnt = path->mnt; in path_to_nameidata()
841 nd->path.dentry = path->dentry; in path_to_nameidata()
850 struct nameidata *nd = current->nameidata; in nd_jump_link() local
851 path_put(&nd->path); in nd_jump_link()
853 nd->path = *path; in nd_jump_link()
854 nd->inode = nd->path.dentry->d_inode; in nd_jump_link()
855 nd->flags |= LOOKUP_JUMPED; in nd_jump_link()
858 static inline void put_link(struct nameidata *nd) in put_link() argument
860 struct saved *last = nd->stack + --nd->depth; in put_link()
864 if (!(nd->flags & LOOKUP_RCU)) in put_link()
886 static inline int may_follow_link(struct nameidata *nd) in may_follow_link() argument
895 inode = nd->stack[0].inode; in may_follow_link()
900 parent = nd->inode; in may_follow_link()
908 if (nd->flags & LOOKUP_RCU) in may_follow_link()
911 audit_log_link_denied("follow_link", &nd->stack[0].link); in may_follow_link()
982 const char *get_link(struct nameidata *nd) in get_link() argument
984 struct saved *last = nd->stack + nd->depth - 1; in get_link()
990 if (!(nd->flags & LOOKUP_RCU)) { in get_link()
994 if (unlikely(unlazy_walk(nd, NULL, 0))) in get_link()
1000 nd->flags & LOOKUP_RCU); in get_link()
1004 nd->last_type = LAST_BIND; in get_link()
1007 if (nd->flags & LOOKUP_RCU) { in get_link()
1008 if (unlikely(unlazy_walk(nd, NULL, 0))) in get_link()
1018 if (nd->flags & LOOKUP_RCU) { in get_link()
1020 if (!nd->root.mnt) in get_link()
1021 set_root_rcu(nd); in get_link()
1022 nd->path = nd->root; in get_link()
1023 d = nd->path.dentry; in get_link()
1024 nd->inode = d->d_inode; in get_link()
1025 nd->seq = nd->root_seq; in get_link()
1026 if (unlikely(read_seqcount_retry(&d->d_seq, nd->seq))) in get_link()
1029 if (!nd->root.mnt) in get_link()
1030 set_root(nd); in get_link()
1031 path_put(&nd->path); in get_link()
1032 nd->path = nd->root; in get_link()
1033 path_get(&nd->root); in get_link()
1034 nd->inode = nd->path.dentry->d_inode; in get_link()
1036 nd->flags |= LOOKUP_JUMPED; in get_link()
1083 static int follow_automount(struct path *path, struct nameidata *nd, in follow_automount() argument
1103 if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY | in follow_automount()
1108 nd->total_link_count++; in follow_automount()
1109 if (nd->total_link_count >= 40) in follow_automount()
1123 if (PTR_ERR(mnt) == -EISDIR && (nd->flags & LOOKUP_PARENT)) in follow_automount()
1163 static int follow_managed(struct path *path, struct nameidata *nd) in follow_managed() argument
1207 ret = follow_automount(path, nd, &need_mntput); in follow_managed()
1222 nd->flags |= LOOKUP_JUMPED; in follow_managed()
1224 path_put_conditional(path, nd); in follow_managed()
1254 static bool __follow_mount_rcu(struct nameidata *nd, struct path *path, in __follow_mount_rcu() argument
1281 nd->flags |= LOOKUP_JUMPED; in __follow_mount_rcu()
1290 return !read_seqretry(&mount_lock, nd->m_seq) && in __follow_mount_rcu()
1294 static int follow_dotdot_rcu(struct nameidata *nd) in follow_dotdot_rcu() argument
1296 struct inode *inode = nd->inode; in follow_dotdot_rcu()
1297 if (!nd->root.mnt) in follow_dotdot_rcu()
1298 set_root_rcu(nd); in follow_dotdot_rcu()
1301 if (path_equal(&nd->path, &nd->root)) in follow_dotdot_rcu()
1303 if (nd->path.dentry != nd->path.mnt->mnt_root) { in follow_dotdot_rcu()
1304 struct dentry *old = nd->path.dentry; in follow_dotdot_rcu()
1310 if (unlikely(read_seqcount_retry(&old->d_seq, nd->seq))) in follow_dotdot_rcu()
1312 nd->path.dentry = parent; in follow_dotdot_rcu()
1313 nd->seq = seq; in follow_dotdot_rcu()
1314 if (unlikely(!path_connected(&nd->path))) in follow_dotdot_rcu()
1318 struct mount *mnt = real_mount(nd->path.mnt); in follow_dotdot_rcu()
1323 if (unlikely(read_seqretry(&mount_lock, nd->m_seq))) in follow_dotdot_rcu()
1325 if (&mparent->mnt == nd->path.mnt) in follow_dotdot_rcu()
1328 nd->path.dentry = mountpoint; in follow_dotdot_rcu()
1329 nd->path.mnt = &mparent->mnt; in follow_dotdot_rcu()
1331 nd->seq = seq; in follow_dotdot_rcu()
1334 while (unlikely(d_mountpoint(nd->path.dentry))) { in follow_dotdot_rcu()
1336 mounted = __lookup_mnt(nd->path.mnt, nd->path.dentry); in follow_dotdot_rcu()
1337 if (unlikely(read_seqretry(&mount_lock, nd->m_seq))) in follow_dotdot_rcu()
1341 nd->path.mnt = &mounted->mnt; in follow_dotdot_rcu()
1342 nd->path.dentry = mounted->mnt.mnt_root; in follow_dotdot_rcu()
1343 inode = nd->path.dentry->d_inode; in follow_dotdot_rcu()
1344 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); in follow_dotdot_rcu()
1346 nd->inode = inode; in follow_dotdot_rcu()
1416 static int follow_dotdot(struct nameidata *nd) in follow_dotdot() argument
1418 if (!nd->root.mnt) in follow_dotdot()
1419 set_root(nd); in follow_dotdot()
1422 struct dentry *old = nd->path.dentry; in follow_dotdot()
1424 if (nd->path.dentry == nd->root.dentry && in follow_dotdot()
1425 nd->path.mnt == nd->root.mnt) { in follow_dotdot()
1428 if (nd->path.dentry != nd->path.mnt->mnt_root) { in follow_dotdot()
1430 nd->path.dentry = dget_parent(nd->path.dentry); in follow_dotdot()
1432 if (unlikely(!path_connected(&nd->path))) in follow_dotdot()
1436 if (!follow_up(&nd->path)) in follow_dotdot()
1439 follow_mount(&nd->path); in follow_dotdot()
1440 nd->inode = nd->path.dentry->d_inode; in follow_dotdot()
1528 static int lookup_fast(struct nameidata *nd, in lookup_fast() argument
1532 struct vfsmount *mnt = nd->path.mnt; in lookup_fast()
1533 struct dentry *dentry, *parent = nd->path.dentry; in lookup_fast()
1543 if (nd->flags & LOOKUP_RCU) { in lookup_fast()
1546 dentry = __d_lookup_rcu(parent, &nd->last, &seq); in lookup_fast()
1566 if (__read_seqcount_retry(&parent->d_seq, nd->seq)) in lookup_fast()
1571 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1586 if (likely(__follow_mount_rcu(nd, path, inode, seqp))) in lookup_fast()
1589 if (unlazy_walk(nd, dentry, seq)) in lookup_fast()
1592 dentry = __d_lookup(parent, &nd->last); in lookup_fast()
1599 status = d_revalidate(dentry, nd->flags); in lookup_fast()
1616 err = follow_managed(path, nd); in lookup_fast()
1626 static int lookup_slow(struct nameidata *nd, struct path *path) in lookup_slow() argument
1630 parent = nd->path.dentry; in lookup_slow()
1631 BUG_ON(nd->inode != parent->d_inode); in lookup_slow()
1634 dentry = __lookup_hash(&nd->last, parent, nd->flags); in lookup_slow()
1638 path->mnt = nd->path.mnt; in lookup_slow()
1640 return follow_managed(path, nd); in lookup_slow()
1643 static inline int may_lookup(struct nameidata *nd) in may_lookup() argument
1645 if (nd->flags & LOOKUP_RCU) { in may_lookup()
1646 int err = inode_permission(nd->inode, MAY_EXEC|MAY_NOT_BLOCK); in may_lookup()
1649 if (unlazy_walk(nd, NULL, 0)) in may_lookup()
1652 return inode_permission(nd->inode, MAY_EXEC); in may_lookup()
1655 static inline int handle_dots(struct nameidata *nd, int type) in handle_dots() argument
1658 if (nd->flags & LOOKUP_RCU) { in handle_dots()
1659 return follow_dotdot_rcu(nd); in handle_dots()
1661 return follow_dotdot(nd); in handle_dots()
1666 static int pick_link(struct nameidata *nd, struct path *link, in pick_link() argument
1671 if (unlikely(nd->total_link_count++ >= MAXSYMLINKS)) { in pick_link()
1672 path_to_nameidata(link, nd); in pick_link()
1675 if (!(nd->flags & LOOKUP_RCU)) { in pick_link()
1676 if (link->mnt == nd->path.mnt) in pick_link()
1679 error = nd_alloc_stack(nd); in pick_link()
1682 if (unlikely(unlazy_link(nd, link, seq))) in pick_link()
1684 error = nd_alloc_stack(nd); in pick_link()
1692 last = nd->stack + nd->depth++; in pick_link()
1706 static inline int should_follow_link(struct nameidata *nd, struct path *link, in should_follow_link() argument
1715 if (nd->flags & LOOKUP_RCU) { in should_follow_link()
1719 return pick_link(nd, link, inode, seq); in should_follow_link()
1724 static int walk_component(struct nameidata *nd, int flags) in walk_component() argument
1735 if (unlikely(nd->last_type != LAST_NORM)) { in walk_component()
1736 err = handle_dots(nd, nd->last_type); in walk_component()
1738 put_link(nd); in walk_component()
1741 err = lookup_fast(nd, &path, &inode, &seq); in walk_component()
1746 err = lookup_slow(nd, &path); in walk_component()
1758 put_link(nd); in walk_component()
1759 err = should_follow_link(nd, &path, flags & WALK_GET, inode, seq); in walk_component()
1762 path_to_nameidata(&path, nd); in walk_component()
1763 nd->inode = inode; in walk_component()
1764 nd->seq = seq; in walk_component()
1768 path_to_nameidata(&path, nd); in walk_component()
1896 static int link_path_walk(const char *name, struct nameidata *nd) in link_path_walk() argument
1910 err = may_lookup(nd); in link_path_walk()
1921 nd->flags |= LOOKUP_JUMPED; in link_path_walk()
1928 struct dentry *parent = nd->path.dentry; in link_path_walk()
1929 nd->flags &= ~LOOKUP_JUMPED; in link_path_walk()
1940 nd->last.hash_len = hash_len; in link_path_walk()
1941 nd->last.name = name; in link_path_walk()
1942 nd->last_type = type; in link_path_walk()
1957 if (!nd->depth) in link_path_walk()
1959 name = nd->stack[nd->depth - 1].name; in link_path_walk()
1964 err = walk_component(nd, WALK_GET | WALK_PUT); in link_path_walk()
1966 err = walk_component(nd, WALK_GET); in link_path_walk()
1972 const char *s = get_link(nd); in link_path_walk()
1979 put_link(nd); in link_path_walk()
1981 nd->stack[nd->depth - 1].name = name; in link_path_walk()
1986 if (unlikely(!d_can_lookup(nd->path.dentry))) { in link_path_walk()
1987 if (nd->flags & LOOKUP_RCU) { in link_path_walk()
1988 if (unlazy_walk(nd, NULL, 0)) in link_path_walk()
1996 static const char *path_init(struct nameidata *nd, unsigned flags) in path_init() argument
1999 const char *s = nd->name->name; in path_init()
2001 nd->last_type = LAST_ROOT; /* if there are only slashes... */ in path_init()
2002 nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT; in path_init()
2003 nd->depth = 0; in path_init()
2005 struct dentry *root = nd->root.dentry; in path_init()
2014 nd->path = nd->root; in path_init()
2015 nd->inode = inode; in path_init()
2018 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2019 nd->root_seq = nd->seq; in path_init()
2020 nd->m_seq = read_seqbegin(&mount_lock); in path_init()
2022 path_get(&nd->path); in path_init()
2027 nd->root.mnt = NULL; in path_init()
2029 nd->m_seq = read_seqbegin(&mount_lock); in path_init()
2033 set_root_rcu(nd); in path_init()
2034 nd->seq = nd->root_seq; in path_init()
2036 set_root(nd); in path_init()
2037 path_get(&nd->root); in path_init()
2039 nd->path = nd->root; in path_init()
2040 } else if (nd->dfd == AT_FDCWD) { in path_init()
2049 nd->path = fs->pwd; in path_init()
2050 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2053 get_fs_pwd(current->fs, &nd->path); in path_init()
2057 struct fd f = fdget_raw(nd->dfd); in path_init()
2072 nd->path = f.file->f_path; in path_init()
2075 nd->inode = nd->path.dentry->d_inode; in path_init()
2076 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); in path_init()
2078 path_get(&nd->path); in path_init()
2079 nd->inode = nd->path.dentry->d_inode; in path_init()
2085 nd->inode = nd->path.dentry->d_inode; in path_init()
2088 if (likely(!read_seqcount_retry(&nd->path.dentry->d_seq, nd->seq))) in path_init()
2090 if (!(nd->flags & LOOKUP_ROOT)) in path_init()
2091 nd->root.mnt = NULL; in path_init()
2096 static const char *trailing_symlink(struct nameidata *nd) in trailing_symlink() argument
2099 int error = may_follow_link(nd); in trailing_symlink()
2102 nd->flags |= LOOKUP_PARENT; in trailing_symlink()
2103 nd->stack[0].name = NULL; in trailing_symlink()
2104 s = get_link(nd); in trailing_symlink()
2108 static inline int lookup_last(struct nameidata *nd) in lookup_last() argument
2110 if (nd->last_type == LAST_NORM && nd->last.name[nd->last.len]) in lookup_last()
2111 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; in lookup_last()
2113 nd->flags &= ~LOOKUP_PARENT; in lookup_last()
2114 return walk_component(nd, in lookup_last()
2115 nd->flags & LOOKUP_FOLLOW in lookup_last()
2116 ? nd->depth in lookup_last()
2123 static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path) in path_lookupat() argument
2125 const char *s = path_init(nd, flags); in path_lookupat()
2130 while (!(err = link_path_walk(s, nd)) in path_lookupat()
2131 && ((err = lookup_last(nd)) > 0)) { in path_lookupat()
2132 s = trailing_symlink(nd); in path_lookupat()
2139 err = complete_walk(nd); in path_lookupat()
2141 if (!err && nd->flags & LOOKUP_DIRECTORY) in path_lookupat()
2142 if (!d_can_lookup(nd->path.dentry)) in path_lookupat()
2145 *path = nd->path; in path_lookupat()
2146 nd->path.mnt = NULL; in path_lookupat()
2147 nd->path.dentry = NULL; in path_lookupat()
2149 terminate_walk(nd); in path_lookupat()
2157 struct nameidata nd; in filename_lookup() local
2161 nd.root = *root; in filename_lookup()
2164 set_nameidata(&nd, dfd, name); in filename_lookup()
2165 retval = path_lookupat(&nd, flags | LOOKUP_RCU, path); in filename_lookup()
2167 retval = path_lookupat(&nd, flags, path); in filename_lookup()
2169 retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path); in filename_lookup()
2179 static int path_parentat(struct nameidata *nd, unsigned flags, in path_parentat() argument
2182 const char *s = path_init(nd, flags); in path_parentat()
2186 err = link_path_walk(s, nd); in path_parentat()
2188 err = complete_walk(nd); in path_parentat()
2190 *parent = nd->path; in path_parentat()
2191 nd->path.mnt = NULL; in path_parentat()
2192 nd->path.dentry = NULL; in path_parentat()
2194 terminate_walk(nd); in path_parentat()
2203 struct nameidata nd; in filename_parentat() local
2207 set_nameidata(&nd, dfd, name); in filename_parentat()
2208 retval = path_parentat(&nd, flags | LOOKUP_RCU, parent); in filename_parentat()
2210 retval = path_parentat(&nd, flags, parent); in filename_parentat()
2212 retval = path_parentat(&nd, flags | LOOKUP_REVAL, parent); in filename_parentat()
2214 *last = nd.last; in filename_parentat()
2215 *type = nd.last_type; in filename_parentat()
2383 mountpoint_last(struct nameidata *nd, struct path *path) in mountpoint_last() argument
2387 struct dentry *dir = nd->path.dentry; in mountpoint_last()
2390 if (nd->flags & LOOKUP_RCU) { in mountpoint_last()
2391 if (unlazy_walk(nd, NULL, 0)) in mountpoint_last()
2395 nd->flags &= ~LOOKUP_PARENT; in mountpoint_last()
2397 if (unlikely(nd->last_type != LAST_NORM)) { in mountpoint_last()
2398 error = handle_dots(nd, nd->last_type); in mountpoint_last()
2401 dentry = dget(nd->path.dentry); in mountpoint_last()
2406 dentry = d_lookup(dir, &nd->last); in mountpoint_last()
2413 dentry = d_alloc(dir, &nd->last); in mountpoint_last()
2418 dentry = lookup_real(dir->d_inode, dentry, nd->flags); in mountpoint_last()
2431 if (nd->depth) in mountpoint_last()
2432 put_link(nd); in mountpoint_last()
2434 path->mnt = nd->path.mnt; in mountpoint_last()
2435 error = should_follow_link(nd, path, nd->flags & LOOKUP_FOLLOW, in mountpoint_last()
2454 path_mountpoint(struct nameidata *nd, unsigned flags, struct path *path) in path_mountpoint() argument
2456 const char *s = path_init(nd, flags); in path_mountpoint()
2460 while (!(err = link_path_walk(s, nd)) && in path_mountpoint()
2461 (err = mountpoint_last(nd, path)) > 0) { in path_mountpoint()
2462 s = trailing_symlink(nd); in path_mountpoint()
2468 terminate_walk(nd); in path_mountpoint()
2476 struct nameidata nd; in filename_mountpoint() local
2480 set_nameidata(&nd, dfd, name); in filename_mountpoint()
2481 error = path_mountpoint(&nd, flags | LOOKUP_RCU, path); in filename_mountpoint()
2483 error = path_mountpoint(&nd, flags, path); in filename_mountpoint()
2485 error = path_mountpoint(&nd, flags | LOOKUP_REVAL, path); in filename_mountpoint()
2778 static int atomic_open(struct nameidata *nd, struct dentry *dentry, in atomic_open() argument
2784 struct inode *dir = nd->path.dentry->d_inode; in atomic_open()
2838 error = may_o_create(&nd->path, dentry, mode); in atomic_open()
2847 if (nd->flags & LOOKUP_DIRECTORY) in atomic_open()
2851 file->f_path.mnt = nd->path.mnt; in atomic_open()
2906 dentry = lookup_real(dir, dentry, nd->flags); in atomic_open()
2916 path->mnt = nd->path.mnt; in atomic_open()
2938 static int lookup_open(struct nameidata *nd, struct path *path, in lookup_open() argument
2943 struct dentry *dir = nd->path.dentry; in lookup_open()
2950 dentry = lookup_dcache(&nd->last, dir, nd->flags, &need_lookup); in lookup_open()
2958 if ((nd->flags & LOOKUP_OPEN) && dir_inode->i_op->atomic_open) { in lookup_open()
2959 return atomic_open(nd, dentry, path, file, op, got_write, in lookup_open()
2966 dentry = lookup_real(dir_inode, dentry, nd->flags); in lookup_open()
2988 error = security_path_mknod(&nd->path, dentry, mode, 0); in lookup_open()
2992 nd->flags & LOOKUP_EXCL); in lookup_open()
2998 path->mnt = nd->path.mnt; in lookup_open()
3009 static int do_last(struct nameidata *nd, in do_last() argument
3013 struct dentry *dir = nd->path.dentry; in do_last()
3025 nd->flags &= ~LOOKUP_PARENT; in do_last()
3026 nd->flags |= op->intent; in do_last()
3028 if (nd->last_type != LAST_NORM) { in do_last()
3029 error = handle_dots(nd, nd->last_type); in do_last()
3036 if (nd->last.name[nd->last.len]) in do_last()
3037 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; in do_last()
3039 error = lookup_fast(nd, &path, &inode, &seq); in do_last()
3046 BUG_ON(nd->inode != dir->d_inode); in do_last()
3054 error = complete_walk(nd); in do_last()
3058 audit_inode(nd->name, dir, LOOKUP_PARENT); in do_last()
3060 if (unlikely(nd->last.name[nd->last.len])) in do_last()
3066 error = mnt_want_write(nd->path.mnt); in do_last()
3076 error = lookup_open(nd, &path, file, op, got_write, opened); in do_last()
3087 audit_inode(nd->name, file->f_path.dentry, 0); in do_last()
3096 path_to_nameidata(&path, nd); in do_last()
3104 audit_inode(nd->name, path.dentry, 0); in do_last()
3112 mnt_drop_write(nd->path.mnt); in do_last()
3117 path_to_nameidata(&path, nd); in do_last()
3121 error = follow_managed(&path, nd); in do_last()
3125 BUG_ON(nd->flags & LOOKUP_RCU); in do_last()
3128 path_to_nameidata(&path, nd); in do_last()
3133 if (nd->depth) in do_last()
3134 put_link(nd); in do_last()
3135 error = should_follow_link(nd, &path, nd->flags & LOOKUP_FOLLOW, in do_last()
3140 if ((nd->flags & LOOKUP_RCU) || nd->path.mnt != path.mnt) { in do_last()
3141 path_to_nameidata(&path, nd); in do_last()
3143 save_parent.dentry = nd->path.dentry; in do_last()
3145 nd->path.dentry = path.dentry; in do_last()
3148 nd->inode = inode; in do_last()
3149 nd->seq = seq; in do_last()
3152 error = complete_walk(nd); in do_last()
3157 audit_inode(nd->name, nd->path.dentry, 0); in do_last()
3158 if (unlikely(d_is_symlink(nd->path.dentry)) && !(open_flag & O_PATH)) { in do_last()
3163 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry)) in do_last()
3166 if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry)) in do_last()
3168 if (!d_is_reg(nd->path.dentry)) in do_last()
3172 error = mnt_want_write(nd->path.mnt); in do_last()
3178 error = may_open(&nd->path, acc_mode, open_flag); in do_last()
3183 error = vfs_open(&nd->path, file, current_cred()); in do_last()
3210 mnt_drop_write(nd->path.mnt); in do_last()
3224 path_put(&nd->path); in do_last()
3225 nd->path = save_parent; in do_last()
3226 nd->inode = dir->d_inode; in do_last()
3230 mnt_drop_write(nd->path.mnt); in do_last()
3237 static int do_tmpfile(struct nameidata *nd, unsigned flags, in do_tmpfile() argument
3245 int error = path_lookupat(nd, flags | LOOKUP_DIRECTORY, &path); in do_tmpfile()
3270 audit_inode(nd->name, child, 0); in do_tmpfile()
3295 static struct file *path_openat(struct nameidata *nd, in path_openat() argument
3310 error = do_tmpfile(nd, flags, op, file, &opened); in path_openat()
3314 s = path_init(nd, flags); in path_openat()
3319 while (!(error = link_path_walk(s, nd)) && in path_openat()
3320 (error = do_last(nd, file, op, &opened)) > 0) { in path_openat()
3321 nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL); in path_openat()
3322 s = trailing_symlink(nd); in path_openat()
3328 terminate_walk(nd); in path_openat()
3349 struct nameidata nd; in do_filp_open() local
3353 set_nameidata(&nd, dfd, pathname); in do_filp_open()
3354 filp = path_openat(&nd, op, flags | LOOKUP_RCU); in do_filp_open()
3356 filp = path_openat(&nd, op, flags); in do_filp_open()
3358 filp = path_openat(&nd, op, flags | LOOKUP_REVAL); in do_filp_open()
3366 struct nameidata nd; in do_file_open_root() local
3371 nd.root.mnt = mnt; in do_file_open_root()
3372 nd.root.dentry = dentry; in do_file_open_root()
3381 set_nameidata(&nd, -1, filename); in do_file_open_root()
3382 file = path_openat(&nd, op, flags | LOOKUP_RCU); in do_file_open_root()
3384 file = path_openat(&nd, op, flags); in do_file_open_root()
3386 file = path_openat(&nd, op, flags | LOOKUP_REVAL); in do_file_open_root()