From 46077e846b0bcee3bda14b3650a2f4be79568826 Mon Sep 17 00:00:00 2001 From: Alex Hornung Date: Sun, 14 Mar 2010 08:27:32 +0000 Subject: [PATCH] nlookup - introduce nlookup_init_root * nlookup_init_root is similar to nlookup_init_raw, but does not assume rootnch is set already, but rather has one more parameter which specifies the root nch. --- sys/kern/vfs_nlookup.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ sys/sys/nlookup.h | 1 + 2 files changed, 45 insertions(+) diff --git a/sys/kern/vfs_nlookup.c b/sys/kern/vfs_nlookup.c index f7377b0918..9d9f22eafd 100644 --- a/sys/kern/vfs_nlookup.c +++ b/sys/kern/vfs_nlookup.c @@ -230,6 +230,50 @@ nlookup_init_raw(struct nlookupdata *nd, } /* + * This works similarly to nlookup_init_raw() but does not rely + * on rootnch being initialized yet. + */ +int +nlookup_init_root(struct nlookupdata *nd, + const char *path, enum uio_seg seg, int flags, + struct ucred *cred, struct nchandle *ncstart, + struct nchandle *ncroot) +{ + size_t pathlen; + thread_t td; + int error; + + td = curthread; + + bzero(nd, sizeof(struct nlookupdata)); + nd->nl_path = objcache_get(namei_oc, M_WAITOK); + nd->nl_flags |= NLC_HASBUF; + if (seg == UIO_SYSSPACE) + error = copystr(path, nd->nl_path, MAXPATHLEN, &pathlen); + else + error = copyinstr(path, nd->nl_path, MAXPATHLEN, &pathlen); + + /* + * Don't allow empty pathnames. + * POSIX.1 requirement: "" is not a vaild file name. + */ + if (error == 0 && pathlen <= 1) + error = ENOENT; + + if (error == 0) { + cache_copy(ncstart, &nd->nl_nch); + cache_copy(ncroot, &nd->nl_rootnch); + cache_copy(ncroot, &nd->nl_jailnch); + nd->nl_cred = crhold(cred); + nd->nl_td = td; + nd->nl_flags |= flags; + } else { + nlookup_done(nd); + } + return(error); +} + +/* * Set a different credential; this credential will be used by future * operations performed on nd.nl_open_vp and nlookupdata structure. */ diff --git a/sys/sys/nlookup.h b/sys/sys/nlookup.h index 29eb7d3176..d058174792 100644 --- a/sys/sys/nlookup.h +++ b/sys/sys/nlookup.h @@ -150,6 +150,7 @@ int nlookup_init(struct nlookupdata *, const char *, enum uio_seg, int); int nlookup_init_at(struct nlookupdata *, struct file **, int, const char *, enum uio_seg, int); int nlookup_init_raw(struct nlookupdata *, const char *, enum uio_seg, int, struct ucred *, struct nchandle *); +int nlookup_init_root(struct nlookupdata *, const char *, enum uio_seg, int, struct ucred *, struct nchandle *, struct nchandle *); void nlookup_set_cred(struct nlookupdata *nd, struct ucred *cred); void nlookup_zero(struct nlookupdata *); void nlookup_done(struct nlookupdata *); -- 2.11.4.GIT