kernel/linprocfs: Implement /proc/devices.
authorSascha Wildner <saw@online.de>
Sat, 25 Aug 2012 20:48:12 +0000 (22:48 +0200)
committerSascha Wildner <saw@online.de>
Sun, 26 Aug 2012 10:31:35 +0000 (12:31 +0200)
As close to Linux' format as I could get, and enough to make LSI's
MegaCli utility (for RAID configuration) work with mfi(4).

sys/emulation/linux/i386/linprocfs/linprocfs_misc.c
sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c

index 7855f91..a2ab09d 100644 (file)
@@ -64,6 +64,7 @@
 #include <vm/swap_pager.h>
 #include <sys/vmmeter.h>
 #include <sys/exec.h>
+#include <sys/devfs.h>
 
 #include <machine/clock.h>
 #include <machine/cputypes.h>
@@ -670,11 +671,29 @@ linprocfs_donetdev(struct proc *curp, struct proc *p, struct pfsnode *pfs,
        return (error);
 }
 
+static void
+linprocfs_dodevices_callback(char *name, cdev_t dev, bool is_alias, void *arg)
+{
+       struct sbuf *sb = arg;
+
+       sbuf_printf(sb, "%3d %s\n", dev->si_umajor, name);
+}
+
 int
 linprocfs_dodevices(struct proc *curp, struct proc *p, struct pfsnode *pfs,
-                  struct uio *uio)
+    struct uio *uio)
 {
-       return 0;
+       struct sbuf *sb;
+       int error;
+
+       sb = sbuf_new_auto();
+       sbuf_printf(sb, "Character devices:\n");
+       devfs_scan_callback(linprocfs_dodevices_callback, sb);
+       sbuf_printf(sb, "\nBlock devices:\n");
+       sbuf_finish(sb);
+       error = uiomove_frombuf(sbuf_data(sb), sbuf_len(sb), uio);
+       sbuf_delete(sb);
+       return (error);
 }
 
 int
index ff2d48c..b076ac4 100644 (file)
@@ -863,6 +863,10 @@ linprocfs_lookup(struct vop_old_lookup_args *ap)
                        error = linprocfs_allocvp(dvp->v_mount, vpp, 0, Psys);
                        goto out;
                }
+               if (CNEQ(cnp, "devices", 7)) {
+                       error = linprocfs_allocvp(dvp->v_mount, vpp, 0, Pdevices);
+                       goto out;
+               }
 
                pid = atopid(pname, cnp->cn_namelen);
                if (pid == NO_PID)
@@ -1072,7 +1076,7 @@ linprocfs_readdir_root(struct vop_readdir_args *ap)
        info.uio = uio;
        info.cred = ap->a_cred;
 
-       while (info.pcnt < 12) {
+       while (info.pcnt < 13) {
                res = linprocfs_readdir_root_callback(NULL, &info);
                if (res < 0)
                        break;
@@ -1176,14 +1180,12 @@ linprocfs_readdir_root_callback(struct proc *p, void *data)
                d_name = "mounts";
                d_type = DT_DIR;
                break;
-#if 0
-       case 11:
+       case 12:
                d_ino = PROCFS_FILENO(0, Pdevices);
                d_namlen = 7;
                d_name = "devices";
                d_type = DT_REG;
                break;          
-#endif
        default:
                /*
                 * Ignore processes that aren't in our prison