|
|
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: 14: int block_write(int dev, long * pos, char * buf, int count) 15: { 1.1.1.2 ! root 16: int block = *pos >> BLOCK_SIZE_BITS; ! 17: int offset = *pos & (BLOCK_SIZE-1); 1.1 root 18: int chars; 19: int written = 0; 20: struct buffer_head * bh; 21: register char * p; 22: 23: while (count>0) { 1.1.1.2 ! root 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++; 1.1 root 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) 48: { 1.1.1.2 ! root 49: int block = *pos >> BLOCK_SIZE_BITS; ! 50: int offset = *pos & (BLOCK_SIZE-1); 1.1 root 51: int chars; 52: int read = 0; 53: struct buffer_head * bh; 54: register char * p; 55: 56: while (count>0) { 1.1.1.2 ! root 57: chars = BLOCK_SIZE-offset; ! 58: if (chars > count) ! 59: chars = count; ! 60: if (!(bh = breada(dev,block,block+1,block+2,-1))) 1.1 root 61: return read?read:-EIO; 1.1.1.2 ! root 62: block++; 1.1 root 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: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.