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