This source file includes following definitions.
- do_rd_request
- rd_init
- do_load
- 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/ext2_fs.h>
15 #include <linux/fs.h>
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <asm/system.h>
19 #include <asm/segment.h>
20
21 #define MAJOR_NR MEM_MAJOR
22 #include "blk.h"
23
24 #define RAMDISK_MINOR 1
25
26 extern void wait_for_keypress(void);
27
28 char *rd_start;
29 int rd_length = 0;
30 static int rd_blocksizes[2] = {0, 0};
31
32 static void do_rd_request(void)
33 {
34 int len;
35 char *addr;
36
37 repeat:
38 INIT_REQUEST;
39 addr = rd_start + (CURRENT->sector << 9);
40 len = CURRENT->current_nr_sectors << 9;
41
42 if ((MINOR(CURRENT->dev) != RAMDISK_MINOR) ||
43 (addr+len > rd_start+rd_length)) {
44 end_request(0);
45 goto repeat;
46 }
47 if (CURRENT-> cmd == WRITE) {
48 (void ) memcpy(addr,
49 CURRENT->buffer,
50 len);
51 } else if (CURRENT->cmd == READ) {
52 (void) memcpy(CURRENT->buffer,
53 addr,
54 len);
55 } else
56 panic("RAMDISK: unknown RAM disk command !\n");
57 end_request(1);
58 goto repeat;
59 }
60
61 static struct file_operations rd_fops = {
62 NULL,
63 block_read,
64 block_write,
65 NULL,
66 NULL,
67 NULL,
68 NULL,
69 NULL,
70 NULL,
71 block_fsync
72 };
73
74
75
76
77 long rd_init(long mem_start, int length)
78 {
79 int i;
80 char *cp;
81
82 if (register_blkdev(MEM_MAJOR,"rd",&rd_fops)) {
83 printk("RAMDISK: Unable to get major %d.\n", MEM_MAJOR);
84 return 0;
85 }
86 blk_dev[MEM_MAJOR].request_fn = DEVICE_REQUEST;
87 rd_start = (char *) mem_start;
88 rd_length = length;
89 cp = rd_start;
90 for (i=0; i < length; i++)
91 *cp++ = '\0';
92
93 for(i=0;i<2;i++) rd_blocksizes[i] = 1024;
94 blksize_size[MAJOR_NR] = rd_blocksizes;
95
96 return(length);
97 }
98
99 static void do_load(void)
100 {
101 struct buffer_head *bh;
102 struct super_block {
103 union
104 {
105 char minix [sizeof (struct minix_super_block)];
106 char ext2 [sizeof (struct ext2_super_block)];
107 } record;
108 } sb;
109 struct minix_super_block *minixsb =
110 (struct minix_super_block *)&sb;
111 struct ext2_super_block *ext2sb =
112 (struct ext2_super_block *)&sb;
113 int block, tries;
114 int i = 1;
115 int nblocks;
116 char *cp;
117
118
119
120
121
122
123
124
125
126 for (tries = 0; tries < 1000; tries += 512) {
127 block = tries;
128 bh = breada(ROOT_DEV,block+1,BLOCK_SIZE, 0, PAGE_SIZE);
129 if (!bh) {
130 printk("RAMDISK: I/O error while looking for super block!\n");
131 return;
132 }
133
134
135 *((struct super_block *) &sb) =
136 *((struct super_block *) bh->b_data);
137 brelse(bh);
138
139
140
141 nblocks = -1;
142 if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
143 minixsb->s_magic == MINIX_SUPER_MAGIC2) {
144 printk("RAMDISK: Minix filesystem found at block %d\n",
145 block);
146 nblocks = minixsb->s_nzones << minixsb->s_log_zone_size;
147 }
148
149
150 if (nblocks == -1 && (ext2sb->s_magic ==
151 EXT2_PRE_02B_MAGIC ||
152 ext2sb->s_magic == EXT2_SUPER_MAGIC))
153 {
154 printk("RAMDISK: Ext2 filesystem found at block %d\n",
155 block);
156 nblocks = ext2sb->s_blocks_count;
157 }
158
159 if (nblocks == -1)
160 {
161 printk("RAMDISK: trying old-style RAM image.\n");
162 continue;
163 }
164
165 if (nblocks > (rd_length >> BLOCK_SIZE_BITS)) {
166 printk("RAMDISK: image too big! (%d/%d blocks)\n",
167 nblocks, rd_length >> BLOCK_SIZE_BITS);
168 return;
169 }
170 printk("RAMDISK: Loading %d blocks into RAM disk", nblocks);
171
172
173 cp = rd_start;
174 while (nblocks) {
175 if (nblocks > 2)
176 bh = breada(ROOT_DEV, block, BLOCK_SIZE, 0, PAGE_SIZE);
177 else
178 bh = bread(ROOT_DEV, block, BLOCK_SIZE);
179 if (!bh) {
180 printk("RAMDISK: I/O error on block %d, aborting!\n",
181 block);
182 return;
183 }
184 (void) memcpy(cp, bh->b_data, BLOCK_SIZE);
185 brelse(bh);
186 if (!(nblocks-- & 15)) printk(".");
187 cp += BLOCK_SIZE;
188 block++;
189 i++;
190 }
191 printk("\ndone\n");
192
193
194 ROOT_DEV = ((MEM_MAJOR << 8) | RAMDISK_MINOR);
195 return;
196 }
197 }
198
199
200
201
202
203
204 void rd_load(void)
205 {
206 struct inode inode;
207 struct file filp;
208
209
210 if (!rd_length)
211 return;
212 printk("RAMDISK: %d bytes, starting at 0x%x\n",
213 rd_length, (int) rd_start);
214
215
216 if (MAJOR(ROOT_DEV) != FLOPPY_MAJOR)
217 return;
218
219
220 printk(KERN_NOTICE "VFS: Insert ramdisk floppy and press ENTER\n");
221 wait_for_keypress();
222
223 memset(&filp, 0, sizeof(filp));
224 memset(&inode, 0, sizeof(inode));
225 inode.i_rdev = ROOT_DEV;
226 filp.f_mode = 1;
227 filp.f_inode = &inode;
228 if(blkdev_open(&inode, &filp) == 0 ){
229 do_load();
230 if(filp.f_op && filp.f_op->release)
231 filp.f_op->release(&inode,&filp);
232 }
233 }