root/fs/proc/scsi.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_not_present_info
  2. proc_readscsi
  3. proc_writescsi
  4. proc_scsilseek

   1 /*
   2  *  linux/fs/proc/scsi.c  
   3  *  (c) 1995 Michael Neuffer neuffer@goofy.zdv.uni-mainz.de
   4  *
   5  *  The original version was derived from linux/fs/proc/net.c,
   6  *  which is Copyright (C) 1991, 1992 Linus Torvalds. 
   7  *  Much has been rewritten, but some of the code still remains.
   8  *
   9  *  /proc/scsi directory handling functions
  10  *
  11  *  last change: 95/07/04    
  12  *
  13  *  Initial version: March '95
  14  *  95/05/15 Added subdirectories for each driver and show every
  15  *           registered HBA as a single file. 
  16  *  95/05/30 Added rudimentary write support for parameter passing
  17  *  95/07/04 Fixed bugs in directory handling
  18  *  95/09/13 Update to support the new proc-dir tree
  19  *
  20  *  TODO: Improve support to write to the driver files
  21  *        Add some more comments
  22  */
  23 #include <linux/autoconf.h>
  24 #include <asm/segment.h>
  25 #include <linux/errno.h>
  26 #include <linux/sched.h>
  27 #include <linux/proc_fs.h>
  28 #include <linux/stat.h>
  29 #include <linux/config.h>
  30 #include <linux/mm.h>
  31 
  32 /* forward references */
  33 static int proc_readscsi(struct inode * inode, struct file * file,
  34                          char * buf, int count);
  35 static int proc_writescsi(struct inode * inode, struct file * file,
  36                          const char * buf, int count);
  37 static int proc_scsilseek(struct inode *, struct file *, off_t, int);
  38 
  39 extern void build_proc_dir_hba_entries(uint);
  40 
  41 /* the *_get_info() functions are in the respective scsi driver code */
  42 extern int (* dispatch_scsi_info_ptr)(int, char *, char **, off_t, int, int);
  43     
  44     
  45 static struct file_operations proc_scsi_operations = {
  46     proc_scsilseek,     /* lseek   */
  47     proc_readscsi,      /* read    */
  48     proc_writescsi,     /* write   */
  49     proc_readdir,       /* readdir */
  50     NULL,               /* select  */
  51     NULL,               /* ioctl   */
  52     NULL,               /* mmap    */
  53     NULL,               /* no special open code    */
  54     NULL,               /* no special release code */
  55     NULL                /* can't fsync */
  56 };
  57 
  58 /*
  59  * proc directories can do almost nothing..
  60  */
  61 struct inode_operations proc_scsi_inode_operations = {
  62     &proc_scsi_operations,  /* default scsi directory file-ops */
  63     NULL,           /* create      */
  64     proc_lookup,    /* lookup      */
  65     NULL,           /* link        */
  66     NULL,           /* unlink      */
  67     NULL,           /* symlink     */
  68     NULL,           /* mkdir       */
  69     NULL,           /* rmdir       */
  70     NULL,           /* mknod       */
  71     NULL,           /* rename      */
  72     NULL,           /* readlink    */
  73     NULL,           /* follow_link */
  74     NULL,           /* bmap        */
  75     NULL,           /* truncate    */
  76     NULL            /* permission  */
  77 };
  78 
  79 int get_not_present_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
  80 {
  81     int len, pos, begin;
  82     
  83     begin = 0;
  84     pos = len = sprintf(buffer, 
  85                         "No low-level scsi modules are currently present\n");
  86     if(pos < offset) {
  87         len = 0;
  88         begin = pos;
  89     }
  90     
  91     *start = buffer + (offset - begin);   /* Start of wanted data */
  92     len -= (offset - begin);
  93     if(len > length)
  94         len = length;
  95     
  96     return(len);
  97 }
  98 
  99 #define PROC_BLOCK_SIZE (3*1024)     /* 4K page size, but our output routines 
 100                                       * use some slack for overruns 
 101                                       */
 102 
 103 static int proc_readscsi(struct inode * inode, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
 104                          char * buf, int count)
 105 {
 106     int length;
 107     int bytes = count;
 108     int copied = 0;
 109     int thistime;
 110     char * page;
 111     char * start;
 112     
 113     if (count < -1)               /* Normally I wouldn't do this, */ 
 114         return(-EINVAL);          /* but it saves some redundant code.
 115                                    * Now it is possible to seek to the 
 116                                    * end of the file */
 117     if (!(page = (char *) __get_free_page(GFP_KERNEL)))
 118         return(-ENOMEM);
 119     
 120     while(bytes > 0 || count == -1) {   
 121         thistime = bytes;
 122         if(bytes > PROC_BLOCK_SIZE || count == -1)
 123             thistime = PROC_BLOCK_SIZE;
 124         
 125         if(dispatch_scsi_info_ptr)
 126             length = dispatch_scsi_info_ptr(inode->i_ino, page, &start, 
 127                                             file->f_pos, thistime, 0);
 128         else
 129             length = get_not_present_info(page, &start, file->f_pos, thistime);
 130         if(length < 0) {
 131             free_page((ulong) page);
 132             return(length);
 133         }
 134         
 135         /*
 136          *  We have been given a non page aligned block of
 137          *  the data we asked for + a bit. We have been given
 138          *  the start pointer and we know the length.. 
 139          */
 140         if (length <= 0)
 141             break;
 142         /*
 143          *  Copy the bytes, if we're not doing a seek to 
 144          *      the end of the file 
 145          */
 146         if (count != -1)
 147             memcpy_tofs(buf + copied, start, length);
 148         file->f_pos += length;  /* Move down the file */
 149         bytes -= length;
 150         copied += length;
 151         
 152         if(length < thistime)
 153             break;  /* End of file */
 154         
 155     }
 156     
 157     free_page((ulong) page);
 158     return(copied);
 159 }
 160 
 161 
 162 static int proc_writescsi(struct inode * inode, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
 163                          const char * buf, int count)
 164 {
 165     int ret = 0;
 166     char * page;
 167     
 168     if(count > PROC_BLOCK_SIZE) {
 169         return(-EOVERFLOW);
 170     }
 171 
 172     if(dispatch_scsi_info_ptr != NULL) {
 173         if (!(page = (char *) __get_free_page(GFP_KERNEL)))
 174             return(-ENOMEM);
 175         memcpy_fromfs(page, buf, count);
 176         ret = dispatch_scsi_info_ptr(inode->i_ino, page, 0, 0, count, 1);
 177     } else 
 178         return(-ENOPKG);          /* Nothing here */
 179     
 180     free_page((ulong) page);
 181     return(ret);
 182 }
 183 
 184 
 185 static int proc_scsilseek(struct inode * inode, struct file * file, 
     /* [previous][next][first][last][top][bottom][index][help] */
 186                           off_t offset, int orig)
 187 {
 188     switch (orig) {
 189     case 0:
 190         file->f_pos = offset;
 191         return(file->f_pos);
 192     case 1:
 193         file->f_pos += offset;
 194         return(file->f_pos);
 195     case 2:                  /* This ugly hack allows us to    */
 196         if (offset)          /* to determine the length of the */
 197             return(-EINVAL); /* file and then later savely to  */ 
 198         proc_readscsi(inode, file, 0, -1); /* seek in it       */ 
 199         return(file->f_pos);
 200     default:
 201         return(-EINVAL);
 202     }
 203 }
 204 
 205 /*
 206  * Overrides for Emacs so that we almost follow Linus's tabbing style.
 207  * Emacs will notice this stuff at the end of the file and automatically
 208  * adjust the settings for this buffer only.  This must remain at the end
 209  * of the file.
 210  * ---------------------------------------------------------------------------
 211  * Local variables:
 212  * c-indent-level: 4
 213  * c-brace-imaginary-offset: 0
 214  * c-brace-offset: -4
 215  * c-argdecl-indent: 4
 216  * c-label-offset: -4
 217  * c-continued-statement-offset: 4
 218  * c-continued-brace-offset: 0
 219  * indent-tabs-mode: nil
 220  * tab-width: 8
 221  * End:
 222  */

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