📄 devps.patch.9_25_2000
字号:
+ if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0) {+ fprintf (stderr, "\nDEVMTAB_GET_MOUNTS: %s\n", + strerror (errno));+ exit (1);+ } ++ fprintf( stdout, "\nEquivalent of /proc/mounts:\n");+ for( i = 0 ; i < numfilesystems ; i++) {+ fprintf( stdout, "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname,+ mntentlist[i].mnt_dir, mntentlist[i].mnt_type, + mntentlist[i].mnt_opts, mntentlist[i].mnt_freq, + mntentlist[i].mnt_passno);+ }+++ /* clean up */+ free( fslist);+ free( mntentlist);+ if (close (fd) != 0) {+ fprintf (stderr, "close failed for `%s': %s\n",+ device, strerror (errno));+ exit (1);+ }+ + exit (0);+}+diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/drivers/char/ps-devps.c linux/drivers/char/ps-devps.c--- linux-2.2.18-9.virgin/drivers/char/ps-devps.c Wed Dec 31 17:00:00 1969+++ linux/drivers/char/ps-devps.c Mon Sep 25 17:32:19 2000@@ -0,0 +1,148 @@+/* vi: set sw=4 ts=4: */+/*+ * Mini ps implementation for use with the Linux devps driver+ *+ *+ * Copyright (C) 2000 by Erik Andersen <andersee@debian.org>+ *+ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation; either version 2 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+ * General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+ *+ */++#include <stdio.h>+#include <stdlib.h>+#include <errno.h>+#include <string.h>+#include <unistd.h>+#include <time.h>+#include <fcntl.h>+#include <sys/ioctl.h>+#include <linux/devps.h>+#include <pwd.h>+#include <grp.h>+#include <sys/types.h>+++#define MAX_COLUMN 79++int+main (int argc, char **argv)+{+ char device[80] = "/dev/ps";+ int i, j, len;+ int fd; /* file descriptor for devps device */+ int status; /* return status for system calls */+ pid_t num_pids;+ pid_t* pid_array = NULL;+ struct pid_info info;+ struct passwd *pwd;+ struct group *grp;+ char uidName[10] = "";+ char groupName[10] = "";++ if (argc > 1 && **(argv + 1) == '-') {+ fprintf(stderr, "Usage: ps-devps\n\nReport process status\n\nThis version of ps accepts no options.\n\n");+ exit(1);+ }++ /* open device */ + //fd = open(device, O_RDWR);+ fd = open(device, O_RDONLY);+ if (fd < 0) {+ fprintf (stderr, "open failed for `%s': %s\n",+ device, strerror (errno));+ goto error;+ }++ /* Find out how many processes there are */+ status = ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids);+ if (status<0) {+ fprintf (stderr, "\nDEVPS_GET_PID_LIST: %s\n", + strerror (errno));+ goto error;+ } + + /* Allocate some memory -- grab a few extras just in case + * some new processes start up while we wait. The kernel will+ * just ignore any extras if we give it too many, and will trunc.+ * the list if we give it too few. */+ pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));+ pid_array[0] = num_pids+10;++ /* Now grab the pid list */+ status = ioctl (fd, DEVPS_GET_PID_LIST, pid_array);+ if (status<0) {+ fprintf (stderr, "\nDEVPS_GET_PID_LIST: %s\n", + strerror (errno));+ goto error;+ } ++ /* Print up a ps listing */+ fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",+ "State", "Command");++ for (i=1; i<pid_array[0] ; i++) {+ info.pid = pid_array[i];+ status = ioctl (fd, DEVPS_GET_PID_INFO, &info);+ if (status<0) {+ fprintf (stderr, "\nDEVPS_GET_PID_INFO: %s\n", + strerror (errno));+ goto error;+ } + /* Make some adjustments as needed */+ pwd = getpwuid(info.euid);+ if (pwd == NULL)+ sprintf(uidName, "%lu", info.euid);+ else+ sprintf(uidName, "%s", pwd->pw_name);+ grp = getgrgid(info.egid);+ if (grp == NULL)+ sprintf(groupName, "%lu", info.egid);+ else+ sprintf(groupName, "%s", grp->gr_name);++ len = fprintf(stdout, "%5d %-8s %-8s %c ", info.pid, uidName, groupName, info.state);++ if (strlen(info.command_line) > 1) {+ for( j=0; j<(sizeof(info.command_line)-1) && j < (MAX_COLUMN-len); j++) {+ if (*(info.command_line+j) == '\0' && *(info.command_line+j+1) != '\0') {+ *(info.command_line+j) = ' ';+ }+ }+ *(info.command_line+j) = '\0';+ fprintf(stdout, "%s\n", info.command_line);+ } else {+ fprintf(stdout, "[%s]\n", info.name);+ }+ }++ /* Free memory */+ free( pid_array);++ /* close device */+ status = close (fd);+ if (status != 0) {+ fprintf (stderr, "close failed for `%s': %s\n",+ device, strerror (errno));+ goto error;+ }+ + exit (0);+error:+ fflush(stdout);+ fflush(stderr);+ exit (1);+}+diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/fs/Makefile linux/fs/Makefile--- linux-2.2.18-9.virgin/fs/Makefile Wed Aug 25 18:29:49 1999+++ linux/fs/Makefile Mon Sep 25 16:33:16 2000@@ -11,9 +11,10 @@ L_OBJS = $(join $(SUB_DIRS),$(SUB_DIRS:%=/%.o)) O_TARGET := fs.o O_OBJS = open.o read_write.o devices.o file_table.o buffer.o \- super.o block_dev.o stat.o exec.o pipe.o namei.o fcntl.o \+ block_dev.o stat.o exec.o pipe.o namei.o fcntl.o \ ioctl.o readdir.o select.o fifo.o locks.o filesystems.o \ dcache.o inode.o attr.o bad_inode.o file.o $(BINFMTS) +OX_OBJS = super.o MOD_LIST_NAME := FS_MODULES ALL_SUB_DIRS = coda minix ext2 fat msdos vfat proc isofs nfs umsdos ntfs \diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/fs/super.c linux/fs/super.c--- linux-2.2.18-9.virgin/fs/super.c Mon Sep 18 15:02:34 2000+++ linux/fs/super.c Mon Sep 25 17:00:57 2000@@ -18,6 +18,7 @@ */ #include <linux/config.h>+#include <linux/module.h> #include <linux/malloc.h> #include <linux/locks.h> #include <linux/smp_lock.h>@@ -25,6 +26,7 @@ #include <linux/init.h> #include <linux/quotaops.h> #include <linux/acct.h>+#include <linux/devmtab.h> #include <asm/uaccess.h> @@ -311,7 +313,57 @@ { 0, NULL } }; -int get_filesystem_info( char *buf )++extern int count_mounted_filesystems()+{+ struct vfsmount *tmp = vfsmntlist;+ int count = 0;++ while (tmp)+ {+ tmp = tmp->mnt_next;+ count++;+ }++ return count;+}+EXPORT_SYMBOL(count_mounted_filesystems);+++extern void get_mtab_entries( int count, struct k_mntent* mntentlist)+{+ struct vfsmount *tmp = vfsmntlist;+ struct proc_fs_info *fs_infop;+ int i = 0, len;++ while (tmp && i < count)+ {+ strncpy(mntentlist[i].mnt_fsname, tmp->mnt_devname, + sizeof(mntentlist[i].mnt_fsname));+ strncpy(mntentlist[i].mnt_dir, tmp->mnt_dirname, + sizeof(mntentlist[i].mnt_dir));+ strncpy(mntentlist[i].mnt_type, tmp->mnt_sb->s_type->name,+ sizeof(mntentlist[i].mnt_type));+ len = 0;+ len+=sprintf(mntentlist[i].mnt_opts, "%s", + tmp->mnt_flags & MS_RDONLY ? "ro" : "rw");+ for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {+ if (tmp->mnt_flags & fs_infop->flag) {+ strncpy(mntentlist[i].mnt_opts+len, fs_infop->str, + sizeof(mntentlist[i].mnt_opts)-len);+ len += strlen(fs_infop->str);+ }+ }++ /* TODO -- add in NFS stuff */ ++ tmp = tmp->mnt_next;+ i++;+ }+}+EXPORT_SYMBOL(get_mtab_entries);++extern int get_filesystem_info( char *buf ) { struct vfsmount *tmp = vfsmntlist; struct proc_fs_info *fs_infop;@@ -383,8 +435,37 @@ return len; }+EXPORT_SYMBOL(get_filesystem_info);++extern int count_kfstypes()+{+ struct file_system_type * tmp = file_systems;+ int count = 0;++ while (tmp) {+ count++;+ tmp = tmp->next;+ }++ return count;+}+EXPORT_SYMBOL(count_kfstypes);++extern void get_kfstype_list(int count, struct k_fstype* fstypelist)+{+ int i = 0;+ struct file_system_type * tmp = file_systems;++ while (tmp && i < count) {+ strncpy(fstypelist[i].mnt_type, tmp->name, sizeof(fstypelist[i].mnt_type));+ fstypelist[i].mnt_nodev = (tmp->fs_flags & FS_REQUIRES_DEV)? 0 : 1;+ tmp = tmp->next;+ i++;+ }+}+EXPORT_SYMBOL(get_kfstype_list); -int get_filesystem_list(char * buf)+extern int get_filesystem_list(char * buf) { int len = 0; struct file_system_type * tmp;@@ -398,6 +479,7 @@ } return len; }+EXPORT_SYMBOL(get_filesystem_list); struct file_system_type *get_fs_type(const char *name) {diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/include/linux/devmtab.h linux/include/linux/devmtab.h--- linux-2.2.18-9.virgin/include/linux/devmtab.h Wed Dec 31 17:00:00 1969+++ linux/include/linux/devmtab.h Mon Sep 25 17:00:57 2000@@ -0,0 +1,55 @@+/* vi: set sw=8 ts=8: */+/*+ * -- <linux/devmtab.h>+ * + * 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.+ *+ */+ +#ifndef _LINUX_DEVMTAB_H+#define _LINUX_DEVMTAB_H+++/*******************************************************+ * The list of all ioctl(2) commands suported by devmtab.+ * For the devmtab ioctls, I have commandeered some of the+ * higher bits of byte 0xeb.+ *******************************************************/+#define DEVMTAB_COUNT_FILESYSTEMS 0xebaa /* Get a list of all fs */ +#define DEVMTAB_GET_FILESYSTEMS 0xebab /* Get a list of all fs */ +#define DEVMTAB_COUNT_MOUNTS 0xebac /* Returns number of mounted filesystems */+#define DEVMTAB_GET_MOUNTS 0xebad /* Get a list of a mounted fs */+#define DEVMTAB_SET_ROOTFS_DEVNAME 0xebae /* Replace /dev/root with real name */++/*******************************************************+ * devmtab ioctl(2) structures+ *******************************************************/++/* An array of these is returned by the DEVMTAB_GET_FILESYSTEMS ioctl.+ */+struct k_fstype {+ char mnt_type[255]; /* filesystem type: ext2, nfs, etc. */+ int mnt_nodev; /* Is this a device-less filesystem? */+};++/* An array of these is returned by the DEVMTAB_GET_MOUNTS ioctl.+ * This struct should be the same as what libc returns via the+ * getmntent(3) function (excat this comes from the kernel, not+ * from whatever noise is in /etc/mtab at the moment... */+struct k_mntent {+ char mnt_fsname[255]; /* name of mounted file system */+ char mnt_dir[255]; /* path of file system mount point */+ char mnt_type[255]; /* filesystem type: ext2, nfs, etc. */+ char mnt_opts[255]; /* Comma-separated list of mount options */+ int mnt_freq; /* dump frequency in days */+ int mnt_passno; /* pass number for parallel fsck */+};++#endif /* _LINUX_DEVMTAB_H */diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/include/linux/devps.h linux/include/linux/devps.h--- linux-2.2.18-9.virgin/include/linux/devps.h Wed Dec 31 17:00:00 1969+++ linux/include/linux/devps.h Mon Sep 25 17:00:57 2000@@ -0,0 +1,78 @@+/*+ * -- <linux/devps.h>+ * + * 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.+ *+ */+ +#ifndef _LINUX_DEVPS_H+#define _LINUX_DEVPS_H+++/*******************************************************+ * The list of all ioctl(2) commands suported by devps.+ * For the devps ioctls, I have commandeered some of the+ * higher bits of byte 0xeb.+ *******************************************************/+#define DEVPS_GET_NUM_PIDS 0xeba1 /* Get a list of all PIDs */ +#define DEVPS_GET_PID_LIST 0xeba2 /* Get a list of all PIDs */ +#define DEVPS_GET_PID_INFO 0xeba3 /* Get info about a specific PID */+#define DEVPS_GET_CURRENT_PID 0xeba4 /* Get the current PID */++/*******************************************************+ * devps ioctl(2) structures+ *******************************************************/+++struct pid_info+{+ char name[16];+ long flags;+ pid_t pgrp;+ clock_t tms_cutime;+ clock_t tms_cstime;+ clock_t tms_utime;+ clock_t tms_stime;+ unsigned long min_flt;+ unsigned long cmin_flt;+ unsigned long maj_flt;+ unsigned long cmaj_flt;+ pid_t session;+ pid_t pid;+ pid_t ppid;+ int tty;+ unsigned long start_time;+ unsigned long uid,euid,suid,fsuid;+ unsigned long gid,egid,sgid,fsgid;+ long priority, nice;+ char state;+ int processor;+ unsigned long nswap, cnswap;+ char command_line[256];+ char environment[256];+ char root[256];+ char cwd[256];+#if 0+ /* TODO: Add in this (and probably more) stuff */++ int resident;+ int size;+ int share;+ unsigned long vsize;+ char exe[MAX_PATH];+ unsigned long vm_total, vm_locked, vm_rss, vm_data, vm_stack, vm_exec, vm_lib;+ unsigned long start_code, end_code, start_data, eip, esp;+ unsigned long signal, blocked;+#endif+++};++#endif /* _LINUX_DEVPS_H */diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/include/linux/fs.h linux/include/linux/fs.h--- linux-2.2.18-9.virgin/include/linux/fs.h Mon Sep 18 15:08:47 2000+++ linux/include/linux/fs.h Mon Sep 25 17:37:50 2000@@ -573,6 +573,16 @@ struct semaphore s_vfs_rename_sem; /* Kludge */ }; +/* fs/super.c */+#include <linux/devmtab.h>++extern int count_kfstypes( void);+extern void get_kfstype_list( int count, struct k_fstype* fstypelist); +extern int count_mounted_filesystems( void);+extern int get_filesystem_info(char *buf);+extern int get_filesystem_list(char *buf);+extern void get_mtab_entries( int count, struct k_mntent* mntentlist);+ /* * VFS helper functions.. */diff -urN --exclude=.version --exclude=.config* --exclude=.*depend linux-2.2.18-9.virgin/include/linux/miscdevice.h linux/include/linux/miscdevice.h--- linux-2.2.18-9.virgin/include/linux/miscdevice.h Mon Aug 9 13:04:41 1999+++ linux/include/linux/miscdevice.h Mon Sep 25 16:33:17 2000@@ -11,6 +11,8 @@ #define APOLLO_MOUSE_MINOR 7 #define PC110PAD_MINOR 9 #define MAC_MOUSE_MINOR 10+#define DEVPS_MINOR 21+#define DEVMTAB_MINOR 22 #define WATCHDOG_MINOR 130 /* Watchdog timer */ #define TEMP_MINOR 131 /* Temperature Sensor */ #define RTC_MINOR 135
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -