+dounmount(mp, flags)
+ register struct mount *mp;
+ int flags;
+{
+ struct vnode *coveredvp;
+ int error;
+
+ 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, 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.
+ */
+/* ARGSUSED */
+sync(scp)
+ struct syscontext *scp;
+{
+ register struct mount *mp;
+
+ mp = rootfs;
+ do {
+ /*
+ * The lock check below is to avoid races with mount
+ * and unmount.
+ */
+ if ((mp->m_flag & (M_MLOCK|M_RDONLY)) == 0)
+ VFS_SYNC(mp, MNT_NOWAIT);
+ mp = mp->m_next;
+ } while (mp != rootfs);
+}
+
+/*
+ * get filesystem statistics
+ */
+statfs(scp)
+ register struct syscontext *scp;
+{
+ struct a {
+ char *path;
+ struct statfs *buf;
+ } *uap = (struct a *)scp->sc_ap;
+ register struct mount *mp;
+ register struct nameidata *ndp = &scp->sc_nd;
+ register struct statfs *sp;
+ int error;
+
+ ndp->ni_nameiop = LOOKUP | FOLLOW;
+ ndp->ni_segflg = UIO_USERSPACE;
+ ndp->ni_dirp = uap->path;
+ if (error = namei(ndp))
+ RETURN (error);
+ mp = ndp->ni_vp->v_mount;
+ sp = &mp->m_stat;
+ vrele(ndp->ni_vp);
+ if (error = VFS_STATFS(mp, sp))
+ RETURN (error);
+ sp->f_flags = mp->m_flag & M_VISFLAGMASK;
+ RETURN (copyout((caddr_t)sp, (caddr_t)uap->buf, sizeof(*sp)));
+}
+
+fstatfs(scp)
+ register struct syscontext *scp;
+{
+ struct a {
+ int fd;
+ struct statfs *buf;
+ } *uap = (struct a *)scp->sc_ap;
+ struct file *fp;
+ struct mount *mp;
+ register struct statfs *sp;
+ int error;
+
+ if (error = getvnode(scp->sc_ofile, uap->fd, &fp))
+ RETURN (error);
+ mp = ((struct vnode *)fp->f_data)->v_mount;
+ sp = &mp->m_stat;
+ if (error = VFS_STATFS(mp, sp))
+ RETURN (error);
+ sp->f_flags = mp->m_flag & M_VISFLAGMASK;
+ RETURN (copyout((caddr_t)sp, (caddr_t)uap->buf, sizeof(*sp)));
+}
+
+/*
+ * get statistics on all filesystems
+ */
+getfsstat(scp)
+ register struct syscontext *scp;
+{
+ struct a {
+ struct statfs *buf;
+ long bufsize;
+ int flags;
+ } *uap = (struct a *)scp->sc_ap;
+ register struct mount *mp;
+ register struct statfs *sp;
+ caddr_t sfsp;
+ long count, maxcount, error;
+
+ maxcount = uap->bufsize / sizeof(struct statfs);
+ sfsp = (caddr_t)uap->buf;
+ mp = rootfs;
+ count = 0;
+ do {
+ if (sfsp && count < maxcount && ((mp->m_flag & M_MLOCK) == 0)) {
+ sp = &mp->m_stat;
+ /*
+ * If MNT_NOWAIT is specified, do not refresh the
+ * fsstat cache. MNT_WAIT overrides MNT_NOWAIT.
+ */
+ if (((uap->flags & MNT_NOWAIT) == 0 ||
+ (uap->flags & MNT_WAIT)) &&
+ (error = VFS_STATFS(mp, sp))) {
+ mp = mp->m_prev;
+ continue;
+ }
+ sp->f_flags = mp->m_flag & M_VISFLAGMASK;
+ if (error = copyout((caddr_t)sp, sfsp, sizeof(*sp)))
+ RETURN (error);
+ sfsp += sizeof(*sp);
+ }
+ count++;
+ mp = mp->m_prev;
+ } while (mp != rootfs);
+ if (sfsp && count > maxcount)
+ scp->sc_retval1 = maxcount;
+ else
+ scp->sc_retval1 = count;
+ RETURN (0);
+}
+
+/*
+ * Change current working directory to a given file descriptor.
+ */
+fchdir(scp)
+ register struct syscontext *scp;
+{
+ struct a {
+ int fd;
+ } *uap = (struct a *)scp->sc_ap;
+ register struct vnode *vp;
+ struct file *fp;
+ int error;
+
+ if (error = getvnode(scp->sc_ofile, 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, scp->sc_cred);
+ VOP_UNLOCK(vp);
+ if (error)
+ RETURN (error);
+ VREF(vp);
+ vrele(scp->sc_cdir);
+ scp->sc_cdir = vp;
+ RETURN (0);
+}
+
+/*
+ * Change current working directory (``.'').
+ */
+chdir(scp)
+ register struct syscontext *scp;