This source file includes following definitions.
- do_rd_request
- rd_init
- rd_load
1
2
3
4
5
6
7 #include <linux/string.h>
8
9 #include <linux/config.h>
10 #include <linux/sched.h>
11 #include <linux/minix_fs.h>
12 #include <linux/fs.h>
13 #include <linux/kernel.h>
14 #include <asm/system.h>
15 #include <asm/segment.h>
16 #include <asm/memory.h>
17
18 #define MAJOR_NR 1
19 #include "blk.h"
20
21 char *rd_start;
22 int rd_length = 0;
23
24 void do_rd_request(void)
25 {
26 int len;
27 char *addr;
28
29 INIT_REQUEST;
30 addr = rd_start + (CURRENT->sector << 9);
31 len = CURRENT->nr_sectors << 9;
32 if ((MINOR(CURRENT->dev) != 1) || (addr+len > rd_start+rd_length)) {
33 end_request(0);
34 goto repeat;
35 }
36 if (CURRENT-> cmd == WRITE) {
37 (void ) memcpy(addr,
38 CURRENT->buffer,
39 len);
40 } else if (CURRENT->cmd == READ) {
41 (void) memcpy(CURRENT->buffer,
42 addr,
43 len);
44 } else
45 panic("unknown ramdisk-command");
46 end_request(1);
47 goto repeat;
48 }
49
50 static struct file_operations rd_fops = {
51 NULL,
52 block_read,
53 block_write,
54 NULL,
55 NULL,
56 NULL,
57 NULL,
58 NULL
59 };
60
61
62
63
64 long rd_init(long mem_start, int length)
65 {
66 int i;
67 char *cp;
68
69 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
70 blkdev_fops[MAJOR_NR] = &rd_fops;
71 rd_start = (char *) mem_start;
72 rd_length = length;
73 cp = rd_start;
74 for (i=0; i < length; i++)
75 *cp++ = '\0';
76 return(length);
77 }
78
79
80
81
82
83
84 void rd_load(void)
85 {
86 struct buffer_head *bh;
87 struct super_block s;
88 int block = 256;
89 int i = 1;
90 int nblocks;
91 char *cp;
92
93 if (!rd_length)
94 return;
95 printk("Ram disk: %d bytes, starting at 0x%x\n", rd_length,
96 (int) rd_start);
97 if (MAJOR(ROOT_DEV) != 2)
98 return;
99 bh = breada(ROOT_DEV,block+1,block,block+2,-1);
100 if (!bh) {
101 printk("Disk error while looking for ramdisk!\n");
102 return;
103 }
104 *((struct minix_super_block *) &s) = *((struct minix_super_block *) bh->b_data);
105 brelse(bh);
106 if (s.s_magic != MINIX_SUPER_MAGIC)
107
108 return;
109 nblocks = s.s_nzones << s.s_log_zone_size;
110 if (nblocks > (rd_length >> BLOCK_SIZE_BITS)) {
111 printk("Ram disk image too big! (%d blocks, %d avail)\n",
112 nblocks, rd_length >> BLOCK_SIZE_BITS);
113 return;
114 }
115 printk("Loading %d bytes into ram disk... 0000k",
116 nblocks << BLOCK_SIZE_BITS);
117 cp = rd_start;
118 while (nblocks) {
119 if (nblocks > 2)
120 bh = breada(ROOT_DEV, block, block+1, block+2, -1);
121 else
122 bh = bread(ROOT_DEV, block);
123 if (!bh) {
124 printk("I/O error on block %d, aborting load\n",
125 block);
126 return;
127 }
128 (void) memcpy(cp, bh->b_data, BLOCK_SIZE);
129 brelse(bh);
130 printk("\010\010\010\010\010%4dk",i);
131 cp += BLOCK_SIZE;
132 block++;
133 nblocks--;
134 i++;
135 }
136 printk("\010\010\010\010\010done \n");
137 ROOT_DEV=0x0101;
138 }