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 #define PROC_BLOCK_SIZE (3*1024)                /* 4K page size but our output routines use some slack for overruns */
  40 
  41 static int proc_readnet(struct inode * inode, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
  42                         char * buf, int count)
  43 {
  44         char * page;
  45         int bytes=count;
  46         int copied=0;
  47         char *start;
  48         struct proc_dir_entry * dp;
  49 
  50         if (count < 0)
  51                 return -EINVAL;
  52         dp = (struct proc_dir_entry *) inode->u.generic_ip;
  53         if (!(page = (char*) __get_free_page(GFP_KERNEL)))
  54                 return -ENOMEM;
  55 
  56         while (bytes>0)
  57         {
  58                 int length, thistime=bytes;
  59                 if (bytes > PROC_BLOCK_SIZE)
  60                         thistime=PROC_BLOCK_SIZE;
  61 
  62                 length = dp->get_info(page, &start,
  63                                       file->f_pos,
  64                                       thistime,
  65                                       (file->f_flags & O_ACCMODE) == O_RDWR);
  66 
  67                 /*
  68                  *      We have been given a non page aligned block of
  69                  *      the data we asked for + a bit. We have been given
  70                  *      the start pointer and we know the length.. 
  71                  */
  72 
  73                 if (length <= 0)
  74                         break;
  75                 /*
  76                  *      Copy the bytes
  77                  */
  78                 memcpy_tofs(buf+copied, start, length);
  79                 file->f_pos += length;  /* Move down the file */
  80                 bytes  -= length;
  81                 copied += length;
  82                 if (length<thistime)
  83                         break;  /* End of file */
  84         }
  85         free_page((unsigned long) page);
  86         return copied;
  87 }
  88 
  89 static struct file_operations proc_net_operations = {
  90         NULL,                   /* lseek - default */
  91         proc_readnet,           /* read - bad */
  92         NULL,                   /* write - bad */
  93         NULL,                   /* readdir */
  94         NULL,                   /* select - default */
  95         NULL,                   /* ioctl - default */
  96         NULL,                   /* mmap */
  97         NULL,                   /* no special open code */
  98         NULL,                   /* no special release code */
  99         NULL                    /* can't fsync */
 100 };
 101 
 102 /*
 103  * proc directories can do almost nothing..
 104  */
 105 struct inode_operations proc_net_inode_operations = {
 106         &proc_net_operations,   /* default net file-ops */
 107         NULL,                   /* create */
 108         NULL,                   /* lookup */
 109         NULL,                   /* link */
 110         NULL,                   /* unlink */
 111         NULL,                   /* symlink */
 112         NULL,                   /* mkdir */
 113         NULL,                   /* rmdir */
 114         NULL,                   /* mknod */
 115         NULL,                   /* rename */
 116         NULL,                   /* readlink */
 117         NULL,                   /* follow_link */
 118         NULL,                   /* bmap */
 119         NULL,                   /* truncate */
 120         NULL                    /* permission */
 121 };

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