summaryrefslogtreecommitdiffstats
path: root/src/fs/block_dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/block_dev.c')
-rw-r--r--src/fs/block_dev.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/fs/block_dev.c b/src/fs/block_dev.c
new file mode 100644
index 0000000..a50ae3f
--- /dev/null
+++ b/src/fs/block_dev.c
@@ -0,0 +1,73 @@
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
14int block_write(int dev, long * pos, char * buf, int count)
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
47int block_read(int dev, unsigned long * pos, char * buf, int count)
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}