Source-Changes-HG archive

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

[src/trunk]: src deduplicate the conversion function from statvfs -> statfs12



details:   https://anonhg.NetBSD.org/src/rev/f77ab40e4a87
branches:  trunk
changeset: 459995:f77ab40e4a87
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Oct 04 01:28:02 2019 +0000

description:
deduplicate the conversion function from statvfs -> statfs12

diffstat:

 lib/libc/compat/sys/compat_statfs.c |  79 ++--------------------------------
 sys/compat/common/vfs_syscalls_20.c |  77 ++-------------------------------
 sys/compat/sys/mount.h              |  83 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 94 insertions(+), 145 deletions(-)

diffs (truncated from 362 to 300 lines):

diff -r 76b3b7088971 -r f77ab40e4a87 lib/libc/compat/sys/compat_statfs.c
--- a/lib/libc/compat/sys/compat_statfs.c       Fri Oct 04 00:04:28 2019 +0000
+++ b/lib/libc/compat/sys/compat_statfs.c       Fri Oct 04 01:28:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_statfs.c,v 1.8 2019/09/22 22:59:38 christos Exp $       */
+/*     $NetBSD: compat_statfs.c,v 1.9 2019/10/04 01:28:03 christos Exp $       */
 
 /*-
  * Copyright (c) 2004, 2019 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: compat_statfs.c,v 1.8 2019/09/22 22:59:38 christos Exp $");
+__RCSID("$NetBSD: compat_statfs.c,v 1.9 2019/10/04 01:28:03 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #define __LIBC12_SOURCE__
@@ -63,73 +63,6 @@
 __strong_alias(fhstatfs, __compat_fhstatfs)
 __strong_alias(getfsstat, __compat_getfsstat)
 
-/*
- * Convert from a new statvfs to an old statfs structure.
- */
-
-static void vfs2fs(struct statfs12 *, const struct statvfs *);
-
-#define MOUNTNO_NONE   0
-#define MOUNTNO_UFS    1               /* UNIX "Fast" Filesystem */
-#define MOUNTNO_NFS    2               /* Network Filesystem */
-#define MOUNTNO_MFS    3               /* Memory Filesystem */
-#define MOUNTNO_MSDOS  4               /* MSDOS Filesystem */
-#define MOUNTNO_CD9660 5               /* iso9660 cdrom */
-#define MOUNTNO_FDESC  6               /* /dev/fd filesystem */
-#define MOUNTNO_KERNFS 7               /* kernel variable filesystem */ 
-#define MOUNTNO_DEVFS  8               /* device node filesystem */
-#define MOUNTNO_AFS    9               /* AFS 3.x */
-static const struct {
-       const char *name;
-       const int value;
-} nv[] = {
-       { MOUNT_UFS, MOUNTNO_UFS },
-       { MOUNT_NFS, MOUNTNO_NFS },
-       { MOUNT_MFS, MOUNTNO_MFS },
-       { MOUNT_MSDOS, MOUNTNO_MSDOS },
-       { MOUNT_CD9660, MOUNTNO_CD9660 },
-       { MOUNT_FDESC, MOUNTNO_FDESC },
-       { MOUNT_KERNFS, MOUNTNO_KERNFS },
-       { MOUNT_AFS, MOUNTNO_AFS },
-};
-
-static void
-vfs2fs(struct statfs12 *bfs, const struct statvfs *fs) 
-{
-       size_t i = 0;
-       bfs->f_type = 0;
-       bfs->f_oflags = (short)fs->f_flag;
-
-       for (i = 0; i < sizeof(nv) / sizeof(nv[0]); i++) {
-               if (strcmp(nv[i].name, fs->f_fstypename) == 0) {
-                       bfs->f_type = nv[i].value;
-                       break;
-               }
-       }
-#define CLAMP(a)       (long)(((a) & ~LONG_MAX) ? LONG_MAX : (a))
-       bfs->f_bsize = CLAMP(fs->f_frsize);
-       bfs->f_iosize = CLAMP(fs->f_iosize);
-       bfs->f_blocks = CLAMP(fs->f_blocks);
-       bfs->f_bfree = CLAMP(fs->f_bfree);
-       if (fs->f_bfree > fs->f_bresvd)
-               bfs->f_bavail = CLAMP(fs->f_bfree - fs->f_bresvd);
-       else
-               bfs->f_bavail = -CLAMP(fs->f_bresvd - fs->f_bfree);
-       bfs->f_files = CLAMP(fs->f_files);
-       bfs->f_ffree = CLAMP(fs->f_ffree);
-       bfs->f_fsid = fs->f_fsidx;
-       bfs->f_owner = fs->f_owner;
-       bfs->f_flags = (long)fs->f_flag;
-       bfs->f_syncwrites = CLAMP(fs->f_syncwrites);
-       bfs->f_asyncwrites = CLAMP(fs->f_asyncwrites);
-       (void)strncpy(bfs->f_fstypename, fs->f_fstypename,
-           sizeof(bfs->f_fstypename));
-       (void)strncpy(bfs->f_mntonname, fs->f_mntonname,
-           sizeof(bfs->f_mntonname));
-       (void)strncpy(bfs->f_mntfromname, fs->f_mntfromname,
-           sizeof(bfs->f_mntfromname));
-}
-
 int
 __compat_statfs(const char *file, struct statfs12 *ost)
 {
@@ -138,7 +71,7 @@
 
        if ((ret = __statvfs90(file, &nst)) == -1)
                return ret;
-       vfs2fs(ost, &nst);
+       statvfs_to_statfs12(&nst, ost);
        return ret;
 }
 
@@ -150,7 +83,7 @@
 
        if ((ret = __fstatvfs90(f, &nst)) == -1)
                return ret;
-       vfs2fs(ost, &nst);
+       statvfs_to_statfs12(&nst, ost);
        return ret;
 }
 
@@ -162,7 +95,7 @@
 
        if ((ret = __fhstatvfs190(fh, FHANDLE30_SIZE, &nst, ST_WAIT)) == -1)
                return ret;
-       vfs2fs(ost, &nst);
+       statvfs_to_statfs12(&nst, ost);
        return ret;
 }
 
@@ -183,7 +116,7 @@
                goto done;
        if (nst)
                for (i = 0; i < ret; i++)
-                       vfs2fs(&ost[i], &nst[i]);
+                       statvfs_to_statfs12(&nst[i], &ost[i]);
 done:
        if (nst)
                free(nst);
diff -r 76b3b7088971 -r f77ab40e4a87 sys/compat/common/vfs_syscalls_20.c
--- a/sys/compat/common/vfs_syscalls_20.c       Fri Oct 04 00:04:28 2019 +0000
+++ b/sys/compat/common/vfs_syscalls_20.c       Fri Oct 04 01:28:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls_20.c,v 1.43 2019/09/26 01:28:27 christos Exp $    */
+/*     $NetBSD: vfs_syscalls_20.c,v 1.44 2019/10/04 01:28:03 christos Exp $    */
 
 /*
  * Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.43 2019/09/26 01:28:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.44 2019/10/04 01:28:03 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -67,30 +67,6 @@
 #include <compat/sys/mount.h>
 #include <compat/sys/statvfs.h>
 
-#define MOUNTNO_NONE   0
-#define MOUNTNO_UFS    1               /* UNIX "Fast" Filesystem */
-#define MOUNTNO_NFS    2               /* Network Filesystem */
-#define MOUNTNO_MFS    3               /* Memory Filesystem */
-#define MOUNTNO_MSDOS  4               /* MSDOS Filesystem */
-#define MOUNTNO_CD9660 5               /* iso9660 cdrom */
-#define MOUNTNO_FDESC  6               /* /dev/fd filesystem */
-#define MOUNTNO_KERNFS 7               /* kernel variable filesystem */
-#define MOUNTNO_DEVFS  8               /* device node filesystem */
-#define MOUNTNO_AFS    9               /* AFS 3.x */
-static const struct {
-       const char *name;
-       const int value;
-} nv[] = {
-       { MOUNT_UFS, MOUNTNO_UFS },
-       { MOUNT_NFS, MOUNTNO_NFS },
-       { MOUNT_MFS, MOUNTNO_MFS },
-       { MOUNT_MSDOS, MOUNTNO_MSDOS },
-       { MOUNT_CD9660, MOUNTNO_CD9660 },
-       { MOUNT_FDESC, MOUNTNO_FDESC },
-       { MOUNT_KERNFS, MOUNTNO_KERNFS },
-       { MOUNT_AFS, MOUNTNO_AFS },
-};
-
 static const struct syscall_package vfs_syscalls_20_syscalls[] = {
        { SYS_compat_20_fhstatfs, 0, (sy_call_t *)compat_20_sys_fhstatfs },
        { SYS_compat_20_fstatfs, 0, (sy_call_t *)compat_20_sys_fstatfs },
@@ -99,47 +75,6 @@
        { 0, 0, NULL }
 };
 
-static int
-statvfs_to_statfs12(const void *vfs, void *vbfs, size_t len)
-{
-       struct statfs12 ofs, *bfs = vbfs;
-       const struct statvfs *fs = vfs;
-       size_t i;
-       ofs.f_type = 0;
-       ofs.f_oflags = (short)fs->f_flag;
-
-       for (i = 0; i < sizeof(nv) / sizeof(nv[0]); i++) {
-               if (strcmp(nv[i].name, fs->f_fstypename) == 0) {
-                       ofs.f_type = nv[i].value;
-                       break;
-               }
-       }
-#define CLAMP(a)       (long)(((a) & ~LONG_MAX) ? LONG_MAX : (a))
-       ofs.f_bsize = CLAMP(fs->f_frsize);
-       ofs.f_iosize = CLAMP(fs->f_iosize);
-       ofs.f_blocks = CLAMP(fs->f_blocks);
-       ofs.f_bfree = CLAMP(fs->f_bfree);
-       if (fs->f_bfree > fs->f_bresvd)
-               ofs.f_bavail = CLAMP(fs->f_bfree - fs->f_bresvd);
-       else
-               ofs.f_bavail = -CLAMP(fs->f_bresvd - fs->f_bfree);
-       ofs.f_files = CLAMP(fs->f_files);
-       ofs.f_ffree = CLAMP(fs->f_ffree);
-       ofs.f_fsid = fs->f_fsidx;
-       ofs.f_owner = fs->f_owner;
-       ofs.f_flags = (long)fs->f_flag;
-       ofs.f_syncwrites = CLAMP(fs->f_syncwrites);
-       ofs.f_asyncwrites = CLAMP(fs->f_asyncwrites);
-       (void)strncpy(ofs.f_fstypename, fs->f_fstypename,
-           sizeof(ofs.f_fstypename));
-       (void)strncpy(ofs.f_mntonname, fs->f_mntonname,
-           sizeof(ofs.f_mntonname));
-       (void)strncpy(ofs.f_mntfromname, fs->f_mntfromname,
-           sizeof(ofs.f_mntfromname));
-
-       return copyout(&ofs, bfs, sizeof(ofs));
-}
-
 /*
  * Get filesystem statistics.
  */
@@ -167,7 +102,7 @@
        if ((error = dostatvfs(mp, sbuf, l, 0, 1)) != 0)
                goto done;
 
-       error = statvfs_to_statfs12(sbuf, SCARG(uap, buf), 0);
+       error = statvfs_to_statfs12_copy(sbuf, SCARG(uap, buf), 0);
 done:
        vrele(vp);
        STATVFSBUF_PUT(sbuf);
@@ -197,7 +132,7 @@
        sbuf = STATVFSBUF_GET();
        if ((error = dostatvfs(mp, sbuf, l, 0, 1)) != 0)
                goto out;
-       error = statvfs_to_statfs12(sbuf, SCARG(uap, buf), 0);
+       error = statvfs_to_statfs12_copy(sbuf, SCARG(uap, buf), 0);
  out:
        fd_putfile(SCARG(uap, fd));
        STATVFSBUF_PUT(sbuf);
@@ -217,7 +152,7 @@
                syscallarg(int) flags;
        } */
        return do_sys_getvfsstat(l, SCARG(uap, buf), SCARG(uap, bufsize),
-           SCARG(uap, flags), statvfs_to_statfs12,
+           SCARG(uap, flags), statvfs_to_statfs12_copy,
            sizeof(struct statvfs90), retval);
 }
 
@@ -253,7 +188,7 @@
        sbuf = STATVFSBUF_GET();
        if ((error = VFS_STATVFS(mp, sbuf)) != 0)
                goto out;
-       error = statvfs_to_statfs12(sbuf, SCARG(uap, buf), 0);
+       error = statvfs_to_statfs12_copy(sbuf, SCARG(uap, buf), 0);
 out:
        vrele(vp);
        STATVFSBUF_PUT(sbuf);
diff -r 76b3b7088971 -r f77ab40e4a87 sys/compat/sys/mount.h
--- a/sys/compat/sys/mount.h    Fri Oct 04 00:04:28 2019 +0000
+++ b/sys/compat/sys/mount.h    Fri Oct 04 01:28:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount.h,v 1.10 2013/10/04 21:07:37 christos Exp $      */
+/*     $NetBSD: mount.h,v 1.11 2019/10/04 01:28:02 christos Exp $      */
 
 /*
  * Copyright (c) 1989, 1991, 1993
@@ -61,10 +61,91 @@
        char    f_mntfromname[MNAMELEN];  /* mounted file system */
 };
 
+#ifndef _KERNEL
+#include <string.h>
+#endif
+
 /*
  * Operations supported on mounted file system.
  */
+/*
+ * Convert from a new statvfs to an old statfs structure.
+ */
+
+#define MOUNTNO_NONE   0
+#define MOUNTNO_UFS    1               /* UNIX "Fast" Filesystem */
+#define MOUNTNO_NFS    2               /* Network Filesystem */
+#define MOUNTNO_MFS    3               /* Memory Filesystem */
+#define MOUNTNO_MSDOS  4               /* MSDOS Filesystem */
+#define MOUNTNO_CD9660 5               /* iso9660 cdrom */
+#define MOUNTNO_FDESC  6               /* /dev/fd filesystem */
+#define MOUNTNO_KERNFS 7               /* kernel variable filesystem */ 
+#define MOUNTNO_DEVFS  8               /* device node filesystem */
+#define MOUNTNO_AFS    9               /* AFS 3.x */
+
+static const struct {
+       const char *name;
+       const int value;
+} __nv[] = {



Home | Main Index | Thread Index | Old Index