|
|
1.1.1.2 root 1: /*
2: * linux/fs/block_dev.c
3: *
4: * (C) 1991 Linus Torvalds
5: */
6:
1.1 root 7: #include <errno.h>
8:
1.1.1.2 root 9: #include <linux/sched.h>
1.1 root 10: #include <linux/kernel.h>
11: #include <asm/segment.h>
1.1.1.2 root 12: #include <asm/system.h>
1.1 root 13:
1.1.1.3 ! root 14: extern int *blk_size[];
! 15:
1.1 root 16: int block_write(int dev, long * pos, char * buf, int count)
17: {
1.1.1.2 root 18: int block = *pos >> BLOCK_SIZE_BITS;
19: int offset = *pos & (BLOCK_SIZE-1);
1.1 root 20: int chars;
21: int written = 0;
1.1.1.3 ! root 22: int size;
1.1 root 23: struct buffer_head * bh;
24: register char * p;
25:
1.1.1.3 ! root 26: if (blk_size[MAJOR(dev)])
! 27: size = blk_size[MAJOR(dev)][MINOR(dev)];
! 28: else
! 29: size = 0x7fffffff;
1.1 root 30: while (count>0) {
1.1.1.3 ! root 31: if (block >= size)
! 32: return written?written:-EIO;
1.1.1.2 root 33: chars = BLOCK_SIZE - offset;
34: if (chars > count)
35: chars=count;
36: if (chars == BLOCK_SIZE)
37: bh = getblk(dev,block);
38: else
39: bh = breada(dev,block,block+1,block+2,-1);
40: block++;
1.1 root 41: if (!bh)
42: return written?written:-EIO;
43: p = offset + bh->b_data;
44: offset = 0;
45: *pos += chars;
46: written += chars;
47: count -= chars;
48: while (chars-->0)
49: *(p++) = get_fs_byte(buf++);
50: bh->b_dirt = 1;
51: brelse(bh);
52: }
53: return written;
54: }
55:
56: int block_read(int dev, unsigned long * pos, char * buf, int count)
57: {
1.1.1.2 root 58: int block = *pos >> BLOCK_SIZE_BITS;
59: int offset = *pos & (BLOCK_SIZE-1);
1.1 root 60: int chars;
1.1.1.3 ! root 61: int size;
1.1 root 62: int read = 0;
63: struct buffer_head * bh;
64: register char * p;
65:
1.1.1.3 ! root 66: if (blk_size[MAJOR(dev)])
! 67: size = blk_size[MAJOR(dev)][MINOR(dev)];
! 68: else
! 69: size = 0x7fffffff;
1.1 root 70: while (count>0) {
1.1.1.3 ! root 71: if (block >= size)
! 72: return read?read:-EIO;
1.1.1.2 root 73: chars = BLOCK_SIZE-offset;
74: if (chars > count)
75: chars = count;
76: if (!(bh = breada(dev,block,block+1,block+2,-1)))
1.1 root 77: return read?read:-EIO;
1.1.1.2 root 78: block++;
1.1 root 79: p = offset + bh->b_data;
80: offset = 0;
81: *pos += chars;
82: read += chars;
83: count -= chars;
84: while (chars-->0)
85: put_fs_byte(*(p++),buf++);
86: brelse(bh);
87: }
88: return read;
89: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.