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/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
26 char *rd_start;
27 int rd_length = 0;
28 static int rd_blocksizes[2] = {0, 0};
29
30 static void do_rd_request(void)
31 {
32 int len;
33 char *addr;
34
35 repeat:
36 INIT_REQUEST;
37 addr = rd_start + (CURRENT->sector << 9);
38 len = CURRENT->current_nr_sectors << 9;
39
40 if ((MINOR(CURRENT->dev) != RAMDISK_MINOR) ||
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(MEM_MAJOR,"rd",&rd_fops)) {
81 printk("RAMDISK: Unable to get major %d.\n", MEM_MAJOR);
82 return 0;
83 }
84 blk_dev[MEM_MAJOR].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
91 for(i=0;i<2;i++) rd_blocksizes[i] = 1024;
92 blksize_size[MAJOR_NR] = rd_blocksizes;
93
94 return(length);
95 }
96
97 static void do_load(void)
98 {
99 struct buffer_head *bh;
100 struct minix_super_block s;
101 int block, tries;
102 int i = 1;
103 int nblocks;
104 char *cp;
105
106
107
108
109
110
111
112
113
114 for (tries = 0; tries < 1000; tries += 512) {
115 block = tries;
116 bh = breada(ROOT_DEV,block+1,BLOCK_SIZE, 0, PAGE_SIZE);
117 if (!bh) {
118 printk("RAMDISK: I/O error while looking for super block!\n");
119 return;
120 }
121
122
123 *((struct minix_super_block *) &s) =
124 *((struct minix_super_block *) bh->b_data);
125 brelse(bh);
126 nblocks = s.s_nzones << s.s_log_zone_size;
127 if (s.s_magic != MINIX_SUPER_MAGIC &&
128 s.s_magic != MINIX_SUPER_MAGIC2) {
129 printk("RAMDISK: trying old-style RAM image.\n");
130 continue;
131 }
132
133 if (nblocks > (rd_length >> BLOCK_SIZE_BITS)) {
134 printk("RAMDISK: image too big! (%d/%d blocks)\n",
135 nblocks, rd_length >> BLOCK_SIZE_BITS);
136 return;
137 }
138 printk("RAMDISK: Loading %d blocks into RAM disk", nblocks);
139
140
141 cp = rd_start;
142 while (nblocks) {
143 if (nblocks > 2)
144 bh = breada(ROOT_DEV, block, BLOCK_SIZE, 0, PAGE_SIZE);
145 else
146 bh = bread(ROOT_DEV, block, BLOCK_SIZE);
147 if (!bh) {
148 printk("RAMDISK: I/O error on block %d, aborting!\n",
149 block);
150 return;
151 }
152 (void) memcpy(cp, bh->b_data, BLOCK_SIZE);
153 brelse(bh);
154 if (!(nblocks-- & 15)) printk(".");
155 cp += BLOCK_SIZE;
156 block++;
157 i++;
158 }
159 printk("\ndone\n");
160
161
162 ROOT_DEV = ((MEM_MAJOR << 8) | RAMDISK_MINOR);
163 return;
164 }
165 }
166
167 int floppy_grab_irq_and_dma(void);
168 void floppy_release_irq_and_dma(void);
169
170
171
172
173
174
175 void rd_load(void)
176 {
177
178 if (!rd_length)
179 return;
180 printk("RAMDISK: %d bytes, starting at 0x%x\n",
181 rd_length, (int) rd_start);
182
183
184 if (MAJOR(ROOT_DEV) != FLOPPY_MAJOR)
185 return;
186
187
188 if (floppy_grab_irq_and_dma()) {
189 printk("Unable to grab floppy IRQ/DMA for loading ramdisk image\n");
190 return;
191 }
192 check_disk_change(ROOT_DEV);
193 do_load();
194 floppy_release_irq_and_dma();
195 }