📄 devps.patch.9_25_2000
字号:
diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/drivers/char/Config.in linux/drivers/char/Config.in--- linux-2.2.18-9.virgin/drivers/char/Config.in Mon Sep 18 15:02:30 2000+++ linux/drivers/char/Config.in Mon Sep 25 16:33:16 2000@@ -56,6 +56,8 @@ dep_tristate 'Microgate SyncLink card support' CONFIG_SYNCLINK m dep_tristate 'HDLC line discipline support' CONFIG_N_HDLC m fi+tristate 'Devps support' CONFIG_DEVPS+tristate 'Devmounts support' CONFIG_DEVMTAB bool 'Unix98 PTY support' CONFIG_UNIX98_PTYS if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then int 'Maximum number of Unix98 PTYs in use (0-2048)' CONFIG_UNIX98_PTY_COUNT 256diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/drivers/char/Makefile linux/drivers/char/Makefile--- linux-2.2.18-9.virgin/drivers/char/Makefile Mon Sep 18 15:02:30 2000+++ linux/drivers/char/Makefile Mon Sep 25 18:01:12 2000@@ -697,6 +697,22 @@ M_OBJS += $(sort $(filter $(module-list), $(obj-m))) +ifeq ($(CONFIG_DEVPS),y)+O_OBJS += devps.o+else+ ifeq ($(CONFIG_DEVPS),m)+ M_OBJS += devps.o+ endif+endif++ifeq ($(CONFIG_DEVMTAB),y)+O_OBJS += devmtab.o+else+ ifeq ($(CONFIG_DEVMTAB),m)+ M_OBJS += devmtab.o+ endif+endif+ include $(TOPDIR)/Rules.make fastdep:diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/drivers/char/devmtab.c linux/drivers/char/devmtab.c--- linux-2.2.18-9.virgin/drivers/char/devmtab.c Wed Dec 31 17:00:00 1969+++ linux/drivers/char/devmtab.c Mon Sep 25 17:00:57 2000@@ -0,0 +1,295 @@+/* vi: set sw=8 ts=8: */+/*+ * linux/drivers/char/devmtab.c+ * + * Copyright (C) 2000 Erik Andersen <andersee@debian.org>+ *+ * May be copied or modified under the terms of the GNU General Public License.+ * See linux/COPYING for more information.+ *+ * This driver implements an interface whereby programs such as mount(8),+ * umount(8), and df(1) may obtain all the process information they need to do+ * their jobs without needing to use /proc. This driver another step in my+ * evil plan to completely dismantle /proc. Muhahahaha!+ *+ * Suggestions are welcome. Patches that work are more welcome though. ;-)+ *+ *+ * When using this driver, running:+ * mknod /dev/mtab c 10 22+ * could be considered helpful.+ *+ * ----------------------------------+ * 1.00 Mar 07, 2000 -- Initial version.+ *+ *************************************************************************/++#define DEVMTAB_VERSION "1.00"++#include <linux/config.h>+#include <linux/module.h>+#include <linux/types.h>+#include <linux/sched.h>+#include <linux/fs.h>+#include <linux/mm.h>+#include <linux/pagemap.h>+#include <linux/malloc.h>+#include <linux/miscdevice.h>+#include <linux/devmtab.h>+#include <linux/wrapper.h>+#include <asm/pgtable.h>+#include <asm/uaccess.h>+++/* Some variables used by this device */+static struct wait_queue *devmtab_waitq = NULL;+static int devmtab_already_opened = 0;+static char *mtabfile = NULL;+static int mtab_ptr;+static int mtab_size;++++/****************************************************************************+ * Handle opening and closing of the device+ */++static long long+devmtab_lseek (struct file *file, long long offset, int orig)+{+ return -ESPIPE;+}++static ssize_t+devmtab_read (struct file *file, char *buf, size_t count, loff_t * ppos)+{+ int n = mtab_size - mtab_ptr;++ if (mtab_size == 0) {+ /* Make some space */+ if (!(mtabfile = (char *) get_free_page (GFP_KERNEL)))+ return -ENOMEM;+ /* Grab the mtab */+ get_filesystem_info (mtabfile);+ mtab_ptr = 0;+ mtab_size = strlen (mtabfile);+ n = mtab_size - mtab_ptr;+ }++ if (n > count)+ n = count;+ if (n <= 0)+ return 0;++ if (copy_to_user (buf, mtabfile, n))+ return -EFAULT;+ mtab_ptr += n;+ return n;+}++static int devmtab_open (struct inode *ip, struct file *fp)+{+ /* Only let one process use us at any time -- putting other+ * processes to sleep. Those opening us O_NONBLOCK will+ * get an EAGAIN error */+ if ((fp->f_flags & O_NONBLOCK) && devmtab_already_opened) + return -EAGAIN;++ MOD_INC_USE_COUNT;++ while (devmtab_already_opened) {+ int i, got_signal=0;++ /* Go to sleep until we get woken up + * by devmtab_close or we receive a signal */+ module_interruptible_sleep_on(&devmtab_waitq);++ for(i=0; i<_NSIG_WORDS && !got_signal; i++)+ got_signal = current->signal.sig[i] & ~current->blocked.sig[i];++ /* If we got a signal, decrement the use count+ * and return to user space */+ if (got_signal) {+ MOD_DEC_USE_COUNT;+ return -EINTR;+ }+ }++ /* Since we got here, then devmtab_already_opened must equal 0 */+ devmtab_already_opened=1;+ mtab_ptr = 0;+ mtab_size = 0;++ return 0;+}++static int devmtab_release (struct inode *ip, struct file *fp)+{+ /* Clean up */+ if (mtabfile != NULL) {+ free_page ((unsigned long) mtabfile);+ mtabfile = NULL;+ }++ /* Zero out the reference counter */+ devmtab_already_opened=0;++ /* Wake up anybody that is waiting to access this device */+ module_wake_up(&devmtab_waitq);++ MOD_DEC_USE_COUNT;++ return 0;+}++static int+devmtab_ioctl (struct inode *ip, struct file *fp,+ unsigned int cmd, unsigned long arg)+{+ switch (cmd) {+ case DEVMTAB_COUNT_FILESYSTEMS:{+ return(count_kfstypes());+ }++ case DEVMTAB_GET_FILESYSTEMS:{+ int stat, count;+ struct k_fstype* fstypelist;++ /* How many are there? */+ count = count_kfstypes();++ /* Make some space */+ fstypelist = (struct k_fstype *)kmalloc(sizeof(struct k_fstype) * count, GFP_KERNEL);+ if (!fstypelist)+ return -ENOMEM;+ memset(fstypelist, 0, sizeof(struct k_fstype) * count);++ /* Grab the mtab entries */+ get_kfstype_list(count, fstypelist);++ /* Make sure there is enough room */+ stat = verify_area (VERIFY_WRITE, (struct k_fstype *) arg,+ sizeof(struct k_fstype) * count);+ if (stat) {+ printk (KERN_INFO+ "devmtab: Insufficient space was provided.\n");+ return stat;+ }++ /* Send it to user space */+ copy_to_user_ret ((struct k_fstype *) arg, fstypelist,+ sizeof(struct k_fstype) * count, + -EFAULT);++ /* Clean up */+ kfree( fstypelist);+ return 0;+ }++ case DEVMTAB_COUNT_MOUNTS:{+ return(count_mounted_filesystems());+ }++ case DEVMTAB_GET_MOUNTS:{+ int stat, count;+ struct k_mntent* mntentlist;++ /* How many are there? */+ count = count_mounted_filesystems();++ /* Make some space */+ mntentlist = (struct k_mntent *)kmalloc(sizeof(struct k_mntent) * count, GFP_KERNEL);+ if (!mntentlist)+ return -ENOMEM;+ memset(mntentlist, 0, sizeof(struct k_mntent) * count);++ /* Grab the mtab entries */+ get_mtab_entries (count, mntentlist);++ /* Make sure there is enough room */+ stat = verify_area (VERIFY_WRITE, (void*) arg,+ sizeof(struct k_mntent) * count);+ if (stat) {+ printk (KERN_INFO+ "devmtab: Insufficient space was provided.\n");+ return stat;+ }++ /* Send it to user space */+ copy_to_user_ret ((struct k_mntent *) arg, mntentlist,+ sizeof(struct k_mntent) * count, + -EFAULT);++ /* Clean up */+ kfree( mntentlist);+ return 0;+ }++ default:+ return -EINVAL;++ }+ return 0;+}++++/****************************************************************************+ * Set up the file operations devmtab will support+ */+static struct file_operations devmtab_fops = {+ devmtab_lseek,+ devmtab_read,+ NULL, /* No write */+ NULL, /* No readdir */+ NULL, /* No poll */+ devmtab_ioctl,+ NULL, /* No mmap */+ devmtab_open,+ NULL, /* flush */+ devmtab_release,+ NULL, /* fsync */+ NULL, /* fasync */+ NULL, /* check_media_change */+ NULL /* revalidate */+};++static struct miscdevice devmtab_misc_dev = {+ DEVMTAB_MINOR,+ "devmtab",+ &devmtab_fops+};++/* The real driver initialization function */+extern int devmtab_init (void)+{+ printk (KERN_INFO "devmtab: driver %s loaded\n", DEVMTAB_VERSION);++ if (misc_register (&devmtab_misc_dev)) {+ printk ("devmtab: can't register misc device %d\n",+ DEVMTAB_MINOR);+ return -EIO;+ }++ return 0;+}++#ifdef MODULE++MODULE_AUTHOR ("Erik Andersen <andersee@debian.org>");+MODULE_DESCRIPTION+ ("devmtab driver -- exports filesystem and mount information to user space");++/* Stub driver initialization function */+int init_module (void)+{+ return (devmtab_init ());+}++void cleanup_module (void)+{+ printk (KERN_INFO "devmtab: driver unloaded\n");+ misc_deregister (&devmtab_misc_dev);+}++#endif /* MODULE */diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/drivers/char/devps.c linux/drivers/char/devps.c--- linux-2.2.18-9.virgin/drivers/char/devps.c Wed Dec 31 17:00:00 1969+++ linux/drivers/char/devps.c Mon Sep 25 17:00:57 2000@@ -0,0 +1,518 @@+/* vi: set sw=8 ts=8: */+/*+ * linux/drivers/char/devps.c+ * + * Copyright (C) 2000 Erik Andersen <andersee@debian.org>+ *+ * May be copied or modified under the terms of the GNU General Public License.+ * See linux/COPYING for more information.+ *+ * This driver implements an interface whereby programs such as ps(1), top(1),+ * killall(1) and the like may obtain all the process information they need to+ * do their jobs. Now you may ask, "Why not use /proc? BSD uses /proc.".+ * Thanks for asking. /proc is designed as a virtual filesystem. As such it+ * presents all of its information in a nice, human readable format. But not+ * human readable enough that mere mortals can actually look at the /proc+ * information and know what is happening on their computer (which is why we+ * have nice programs like ps(1) to help us out. Additionally, for ps (using+ * /proc) to do its job, it has to do something like:+ *+ * dir = opendir("/proc");+ * while ((entry = readdir(dir)) != NULL) { + * if (!isdigit(*entry->d_name))+ * continue;+ * open_lots_of files();+ * parse_lots_of_strings();+ * close_lots_of_files();+ * print_stuff();+ * }+ *+ *+ * This is bad, because:+ *+ * 1) opening and closing lots of files is slow,+ *+ * 2) parsing lots of strings is slow,+ *+ * 3) every one of those strings had to be carefully printed out and formatted+ * by the kernel, which is slow,+ *+ * 4) using a virtual filesystem is not the traditional UN*X solution to+ * getting information from the kernel out to userspace (ioctls and syscalls+ * are the established way to do this), and worst of all+ *+ * 5) having a virtual filesystem around has been so inviting that everyone has+ * put their own weird little files into it, causing /proc to become a+ * cluttered rubbish heap of 64 flavors of strange that takes a ridiculous+ * amount of memory. + *+ * This driver is the first step in my evil plan to completely + * dismantle /proc. Muhahahaha!+ *+ * Suggestions are welcome. Patches that work are more welcome though. ;-)+ *+ * When using this driver, running:+ * mknod /dev/ps c 10 21+ * could be considered helpful.+ *+ * ----------------------------------+ * 1.00 Mar 07, 2000 -- Initial version.+ *+ *+ * TODO+ * ----------------------------------+ *+ * * Right now none of the vm or fd info is being returned to user space. + * * There is probably other stuff that should be exported to user space.+ *+ *+ *************************************************************************/++#define DEVPS_VERSION "1.00"++#include <linux/config.h>+#include <linux/module.h>+#include <linux/types.h>+#include <linux/sched.h>+#include <linux/fs.h>+#include <linux/mm.h>+#include <linux/pagemap.h>+#include <linux/malloc.h>+#include <linux/miscdevice.h>+#include <linux/devps.h>+#include <linux/wrapper.h>+#include <asm/pgtable.h>+#include <asm/uaccess.h>++/* Some variables used by this device */+static struct wait_queue *devps_waitq = NULL;+static int devps_already_opened = 0;++/****************************************************************************+ * Handle opening and closing of the device+ */++static int devps_open (struct inode *ip, struct file *fp)+{+ /* Only let one process use us at any time -- putting other+ * processes to sleep. Those opening us O_NONBLOCK will+ * get an EAGAIN error */+ if ((fp->f_flags & O_NONBLOCK) && devps_already_opened) + return -EAGAIN;++ MOD_INC_USE_COUNT;++ while (devps_already_opened) {+ int i, got_signal=0;++ /* Go to sleep until we get woken up + * by devps_close or we receive a signal */+ module_interruptible_sleep_on(&devps_waitq);++ for(i=0; i<_NSIG_WORDS && !got_signal; i++)+ got_signal = current->signal.sig[i] & ~current->blocked.sig[i];++ /* If we got a signal, decrement the use count+ * and return to user space */+ if (got_signal) {+ MOD_DEC_USE_COUNT;+ return -EINTR;+ }+ }++ /* Since we got here, then device_already_opened must equal 0 */+ devps_already_opened=1;+ return 0;+}++static int devps_release (struct inode *ip, struct file *fp)+{+ /* Zero out the reference counter */+ devps_already_opened=0;++ /* Wake up anybody that is waiting to access this device */+ module_wake_up(&devps_waitq);++ MOD_DEC_USE_COUNT;+ return 0;+}+++/*+ * This pretty-prints the pathname of a dentry,+ * clarifying sockets etc.+ */+static int+get_name_from_dentry (struct dentry *dentry, char *buffer, int buflen)+{+ struct inode *inode;+ char *tmp = (char *) __get_free_page (GFP_KERNEL), *path, *pattern;+ int len;++ if (tmp == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -