Fix: proc-fs more than 256 fds

Edgar Toernig (froese@gmx.de)
Sat, 02 May 1998 01:44:32 +0200


This is a multi-part message in MIME format.
--------------F15A725D3384CC21E15003E9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

below a small fix to allow more than 256 fds in the
/proc/<pid>/fd directories. The limit is raised to
32768. Should be enough for a while...

It's not testest...

Sorry, it's against 2.1.98.

Ciao, ET.

PS: Is a patch for 2.0.34 required? (Alan)
--------------F15A725D3384CC21E15003E9
Content-Type: text/plain; charset=us-ascii; name="proc-fd-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="proc-fd-patch"

diff -u --recursive --new-file linux-2.1.98/fs/proc/base.c linux-2.1.98.et/fs/proc/base.c
--- linux-2.1.98/fs/proc/base.c Sat Mar 21 23:55:34 1998
+++ linux-2.1.98.et/fs/proc/base.c Fri May 1 20:37:56 1998
@@ -189,13 +189,3 @@
proc_register(&proc_pid, &proc_pid_cpu);
#endif
};
-
-
-
-
-
-
-
-
-
-
diff -u --recursive --new-file linux-2.1.98/fs/proc/fd.c linux-2.1.98.et/fs/proc/fd.c
--- linux-2.1.98/fs/proc/fd.c Sun Apr 5 18:25:40 1998
+++ linux-2.1.98.et/fs/proc/fd.c Sat May 2 00:19:01 1998
@@ -4,6 +4,10 @@
* Copyright (C) 1991, 1992 Linus Torvalds
*
* proc fd directory handling functions
+ *
+ * 01-May-98 Edgar Toernig <froese@gmx.de>
+ * Added support for more than 256 fds.
+ * Limit raised to 32768.
*/

#include <linux/errno.h>
@@ -91,7 +95,7 @@
goto out;
fd *= 10;
fd += c;
- if (fd & 0xffff0000)
+ if (fd & 0xffff8000)
goto out;
}

@@ -111,8 +115,7 @@
if (!file || !file->f_dentry)
goto out;

- /* N.B. What happens if fd > 255?? */
- ino = (pid << 16) + (PROC_PID_FD_DIR << 8) + fd;
+ ino = (pid << 16) + PROC_PID_FD_DIR + fd;
inode = proc_get_inode(dir->i_sb, ino, NULL);
if (inode) {
d_add(dentry, inode);
@@ -144,7 +147,7 @@
goto out;

for (fd = filp->f_pos; fd < 2; fd++, filp->f_pos++) {
- unsigned long ino = inode->i_ino;
+ ino = inode->i_ino;
if (fd)
ino = (ino & 0xffff0000) | PROC_PID_INO;
if (filldir(dirent, "..", fd+1, fd, ino) < 0)
@@ -176,7 +179,7 @@
/* Drop the task lock, as the filldir function may block */
read_unlock(&tasklist_lock);

- ino = (pid << 16) + (PROC_PID_FD_DIR << 8) + fd;
+ ino = (pid << 16) + PROC_PID_FD_DIR + fd;
if (filldir(dirent, buf+j, NUMBUF-j, fd+2, ino) < 0)
goto out;

diff -u --recursive --new-file linux-2.1.98/fs/proc/inode-alloc.txt linux-2.1.98.et/fs/proc/inode-alloc.txt
--- linux-2.1.98/fs/proc/inode-alloc.txt Thu Jan 1 01:00:00 1970
+++ linux-2.1.98.et/fs/proc/inode-alloc.txt Fri May 1 21:20:17 1998
@@ -0,0 +1,50 @@
+Inode allocations in the proc-fs (hex-numbers):
+
+ 00000000 reserved
+ 00000001-00000fff static entries
+ 001 root-ino
+ 002 load-avg
+ 003 uptime
+ ...
+ 080 net/*
+ ...
+ 100 scsi/*
+ ...
+ xxx mca/*
+ ...
+ yyy bus/*
+ ...
+ fff end
+
+ 00001000-00001fff dynamic entries
+
+ 00002000-00002fff openprom entries
+
+ 0001xxxx-7fffxxxx pid-dir entries for pid 1-7fff
+ 0000 unused
+ 0001 unused
+ 0002 pid
+ 0003 pid/status
+ ...
+ 0008 pid/fd
+ ...
+ 00xx-00ff unused
+ 01xx pid/fd/* for fd 0-ff
+ ...
+ 01ff end
+ 0200-ffff unused
+
+ 80000000-ffffffff unused
+
+
+
+New allocation:
+
+ 00000000-0000ffff unchanged
+
+ 0001xxxx-7fffxxxx pid-dir entries for pid 1-7fff
+ 0000-00ff unchanged
+ 0100-7fff unused
+ 8000-ffff pid/fd/* for fd 0-7fff
+
+ 80000000-ffffffff unchanged
diff -u --recursive --new-file linux-2.1.98/fs/proc/inode.c linux-2.1.98.et/fs/proc/inode.c
--- linux-2.1.98/fs/proc/inode.c Fri May 1 18:23:25 1998
+++ linux-2.1.98.et/fs/proc/inode.c Fri May 1 20:57:40 1998
@@ -377,10 +377,9 @@
inode->i_uid = p->euid;
inode->i_gid = p->egid;
}
- switch (ino >> 8) {
+ if (ino & PROC_PID_FD_DIR) {
struct file * file;
- case PROC_PID_FD_DIR:
- ino &= 0xff;
+ ino &= 0x7fff;
file = fcheck_task(p, ino);
if (!file)
goto out_unlock;
diff -u --recursive --new-file linux-2.1.98/fs/proc/link.c linux-2.1.98.et/fs/proc/link.c
--- linux-2.1.98/fs/proc/link.c Fri May 1 18:22:30 1998
+++ linux-2.1.98.et/fs/proc/link.c Fri May 1 21:00:11 1998
@@ -111,10 +111,9 @@
goto out_unlock;
}
default:
- switch (ino >> 8) {
+ if (ino & PROC_PID_FD_DIR) {
struct file * file;
- case PROC_PID_FD_DIR:
- ino &= 0xff;
+ ino &= 0x7fff;
file = fcheck_task(p, ino);
if (!file || !file->f_dentry)
goto out_unlock;
diff -u --recursive --new-file linux-2.1.98/include/linux/proc_fs.h linux-2.1.98.et/include/linux/proc_fs.h
--- linux-2.1.98/include/linux/proc_fs.h Fri May 1 18:23:27 1998
+++ linux-2.1.98.et/include/linux/proc_fs.h Fri May 1 23:55:08 1998
@@ -72,7 +72,7 @@
};

enum pid_subdirectory_inos {
- PROC_PID_FD_DIR = 1
+ PROC_PID_FD_DIR = 0x8000, /* 0x8000-0xffff */
};

enum net_directory_inos {

--------------F15A725D3384CC21E15003E9--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu