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 int block_write(int dev, long * pos, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  15 {
  16         int block = *pos >> BLOCK_SIZE_BITS;
  17         int offset = *pos & (BLOCK_SIZE-1);
  18         int chars;
  19         int written = 0;
  20         struct buffer_head * bh;
  21         register char * p;
  22 
  23         while (count>0) {
  24                 chars = BLOCK_SIZE - offset;
  25                 if (chars > count)
  26                         chars=count;
  27                 if (chars == BLOCK_SIZE)
  28                         bh = getblk(dev,block);
  29                 else
  30                         bh = breada(dev,block,block+1,block+2,-1);
  31                 block++;
  32                 if (!bh)
  33                         return written?written:-EIO;
  34                 p = offset + bh->b_data;
  35                 offset = 0;
  36                 *pos += chars;
  37                 written += chars;
  38                 count -= chars;
  39                 while (chars-->0)
  40                         *(p++) = get_fs_byte(buf++);
  41                 bh->b_dirt = 1;
  42                 brelse(bh);
  43         }
  44         return written;
  45 }
  46 
  47 int block_read(int dev, unsigned long * pos, char * buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49         int block = *pos >> BLOCK_SIZE_BITS;
  50         int offset = *pos & (BLOCK_SIZE-1);
  51         int chars;
  52         int read = 0;
  53         struct buffer_head * bh;
  54         register char * p;
  55 
  56         while (count>0) {
  57                 chars = BLOCK_SIZE-offset;
  58                 if (chars > count)
  59                         chars = count;
  60                 if (!(bh = breada(dev,block,block+1,block+2,-1)))
  61                         return read?read:-EIO;
  62                 block++;
  63                 p = offset + bh->b_data;
  64                 offset = 0;
  65                 *pos += chars;
  66                 read += chars;
  67                 count -= chars;
  68                 while (chars-->0)
  69                         put_fs_byte(*(p++),buf++);
  70                 brelse(bh);
  71         }
  72         return read;
  73 }

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