Linux 2.2.0
[davej-history.git] / fs / proc / net.c
bloba6d8c561654724ee29083a0ba987bfdf4317bcb0
1 /*
2 * linux/fs/proc/net.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * gjh 3/'93 heim@peanuts.informatik.uni-tuebingen.de (Gerald J. Heim)
7 * most of this file is stolen from base.c
8 * it works, but you shouldn't use it as a guideline
9 * for new proc-fs entries. once i'll make it better.
10 * fvk 3/'93 waltje@uwalt.nl.mugnet.org (Fred N. van Kempen)
11 * cleaned up the whole thing, moved "net" specific code to
12 * the NET kernel layer (where it belonged in the first place).
13 * Michael K. Johnson (johnsonm@stolaf.edu) 3/93
14 * Added support from my previous inet.c. Cleaned things up
15 * quite a bit, modularized the code.
16 * fvk 4/'93 waltje@uwalt.nl.mugnet.org (Fred N. van Kempen)
17 * Renamed "route_get_info()" to "rt_get_info()" for consistency.
18 * Alan Cox (gw4pts@gw4pts.ampr.org) 4/94
19 * Dusted off the code and added IPX. Fixed the 4K limit.
20 * Erik Schoenfelder (schoenfr@ibr.cs.tu-bs.de)
21 * /proc/net/snmp.
22 * Alan Cox (gw4pts@gw4pts.ampr.org) 1/95
23 * Added AppleTalk slots
25 * proc net directory handling functions
27 #include <linux/errno.h>
28 #include <linux/sched.h>
29 #include <linux/proc_fs.h>
30 #include <linux/stat.h>
31 #include <linux/fcntl.h>
32 #include <linux/mm.h>
34 #include <asm/uaccess.h>
36 #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */
38 static long proc_readnet(struct inode * inode, struct file * file,
39 char * buf, unsigned long count)
41 char * page;
42 int bytes=count;
43 int copied=0;
44 char *start;
45 struct proc_dir_entry * dp;
47 if (count < 0)
48 return -EINVAL;
49 dp = (struct proc_dir_entry *) inode->u.generic_ip;
50 if (!(page = (char*) __get_free_page(GFP_KERNEL)))
51 return -ENOMEM;
53 while (bytes>0)
55 int length, thistime=bytes;
56 if (bytes > PROC_BLOCK_SIZE)
57 thistime=PROC_BLOCK_SIZE;
59 length = dp->get_info(page, &start,
60 file->f_pos,
61 thistime,
62 (file->f_flags & O_ACCMODE) == O_RDWR);
65 * We have been given a non page aligned block of
66 * the data we asked for + a bit. We have been given
67 * the start pointer and we know the length..
70 if (length <= 0)
71 break;
73 * Copy the bytes
75 copy_to_user(buf+copied, start, length);
76 file->f_pos += length; /* Move down the file */
77 bytes -= length;
78 copied += length;
79 if (length<thistime)
80 break; /* End of file */
82 free_page((unsigned long) page);
83 return copied;
86 static struct file_operations proc_net_operations = {
87 NULL, /* lseek - default */
88 proc_readnet, /* read - bad */
89 NULL, /* write - bad */
90 NULL, /* readdir */
91 NULL, /* poll - default */
92 NULL, /* ioctl - default */
93 NULL, /* mmap */
94 NULL, /* no special open code */
95 NULL, /* flush */
96 NULL, /* no special release code */
97 NULL /* can't fsync */
101 * proc directories can do almost nothing..
103 struct inode_operations proc_net_inode_operations = {
104 &proc_net_operations, /* default net file-ops */
105 NULL, /* create */
106 NULL, /* lookup */
107 NULL, /* link */
108 NULL, /* unlink */
109 NULL, /* symlink */
110 NULL, /* mkdir */
111 NULL, /* rmdir */
112 NULL, /* mknod */
113 NULL, /* rename */
114 NULL, /* readlink */
115 NULL, /* follow_link */
116 NULL, /* readpage */
117 NULL, /* writepage */
118 NULL, /* bmap */
119 NULL, /* truncate */
120 NULL /* permission */