|
|
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.1.4 root 16: int block_write(struct inode * inode, struct file * filp, char * buf, int count)
1.1 root 17: {
1.1.1.4 root 18: int block = filp->f_pos >> BLOCK_SIZE_BITS;
19: int offset = filp->f_pos & (BLOCK_SIZE-1);
1.1 root 20: int chars;
21: int written = 0;
1.1.1.3 root 22: int size;
1.1.1.4 root 23: unsigned int dev;
1.1 root 24: struct buffer_head * bh;
25: register char * p;
26:
1.1.1.4 root 27: dev = inode->i_rdev;
1.1.1.3 root 28: if (blk_size[MAJOR(dev)])
29: size = blk_size[MAJOR(dev)][MINOR(dev)];
30: else
31: size = 0x7fffffff;
1.1 root 32: while (count>0) {
1.1.1.3 root 33: if (block >= size)
1.1.1.4 root 34: return written;
1.1.1.2 root 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++;
1.1 root 43: if (!bh)
44: return written?written:-EIO;
45: p = offset + bh->b_data;
46: offset = 0;
1.1.1.4 root 47: filp->f_pos += chars;
1.1 root 48: written += chars;
49: count -= chars;
1.1.1.5 root 50: memcpy_fromfs(p,buf,chars);
51: p += chars;
52: buf += chars;
1.1.1.6 ! root 53: bh->b_uptodate = 1;
1.1 root 54: bh->b_dirt = 1;
55: brelse(bh);
56: }
57: return written;
58: }
59:
1.1.1.4 root 60: int block_read(struct inode * inode, struct file * filp, char * buf, int count)
1.1 root 61: {
1.1.1.4 root 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;
1.1 root 67: int read = 0;
68: struct buffer_head * bh;
69: register char * p;
70:
1.1.1.4 root 71: dev = inode->i_rdev;
1.1.1.3 root 72: if (blk_size[MAJOR(dev)])
73: size = blk_size[MAJOR(dev)][MINOR(dev)];
74: else
75: size = 0x7fffffff;
1.1 root 76: while (count>0) {
1.1.1.3 root 77: if (block >= size)
1.1.1.4 root 78: return read;
1.1.1.2 root 79: chars = BLOCK_SIZE-offset;
80: if (chars > count)
81: chars = count;
82: if (!(bh = breada(dev,block,block+1,block+2,-1)))
1.1 root 83: return read?read:-EIO;
1.1.1.2 root 84: block++;
1.1 root 85: p = offset + bh->b_data;
86: offset = 0;
1.1.1.4 root 87: filp->f_pos += chars;
1.1 root 88: read += chars;
89: count -= chars;
1.1.1.5 root 90: memcpy_tofs(buf,p,chars);
91: p += chars;
92: buf += chars;
1.1 root 93: brelse(bh);
94: }
95: return read;
96: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.