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  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <linux/errno.h>
   8 #include <linux/sched.h>
   9 #include <linux/kernel.h>
  10 #include <asm/segment.h>
  11 #include <asm/system.h>
  12 
  13 extern int *blk_size[];
  14 
  15 int block_write(struct inode * inode, struct file * filp, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  16 {
  17         int block = filp->f_pos >> BLOCK_SIZE_BITS;
  18         int offset = filp->f_pos & (BLOCK_SIZE-1);
  19         int chars;
  20         int written = 0;
  21         int size;
  22         unsigned int dev;
  23         struct buffer_head * bh;
  24         register char * p;
  25 
  26         dev = inode->i_rdev;
  27         if (blk_size[MAJOR(dev)])
  28                 size = blk_size[MAJOR(dev)][MINOR(dev)];
  29         else
  30                 size = 0x7fffffff;
  31         while (count>0) {
  32                 if (block >= size)
  33                         return written;
  34                 chars = BLOCK_SIZE - offset;
  35                 if (chars > count)
  36                         chars=count;
  37                 if (chars == BLOCK_SIZE)
  38                         bh = getblk(dev, block, BLOCK_SIZE);
  39                 else
  40                         bh = breada(dev,block,block+1,block+2,-1);
  41                 block++;
  42                 if (!bh)
  43                         return written?written:-EIO;
  44                 p = offset + bh->b_data;
  45                 offset = 0;
  46                 filp->f_pos += chars;
  47                 written += chars;
  48                 count -= chars;
  49                 memcpy_fromfs(p,buf,chars);
  50                 p += chars;
  51                 buf += chars;
  52                 bh->b_uptodate = 1;
  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] */