Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/netbsd32 o Add support for the statvfs family of ...



details:   https://anonhg.NetBSD.org/src/rev/d57011a26952
branches:  trunk
changeset: 567514:d57011a26952
user:      cube <cube%NetBSD.org@localhost>
date:      Thu Jun 17 18:29:40 2004 +0000

description:
o Add support for the statvfs family of syscalls (statvfs1, fstatvfs1,
  fhstatvfs1 and getvfsstat)
o Move the statfs family out of netbsd32_fs.c and netbsd32_netbsd.c to
  netbsd_compat_20.c, compiled with COMPAT_20

Reviewed by christos@.

diffstat:

 sys/compat/netbsd32/files.netbsd32       |    3 +-
 sys/compat/netbsd32/netbsd32.h           |   32 +++-
 sys/compat/netbsd32/netbsd32_compat_20.c |  239 +++++++++++++++++++++++++++
 sys/compat/netbsd32/netbsd32_conv.h      |   44 +++-
 sys/compat/netbsd32/netbsd32_fs.c        |  272 ++++++++++++++++++++----------
 sys/compat/netbsd32/netbsd32_netbsd.c    |   23 +--
 sys/compat/netbsd32/syscalls.master      |   33 +++-
 7 files changed, 508 insertions(+), 138 deletions(-)

diffs (truncated from 837 to 300 lines):

diff -r cbce8a1281a5 -r d57011a26952 sys/compat/netbsd32/files.netbsd32
--- a/sys/compat/netbsd32/files.netbsd32        Thu Jun 17 15:35:15 2004 +0000
+++ b/sys/compat/netbsd32/files.netbsd32        Thu Jun 17 18:29:40 2004 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.netbsd32,v 1.16 2004/01/16 05:03:02 mrg Exp $
+#      $NetBSD: files.netbsd32,v 1.17 2004/06/17 18:29:40 cube Exp $
 #
 # config file description for machine-independent netbsd32 compat code.
 # included by ports that need it.
@@ -28,4 +28,5 @@
 file   compat/netbsd32/netbsd32_compat_12.c    compat_netbsd32 & (compat_12 | compat_sunos)
 file   compat/netbsd32/netbsd32_compat_13.c    compat_netbsd32 & compat_13
 file   compat/netbsd32/netbsd32_compat_14.c    compat_netbsd32 & compat_14
+file   compat/netbsd32/netbsd32_compat_20.c    compat_netbsd32 & compat_20
 file   compat/netbsd32/netbsd32_compat_43.c    compat_netbsd32 & (compat_43 | compat_sunos)
diff -r cbce8a1281a5 -r d57011a26952 sys/compat/netbsd32/netbsd32.h
--- a/sys/compat/netbsd32/netbsd32.h    Thu Jun 17 15:35:15 2004 +0000
+++ b/sys/compat/netbsd32/netbsd32.h    Thu Jun 17 18:29:40 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32.h,v 1.28 2004/05/20 06:34:25 atatat Exp $     */
+/*     $NetBSD: netbsd32.h,v 1.29 2004/06/17 18:29:40 cube Exp $       */
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -41,6 +41,7 @@
 #include <sys/systm.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
+#include <sys/statvfs.h>
 #include <sys/sa.h>
 #include <sys/syscallargs.h>
 #include <sys/ipc.h>
@@ -474,6 +475,35 @@
 #endif
 ;
 
+/* from <sys/statvfs.h> */
+typedef netbsd32_pointer_t netbsd32_statvfsp_t;
+struct netbsd32_statvfs {
+       netbsd32_u_long f_flag;         /* copy of mount exported flags */
+       netbsd32_u_long f_bsize;        /* system block size */
+       netbsd32_u_long f_frsize;       /* system fragment size */
+       netbsd32_u_long f_iosize;       /* optimal file system block size */
+       fsblkcnt_t      f_blocks;       /* number of blocks in file system */
+       fsblkcnt_t      f_bfree;        /* free blocks avail in file system */
+       fsblkcnt_t      f_bavail;       /* free blocks avail to non-root */
+       fsblkcnt_t      f_bresvd;       /* blocks reserved for root */
+       fsfilcnt_t      f_files;        /* total file nodes in file system */
+       fsfilcnt_t      f_ffree;        /* free file nodes in file system */
+       fsfilcnt_t      f_favail;       /* free file nodes avail to non-root */
+       fsfilcnt_t      f_fresvd;       /* file nodes reserved for root */
+       uint64_t        f_syncreads;    /* count of sync reads since mount */
+       uint64_t        f_syncwrites;   /* count of sync writes since mount */
+       uint64_t        f_asyncreads;   /* count of async reads since mount */
+       uint64_t        f_asyncwrites;  /* count of async writes since mount */
+       fsid_t          f_fsidx;        /* NetBSD compatible fsid */
+       netbsd32_u_long f_fsid;         /* Posix compatible fsid */
+       netbsd32_u_long f_namemax;      /* maximum filename length */
+       uid_t           f_owner;        /* user that mounted the file system */
+       uint32_t        f_spare[4];     /* spare space */
+       char    f_fstypename[_VFS_NAMELEN]; /* fs type name */
+       char    f_mntonname[_VFS_MNAMELEN];  /* directory on which mounted */
+       char    f_mntfromname[_VFS_MNAMELEN];  /* mounted file system */
+} __attribute__((packed));
+
 /* from <sys/timex.h> */
 typedef netbsd32_pointer_t netbsd32_ntptimevalp_t;
 struct netbsd32_ntptimeval {
diff -r cbce8a1281a5 -r d57011a26952 sys/compat/netbsd32/netbsd32_compat_20.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/netbsd32/netbsd32_compat_20.c  Thu Jun 17 18:29:40 2004 +0000
@@ -0,0 +1,239 @@
+/*     $NetBSD: netbsd32_compat_20.c,v 1.1 2004/06/17 18:29:40 cube Exp $      */
+
+/*
+ * Copyright (c) 1998, 2001 Matthew R. Green
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.1 2004/06/17 18:29:40 cube Exp $");
+
+#if defined(_KERNEL_OPT)
+#include "opt_ktrace.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/ktrace.h>
+#include <sys/vnode.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/namei.h>
+#include <sys/sa.h>
+#include <sys/syscallargs.h>
+#include <sys/proc.h>
+
+#include <compat/netbsd32/netbsd32.h>
+#include <compat/netbsd32/netbsd32_syscallargs.h>
+#include <compat/netbsd32/netbsd32_conv.h>
+
+static __inline void compat_20_netbsd32_from_statvfs(struct statvfs *,
+    struct netbsd32_statfs *);
+
+static __inline void
+compat_20_netbsd32_from_statvfs(sbp, sb32p)
+       struct statvfs *sbp;
+       struct netbsd32_statfs *sb32p;
+{
+       sb32p->f_flags = sbp->f_flag;
+       sb32p->f_bsize = (netbsd32_long)sbp->f_bsize;
+       sb32p->f_iosize = (netbsd32_long)sbp->f_iosize;
+       sb32p->f_blocks = (netbsd32_long)sbp->f_blocks;
+       sb32p->f_bfree = (netbsd32_long)sbp->f_bfree;
+       sb32p->f_bavail = (netbsd32_long)sbp->f_bavail;
+       sb32p->f_files = (netbsd32_long)sbp->f_files;
+       sb32p->f_ffree = (netbsd32_long)sbp->f_ffree;
+       sb32p->f_fsid = sbp->f_fsidx;
+       sb32p->f_owner = sbp->f_owner;
+       sb32p->f_spare[0] = 0;
+       sb32p->f_spare[1] = 0;
+       sb32p->f_spare[2] = 0;
+       sb32p->f_spare[3] = 0;
+#if 1
+       /* May as well do the whole batch in one go */
+       memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN+MNAMELEN+MNAMELEN);
+#else
+       /* If we want to be careful */
+       memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN);
+       memcpy(sb32p->f_mntonname, sbp->f_mntonname, MNAMELEN);
+       memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, MNAMELEN);
+#endif
+}
+
+int
+compat_20_netbsd32_getfsstat(l, v, retval)
+       struct lwp *l;
+       void *v;
+       register_t *retval;
+{
+       struct compat_20_netbsd32_getfsstat_args /* {
+               syscallarg(netbsd32_statfsp_t) buf;
+               syscallarg(netbsd32_long) bufsize;
+               syscallarg(int) flags;
+       } */ *uap = v;
+       struct mount *mp, *nmp;
+       struct statvfs *sp;
+       struct netbsd32_statfs sb32;
+       caddr_t sfsp;
+       long count, maxcount, error;
+       struct proc *p = l->l_proc;
+
+       maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statfs);
+       sfsp = (caddr_t)NETBSD32PTR64(SCARG(uap, buf));
+       simple_lock(&mountlist_slock);
+       count = 0;
+       for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
+               if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
+                       nmp = mp->mnt_list.cqe_next;
+                       continue;
+               }
+               if (sfsp && count < maxcount) {
+                       sp = &mp->mnt_stat;
+                       /*
+                        * If MNT_NOWAIT or MNT_LAZY is specified, do not
+                        * refresh the fsstat cache. MNT_WAIT or MNT_LAXY
+                        * overrides MNT_NOWAIT.
+                        */
+                       if (SCARG(uap, flags) != MNT_NOWAIT &&
+                           SCARG(uap, flags) != MNT_LAZY &&
+                           (SCARG(uap, flags) == MNT_WAIT ||
+                            SCARG(uap, flags) == 0) &&
+                           (error = VFS_STATVFS(mp, sp, p)) != 0) {
+                               simple_lock(&mountlist_slock);
+                               nmp = mp->mnt_list.cqe_next;
+                               vfs_unbusy(mp);
+                               continue;
+                       }
+                       sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
+                       compat_20_netbsd32_from_statvfs(sp, &sb32);
+                       error = copyout(&sb32, sfsp, sizeof(sb32));
+                       if (error) {
+                               vfs_unbusy(mp);
+                               return (error);
+                       }
+                       sfsp += sizeof(sb32);
+               }
+               count++;
+               simple_lock(&mountlist_slock);
+               nmp = mp->mnt_list.cqe_next;
+               vfs_unbusy(mp);
+       }
+       simple_unlock(&mountlist_slock);
+       if (sfsp && count > maxcount)
+               *retval = maxcount;
+       else
+               *retval = count;
+       return (0);
+}
+
+int
+compat_20_netbsd32_statfs(l, v, retval)
+       struct lwp *l;
+       void *v;
+       register_t *retval;
+{
+       struct compat_20_netbsd32_statfs_args /* {
+               syscallarg(const netbsd32_charp) path;
+               syscallarg(netbsd32_statfsp_t) buf;
+       } */ *uap = v;
+       struct mount *mp;
+       struct statvfs *sp;
+       struct netbsd32_statfs s32;
+       int error;
+       struct nameidata nd;
+       struct proc *p = l->l_proc;
+
+       NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
+           (char *)NETBSD32PTR64(SCARG(uap, path)), p);
+       if ((error = namei(&nd)) != 0)
+               return (error);
+       mp = nd.ni_vp->v_mount;
+       sp = &mp->mnt_stat;
+       vrele(nd.ni_vp);
+       if ((error = VFS_STATVFS(mp, sp, p)) != 0)
+               return (error);
+       sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
+       compat_20_netbsd32_from_statvfs(sp, &s32);
+       return (copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
+           sizeof(s32)));
+}
+
+int
+compat_20_netbsd32_fstatfs(l, v, retval)
+       struct lwp *l;
+       void *v;
+       register_t *retval;
+{
+       struct compat_20_netbsd32_fstatfs_args /* {
+               syscallarg(int) fd;
+               syscallarg(netbsd32_statfsp_t) buf;
+       } */ *uap = v;
+       struct file *fp;
+       struct mount *mp;
+       struct statvfs *sp;
+       struct netbsd32_statfs s32;
+       int error;
+       struct proc *p = l->l_proc;
+
+       /* getvnode() will use the descriptor for us */
+       if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+               return (error);
+       mp = ((struct vnode *)fp->f_data)->v_mount;
+       sp = &mp->mnt_stat;
+       if ((error = VFS_STATVFS(mp, sp, p)) != 0)
+               goto out;
+       sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
+       compat_20_netbsd32_from_statvfs(sp, &s32);
+       error = copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
+           sizeof(s32));
+ out:
+       FILE_UNUSE(fp, p);
+       return (error);
+}
+
+int
+compat_20_netbsd32_fhstatfs(l, v, retval)
+       struct lwp *l;
+       void *v;
+       register_t *retval;
+{
+       struct compat_20_netbsd32_fhstatfs_args /* {
+               syscallarg(const netbsd32_fhandlep_t) fhp;



Home | Main Index | Thread Index | Old Index