From 715baff10ca319398d8285a0ac7c56219dc65fff Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Sun, 8 Jul 1984 23:24:10 -0800 Subject: [PATCH] rework `namei' interface to eliminate global variables SCCS-vsn: sys/kern/kern_proc.c 6.3 SCCS-vsn: sys/kern/kern_sig.c 6.4 SCCS-vsn: sys/kern/vfs_vnops.c 6.2 SCCS-vsn: sys/kern/vfs_syscalls.c 6.11 SCCS-vsn: sys/ufs/ffs/ffs_vnops.c 6.11 SCCS-vsn: sys/ufs/ffs/ufs_vnops.c 6.11 SCCS-vsn: sys/ufs/lfs/lfs_vnops.c 6.11 SCCS-vsn: sys/ufs/ufs/ufs_vnops.c 6.11 SCCS-vsn: sys/kern/vfs_xxx.c 6.2 SCCS-vsn: sys/vm/vm_swap.c 6.2 SCCS-vsn: sys/kern/kern_acct.c 6.2 SCCS-vsn: sys/kern/uipc_usrreq.c 6.5 SCCS-vsn: sys/kern/kern_exec.c 6.3 SCCS-vsn: sys/ufs/ffs/ffs_vfsops.c 6.5 SCCS-vsn: sys/ufs/ffs/ufs_vfsops.c 6.5 SCCS-vsn: sys/ufs/lfs/lfs_vfsops.c 6.5 SCCS-vsn: sys/ufs/ufs/ufs_vfsops.c 6.5 SCCS-vsn: sys/vax/vax/trap.c 6.3 --- usr/src/sys/kern/kern_acct.c | 9 +- usr/src/sys/kern/kern_exec.c | 45 +++--- usr/src/sys/kern/kern_proc.c | 3 +- usr/src/sys/kern/kern_sig.c | 13 +- usr/src/sys/kern/uipc_usrreq.c | 20 +-- usr/src/sys/kern/vfs_syscalls.c | 239 +++++++++++++++++++------------ usr/src/sys/kern/vfs_vnops.c | 12 +- usr/src/sys/kern/vfs_xxx.c | 39 ++--- usr/src/sys/ufs/ffs/ffs_vfsops.c | 40 +++--- usr/src/sys/ufs/ffs/ffs_vnops.c | 239 +++++++++++++++++++------------ usr/src/sys/ufs/ffs/ufs_vfsops.c | 40 +++--- usr/src/sys/ufs/ffs/ufs_vnops.c | 239 +++++++++++++++++++------------ usr/src/sys/ufs/lfs/lfs_vfsops.c | 40 +++--- usr/src/sys/ufs/lfs/lfs_vnops.c | 239 +++++++++++++++++++------------ usr/src/sys/ufs/ufs/ufs_vfsops.c | 40 +++--- usr/src/sys/ufs/ufs/ufs_vnops.c | 239 +++++++++++++++++++------------ usr/src/sys/vax/vax/trap.c | 3 +- usr/src/sys/vm/vm_swap.c | 11 +- 18 files changed, 882 insertions(+), 628 deletions(-) diff --git a/usr/src/sys/kern/kern_acct.c b/usr/src/sys/kern/kern_acct.c index 06d09ad9f7..26b70bde96 100644 --- a/usr/src/sys/kern/kern_acct.c +++ b/usr/src/sys/kern/kern_acct.c @@ -1,4 +1,4 @@ -/* kern_acct.c 6.1 83/07/29 */ +/* kern_acct.c 6.2 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -8,7 +8,6 @@ #include "../h/fs.h" #include "../h/kernel.h" #include "../h/acct.h" -#include "../h/nami.h" #include "../h/uio.h" /* @@ -26,6 +25,7 @@ sysacct() register struct a { char *fname; } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; if (suser()) { if (savacctp) { @@ -39,7 +39,10 @@ sysacct() } return; } - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if(ip == NULL) return; if((ip->i_mode & IFMT) != IFREG) { diff --git a/usr/src/sys/kern/kern_exec.c b/usr/src/sys/kern/kern_exec.c index 6f873653fb..42ff5ffbe3 100644 --- a/usr/src/sys/kern/kern_exec.c +++ b/usr/src/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* kern_exec.c 6.2 83/08/23 */ +/* kern_exec.c 6.3 84/07/08 */ #include "../machine/reg.h" #include "../machine/pte.h" @@ -18,7 +18,6 @@ #include "../h/text.h" #include "../h/file.h" #include "../h/uio.h" -#include "../h/nami.h" #include "../h/acct.h" #ifdef vax @@ -53,9 +52,13 @@ execve() swblk_t bno; char cfname[MAXCOMLEN + 1]; char cfarg[SHSIZE]; + register struct nameidata *ndp = &u.u_nd; int resid; - if ((ip = namei(uchar, LOOKUP, 1)) == NULL) + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = ((struct execa *)u.u_ap)->fname; + if ((ip = namei(ndp)) == NULL) return; bno = 0; bp = 0; @@ -97,9 +100,8 @@ execve() 0, 1, &resid); if (u.u_error) goto bad; - u.u_count = resid; #ifndef lint - if (u.u_count > sizeof(u.u_exdata) - sizeof(u.u_exdata.Ux_A) && + if (resid > sizeof(u.u_exdata) - sizeof(u.u_exdata.Ux_A) && u.u_exdata.ux_shell[0] != '#') { u.u_error = ENOEXEC; goto bad; @@ -144,7 +146,7 @@ execve() cp = &u.u_exdata.ux_shell[2]; while (*cp == ' ') cp++; - u.u_dirp = cp; + ndp->ni_dirp = cp; while (*cp && *cp != ' ') cp++; sharg = NULL; @@ -157,14 +159,16 @@ execve() sharg = cfarg; } } - if (u.u_dent.d_namlen > MAXCOMLEN) - u.u_dent.d_namlen = MAXCOMLEN; - bcopy((caddr_t)u.u_dent.d_name, (caddr_t)cfname, - (unsigned)(u.u_dent.d_namlen + 1)); + if (ndp->ni_dent.d_namlen > MAXCOMLEN) + ndp->ni_dent.d_namlen = MAXCOMLEN; + bcopy((caddr_t)ndp->ni_dent.d_name, (caddr_t)cfname, + (unsigned)(ndp->ni_dent.d_namlen + 1)); cfname[MAXCOMLEN] = 0; indir = 1; iput(ip); - ip = namei(schar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_SYSSPACE; + ip = namei(ndp); if (ip == NULL) return; goto again; @@ -232,9 +236,9 @@ execve() bp = 0; nc = (nc + NBPW-1) & ~(NBPW-1); if (indir) { - u.u_dent.d_namlen = strlen(cfname); - bcopy((caddr_t)cfname, (caddr_t)u.u_dent.d_name, - (unsigned)(u.u_dent.d_namlen + 1)); + ndp->ni_dent.d_namlen = strlen(cfname); + bcopy((caddr_t)cfname, (caddr_t)ndp->ni_dent.d_name, + (unsigned)(ndp->ni_dent.d_namlen + 1)); } getxfile(ip, nc + (na+4)*NBPW, uid, gid); if (u.u_error) { @@ -284,6 +288,12 @@ badarg: } (void) suword((caddr_t)ap, 0); setregs(); + /* + * Remember file name for accounting. + */ + u.u_acflag &= ~AFORK; + bcopy((caddr_t)ndp->ni_dent.d_name, (caddr_t)u.u_comm, + (unsigned)(ndp->ni_dent.d_namlen + 1)); bad: if (bp) brelse(bp); @@ -432,11 +442,4 @@ setregs() } u.u_pofile[i] &= ~UF_MAPPED; } - - /* - * Remember file name for accounting. - */ - u.u_acflag &= ~AFORK; - bcopy((caddr_t)u.u_dent.d_name, (caddr_t)u.u_comm, - (unsigned)(u.u_dent.d_namlen + 1)); } diff --git a/usr/src/sys/kern/kern_proc.c b/usr/src/sys/kern/kern_proc.c index 1584eb8d95..c7a14a2e06 100644 --- a/usr/src/sys/kern/kern_proc.c +++ b/usr/src/sys/kern/kern_proc.c @@ -1,4 +1,4 @@ -/* kern_proc.c 6.2 84/05/22 */ +/* kern_proc.c 6.3 84/07/08 */ #include "../machine/reg.h" #include "../machine/pte.h" @@ -22,7 +22,6 @@ #include "../h/quota.h" #include "../h/uio.h" #include "../h/mbuf.h" -#include "../h/nami.h" spgrp(top, npgrp) register struct proc *top; diff --git a/usr/src/sys/kern/kern_sig.c b/usr/src/sys/kern/kern_sig.c index 912823dcfc..796faf1805 100644 --- a/usr/src/sys/kern/kern_sig.c +++ b/usr/src/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* kern_sig.c 6.3 84/05/22 */ +/* kern_sig.c 6.4 84/07/08 */ #include "../machine/reg.h" #include "../machine/pte.h" @@ -21,7 +21,6 @@ #include "../h/acct.h" #include "../h/uio.h" #include "../h/kernel.h" -#include "../h/nami.h" #define mask(s) (1 << ((s)-1)) #define cantmask (mask(SIGKILL)|mask(SIGCONT)|mask(SIGSTOP)) @@ -736,7 +735,7 @@ psig() core() { register struct inode *ip; - extern schar(); + register struct nameidata *ndp = &u.u_nd; if (u.u_uid != u.u_ruid || u.u_gid != u.u_rgid) return (0); @@ -744,12 +743,14 @@ core() u.u_rlimit[RLIMIT_CORE].rlim_cur) return (0); u.u_error = 0; - u.u_dirp = "core"; - ip = namei(schar, CREATE, 1); + ndp->ni_nameiop = CREATE | FOLLOW; + ndp->ni_segflg = UIO_SYSSPACE; + ndp->ni_dirp = "core"; + ip = namei(ndp); if (ip == NULL) { if (u.u_error) return (0); - ip = maknode(0644); + ip = maknode(0644, ndp); if (ip==NULL) return (0); } diff --git a/usr/src/sys/kern/uipc_usrreq.c b/usr/src/sys/kern/uipc_usrreq.c index 569ec34ef4..dfba23f221 100644 --- a/usr/src/sys/kern/uipc_usrreq.c +++ b/usr/src/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* uipc_usrreq.c 6.4 84/05/02 */ +/* uipc_usrreq.c 6.5 84/07/08 */ #include "../h/param.h" #include "../h/dir.h" @@ -10,7 +10,6 @@ #include "../h/unpcb.h" #include "../h/un.h" #include "../h/inode.h" -#include "../h/nami.h" #include "../h/file.h" /* @@ -274,15 +273,17 @@ unp_bind(unp, nam) { struct sockaddr_un *soun = mtod(nam, struct sockaddr_un *); register struct inode *ip; - extern schar(); + register struct nameidata *ndp = &u.u_nd; int error; - u.u_dirp = soun->sun_path; + ndp->ni_dirp = soun->sun_path; if (nam->m_len == MLEN) return (EINVAL); *(mtod(nam, caddr_t) + nam->m_len) = 0; /* SHOULD BE ABLE TO ADOPT EXISTING AND wakeup() ALA FIFO's */ - ip = namei(schar, CREATE, 1); + ndp->ni_nameiop = CREATE | FOLLOW; + ndp->ni_segflg = UIO_SYSSPACE; + ip = namei(ndp); if (ip) { iput(ip); return (EADDRINUSE); @@ -291,7 +292,7 @@ unp_bind(unp, nam) u.u_error = 0; /* XXX */ return (error); } - ip = maknode(IFSOCK | 0777); + ip = maknode(IFSOCK | 0777, ndp); if (ip == NULL) { error = u.u_error; /* XXX */ u.u_error = 0; /* XXX */ @@ -311,12 +312,15 @@ unp_connect(so, nam) register struct inode *ip; int error; register struct socket *so2; + register struct nameidata *ndp = &u.u_nd; - u.u_dirp = soun->sun_path; + ndp->ni_dirp = soun->sun_path; if (nam->m_len + (nam->m_off - MMINOFF) == MLEN) return (EMSGSIZE); *(mtod(nam, caddr_t) + nam->m_len) = 0; - ip = namei(schar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_SYSSPACE; + ip = namei(ndp); if (ip == 0) { error = u.u_error; u.u_error = 0; diff --git a/usr/src/sys/kern/vfs_syscalls.c b/usr/src/sys/kern/vfs_syscalls.c index b4fc1a95d9..9a4bf4a995 100644 --- a/usr/src/sys/kern/vfs_syscalls.c +++ b/usr/src/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* vfs_syscalls.c 6.10 84/07/04 */ +/* vfs_syscalls.c 6.11 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -15,7 +15,6 @@ #include "../h/uio.h" #include "../h/socket.h" #include "../h/socketvar.h" -#include "../h/nami.h" #include "../h/mount.h" extern struct fileops inodeops; @@ -49,9 +48,13 @@ chdirec(ipp) register struct inode *ip; struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFDIR) { @@ -81,7 +84,7 @@ open() int crtmode; } *uap = (struct a *) u.u_ap; - copen(uap->mode-FOPEN, uap->crtmode); + copen(uap->mode-FOPEN, uap->crtmode, uap->fname); } /* @@ -94,7 +97,7 @@ creat() int fmode; } *uap = (struct a *)u.u_ap; - copen(FWRITE|FCREAT|FTRUNC, uap->fmode); + copen(FWRITE|FCREAT|FTRUNC, uap->fmode, uap->fname); } /* @@ -102,12 +105,14 @@ creat() * Check permissions, allocate an open file structure, * and call the device open routine if any. */ -copen(mode, arg) +copen(mode, arg, fname) register int mode; int arg; + caddr_t fname; { register struct inode *ip; register struct file *fp; + register struct nameidata *ndp = &u.u_nd; int i; #ifdef notdef @@ -116,12 +121,15 @@ copen(mode, arg) return; } #endif + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; if (mode&FCREAT) { - ip = namei(uchar, CREATE, 1); + ndp->ni_nameiop = CREATE | FOLLOW; + ip = namei(ndp); if (ip == NULL) { if (u.u_error) return; - ip = maknode(arg&07777&(~ISVTX)); + ip = maknode(arg&07777&(~ISVTX), ndp); if (ip == NULL) return; mode &= ~FTRUNC; @@ -134,7 +142,8 @@ copen(mode, arg) mode &= ~FCREAT; } } else { - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ip = namei(ndp); if (ip == NULL) return; } @@ -194,19 +203,22 @@ mknod() char *fname; int fmode; int dev; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; if (!suser()) return; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { u.u_error = EEXIST; goto out; } if (u.u_error) return; - ip = maknode(uap->fmode); + ip = maknode(uap->fmode, ndp); if (ip == NULL) return; switch (ip->i_mode & IFMT) { @@ -237,10 +249,13 @@ link() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, 1); /* well, this routine is doomed anyhow */ + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->target; + ip = namei(ndp); /* well, this routine is doomed anyhow */ if (ip == NULL) return; if ((ip->i_mode&IFMT) == IFDIR && !suser()) { @@ -251,8 +266,10 @@ link() ip->i_flag |= ICHG; iupdat(ip, &time, &time, 1); IUNLOCK(ip); - u.u_dirp = (caddr_t)uap->linkname; - xp = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = (caddr_t)uap->linkname; + xp = namei(ndp); if (xp != NULL) { u.u_error = EEXIST; iput(xp); @@ -260,12 +277,12 @@ link() } if (u.u_error) goto out; - if (u.u_pdir->i_dev != ip->i_dev) { - iput(u.u_pdir); + if (ndp->ni_pdir->i_dev != ip->i_dev) { + iput(ndp->ni_pdir); u.u_error = EXDEV; goto out; } - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); out: if (u.u_error) { ip->i_nlink--; @@ -282,12 +299,12 @@ symlink() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register char *tp; register c, nc; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; tp = uap->target; nc = 0; while (c = fubyte(tp)) { @@ -298,8 +315,10 @@ symlink() tp++; nc++; } - u.u_dirp = uap->linkname; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->linkname; + ip = namei(ndp); if (ip) { iput(ip); u.u_error = EEXIST; @@ -307,7 +326,7 @@ symlink() } if (u.u_error) return; - ip = maknode(IFLNK | 0777); + ip = maknode(IFLNK | 0777, ndp); if (ip == NULL) return; u.u_error = rdwri(UIO_WRITE, ip, uap->target, nc, 0, 0, (int *)0); @@ -324,13 +343,17 @@ unlink() { struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) == IFDIR && !suser()) goto out; /* @@ -342,7 +365,7 @@ unlink() } if (ip->i_flag&ITEXT) xrele(ip); /* try once to free text */ - if (dirremove()) { + if (dirremove(ndp)) { ip->i_nlink--; ip->i_flag |= ICHG; } @@ -364,9 +387,8 @@ lseek() int fd; off_t off; int sbase; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; GETF(fp, uap->fd); if (fp->f_type != DTYPE_INODE) { u.u_error = ESPIPE; @@ -403,14 +425,17 @@ saccess() register struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; svuid = u.u_uid; svgid = u.u_gid; u.u_uid = u.u_ruid; u.u_gid = u.u_rgid; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { if ((uap->fmode&R_OK) && access(ip, IREAD)) goto done; @@ -431,7 +456,7 @@ done: stat() { - stat1(1); + stat1(FOLLOW); } /* @@ -440,7 +465,7 @@ stat() lstat() { - stat1(0); + stat1(NOFOLLOW); } stat1(follow) @@ -450,11 +475,14 @@ stat1(follow) register struct a { char *fname; struct stat *ub; - } *uap; + } *uap = (struct a *)u.u_ap; struct stat sb; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, follow); + ndp->ni_nameiop = LOOKUP | follow; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; (void) ino_stat(ip, &sb); @@ -473,9 +501,13 @@ readlink() char *buf; int count; } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; int resid; - ip = namei(uchar, LOOKUP, 0); + ndp->ni_nameiop = LOOKUP; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFLNK) { @@ -497,10 +529,9 @@ chmod() struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; chmod1(ip, uap->fmode); iput(ip); @@ -514,11 +545,10 @@ fchmod() struct a { int fd; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -561,10 +591,9 @@ chown() char *fname; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if (!suser() || (ip = owner(0)) == NULL) + if (!suser() || (ip = owner(uap->fname, NOFOLLOW)) == NULL) return; u.u_error = chown1(ip, uap->uid, uap->gid); iput(ip); @@ -579,11 +608,10 @@ fchown() int fd; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -644,7 +672,7 @@ utimes() register struct inode *ip; struct timeval tv[2]; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; u.u_error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)); if (u.u_error == 0) { @@ -673,8 +701,12 @@ truncate() u_long length; } *uap = (struct a *)u.u_ap; struct inode *ip; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if (access(ip, IWRITE)) @@ -764,22 +796,25 @@ rename() struct a { char *from; char *to; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *xp, *dp; struct inode *zp; int oldparent, parentdifferent, doingdirectory; + register struct nameidata *ndp = &u.u_nd; int error = 0; - uap = (struct a *)u.u_ap; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; oldparent = 0, doingdirectory = 0; if ((ip->i_mode&IFMT) == IFDIR) { register struct direct *d; - d = &u.u_dent; + d = &ndp->ni_dent; /* * Avoid ".", "..", and aliases of "." for obvious reasons. */ @@ -814,13 +849,14 @@ rename() * When the target exists, both the directory * and target inodes are returned locked. */ - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + ndp->ni_nameiop = CREATE | LOCKPARENT | NOCACHE; + ndp->ni_dirp = (caddr_t)uap->to; + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * If ".." must be changed (ie the directory gets a new * parent) then the source directory must not be in the @@ -836,19 +872,18 @@ rename() if (access(ip, IWRITE)) goto bad; do { - dp = u.u_pdir; + dp = ndp->ni_pdir; if (xp != NULL) iput(xp); u.u_error = checkpath(ip, dp); if (u.u_error) goto out; - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - } while (dp != u.u_pdir); + } while (dp != ndp->ni_pdir); } /* * 2) If target doesn't exist, link the target @@ -874,7 +909,7 @@ rename() dp->i_flag |= ICHG; iupdat(dp, &time, &time, 1); } - error = direnter(ip); + error = direnter(ip, ndp); if (error) goto out; } else { @@ -907,7 +942,7 @@ rename() error = EISDIR; goto bad; } - dirrewrite(dp, ip); + dirrewrite(dp, ip, ndp); if (u.u_error) { error = u.u_error; goto bad1; @@ -937,9 +972,11 @@ rename() /* * 3) Unlink the source. */ - u.u_dirp = uap->from; - zp = namei(uchar, DELETE | LOCKPARENT, 0); - dp = u.u_pdir; + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + zp = namei(ndp); + dp = ndp->ni_pdir; /* * Insure directory entry still exists and * has not changed since the start of all @@ -961,7 +998,7 @@ rename() dp->i_nlink--; dp->i_flag |= ICHG; } - if (dirremove()) { + if (dirremove(ndp)) { zp->i_nlink--; zp->i_flag |= ICHG; } @@ -985,13 +1022,15 @@ rename() if (doingdirectory && parentdifferent && error == 0) { struct dirtemplate dirbuf; - u.u_dirp = uap->to; - ip = namei(uchar, LOOKUP | LOCKPARENT, 0); + ndp->ni_nameiop = LOOKUP | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->to; + ip = namei(ndp); if (ip == NULL) { printf("rename: .. went away\n"); return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) != IFDIR) { printf("rename: .. not a directory\n"); goto stuck; @@ -1028,19 +1067,21 @@ done: * Make a new file. */ struct inode * -maknode(mode) +maknode(mode, ndp) int mode; + register struct nameidata *ndp; { register struct inode *ip; + register struct inode *pdir = ndp->ni_pdir; ino_t ipref; if ((mode & IFMT) == IFDIR) - ipref = dirpref(u.u_pdir->i_fs); + ipref = dirpref(pdir->i_fs); else - ipref = u.u_pdir->i_number; - ip = ialloc(u.u_pdir, ipref, mode); + ipref = pdir->i_number; + ip = ialloc(pdir, ipref, mode); if (ip == NULL) { - iput(u.u_pdir); + iput(pdir); return (NULL); } #ifdef QUOTA @@ -1053,7 +1094,7 @@ maknode(mode) ip->i_mode = mode & ~u.u_cmask; ip->i_nlink = 1; ip->i_uid = u.u_uid; - ip->i_gid = u.u_pdir->i_gid; + ip->i_gid = pdir->i_gid; if (ip->i_mode & ISGID && !groupmember(ip->i_gid)) ip->i_mode &= ~ISGID; #ifdef QUOTA @@ -1064,7 +1105,7 @@ maknode(mode) * Make sure inode goes to disk before directory entry. */ iupdat(ip, &time, &time, 1); - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); if (u.u_error) { /* * Write error occurred trying to update directory @@ -1094,12 +1135,15 @@ mkdir() struct a { char *name; int dmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; struct dirtemplate dirtemplate; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (u.u_error) return; if (ip != NULL) { @@ -1107,7 +1151,7 @@ mkdir() u.u_error = EEXIST; return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; uap->dmode &= 0777; uap->dmode |= IFDIR; /* @@ -1165,11 +1209,13 @@ mkdir() * install the entry for it in * the parent directory. */ - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); dp = NULL; if (u.u_error) { - u.u_dirp = uap->name; - dp = namei(uchar, LOOKUP | NOCACHE, 0); + ndp->ni_nameiop = LOOKUP | NOCACHE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + dp = namei(ndp); if (dp) { dp->i_nlink--; dp->i_flag |= ICHG; @@ -1197,13 +1243,17 @@ rmdir() { struct a { char *name; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * No rmdir "." please. */ @@ -1240,7 +1290,7 @@ rmdir() * inode. If we crash in between, the directory * will be reattached to lost+found, */ - if (dirremove() == 0) + if (dirremove(ndp) == 0) goto out; dp->i_nlink--; dp->i_flag |= ICHG; @@ -1289,9 +1339,8 @@ umask() { register struct a { int mask; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; u.u_r.r_val1 = u.u_cmask; u.u_cmask = uap->mask & 07777; } diff --git a/usr/src/sys/kern/vfs_vnops.c b/usr/src/sys/kern/vfs_vnops.c index 4f78e96f7f..3f76e75930 100644 --- a/usr/src/sys/kern/vfs_vnops.c +++ b/usr/src/sys/kern/vfs_vnops.c @@ -1,4 +1,4 @@ -/* vfs_vnops.c 6.1 83/07/29 */ +/* vfs_vnops.c 6.2 84/07/08 */ #include "../machine/reg.h" @@ -15,7 +15,6 @@ #include "../h/socket.h" #include "../h/socketvar.h" #include "../h/proc.h" -#include "../h/nami.h" /* * Check mode permission on inode pointer. @@ -104,12 +103,17 @@ found: * return inode pointer. */ struct inode * -owner(follow) +owner(fname, follow) + caddr_t fname; int follow; { register struct inode *ip; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, follow); + ndp->ni_nameiop = LOOKUP | follow; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; + ip = namei(ndp); if (ip == NULL) return (NULL); if (u.u_uid == ip->i_uid) diff --git a/usr/src/sys/kern/vfs_xxx.c b/usr/src/sys/kern/vfs_xxx.c index c701c186bd..662ecbf9a8 100644 --- a/usr/src/sys/kern/vfs_xxx.c +++ b/usr/src/sys/kern/vfs_xxx.c @@ -1,4 +1,4 @@ -/* vfs_xxx.c 6.1 83/07/29 */ +/* vfs_xxx.c 6.2 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -10,34 +10,8 @@ #include "../h/buf.h" #include "../h/conf.h" -/* - * Return the next character fromt the - * kernel string pointed at by dirp. - */ -schar() -{ - return (*u.u_dirp++ & 0377); -} - -/* - * Return the next character from the - * user string pointed at by dirp. - */ -uchar() -{ - register c; - - c = fubyte(u.u_dirp++); - if (c == -1) { - u.u_error = EFAULT; - c = 0; - } - return (c); -} - #ifdef COMPAT #include "../h/file.h" -#include "../h/nami.h" #include "../h/kernel.h" /* @@ -84,10 +58,13 @@ ostat() register struct a { char *fname; struct ostat *sb; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; ostat1(ip, uap->sb); @@ -132,7 +109,7 @@ outime() time_t tv[2]; struct timeval tv0, tv1; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; u.u_error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)); if (u.u_error == 0) { diff --git a/usr/src/sys/ufs/ffs/ffs_vfsops.c b/usr/src/sys/ufs/ffs/ffs_vfsops.c index 2f2e38e411..5607158902 100644 --- a/usr/src/sys/ufs/ffs/ffs_vfsops.c +++ b/usr/src/sys/ufs/ffs/ffs_vfsops.c @@ -1,4 +1,4 @@ -/* ffs_vfsops.c 6.4 84/06/26 */ +/* ffs_vfsops.c 6.5 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -10,7 +10,6 @@ #include "../h/buf.h" #include "../h/mount.h" #include "../h/file.h" -#include "../h/nami.h" #include "../h/conf.h" smount() @@ -19,18 +18,20 @@ smount() char *fspec; char *freg; int ronly; - } *uap; + } *uap = (struct a *)u.u_ap; dev_t dev; register struct inode *ip; register struct fs *fs; register char *cp; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - u.u_error = getmdev(&dev); + u.u_error = getmdev(&dev, uap->fspec); if (u.u_error) return; - u.u_dirp = (caddr_t)uap->freg; - ip = namei(uchar, LOOKUP | NOCACHE, 1); + ndp->ni_nameiop = LOOKUP | NOCACHE | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = (caddr_t)uap->freg; + ip = namei(ndp); if (ip == NULL) return; if (ip->i_count!=1 || (ip->i_mode&IFMT) != IFDIR) { @@ -41,11 +42,8 @@ smount() fs = mountfs(dev, uap->ronly, ip); if (fs == 0) return; - u.u_dirp = uap->freg; - for (cp = fs->fs_fsmnt; cp < &fs->fs_fsmnt[sizeof(fs->fs_fsmnt) - 2]; ) - if ((*cp++ = uchar()) == 0) - u.u_dirp--; /* get 0 again */ - *cp = 0; + bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); + copyinstr(uap->freg, fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); } /* this routine has races if running twice */ @@ -149,12 +147,13 @@ umount() { struct a { char *fspec; - }; + } *uap = (struct a *)u.u_ap; - u.u_error = unmount1(0); + u.u_error = unmount1(uap->fspec, 0); } -unmount1(forcibly) +unmount1(fname, forcibly) + caddr_t fname; int forcibly; { dev_t dev; @@ -163,7 +162,7 @@ unmount1(forcibly) register struct inode *ip; register struct fs *fs; - error = getmdev(&dev); + error = getmdev(&dev, fname); if (error) return (error); for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) @@ -237,15 +236,20 @@ sbupdate(mp) * Check that the user's argument is a reasonable * thing on which to mount, and return the device number if so. */ -getmdev(pdev) +getmdev(pdev, fname) + caddr_t fname; dev_t *pdev; { dev_t dev; register struct inode *ip; + register struct nameidata *ndp = &u.u_nd; if (!suser()) return (u.u_error); - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; + ip = namei(ndp); if (ip == NULL) return (u.u_error); if ((ip->i_mode&IFMT) != IFBLK) { diff --git a/usr/src/sys/ufs/ffs/ffs_vnops.c b/usr/src/sys/ufs/ffs/ffs_vnops.c index 8aee75d76a..157a7fe307 100644 --- a/usr/src/sys/ufs/ffs/ffs_vnops.c +++ b/usr/src/sys/ufs/ffs/ffs_vnops.c @@ -1,4 +1,4 @@ -/* ffs_vnops.c 6.10 84/07/04 */ +/* ffs_vnops.c 6.11 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -15,7 +15,6 @@ #include "../h/uio.h" #include "../h/socket.h" #include "../h/socketvar.h" -#include "../h/nami.h" #include "../h/mount.h" extern struct fileops inodeops; @@ -49,9 +48,13 @@ chdirec(ipp) register struct inode *ip; struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFDIR) { @@ -81,7 +84,7 @@ open() int crtmode; } *uap = (struct a *) u.u_ap; - copen(uap->mode-FOPEN, uap->crtmode); + copen(uap->mode-FOPEN, uap->crtmode, uap->fname); } /* @@ -94,7 +97,7 @@ creat() int fmode; } *uap = (struct a *)u.u_ap; - copen(FWRITE|FCREAT|FTRUNC, uap->fmode); + copen(FWRITE|FCREAT|FTRUNC, uap->fmode, uap->fname); } /* @@ -102,12 +105,14 @@ creat() * Check permissions, allocate an open file structure, * and call the device open routine if any. */ -copen(mode, arg) +copen(mode, arg, fname) register int mode; int arg; + caddr_t fname; { register struct inode *ip; register struct file *fp; + register struct nameidata *ndp = &u.u_nd; int i; #ifdef notdef @@ -116,12 +121,15 @@ copen(mode, arg) return; } #endif + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; if (mode&FCREAT) { - ip = namei(uchar, CREATE, 1); + ndp->ni_nameiop = CREATE | FOLLOW; + ip = namei(ndp); if (ip == NULL) { if (u.u_error) return; - ip = maknode(arg&07777&(~ISVTX)); + ip = maknode(arg&07777&(~ISVTX), ndp); if (ip == NULL) return; mode &= ~FTRUNC; @@ -134,7 +142,8 @@ copen(mode, arg) mode &= ~FCREAT; } } else { - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ip = namei(ndp); if (ip == NULL) return; } @@ -194,19 +203,22 @@ mknod() char *fname; int fmode; int dev; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; if (!suser()) return; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { u.u_error = EEXIST; goto out; } if (u.u_error) return; - ip = maknode(uap->fmode); + ip = maknode(uap->fmode, ndp); if (ip == NULL) return; switch (ip->i_mode & IFMT) { @@ -237,10 +249,13 @@ link() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, 1); /* well, this routine is doomed anyhow */ + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->target; + ip = namei(ndp); /* well, this routine is doomed anyhow */ if (ip == NULL) return; if ((ip->i_mode&IFMT) == IFDIR && !suser()) { @@ -251,8 +266,10 @@ link() ip->i_flag |= ICHG; iupdat(ip, &time, &time, 1); IUNLOCK(ip); - u.u_dirp = (caddr_t)uap->linkname; - xp = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = (caddr_t)uap->linkname; + xp = namei(ndp); if (xp != NULL) { u.u_error = EEXIST; iput(xp); @@ -260,12 +277,12 @@ link() } if (u.u_error) goto out; - if (u.u_pdir->i_dev != ip->i_dev) { - iput(u.u_pdir); + if (ndp->ni_pdir->i_dev != ip->i_dev) { + iput(ndp->ni_pdir); u.u_error = EXDEV; goto out; } - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); out: if (u.u_error) { ip->i_nlink--; @@ -282,12 +299,12 @@ symlink() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register char *tp; register c, nc; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; tp = uap->target; nc = 0; while (c = fubyte(tp)) { @@ -298,8 +315,10 @@ symlink() tp++; nc++; } - u.u_dirp = uap->linkname; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->linkname; + ip = namei(ndp); if (ip) { iput(ip); u.u_error = EEXIST; @@ -307,7 +326,7 @@ symlink() } if (u.u_error) return; - ip = maknode(IFLNK | 0777); + ip = maknode(IFLNK | 0777, ndp); if (ip == NULL) return; u.u_error = rdwri(UIO_WRITE, ip, uap->target, nc, 0, 0, (int *)0); @@ -324,13 +343,17 @@ unlink() { struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) == IFDIR && !suser()) goto out; /* @@ -342,7 +365,7 @@ unlink() } if (ip->i_flag&ITEXT) xrele(ip); /* try once to free text */ - if (dirremove()) { + if (dirremove(ndp)) { ip->i_nlink--; ip->i_flag |= ICHG; } @@ -364,9 +387,8 @@ lseek() int fd; off_t off; int sbase; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; GETF(fp, uap->fd); if (fp->f_type != DTYPE_INODE) { u.u_error = ESPIPE; @@ -403,14 +425,17 @@ saccess() register struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; svuid = u.u_uid; svgid = u.u_gid; u.u_uid = u.u_ruid; u.u_gid = u.u_rgid; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { if ((uap->fmode&R_OK) && access(ip, IREAD)) goto done; @@ -431,7 +456,7 @@ done: stat() { - stat1(1); + stat1(FOLLOW); } /* @@ -440,7 +465,7 @@ stat() lstat() { - stat1(0); + stat1(NOFOLLOW); } stat1(follow) @@ -450,11 +475,14 @@ stat1(follow) register struct a { char *fname; struct stat *ub; - } *uap; + } *uap = (struct a *)u.u_ap; struct stat sb; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, follow); + ndp->ni_nameiop = LOOKUP | follow; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; (void) ino_stat(ip, &sb); @@ -473,9 +501,13 @@ readlink() char *buf; int count; } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; int resid; - ip = namei(uchar, LOOKUP, 0); + ndp->ni_nameiop = LOOKUP; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFLNK) { @@ -497,10 +529,9 @@ chmod() struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; chmod1(ip, uap->fmode); iput(ip); @@ -514,11 +545,10 @@ fchmod() struct a { int fd; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -561,10 +591,9 @@ chown() char *fname; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if (!suser() || (ip = owner(0)) == NULL) + if (!suser() || (ip = owner(uap->fname, NOFOLLOW)) == NULL) return; u.u_error = chown1(ip, uap->uid, uap->gid); iput(ip); @@ -579,11 +608,10 @@ fchown() int fd; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -644,7 +672,7 @@ utimes() register struct inode *ip; struct timeval tv[2]; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; u.u_error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)); if (u.u_error == 0) { @@ -673,8 +701,12 @@ truncate() u_long length; } *uap = (struct a *)u.u_ap; struct inode *ip; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if (access(ip, IWRITE)) @@ -764,22 +796,25 @@ rename() struct a { char *from; char *to; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *xp, *dp; struct inode *zp; int oldparent, parentdifferent, doingdirectory; + register struct nameidata *ndp = &u.u_nd; int error = 0; - uap = (struct a *)u.u_ap; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; oldparent = 0, doingdirectory = 0; if ((ip->i_mode&IFMT) == IFDIR) { register struct direct *d; - d = &u.u_dent; + d = &ndp->ni_dent; /* * Avoid ".", "..", and aliases of "." for obvious reasons. */ @@ -814,13 +849,14 @@ rename() * When the target exists, both the directory * and target inodes are returned locked. */ - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + ndp->ni_nameiop = CREATE | LOCKPARENT | NOCACHE; + ndp->ni_dirp = (caddr_t)uap->to; + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * If ".." must be changed (ie the directory gets a new * parent) then the source directory must not be in the @@ -836,19 +872,18 @@ rename() if (access(ip, IWRITE)) goto bad; do { - dp = u.u_pdir; + dp = ndp->ni_pdir; if (xp != NULL) iput(xp); u.u_error = checkpath(ip, dp); if (u.u_error) goto out; - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - } while (dp != u.u_pdir); + } while (dp != ndp->ni_pdir); } /* * 2) If target doesn't exist, link the target @@ -874,7 +909,7 @@ rename() dp->i_flag |= ICHG; iupdat(dp, &time, &time, 1); } - error = direnter(ip); + error = direnter(ip, ndp); if (error) goto out; } else { @@ -907,7 +942,7 @@ rename() error = EISDIR; goto bad; } - dirrewrite(dp, ip); + dirrewrite(dp, ip, ndp); if (u.u_error) { error = u.u_error; goto bad1; @@ -937,9 +972,11 @@ rename() /* * 3) Unlink the source. */ - u.u_dirp = uap->from; - zp = namei(uchar, DELETE | LOCKPARENT, 0); - dp = u.u_pdir; + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + zp = namei(ndp); + dp = ndp->ni_pdir; /* * Insure directory entry still exists and * has not changed since the start of all @@ -961,7 +998,7 @@ rename() dp->i_nlink--; dp->i_flag |= ICHG; } - if (dirremove()) { + if (dirremove(ndp)) { zp->i_nlink--; zp->i_flag |= ICHG; } @@ -985,13 +1022,15 @@ rename() if (doingdirectory && parentdifferent && error == 0) { struct dirtemplate dirbuf; - u.u_dirp = uap->to; - ip = namei(uchar, LOOKUP | LOCKPARENT, 0); + ndp->ni_nameiop = LOOKUP | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->to; + ip = namei(ndp); if (ip == NULL) { printf("rename: .. went away\n"); return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) != IFDIR) { printf("rename: .. not a directory\n"); goto stuck; @@ -1028,19 +1067,21 @@ done: * Make a new file. */ struct inode * -maknode(mode) +maknode(mode, ndp) int mode; + register struct nameidata *ndp; { register struct inode *ip; + register struct inode *pdir = ndp->ni_pdir; ino_t ipref; if ((mode & IFMT) == IFDIR) - ipref = dirpref(u.u_pdir->i_fs); + ipref = dirpref(pdir->i_fs); else - ipref = u.u_pdir->i_number; - ip = ialloc(u.u_pdir, ipref, mode); + ipref = pdir->i_number; + ip = ialloc(pdir, ipref, mode); if (ip == NULL) { - iput(u.u_pdir); + iput(pdir); return (NULL); } #ifdef QUOTA @@ -1053,7 +1094,7 @@ maknode(mode) ip->i_mode = mode & ~u.u_cmask; ip->i_nlink = 1; ip->i_uid = u.u_uid; - ip->i_gid = u.u_pdir->i_gid; + ip->i_gid = pdir->i_gid; if (ip->i_mode & ISGID && !groupmember(ip->i_gid)) ip->i_mode &= ~ISGID; #ifdef QUOTA @@ -1064,7 +1105,7 @@ maknode(mode) * Make sure inode goes to disk before directory entry. */ iupdat(ip, &time, &time, 1); - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); if (u.u_error) { /* * Write error occurred trying to update directory @@ -1094,12 +1135,15 @@ mkdir() struct a { char *name; int dmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; struct dirtemplate dirtemplate; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (u.u_error) return; if (ip != NULL) { @@ -1107,7 +1151,7 @@ mkdir() u.u_error = EEXIST; return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; uap->dmode &= 0777; uap->dmode |= IFDIR; /* @@ -1165,11 +1209,13 @@ mkdir() * install the entry for it in * the parent directory. */ - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); dp = NULL; if (u.u_error) { - u.u_dirp = uap->name; - dp = namei(uchar, LOOKUP | NOCACHE, 0); + ndp->ni_nameiop = LOOKUP | NOCACHE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + dp = namei(ndp); if (dp) { dp->i_nlink--; dp->i_flag |= ICHG; @@ -1197,13 +1243,17 @@ rmdir() { struct a { char *name; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * No rmdir "." please. */ @@ -1240,7 +1290,7 @@ rmdir() * inode. If we crash in between, the directory * will be reattached to lost+found, */ - if (dirremove() == 0) + if (dirremove(ndp) == 0) goto out; dp->i_nlink--; dp->i_flag |= ICHG; @@ -1289,9 +1339,8 @@ umask() { register struct a { int mask; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; u.u_r.r_val1 = u.u_cmask; u.u_cmask = uap->mask & 07777; } diff --git a/usr/src/sys/ufs/ffs/ufs_vfsops.c b/usr/src/sys/ufs/ffs/ufs_vfsops.c index 3cee7d1349..2f996b8974 100644 --- a/usr/src/sys/ufs/ffs/ufs_vfsops.c +++ b/usr/src/sys/ufs/ffs/ufs_vfsops.c @@ -1,4 +1,4 @@ -/* ufs_vfsops.c 6.4 84/06/26 */ +/* ufs_vfsops.c 6.5 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -10,7 +10,6 @@ #include "../h/buf.h" #include "../h/mount.h" #include "../h/file.h" -#include "../h/nami.h" #include "../h/conf.h" smount() @@ -19,18 +18,20 @@ smount() char *fspec; char *freg; int ronly; - } *uap; + } *uap = (struct a *)u.u_ap; dev_t dev; register struct inode *ip; register struct fs *fs; register char *cp; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - u.u_error = getmdev(&dev); + u.u_error = getmdev(&dev, uap->fspec); if (u.u_error) return; - u.u_dirp = (caddr_t)uap->freg; - ip = namei(uchar, LOOKUP | NOCACHE, 1); + ndp->ni_nameiop = LOOKUP | NOCACHE | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = (caddr_t)uap->freg; + ip = namei(ndp); if (ip == NULL) return; if (ip->i_count!=1 || (ip->i_mode&IFMT) != IFDIR) { @@ -41,11 +42,8 @@ smount() fs = mountfs(dev, uap->ronly, ip); if (fs == 0) return; - u.u_dirp = uap->freg; - for (cp = fs->fs_fsmnt; cp < &fs->fs_fsmnt[sizeof(fs->fs_fsmnt) - 2]; ) - if ((*cp++ = uchar()) == 0) - u.u_dirp--; /* get 0 again */ - *cp = 0; + bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); + copyinstr(uap->freg, fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); } /* this routine has races if running twice */ @@ -149,12 +147,13 @@ umount() { struct a { char *fspec; - }; + } *uap = (struct a *)u.u_ap; - u.u_error = unmount1(0); + u.u_error = unmount1(uap->fspec, 0); } -unmount1(forcibly) +unmount1(fname, forcibly) + caddr_t fname; int forcibly; { dev_t dev; @@ -163,7 +162,7 @@ unmount1(forcibly) register struct inode *ip; register struct fs *fs; - error = getmdev(&dev); + error = getmdev(&dev, fname); if (error) return (error); for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) @@ -237,15 +236,20 @@ sbupdate(mp) * Check that the user's argument is a reasonable * thing on which to mount, and return the device number if so. */ -getmdev(pdev) +getmdev(pdev, fname) + caddr_t fname; dev_t *pdev; { dev_t dev; register struct inode *ip; + register struct nameidata *ndp = &u.u_nd; if (!suser()) return (u.u_error); - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; + ip = namei(ndp); if (ip == NULL) return (u.u_error); if ((ip->i_mode&IFMT) != IFBLK) { diff --git a/usr/src/sys/ufs/ffs/ufs_vnops.c b/usr/src/sys/ufs/ffs/ufs_vnops.c index 4cf1b76722..71aba2b2a5 100644 --- a/usr/src/sys/ufs/ffs/ufs_vnops.c +++ b/usr/src/sys/ufs/ffs/ufs_vnops.c @@ -1,4 +1,4 @@ -/* ufs_vnops.c 6.10 84/07/04 */ +/* ufs_vnops.c 6.11 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -15,7 +15,6 @@ #include "../h/uio.h" #include "../h/socket.h" #include "../h/socketvar.h" -#include "../h/nami.h" #include "../h/mount.h" extern struct fileops inodeops; @@ -49,9 +48,13 @@ chdirec(ipp) register struct inode *ip; struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFDIR) { @@ -81,7 +84,7 @@ open() int crtmode; } *uap = (struct a *) u.u_ap; - copen(uap->mode-FOPEN, uap->crtmode); + copen(uap->mode-FOPEN, uap->crtmode, uap->fname); } /* @@ -94,7 +97,7 @@ creat() int fmode; } *uap = (struct a *)u.u_ap; - copen(FWRITE|FCREAT|FTRUNC, uap->fmode); + copen(FWRITE|FCREAT|FTRUNC, uap->fmode, uap->fname); } /* @@ -102,12 +105,14 @@ creat() * Check permissions, allocate an open file structure, * and call the device open routine if any. */ -copen(mode, arg) +copen(mode, arg, fname) register int mode; int arg; + caddr_t fname; { register struct inode *ip; register struct file *fp; + register struct nameidata *ndp = &u.u_nd; int i; #ifdef notdef @@ -116,12 +121,15 @@ copen(mode, arg) return; } #endif + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; if (mode&FCREAT) { - ip = namei(uchar, CREATE, 1); + ndp->ni_nameiop = CREATE | FOLLOW; + ip = namei(ndp); if (ip == NULL) { if (u.u_error) return; - ip = maknode(arg&07777&(~ISVTX)); + ip = maknode(arg&07777&(~ISVTX), ndp); if (ip == NULL) return; mode &= ~FTRUNC; @@ -134,7 +142,8 @@ copen(mode, arg) mode &= ~FCREAT; } } else { - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ip = namei(ndp); if (ip == NULL) return; } @@ -194,19 +203,22 @@ mknod() char *fname; int fmode; int dev; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; if (!suser()) return; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { u.u_error = EEXIST; goto out; } if (u.u_error) return; - ip = maknode(uap->fmode); + ip = maknode(uap->fmode, ndp); if (ip == NULL) return; switch (ip->i_mode & IFMT) { @@ -237,10 +249,13 @@ link() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, 1); /* well, this routine is doomed anyhow */ + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->target; + ip = namei(ndp); /* well, this routine is doomed anyhow */ if (ip == NULL) return; if ((ip->i_mode&IFMT) == IFDIR && !suser()) { @@ -251,8 +266,10 @@ link() ip->i_flag |= ICHG; iupdat(ip, &time, &time, 1); IUNLOCK(ip); - u.u_dirp = (caddr_t)uap->linkname; - xp = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = (caddr_t)uap->linkname; + xp = namei(ndp); if (xp != NULL) { u.u_error = EEXIST; iput(xp); @@ -260,12 +277,12 @@ link() } if (u.u_error) goto out; - if (u.u_pdir->i_dev != ip->i_dev) { - iput(u.u_pdir); + if (ndp->ni_pdir->i_dev != ip->i_dev) { + iput(ndp->ni_pdir); u.u_error = EXDEV; goto out; } - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); out: if (u.u_error) { ip->i_nlink--; @@ -282,12 +299,12 @@ symlink() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register char *tp; register c, nc; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; tp = uap->target; nc = 0; while (c = fubyte(tp)) { @@ -298,8 +315,10 @@ symlink() tp++; nc++; } - u.u_dirp = uap->linkname; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->linkname; + ip = namei(ndp); if (ip) { iput(ip); u.u_error = EEXIST; @@ -307,7 +326,7 @@ symlink() } if (u.u_error) return; - ip = maknode(IFLNK | 0777); + ip = maknode(IFLNK | 0777, ndp); if (ip == NULL) return; u.u_error = rdwri(UIO_WRITE, ip, uap->target, nc, 0, 0, (int *)0); @@ -324,13 +343,17 @@ unlink() { struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) == IFDIR && !suser()) goto out; /* @@ -342,7 +365,7 @@ unlink() } if (ip->i_flag&ITEXT) xrele(ip); /* try once to free text */ - if (dirremove()) { + if (dirremove(ndp)) { ip->i_nlink--; ip->i_flag |= ICHG; } @@ -364,9 +387,8 @@ lseek() int fd; off_t off; int sbase; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; GETF(fp, uap->fd); if (fp->f_type != DTYPE_INODE) { u.u_error = ESPIPE; @@ -403,14 +425,17 @@ saccess() register struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; svuid = u.u_uid; svgid = u.u_gid; u.u_uid = u.u_ruid; u.u_gid = u.u_rgid; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { if ((uap->fmode&R_OK) && access(ip, IREAD)) goto done; @@ -431,7 +456,7 @@ done: stat() { - stat1(1); + stat1(FOLLOW); } /* @@ -440,7 +465,7 @@ stat() lstat() { - stat1(0); + stat1(NOFOLLOW); } stat1(follow) @@ -450,11 +475,14 @@ stat1(follow) register struct a { char *fname; struct stat *ub; - } *uap; + } *uap = (struct a *)u.u_ap; struct stat sb; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, follow); + ndp->ni_nameiop = LOOKUP | follow; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; (void) ino_stat(ip, &sb); @@ -473,9 +501,13 @@ readlink() char *buf; int count; } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; int resid; - ip = namei(uchar, LOOKUP, 0); + ndp->ni_nameiop = LOOKUP; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFLNK) { @@ -497,10 +529,9 @@ chmod() struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; chmod1(ip, uap->fmode); iput(ip); @@ -514,11 +545,10 @@ fchmod() struct a { int fd; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -561,10 +591,9 @@ chown() char *fname; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if (!suser() || (ip = owner(0)) == NULL) + if (!suser() || (ip = owner(uap->fname, NOFOLLOW)) == NULL) return; u.u_error = chown1(ip, uap->uid, uap->gid); iput(ip); @@ -579,11 +608,10 @@ fchown() int fd; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -644,7 +672,7 @@ utimes() register struct inode *ip; struct timeval tv[2]; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; u.u_error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)); if (u.u_error == 0) { @@ -673,8 +701,12 @@ truncate() u_long length; } *uap = (struct a *)u.u_ap; struct inode *ip; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if (access(ip, IWRITE)) @@ -764,22 +796,25 @@ rename() struct a { char *from; char *to; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *xp, *dp; struct inode *zp; int oldparent, parentdifferent, doingdirectory; + register struct nameidata *ndp = &u.u_nd; int error = 0; - uap = (struct a *)u.u_ap; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; oldparent = 0, doingdirectory = 0; if ((ip->i_mode&IFMT) == IFDIR) { register struct direct *d; - d = &u.u_dent; + d = &ndp->ni_dent; /* * Avoid ".", "..", and aliases of "." for obvious reasons. */ @@ -814,13 +849,14 @@ rename() * When the target exists, both the directory * and target inodes are returned locked. */ - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + ndp->ni_nameiop = CREATE | LOCKPARENT | NOCACHE; + ndp->ni_dirp = (caddr_t)uap->to; + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * If ".." must be changed (ie the directory gets a new * parent) then the source directory must not be in the @@ -836,19 +872,18 @@ rename() if (access(ip, IWRITE)) goto bad; do { - dp = u.u_pdir; + dp = ndp->ni_pdir; if (xp != NULL) iput(xp); u.u_error = checkpath(ip, dp); if (u.u_error) goto out; - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - } while (dp != u.u_pdir); + } while (dp != ndp->ni_pdir); } /* * 2) If target doesn't exist, link the target @@ -874,7 +909,7 @@ rename() dp->i_flag |= ICHG; iupdat(dp, &time, &time, 1); } - error = direnter(ip); + error = direnter(ip, ndp); if (error) goto out; } else { @@ -907,7 +942,7 @@ rename() error = EISDIR; goto bad; } - dirrewrite(dp, ip); + dirrewrite(dp, ip, ndp); if (u.u_error) { error = u.u_error; goto bad1; @@ -937,9 +972,11 @@ rename() /* * 3) Unlink the source. */ - u.u_dirp = uap->from; - zp = namei(uchar, DELETE | LOCKPARENT, 0); - dp = u.u_pdir; + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + zp = namei(ndp); + dp = ndp->ni_pdir; /* * Insure directory entry still exists and * has not changed since the start of all @@ -961,7 +998,7 @@ rename() dp->i_nlink--; dp->i_flag |= ICHG; } - if (dirremove()) { + if (dirremove(ndp)) { zp->i_nlink--; zp->i_flag |= ICHG; } @@ -985,13 +1022,15 @@ rename() if (doingdirectory && parentdifferent && error == 0) { struct dirtemplate dirbuf; - u.u_dirp = uap->to; - ip = namei(uchar, LOOKUP | LOCKPARENT, 0); + ndp->ni_nameiop = LOOKUP | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->to; + ip = namei(ndp); if (ip == NULL) { printf("rename: .. went away\n"); return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) != IFDIR) { printf("rename: .. not a directory\n"); goto stuck; @@ -1028,19 +1067,21 @@ done: * Make a new file. */ struct inode * -maknode(mode) +maknode(mode, ndp) int mode; + register struct nameidata *ndp; { register struct inode *ip; + register struct inode *pdir = ndp->ni_pdir; ino_t ipref; if ((mode & IFMT) == IFDIR) - ipref = dirpref(u.u_pdir->i_fs); + ipref = dirpref(pdir->i_fs); else - ipref = u.u_pdir->i_number; - ip = ialloc(u.u_pdir, ipref, mode); + ipref = pdir->i_number; + ip = ialloc(pdir, ipref, mode); if (ip == NULL) { - iput(u.u_pdir); + iput(pdir); return (NULL); } #ifdef QUOTA @@ -1053,7 +1094,7 @@ maknode(mode) ip->i_mode = mode & ~u.u_cmask; ip->i_nlink = 1; ip->i_uid = u.u_uid; - ip->i_gid = u.u_pdir->i_gid; + ip->i_gid = pdir->i_gid; if (ip->i_mode & ISGID && !groupmember(ip->i_gid)) ip->i_mode &= ~ISGID; #ifdef QUOTA @@ -1064,7 +1105,7 @@ maknode(mode) * Make sure inode goes to disk before directory entry. */ iupdat(ip, &time, &time, 1); - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); if (u.u_error) { /* * Write error occurred trying to update directory @@ -1094,12 +1135,15 @@ mkdir() struct a { char *name; int dmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; struct dirtemplate dirtemplate; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (u.u_error) return; if (ip != NULL) { @@ -1107,7 +1151,7 @@ mkdir() u.u_error = EEXIST; return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; uap->dmode &= 0777; uap->dmode |= IFDIR; /* @@ -1165,11 +1209,13 @@ mkdir() * install the entry for it in * the parent directory. */ - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); dp = NULL; if (u.u_error) { - u.u_dirp = uap->name; - dp = namei(uchar, LOOKUP | NOCACHE, 0); + ndp->ni_nameiop = LOOKUP | NOCACHE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + dp = namei(ndp); if (dp) { dp->i_nlink--; dp->i_flag |= ICHG; @@ -1197,13 +1243,17 @@ rmdir() { struct a { char *name; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * No rmdir "." please. */ @@ -1240,7 +1290,7 @@ rmdir() * inode. If we crash in between, the directory * will be reattached to lost+found, */ - if (dirremove() == 0) + if (dirremove(ndp) == 0) goto out; dp->i_nlink--; dp->i_flag |= ICHG; @@ -1289,9 +1339,8 @@ umask() { register struct a { int mask; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; u.u_r.r_val1 = u.u_cmask; u.u_cmask = uap->mask & 07777; } diff --git a/usr/src/sys/ufs/lfs/lfs_vfsops.c b/usr/src/sys/ufs/lfs/lfs_vfsops.c index f154e5818f..35a967b06f 100644 --- a/usr/src/sys/ufs/lfs/lfs_vfsops.c +++ b/usr/src/sys/ufs/lfs/lfs_vfsops.c @@ -1,4 +1,4 @@ -/* lfs_vfsops.c 6.4 84/06/26 */ +/* lfs_vfsops.c 6.5 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -10,7 +10,6 @@ #include "../h/buf.h" #include "../h/mount.h" #include "../h/file.h" -#include "../h/nami.h" #include "../h/conf.h" smount() @@ -19,18 +18,20 @@ smount() char *fspec; char *freg; int ronly; - } *uap; + } *uap = (struct a *)u.u_ap; dev_t dev; register struct inode *ip; register struct fs *fs; register char *cp; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - u.u_error = getmdev(&dev); + u.u_error = getmdev(&dev, uap->fspec); if (u.u_error) return; - u.u_dirp = (caddr_t)uap->freg; - ip = namei(uchar, LOOKUP | NOCACHE, 1); + ndp->ni_nameiop = LOOKUP | NOCACHE | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = (caddr_t)uap->freg; + ip = namei(ndp); if (ip == NULL) return; if (ip->i_count!=1 || (ip->i_mode&IFMT) != IFDIR) { @@ -41,11 +42,8 @@ smount() fs = mountfs(dev, uap->ronly, ip); if (fs == 0) return; - u.u_dirp = uap->freg; - for (cp = fs->fs_fsmnt; cp < &fs->fs_fsmnt[sizeof(fs->fs_fsmnt) - 2]; ) - if ((*cp++ = uchar()) == 0) - u.u_dirp--; /* get 0 again */ - *cp = 0; + bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); + copyinstr(uap->freg, fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); } /* this routine has races if running twice */ @@ -149,12 +147,13 @@ umount() { struct a { char *fspec; - }; + } *uap = (struct a *)u.u_ap; - u.u_error = unmount1(0); + u.u_error = unmount1(uap->fspec, 0); } -unmount1(forcibly) +unmount1(fname, forcibly) + caddr_t fname; int forcibly; { dev_t dev; @@ -163,7 +162,7 @@ unmount1(forcibly) register struct inode *ip; register struct fs *fs; - error = getmdev(&dev); + error = getmdev(&dev, fname); if (error) return (error); for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) @@ -237,15 +236,20 @@ sbupdate(mp) * Check that the user's argument is a reasonable * thing on which to mount, and return the device number if so. */ -getmdev(pdev) +getmdev(pdev, fname) + caddr_t fname; dev_t *pdev; { dev_t dev; register struct inode *ip; + register struct nameidata *ndp = &u.u_nd; if (!suser()) return (u.u_error); - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; + ip = namei(ndp); if (ip == NULL) return (u.u_error); if ((ip->i_mode&IFMT) != IFBLK) { diff --git a/usr/src/sys/ufs/lfs/lfs_vnops.c b/usr/src/sys/ufs/lfs/lfs_vnops.c index fd5870a4fe..2239fc5257 100644 --- a/usr/src/sys/ufs/lfs/lfs_vnops.c +++ b/usr/src/sys/ufs/lfs/lfs_vnops.c @@ -1,4 +1,4 @@ -/* lfs_vnops.c 6.10 84/07/04 */ +/* lfs_vnops.c 6.11 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -15,7 +15,6 @@ #include "../h/uio.h" #include "../h/socket.h" #include "../h/socketvar.h" -#include "../h/nami.h" #include "../h/mount.h" extern struct fileops inodeops; @@ -49,9 +48,13 @@ chdirec(ipp) register struct inode *ip; struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFDIR) { @@ -81,7 +84,7 @@ open() int crtmode; } *uap = (struct a *) u.u_ap; - copen(uap->mode-FOPEN, uap->crtmode); + copen(uap->mode-FOPEN, uap->crtmode, uap->fname); } /* @@ -94,7 +97,7 @@ creat() int fmode; } *uap = (struct a *)u.u_ap; - copen(FWRITE|FCREAT|FTRUNC, uap->fmode); + copen(FWRITE|FCREAT|FTRUNC, uap->fmode, uap->fname); } /* @@ -102,12 +105,14 @@ creat() * Check permissions, allocate an open file structure, * and call the device open routine if any. */ -copen(mode, arg) +copen(mode, arg, fname) register int mode; int arg; + caddr_t fname; { register struct inode *ip; register struct file *fp; + register struct nameidata *ndp = &u.u_nd; int i; #ifdef notdef @@ -116,12 +121,15 @@ copen(mode, arg) return; } #endif + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; if (mode&FCREAT) { - ip = namei(uchar, CREATE, 1); + ndp->ni_nameiop = CREATE | FOLLOW; + ip = namei(ndp); if (ip == NULL) { if (u.u_error) return; - ip = maknode(arg&07777&(~ISVTX)); + ip = maknode(arg&07777&(~ISVTX), ndp); if (ip == NULL) return; mode &= ~FTRUNC; @@ -134,7 +142,8 @@ copen(mode, arg) mode &= ~FCREAT; } } else { - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ip = namei(ndp); if (ip == NULL) return; } @@ -194,19 +203,22 @@ mknod() char *fname; int fmode; int dev; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; if (!suser()) return; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { u.u_error = EEXIST; goto out; } if (u.u_error) return; - ip = maknode(uap->fmode); + ip = maknode(uap->fmode, ndp); if (ip == NULL) return; switch (ip->i_mode & IFMT) { @@ -237,10 +249,13 @@ link() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, 1); /* well, this routine is doomed anyhow */ + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->target; + ip = namei(ndp); /* well, this routine is doomed anyhow */ if (ip == NULL) return; if ((ip->i_mode&IFMT) == IFDIR && !suser()) { @@ -251,8 +266,10 @@ link() ip->i_flag |= ICHG; iupdat(ip, &time, &time, 1); IUNLOCK(ip); - u.u_dirp = (caddr_t)uap->linkname; - xp = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = (caddr_t)uap->linkname; + xp = namei(ndp); if (xp != NULL) { u.u_error = EEXIST; iput(xp); @@ -260,12 +277,12 @@ link() } if (u.u_error) goto out; - if (u.u_pdir->i_dev != ip->i_dev) { - iput(u.u_pdir); + if (ndp->ni_pdir->i_dev != ip->i_dev) { + iput(ndp->ni_pdir); u.u_error = EXDEV; goto out; } - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); out: if (u.u_error) { ip->i_nlink--; @@ -282,12 +299,12 @@ symlink() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register char *tp; register c, nc; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; tp = uap->target; nc = 0; while (c = fubyte(tp)) { @@ -298,8 +315,10 @@ symlink() tp++; nc++; } - u.u_dirp = uap->linkname; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->linkname; + ip = namei(ndp); if (ip) { iput(ip); u.u_error = EEXIST; @@ -307,7 +326,7 @@ symlink() } if (u.u_error) return; - ip = maknode(IFLNK | 0777); + ip = maknode(IFLNK | 0777, ndp); if (ip == NULL) return; u.u_error = rdwri(UIO_WRITE, ip, uap->target, nc, 0, 0, (int *)0); @@ -324,13 +343,17 @@ unlink() { struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) == IFDIR && !suser()) goto out; /* @@ -342,7 +365,7 @@ unlink() } if (ip->i_flag&ITEXT) xrele(ip); /* try once to free text */ - if (dirremove()) { + if (dirremove(ndp)) { ip->i_nlink--; ip->i_flag |= ICHG; } @@ -364,9 +387,8 @@ lseek() int fd; off_t off; int sbase; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; GETF(fp, uap->fd); if (fp->f_type != DTYPE_INODE) { u.u_error = ESPIPE; @@ -403,14 +425,17 @@ saccess() register struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; svuid = u.u_uid; svgid = u.u_gid; u.u_uid = u.u_ruid; u.u_gid = u.u_rgid; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { if ((uap->fmode&R_OK) && access(ip, IREAD)) goto done; @@ -431,7 +456,7 @@ done: stat() { - stat1(1); + stat1(FOLLOW); } /* @@ -440,7 +465,7 @@ stat() lstat() { - stat1(0); + stat1(NOFOLLOW); } stat1(follow) @@ -450,11 +475,14 @@ stat1(follow) register struct a { char *fname; struct stat *ub; - } *uap; + } *uap = (struct a *)u.u_ap; struct stat sb; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, follow); + ndp->ni_nameiop = LOOKUP | follow; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; (void) ino_stat(ip, &sb); @@ -473,9 +501,13 @@ readlink() char *buf; int count; } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; int resid; - ip = namei(uchar, LOOKUP, 0); + ndp->ni_nameiop = LOOKUP; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFLNK) { @@ -497,10 +529,9 @@ chmod() struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; chmod1(ip, uap->fmode); iput(ip); @@ -514,11 +545,10 @@ fchmod() struct a { int fd; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -561,10 +591,9 @@ chown() char *fname; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if (!suser() || (ip = owner(0)) == NULL) + if (!suser() || (ip = owner(uap->fname, NOFOLLOW)) == NULL) return; u.u_error = chown1(ip, uap->uid, uap->gid); iput(ip); @@ -579,11 +608,10 @@ fchown() int fd; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -644,7 +672,7 @@ utimes() register struct inode *ip; struct timeval tv[2]; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; u.u_error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)); if (u.u_error == 0) { @@ -673,8 +701,12 @@ truncate() u_long length; } *uap = (struct a *)u.u_ap; struct inode *ip; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if (access(ip, IWRITE)) @@ -764,22 +796,25 @@ rename() struct a { char *from; char *to; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *xp, *dp; struct inode *zp; int oldparent, parentdifferent, doingdirectory; + register struct nameidata *ndp = &u.u_nd; int error = 0; - uap = (struct a *)u.u_ap; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; oldparent = 0, doingdirectory = 0; if ((ip->i_mode&IFMT) == IFDIR) { register struct direct *d; - d = &u.u_dent; + d = &ndp->ni_dent; /* * Avoid ".", "..", and aliases of "." for obvious reasons. */ @@ -814,13 +849,14 @@ rename() * When the target exists, both the directory * and target inodes are returned locked. */ - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + ndp->ni_nameiop = CREATE | LOCKPARENT | NOCACHE; + ndp->ni_dirp = (caddr_t)uap->to; + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * If ".." must be changed (ie the directory gets a new * parent) then the source directory must not be in the @@ -836,19 +872,18 @@ rename() if (access(ip, IWRITE)) goto bad; do { - dp = u.u_pdir; + dp = ndp->ni_pdir; if (xp != NULL) iput(xp); u.u_error = checkpath(ip, dp); if (u.u_error) goto out; - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - } while (dp != u.u_pdir); + } while (dp != ndp->ni_pdir); } /* * 2) If target doesn't exist, link the target @@ -874,7 +909,7 @@ rename() dp->i_flag |= ICHG; iupdat(dp, &time, &time, 1); } - error = direnter(ip); + error = direnter(ip, ndp); if (error) goto out; } else { @@ -907,7 +942,7 @@ rename() error = EISDIR; goto bad; } - dirrewrite(dp, ip); + dirrewrite(dp, ip, ndp); if (u.u_error) { error = u.u_error; goto bad1; @@ -937,9 +972,11 @@ rename() /* * 3) Unlink the source. */ - u.u_dirp = uap->from; - zp = namei(uchar, DELETE | LOCKPARENT, 0); - dp = u.u_pdir; + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + zp = namei(ndp); + dp = ndp->ni_pdir; /* * Insure directory entry still exists and * has not changed since the start of all @@ -961,7 +998,7 @@ rename() dp->i_nlink--; dp->i_flag |= ICHG; } - if (dirremove()) { + if (dirremove(ndp)) { zp->i_nlink--; zp->i_flag |= ICHG; } @@ -985,13 +1022,15 @@ rename() if (doingdirectory && parentdifferent && error == 0) { struct dirtemplate dirbuf; - u.u_dirp = uap->to; - ip = namei(uchar, LOOKUP | LOCKPARENT, 0); + ndp->ni_nameiop = LOOKUP | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->to; + ip = namei(ndp); if (ip == NULL) { printf("rename: .. went away\n"); return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) != IFDIR) { printf("rename: .. not a directory\n"); goto stuck; @@ -1028,19 +1067,21 @@ done: * Make a new file. */ struct inode * -maknode(mode) +maknode(mode, ndp) int mode; + register struct nameidata *ndp; { register struct inode *ip; + register struct inode *pdir = ndp->ni_pdir; ino_t ipref; if ((mode & IFMT) == IFDIR) - ipref = dirpref(u.u_pdir->i_fs); + ipref = dirpref(pdir->i_fs); else - ipref = u.u_pdir->i_number; - ip = ialloc(u.u_pdir, ipref, mode); + ipref = pdir->i_number; + ip = ialloc(pdir, ipref, mode); if (ip == NULL) { - iput(u.u_pdir); + iput(pdir); return (NULL); } #ifdef QUOTA @@ -1053,7 +1094,7 @@ maknode(mode) ip->i_mode = mode & ~u.u_cmask; ip->i_nlink = 1; ip->i_uid = u.u_uid; - ip->i_gid = u.u_pdir->i_gid; + ip->i_gid = pdir->i_gid; if (ip->i_mode & ISGID && !groupmember(ip->i_gid)) ip->i_mode &= ~ISGID; #ifdef QUOTA @@ -1064,7 +1105,7 @@ maknode(mode) * Make sure inode goes to disk before directory entry. */ iupdat(ip, &time, &time, 1); - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); if (u.u_error) { /* * Write error occurred trying to update directory @@ -1094,12 +1135,15 @@ mkdir() struct a { char *name; int dmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; struct dirtemplate dirtemplate; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (u.u_error) return; if (ip != NULL) { @@ -1107,7 +1151,7 @@ mkdir() u.u_error = EEXIST; return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; uap->dmode &= 0777; uap->dmode |= IFDIR; /* @@ -1165,11 +1209,13 @@ mkdir() * install the entry for it in * the parent directory. */ - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); dp = NULL; if (u.u_error) { - u.u_dirp = uap->name; - dp = namei(uchar, LOOKUP | NOCACHE, 0); + ndp->ni_nameiop = LOOKUP | NOCACHE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + dp = namei(ndp); if (dp) { dp->i_nlink--; dp->i_flag |= ICHG; @@ -1197,13 +1243,17 @@ rmdir() { struct a { char *name; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * No rmdir "." please. */ @@ -1240,7 +1290,7 @@ rmdir() * inode. If we crash in between, the directory * will be reattached to lost+found, */ - if (dirremove() == 0) + if (dirremove(ndp) == 0) goto out; dp->i_nlink--; dp->i_flag |= ICHG; @@ -1289,9 +1339,8 @@ umask() { register struct a { int mask; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; u.u_r.r_val1 = u.u_cmask; u.u_cmask = uap->mask & 07777; } diff --git a/usr/src/sys/ufs/ufs/ufs_vfsops.c b/usr/src/sys/ufs/ufs/ufs_vfsops.c index 3cee7d1349..2f996b8974 100644 --- a/usr/src/sys/ufs/ufs/ufs_vfsops.c +++ b/usr/src/sys/ufs/ufs/ufs_vfsops.c @@ -1,4 +1,4 @@ -/* ufs_vfsops.c 6.4 84/06/26 */ +/* ufs_vfsops.c 6.5 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -10,7 +10,6 @@ #include "../h/buf.h" #include "../h/mount.h" #include "../h/file.h" -#include "../h/nami.h" #include "../h/conf.h" smount() @@ -19,18 +18,20 @@ smount() char *fspec; char *freg; int ronly; - } *uap; + } *uap = (struct a *)u.u_ap; dev_t dev; register struct inode *ip; register struct fs *fs; register char *cp; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - u.u_error = getmdev(&dev); + u.u_error = getmdev(&dev, uap->fspec); if (u.u_error) return; - u.u_dirp = (caddr_t)uap->freg; - ip = namei(uchar, LOOKUP | NOCACHE, 1); + ndp->ni_nameiop = LOOKUP | NOCACHE | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = (caddr_t)uap->freg; + ip = namei(ndp); if (ip == NULL) return; if (ip->i_count!=1 || (ip->i_mode&IFMT) != IFDIR) { @@ -41,11 +42,8 @@ smount() fs = mountfs(dev, uap->ronly, ip); if (fs == 0) return; - u.u_dirp = uap->freg; - for (cp = fs->fs_fsmnt; cp < &fs->fs_fsmnt[sizeof(fs->fs_fsmnt) - 2]; ) - if ((*cp++ = uchar()) == 0) - u.u_dirp--; /* get 0 again */ - *cp = 0; + bzero(fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); + copyinstr(uap->freg, fs->fs_fsmnt, sizeof(fs->fs_fsmnt)); } /* this routine has races if running twice */ @@ -149,12 +147,13 @@ umount() { struct a { char *fspec; - }; + } *uap = (struct a *)u.u_ap; - u.u_error = unmount1(0); + u.u_error = unmount1(uap->fspec, 0); } -unmount1(forcibly) +unmount1(fname, forcibly) + caddr_t fname; int forcibly; { dev_t dev; @@ -163,7 +162,7 @@ unmount1(forcibly) register struct inode *ip; register struct fs *fs; - error = getmdev(&dev); + error = getmdev(&dev, fname); if (error) return (error); for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) @@ -237,15 +236,20 @@ sbupdate(mp) * Check that the user's argument is a reasonable * thing on which to mount, and return the device number if so. */ -getmdev(pdev) +getmdev(pdev, fname) + caddr_t fname; dev_t *pdev; { dev_t dev; register struct inode *ip; + register struct nameidata *ndp = &u.u_nd; if (!suser()) return (u.u_error); - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; + ip = namei(ndp); if (ip == NULL) return (u.u_error); if ((ip->i_mode&IFMT) != IFBLK) { diff --git a/usr/src/sys/ufs/ufs/ufs_vnops.c b/usr/src/sys/ufs/ufs/ufs_vnops.c index 4cf1b76722..71aba2b2a5 100644 --- a/usr/src/sys/ufs/ufs/ufs_vnops.c +++ b/usr/src/sys/ufs/ufs/ufs_vnops.c @@ -1,4 +1,4 @@ -/* ufs_vnops.c 6.10 84/07/04 */ +/* ufs_vnops.c 6.11 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -15,7 +15,6 @@ #include "../h/uio.h" #include "../h/socket.h" #include "../h/socketvar.h" -#include "../h/nami.h" #include "../h/mount.h" extern struct fileops inodeops; @@ -49,9 +48,13 @@ chdirec(ipp) register struct inode *ip; struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFDIR) { @@ -81,7 +84,7 @@ open() int crtmode; } *uap = (struct a *) u.u_ap; - copen(uap->mode-FOPEN, uap->crtmode); + copen(uap->mode-FOPEN, uap->crtmode, uap->fname); } /* @@ -94,7 +97,7 @@ creat() int fmode; } *uap = (struct a *)u.u_ap; - copen(FWRITE|FCREAT|FTRUNC, uap->fmode); + copen(FWRITE|FCREAT|FTRUNC, uap->fmode, uap->fname); } /* @@ -102,12 +105,14 @@ creat() * Check permissions, allocate an open file structure, * and call the device open routine if any. */ -copen(mode, arg) +copen(mode, arg, fname) register int mode; int arg; + caddr_t fname; { register struct inode *ip; register struct file *fp; + register struct nameidata *ndp = &u.u_nd; int i; #ifdef notdef @@ -116,12 +121,15 @@ copen(mode, arg) return; } #endif + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = fname; if (mode&FCREAT) { - ip = namei(uchar, CREATE, 1); + ndp->ni_nameiop = CREATE | FOLLOW; + ip = namei(ndp); if (ip == NULL) { if (u.u_error) return; - ip = maknode(arg&07777&(~ISVTX)); + ip = maknode(arg&07777&(~ISVTX), ndp); if (ip == NULL) return; mode &= ~FTRUNC; @@ -134,7 +142,8 @@ copen(mode, arg) mode &= ~FCREAT; } } else { - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ip = namei(ndp); if (ip == NULL) return; } @@ -194,19 +203,22 @@ mknod() char *fname; int fmode; int dev; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; if (!suser()) return; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { u.u_error = EEXIST; goto out; } if (u.u_error) return; - ip = maknode(uap->fmode); + ip = maknode(uap->fmode, ndp); if (ip == NULL) return; switch (ip->i_mode & IFMT) { @@ -237,10 +249,13 @@ link() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, 1); /* well, this routine is doomed anyhow */ + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->target; + ip = namei(ndp); /* well, this routine is doomed anyhow */ if (ip == NULL) return; if ((ip->i_mode&IFMT) == IFDIR && !suser()) { @@ -251,8 +266,10 @@ link() ip->i_flag |= ICHG; iupdat(ip, &time, &time, 1); IUNLOCK(ip); - u.u_dirp = (caddr_t)uap->linkname; - xp = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = (caddr_t)uap->linkname; + xp = namei(ndp); if (xp != NULL) { u.u_error = EEXIST; iput(xp); @@ -260,12 +277,12 @@ link() } if (u.u_error) goto out; - if (u.u_pdir->i_dev != ip->i_dev) { - iput(u.u_pdir); + if (ndp->ni_pdir->i_dev != ip->i_dev) { + iput(ndp->ni_pdir); u.u_error = EXDEV; goto out; } - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); out: if (u.u_error) { ip->i_nlink--; @@ -282,12 +299,12 @@ symlink() register struct a { char *target; char *linkname; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register char *tp; register c, nc; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; tp = uap->target; nc = 0; while (c = fubyte(tp)) { @@ -298,8 +315,10 @@ symlink() tp++; nc++; } - u.u_dirp = uap->linkname; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->linkname; + ip = namei(ndp); if (ip) { iput(ip); u.u_error = EEXIST; @@ -307,7 +326,7 @@ symlink() } if (u.u_error) return; - ip = maknode(IFLNK | 0777); + ip = maknode(IFLNK | 0777, ndp); if (ip == NULL) return; u.u_error = rdwri(UIO_WRITE, ip, uap->target, nc, 0, 0, (int *)0); @@ -324,13 +343,17 @@ unlink() { struct a { char *fname; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) == IFDIR && !suser()) goto out; /* @@ -342,7 +365,7 @@ unlink() } if (ip->i_flag&ITEXT) xrele(ip); /* try once to free text */ - if (dirremove()) { + if (dirremove(ndp)) { ip->i_nlink--; ip->i_flag |= ICHG; } @@ -364,9 +387,8 @@ lseek() int fd; off_t off; int sbase; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; GETF(fp, uap->fd); if (fp->f_type != DTYPE_INODE) { u.u_error = ESPIPE; @@ -403,14 +425,17 @@ saccess() register struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; svuid = u.u_uid; svgid = u.u_gid; u.u_uid = u.u_ruid; u.u_gid = u.u_rgid; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip != NULL) { if ((uap->fmode&R_OK) && access(ip, IREAD)) goto done; @@ -431,7 +456,7 @@ done: stat() { - stat1(1); + stat1(FOLLOW); } /* @@ -440,7 +465,7 @@ stat() lstat() { - stat1(0); + stat1(NOFOLLOW); } stat1(follow) @@ -450,11 +475,14 @@ stat1(follow) register struct a { char *fname; struct stat *ub; - } *uap; + } *uap = (struct a *)u.u_ap; struct stat sb; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, LOOKUP, follow); + ndp->ni_nameiop = LOOKUP | follow; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; (void) ino_stat(ip, &sb); @@ -473,9 +501,13 @@ readlink() char *buf; int count; } *uap = (struct a *)u.u_ap; + register struct nameidata *ndp = &u.u_nd; int resid; - ip = namei(uchar, LOOKUP, 0); + ndp->ni_nameiop = LOOKUP; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFLNK) { @@ -497,10 +529,9 @@ chmod() struct a { char *fname; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; chmod1(ip, uap->fmode); iput(ip); @@ -514,11 +545,10 @@ fchmod() struct a { int fd; int fmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -561,10 +591,9 @@ chown() char *fname; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; - if (!suser() || (ip = owner(0)) == NULL) + if (!suser() || (ip = owner(uap->fname, NOFOLLOW)) == NULL) return; u.u_error = chown1(ip, uap->uid, uap->gid); iput(ip); @@ -579,11 +608,10 @@ fchown() int fd; int uid; int gid; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip; register struct file *fp; - uap = (struct a *)u.u_ap; fp = getinode(uap->fd); if (fp == NULL) return; @@ -644,7 +672,7 @@ utimes() register struct inode *ip; struct timeval tv[2]; - if ((ip = owner(1)) == NULL) + if ((ip = owner(uap->fname, FOLLOW)) == NULL) return; u.u_error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)); if (u.u_error == 0) { @@ -673,8 +701,12 @@ truncate() u_long length; } *uap = (struct a *)u.u_ap; struct inode *ip; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->fname; + ip = namei(ndp); if (ip == NULL) return; if (access(ip, IWRITE)) @@ -764,22 +796,25 @@ rename() struct a { char *from; char *to; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *xp, *dp; struct inode *zp; int oldparent, parentdifferent, doingdirectory; + register struct nameidata *ndp = &u.u_nd; int error = 0; - uap = (struct a *)u.u_ap; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; oldparent = 0, doingdirectory = 0; if ((ip->i_mode&IFMT) == IFDIR) { register struct direct *d; - d = &u.u_dent; + d = &ndp->ni_dent; /* * Avoid ".", "..", and aliases of "." for obvious reasons. */ @@ -814,13 +849,14 @@ rename() * When the target exists, both the directory * and target inodes are returned locked. */ - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + ndp->ni_nameiop = CREATE | LOCKPARENT | NOCACHE; + ndp->ni_dirp = (caddr_t)uap->to; + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * If ".." must be changed (ie the directory gets a new * parent) then the source directory must not be in the @@ -836,19 +872,18 @@ rename() if (access(ip, IWRITE)) goto bad; do { - dp = u.u_pdir; + dp = ndp->ni_pdir; if (xp != NULL) iput(xp); u.u_error = checkpath(ip, dp); if (u.u_error) goto out; - u.u_dirp = (caddr_t)uap->to; - xp = namei(uchar, CREATE | LOCKPARENT | NOCACHE, 0); + xp = namei(ndp); if (u.u_error) { error = u.u_error; goto out; } - } while (dp != u.u_pdir); + } while (dp != ndp->ni_pdir); } /* * 2) If target doesn't exist, link the target @@ -874,7 +909,7 @@ rename() dp->i_flag |= ICHG; iupdat(dp, &time, &time, 1); } - error = direnter(ip); + error = direnter(ip, ndp); if (error) goto out; } else { @@ -907,7 +942,7 @@ rename() error = EISDIR; goto bad; } - dirrewrite(dp, ip); + dirrewrite(dp, ip, ndp); if (u.u_error) { error = u.u_error; goto bad1; @@ -937,9 +972,11 @@ rename() /* * 3) Unlink the source. */ - u.u_dirp = uap->from; - zp = namei(uchar, DELETE | LOCKPARENT, 0); - dp = u.u_pdir; + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->from; + zp = namei(ndp); + dp = ndp->ni_pdir; /* * Insure directory entry still exists and * has not changed since the start of all @@ -961,7 +998,7 @@ rename() dp->i_nlink--; dp->i_flag |= ICHG; } - if (dirremove()) { + if (dirremove(ndp)) { zp->i_nlink--; zp->i_flag |= ICHG; } @@ -985,13 +1022,15 @@ rename() if (doingdirectory && parentdifferent && error == 0) { struct dirtemplate dirbuf; - u.u_dirp = uap->to; - ip = namei(uchar, LOOKUP | LOCKPARENT, 0); + ndp->ni_nameiop = LOOKUP | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->to; + ip = namei(ndp); if (ip == NULL) { printf("rename: .. went away\n"); return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; if ((ip->i_mode&IFMT) != IFDIR) { printf("rename: .. not a directory\n"); goto stuck; @@ -1028,19 +1067,21 @@ done: * Make a new file. */ struct inode * -maknode(mode) +maknode(mode, ndp) int mode; + register struct nameidata *ndp; { register struct inode *ip; + register struct inode *pdir = ndp->ni_pdir; ino_t ipref; if ((mode & IFMT) == IFDIR) - ipref = dirpref(u.u_pdir->i_fs); + ipref = dirpref(pdir->i_fs); else - ipref = u.u_pdir->i_number; - ip = ialloc(u.u_pdir, ipref, mode); + ipref = pdir->i_number; + ip = ialloc(pdir, ipref, mode); if (ip == NULL) { - iput(u.u_pdir); + iput(pdir); return (NULL); } #ifdef QUOTA @@ -1053,7 +1094,7 @@ maknode(mode) ip->i_mode = mode & ~u.u_cmask; ip->i_nlink = 1; ip->i_uid = u.u_uid; - ip->i_gid = u.u_pdir->i_gid; + ip->i_gid = pdir->i_gid; if (ip->i_mode & ISGID && !groupmember(ip->i_gid)) ip->i_mode &= ~ISGID; #ifdef QUOTA @@ -1064,7 +1105,7 @@ maknode(mode) * Make sure inode goes to disk before directory entry. */ iupdat(ip, &time, &time, 1); - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); if (u.u_error) { /* * Write error occurred trying to update directory @@ -1094,12 +1135,15 @@ mkdir() struct a { char *name; int dmode; - } *uap; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; struct dirtemplate dirtemplate; + register struct nameidata *ndp = &u.u_nd; - uap = (struct a *)u.u_ap; - ip = namei(uchar, CREATE, 0); + ndp->ni_nameiop = CREATE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (u.u_error) return; if (ip != NULL) { @@ -1107,7 +1151,7 @@ mkdir() u.u_error = EEXIST; return; } - dp = u.u_pdir; + dp = ndp->ni_pdir; uap->dmode &= 0777; uap->dmode |= IFDIR; /* @@ -1165,11 +1209,13 @@ mkdir() * install the entry for it in * the parent directory. */ - u.u_error = direnter(ip); + u.u_error = direnter(ip, ndp); dp = NULL; if (u.u_error) { - u.u_dirp = uap->name; - dp = namei(uchar, LOOKUP | NOCACHE, 0); + ndp->ni_nameiop = LOOKUP | NOCACHE; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + dp = namei(ndp); if (dp) { dp->i_nlink--; dp->i_flag |= ICHG; @@ -1197,13 +1243,17 @@ rmdir() { struct a { char *name; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip, *dp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, DELETE | LOCKPARENT, 0); + ndp->ni_nameiop = DELETE | LOCKPARENT; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; - dp = u.u_pdir; + dp = ndp->ni_pdir; /* * No rmdir "." please. */ @@ -1240,7 +1290,7 @@ rmdir() * inode. If we crash in between, the directory * will be reattached to lost+found, */ - if (dirremove() == 0) + if (dirremove(ndp) == 0) goto out; dp->i_nlink--; dp->i_flag |= ICHG; @@ -1289,9 +1339,8 @@ umask() { register struct a { int mask; - } *uap; + } *uap = (struct a *)u.u_ap; - uap = (struct a *)u.u_ap; u.u_r.r_val1 = u.u_cmask; u.u_cmask = uap->mask & 07777; } diff --git a/usr/src/sys/vax/vax/trap.c b/usr/src/sys/vax/vax/trap.c index 10e85e132c..bf4b02ba6a 100644 --- a/usr/src/sys/vax/vax/trap.c +++ b/usr/src/sys/vax/vax/trap.c @@ -1,4 +1,4 @@ -/* trap.c 6.2 84/06/10 */ +/* trap.c 6.3 84/07/08 */ #include "../machine/psl.h" #include "../machine/reg.h" @@ -218,7 +218,6 @@ asm("ok:"); /* GROT */ #endif } u.u_ap = u.u_arg; - u.u_dirp = (caddr_t)u.u_arg[0]; u.u_r.r_val1 = 0; u.u_r.r_val2 = locr0[R1]; if (setjmp(&u.u_qsave)) { diff --git a/usr/src/sys/vm/vm_swap.c b/usr/src/sys/vm/vm_swap.c index e5fa69677e..fc349272c2 100644 --- a/usr/src/sys/vm/vm_swap.c +++ b/usr/src/sys/vm/vm_swap.c @@ -1,4 +1,4 @@ -/* vm_swap.c 6.1 83/07/29 */ +/* vm_swap.c 6.2 84/07/08 */ #include "../h/param.h" #include "../h/systm.h" @@ -10,7 +10,6 @@ #include "../h/map.h" #include "../h/uio.h" #include "../h/file.h" -#include "../h/nami.h" struct buf rswbuf; /* @@ -83,12 +82,16 @@ swapon() { struct a { char *name; - }; + } *uap = (struct a *)u.u_ap; register struct inode *ip; dev_t dev; register struct swdevt *sp; + register struct nameidata *ndp = &u.u_nd; - ip = namei(uchar, LOOKUP, 1); + ndp->ni_nameiop = LOOKUP | FOLLOW; + ndp->ni_segflg = UIO_USERSPACE; + ndp->ni_dirp = uap->name; + ip = namei(ndp); if (ip == NULL) return; if ((ip->i_mode&IFMT) != IFBLK) { -- 2.20.1