This source file includes following definitions.
- do_rd_request
- rd_init
- rd_load
1
2
3
4
5
6
7
8
9
10
11 #include <linux/config.h>
12 #include <linux/sched.h>
13 #include <linux/minix_fs.h>
14 #include <linux/fs.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <asm/system.h>
18 #include <asm/segment.h>
19
20 #define MAJOR_RAMDISK 1
21 #define MAJOR_FLOPPY 2
22 #define MINOR_RAMDISK 1
23
24 #define MAJOR_NR MAJOR_RAMDISK
25 #include "blk.h"
26
27
28 char *rd_start;
29 int rd_length = 0;
30
31 static void do_rd_request(void)
32 {
33 int len;
34 char *addr;
35
36 repeat:
37 INIT_REQUEST;
38 addr = rd_start + (CURRENT->sector << 9);
39 len = CURRENT->nr_sectors << 9;
40 if ((MINOR(CURRENT->dev) != MINOR_RAMDISK) ||
41 (addr+len > rd_start+rd_length)) {
42 end_request(0);
43 goto repeat;
44 }
45 if (CURRENT-> cmd == WRITE) {
46 (void ) memcpy(addr,
47 CURRENT->buffer,
48 len);
49 } else if (CURRENT->cmd == READ) {
50 (void) memcpy(CURRENT->buffer,
51 addr,
52 len);
53 } else
54 panic("RAMDISK: unknown RAM disk command !\n");
55 end_request(1);
56 goto repeat;
57 }
58
59 static struct file_operations rd_fops = {
60 NULL,
61 block_read,
62 block_write,
63 NULL,
64 NULL,
65 NULL,
66 NULL,
67 NULL,
68 NULL,
69 block_fsync
70 };
71
72
73
74
75 long rd_init(long mem_start, int length)
76 {
77 int i;
78 char *cp;
79
80 if (register_blkdev(MAJOR_RAMDISK,"rd",&rd_fops)) {
81 printk("RAMDISK: Unable to get major %d.\n", MAJOR_RAMDISK);
82 return 0;
83 }
84 blk_dev[MAJOR_RAMDISK].request_fn = DEVICE_REQUEST;
85 rd_start = (char *) mem_start;
86 rd_length = length;
87 cp = rd_start;
88 for (i=0; i < length; i++)
89 *cp++ = '\0';
90 return(length);
91 }
92
93
94
95
96
97
98 void rd_load(void)
99 {
100 struct buffer_head *bh;
101 struct minix_super_block s;
102 int block, try;
103 int i = 1;
104 int nblocks;
105 char *cp;
106
107
108 if (!rd_length) return;
109 printk("RAMDISK: %d bytes, starting at 0x%x\n",
110 rd_length, (int) rd_start);
111
112
113 if (MAJOR(ROOT_DEV) != MAJOR_FLOPPY) return;
114
115
116
117
118
119
120
121
122
123 for (try = 0; try < 1000; try += 512) {
124 block = try;
125 bh = breada(ROOT_DEV,block+1,block,block+2,-1);
126 if (!bh) {
127 printk("RAMDISK: I/O error while looking for super block!\n");
128 return;
129 }
130
131
132 *((struct minix_super_block *) &s) =
133 *((struct minix_super_block *) bh->b_data);
134 brelse(bh);
135 nblocks = s.s_nzones << s.s_log_zone_size;
136 if (s.s_magic != MINIX_SUPER_MAGIC) {
137 printk("RAMDISK: trying old-style RAM image.\n");
138 continue;
139 }
140
141 if (nblocks > (rd_length >> BLOCK_SIZE_BITS)) {
142 printk("RAMDISK: image too big! (%d/%d blocks)\n",
143 nblocks, rd_length >> BLOCK_SIZE_BITS);
144 return;
145 }
146 printk("RAMDISK: Loading %d blocks into RAM disk", nblocks);
147
148
149 cp = rd_start;
150 while (nblocks) {
151 if (nblocks > 2)
152 bh = breada(ROOT_DEV, block, block+1, block+2, -1);
153 else
154 bh = bread(ROOT_DEV, block, BLOCK_SIZE);
155 if (!bh) {
156 printk("RAMDISK: I/O error on block %d, aborting!\n",
157 block);
158 return;
159 }
160 (void) memcpy(cp, bh->b_data, BLOCK_SIZE);
161 brelse(bh);
162 if (!(nblocks-- & 15)) printk(".");
163 cp += BLOCK_SIZE;
164 block++;
165 i++;
166 }
167 printk("\ndone\n");
168
169
170 ROOT_DEV = ((MAJOR_RAMDISK << 8) | MINOR_RAMDISK);
171 return;
172 }
173 }