/* Check if a directory can be found inside another in the hierarchy */ int vn_isunder(struct vnode *lvp, struct vnode *rvp, struct proc *p) { int error; error = vfs_getcwd_common(lvp, rvp, NULL, NULL, MAXPATHLEN/2, 0, p); if (!error) return (1); return (0); }
/* Find pathname of a process's current directory */ int sys___getcwd(struct proc *p, void *v, register_t *retval) { struct sys___getcwd_args *uap = v; int error, lenused, len = SCARG(uap, len); char *path, *bp, *bend; if (len > MAXPATHLEN * 4) len = MAXPATHLEN * 4; else if (len < 2) return (ERANGE); path = malloc(len, M_TEMP, M_WAITOK); bp = &path[len]; bend = bp; *(--bp) = '\0'; /* * 5th argument here is "max number of vnodes to traverse". * Since each entry takes up at least 2 bytes in the output * buffer, limit it to N/2 vnodes for an N byte buffer. */ error = vfs_getcwd_common(p->p_fd->fd_cdir, NULL, &bp, path, len/2, GETCWD_CHECK_ACCESS, p); if (error) goto out; lenused = bend - bp; *retval = lenused; /* Put the result into user buffer */ error = copyout(bp, SCARG(uap, buf), lenused); out: free(path, M_TEMP); return (error); }