blob: 0f354a025039e4ca84b2cc65021608e89a6d8b18 [file] [log] [blame]
Erik Andersen47d3bb32000-03-08 06:52:04 +00001diff -ur --new-file linux-2.2.15-pre13.virgin/arch/alpha/defconfig linux/arch/alpha/defconfig
2--- linux-2.2.15-pre13.virgin/arch/alpha/defconfig Tue Jan 4 11:12:10 2000
3+++ linux/arch/alpha/defconfig Tue Mar 7 19:57:29 2000
4@@ -239,6 +239,9 @@
5 # CONFIG_SERIAL_CONSOLE is not set
6 # CONFIG_SERIAL_EXTENDED is not set
7 # CONFIG_SERIAL_NONSTANDARD is not set
8+# CONFIG_DEVPS is not set
9+# CONFIG_DEVMTAB is not set
10+# CONFIG_DEVMODULES is not set
11 CONFIG_UNIX98_PTYS=y
12 CONFIG_UNIX98_PTY_COUNT=256
13 CONFIG_MOUSE=y
14diff -ur --new-file linux-2.2.15-pre13.virgin/arch/arm/defconfig linux/arch/arm/defconfig
15--- linux-2.2.15-pre13.virgin/arch/arm/defconfig Thu Feb 25 11:46:46 1999
16+++ linux/arch/arm/defconfig Tue Mar 7 20:01:46 2000
17@@ -156,6 +156,10 @@
18 CONFIG_SCSI_PPA=m
19 CONFIG_SCSI_PPA_HAVE_PEDANTIC=2
20
21+# CONFIG_DEVPS is not set
22+# CONFIG_DEVMTAB is not set
23+# CONFIG_DEVMODULES is not set
24+
25 #
26 # Network device support
27 #
28diff -ur --new-file linux-2.2.15-pre13.virgin/arch/i386/defconfig linux/arch/i386/defconfig
29--- linux-2.2.15-pre13.virgin/arch/i386/defconfig Tue Mar 7 19:46:57 2000
30+++ linux/arch/i386/defconfig Tue Mar 7 19:57:40 2000
31@@ -300,6 +300,9 @@
32 # CONFIG_SERIAL_CONSOLE is not set
33 # CONFIG_SERIAL_EXTENDED is not set
34 # CONFIG_SERIAL_NONSTANDARD is not set
35+# CONFIG_DEVPS is not set
36+# CONFIG_DEVMTAB is not set
37+# CONFIG_DEVMODULES is not set
38 CONFIG_UNIX98_PTYS=y
39 CONFIG_UNIX98_PTY_COUNT=256
40 CONFIG_MOUSE=y
41diff -ur --new-file linux-2.2.15-pre13.virgin/arch/i386/kernel/Makefile linux/arch/i386/kernel/Makefile
42--- linux-2.2.15-pre13.virgin/arch/i386/kernel/Makefile Wed Jan 20 11:18:53 1999
43+++ linux/arch/i386/kernel/Makefile Tue Mar 7 19:52:45 2000
44@@ -14,8 +14,8 @@
45
46 O_TARGET := kernel.o
47 O_OBJS := process.o signal.o entry.o traps.o irq.o vm86.o \
48- ptrace.o ioport.o ldt.o setup.o time.o sys_i386.o
49-OX_OBJS := i386_ksyms.o
50+ ptrace.o ioport.o ldt.o time.o sys_i386.o
51+OX_OBJS := i386_ksyms.o setup.o
52 MX_OBJS :=
53
54 ifdef CONFIG_PCI
55diff -ur --new-file linux-2.2.15-pre13.virgin/arch/m68k/defconfig linux/arch/m68k/defconfig
56--- linux-2.2.15-pre13.virgin/arch/m68k/defconfig Thu Feb 25 11:46:46 1999
57+++ linux/arch/m68k/defconfig Tue Mar 7 19:58:10 2000
58@@ -223,6 +223,9 @@
59 CONFIG_AMIGAMOUSE=y
60 CONFIG_ATARIMOUSE=y
61 CONFIG_AMIGA_BUILTIN_SERIAL=y
62+# CONFIG_DEVPS is not set
63+# CONFIG_DEVMTAB is not set
64+# CONFIG_DEVMODULES is not set
65 # CONFIG_GVPIOEXT is not set
66 # CONFIG_GVPIOEXT_LP is not set
67 # CONFIG_GVPIOEXT_PLIP is not set
68diff -ur --new-file linux-2.2.15-pre13.virgin/arch/mips/defconfig linux/arch/mips/defconfig
69--- linux-2.2.15-pre13.virgin/arch/mips/defconfig Mon Aug 9 13:04:38 1999
70+++ linux/arch/mips/defconfig Tue Mar 7 19:58:30 2000
71@@ -252,6 +252,9 @@
72 CONFIG_SERIAL=m
73 # CONFIG_SERIAL_EXTENDED is not set
74 # CONFIG_SERIAL_NONSTANDARD is not set
75+# CONFIG_DEVPS is not set
76+# CONFIG_DEVMTAB is not set
77+# CONFIG_DEVMODULES is not set
78 # CONFIG_UNIX98_PTYS is not set
79 # CONFIG_MOUSE is not set
80 # CONFIG_QIC02_TAPE is not set
81diff -ur --new-file linux-2.2.15-pre13.virgin/arch/ppc/apus_defconfig linux/arch/ppc/apus_defconfig
82--- linux-2.2.15-pre13.virgin/arch/ppc/apus_defconfig Thu Feb 25 11:46:47 1999
83+++ linux/arch/ppc/apus_defconfig Tue Mar 7 19:59:14 2000
84@@ -303,6 +303,9 @@
85 CONFIG_SERIAL=m
86 # CONFIG_SERIAL_EXTENDED is not set
87 # CONFIG_SERIAL_NONSTANDARD is not set
88+# CONFIG_DEVPS is not set
89+# CONFIG_DEVMTAB is not set
90+# CONFIG_DEVMODULES is not set
91 CONFIG_UNIX98_PTYS=y
92 CONFIG_UNIX98_PTY_COUNT=256
93 # CONFIG_MOUSE is not set
94diff -ur --new-file linux-2.2.15-pre13.virgin/arch/ppc/chrp_defconfig linux/arch/ppc/chrp_defconfig
95--- linux-2.2.15-pre13.virgin/arch/ppc/chrp_defconfig Thu Feb 25 11:46:47 1999
96+++ linux/arch/ppc/chrp_defconfig Tue Mar 7 19:58:57 2000
97@@ -261,6 +261,9 @@
98 # CONFIG_SERIAL_CONSOLE is not set
99 # CONFIG_SERIAL_EXTENDED is not set
100 # CONFIG_SERIAL_NONSTANDARD is not set
101+# CONFIG_DEVPS is not set
102+# CONFIG_DEVMTAB is not set
103+# CONFIG_DEVMODULES is not set
104 # CONFIG_UNIX98_PTYS is not set
105 # CONFIG_MOUSE is not set
106 # CONFIG_UMISC is not set
107diff -ur --new-file linux-2.2.15-pre13.virgin/arch/ppc/common_defconfig linux/arch/ppc/common_defconfig
108--- linux-2.2.15-pre13.virgin/arch/ppc/common_defconfig Tue Jan 4 11:12:12 2000
109+++ linux/arch/ppc/common_defconfig Tue Mar 7 19:59:35 2000
110@@ -337,6 +337,9 @@
111 CONFIG_SERIAL=m
112 # CONFIG_SERIAL_EXTENDED is not set
113 # CONFIG_SERIAL_NONSTANDARD is not set
114+# CONFIG_DEVPS is not set
115+# CONFIG_DEVMTAB is not set
116+# CONFIG_DEVMODULES is not set
117 CONFIG_UNIX98_PTYS=y
118 CONFIG_UNIX98_PTY_COUNT=256
119 CONFIG_MOUSE=y
120diff -ur --new-file linux-2.2.15-pre13.virgin/arch/ppc/defconfig linux/arch/ppc/defconfig
121--- linux-2.2.15-pre13.virgin/arch/ppc/defconfig Tue Jan 4 11:12:12 2000
122+++ linux/arch/ppc/defconfig Tue Mar 7 19:58:43 2000
123@@ -337,6 +337,9 @@
124 CONFIG_SERIAL=m
125 # CONFIG_SERIAL_EXTENDED is not set
126 # CONFIG_SERIAL_NONSTANDARD is not set
127+# CONFIG_DEVPS is not set
128+# CONFIG_DEVMTAB is not set
129+# CONFIG_DEVMODULES is not set
130 CONFIG_UNIX98_PTYS=y
131 CONFIG_UNIX98_PTY_COUNT=256
132 CONFIG_MOUSE=y
133diff -ur --new-file linux-2.2.15-pre13.virgin/arch/ppc/gemini_defconfig linux/arch/ppc/gemini_defconfig
134--- linux-2.2.15-pre13.virgin/arch/ppc/gemini_defconfig Tue Jan 4 11:12:12 2000
135+++ linux/arch/ppc/gemini_defconfig Tue Mar 7 19:59:23 2000
136@@ -285,6 +285,9 @@
137 CONFIG_SERIAL_CONSOLE=y
138 # CONFIG_SERIAL_EXTENDED is not set
139 # CONFIG_SERIAL_NONSTANDARD is not set
140+# CONFIG_DEVPS is not set
141+# CONFIG_DEVMTAB is not set
142+# CONFIG_DEVMODULES is not set
143 CONFIG_UNIX98_PTYS=y
144 CONFIG_UNIX98_PTY_COUNT=256
145 # CONFIG_MOUSE is not set
146diff -ur --new-file linux-2.2.15-pre13.virgin/arch/ppc/mbx_defconfig linux/arch/ppc/mbx_defconfig
147--- linux-2.2.15-pre13.virgin/arch/ppc/mbx_defconfig Wed Mar 10 22:30:32 1999
148+++ linux/arch/ppc/mbx_defconfig Tue Mar 7 19:59:49 2000
149@@ -192,6 +192,9 @@
150 CONFIG_SERIAL_CONSOLE=y
151 # CONFIG_SERIAL_EXTENDED is not set
152 # CONFIG_SERIAL_NONSTANDARD is not set
153+# CONFIG_DEVPS is not set
154+# CONFIG_DEVMTAB is not set
155+# CONFIG_DEVMODULES is not set
156 # CONFIG_UNIX98_PTYS is not set
157 # CONFIG_MOUSE is not set
158 # CONFIG_QIC02_TAPE is not set
159diff -ur --new-file linux-2.2.15-pre13.virgin/arch/ppc/pmac_defconfig linux/arch/ppc/pmac_defconfig
160--- linux-2.2.15-pre13.virgin/arch/ppc/pmac_defconfig Tue Oct 26 18:53:39 1999
161+++ linux/arch/ppc/pmac_defconfig Tue Mar 7 19:59:59 2000
162@@ -368,6 +368,9 @@
163 # CONFIG_SERIAL is not set
164 # CONFIG_SERIAL_EXTENDED is not set
165 # CONFIG_SERIAL_NONSTANDARD is not set
166+# CONFIG_DEVPS is not set
167+# CONFIG_DEVMTAB is not set
168+# CONFIG_DEVMODULES is not set
169 CONFIG_UNIX98_PTYS=y
170 CONFIG_UNIX98_PTY_COUNT=256
171 # CONFIG_PRINTER is not set
172diff -ur --new-file linux-2.2.15-pre13.virgin/arch/s390/defconfig linux/arch/s390/defconfig
173--- linux-2.2.15-pre13.virgin/arch/s390/defconfig Tue Mar 7 19:46:57 2000
174+++ linux/arch/s390/defconfig Tue Mar 7 20:02:36 2000
175@@ -64,6 +64,9 @@
176 CONFIG_3215_CONSOLE=y
177 CONFIG_HWC=y
178 CONFIG_HWC_CONSOLE=y
179+# CONFIG_DEVPS is not set
180+# CONFIG_DEVMTAB is not set
181+# CONFIG_DEVMODULES is not set
182
183 #
184 # Networking options
185diff -ur --new-file linux-2.2.15-pre13.virgin/arch/sparc/defconfig linux/arch/sparc/defconfig
186--- linux-2.2.15-pre13.virgin/arch/sparc/defconfig Tue Mar 7 19:46:57 2000
187+++ linux/arch/sparc/defconfig Tue Mar 7 20:01:00 2000
188@@ -219,6 +219,10 @@
189 CONFIG_SUNQE=m
190 CONFIG_MYRI_SBUS=m
191
192+# CONFIG_DEVPS is not set
193+# CONFIG_DEVMTAB is not set
194+# CONFIG_DEVMODULES is not set
195+
196 #
197 # Unix98 PTY support
198 #
199diff -ur --new-file linux-2.2.15-pre13.virgin/arch/sparc64/defconfig linux/arch/sparc64/defconfig
200--- linux-2.2.15-pre13.virgin/arch/sparc64/defconfig Tue Mar 7 19:46:57 2000
201+++ linux/arch/sparc64/defconfig Tue Mar 7 20:01:16 2000
202@@ -262,6 +262,10 @@
203 CONFIG_EEXPRESS_PRO100=m
204 CONFIG_SK98LIN=m
205
206+# CONFIG_DEVPS is not set
207+# CONFIG_DEVMTAB is not set
208+# CONFIG_DEVMODULES is not set
209+
210 #
211 # Unix 98 PTY support
212 #
213diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/Config.in linux/drivers/char/Config.in
214--- linux-2.2.15-pre13.virgin/drivers/char/Config.in Tue Mar 7 19:46:58 2000
215+++ linux/drivers/char/Config.in Tue Mar 7 19:52:45 2000
216@@ -56,6 +56,9 @@
217 dep_tristate 'Microgate SyncLink card support' CONFIG_SYNCLINK m
218 dep_tristate 'HDLC line discipline support' CONFIG_N_HDLC m
219 fi
220+tristate 'Devps support' CONFIG_DEVPS
221+tristate 'Devmounts support' CONFIG_DEVMTAB
222+tristate 'Devmodules support' CONFIG_DEVMODULES
223 bool 'Unix98 PTY support' CONFIG_UNIX98_PTYS
224 if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then
225 int 'Maximum number of Unix98 PTYs in use (0-2048)' CONFIG_UNIX98_PTY_COUNT 256
226diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/Makefile linux/drivers/char/Makefile
227--- linux-2.2.15-pre13.virgin/drivers/char/Makefile Tue Mar 7 19:46:58 2000
228+++ linux/drivers/char/Makefile Tue Mar 7 19:52:45 2000
229@@ -620,6 +620,30 @@
230 L_OBJS += dz.o
231 endif
232
233+ifeq ($(CONFIG_DEVPS),y)
234+L_OBJS += devps.o
235+else
236+ ifeq ($(CONFIG_DEVPS),m)
237+ M_OBJS += devps.o
238+ endif
239+endif
240+
241+ifeq ($(CONFIG_DEVMTAB),y)
242+L_OBJS += devmtab.o
243+else
244+ ifeq ($(CONFIG_DEVMTAB),m)
245+ M_OBJS += devmtab.o
246+ endif
247+endif
248+
249+ifeq ($(CONFIG_DEVMODULES),y)
250+L_OBJS += devmodules.o
251+else
252+ ifeq ($(CONFIG_DEVMODULES),m)
253+ M_OBJS += devmodules.o
254+ endif
255+endif
256+
257 include $(TOPDIR)/Rules.make
258
259 fastdep:
260diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/devmodules.c linux/drivers/char/devmodules.c
261--- linux-2.2.15-pre13.virgin/drivers/char/devmodules.c Wed Dec 31 17:00:00 1969
262+++ linux/drivers/char/devmodules.c Tue Mar 7 22:37:42 2000
263@@ -0,0 +1,270 @@
264+/* vi: set sw=8 ts=8: */
265+/*
266+ * linux/drivers/char/devmodules.c
267+ *
268+ * Copyright (C) 2000 Erik Andersen <andersee@debian.org>
269+ *
270+ * May be copied or modified under the terms of the GNU General Public License.
271+ * See linux/COPYING for more information.
272+ *
273+ * This driver implements an interface whereby programs such as lsmod(8) may
274+ * obtain all the information they need to do their jobs. Now you may ask,
275+ * "Why not use /proc/modules?". Thanks for asking. Because /proc is big and
276+ * bloated, and because using this driver we can avoid all that bloat and avoid
277+ * having the kernel need to pretty print stuff and avoid having user-space
278+ * then have to parse the stuff the kernel wasted its time formatting.
279+ *
280+ *
281+ * Suggestions are welcome. Patches that work are more welcome though. ;-)
282+ *
283+ * When using this driver, running:
284+ * mknod /dev/modules c 10 23
285+ * could be considered helpful.
286+ *
287+ * ----------------------------------
288+ * 1.00 Mar 07, 2000 -- Initial version.
289+ *
290+ *
291+ *************************************************************************/
292+
293+#define DEVMODULES_VERSION "1.00"
294+
295+#include <linux/config.h>
296+#include <linux/module.h>
297+#include <linux/types.h>
298+#include <linux/sched.h>
299+#include <linux/fs.h>
300+#include <linux/mm.h>
301+#include <linux/pagemap.h>
302+#include <linux/malloc.h>
303+#include <linux/miscdevice.h>
304+#include <linux/devmodules.h>
305+#include <linux/wrapper.h>
306+#include <asm/pgtable.h>
307+#include <asm/uaccess.h>
308+
309+
310+/* Some variables used by this device */
311+static struct wait_queue *devmodules_waitq = NULL;
312+static int devmodules_already_opened = 0;
313+static char *devmodulesfile = NULL;
314+static int devmodules_ptr;
315+static int devmodules_size;
316+
317+
318+
319+/****************************************************************************
320+ * Handle opening and closing of the device
321+ */
322+
323+static long long
324+devmodules_lseek (struct file *file, long long offset, int orig)
325+{
326+ return -ESPIPE;
327+}
328+
329+static ssize_t
330+devmodules_read (struct file *file, char *buf, size_t count, loff_t * ppos)
331+{
332+ int n = devmodules_size - devmodules_ptr;
333+
334+ if (devmodules_size == 0) {
335+ /* Make some space */
336+ if (!(devmodulesfile = (char *) get_free_page (GFP_KERNEL)))
337+ return -ENOMEM;
338+ /* Grab the module list */
339+ get_module_list (devmodulesfile);
340+ devmodules_ptr = 0;
341+ devmodules_size = strlen (devmodulesfile);
342+ n = devmodules_size - devmodules_ptr;
343+ }
344+
345+ if (n > count)
346+ n = count;
347+ if (n <= 0)
348+ return 0;
349+
350+ if (copy_to_user (buf, devmodulesfile, n))
351+ return -EFAULT;
352+ devmodules_ptr += n;
353+ return n;
354+}
355+
356+static int devmodules_open (struct inode *ip, struct file *fp)
357+{
358+ /* Only let one process use us at any time -- putting other
359+ * processes to sleep. Those opening us O_NONBLOCK will
360+ * get an EAGAIN error */
361+ if ((fp->f_flags & O_NONBLOCK) && devmodules_already_opened)
362+ return -EAGAIN;
363+
364+ MOD_INC_USE_COUNT;
365+
366+ while (devmodules_already_opened) {
367+ int i, got_signal=0;
368+
369+ /* Go to sleep until we get woken up
370+ * by devmodules_close or we receive a signal */
371+ module_interruptible_sleep_on(&devmodules_waitq);
372+
373+ for(i=0; i<_NSIG_WORDS && !got_signal; i++)
374+ got_signal = current->signal.sig[i] & ~current->blocked.sig[i];
375+
376+ /* If we got a signal, decrement the use count
377+ * and return to user space */
378+ if (got_signal) {
379+ MOD_DEC_USE_COUNT;
380+ return -EINTR;
381+ }
382+ }
383+
384+ /* Since we got here, then devmodules_already_opened must equal 0 */
385+ devmodules_already_opened=1;
386+ devmodules_ptr = 0;
387+ devmodules_size = 0;
388+
389+ return 0;
390+}
391+
392+static int devmodules_release (struct inode *ip, struct file *fp)
393+{
394+ /* Clean up */
395+ if (devmodulesfile != NULL) {
396+ free_page ((unsigned long) devmodulesfile);
397+ devmodulesfile = NULL;
398+ }
399+
400+ /* Zero out the reference counter */
401+ devmodules_already_opened=0;
402+
403+ /* Wake up anybody that is waiting to access this device */
404+ module_wake_up(&devmodules_waitq);
405+
406+ MOD_DEC_USE_COUNT;
407+
408+ return 0;
409+}
410+
411+static int
412+devmodules_ioctl (struct inode *ip, struct file *fp,
413+ unsigned int cmd, unsigned long arg)
414+{
415+ switch (cmd) {
416+
417+ case DEVMODULES_COUNT_MODULES:{
418+#ifdef CONFIG_MODULES
419+ return(count_kmodules());
420+#else
421+ return -ENOSYS;
422+#endif
423+ }
424+
425+ case DEVMODULES_GET_MODULES_LIST:{
426+#if !defined CONFIG_MODULES
427+ return -ENOSYS;
428+#else
429+
430+ int stat, count;
431+ struct k_module_item* module_list;
432+
433+
434+ /* How many are there? */
435+ count = count_kmodules();
436+
437+ /* Make some space */
438+ module_list = (struct k_module_item *)kmalloc(sizeof(struct k_module_item) * count, GFP_KERNEL);
439+ if (!module_list)
440+ return -ENOMEM;
441+ memset(module_list, 0, sizeof(struct k_module_item) * count);
442+
443+ /* Grab the list of modules */
444+ get_kmodule_list(count, module_list);
445+
446+ /* Make sure there is enough room */
447+ stat = verify_area (VERIFY_WRITE, (struct k_module_item *) arg,
448+ sizeof(struct k_module_item) * count);
449+ if (stat) {
450+ printk (KERN_INFO
451+ "devmodules: Insufficient space was provided.\n");
452+ return stat;
453+ }
454+
455+ /* Send it to user space */
456+ copy_to_user_ret ((struct k_module_item *) arg, module_list,
457+ sizeof(struct k_module_item) * count,
458+ -EFAULT);
459+
460+ /* Clean up */
461+ kfree( module_list);
462+ return 0;
463+#endif
464+ }
465+
466+ default:
467+ return -EINVAL;
468+
469+ }
470+ return 0;
471+}
472+
473+
474+
475+/****************************************************************************
476+ * Set up the file operations devmodules will support
477+ */
478+static struct file_operations devmodules_fops = {
479+ devmodules_lseek,
480+ devmodules_read,
481+ NULL, /* No write */
482+ NULL, /* No readdir */
483+ NULL, /* No poll */
484+ devmodules_ioctl,
485+ NULL, /* No mmap */
486+ devmodules_open,
487+ NULL, /* flush */
488+ devmodules_release,
489+ NULL, /* fsync */
490+ NULL, /* fasync */
491+ NULL, /* check_media_change */
492+ NULL /* revalidate */
493+};
494+
495+static struct miscdevice devmodules_misc_dev = {
496+ DEVMODULES_MINOR,
497+ "devmodules",
498+ &devmodules_fops
499+};
500+
501+/* The real driver initialization function */
502+extern int devmodules_init (void)
503+{
504+ printk (KERN_INFO "devmodules: driver %s loaded\n", DEVMODULES_VERSION);
505+
506+ if (misc_register (&devmodules_misc_dev)) {
507+ printk ("devmodules: can't register misc device %d\n",
508+ DEVMODULES_MINOR);
509+ return -EIO;
510+ }
511+
512+ return 0;
513+}
514+
515+#ifdef MODULE
516+
517+MODULE_AUTHOR ("Erik Andersen <andersee@debian.org>");
518+MODULE_DESCRIPTION
519+ ("devmodules driver -- exports filesystem and mount information to user space");
520+
521+/* Stub driver initialization function */
522+int init_module (void)
523+{
524+ return (devmodules_init ());
525+}
526+
527+void cleanup_module (void)
528+{
529+ printk (KERN_INFO "devmodules: driver unloaded\n");
530+ misc_deregister (&devmodules_misc_dev);
531+}
532+
533+#endif /* MODULE */
534diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/devmtab.c linux/drivers/char/devmtab.c
535--- linux-2.2.15-pre13.virgin/drivers/char/devmtab.c Wed Dec 31 17:00:00 1969
536+++ linux/drivers/char/devmtab.c Tue Mar 7 19:52:45 2000
537@@ -0,0 +1,304 @@
538+/* vi: set sw=8 ts=8: */
539+/*
540+ * linux/drivers/char/devmtab.c
541+ *
542+ * Copyright (C) 2000 Erik Andersen <andersee@debian.org>
543+ *
544+ * May be copied or modified under the terms of the GNU General Public License.
545+ * See linux/COPYING for more information.
546+ *
547+ * This driver implements an interface whereby programs such as mount(8),
548+ * umount(8), and df(1) may obtain all the process information they need to do
549+ * their jobs without needing to use /proc. This driver another step in my
550+ * evil plan to completely dismantle /proc. Muhahahaha!
551+ *
552+ * Suggestions are welcome. Patches that work are more welcome though. ;-)
553+ *
554+ *
555+ * When using this driver, running:
556+ * mknod /dev/mtab c 10 22
557+ * could be considered helpful.
558+ *
559+ * ----------------------------------
560+ * 1.00 Mar 07, 2000 -- Initial version.
561+ *
562+ *************************************************************************/
563+
564+#define DEVMTAB_VERSION "1.00"
565+
566+#include <linux/config.h>
567+#include <linux/module.h>
568+#include <linux/types.h>
569+#include <linux/sched.h>
570+#include <linux/fs.h>
571+#include <linux/mm.h>
572+#include <linux/pagemap.h>
573+#include <linux/malloc.h>
574+#include <linux/miscdevice.h>
575+#include <linux/devmtab.h>
576+#include <linux/wrapper.h>
577+#include <asm/pgtable.h>
578+#include <asm/uaccess.h>
579+
580+
581+/* Some variables used by this device */
582+static struct wait_queue *devmtab_waitq = NULL;
583+static int devmtab_already_opened = 0;
584+static char *mtabfile = NULL;
585+static int mtab_ptr;
586+static int mtab_size;
587+
588+
589+
590+/****************************************************************************
591+ * Handle opening and closing of the device
592+ */
593+
594+static long long
595+devmtab_lseek (struct file *file, long long offset, int orig)
596+{
597+ return -ESPIPE;
598+}
599+
600+static ssize_t
601+devmtab_read (struct file *file, char *buf, size_t count, loff_t * ppos)
602+{
603+ int n = mtab_size - mtab_ptr;
604+
605+ if (mtab_size == 0) {
606+ /* Make some space */
607+ if (!(mtabfile = (char *) get_free_page (GFP_KERNEL)))
608+ return -ENOMEM;
609+ /* Grab the mtab */
610+ get_filesystem_info (mtabfile);
611+ mtab_ptr = 0;
612+ mtab_size = strlen (mtabfile);
613+ n = mtab_size - mtab_ptr;
614+ }
615+
616+ if (n > count)
617+ n = count;
618+ if (n <= 0)
619+ return 0;
620+
621+ if (copy_to_user (buf, mtabfile, n))
622+ return -EFAULT;
623+ mtab_ptr += n;
624+ return n;
625+}
626+
627+static int devmtab_open (struct inode *ip, struct file *fp)
628+{
629+ /* Only let one process use us at any time -- putting other
630+ * processes to sleep. Those opening us O_NONBLOCK will
631+ * get an EAGAIN error */
632+ if ((fp->f_flags & O_NONBLOCK) && devmtab_already_opened)
633+ return -EAGAIN;
634+
635+ MOD_INC_USE_COUNT;
636+
637+ while (devmtab_already_opened) {
638+ int i, got_signal=0;
639+
640+ /* Go to sleep until we get woken up
641+ * by devmtab_close or we receive a signal */
642+ module_interruptible_sleep_on(&devmtab_waitq);
643+
644+ for(i=0; i<_NSIG_WORDS && !got_signal; i++)
645+ got_signal = current->signal.sig[i] & ~current->blocked.sig[i];
646+
647+ /* If we got a signal, decrement the use count
648+ * and return to user space */
649+ if (got_signal) {
650+ MOD_DEC_USE_COUNT;
651+ return -EINTR;
652+ }
653+ }
654+
655+ /* Since we got here, then devmtab_already_opened must equal 0 */
656+ devmtab_already_opened=1;
657+ mtab_ptr = 0;
658+ mtab_size = 0;
659+
660+ return 0;
661+}
662+
663+static int devmtab_release (struct inode *ip, struct file *fp)
664+{
665+ /* Clean up */
666+ if (mtabfile != NULL) {
667+ free_page ((unsigned long) mtabfile);
668+ mtabfile = NULL;
669+ }
670+
671+ /* Zero out the reference counter */
672+ devmtab_already_opened=0;
673+
674+ /* Wake up anybody that is waiting to access this device */
675+ module_wake_up(&devmtab_waitq);
676+
677+ MOD_DEC_USE_COUNT;
678+
679+ return 0;
680+}
681+
682+static int
683+devmtab_ioctl (struct inode *ip, struct file *fp,
684+ unsigned int cmd, unsigned long arg)
685+{
686+ switch (cmd) {
687+ case DEVMTAB_COUNT_FILESYSTEMS:{
688+ return(count_kfstypes());
689+ }
690+
691+ case DEVMTAB_GET_FILESYSTEMS:{
692+ int stat, count;
693+ struct k_fstype* fstypelist;
694+
695+ /* How many are there? */
696+ count = count_kfstypes();
697+
698+ /* Make some space */
699+ fstypelist = (struct k_fstype *)kmalloc(sizeof(struct k_fstype) * count, GFP_KERNEL);
700+ if (!fstypelist)
701+ return -ENOMEM;
702+ memset(fstypelist, 0, sizeof(struct k_fstype) * count);
703+
704+ /* Grab the mtab entries */
705+ get_kfstype_list(count, fstypelist);
706+
707+ /* Make sure there is enough room */
708+ stat = verify_area (VERIFY_WRITE, (struct k_fstype *) arg,
709+ sizeof(struct k_fstype) * count);
710+ if (stat) {
711+ printk (KERN_INFO
712+ "devmtab: Insufficient space was provided.\n");
713+ return stat;
714+ }
715+
716+ /* Send it to user space */
717+ copy_to_user_ret ((struct k_fstype *) arg, fstypelist,
718+ sizeof(struct k_fstype) * count,
719+ -EFAULT);
720+
721+ /* Clean up */
722+ kfree( fstypelist);
723+ return 0;
724+ }
725+
726+ case DEVMTAB_COUNT_MOUNTS:{
727+ return(count_mounted_filesystems());
728+ }
729+
730+ case DEVMTAB_GET_MOUNTS:{
731+ int stat, count;
732+ struct k_mntent* mntentlist;
733+
734+ /* How many are there? */
735+ count = count_mounted_filesystems();
736+
737+ /* Make some space */
738+ mntentlist = (struct k_mntent *)kmalloc(sizeof(struct k_mntent) * count, GFP_KERNEL);
739+ if (!mntentlist)
740+ return -ENOMEM;
741+ memset(mntentlist, 0, sizeof(struct k_mntent) * count);
742+
743+ /* Grab the mtab entries */
744+ get_mtab_entries (count, mntentlist);
745+
746+ /* Make sure there is enough room */
747+ stat = verify_area (VERIFY_WRITE, (void*) arg,
748+ sizeof(struct k_mntent) * count);
749+ if (stat) {
750+ printk (KERN_INFO
751+ "devmtab: Insufficient space was provided.\n");
752+ return stat;
753+ }
754+
755+ /* Send it to user space */
756+ copy_to_user_ret ((struct k_mntent *) arg, mntentlist,
757+ sizeof(struct k_mntent) * count,
758+ -EFAULT);
759+
760+ /* Clean up */
761+ kfree( mntentlist);
762+ return 0;
763+ }
764+
765+ case DEVMTAB_SET_ROOTFS_DEVNAME:{
766+ char rootdevname[256];
767+
768+ copy_from_user_ret (rootdevname, (char*) arg,
769+ sizeof(rootdevname), -EFAULT);
770+ return( set_root_filesystem_name( rootdevname));
771+ }
772+
773+
774+ default:
775+ return -EINVAL;
776+
777+ }
778+ return 0;
779+}
780+
781+
782+
783+/****************************************************************************
784+ * Set up the file operations devmtab will support
785+ */
786+static struct file_operations devmtab_fops = {
787+ devmtab_lseek,
788+ devmtab_read,
789+ NULL, /* No write */
790+ NULL, /* No readdir */
791+ NULL, /* No poll */
792+ devmtab_ioctl,
793+ NULL, /* No mmap */
794+ devmtab_open,
795+ NULL, /* flush */
796+ devmtab_release,
797+ NULL, /* fsync */
798+ NULL, /* fasync */
799+ NULL, /* check_media_change */
800+ NULL /* revalidate */
801+};
802+
803+static struct miscdevice devmtab_misc_dev = {
804+ DEVMTAB_MINOR,
805+ "devmtab",
806+ &devmtab_fops
807+};
808+
809+/* The real driver initialization function */
810+extern int devmtab_init (void)
811+{
812+ printk (KERN_INFO "devmtab: driver %s loaded\n", DEVMTAB_VERSION);
813+
814+ if (misc_register (&devmtab_misc_dev)) {
815+ printk ("devmtab: can't register misc device %d\n",
816+ DEVMTAB_MINOR);
817+ return -EIO;
818+ }
819+
820+ return 0;
821+}
822+
823+#ifdef MODULE
824+
825+MODULE_AUTHOR ("Erik Andersen <andersee@debian.org>");
826+MODULE_DESCRIPTION
827+ ("devmtab driver -- exports filesystem and mount information to user space");
828+
829+/* Stub driver initialization function */
830+int init_module (void)
831+{
832+ return (devmtab_init ());
833+}
834+
835+void cleanup_module (void)
836+{
837+ printk (KERN_INFO "devmtab: driver unloaded\n");
838+ misc_deregister (&devmtab_misc_dev);
839+}
840+
841+#endif /* MODULE */
842diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/devps.c linux/drivers/char/devps.c
843--- linux-2.2.15-pre13.virgin/drivers/char/devps.c Wed Dec 31 17:00:00 1969
844+++ linux/drivers/char/devps.c Tue Mar 7 19:52:45 2000
845@@ -0,0 +1,518 @@
846+/* vi: set sw=8 ts=8: */
847+/*
848+ * linux/drivers/char/devps.c
849+ *
850+ * Copyright (C) 2000 Erik Andersen <andersee@debian.org>
851+ *
852+ * May be copied or modified under the terms of the GNU General Public License.
853+ * See linux/COPYING for more information.
854+ *
855+ * This driver implements an interface whereby programs such as ps(1), top(1),
856+ * killall(1) and the like may obtain all the process information they need to
857+ * do their jobs. Now you may ask, "Why not use /proc? BSD uses /proc.".
858+ * Thanks for asking. /proc is designed as a virtual filesystem. As such it
859+ * presents all of its information in a nice, human readable format. But not
860+ * human readable enough that mere mortals can actually look at the /proc
861+ * information and know what is happening on their computer (which is why we
862+ * have nice programs like ps(1) to help us out. Additionally, for ps (using
863+ * /proc) to do its job, it has to do something like:
864+ *
865+ * dir = opendir("/proc");
866+ * while ((entry = readdir(dir)) != NULL) {
867+ * if (!isdigit(*entry->d_name))
868+ * continue;
869+ * open_lots_of files();
870+ * parse_lots_of_strings();
871+ * close_lots_of_files();
872+ * print_stuff();
873+ * }
874+ *
875+ *
876+ * This is bad, because:
877+ *
878+ * 1) opening and closing lots of files is slow,
879+ *
880+ * 2) parsing lots of strings is slow,
881+ *
882+ * 3) every one of those strings had to be carefully printed out and formatted
883+ * by the kernel, which is slow,
884+ *
885+ * 4) using a virtual filesystem is not the traditional UN*X solution to
886+ * getting information from the kernel out to userspace (ioctls and syscalls
887+ * are the established way to do this), and worst of all
888+ *
889+ * 5) having a virtual filesystem around has been so inviting that everyone has
890+ * put their own weird little files into it, causing /proc to become a
891+ * cluttered rubbish heap of 64 flavors of strange that takes a ridiculous
892+ * amount of memory.
893+ *
894+ * This driver is the first step in my evil plan to completely
895+ * dismantle /proc. Muhahahaha!
896+ *
897+ * Suggestions are welcome. Patches that work are more welcome though. ;-)
898+ *
899+ * When using this driver, running:
900+ * mknod /dev/ps c 10 21
901+ * could be considered helpful.
902+ *
903+ * ----------------------------------
904+ * 1.00 Mar 07, 2000 -- Initial version.
905+ *
906+ *
907+ * TODO
908+ * ----------------------------------
909+ *
910+ * * Right now none of the vm or fd info is being returned to user space.
911+ * * There is probably other stuff that should be exported to user space.
912+ *
913+ *
914+ *************************************************************************/
915+
916+#define DEVPS_VERSION "1.00"
917+
918+#include <linux/config.h>
919+#include <linux/module.h>
920+#include <linux/types.h>
921+#include <linux/sched.h>
922+#include <linux/fs.h>
923+#include <linux/mm.h>
924+#include <linux/pagemap.h>
925+#include <linux/malloc.h>
926+#include <linux/miscdevice.h>
927+#include <linux/devps.h>
928+#include <linux/wrapper.h>
929+#include <asm/pgtable.h>
930+#include <asm/uaccess.h>
931+
932+/* Some variables used by this device */
933+static struct wait_queue *devps_waitq = NULL;
934+static int devps_already_opened = 0;
935+
936+/****************************************************************************
937+ * Handle opening and closing of the device
938+ */
939+
940+static int devps_open (struct inode *ip, struct file *fp)
941+{
942+ /* Only let one process use us at any time -- putting other
943+ * processes to sleep. Those opening us O_NONBLOCK will
944+ * get an EAGAIN error */
945+ if ((fp->f_flags & O_NONBLOCK) && devps_already_opened)
946+ return -EAGAIN;
947+
948+ MOD_INC_USE_COUNT;
949+
950+ while (devps_already_opened) {
951+ int i, got_signal=0;
952+
953+ /* Go to sleep until we get woken up
954+ * by devps_close or we receive a signal */
955+ module_interruptible_sleep_on(&devps_waitq);
956+
957+ for(i=0; i<_NSIG_WORDS && !got_signal; i++)
958+ got_signal = current->signal.sig[i] & ~current->blocked.sig[i];
959+
960+ /* If we got a signal, decrement the use count
961+ * and return to user space */
962+ if (got_signal) {
963+ MOD_DEC_USE_COUNT;
964+ return -EINTR;
965+ }
966+ }
967+
968+ /* Since we got here, then device_already_opened must equal 0 */
969+ devps_already_opened=1;
970+ return 0;
971+}
972+
973+static int devps_release (struct inode *ip, struct file *fp)
974+{
975+ /* Zero out the reference counter */
976+ devps_already_opened=0;
977+
978+ /* Wake up anybody that is waiting to access this device */
979+ module_wake_up(&devps_waitq);
980+
981+ MOD_DEC_USE_COUNT;
982+ return 0;
983+}
984+
985+
986+/*
987+ * This pretty-prints the pathname of a dentry,
988+ * clarifying sockets etc.
989+ */
990+static int
991+get_name_from_dentry (struct dentry *dentry, char *buffer, int buflen)
992+{
993+ struct inode *inode;
994+ char *tmp = (char *) __get_free_page (GFP_KERNEL), *path, *pattern;
995+ int len;
996+
997+ if (tmp == NULL)
998+ return -ENOMEM;
999+
1000+ /* Check for special dentries.. */
1001+ pattern = NULL;
1002+ inode = dentry->d_inode;
1003+ if (inode && dentry->d_parent == dentry) {
1004+ if (S_ISSOCK (inode->i_mode))
1005+ pattern = "socket:[%lu]";
1006+ if (S_ISFIFO (inode->i_mode))
1007+ pattern = "pipe:[%lu]";
1008+ }
1009+
1010+ if (pattern) {
1011+ len = sprintf (tmp, pattern, inode->i_ino);
1012+ path = tmp;
1013+ } else {
1014+ path = d_path (dentry, tmp, PAGE_SIZE);
1015+ len = tmp + PAGE_SIZE - 1 - path;
1016+ }
1017+
1018+ if (len < buflen)
1019+ buflen = len;
1020+ dput (dentry);
1021+ strncpy (buffer, path, buflen);
1022+ free_page ((unsigned long) tmp);
1023+ return buflen;
1024+}
1025+
1026+static unsigned long get_phys_addr (struct task_struct *p,
1027+ unsigned long ptr)
1028+{
1029+ pgd_t *page_dir;
1030+ pmd_t *page_middle;
1031+ pte_t pte;
1032+
1033+ if (!p || !p->mm || ptr >= TASK_SIZE)
1034+ return 0;
1035+ /* Check for NULL pgd .. shouldn't happen! */
1036+ if (!p->mm->pgd) {
1037+ printk ("get_phys_addr: pid %d has NULL pgd!\n", p->pid);
1038+ return 0;
1039+ }
1040+
1041+ page_dir = pgd_offset (p->mm, ptr);
1042+ if (pgd_none (*page_dir))
1043+ return 0;
1044+ if (pgd_bad (*page_dir)) {
1045+ printk ("bad page directory entry %08lx\n",
1046+ pgd_val (*page_dir));
1047+ pgd_clear (page_dir);
1048+ return 0;
1049+ }
1050+ page_middle = pmd_offset (page_dir, ptr);
1051+ if (pmd_none (*page_middle))
1052+ return 0;
1053+ if (pmd_bad (*page_middle)) {
1054+ printk ("bad page middle entry %08lx\n",
1055+ pmd_val (*page_middle));
1056+ pmd_clear (page_middle);
1057+ return 0;
1058+ }
1059+ pte = *pte_offset (page_middle, ptr);
1060+ if (!pte_present (pte))
1061+ return 0;
1062+ return pte_page (pte) + (ptr & ~PAGE_MASK);
1063+}
1064+
1065+static int get_array (struct task_struct *p, unsigned long start,
1066+ unsigned long end, char *buffer)
1067+{
1068+ unsigned long addr;
1069+ int size = 0, result = 0;
1070+ char c;
1071+
1072+ if (start >= end)
1073+ return result;
1074+ for (;;) {
1075+ addr = get_phys_addr (p, start);
1076+ if (!addr)
1077+ return result;
1078+ do {
1079+ c = *(char *) addr;
1080+ if (!c)
1081+ result = size;
1082+ if (size < PAGE_SIZE)
1083+ buffer[size++] = c;
1084+ else
1085+ return result;
1086+ addr++;
1087+ start++;
1088+ if (!c && start >= end)
1089+ return result;
1090+ } while (addr & ~PAGE_MASK);
1091+ }
1092+ return result;
1093+}
1094+
1095+static int
1096+devps_ioctl (struct inode *ip, struct file *fp,
1097+ unsigned int cmd, unsigned long arg)
1098+{
1099+ switch (cmd) {
1100+
1101+ /* Count up the total number of processes,
1102+ * and then return that total */
1103+ case DEVPS_GET_NUM_PIDS:{
1104+ struct task_struct *p;
1105+ pid_t num_pids = 0;
1106+
1107+ read_lock (&tasklist_lock);
1108+ for_each_task (p) {
1109+ if (!p->pid)
1110+ continue;
1111+ num_pids++;
1112+ }
1113+ read_unlock (&tasklist_lock);
1114+
1115+ copy_to_user_ret ((pid_t *) arg, &num_pids,
1116+ sizeof (num_pids), -EFAULT);
1117+ return 0;
1118+ }
1119+
1120+ /* Returns an array containing all current pids, where
1121+ pidlist[0]=number of PIDs in the array. pidlist[0] also
1122+ specifies the size of the array for the kernel to
1123+ fill... */
1124+ case DEVPS_GET_PID_LIST:{
1125+ struct task_struct *p;
1126+ pid_t *pid_array = NULL;
1127+ pid_t num_pids;
1128+ int stat;
1129+
1130+ /* Grab the first element to see how many * entries
1131+ they want us to fill */
1132+ stat = verify_area (VERIFY_READ, (char *) arg,
1133+ sizeof (pid_t));
1134+ if (stat) {
1135+ printk (KERN_INFO
1136+ "devps: can't tell how many "
1137+ "to pid's to write.\n");
1138+ return stat;
1139+ }
1140+
1141+ copy_from_user (&num_pids, (void *) arg,
1142+ sizeof (num_pids));
1143+
1144+ /* Now make sure we can write the specified amount
1145+ of stuff into the array. If we can't we might
1146+ as well quit now and save ourselves the bother. */
1147+ stat = verify_area (VERIFY_WRITE, (char *) arg,
1148+ sizeof (pid_t) * num_pids);
1149+ if (stat) {
1150+ printk (KERN_INFO
1151+ "devps: Insufficient space was "
1152+ "provided to write %d pid's.\n",
1153+ num_pids);
1154+ return stat;
1155+ }
1156+
1157+ /* Allocate some memory to hold this stuff in before
1158+ * we copy it out to user-space */
1159+ pid_array = (pid_t *) kmalloc (num_pids *
1160+ sizeof (pid_t),
1161+ GFP_KERNEL);
1162+ if (pid_array == NULL)
1163+ return -ENOMEM;
1164+
1165+ /* Now march through the PID list */
1166+ pid_array[0] = 0;
1167+ read_lock (&tasklist_lock);
1168+ for_each_task (p) {
1169+ if (!p->pid)
1170+ continue;
1171+ (pid_array[0])++;
1172+ if (pid_array[0] >= (num_pids - 1))
1173+ continue;
1174+ pid_array[pid_array[0]] = p->pid;
1175+ }
1176+ read_unlock (&tasklist_lock);
1177+
1178+ /* Copy out to the user the number we actually filled
1179+ */
1180+ copy_to_user_ret ((void *) arg, pid_array,
1181+ sizeof (pid_t) * pid_array[0],
1182+ -EFAULT);
1183+ kfree (pid_array);
1184+
1185+ return 0;
1186+ }
1187+
1188+ /* Find the details on a particular pid, and fill out a
1189+ struct with all the gory details. */
1190+ case DEVPS_GET_PID_INFO:{
1191+ struct task_struct *p;
1192+ struct pid_info mypidinfo;
1193+ unsigned int state;
1194+ /* 'R' running */
1195+ /* 'S' sleeping */
1196+ /* 'D' disk sleep */
1197+ /* 'Z' zombie */
1198+ /* 'T' stopped */
1199+ /* 'W' paging */
1200+ const char *state_string = "RSDZTW";
1201+
1202+ copy_from_user_ret (&mypidinfo,
1203+ (struct pid_info *) arg,
1204+ sizeof (mypidinfo), -EFAULT);
1205+
1206+ read_lock (&tasklist_lock);
1207+ p = find_task_by_pid (mypidinfo.pid);
1208+ read_unlock (&tasklist_lock);
1209+
1210+ /* Now copy all this crap so we can tell user space
1211+ all about it. ick. */
1212+ memset (mypidinfo.name, 0,
1213+ sizeof (mypidinfo.name));
1214+ strcpy (mypidinfo.name, p->comm);
1215+ mypidinfo.flags = p->flags;
1216+ mypidinfo.pgrp = p->pgrp;
1217+ mypidinfo.tms_cutime = p->times.tms_cutime;
1218+ mypidinfo.tms_cstime = p->times.tms_cstime;
1219+ mypidinfo.tms_utime = p->times.tms_utime;
1220+ mypidinfo.tms_stime = p->times.tms_stime;
1221+ mypidinfo.min_flt = p->min_flt;
1222+ mypidinfo.cmin_flt = p->cmin_flt;
1223+ mypidinfo.maj_flt = p->maj_flt;
1224+ mypidinfo.cmaj_flt = p->cmaj_flt;
1225+ mypidinfo.session = p->session;
1226+ mypidinfo.pid = p->pid;
1227+ mypidinfo.ppid = p->p_pptr->pid;
1228+ mypidinfo.tty =
1229+ p->tty ? kdev_t_to_nr (p->tty->device) : 0;
1230+ mypidinfo.start_time = p->start_time;
1231+ mypidinfo.uid = p->uid;
1232+ mypidinfo.euid = p->euid;
1233+ mypidinfo.suid = p->suid;
1234+ mypidinfo.fsuid = p->fsuid;
1235+ mypidinfo.gid = p->gid;
1236+ mypidinfo.egid = p->egid;
1237+ mypidinfo.sgid = p->sgid;
1238+ mypidinfo.fsgid = p->fsgid;
1239+ mypidinfo.priority = 20 - (p->counter * 10 +
1240+ DEF_PRIORITY / 2) / DEF_PRIORITY;
1241+ mypidinfo.nice = 20 - (mypidinfo.priority * 20 +
1242+ DEF_PRIORITY / 2) / DEF_PRIORITY;
1243+ state = p-> state & (TASK_RUNNING | TASK_INTERRUPTIBLE
1244+ | TASK_UNINTERRUPTIBLE |
1245+ TASK_ZOMBIE | TASK_STOPPED |
1246+ TASK_SWAPPING);
1247+ while (state) {
1248+ state_string++;
1249+ state >>= 1;
1250+ }
1251+ mypidinfo.state = *state_string;
1252+ mypidinfo.processor = p->processor;
1253+ mypidinfo.nswap = p->nswap;
1254+ mypidinfo.cnswap = p->cnswap;
1255+ if (p && p->mm) {
1256+ char *page = NULL;
1257+
1258+ /* Look for some elbow room */
1259+ if (!(page = (char*)get_free_page (GFP_KERNEL)))
1260+ return -ENOMEM;
1261+ /* Grab the command line */
1262+ get_array (p, p->mm->arg_start,
1263+ p->mm->arg_end, page);
1264+ memcpy( mypidinfo.command_line, page, sizeof( mypidinfo.command_line));
1265+ mypidinfo.command_line[sizeof( mypidinfo.command_line)-1]='\0';
1266+
1267+ /* Grab the environment */
1268+ memset (page, 0, PAGE_SIZE);
1269+ get_array (p, p->mm->env_start,
1270+ p->mm->env_end, page);
1271+ memcpy( mypidinfo.environment, page, sizeof( mypidinfo.environment));
1272+ mypidinfo.command_line[sizeof( mypidinfo.environment)-1]='\0';
1273+ free_page ((unsigned long) page);
1274+ }
1275+ memset (mypidinfo.cwd, 0, sizeof (mypidinfo.cwd));
1276+ get_name_from_dentry (dget (p->fs->pwd), mypidinfo.cwd,
1277+ sizeof (mypidinfo.cwd));
1278+ memset (mypidinfo.root, 0, sizeof (mypidinfo.root));
1279+ get_name_from_dentry (dget (p->fs->root),
1280+ mypidinfo.root,
1281+ sizeof (mypidinfo.root));
1282+
1283+ copy_to_user_ret ((struct pid_info *) arg,
1284+ &mypidinfo, sizeof (mypidinfo),
1285+ -EFAULT);
1286+
1287+ return 0;
1288+ }
1289+
1290+ /* Return the PID of the current process */
1291+ case DEVPS_GET_CURRENT_PID:{
1292+ return current->pid;
1293+ }
1294+
1295+ default:
1296+ return -EINVAL;
1297+
1298+ }
1299+ return 0;
1300+}
1301+
1302+
1303+
1304+/****************************************************************************
1305+ * Set up the file operations devps will support
1306+ */
1307+static struct file_operations devps_fops = {
1308+ NULL, /* No lseek */
1309+ NULL, /* No read */
1310+ NULL, /* No write */
1311+ NULL, /* No readdir */
1312+ NULL, /* No poll */
1313+ devps_ioctl,
1314+ NULL, /* No mmap */
1315+ devps_open,
1316+ NULL, /* flush */
1317+ devps_release,
1318+ NULL, /* fsync */
1319+ NULL, /* fasync */
1320+ NULL, /* check_media_change */
1321+ NULL /* revalidate */
1322+};
1323+
1324+static struct miscdevice devps_misc_dev = {
1325+ DEVPS_MINOR,
1326+ "devps",
1327+ &devps_fops
1328+};
1329+
1330+/* The real driver initialization function */
1331+extern int devps_init (void)
1332+{
1333+ printk (KERN_INFO "devps driver %s loaded\n", DEVPS_VERSION);
1334+
1335+ if (misc_register (&devps_misc_dev)) {
1336+ printk ("devps: unable to get misc device %d\n",
1337+ DEVPS_MINOR);
1338+ return -EIO;
1339+ }
1340+
1341+ return 0;
1342+}
1343+
1344+#ifdef MODULE
1345+
1346+MODULE_AUTHOR ("Erik Andersen <andersee@debian.org>");
1347+MODULE_DESCRIPTION
1348+ ("devps driver -- exports kernel process information to user space");
1349+
1350+
1351+/* Stub driver initialization function */
1352+int init_module (void)
1353+{
1354+ return (devps_init ());
1355+}
1356+
1357+void cleanup_module (void)
1358+{
1359+ printk (KERN_INFO "devps driver unloaded\n");
1360+ misc_deregister (&devps_misc_dev);
1361+}
1362+
1363+#endif /* endif MODULE */
1364diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/makedevps.sh linux/drivers/char/makedevps.sh
1365--- linux-2.2.15-pre13.virgin/drivers/char/makedevps.sh Wed Dec 31 17:00:00 1969
1366+++ linux/drivers/char/makedevps.sh Tue Mar 7 23:31:52 2000
1367@@ -0,0 +1,6 @@
1368+#!/bin/sh -x
1369+
1370+gcc -Wall -g -I /usr/src/linux/include ps-devps.c -o ps-devps
1371+gcc -Wall -g -I /usr/src/linux/include mounts.c -o mounts
1372+gcc -Wall -g -I /usr/src/linux/include modules.c -o modules
1373+
1374diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/misc.c linux/drivers/char/misc.c
1375--- linux-2.2.15-pre13.virgin/drivers/char/misc.c Tue Mar 7 19:46:58 2000
1376+++ linux/drivers/char/misc.c Tue Mar 7 19:52:45 2000
1377@@ -84,6 +84,8 @@
1378 extern void hfmodem_init(void);
1379 extern int pc110pad_init(void);
1380 extern int pmu_device_init(void);
1381+extern int devps_init(void);
1382+extern int devmtab_init(void);
1383
1384 static int misc_read_proc(char *buf, char **start, off_t offset,
1385 int len, int *eof, void *private)
1386@@ -267,6 +269,12 @@
1387 #endif
1388 #ifdef CONFIG_PMAC_PBOOK
1389 pmu_device_init();
1390+#endif
1391+#ifdef CONFIG_DEVPS
1392+ devps_init();
1393+#endif
1394+#ifdef CONFIG_DEVMTAB
1395+ devmtab_init();
1396 #endif
1397 #ifdef CONFIG_SGI_NEWPORT_GFX
1398 gfx_register ();
1399diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/modules.c linux/drivers/char/modules.c
1400--- linux-2.2.15-pre13.virgin/drivers/char/modules.c Wed Dec 31 17:00:00 1969
1401+++ linux/drivers/char/modules.c Tue Mar 7 23:35:26 2000
1402@@ -0,0 +1,102 @@
1403+/* vi: set sw=4 ts=4: */
1404+/*
1405+ * devmodules tester
1406+ *
1407+ *
1408+ * Copyright (C) 2000 by Erik Andersen <andersee@debian.org>
1409+ *
1410+ * This program is free software; you can redistribute it and/or modify
1411+ * it under the terms of the GNU General Public License as published by
1412+ * the Free Software Foundation; either version 2 of the License, or
1413+ * (at your option) any later version.
1414+ *
1415+ * This program is distributed in the hope that it will be useful,
1416+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1417+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1418+ * General Public License for more details.
1419+ *
1420+ * You should have received a copy of the GNU General Public License
1421+ * along with this program; if not, write to the Free Software
1422+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1423+ *
1424+ */
1425+
1426+#include <stdio.h>
1427+#include <stdlib.h>
1428+#include <errno.h>
1429+#include <string.h>
1430+#include <unistd.h>
1431+#include <time.h>
1432+#include <fcntl.h>
1433+#include <sys/ioctl.h>
1434+#include <sys/types.h>
1435+#include <linux/devmodules.h>
1436+
1437+
1438+int main (int argc, char **argv)
1439+{
1440+ char device[80] = "/dev/modules";
1441+ int fd; /* file descriptor for devmodules device */
1442+ int i, num_modules;
1443+ struct k_module_item *modlist;
1444+
1445+ if (argc > 1 && **(argv + 1) == '-') {
1446+ fprintf(stderr, "Usage: modules\n\nLists loaded modules\n\nThis version of modules accepts no options.\n\n");
1447+ exit(1);
1448+ }
1449+
1450+ /* open device */
1451+ fd = open(device, O_RDONLY);
1452+ if (fd < 0) {
1453+ fprintf (stderr, "open failed for `%s': %s\n",
1454+ device, strerror (errno));
1455+ exit (1);
1456+ }
1457+
1458+ /* How many modules? We need to know to allocate
1459+ * enough space for later... */
1460+ num_modules = ioctl (fd, DEVMODULES_COUNT_MODULES);
1461+ if (num_modules<0) {
1462+ fprintf (stderr, "\nDEVMODULES_COUNT_MODULES: %s\n",
1463+ strerror (errno));
1464+ exit (1);
1465+ }
1466+ modlist = (struct k_module_item *) calloc ( num_modules, sizeof(struct k_module_item));
1467+
1468+ /* Grab the list of loaded modules */
1469+ if (ioctl (fd, DEVMODULES_GET_MODULES_LIST, modlist)<0) {
1470+ fprintf (stderr, "\nDEVMODULES_GET_MODULES_LIST: %s\n",
1471+ strerror (errno));
1472+ exit (1);
1473+ }
1474+ fprintf( stdout, "\nEquivalent of /proc/modules:\n");
1475+ for( i = 0 ; i < num_modules ; i++) {
1476+ fprintf( stdout, "%-20s%8lu%4ld", modlist[i].name,
1477+ modlist[i].size, modlist[i].usecount);
1478+ if (modlist[i].flags & MOD_DELETED)
1479+ fprintf( stdout, " (deleted)");
1480+ else if (modlist[i].flags & MOD_RUNNING) {
1481+ if (modlist[i].flags & MOD_AUTOCLEAN)
1482+ fprintf( stdout, " (autoclean)");
1483+ if (!(modlist[i].flags & MOD_USED_ONCE))
1484+ fprintf( stdout, " (unused)");
1485+ }
1486+ else if (modlist[i].flags & MOD_INITIALIZING)
1487+ fprintf( stdout, " (initializing)");
1488+ else
1489+ fprintf( stdout, " (uninitialized)");
1490+ /* TODO: Add in module reference list */
1491+ fprintf( stdout, "\n");
1492+ }
1493+
1494+ /* Clean up */
1495+ free( modlist);
1496+ if (close (fd) != 0) {
1497+ fprintf (stderr, "close failed for `%s': %s\n",
1498+ device, strerror (errno));
1499+ exit (1);
1500+ }
1501+
1502+ exit (0);
1503+}
1504+
1505diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/mounts.c linux/drivers/char/mounts.c
1506--- linux-2.2.15-pre13.virgin/drivers/char/mounts.c Wed Dec 31 17:00:00 1969
1507+++ linux/drivers/char/mounts.c Tue Mar 7 23:29:27 2000
1508@@ -0,0 +1,124 @@
1509+/* vi: set sw=4 ts=4: */
1510+/*
1511+ * devmtab tester
1512+ *
1513+ *
1514+ * Copyright (C) 2000 by Erik Andersen <andersee@debian.org>
1515+ *
1516+ * This program is free software; you can redistribute it and/or modify
1517+ * it under the terms of the GNU General Public License as published by
1518+ * the Free Software Foundation; either version 2 of the License, or
1519+ * (at your option) any later version.
1520+ *
1521+ * This program is distributed in the hope that it will be useful,
1522+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1523+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1524+ * General Public License for more details.
1525+ *
1526+ * You should have received a copy of the GNU General Public License
1527+ * along with this program; if not, write to the Free Software
1528+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1529+ *
1530+ */
1531+
1532+#include <stdio.h>
1533+#include <stdlib.h>
1534+#include <errno.h>
1535+#include <string.h>
1536+#include <unistd.h>
1537+#include <time.h>
1538+#include <fcntl.h>
1539+#include <sys/ioctl.h>
1540+#include <sys/types.h>
1541+#include <linux/devmtab.h>
1542+
1543+
1544+int main (int argc, char **argv)
1545+{
1546+ char device[80] = "/dev/mtab";
1547+ int fd; /* file descriptor for devmtab device */
1548+ int i, numfilesystems;
1549+ struct k_fstype *fslist;
1550+ struct k_mntent *mntentlist;
1551+
1552+ if (argc > 1 && **(argv + 1) == '-') {
1553+ fprintf(stderr, "Usage: mounts\n\nReport mounted stuff\n\nThis version of mounts accepts no options.\n\n");
1554+ exit(1);
1555+ }
1556+
1557+ /* open device */
1558+ if ((fd = open(device, O_RDONLY)) < 0) {
1559+ fprintf (stderr, "open failed for `%s': %s\n",
1560+ device, strerror (errno));
1561+ exit (1);
1562+ }
1563+
1564+ /* How many filesystems? We need to know to allocate
1565+ * enough space for later... */
1566+ numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
1567+ if (numfilesystems<0) {
1568+ fprintf (stderr, "\nDEVMTAB_COUNT_FILESYSTEMS: %s\n",
1569+ strerror (errno));
1570+ exit (1);
1571+ }
1572+ fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype));
1573+
1574+ /* Grab the list of available filesystems */
1575+ if (ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist)<0) {
1576+ fprintf (stderr, "\nDEVMTAB_GET_FILESYSTEMS: %s\n",
1577+ strerror (errno));
1578+ exit (1);
1579+ }
1580+ fprintf( stdout, "\nEquivalent of /proc/filesystems:\n");
1581+ for( i = 0 ; i < numfilesystems ; i++) {
1582+ fprintf( stdout, "%s%s\n", fslist[i].mnt_type,
1583+ (fslist[i].mnt_nodev)? " nodev" : "");
1584+ }
1585+
1586+
1587+ /* How many mounted filesystems? We need to know to
1588+ * allocate enough space for later... */
1589+ numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
1590+ if (numfilesystems<0) {
1591+ fprintf (stderr, "\nDEVMTAB_COUNT_MOUNTS: %s\n",
1592+ strerror (errno));
1593+ exit (1);
1594+ }
1595+ mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent));
1596+
1597+ /* Grab the list of mounted filesystems */
1598+ if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0) {
1599+ fprintf (stderr, "\nDEVMTAB_GET_MOUNTS: %s\n",
1600+ strerror (errno));
1601+ exit (1);
1602+ }
1603+
1604+ fprintf( stdout, "\nEquivalent of /proc/mounts:\n");
1605+ for( i = 0 ; i < numfilesystems ; i++) {
1606+ fprintf( stdout, "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname,
1607+ mntentlist[i].mnt_dir, mntentlist[i].mnt_type,
1608+ mntentlist[i].mnt_opts, mntentlist[i].mnt_freq,
1609+ mntentlist[i].mnt_passno);
1610+ }
1611+
1612+
1613+ /* Change the root filesystem's device name */
1614+ if (ioctl (fd, DEVMTAB_SET_ROOTFS_DEVNAME, "/dev/foo")<0) {
1615+ fprintf (stderr, "\nDEVMTAB_SET_ROOTFS_DEVNAME: %s\n",
1616+ strerror (errno));
1617+ exit (1);
1618+ }
1619+
1620+
1621+ /* clean up */
1622+ free( fslist);
1623+ free( mntentlist);
1624+ if (close (fd) != 0) {
1625+ fprintf (stderr, "close failed for `%s': %s\n",
1626+ device, strerror (errno));
1627+ exit (1);
1628+ }
1629+
1630+ exit (0);
1631+}
1632+
1633diff -ur --new-file linux-2.2.15-pre13.virgin/drivers/char/ps-devps.c linux/drivers/char/ps-devps.c
1634--- linux-2.2.15-pre13.virgin/drivers/char/ps-devps.c Wed Dec 31 17:00:00 1969
1635+++ linux/drivers/char/ps-devps.c Tue Mar 7 19:52:45 2000
1636@@ -0,0 +1,147 @@
1637+/* vi: set sw=4 ts=4: */
1638+/*
1639+ * Mini ps implementation for use with the Linux devps driver
1640+ *
1641+ *
1642+ * Copyright (C) 2000 by Erik Andersen <andersee@debian.org>
1643+ *
1644+ * This program is free software; you can redistribute it and/or modify
1645+ * it under the terms of the GNU General Public License as published by
1646+ * the Free Software Foundation; either version 2 of the License, or
1647+ * (at your option) any later version.
1648+ *
1649+ * This program is distributed in the hope that it will be useful,
1650+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1651+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1652+ * General Public License for more details.
1653+ *
1654+ * You should have received a copy of the GNU General Public License
1655+ * along with this program; if not, write to the Free Software
1656+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1657+ *
1658+ */
1659+
1660+#include <stdio.h>
1661+#include <stdlib.h>
1662+#include <errno.h>
1663+#include <string.h>
1664+#include <unistd.h>
1665+#include <time.h>
1666+#include <fcntl.h>
1667+#include <sys/ioctl.h>
1668+#include <linux/devps.h>
1669+#include <pwd.h>
1670+#include <grp.h>
1671+#include <sys/types.h>
1672+
1673+
1674+#define MAX_COLUMN 79
1675+
1676+int
1677+main (int argc, char **argv)
1678+{
1679+ char device[80] = "/dev/ps";
1680+ int i, j, len;
1681+ int fd; /* file descriptor for devps device */
1682+ int status; /* return status for system calls */
1683+ pid_t num_pids;
1684+ pid_t* pid_array = NULL;
1685+ struct pid_info info;
1686+ struct passwd *pwd;
1687+ struct group *grp;
1688+ char uidName[10] = "";
1689+ char groupName[10] = "";
1690+
1691+ if (argc > 1 && **(argv + 1) == '-') {
1692+ fprintf(stderr, "Usage: ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n");
1693+ exit(1);
1694+ }
1695+
1696+ /* open device */
1697+ fd = open(device, O_RDWR);
1698+ if (fd < 0) {
1699+ fprintf (stderr, "open failed for `%s': %s\n",
1700+ device, strerror (errno));
1701+ goto error;
1702+ }
1703+
1704+ /* Find out how many processes there are */
1705+ status = ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids);
1706+ if (status<0) {
1707+ fprintf (stderr, "\nDEVPS_GET_PID_LIST: %s\n",
1708+ strerror (errno));
1709+ goto error;
1710+ }
1711+
1712+ /* Allocate some memory -- grab a few extras just in case
1713+ * some new processes start up while we wait. The kernel will
1714+ * just ignore any extras if we give it too many, and will trunc.
1715+ * the list if we give it too few. */
1716+ pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
1717+ pid_array[0] = num_pids+10;
1718+
1719+ /* Now grab the pid list */
1720+ status = ioctl (fd, DEVPS_GET_PID_LIST, pid_array);
1721+ if (status<0) {
1722+ fprintf (stderr, "\nDEVPS_GET_PID_LIST: %s\n",
1723+ strerror (errno));
1724+ goto error;
1725+ }
1726+
1727+ /* Print up a ps listing */
1728+ fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
1729+ "State", "Command");
1730+
1731+ for (i=1; i<pid_array[0] ; i++) {
1732+ info.pid = pid_array[i];
1733+ status = ioctl (fd, DEVPS_GET_PID_INFO, &info);
1734+ if (status<0) {
1735+ fprintf (stderr, "\nDEVPS_GET_PID_INFO: %s\n",
1736+ strerror (errno));
1737+ goto error;
1738+ }
1739+ /* Make some adjustments as needed */
1740+ pwd = getpwuid(info.euid);
1741+ if (pwd == NULL)
1742+ sprintf(uidName, "%lu", info.euid);
1743+ else
1744+ sprintf(uidName, "%s", pwd->pw_name);
1745+ grp = getgrgid(info.egid);
1746+ if (grp == NULL)
1747+ sprintf(groupName, "%lu", info.egid);
1748+ else
1749+ sprintf(groupName, "%s", grp->gr_name);
1750+
1751+ len = fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state);
1752+
1753+ if (strlen(info.command_line) > 1) {
1754+ for( j=0; j<(sizeof(info.command_line)-1) && j < (MAX_COLUMN-len); j++) {
1755+ if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') {
1756+ *(info.command_line+j) = ' ';
1757+ }
1758+ }
1759+ *(info.command_line+j) = '\0';
1760+ fprintf(stdout, "%s\n", info.command_line);
1761+ } else {
1762+ fprintf(stdout, "[%s]\n", info.name);
1763+ }
1764+ }
1765+
1766+ /* Free memory */
1767+ free( pid_array);
1768+
1769+ /* close device */
1770+ status = close (fd);
1771+ if (status != 0) {
1772+ fprintf (stderr, "close failed for `%s': %s\n",
1773+ device, strerror (errno));
1774+ goto error;
1775+ }
1776+
1777+ exit (0);
1778+error:
1779+ fflush(stdout);
1780+ fflush(stderr);
1781+ exit (1);
1782+}
1783+
1784diff -ur --new-file linux-2.2.15-pre13.virgin/fs/Makefile linux/fs/Makefile
1785--- linux-2.2.15-pre13.virgin/fs/Makefile Mon Mar 6 10:23:14 2000
1786+++ linux/fs/Makefile Tue Mar 7 19:52:45 2000
1787@@ -11,9 +11,10 @@
1788 L_OBJS = $(join $(SUB_DIRS),$(SUB_DIRS:%=/%.o))
1789 O_TARGET := fs.o
1790 O_OBJS = open.o read_write.o devices.o file_table.o buffer.o \
1791- super.o block_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
1792+ block_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
1793 ioctl.o readdir.o select.o fifo.o locks.o filesystems.o \
1794 dcache.o inode.o attr.o bad_inode.o file.o $(BINFMTS)
1795+OX_OBJS = super.o
1796
1797 MOD_LIST_NAME := FS_MODULES
1798 ALL_SUB_DIRS = coda minix ext2 fat msdos vfat proc isofs nfs umsdos ntfs \
1799diff -ur --new-file linux-2.2.15-pre13.virgin/fs/proc/array.c linux/fs/proc/array.c
1800--- linux-2.2.15-pre13.virgin/fs/proc/array.c Tue Mar 7 19:47:04 2000
1801+++ linux/fs/proc/array.c Tue Mar 7 19:52:45 2000
1802@@ -44,6 +44,7 @@
1803 *
1804 */
1805
1806+#include <linux/module.h>
1807 #include <linux/types.h>
1808 #include <linux/errno.h>
1809 #include <linux/sched.h>
1810@@ -1306,10 +1307,6 @@
1811 }
1812 #endif
1813
1814-#ifdef CONFIG_MODULES
1815-extern int get_module_list(char *);
1816-extern int get_ksyms_list(char *, char **, off_t, int);
1817-#endif
1818 extern int get_device_list(char *);
1819 extern int get_partition_list(char *);
1820 extern int get_filesystem_list(char *);
1821diff -ur --new-file linux-2.2.15-pre13.virgin/fs/super.c linux/fs/super.c
1822--- linux-2.2.15-pre13.virgin/fs/super.c Tue Jan 4 11:12:23 2000
1823+++ linux/fs/super.c Tue Mar 7 19:52:45 2000
1824@@ -18,6 +18,7 @@
1825 */
1826
1827 #include <linux/config.h>
1828+#include <linux/module.h>
1829 #include <linux/malloc.h>
1830 #include <linux/locks.h>
1831 #include <linux/smp_lock.h>
1832@@ -25,6 +26,7 @@
1833 #include <linux/init.h>
1834 #include <linux/quotaops.h>
1835 #include <linux/acct.h>
1836+#include <linux/devmtab.h>
1837
1838 #include <asm/uaccess.h>
1839
1840@@ -309,7 +311,57 @@
1841 { 0, NULL }
1842 };
1843
1844-int get_filesystem_info( char *buf )
1845+
1846+extern int count_mounted_filesystems()
1847+{
1848+ struct vfsmount *tmp = vfsmntlist;
1849+ int count = 0;
1850+
1851+ while (tmp)
1852+ {
1853+ tmp = tmp->mnt_next;
1854+ count++;
1855+ }
1856+
1857+ return count;
1858+}
1859+EXPORT_SYMBOL(count_mounted_filesystems);
1860+
1861+
1862+extern void get_mtab_entries( int count, struct k_mntent* mntentlist)
1863+{
1864+ struct vfsmount *tmp = vfsmntlist;
1865+ struct proc_fs_info *fs_infop;
1866+ int i = 0, len;
1867+
1868+ while (tmp && i < count)
1869+ {
1870+ strncpy(mntentlist[i].mnt_fsname, tmp->mnt_devname,
1871+ sizeof(mntentlist[i].mnt_fsname));
1872+ strncpy(mntentlist[i].mnt_dir, tmp->mnt_dirname,
1873+ sizeof(mntentlist[i].mnt_dir));
1874+ strncpy(mntentlist[i].mnt_type, tmp->mnt_sb->s_type->name,
1875+ sizeof(mntentlist[i].mnt_type));
1876+ len = 0;
1877+ len+=sprintf(mntentlist[i].mnt_opts, "%s",
1878+ tmp->mnt_flags & MS_RDONLY ? "ro" : "rw");
1879+ for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
1880+ if (tmp->mnt_flags & fs_infop->flag) {
1881+ strncpy(mntentlist[i].mnt_opts+len, fs_infop->str,
1882+ sizeof(mntentlist[i].mnt_opts)-len);
1883+ len += strlen(fs_infop->str);
1884+ }
1885+ }
1886+
1887+ /* TODO -- add in NFS stuff */
1888+
1889+ tmp = tmp->mnt_next;
1890+ i++;
1891+ }
1892+}
1893+EXPORT_SYMBOL(get_mtab_entries);
1894+
1895+extern int get_filesystem_info( char *buf )
1896 {
1897 struct vfsmount *tmp = vfsmntlist;
1898 struct proc_fs_info *fs_infop;
1899@@ -379,8 +431,54 @@
1900
1901 return len;
1902 }
1903+EXPORT_SYMBOL(get_filesystem_info);
1904+
1905+extern int count_kfstypes()
1906+{
1907+ struct file_system_type * tmp = file_systems;
1908+ int count = 0;
1909+
1910+ while (tmp) {
1911+ count++;
1912+ tmp = tmp->next;
1913+ }
1914+
1915+ return count;
1916+}
1917+EXPORT_SYMBOL(count_kfstypes);
1918+
1919+extern int set_root_filesystem_name( char *newname)
1920+{
1921+ struct vfsmount *tmp = vfsmntlist;
1922+ char *name;
1923+
1924+ if (tmp && newname) {
1925+ kfree( tmp->mnt_devname);
1926+ name = (char *) kmalloc(strlen(newname)+1, GFP_KERNEL);
1927+ if (!name)
1928+ return -ENOMEM;
1929+ strcpy(name, newname);
1930+ tmp->mnt_devname = name;
1931+ }
1932+ return 0;
1933+}
1934+EXPORT_SYMBOL(set_root_filesystem_name);
1935+
1936+extern void get_kfstype_list(int count, struct k_fstype* fstypelist)
1937+{
1938+ int i = 0;
1939+ struct file_system_type * tmp = file_systems;
1940+
1941+ while (tmp && i < count) {
1942+ strncpy(fstypelist[i].mnt_type, tmp->name, sizeof(fstypelist[i].mnt_type));
1943+ fstypelist[i].mnt_nodev = (tmp->fs_flags & FS_REQUIRES_DEV)? 0 : 1;
1944+ tmp = tmp->next;
1945+ i++;
1946+ }
1947+}
1948+EXPORT_SYMBOL(get_kfstype_list);
1949
1950-int get_filesystem_list(char * buf)
1951+extern int get_filesystem_list(char * buf)
1952 {
1953 int len = 0;
1954 struct file_system_type * tmp;
1955@@ -394,6 +492,7 @@
1956 }
1957 return len;
1958 }
1959+EXPORT_SYMBOL(get_filesystem_list);
1960
1961 struct file_system_type *get_fs_type(const char *name)
1962 {
1963diff -ur --new-file linux-2.2.15-pre13.virgin/include/linux/devmodules.h linux/include/linux/devmodules.h
1964--- linux-2.2.15-pre13.virgin/include/linux/devmodules.h Wed Dec 31 17:00:00 1969
1965+++ linux/include/linux/devmodules.h Tue Mar 7 23:37:48 2000
1966@@ -0,0 +1,55 @@
1967+/* vi: set sw=8 ts=8: */
1968+/*
1969+ * -- <linux/devmodules.h>
1970+ *
1971+ * Copyright (C) 2000 Erik Andersen <andersee@debian.org>
1972+ *
1973+ * May be copied or modified under the terms of the GNU General Public License.
1974+ * See linux/COPYING for more information.
1975+ *
1976+ * This driver implements an interface whereby programs such as lsmod(8) may
1977+ * obtain all the information they need to do their jobs without needing to
1978+ * use /proc.
1979+ *
1980+ */
1981+
1982+#ifndef _LINUX_DEVMODULES_H
1983+#define _LINUX_DEVMODULES_H
1984+
1985+
1986+/*******************************************************
1987+ * The list of all ioctl(2) commands suported by devmodules.
1988+ * For the devmodules ioctls, I have commandeered some of the
1989+ * higher bits of byte 0xeb.
1990+ *******************************************************/
1991+#define DEVMODULES_COUNT_MODULES 0xebba /* How many modules are there? */
1992+#define DEVMODULES_GET_MODULES_LIST 0xebbb /* Get a list of all installed modules */
1993+
1994+/*******************************************************
1995+ * devmodules ioctl(2) structures
1996+ *******************************************************/
1997+
1998+/* An array of these is returned by the DEVMODULES_GET_MODULES_LIST ioctl.
1999+ */
2000+struct k_module_item {
2001+ char name[255];/* Name of the module */
2002+ unsigned long size; /* Size of module in bytes */
2003+ unsigned long flags; /* Flags set by the module */
2004+ long usecount; /* Module use count value */
2005+
2006+ /* TODO: Add in module reference list */
2007+
2008+};
2009+
2010+/* Possible bits for k_module_item's flags. */
2011+#define MOD_UNINITIALIZED 0
2012+#define MOD_RUNNING 1
2013+#define MOD_DELETED 2
2014+#define MOD_AUTOCLEAN 4
2015+#define MOD_VISITED 8
2016+#define MOD_USED_ONCE 16
2017+#define MOD_JUST_FREED 32
2018+#define MOD_INITIALIZING 64
2019+
2020+
2021+#endif /* _LINUX_DEVMODULES_H */
2022diff -ur --new-file linux-2.2.15-pre13.virgin/include/linux/devmtab.h linux/include/linux/devmtab.h
2023--- linux-2.2.15-pre13.virgin/include/linux/devmtab.h Wed Dec 31 17:00:00 1969
2024+++ linux/include/linux/devmtab.h Tue Mar 7 19:52:45 2000
2025@@ -0,0 +1,55 @@
2026+/* vi: set sw=8 ts=8: */
2027+/*
2028+ * -- <linux/devmtab.h>
2029+ *
2030+ * Copyright (C) 2000 Erik Andersen <andersee@debian.org>
2031+ *
2032+ * May be copied or modified under the terms of the GNU General Public License.
2033+ * See linux/COPYING for more information.
2034+ *
2035+ * This driver implements an interface whereby programs such as mount(8),
2036+ * umount(8), and df(1) may obtain all the process information they need to do
2037+ * their jobs without needing to use /proc.
2038+ *
2039+ */
2040+
2041+#ifndef _LINUX_DEVMTAB_H
2042+#define _LINUX_DEVMTAB_H
2043+
2044+
2045+/*******************************************************
2046+ * The list of all ioctl(2) commands suported by devmtab.
2047+ * For the devmtab ioctls, I have commandeered some of the
2048+ * higher bits of byte 0xeb.
2049+ *******************************************************/
2050+#define DEVMTAB_COUNT_FILESYSTEMS 0xebaa /* Get a list of all fs */
2051+#define DEVMTAB_GET_FILESYSTEMS 0xebab /* Get a list of all fs */
2052+#define DEVMTAB_COUNT_MOUNTS 0xebac /* Returns number of mounted filesystems */
2053+#define DEVMTAB_GET_MOUNTS 0xebad /* Get a list of a mounted fs */
2054+#define DEVMTAB_SET_ROOTFS_DEVNAME 0xebae /* Replace /dev/root with real name */
2055+
2056+/*******************************************************
2057+ * devmtab ioctl(2) structures
2058+ *******************************************************/
2059+
2060+/* An array of these is returned by the DEVMTAB_GET_FILESYSTEMS ioctl.
2061+ */
2062+struct k_fstype {
2063+ char mnt_type[255]; /* filesystem type: ext2, nfs, etc. */
2064+ int mnt_nodev; /* Is this a device-less filesystem? */
2065+};
2066+
2067+/* An array of these is returned by the DEVMTAB_GET_MOUNTS ioctl.
2068+ * This struct should be the same as what libc returns via the
2069+ * getmntent(3) function (excat this comes from the kernel, not
2070+ * from whatever noise is in /etc/mtab at the moment... */
2071+struct k_mntent {
2072+ char mnt_fsname[255]; /* name of mounted file system */
2073+ char mnt_dir[255]; /* path of file system mount point */
2074+ char mnt_type[255]; /* filesystem type: ext2, nfs, etc. */
2075+ char mnt_opts[255]; /* Comma-separated list of mount options */
2076+ int mnt_freq; /* dump frequency in days */
2077+ int mnt_passno; /* pass number for parallel fsck */
2078+};
2079+
2080+#endif /* _LINUX_DEVMTAB_H */
2081diff -ur --new-file linux-2.2.15-pre13.virgin/include/linux/devps.h linux/include/linux/devps.h
2082--- linux-2.2.15-pre13.virgin/include/linux/devps.h Wed Dec 31 17:00:00 1969
2083+++ linux/include/linux/devps.h Tue Mar 7 19:52:45 2000
2084@@ -0,0 +1,78 @@
2085+/*
2086+ * -- <linux/devps.h>
2087+ *
2088+ * Copyright (C) 2000 Erik Andersen <andersee@debian.org>
2089+ *
2090+ * May be copied or modified under the terms of the GNU General Public License.
2091+ * See linux/COPYING for more information.
2092+ *
2093+ * This driver implements an interface whereby programs such as ps(1), top(1),
2094+ * killall(1) and the like may obtain all the process information they need to
2095+ * do their jobs.
2096+ *
2097+ */
2098+
2099+#ifndef _LINUX_DEVPS_H
2100+#define _LINUX_DEVPS_H
2101+
2102+
2103+/*******************************************************
2104+ * The list of all ioctl(2) commands suported by devps.
2105+ * For the devps ioctls, I have commandeered some of the
2106+ * higher bits of byte 0xeb.
2107+ *******************************************************/
2108+#define DEVPS_GET_NUM_PIDS 0xeba1 /* Get a list of all PIDs */
2109+#define DEVPS_GET_PID_LIST 0xeba2 /* Get a list of all PIDs */
2110+#define DEVPS_GET_PID_INFO 0xeba3 /* Get info about a specific PID */
2111+#define DEVPS_GET_CURRENT_PID 0xeba4 /* Get the current PID */
2112+
2113+/*******************************************************
2114+ * devps ioctl(2) structures
2115+ *******************************************************/
2116+
2117+
2118+struct pid_info
2119+{
2120+ char name[16];
2121+ long flags;
2122+ pid_t pgrp;
2123+ clock_t tms_cutime;
2124+ clock_t tms_cstime;
2125+ clock_t tms_utime;
2126+ clock_t tms_stime;
2127+ unsigned long min_flt;
2128+ unsigned long cmin_flt;
2129+ unsigned long maj_flt;
2130+ unsigned long cmaj_flt;
2131+ pid_t session;
2132+ pid_t pid;
2133+ pid_t ppid;
2134+ int tty;
2135+ unsigned long start_time;
2136+ unsigned long uid,euid,suid,fsuid;
2137+ unsigned long gid,egid,sgid,fsgid;
2138+ long priority, nice;
2139+ char state;
2140+ int processor;
2141+ unsigned long nswap, cnswap;
2142+ char command_line[256];
2143+ char environment[256];
2144+ char root[256];
2145+ char cwd[256];
2146+#if 0
2147+ /* TODO: Add in this (and probably more) stuff */
2148+
2149+ int resident;
2150+ int size;
2151+ int share;
2152+ unsigned long vsize;
2153+ char exe[MAX_PATH];
2154+ unsigned long vm_total, vm_locked, vm_rss, vm_data, vm_stack, vm_exec, vm_lib;
2155+ unsigned long start_code, end_code, start_data, eip, esp;
2156+ unsigned long signal, blocked;
2157+#endif
2158+
2159+
2160+};
2161+
2162+#endif /* _LINUX_DEVPS_H */
2163diff -ur --new-file linux-2.2.15-pre13.virgin/include/linux/fs.h linux/include/linux/fs.h
2164--- linux-2.2.15-pre13.virgin/include/linux/fs.h Mon Mar 6 10:23:14 2000
2165+++ linux/include/linux/fs.h Tue Mar 7 21:14:11 2000
2166@@ -566,6 +566,17 @@
2167 struct semaphore s_vfs_rename_sem; /* Kludge */
2168 };
2169
2170+/* fs/super.c */
2171+#include <linux/devmtab.h>
2172+
2173+extern int count_kfstypes( void);
2174+extern void get_kfstype_list( int count, struct k_fstype* fstypelist);
2175+extern int count_mounted_filesystems( void);
2176+extern int get_filesystem_info(char *buf);
2177+extern int get_filesystem_list(char *buf);
2178+extern void get_mtab_entries( int count, struct k_mntent* mntentlist);
2179+extern int set_root_filesystem_name( char *newname);
2180+
2181 /*
2182 * VFS helper functions..
2183 */
2184diff -ur --new-file linux-2.2.15-pre13.virgin/include/linux/miscdevice.h linux/include/linux/miscdevice.h
2185--- linux-2.2.15-pre13.virgin/include/linux/miscdevice.h Mon Aug 9 13:04:41 1999
2186+++ linux/include/linux/miscdevice.h Tue Mar 7 22:24:50 2000
2187@@ -11,6 +11,9 @@
2188 #define APOLLO_MOUSE_MINOR 7
2189 #define PC110PAD_MINOR 9
2190 #define MAC_MOUSE_MINOR 10
2191+#define DEVPS_MINOR 21
2192+#define DEVMTAB_MINOR 22
2193+#define DEVMODULES_MINOR 23
2194 #define WATCHDOG_MINOR 130 /* Watchdog timer */
2195 #define TEMP_MINOR 131 /* Temperature Sensor */
2196 #define RTC_MINOR 135
2197diff -ur --new-file linux-2.2.15-pre13.virgin/include/linux/module.h linux/include/linux/module.h
2198--- linux-2.2.15-pre13.virgin/include/linux/module.h Tue Mar 7 19:47:04 2000
2199+++ linux/include/linux/module.h Tue Mar 7 21:26:48 2000
2200@@ -8,6 +8,7 @@
2201 #define _LINUX_MODULE_H
2202
2203 #include <linux/config.h>
2204+#include <linux/types.h>
2205
2206 #ifdef __GENKSYMS__
2207 # define _set_ver(sym) sym
2208@@ -143,6 +144,21 @@
2209
2210 /* Find a symbol exported by the kernel or another module */
2211 extern unsigned long get_module_symbol(char *, char *);
2212+/* Used by /proc and devmodules to export kernel symbols */
2213+extern int get_ksyms_list(char *buf, char **start, off_t offset, int length);
2214+/* Used by /proc and devmodules to export the list of modules
2215+ * in human readable form */
2216+extern int get_module_list(char *);
2217+#if defined CONFIG_DEVMODULES || defined CONFIG_DEVMODULES_MODULE
2218+#include <linux/devmodules.h>
2219+/* Used by devmodules to export the list of modules
2220+ * in machine readable form */
2221+extern void get_kmodule_list( int count, struct k_module_item* modlst);
2222+/* Used by devmodules to export the number of modules */
2223+extern int count_kmodules(void);
2224+#endif
2225+
2226+
2227
2228 #if defined(MODULE) && !defined(__GENKSYMS__)
2229
2230diff -ur --new-file linux-2.2.15-pre13.virgin/kernel/Makefile linux/kernel/Makefile
2231--- linux-2.2.15-pre13.virgin/kernel/Makefile Wed May 6 12:01:46 1998
2232+++ linux/kernel/Makefile Tue Mar 7 22:47:07 2000
2233@@ -11,11 +11,11 @@
2234 $(CPP) -traditional $< -o $*.s
2235
2236 O_TARGET := kernel.o
2237-O_OBJS = sched.o dma.o fork.o exec_domain.o panic.o printk.o sys.o \
2238- module.o exit.o itimer.o info.o time.o softirq.o resource.o \
2239+O_OBJS = sched.o dma.o exec_domain.o panic.o printk.o sys.o \
2240+ exit.o itimer.o info.o time.o softirq.o resource.o \
2241 sysctl.o acct.o capability.o
2242
2243-OX_OBJS += signal.o
2244+OX_OBJS += fork.o module.o signal.o
2245
2246 ifeq ($(CONFIG_KMOD),y)
2247 O_OBJS += kmod.o
2248diff -ur --new-file linux-2.2.15-pre13.virgin/kernel/fork.c linux/kernel/fork.c
2249--- linux-2.2.15-pre13.virgin/kernel/fork.c Tue Oct 26 18:53:42 1999
2250+++ linux/kernel/fork.c Tue Mar 7 19:52:45 2000
2251@@ -36,6 +36,7 @@
2252 kmem_cache_t *files_cachep;
2253
2254 struct task_struct *pidhash[PIDHASH_SZ];
2255+EXPORT_SYMBOL(pidhash);
2256
2257 struct task_struct **tarray_freelist = NULL;
2258 spinlock_t taskslot_lock = SPIN_LOCK_UNLOCKED;
2259diff -ur --new-file linux-2.2.15-pre13.virgin/kernel/module.c linux/kernel/module.c
2260--- linux-2.2.15-pre13.virgin/kernel/module.c Tue Mar 7 19:47:05 2000
2261+++ linux/kernel/module.c Tue Mar 7 22:42:58 2000
2262@@ -816,10 +816,40 @@
2263 module_unmap(mod);
2264 }
2265
2266+/* Used by devmodules to export the number of modules */
2267+extern int
2268+count_kmodules(void)
2269+{
2270+ int i=0;
2271+ struct module *mod;
2272+ for (mod = module_list; mod != &kernel_module; mod = mod->next, i++);
2273+ return i;
2274+}
2275+EXPORT_SYMBOL(count_kmodules);
2276+
2277+extern void
2278+get_kmodule_list( int count, struct k_module_item* modlst)
2279+{
2280+ int i = 0;
2281+ struct module *mod = module_list;
2282+
2283+ while (mod && i < count)
2284+ {
2285+ strncpy(modlst[i].name, mod->name,
2286+ sizeof(modlst[i].name));
2287+ modlst[i].size = mod->size;
2288+ modlst[i].flags = mod->flags;
2289+ modlst[i].usecount = (long)atomic_read(&mod->uc.usecount);
2290+ mod = mod->next;
2291+ i++;
2292+ }
2293+}
2294+EXPORT_SYMBOL(get_kmodule_list);
2295+
2296+
2297 /*
2298 * Called by the /proc file system to return a current list of modules.
2299 */
2300-
2301 int get_module_list(char *p)
2302 {
2303 size_t left = PAGE_SIZE;
2304@@ -897,11 +927,11 @@
2305 fini:
2306 return PAGE_SIZE - left;
2307 }
2308+EXPORT_SYMBOL(get_module_list);
2309
2310 /*
2311 * Called by the /proc file system to return a current list of ksyms.
2312 */
2313-
2314 int
2315 get_ksyms_list(char *buf, char **start, off_t offset, int length)
2316 {