Source-Changes-HG archive

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

[src/trunk]: src/sys/miscfs/procfs add 'mounts' file for -o linux, which list...



details:   https://anonhg.NetBSD.org/src/rev/9fc12c86dd8f
branches:  trunk
changeset: 570064:9fc12c86dd8f
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Mon Sep 20 17:53:08 2004 +0000

description:
add 'mounts' file for -o linux, which lists all currently mounted
filesystems; Linux glibc statvfs() uses this to get some of mount flags,
and this file is also useful as /emul/linux/etc/mtab (via symlink)

diffstat:

 sys/miscfs/procfs/procfs.h       |   5 ++-
 sys/miscfs/procfs/procfs_linux.c |  64 ++++++++++++++++++++++++++++++++++++++-
 sys/miscfs/procfs/procfs_subr.c  |   8 +++-
 sys/miscfs/procfs/procfs_vnops.c |   7 +++-
 4 files changed, 77 insertions(+), 7 deletions(-)

diffs (193 lines):

diff -r 32c1e61f5cd6 -r 9fc12c86dd8f sys/miscfs/procfs/procfs.h
--- a/sys/miscfs/procfs/procfs.h        Mon Sep 20 17:31:57 2004 +0000
+++ b/sys/miscfs/procfs/procfs.h        Mon Sep 20 17:53:08 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs.h,v 1.55 2004/08/27 07:02:45 skrll Exp $        */
+/*     $NetBSD: procfs.h,v 1.56 2004/09/20 17:53:08 jdolecek Exp $     */
 
 /*
  * Copyright (c) 1993
@@ -99,6 +99,7 @@
        PFSmaps,        /* memory map, Linux style (if -o linux) */
        PFSfd,          /* a directory containing the processes open fd's */
        PFSuptime,      /* elapsed time since (if -o linux) */
+       PFSmounts,      /* mounted filesystems (if -o linux) */
 #ifdef __HAVE_PROCFS_MACHDEP
        PROCFS_MACHDEP_NODE_TYPES
 #endif
@@ -201,6 +202,8 @@
     struct uio *));
 int procfs_douptime __P((struct proc *, struct proc *, struct pfsnode *,
     struct uio *));
+int procfs_domounts __P((struct proc *, struct proc *, struct pfsnode *,
+    struct uio *));
 
 void procfs_revoke_vnodes __P((struct proc *, void *));
 void procfs_hashinit __P((void));
diff -r 32c1e61f5cd6 -r 9fc12c86dd8f sys/miscfs/procfs/procfs_linux.c
--- a/sys/miscfs/procfs/procfs_linux.c  Mon Sep 20 17:31:57 2004 +0000
+++ b/sys/miscfs/procfs/procfs_linux.c  Mon Sep 20 17:53:08 2004 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: procfs_linux.c,v 1.18 2004/08/27 07:02:45 skrll Exp $      */
+/*      $NetBSD: procfs_linux.c,v 1.19 2004/09/20 17:53:08 jdolecek Exp $      */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.18 2004/08/27 07:02:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.19 2004/09/20 17:53:08 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -50,6 +50,8 @@
 #include <sys/signal.h>
 #include <sys/signalvar.h>
 #include <sys/tty.h>
+#include <sys/malloc.h>
+#include <sys/mount.h>
 
 #include <miscfs/procfs/procfs.h>
 #include <compat/linux/common/linux_exec.h>
@@ -249,3 +251,61 @@
 
        return (uiomove_frombuf(buf, len, uio));
 }
+
+int
+procfs_domounts(struct proc *curp, struct proc *p, struct pfsnode *pfs,
+                struct uio *uio)
+{
+       char buf[512], *mtab = NULL;
+       const char *fsname;
+       size_t len, mtabsz = 0;
+       struct mount *mp, *nmp;
+       struct statvfs *sfs;
+       int error = 0;
+
+       simple_lock(&mountlist_slock);
+       for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
+            mp = nmp) {
+               if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
+                       nmp = CIRCLEQ_NEXT(mp, mnt_list);
+                       continue;
+               }
+
+               sfs = &mp->mnt_stat;
+
+               /* Linux uses different names for some filesystems */
+               fsname = sfs->f_fstypename;
+               if (strcmp(fsname, "procfs") == 0)
+                       fsname = "proc";
+               else if (strcmp(fsname, "ext2fs") == 0)
+                       fsname = "ext2";
+               
+               len = snprintf(buf, sizeof(buf), "%s %s %s %s%s%s%s%s%s 0 0\n",
+                       sfs->f_mntfromname,
+                       sfs->f_mntonname,
+                       fsname,
+                       (mp->mnt_flag & MNT_RDONLY) ? "ro" : "rw",
+                       (mp->mnt_flag & MNT_NOSUID) ? ",nosuid" : "",
+                       (mp->mnt_flag & MNT_NOEXEC) ? ",noexec" : "",
+                       (mp->mnt_flag & MNT_NODEV) ? ",nodev" : "",
+                       (mp->mnt_flag & MNT_SYNCHRONOUS) ? ",sync" : "",
+                       (mp->mnt_flag & MNT_NOATIME) ? ",noatime" : ""
+                       );
+
+               mtab = realloc(mtab, mtabsz + len, M_TEMP, M_WAITOK);
+               memcpy(mtab + mtabsz, buf, len);
+               mtabsz += len;
+
+               simple_lock(&mountlist_slock);
+               nmp = CIRCLEQ_NEXT(mp, mnt_list);
+               vfs_unbusy(mp);
+       }
+       simple_unlock(&mountlist_slock);
+
+       if (mtabsz > 0) {
+               error = uiomove_frombuf(mtab, mtabsz, uio);
+               free(mtab, M_TEMP);
+       }
+
+       return error;
+}
diff -r 32c1e61f5cd6 -r 9fc12c86dd8f sys/miscfs/procfs/procfs_subr.c
--- a/sys/miscfs/procfs/procfs_subr.c   Mon Sep 20 17:31:57 2004 +0000
+++ b/sys/miscfs/procfs/procfs_subr.c   Mon Sep 20 17:53:08 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_subr.c,v 1.61 2004/08/27 07:02:45 skrll Exp $   */
+/*     $NetBSD: procfs_subr.c,v 1.62 2004/09/20 17:53:08 jdolecek Exp $        */
 
 /*
  * Copyright (c) 1993
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.61 2004/08/27 07:02:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.62 2004/09/20 17:53:08 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -246,6 +246,7 @@
        case PFSmeminfo:        /* /proc/meminfo = -r--r--r-- */
        case PFScpuinfo:        /* /proc/cpuinfo = -r--r--r-- */
        case PFSuptime: /* /proc/uptime = -r--r--r-- */
+       case PFSmounts: /* /proc/mounts = -r--r--r-- */
                pfs->pfs_mode = S_IRUSR|S_IRGRP|S_IROTH;
                vp->v_type = VREG;
                break;
@@ -362,6 +363,9 @@
        case PFSuptime:
                return (procfs_douptime(curp, p, pfs, uio));
 
+       case PFSmounts:
+               return (procfs_domounts(curp, p, pfs, uio));
+
 #ifdef __HAVE_PROCFS_MACHDEP
        PROCFS_MACHDEP_NODETYPE_CASES
                return (procfs_machdep_rw(curp, l, pfs, uio));
diff -r 32c1e61f5cd6 -r 9fc12c86dd8f sys/miscfs/procfs/procfs_vnops.c
--- a/sys/miscfs/procfs/procfs_vnops.c  Mon Sep 20 17:31:57 2004 +0000
+++ b/sys/miscfs/procfs/procfs_vnops.c  Mon Sep 20 17:53:08 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_vnops.c,v 1.113 2004/04/29 16:10:55 jrf Exp $   */
+/*     $NetBSD: procfs_vnops.c,v 1.114 2004/09/20 17:53:08 jdolecek Exp $      */
 
 /*
  * Copyright (c) 1993, 1995
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.113 2004/04/29 16:10:55 jrf Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.114 2004/09/20 17:53:08 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -155,6 +155,7 @@
        { DT_REG, N("meminfo"),     PFSmeminfo,        procfs_validfile_linux },
        { DT_REG, N("cpuinfo"),     PFScpuinfo,        procfs_validfile_linux },
        { DT_REG, N("uptime"),      PFSuptime,         procfs_validfile_linux },
+       { DT_REG, N("mounts"),      PFSmounts,         procfs_validfile_linux },
 #undef N
 };
 static const int nproc_root_targets =
@@ -578,6 +579,7 @@
        case PFSmeminfo:
        case PFScpuinfo:
        case PFSuptime:
+       case PFSmounts:
                vap->va_nlink = 1;
                vap->va_uid = vap->va_gid = 0;
                break;
@@ -687,6 +689,7 @@
        case PFSmeminfo:
        case PFScpuinfo:
        case PFSuptime:
+       case PFSmounts:
                vap->va_bytes = vap->va_size = 0;
                break;
        case PFSmap:



Home | Main Index | Thread Index | Old Index