#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/cred.h>
#include <sys/user.h>
#include <sys/uio.h>
#include <sys/vfs.h>
#include <sys/vnode.h>
#include <sys/pathname.h>
#include <sys/proc.h>
#include <sys/vtrace.h>
#include <sys/sysmacros.h>
#include <sys/debug.h>
#include <sys/dirent.h>
#include <sys/zone.h>
#include <sys/fs/snode.h>
#include <libfksmbfs.h>
extern vnode_t *rootdir;
int
fake_lookup(vnode_t *dvp, char *path, vnode_t **vpp)
{
char component[MAXNAMELEN];
pathname_t pn;
cred_t *cr;
vnode_t *cvp;
vnode_t *nvp;
char *p;
int flags = 0;
int error, len;
bzero(&pn, sizeof (pn));
pn.pn_buf = path;
pn.pn_path = path;
pn.pn_pathlen = strlen(path);
pn.pn_bufsize = pn.pn_pathlen + 1;
p = path;
cr = CRED();
cvp = (dvp != NULL) ? dvp : rootdir;
VN_HOLD(cvp);
nvp = NULL;
while (*p != '\0') {
if (*p == '/') {
p++;
continue;
}
len = strcspn(p, "/");
ASSERT(len > 0);
if (len >= MAXNAMELEN)
return (EINVAL);
(void) strncpy(component, p, len);
component[len] = '\0';
pn.pn_path = p;
pn.pn_pathlen = strlen(p);
error = VOP_LOOKUP(cvp, component, &nvp, &pn, flags,
rootdir, cr, NULL, NULL, NULL);
VN_RELE(cvp);
if (error != 0)
return (error);
cvp = nvp;
nvp = NULL;
p += len;
}
*vpp = cvp;
return (0);
}
int
fake_lookup_dir(char *path, vnode_t **vpp, char **lastcomp)
{
vnode_t *dvp;
char *last;
char *tpn = NULL;
int tpn_sz;
int lc_off;
int error;
*vpp = NULL;
*lastcomp = NULL;
tpn_sz = strlen(path) + 1;
tpn = kmem_alloc(tpn_sz, KM_SLEEP);
bcopy(path, tpn, tpn_sz);
last = strrchr(tpn, '/');
if (last == NULL) {
lc_off = 0;
dvp = rootdir;
VN_HOLD(dvp);
error = 0;
} else {
*last++ = '\0';
if (*last == '\0') {
error = EINVAL;
goto out;
}
error = fake_lookup(rootdir, tpn, &dvp);
if (error != 0) {
goto out;
}
lc_off = last - tpn;
ASSERT(lc_off >= 0 && lc_off < tpn_sz);
}
*vpp = dvp;
*lastcomp = path + lc_off;
out:
if (tpn != NULL)
kmem_free(tpn, tpn_sz);
return (error);
}