From: Sascha Wildner Date: Sat, 25 Aug 2012 20:48:12 +0000 (+0200) Subject: kernel/linprocfs: Implement /proc/devices. X-Git-Tag: v3.2.0~255 X-Git-Url: http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/b5fa004e9a1f84a4a421f79c036c9fa6f8a862d2 kernel/linprocfs: Implement /proc/devices. As close to Linux' format as I could get, and enough to make LSI's MegaCli utility (for RAID configuration) work with mfi(4). --- diff --git a/sys/emulation/linux/i386/linprocfs/linprocfs_misc.c b/sys/emulation/linux/i386/linprocfs/linprocfs_misc.c index 7855f91..a2ab09d 100644 --- a/sys/emulation/linux/i386/linprocfs/linprocfs_misc.c +++ b/sys/emulation/linux/i386/linprocfs/linprocfs_misc.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c b/sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c index ff2d48c..b076ac4 100644 --- a/sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c +++ b/sys/emulation/linux/i386/linprocfs/linprocfs_vnops.c @@ -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