Messages in this thread Patch in this message | | | Date | Sun, 9 May 1999 02:18:26 +0000 | From | Michele Bini <> | Subject | [patch] obvious (?) fix for procfs (solves sed problem, too) |
| |
When a file on /proc is stat()'ed the bit S_IFREG (regular file) is returned so many programs & libs (including libc) assume that the st_size file returned during that stat is valid, so they read data only up to that size.
The attached patch simply makes the kernel not to set the 'regular file' bit.
This patch solves the problem with sed which came up in linux-kernel:
$ sed "s/a/a/" </proc/modules autofs 8980 2 (autoclean) unix 10588 33 (autoclean)
-Michele diff --recursive -u linux/fs/proc/base.c linux-proc/fs/proc/base.c --- linux/fs/proc/base.c Mon Aug 24 20:02:43 1998 +++ linux-proc/fs/proc/base.c Sun May 9 00:02:17 1999 @@ -92,13 +92,13 @@ static struct proc_dir_entry proc_pid_status = { PROC_PID_STATUS, 6, "status", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations, NULL, proc_pid_fill_inode, }; static struct proc_dir_entry proc_pid_mem = { PROC_PID_MEM, 3, "mem", - S_IFREG | S_IRUSR | S_IWUSR, 1, 0, 0, + S_IRUSR | S_IWUSR, 1, 0, 0, 0, &proc_mem_inode_operations, NULL, proc_pid_fill_inode, }; @@ -128,25 +128,25 @@ }; static struct proc_dir_entry proc_pid_environ = { PROC_PID_ENVIRON, 7, "environ", - S_IFREG | S_IRUSR, 1, 0, 0, + S_IRUSR, 1, 0, 0, 0, &proc_array_inode_operations, NULL, proc_pid_fill_inode, }; static struct proc_dir_entry proc_pid_cmdline = { PROC_PID_CMDLINE, 7, "cmdline", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations, NULL, proc_pid_fill_inode, }; static struct proc_dir_entry proc_pid_stat = { PROC_PID_STAT, 4, "stat", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations, NULL, proc_pid_fill_inode, }; static struct proc_dir_entry proc_pid_statm = { PROC_PID_STATM, 5, "statm", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations, NULL, proc_pid_fill_inode, }; @@ -160,7 +160,7 @@ #if CONFIG_AP1000 static struct proc_dir_entry proc_pid_ringbuf = { PROC_PID_RINGBUF, 7, "ringbuf", - S_IFREG | S_IRUGO | S_IWUSR, 1, 0, 0, + S_IRUGO | S_IWUSR, 1, 0, 0, 0, &proc_ringbuf_inode_operations, NULL, proc_pid_fill_inode, }; @@ -169,7 +169,7 @@ #ifdef __SMP__ static struct proc_dir_entry proc_pid_cpu = { PROC_PID_CPU, 3, "cpu", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations, NULL, proc_pid_fill_inode, }; diff --recursive -u linux/fs/proc/generic.c linux-proc/fs/proc/generic.c --- linux/fs/proc/generic.c Mon Aug 24 20:02:44 1998 +++ linux-proc/fs/proc/generic.c Sun May 9 00:04:00 1999 @@ -267,8 +267,6 @@ ent->ops = &proc_dyna_dir_inode_operations; ent->nlink = 2; } else { - if ((mode & S_IFMT) == 0) - mode |= S_IFREG; if ((mode & S_IALLUGO) == 0) mode |= S_IRUGO; ent->nlink = 1; diff --recursive -u linux/fs/proc/openpromfs.c linux-proc/fs/proc/openpromfs.c --- linux/fs/proc/openpromfs.c Sun May 9 01:20:00 1999 +++ linux-proc/fs/proc/openpromfs.c Sun May 9 00:02:17 1999 @@ -792,7 +792,7 @@ inode->i_nlink = 2; break; case OPFSL_NODENUM: - inode->i_mode = S_IFREG | S_IRUGO; + inode->i_mode = S_IRUGO; inode->i_op = &openpromfs_nodenum_inode_ops; inode->i_nlink = 1; inode->u.generic_ip = (void *)(long)(n); @@ -800,9 +800,9 @@ case OPFSL_PROPERTY: if ((dirnode == options) && (len == 17) && !strncmp (name, "security-password", 17)) - inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR; + inode->i_mode = S_IRUSR | S_IWUSR; else { - inode->i_mode = S_IFREG | S_IRUGO; + inode->i_mode = S_IRUGO; if (dirnode == options || dirnode == aliases) { if (len != 4 || strncmp (name, "name", 4)) inode->i_mode |= S_IWUSR; @@ -943,7 +943,7 @@ + aliases_nodes, 0); if (!inode) return -EINVAL; - inode->i_mode = S_IFREG | S_IRUGO | S_IWUSR; + inode->i_mode = S_IRUGO | S_IWUSR; inode->i_op = &openpromfs_prop_inode_ops; inode->i_nlink = 1; if (inode->i_size < 0) inode->i_size = 0; diff --recursive -u linux/fs/proc/proc_devtree.c linux-proc/fs/proc/proc_devtree.c --- linux/fs/proc/proc_devtree.c Sat Sep 19 20:43:36 1998 +++ linux-proc/fs/proc/proc_devtree.c Sun May 9 00:02:17 1999 @@ -119,7 +119,7 @@ memset(ent, 0, sizeof(struct proc_dir_entry)); ent->name = pp->name; ent->namelen = strlen(pp->name); - ent->mode = S_IFREG | S_IRUGO; + ent->mode = S_IRUGO; ent->nlink = 1; ent->data = pp; ent->read_proc = property_read_proc; diff --recursive -u linux/fs/proc/root.c linux-proc/fs/proc/root.c --- linux/fs/proc/root.c Sun May 9 01:20:00 1999 +++ linux-proc/fs/proc/root.c Sun May 9 00:02:18 1999 @@ -507,45 +507,45 @@ static struct proc_dir_entry proc_root_loadavg = { PROC_LOADAVG, 7, "loadavg", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_uptime = { PROC_UPTIME, 6, "uptime", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_meminfo = { PROC_MEMINFO, 7, "meminfo", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_kmsg = { PROC_KMSG, 4, "kmsg", - S_IFREG | S_IRUSR, 1, 0, 0, + S_IRUSR, 1, 0, 0, 0, &proc_kmsg_inode_operations }; static struct proc_dir_entry proc_root_version = { PROC_VERSION, 7, "version", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_cpuinfo = { PROC_CPUINFO, 7, "cpuinfo", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; #if defined (CONFIG_PROC_HARDWARE) static struct proc_dir_entry proc_root_hardware = { PROC_HARDWARE, 8, "hardware", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; #endif #ifdef CONFIG_STRAM_PROC static struct proc_dir_entry proc_root_stram = { PROC_STRAM, 5, "stram", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; #endif @@ -557,50 +557,50 @@ #ifdef CONFIG_DEBUG_MALLOC static struct proc_dir_entry proc_root_malloc = { PROC_MALLOC, 6, "malloc", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; #endif static struct proc_dir_entry proc_root_kcore = { PROC_KCORE, 5, "kcore", - S_IFREG | S_IRUSR, 1, 0, 0, + S_IRUSR, 1, 0, 0, 0, &proc_kcore_inode_operations }; #ifdef CONFIG_MODULES static struct proc_dir_entry proc_root_modules = { PROC_MODULES, 7, "modules", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_ksyms = { PROC_KSYMS, 5, "ksyms", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; #endif static struct proc_dir_entry proc_root_stat = { PROC_STAT, 4, "stat", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_devices = { PROC_DEVICES, 7, "devices", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_partitions = { PROC_PARTITIONS, 10, "partitions", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_interrupts = { PROC_INTERRUPTS, 10,"interrupts", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_filesystems = { PROC_FILESYSTEMS, 11,"filesystems", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; struct proc_dir_entry proc_root_fs = { @@ -613,55 +613,55 @@ }; static struct proc_dir_entry proc_root_dma = { PROC_DMA, 3, "dma", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_ioports = { PROC_IOPORTS, 7, "ioports", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_cmdline = { PROC_CMDLINE, 7, "cmdline", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; #ifdef CONFIG_RTC static struct proc_dir_entry proc_root_rtc = { PROC_RTC, 3, "rtc", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; #endif static struct proc_dir_entry proc_root_locks = { PROC_LOCKS, 5, "locks", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_mounts = { PROC_MTAB, 6, "mounts", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_swaps = { PROC_SWAP, 5, "swaps", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; static struct proc_dir_entry proc_root_profile = { PROC_PROFILE, 7, "profile", - S_IFREG | S_IRUGO | S_IWUSR, 1, 0, 0, + S_IRUGO | S_IWUSR, 1, 0, 0, 0, &proc_profile_inode_operations }; static struct proc_dir_entry proc_root_slab = { PROC_SLABINFO, 8, "slabinfo", - S_IFREG | S_IRUGO, 1, 0, 0, + S_IRUGO, 1, 0, 0, 0, &proc_array_inode_operations }; #ifdef __powerpc__ static struct proc_dir_entry proc_root_ppc_htab = { PROC_PPC_HTAB, 8, "ppc_htab", - S_IFREG | S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, 1, 0, 0, + S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, 1, 0, 0, 0, &proc_ppc_htab_inode_operations, NULL, NULL, /* get_info, fill_inode */ NULL, /* next */ | |