This source file includes following definitions.
- do_rd_request
- rd_init
- rd_load
1
2
3
4
5
6
7 #include <string.h>
8
9 #include <linux/config.h>
10 #include <linux/sched.h>
11 #include <linux/minix_fs.h>
12 #include <linux/fs.h>
13 #include <linux/kernel.h>
14 #include <asm/system.h>
15 #include <asm/segment.h>
16 #include <asm/memory.h>
17
18 #define MAJOR_NR 1
19 #include "blk.h"
20
21 char *rd_start;
22 int rd_length = 0;
23
24 void do_rd_request(void)
25 {
26 int len;
27 char *addr;
28
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
51
52
53 long rd_init(long mem_start, int length)
54 {
55 int i;
56 char *cp;
57
58 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
59 rd_start = (char *) mem_start;
60 rd_length = length;
61 cp = rd_start;
62 for (i=0; i < length; i++)
63 *cp++ = '\0';
64 return(length);
65 }
66
67
68
69
70
71
72 void rd_load(void)
73 {
74 struct buffer_head *bh;
75 struct super_block s;
76 int block = 256;
77 int i = 1;
78 int nblocks;
79 char *cp;
80
81 if (!rd_length)
82 return;
83 printk("Ram disk: %d bytes, starting at 0x%x\n", rd_length,
84 (int) rd_start);
85 if (MAJOR(ROOT_DEV) != 2)
86 return;
87 bh = breada(ROOT_DEV,block+1,block,block+2,-1);
88 if (!bh) {
89 printk("Disk error while looking for ramdisk!\n");
90 return;
91 }
92 *((struct minix_super_block *) &s) = *((struct minix_super_block *) bh->b_data);
93 brelse(bh);
94 if (s.s_magic != MINIX_SUPER_MAGIC)
95
96 return;
97 nblocks = s.s_nzones << s.s_log_zone_size;
98 if (nblocks > (rd_length >> BLOCK_SIZE_BITS)) {
99 printk("Ram disk image too big! (%d blocks, %d avail)\n",
100 nblocks, rd_length >> BLOCK_SIZE_BITS);
101 return;
102 }
103 printk("Loading %d bytes into ram disk... 0000k",
104 nblocks << BLOCK_SIZE_BITS);
105 cp = rd_start;
106 while (nblocks) {
107 if (nblocks > 2)
108 bh = breada(ROOT_DEV, block, block+1, block+2, -1);
109 else
110 bh = bread(ROOT_DEV, block);
111 if (!bh) {
112 printk("I/O error on block %d, aborting load\n",
113 block);
114 return;
115 }
116 (void) memcpy(cp, bh->b_data, BLOCK_SIZE);
117 brelse(bh);
118 printk("\010\010\010\010\010%4dk",i);
119 cp += BLOCK_SIZE;
120 block++;
121 nblocks--;
122 i++;
123 }
124 printk("\010\010\010\010\010done \n");
125 ROOT_DEV=0x0101;
126 }