A litte trouble with declarations of boot() and panic() resolved. gcc-2.5.8
[unix-history] / sys / kern / vfs_syscalls.c
index d4843c3..08824db 100644 (file)
@@ -30,7 +30,8 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     @(#)vfs_syscalls.c      7.74 (Berkeley) 6/21/91
+ *     from: @(#)vfs_syscalls.c        7.74 (Berkeley) 6/21/91
+ *     $Id: vfs_syscalls.c,v 1.9 1994/01/19 20:27:38 guido Exp $
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -46,6 +47,9 @@
 #include "uio.h"
 #include "malloc.h"
 
 #include "uio.h"
 #include "malloc.h"
 
+static int getvnode(struct filedesc *, int, struct file **);
+static int chdirec(struct nameidata *, struct proc *);
+
 /*
  * Virtual File System System Calls
  */
 /*
  * Virtual File System System Calls
  */
@@ -62,6 +66,7 @@ struct mount_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 mount(p, uap, retval)
        struct proc *p;
        register struct mount_args *uap;
 mount(p, uap, retval)
        struct proc *p;
        register struct mount_args *uap;
@@ -70,7 +75,7 @@ mount(p, uap, retval)
        register struct nameidata *ndp;
        register struct vnode *vp;
        register struct mount *mp;
        register struct nameidata *ndp;
        register struct vnode *vp;
        register struct mount *mp;
-       int error, flag;
+       int error, flag = 0;
        struct nameidata nd;
 
        /*
        struct nameidata nd;
 
        /*
@@ -149,30 +154,10 @@ update:
        /*
         * Set the mount level flags.
         */
        /*
         * Set the mount level flags.
         */
-       if (uap->flags & MNT_RDONLY)
-               mp->mnt_flag |= MNT_RDONLY;
-       else
-               mp->mnt_flag &= ~MNT_RDONLY;
-       if (uap->flags & MNT_NOSUID)
-               mp->mnt_flag |= MNT_NOSUID;
-       else
-               mp->mnt_flag &= ~MNT_NOSUID;
-       if (uap->flags & MNT_NOEXEC)
-               mp->mnt_flag |= MNT_NOEXEC;
-       else
-               mp->mnt_flag &= ~MNT_NOEXEC;
-       if (uap->flags & MNT_NODEV)
-               mp->mnt_flag |= MNT_NODEV;
-       else
-               mp->mnt_flag &= ~MNT_NODEV;
-       if (uap->flags & MNT_NOCORE)
-               mp->mnt_flag |= MNT_NOCORE;
-       else
-               mp->mnt_flag &= ~MNT_NOCORE;
-       if (uap->flags & MNT_SYNCHRONOUS)
-               mp->mnt_flag |= MNT_SYNCHRONOUS;
-       else
-               mp->mnt_flag &= ~MNT_SYNCHRONOUS;
+       mp->mnt_flag &=
+               ~(MNT_RDONLY|MNT_NOSUID|MNT_NOEXEC|MNT_NODEV|MNT_SYNCHRONOUS);
+       mp->mnt_flag |= uap->flags &
+               (MNT_RDONLY|MNT_NOSUID|MNT_NOEXEC|MNT_NODEV|MNT_SYNCHRONOUS);
        /*
         * Mount the filesystem.
         */
        /*
         * Mount the filesystem.
         */
@@ -217,6 +202,7 @@ struct umount_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 unmount(p, uap, retval)
        struct proc *p;
        register struct umount_args *uap;
 unmount(p, uap, retval)
        struct proc *p;
        register struct umount_args *uap;
@@ -256,6 +242,7 @@ unmount(p, uap, retval)
 /*
  * Do an unmount.
  */
 /*
  * Do an unmount.
  */
+int
 dounmount(mp, flags, p)
        register struct mount *mp;
        int flags;
 dounmount(mp, flags, p)
        register struct mount *mp;
        int flags;
@@ -292,6 +279,7 @@ dounmount(mp, flags, p)
  * Sync each mounted filesystem.
  */
 /* ARGSUSED */
  * Sync each mounted filesystem.
  */
 /* ARGSUSED */
+int
 sync(p, uap, retval)
        struct proc *p;
        void *uap;
 sync(p, uap, retval)
        struct proc *p;
        void *uap;
@@ -300,7 +288,8 @@ sync(p, uap, retval)
        register struct mount *mp;
        struct mount *omp;
 
        register struct mount *mp;
        struct mount *omp;
 
-       mp = rootfs;
+       if ((mp = rootfs) == NULL)
+               return (0);
        do {
                /*
                 * The lock check below is to avoid races with mount
        do {
                /*
                 * The lock check below is to avoid races with mount
@@ -330,6 +319,7 @@ struct quotactl_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 quotactl(p, uap, retval)
        struct proc *p;
        register struct quotactl_args *uap;
 quotactl(p, uap, retval)
        struct proc *p;
        register struct quotactl_args *uap;
@@ -361,6 +351,7 @@ struct statfs_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 statfs(p, uap, retval)
        struct proc *p;
        register struct statfs_args *uap;
 statfs(p, uap, retval)
        struct proc *p;
        register struct statfs_args *uap;
@@ -397,6 +388,7 @@ struct fstatfs_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 fstatfs(p, uap, retval)
        struct proc *p;
        register struct fstatfs_args *uap;
 fstatfs(p, uap, retval)
        struct proc *p;
        register struct fstatfs_args *uap;
@@ -427,6 +419,7 @@ struct getfsstat_args {
        int flags;
 };
 
        int flags;
 };
 
+int
 getfsstat(p, uap, retval)
        struct proc *p;
        register struct getfsstat_args *uap;
 getfsstat(p, uap, retval)
        struct proc *p;
        register struct getfsstat_args *uap;
@@ -479,6 +472,7 @@ struct fchdir_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 fchdir(p, uap, retval)
        struct proc *p;
        struct fchdir_args *uap;
 fchdir(p, uap, retval)
        struct proc *p;
        struct fchdir_args *uap;
@@ -515,6 +509,7 @@ struct chdir_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 chdir(p, uap, retval)
        struct proc *p;
        struct chdir_args *uap;
 chdir(p, uap, retval)
        struct proc *p;
        struct chdir_args *uap;
@@ -545,6 +540,7 @@ struct chroot_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 chroot(p, uap, retval)
        struct proc *p;
        struct chroot_args *uap;
 chroot(p, uap, retval)
        struct proc *p;
        struct chroot_args *uap;
@@ -572,6 +568,7 @@ chroot(p, uap, retval)
 /*
  * Common routine for chroot and chdir.
  */
 /*
  * Common routine for chroot and chdir.
  */
+static int
 chdirec(ndp, p)
        struct nameidata *ndp;
        struct proc *p;
 chdirec(ndp, p)
        struct nameidata *ndp;
        struct proc *p;
@@ -604,6 +601,7 @@ struct open_args {
        int     crtmode;
 };
 
        int     crtmode;
 };
 
+int
 open(p, uap, retval)
        struct proc *p;
        register struct open_args *uap;
 open(p, uap, retval)
        struct proc *p;
        register struct open_args *uap;
@@ -643,6 +641,7 @@ open(p, uap, retval)
                return (error);
        }
        vp = ndp->ni_vp;
                return (error);
        }
        vp = ndp->ni_vp;
+       VOP_UNLOCK(vp);
        fp->f_flag = fmode & FMASK;
        if (fmode & (O_EXLOCK | O_SHLOCK)) {
                lf.l_whence = SEEK_SET;
        fp->f_flag = fmode & FMASK;
        if (fmode & (O_EXLOCK | O_SHLOCK)) {
                lf.l_whence = SEEK_SET;
@@ -656,7 +655,6 @@ open(p, uap, retval)
                if ((fmode & FNONBLOCK) == 0)
                        type |= F_WAIT;
                if (error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, type)) {
                if ((fmode & FNONBLOCK) == 0)
                        type |= F_WAIT;
                if (error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, type)) {
-                       VOP_UNLOCK(vp);
                        (void) vn_close(vp, fp->f_flag, fp->f_cred, p);
                        ffree(fp);
                        fdp->fd_ofiles[indx] = NULL;
                        (void) vn_close(vp, fp->f_flag, fp->f_cred, p);
                        ffree(fp);
                        fdp->fd_ofiles[indx] = NULL;
@@ -664,7 +662,6 @@ open(p, uap, retval)
                }
                fp->f_flag |= FHASLOCK;
        }
                }
                fp->f_flag |= FHASLOCK;
        }
-       VOP_UNLOCK(vp);
        fp->f_type = DTYPE_VNODE;
        fp->f_ops = &vnops;
        fp->f_data = (caddr_t)vp;
        fp->f_type = DTYPE_VNODE;
        fp->f_ops = &vnops;
        fp->f_data = (caddr_t)vp;
@@ -682,6 +679,7 @@ struct ocreat_args {
        int     fmode;
 };
 
        int     fmode;
 };
 
+int
 ocreat(p, uap, retval)
        struct proc *p;
        register struct ocreat_args *uap;
 ocreat(p, uap, retval)
        struct proc *p;
        register struct ocreat_args *uap;
@@ -711,6 +709,7 @@ struct mknod_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 mknod(p, uap, retval)
        struct proc *p;
        register struct mknod_args *uap;
 mknod(p, uap, retval)
        struct proc *p;
        register struct mknod_args *uap;
@@ -778,6 +777,7 @@ struct mkfifo_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 mkfifo(p, uap, retval)
        struct proc *p;
        register struct mkfifo_args *uap;
 mkfifo(p, uap, retval)
        struct proc *p;
        register struct mkfifo_args *uap;
@@ -823,6 +823,7 @@ struct link_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 link(p, uap, retval)
        struct proc *p;
        register struct link_args *uap;
 link(p, uap, retval)
        struct proc *p;
        register struct link_args *uap;
@@ -882,6 +883,7 @@ struct symlink_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 symlink(p, uap, retval)
        struct proc *p;
        register struct symlink_args *uap;
 symlink(p, uap, retval)
        struct proc *p;
        register struct symlink_args *uap;
@@ -929,6 +931,7 @@ struct unlink_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 unlink(p, uap, retval)
        struct proc *p;
        struct unlink_args *uap;
 unlink(p, uap, retval)
        struct proc *p;
        struct unlink_args *uap;
@@ -981,6 +984,7 @@ struct lseek_args {
        int     sbase;
 };
 
        int     sbase;
 };
 
+int
 lseek(p, uap, retval)
        struct proc *p;
        register struct lseek_args *uap;
 lseek(p, uap, retval)
        struct proc *p;
        register struct lseek_args *uap;
@@ -1031,6 +1035,7 @@ struct saccess_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 saccess(p, uap, retval)
        struct proc *p;
        register struct saccess_args *uap;
 saccess(p, uap, retval)
        struct proc *p;
        register struct saccess_args *uap;
@@ -1085,6 +1090,7 @@ struct stat_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 stat(p, uap, retval)
        struct proc *p;
        register struct stat_args *uap;
 stat(p, uap, retval)
        struct proc *p;
        register struct stat_args *uap;
@@ -1120,6 +1126,7 @@ struct lstat_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 lstat(p, uap, retval)
        struct proc *p;
        register struct lstat_args *uap;
 lstat(p, uap, retval)
        struct proc *p;
        register struct lstat_args *uap;
@@ -1155,6 +1162,7 @@ struct readlink_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 readlink(p, uap, retval)
        struct proc *p;
        register struct readlink_args *uap;
 readlink(p, uap, retval)
        struct proc *p;
        register struct readlink_args *uap;
@@ -1204,6 +1212,7 @@ struct chflags_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 chflags(p, uap, retval)
        struct proc *p;
        register struct chflags_args *uap;
 chflags(p, uap, retval)
        struct proc *p;
        register struct chflags_args *uap;
@@ -1244,6 +1253,7 @@ struct fdchflags_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 fchflags(p, uap, retval)
        struct proc *p;
        register struct fdchflags_args *uap;
 fchflags(p, uap, retval)
        struct proc *p;
        register struct fdchflags_args *uap;
@@ -1280,6 +1290,7 @@ struct chmod_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 chmod(p, uap, retval)
        struct proc *p;
        register struct chmod_args *uap;
 chmod(p, uap, retval)
        struct proc *p;
        register struct chmod_args *uap;
@@ -1320,6 +1331,7 @@ struct fchmod_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 fchmod(p, uap, retval)
        struct proc *p;
        register struct fchmod_args *uap;
 fchmod(p, uap, retval)
        struct proc *p;
        register struct fchmod_args *uap;
@@ -1357,6 +1369,7 @@ struct chown_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 chown(p, uap, retval)
        struct proc *p;
        register struct chown_args *uap;
 chown(p, uap, retval)
        struct proc *p;
        register struct chown_args *uap;
@@ -1399,6 +1412,7 @@ struct fchown_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 fchown(p, uap, retval)
        struct proc *p;
        register struct fchown_args *uap;
 fchown(p, uap, retval)
        struct proc *p;
        register struct fchown_args *uap;
@@ -1436,6 +1450,7 @@ struct utimes_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 utimes(p, uap, retval)
        struct proc *p;
        register struct utimes_args *uap;
 utimes(p, uap, retval)
        struct proc *p;
        register struct utimes_args *uap;
@@ -1448,7 +1463,12 @@ utimes(p, uap, retval)
        int error;
        struct nameidata nd;
 
        int error;
        struct nameidata nd;
 
-       if (error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)))
+       VATTR_NULL(&vattr);
+       if ((caddr_t)uap->tptr == NULL) {
+               microtime(&tv[0]);
+               tv[1] = tv[0];
+               vattr.va_vaflags |= VA_UTIMES_NULL;
+       } else if (error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)))
                return (error);
        ndp = &nd;
        ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
                return (error);
        ndp = &nd;
        ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
@@ -1461,7 +1481,6 @@ utimes(p, uap, retval)
                error = EROFS;
                goto out;
        }
                error = EROFS;
                goto out;
        }
-       VATTR_NULL(&vattr);
        vattr.va_atime = tv[0];
        vattr.va_mtime = tv[1];
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
        vattr.va_atime = tv[0];
        vattr.va_mtime = tv[1];
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
@@ -1480,6 +1499,7 @@ struct truncate_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 truncate(p, uap, retval)
        struct proc *p;
        register struct truncate_args *uap;
 truncate(p, uap, retval)
        struct proc *p;
        register struct truncate_args *uap;
@@ -1523,6 +1543,7 @@ struct ftruncate_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 ftruncate(p, uap, retval)
        struct proc *p;
        register struct ftruncate_args *uap;
 ftruncate(p, uap, retval)
        struct proc *p;
        register struct ftruncate_args *uap;
@@ -1562,6 +1583,7 @@ struct fsync_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 fsync(p, uap, retval)
        struct proc *p;
        struct fsync_args *uap;
 fsync(p, uap, retval)
        struct proc *p;
        struct fsync_args *uap;
@@ -1593,6 +1615,7 @@ struct rename_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 rename(p, uap, retval)
        struct proc *p;
        register struct rename_args *uap;
 rename(p, uap, retval)
        struct proc *p;
        register struct rename_args *uap;
@@ -1665,7 +1688,8 @@ out:
        vrele(tond.ni_startdir);
        FREE(tond.ni_pnbuf, M_NAMEI);
 out1:
        vrele(tond.ni_startdir);
        FREE(tond.ni_pnbuf, M_NAMEI);
 out1:
-       vrele(fromnd.ni_startdir);
+       if (fromnd.ni_startdir)
+               vrele(fromnd.ni_startdir);
        FREE(fromnd.ni_pnbuf, M_NAMEI);
        if (error == -1)
                return (0);
        FREE(fromnd.ni_pnbuf, M_NAMEI);
        if (error == -1)
                return (0);
@@ -1682,6 +1706,7 @@ struct mkdir_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 mkdir(p, uap, retval)
        struct proc *p;
        register struct mkdir_args *uap;
 mkdir(p, uap, retval)
        struct proc *p;
        register struct mkdir_args *uap;
@@ -1727,6 +1752,7 @@ struct rmdir_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 rmdir(p, uap, retval)
        struct proc *p;
        struct rmdir_args *uap;
 rmdir(p, uap, retval)
        struct proc *p;
        struct rmdir_args *uap;
@@ -1785,6 +1811,7 @@ struct getdirentries_args {
        long    *basep;
 };
 
        long    *basep;
 };
 
+int
 getdirentries(p, uap, retval)
        struct proc *p;
        register struct getdirentries_args *uap;
 getdirentries(p, uap, retval)
        struct proc *p;
        register struct getdirentries_args *uap;
@@ -1855,6 +1882,7 @@ struct revoke_args {
 };
 
 /* ARGSUSED */
 };
 
 /* ARGSUSED */
+int
 revoke(p, uap, retval)
        struct proc *p;
        register struct revoke_args *uap;
 revoke(p, uap, retval)
        struct proc *p;
        register struct revoke_args *uap;
@@ -1892,10 +1920,11 @@ out:
 /*
  * Convert a user file descriptor to a kernel file entry.
  */
 /*
  * Convert a user file descriptor to a kernel file entry.
  */
+static int
 getvnode(fdp, fdes, fpp)
        struct filedesc *fdp;
 getvnode(fdp, fdes, fpp)
        struct filedesc *fdp;
-       struct file **fpp;
        int fdes;
        int fdes;
+       struct file **fpp;
 {
        struct file *fp;
 
 {
        struct file *fp;