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 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->nr_sectors << 9;
41 if ((MINOR(CURRENT->dev) != MINOR_RAMDISK) ||
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(MAJOR_RAMDISK,"rd",&rd_fops)) {
82 printk("RAMDISK: Unable to get major %d.\n", MAJOR_RAMDISK);
83 return 0;
84 }
85 blk_dev[MAJOR_RAMDISK].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
99
100
101
102
103 void rd_load(void)
104 {
105 struct buffer_head *bh;
106 struct minix_super_block s;
107 int block, try;
108 int i = 1;
109 int nblocks;
110 char *cp;
111
112
113 if (!rd_length) return;
114 printk("RAMDISK: %d bytes, starting at 0x%x\n",
115 rd_length, (int) rd_start);
116
117
118 if (MAJOR(ROOT_DEV) != MAJOR_FLOPPY) return;
119
120
121
122
123
124
125
126
127
128 for (try = 0; try < 1000; try += 512) {
129 block = try;
130 bh = breada(ROOT_DEV,block+1,block,block+2,-1);
131 if (!bh) {
132 printk("RAMDISK: I/O error while looking for super block!\n");
133 return;
134 }
135
136
137 *((struct minix_super_block *) &s) =
138 *((struct minix_super_block *) bh->b_data);
139 brelse(bh);
140 nblocks = s.s_nzones << s.s_log_zone_size;
141 if (s.s_magic != MINIX_SUPER_MAGIC) {
142 printk("RAMDISK: trying old-style RAM image.\n");
143 continue;
144 }
145
146 if (nblocks > (rd_length >> BLOCK_SIZE_BITS)) {
147 printk("RAMDISK: image too big! (%d/%d blocks)\n",
148 nblocks, rd_length >> BLOCK_SIZE_BITS);
149 return;
150 }
151 printk("RAMDISK: Loading %d blocks into RAM disk", nblocks);
152
153
154 cp = rd_start;
155 while (nblocks) {
156 if (nblocks > 2)
157 bh = breada(ROOT_DEV, block, block+1, block+2, -1);
158 else
159 bh = bread(ROOT_DEV, block, BLOCK_SIZE);
160 if (!bh) {
161 printk("RAMDISK: I/O error on block %d, aborting!\n",
162 block);
163 return;
164 }
165 (void) memcpy(cp, bh->b_data, BLOCK_SIZE);
166 brelse(bh);
167 if (!(nblocks-- & 15)) printk(".");
168 cp += BLOCK_SIZE;
169 block++;
170 i++;
171 }
172 printk("\ndone\n");
173
174
175 ROOT_DEV = ((MAJOR_RAMDISK << 8) | MINOR_RAMDISK);
176 return;
177 }
178 }