This source file includes following definitions.
- minor_name
- add_partition
- extended_partition
- check_partition
- resetup_one_dev
- setup_dev
- device_setup
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/config.h>
14 #include <linux/fs.h>
15 #include <linux/genhd.h>
16 #include <linux/kernel.h>
17 #include <linux/major.h>
18
19 struct gendisk *gendisk_head = NULL;
20
21 static int current_minor = 0;
22 extern int *blk_size[];
23 extern void rd_load(void);
24 extern int ramdisk_size;
25
26 static char minor_name (struct gendisk *hd, int minor)
27 {
28 char base_name = (hd->major == IDE1_MAJOR) ? 'c' : 'a';
29 return base_name + (minor >> hd->minor_shift);
30 }
31
32 static void add_partition (struct gendisk *hd, int minor, int start, int size)
33 {
34 hd->part[minor].start_sect = start;
35 hd->part[minor].nr_sects = size;
36 printk(" %s%c%d", hd->major_name, minor_name(hd, minor),
37 minor & ((1 << hd->minor_shift) - 1));
38 }
39
40
41
42
43
44
45
46
47
48
49
50 static void extended_partition(struct gendisk *hd, int dev)
51 {
52 struct buffer_head *bh;
53 struct partition *p;
54 unsigned long first_sector, this_sector;
55 int mask = (1 << hd->minor_shift) - 1;
56
57 first_sector = hd->part[MINOR(dev)].start_sect;
58 this_sector = first_sector;
59
60 while (1) {
61 if ((current_minor & mask) >= (4 + hd->max_p))
62 return;
63 if (!(bh = bread(dev,0,1024)))
64 return;
65
66
67
68
69 bh->b_dirt = 0;
70 bh->b_uptodate = 0;
71 bh->b_req = 0;
72 if (*(unsigned short *) (bh->b_data+510) == 0xAA55) {
73 p = (struct partition *) (0x1BE + bh->b_data);
74
75
76
77
78 if (p->sys_ind == EXTENDED_PARTITION || !p->nr_sects)
79 goto done;
80 add_partition(hd, current_minor, this_sector+p->start_sect, p->nr_sects);
81 current_minor++;
82 p++;
83
84
85
86
87
88
89
90 if (p->sys_ind != EXTENDED_PARTITION ||
91 !(hd->part[current_minor].nr_sects = p->nr_sects))
92 goto done;
93 hd->part[current_minor].start_sect = first_sector + p->start_sect;
94 this_sector = first_sector + p->start_sect;
95 dev = ((hd->major) << 8) | current_minor;
96 brelse(bh);
97 } else
98 goto done;
99 }
100 done:
101 brelse(bh);
102 }
103
104 static void check_partition(struct gendisk *hd, unsigned int dev)
105 {
106 static int first_time = 1;
107 int i, minor = current_minor;
108 struct buffer_head *bh;
109 struct partition *p;
110 unsigned long first_sector;
111 int mask = (1 << hd->minor_shift) - 1;
112
113 if (first_time)
114 printk("Partition check:\n");
115 first_time = 0;
116 first_sector = hd->part[MINOR(dev)].start_sect;
117
118
119
120
121
122 if ((int)first_sector == -1) {
123 hd->part[MINOR(dev)].start_sect = 0;
124 return;
125 }
126
127 if (!(bh = bread(dev,0,1024))) {
128 printk(" unable to read partition table of device %04x\n",dev);
129 return;
130 }
131 printk(" %s%c:", hd->major_name, minor_name(hd, minor));
132 current_minor += 4;
133 if (*(unsigned short *) (bh->b_data+510) == 0xAA55) {
134 p = (struct partition *) (0x1BE + bh->b_data);
135 for (i=1 ; i<=4 ; minor++,i++,p++) {
136 if (!p->nr_sects)
137 continue;
138 add_partition(hd, minor, first_sector+p->start_sect, p->nr_sects);
139 if ((current_minor & 0x3f) >= 60)
140 continue;
141 if (p->sys_ind == EXTENDED_PARTITION) {
142 printk(" <");
143 extended_partition(hd, (hd->major << 8) | minor);
144 printk(" >");
145 }
146 }
147
148
149
150 if (*(unsigned short *) (bh->b_data+0xfc) == 0x55AA) {
151 p = (struct partition *) (0x1BE + bh->b_data);
152 for (i = 4 ; i < 16 ; i++, current_minor++) {
153 p--;
154 if ((current_minor & mask) >= mask-2)
155 break;
156 if (!(p->start_sect && p->nr_sects))
157 continue;
158 add_partition(hd, current_minor, p->start_sect, p->nr_sects);
159 }
160 }
161 } else
162 printk(" bad partition table");
163 printk("\n");
164 brelse(bh);
165 }
166
167
168
169
170
171
172
173
174
175
176 void resetup_one_dev(struct gendisk *dev, int drive)
177 {
178 int i;
179 int start = drive<<dev->minor_shift;
180 int j = start + dev->max_p;
181 int major = dev->major << 8;
182
183 current_minor = 1+(drive<<dev->minor_shift);
184 check_partition(dev, major+(drive<<dev->minor_shift));
185
186 for (i=start ; i < j ; i++)
187 dev->sizes[i] = dev->part[i].nr_sects >> (BLOCK_SIZE_BITS - 9);
188 }
189
190 static void setup_dev(struct gendisk *dev)
191 {
192 int i;
193 int j = dev->max_nr * dev->max_p;
194 int major = dev->major << 8;
195 int drive;
196
197
198 for (i = 0 ; i < j; i++) {
199 dev->part[i].start_sect = 0;
200 dev->part[i].nr_sects = 0;
201 }
202 dev->init();
203 for (drive=0 ; drive<dev->nr_real ; drive++) {
204 current_minor = 1+(drive<<dev->minor_shift);
205 check_partition(dev, major+(drive<<dev->minor_shift));
206 }
207 for (i=0 ; i < j ; i++)
208 dev->sizes[i] = dev->part[i].nr_sects >> (BLOCK_SIZE_BITS - 9);
209 blk_size[dev->major] = dev->sizes;
210 }
211
212 void device_setup(void)
213 {
214 struct gendisk *p;
215 int nr=0;
216
217 for (p = gendisk_head ; p ; p=p->next) {
218 setup_dev(p);
219 nr += p->nr_real;
220 }
221
222 if (ramdisk_size)
223 rd_load();
224 }