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