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_uptodate = 1;
  54                 bh->b_dirt = 1;
  55                 brelse(bh);
  56         }
  57         return written;
  58 }
  59 
  60 int block_read(struct inode * inode, struct file * filp, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  61 {
  62         unsigned int block = filp->f_pos >> BLOCK_SIZE_BITS;
  63         unsigned int offset = filp->f_pos & (BLOCK_SIZE-1);
  64         unsigned int chars;
  65         unsigned int size;
  66         unsigned int dev;
  67         int read = 0;
  68         struct buffer_head * bh;
  69         register char * p;
  70 
  71         dev = inode->i_rdev;
  72         if (blk_size[MAJOR(dev)])
  73                 size = blk_size[MAJOR(dev)][MINOR(dev)];
  74         else
  75                 size = 0x7fffffff;
  76         while (count>0) {
  77                 if (block >= size)
  78                         return read;
  79                 chars = BLOCK_SIZE-offset;
  80                 if (chars > count)
  81                         chars = count;
  82                 if (!(bh = breada(dev,block,block+1,block+2,-1)))
  83                         return read?read:-EIO;
  84                 block++;
  85                 p = offset + bh->b_data;
  86                 offset = 0;
  87                 filp->f_pos += chars;
  88                 read += chars;
  89                 count -= chars;
  90                 memcpy_tofs(buf,p,chars);
  91                 p += chars;
  92                 buf += chars;
  93                 brelse(bh);
  94         }
  95         return read;
  96 }

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