root/fs/block_dev.c

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

DEFINITIONS

This source file includes following definitions.
  1. block_write
  2. block_read

   1 /*
   2  *  linux/fs/block_dev.c
   3  *
   4  *  (C) 1991  Linus Torvalds
   5  */
   6 
   7 #include <errno.h>
   8 
   9 #include <linux/sched.h>
  10 #include <linux/kernel.h>
  11 #include <asm/segment.h>
  12 #include <asm/system.h>
  13 
  14 extern int *blk_size[];
  15 
  16 int block_write(struct inode * inode, struct file * filp, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18         int block = filp->f_pos >> BLOCK_SIZE_BITS;
  19         int offset = filp->f_pos & (BLOCK_SIZE-1);
  20         int chars;
  21         int written = 0;
  22         int size;
  23         unsigned int dev;
  24         struct buffer_head * bh;
  25         register char * p;
  26 
  27         dev = inode->i_rdev;
  28         if (blk_size[MAJOR(dev)])
  29                 size = blk_size[MAJOR(dev)][MINOR(dev)];
  30         else
  31                 size = 0x7fffffff;
  32         while (count>0) {
  33                 if (block >= size)
  34                         return written;
  35                 chars = BLOCK_SIZE - offset;
  36                 if (chars > count)
  37                         chars=count;
  38                 if (chars == BLOCK_SIZE)
  39                         bh = getblk(dev,block);
  40                 else
  41                         bh = breada(dev,block,block+1,block+2,-1);
  42                 block++;
  43                 if (!bh)
  44                         return written?written:-EIO;
  45                 p = offset + bh->b_data;
  46                 offset = 0;
  47                 filp->f_pos += chars;
  48                 written += chars;
  49                 count -= chars;
  50                 memcpy_fromfs(p,buf,chars);
  51                 p += chars;
  52                 buf += chars;
  53                 bh->b_dirt = 1;
  54                 brelse(bh);
  55         }
  56         return written;
  57 }
  58 
  59 int block_read(struct inode * inode, struct file * filp, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61         unsigned int block = filp->f_pos >> BLOCK_SIZE_BITS;
  62         unsigned int offset = filp->f_pos & (BLOCK_SIZE-1);
  63         unsigned int chars;
  64         unsigned int size;
  65         unsigned int dev;
  66         int read = 0;
  67         struct buffer_head * bh;
  68         register char * p;
  69 
  70         dev = inode->i_rdev;
  71         if (blk_size[MAJOR(dev)])
  72                 size = blk_size[MAJOR(dev)][MINOR(dev)];
  73         else
  74                 size = 0x7fffffff;
  75         while (count>0) {
  76                 if (block >= size)
  77                         return read;
  78                 chars = BLOCK_SIZE-offset;
  79                 if (chars > count)
  80                         chars = count;
  81                 if (!(bh = breada(dev,block,block+1,block+2,-1)))
  82                         return read?read:-EIO;
  83                 block++;
  84                 p = offset + bh->b_data;
  85                 offset = 0;
  86                 filp->f_pos += chars;
  87                 read += chars;
  88                 count -= chars;
  89                 memcpy_tofs(buf,p,chars);
  90                 p += chars;
  91                 buf += chars;
  92                 brelse(bh);
  93         }
  94         return read;
  95 }

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