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