root/fs/proc/net.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. proc_readnet

   1 /*
   2  *  linux/fs/proc/net.c
   3  *
   4  *  Copyright (C) 1991, 1992 Linus Torvalds
   5  *
   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
  24  *
  25  *  proc net directory handling functions
  26  */
  27 #include <linux/autoconf.h>
  28 
  29 #include <asm/segment.h>
  30 
  31 #include <linux/errno.h>
  32 #include <linux/sched.h>
  33 #include <linux/proc_fs.h>
  34 #include <linux/stat.h>
  35 #include <linux/fcntl.h>
  36 #include <linux/config.h>
  37 #include <linux/mm.h>
  38 
  39 static struct file_operations proc_netdir_operations = {
  40         NULL,                   /* lseek - default */
  41         NULL,                   /* read - bad */
  42         NULL,                   /* write - bad */
  43         proc_readdir,           /* readdir */
  44         NULL,                   /* select - default */
  45         NULL,                   /* ioctl - default */
  46         NULL,                   /* mmap */
  47         NULL,                   /* no special open code */
  48         NULL,                   /* no special release code */
  49         NULL                    /* can't fsync */
  50 };
  51 
  52 /*
  53  * proc directories can do almost nothing..
  54  */
  55 static struct inode_operations proc_netdir_inode_operations = {
  56         &proc_netdir_operations,        /* default net directory file-ops */
  57         NULL,                   /* create */
  58         proc_lookup,            /* lookup */
  59         NULL,                   /* link */
  60         NULL,                   /* unlink */
  61         NULL,                   /* symlink */
  62         NULL,                   /* mkdir */
  63         NULL,                   /* rmdir */
  64         NULL,                   /* mknod */
  65         NULL,                   /* rename */
  66         NULL,                   /* readlink */
  67         NULL,                   /* follow_link */
  68         NULL,                   /* bmap */
  69         NULL,                   /* truncate */
  70         NULL                    /* permission */
  71 };
  72 
  73 struct proc_dir_entry proc_net = {
  74         PROC_NET, 3, "net",
  75         S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0,
  76         0, &proc_netdir_inode_operations,
  77         NULL, NULL,
  78         NULL,
  79         NULL, NULL      
  80 };
  81 
  82 #define PROC_BLOCK_SIZE (3*1024)                /* 4K page size but our output routines use some slack for overruns */
  83 
  84 static int proc_readnet(struct inode * inode, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
  85                         char * buf, int count)
  86 {
  87         char * page;
  88         int bytes=count;
  89         int copied=0;
  90         char *start;
  91         struct proc_dir_entry * dp;
  92 
  93         if (count < 0)
  94                 return -EINVAL;
  95         dp = (struct proc_dir_entry *) inode->u.generic_ip;
  96         if (!(page = (char*) __get_free_page(GFP_KERNEL)))
  97                 return -ENOMEM;
  98 
  99         while (bytes>0)
 100         {
 101                 int length, thistime=bytes;
 102                 if (bytes > PROC_BLOCK_SIZE)
 103                         thistime=PROC_BLOCK_SIZE;
 104 
 105                 length = dp->get_info(page, &start,
 106                                       file->f_pos,
 107                                       thistime,
 108                                       (file->f_flags & O_ACCMODE) == O_RDWR);
 109 
 110                 /*
 111                  *      We have been given a non page aligned block of
 112                  *      the data we asked for + a bit. We have been given
 113                  *      the start pointer and we know the length.. 
 114                  */
 115 
 116                 if (length <= 0)
 117                         break;
 118                 /*
 119                  *      Copy the bytes
 120                  */
 121                 memcpy_tofs(buf+copied, start, length);
 122                 file->f_pos += length;  /* Move down the file */
 123                 bytes  -= length;
 124                 copied += length;
 125                 if (length<thistime)
 126                         break;  /* End of file */
 127         }
 128         free_page((unsigned long) page);
 129         return copied;
 130 }
 131 
 132 static struct file_operations proc_net_operations = {
 133         NULL,                   /* lseek - default */
 134         proc_readnet,           /* read - bad */
 135         NULL,                   /* write - bad */
 136         NULL,                   /* readdir */
 137         NULL,                   /* select - default */
 138         NULL,                   /* ioctl - default */
 139         NULL,                   /* mmap */
 140         NULL,                   /* no special open code */
 141         NULL,                   /* no special release code */
 142         NULL                    /* can't fsync */
 143 };
 144 
 145 /*
 146  * proc directories can do almost nothing..
 147  */
 148 struct inode_operations proc_net_inode_operations = {
 149         &proc_net_operations,   /* default net file-ops */
 150         NULL,                   /* create */
 151         NULL,                   /* lookup */
 152         NULL,                   /* link */
 153         NULL,                   /* unlink */
 154         NULL,                   /* symlink */
 155         NULL,                   /* mkdir */
 156         NULL,                   /* rmdir */
 157         NULL,                   /* mknod */
 158         NULL,                   /* rename */
 159         NULL,                   /* readlink */
 160         NULL,                   /* follow_link */
 161         NULL,                   /* bmap */
 162         NULL,                   /* truncate */
 163         NULL                    /* permission */
 164 };

/* [previous][next][first][last][top][bottom][index][help] */