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