+unmount()
+{
+ struct a {
+ char *pathp;
+ int flags;
+ } *uap = (struct a *)u.u_ap;
+ register struct vnode *vp;
+ register struct mount *mp;
+ register struct nameidata *ndp = &u.u_nd;
+ struct vnode *coveredvp;
+ int error;
+
+ /*
+ * Must be super user
+ */
+ if (error = suser(u.u_cred, &u.u_acflag))
+ RETURN (error);
+
+ ndp->ni_nameiop = LOOKUP | LOCKLEAF | FOLLOW;
+ ndp->ni_segflg = UIO_USERSPACE;
+ ndp->ni_dirp = uap->pathp;
+ if (error = namei(ndp))
+ RETURN (error);
+ vp = ndp->ni_vp;
+ /*
+ * Must be the root of the filesystem
+ */
+ if ((vp->v_flag & VROOT) == 0) {
+ vput(vp);
+ RETURN (EINVAL);
+ }
+ mp = vp->v_mount;
+ vput(vp);
+ /*
+ * Do the unmount.
+ */
+ coveredvp = mp->m_vnodecovered;
+ if (error = vfs_lock(mp))
+ RETURN (error);
+
+ xumount(mp); /* remove unused sticky files from text table */
+ cache_purgevfs(mp); /* remove cache entries for this file sys */
+ VFS_SYNC(mp, MNT_WAIT);
+
+ error = VFS_UNMOUNT(mp, uap->flags);
+ if (error) {
+ vfs_unlock(mp);
+ } else {
+ vrele(coveredvp);
+ vfs_remove(mp);
+ free((caddr_t)mp, M_MOUNT);
+ }
+ RETURN (error);
+}
+
+/*
+ * Sync system call.
+ * Sync each mounted filesystem.
+ */
+sync()
+{
+ register struct mount *mp;
+
+ mp = rootfs;
+ do {
+ if ((mp->m_flag & M_RDONLY) == 0)
+ VFS_SYNC(mp, MNT_NOWAIT);
+ mp = mp->m_next;
+ } while (mp != rootfs);
+}
+
+/*
+ * get filesystem statistics
+ */
+statfs()
+{
+ struct a {
+ char *path;
+ struct statfs *buf;
+ } *uap = (struct a *)u.u_ap;
+ register struct vnode *vp;
+ register struct nameidata *ndp = &u.u_nd;
+ struct statfs sb;
+ int error;
+
+ ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
+ ndp->ni_segflg = UIO_USERSPACE;
+ ndp->ni_dirp = uap->path;
+ if (error = namei(ndp))
+ RETURN (error);
+ vp = ndp->ni_vp;
+ if (error = VFS_STATFS(vp->v_mount, &sb))
+ goto out;
+ error = copyout((caddr_t)&sb, (caddr_t)uap->buf, sizeof(sb));
+out:
+ vput(vp);
+ RETURN (error);
+}
+
+fstatfs()
+{
+ struct a {
+ int fd;
+ struct statfs *buf;
+ } *uap = (struct a *)u.u_ap;
+ struct file *fp;
+ struct statfs sb;
+ int error;
+
+ if (error = getvnode(uap->fd, &fp))
+ RETURN (error);
+ if (error = VFS_STATFS(((struct vnode *)fp->f_data)->v_mount, &sb))
+ RETURN (error);
+ RETURN (copyout((caddr_t)&sb, (caddr_t)uap->buf, sizeof(sb)));
+}
+
+/*
+ * get statistics on all filesystems
+ */
+getfsstat()
+{
+ struct a {
+ struct statfs *buf;
+ long bufsize;
+ } *uap = (struct a *)u.u_ap;
+ register struct mount *mp;
+ register struct statfs *sfsp;
+ long count, maxcount, error;
+
+ maxcount = uap->bufsize / sizeof(struct statfs);
+ sfsp = uap->buf;
+ mp = rootfs;
+ count = 0;
+ do {
+ count++;
+ if (sfsp && count <= maxcount) {
+ if (error = VFS_STATFS(mp, sfsp))
+ RETURN (error);
+ sfsp++;
+ }
+ mp = mp->m_prev;
+ } while (mp != rootfs);
+ if (sfsp && count > maxcount)
+ u.u_r.r_val1 = maxcount;
+ else
+ u.u_r.r_val1 = count;
+ RETURN (0);
+}
+
+/*
+ * Change current working directory to a given file descriptor.
+ */
+fchdir()
+{
+ struct a {
+ int fd;
+ } *uap = (struct a *)u.u_ap;
+ register struct vnode *vp;
+ struct file *fp;
+ int error;
+
+ if (error = getvnode(uap->fd, &fp))
+ RETURN (error);
+ vp = (struct vnode *)fp->f_data;
+ VOP_LOCK(vp);
+ if (vp->v_type != VDIR)
+ error = ENOTDIR;
+ else
+ error = VOP_ACCESS(vp, VEXEC, u.u_cred);
+ VOP_UNLOCK(vp);
+ vrele(u.u_cdir);
+ u.u_cdir = vp;
+ RETURN (error);
+}
+
+/*
+ * Change current working directory (``.'').
+ */
+chdir()
+{
+ struct a {
+ char *fname;
+ } *uap = (struct a *)u.u_ap;
+ register struct nameidata *ndp = &u.u_nd;
+ int error;
+
+ ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
+ ndp->ni_segflg = UIO_USERSPACE;
+ ndp->ni_dirp = uap->fname;
+ if (error = chdirec(ndp))
+ RETURN (error);
+ vrele(u.u_cdir);
+ u.u_cdir = ndp->ni_vp;
+ RETURN (0);
+}
+
+/*
+ * Change notion of root (``/'') directory.
+ */
+chroot()
+{
+ struct a {
+ char *fname;
+ } *uap = (struct a *)u.u_ap;
+ register struct nameidata *ndp = &u.u_nd;
+ int error;
+
+ if (error = suser(u.u_cred, &u.u_acflag))
+ RETURN (error);
+ ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
+ ndp->ni_segflg = UIO_USERSPACE;
+ ndp->ni_dirp = uap->fname;
+ if (error = chdirec(ndp))
+ RETURN (error);
+ vrele(u.u_rdir);
+ u.u_rdir = ndp->ni_vp;
+ RETURN (0);
+}
+
+/*
+ * Common routine for chroot and chdir.
+ */
+chdirec(ndp)
+ register struct nameidata *ndp;
+{
+ struct vnode *vp;
+ int error;
+
+ if (error = namei(ndp))
+ return (error);
+ vp = ndp->ni_vp;
+ if (vp->v_type != VDIR)
+ error = ENOTDIR;
+ else
+ error = VOP_ACCESS(vp, VEXEC, ndp->ni_cred);
+ VOP_UNLOCK(vp);
+ if (error)
+ vrele(vp);
+ return (error);
+}
+
+/*
+ * Open system call.
+ */
+open()
+{
+ struct a {
+ char *fname;
+ int mode;
+ int crtmode;
+ } *uap = (struct a *) u.u_ap;
+ struct nameidata *ndp = &u.u_nd;
+
+ ndp->ni_segflg = UIO_USERSPACE;
+ ndp->ni_dirp = uap->fname;
+ RETURN (copen(uap->mode-FOPEN, uap->crtmode &~ u.u_cmask, ndp,
+ &u.u_r.r_val1));
+}
+
+/*
+ * Creat system call.
+ */
+creat()
+{
+ struct a {
+ char *fname;
+ int fmode;
+ } *uap = (struct a *)u.u_ap;
+ struct nameidata *ndp = &u.u_nd;
+
+ ndp->ni_segflg = UIO_USERSPACE;
+ ndp->ni_dirp = uap->fname;
+ RETURN (copen(FWRITE|FCREAT|FTRUNC, uap->fmode &~ u.u_cmask, ndp,
+ &u.u_r.r_val1));
+}
+
+/*
+ * Common code for open and creat.
+ * Check permissions, allocate an open file structure,
+ * and call the device open routine if any.
+ */
+copen(fmode, cmode, ndp, resultfd)
+ int fmode, cmode;
+ struct nameidata *ndp;
+ int *resultfd;
+{
+ register struct file *fp;
+ struct file *nfp;
+ int indx, error;
+ extern struct fileops vnops;
+
+ if (error = falloc(&nfp, &indx))
+ return (error);
+ fp = nfp;
+ u.u_r.r_val1 = indx; /* XXX for fdopen() */
+ if (error = vn_open(ndp, fmode, (cmode & 07777) &~ ISVTX)) {
+ u.u_ofile[indx] = NULL;
+ crfree(fp->f_cred);
+ fp->f_count--;
+ return (error);
+ }
+ fp->f_flag = fmode & FMASK;
+ fp->f_type = DTYPE_VNODE;
+ fp->f_ops = &vnops;
+ fp->f_data = (caddr_t)ndp->ni_vp;
+ if (resultfd)
+ *resultfd = indx;
+ return (0);
+}
+
+/*
+ * Mknod system call
+ */
+mknod()