1 | /*␊ |
2 | * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * ␊ |
5 | * This file contains Original Code and/or Modifications of Original Code␊ |
6 | * as defined in and that are subject to the Apple Public Source License␊ |
7 | * Version 2.0 (the 'License'). You may not use this file except in␊ |
8 | * compliance with the License. Please obtain a copy of the License at␊ |
9 | * http://www.opensource.apple.com/apsl/ and read it before using this␊ |
10 | * file.␊ |
11 | * ␊ |
12 | * The Original Code and all software distributed under the License are␊ |
13 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
16 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.␊ |
17 | * Please see the License for the specific language governing rights and␊ |
18 | * limitations under the License.␊ |
19 | * ␊ |
20 | *␊ |
21 | * 2008-05-24:␊ |
22 | * Tamas Kosarszky: changed caption for partition type 0x07␊ |
23 | * and added caption for type 0xEE.␊ |
24 | *␊ |
25 | *␊ |
26 | * Copyright (c) 1997 Tobias Weingartner␊ |
27 | * All rights reserved.␊ |
28 | *␊ |
29 | * Redistribution and use in source and binary forms, with or without␊ |
30 | * modification, are permitted provided that the following conditions␊ |
31 | * are met:␊ |
32 | * 1. Redistributions of source code must retain the above copyright␊ |
33 | * notice, this list of conditions and the following disclaimer.␊ |
34 | * 2. Redistributions in binary form must reproduce the above copyright␊ |
35 | * notice, this list of conditions and the following disclaimer in the␊ |
36 | * documentation and/or other materials provided with the distribution.␊ |
37 | * 3. All advertising materials mentioning features or use of this software␊ |
38 | * must display the following acknowledgement:␊ |
39 | * This product includes software developed by Tobias Weingartner.␊ |
40 | * 4. The name of the author may not be used to endorse or promote products␊ |
41 | * derived from this software without specific prior written permission.␊ |
42 | *␊ |
43 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR␊ |
44 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES␊ |
45 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.␊ |
46 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,␊ |
47 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT␊ |
48 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,␊ |
49 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY␊ |
50 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT␊ |
51 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF␊ |
52 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.␊ |
53 | */␊ |
54 | ␊ |
55 | #include <err.h>␊ |
56 | #include <util.h>␊ |
57 | #include <stdio.h>␊ |
58 | #include <string.h>␊ |
59 | #include <unistd.h>␊ |
60 | #include <sys/fcntl.h>␊ |
61 | #include <sys/types.h>␊ |
62 | #include <sys/stat.h>␊ |
63 | #include <machine/param.h>␊ |
64 | #include "disk.h"␊ |
65 | #include "misc.h"␊ |
66 | #include "mbr.h"␊ |
67 | ␊ |
68 | ␊ |
69 | static const struct part_type {␊ |
70 | ␉int␉type;␊ |
71 | ␉char␉sname[14];␊ |
72 | ␉char␉*lname;␊ |
73 | } part_types[] = {␊ |
74 | ␉{ 0x00, "unused ", "unused"},␊ |
75 | ␉{ 0x01, "DOS FAT-12 ", "Primary DOS with 12 bit FAT"},␊ |
76 | ␉{ 0x02, "XENIX / ", "XENIX / filesystem"},␊ |
77 | ␉{ 0x03, "XENIX /usr ", "XENIX /usr filesystem"},␊ |
78 | ␉{ 0x04, "DOS FAT-16 ", "Primary DOS with 16 bit FAT"},␊ |
79 | ␉{ 0x05, "Extended DOS", "Extended DOS"},␊ |
80 | ␉{ 0x06, "DOS > 32MB ", "Primary 'big' DOS (> 32MB)"},␊ |
81 | ␉{ 0x07, "NTFS ", "Windows NT NTFS"},␊ |
82 | ␉{ 0x08, "AIX fs ", "AIX filesystem"},␊ |
83 | ␉{ 0x09, "AIX/Coherent", "AIX boot partition or Coherent"},␊ |
84 | ␉{ 0x0A, "OS/2 Bootmgr", "OS/2 Boot Manager or OPUS"},␊ |
85 | ␉{ 0x0B, "Win95 FAT-32", "Primary Win95 w/ 32-bit FAT"},␊ |
86 | ␉{ 0x0C, "Win95 FAT32L", "Primary Win95 w/ 32-bit FAT LBA-mapped"},␊ |
87 | ␉{ 0x0E, "DOS FAT-16 ", "Primary DOS w/ 16-bit FAT, CHS-mapped"},␊ |
88 | ␉{ 0x0F, "Extended LBA", "Extended DOS LBA-mapped"},␊ |
89 | ␉{ 0x10, "OPUS ", "OPUS"},␊ |
90 | ␉{ 0x11, "OS/2 hidden ", "OS/2 BM: hidden DOS 12-bit FAT"},␊ |
91 | ␉{ 0x12, "Compaq Diag.", "Compaq Diagnostics"},␊ |
92 | ␉{ 0x14, "OS/2 hidden ", "OS/2 BM: hidden DOS 16-bit FAT <32M or Novell DOS 7.0 bug"},␊ |
93 | ␉{ 0x16, "OS/2 hidden ", "OS/2 BM: hidden DOS 16-bit FAT >=32M"},␊ |
94 | ␉{ 0x17, "OS/2 hidden ", "OS/2 BM: hidden IFS"},␊ |
95 | ␉{ 0x18, "AST swap ", "AST Windows swapfile"},␊ |
96 | ␉{ 0x19, "Willowtech ", "Willowtech Photon coS"},␊ |
97 | ␉{ 0x20, "Willowsoft ", "Willowsoft OFS1"},␊ |
98 | ␉{ 0x24, "NEC DOS ", "NEC DOS"},␊ |
99 | ␉{ 0x38, "Theos ", "Theos"},␊ |
100 | ␉{ 0x39, "Plan 9 ",␉"Plan 9"},␊ |
101 | ␉{ 0x40, "VENIX 286 ", "VENIX 286 or LynxOS"},␊ |
102 | ␉{ 0x41, "Lin/Minux DR", "Linux/MINIX (sharing disk with DRDOS) or Personal RISC boot"},␊ |
103 | ␉{ 0x42, "LinuxSwap DR", "SFS or Linux swap (sharing disk with DRDOS)"},␊ |
104 | ␉{ 0x43, "Linux DR ", "Linux native (sharing disk with DRDOS)"},␊ |
105 | ␉{ 0x4D, "QNX 4.2 Pri ", "QNX 4.2 Primary"},␊ |
106 | ␉{ 0x4E, "QNX 4.2 Sec ", "QNX 4.2 Secondary"},␊ |
107 | ␉{ 0x4F, "QNX 4.2 Ter ", "QNX 4.2 Tertiary"},␊ |
108 | ␉{ 0x50, "DM ", "DM (disk manager)"},␊ |
109 | ␉{ 0x51, "DM ", "DM6 Aux1 (or Novell)"},␊ |
110 | ␉{ 0x52, "CP/M or SysV", "CP/M or Microport SysV/AT"},␊ |
111 | ␉{ 0x53, "DM ", "DM6 Aux3"},␊ |
112 | ␉{ 0x54, "Ontrack ", "Ontrack"},␊ |
113 | ␉{ 0x55, "EZ-Drive ", "EZ-Drive (disk manager)"},␊ |
114 | ␉{ 0x56, "Golden Bow ", "Golden Bow (disk manager)"},␊ |
115 | ␉{ 0x5C, "Priam ", "Priam Edisk (disk manager)"},␊ |
116 | ␉{ 0x61, "SpeedStor ", "SpeedStor"},␊ |
117 | ␉{ 0x63, "ISC, HURD, *", "ISC, System V/386, GNU HURD or Mach"},␊ |
118 | ␉{ 0x64, "Netware 2.xx", "Novell Netware 2.xx"},␊ |
119 | ␉{ 0x65, "Netware 3.xx", "Novell Netware 3.xx"},␊ |
120 | ␉{ 0x66, "Netware 386 ", "Novell 386 Netware"},␊ |
121 | ␉{ 0x67, "Novell ", "Novell"},␊ |
122 | ␉{ 0x68, "Novell ", "Novell"},␊ |
123 | ␉{ 0x69, "Novell ", "Novell"},␊ |
124 | ␉{ 0x70, "DiskSecure ", "DiskSecure Multi-Boot"},␊ |
125 | ␉{ 0x75, "PCIX ", "PCIX"},␊ |
126 | ␉{ 0x80, "Minix (old) ", "Minix 1.1 ... 1.4a"},␊ |
127 | ␉{ 0x81, "Minix (new) ", "Minix 1.4b ... 1.5.10"},␊ |
128 | ␉{ 0x82, "Linux swap ", "Linux swap"},␊ |
129 | ␉{ 0x83, "Linux files*", "Linux filesystem"},␊ |
130 | ␉{ 0x93, "Amoeba file*", "Amoeba filesystem"},␊ |
131 | ␉{ 0x94, "Amoeba BBT ", "Amoeba bad block table"},␊ |
132 | ␉{ 0x84, "OS/2 hidden ", "OS/2 hidden C: drive"},␊ |
133 | ␉{ 0x85, "Linux ext. ", "Linux extended"},␊ |
134 | ␉{ 0x86, "NT FAT VS ", "NT FAT volume set"},␊ |
135 | ␉{ 0x87, "NTFS VS ", "NTFS volume set or HPFS mirrored"},␊ |
136 | ␉{ 0x93, "Amoeba FS ", "Amoeba filesystem"},␊ |
137 | ␉{ 0x94, "Amoeba BBT ", "Amoeba bad block table"},␊ |
138 | ␉{ 0x99, "Mylex ", "Mylex EISA SCSI"},␊ |
139 | ␉{ 0x9F, "BSDI ", "BSDI BSD/OS"},␊ |
140 | ␉{ 0xA0, "NotebookSave", "Phoenix NoteBIOS save-to-disk"},␊ |
141 | ␉{ 0xA5, "FreeBSD ",␉"FreeBSD"},␊ |
142 | ␉{ 0xA6, "OpenBSD ", "OpenBSD"},␊ |
143 | ␉{ 0xA7, "NEXTSTEP ", "NEXTSTEP"},␊ |
144 | ␉{ 0xA8, "Darwin UFS ",␉"Darwin UFS partition"},␊ |
145 | ␉{ 0xA9, "NetBSD ",␉"NetBSD"},␊ |
146 | ␉{ 0xAB, "Darwin Boot ",␉"Darwin boot partition"},␊ |
147 | ␉{ 0xAF, "HFS+ ",␉"Darwin HFS+ partition"},␊ |
148 | ␉{ 0xB7, "BSDI filesy*", "BSDI BSD/386 filesystem"},␊ |
149 | ␉{ 0xB8, "BSDI swap ", "BSDI BSD/386 swap"},␊ |
150 | ␉{ 0xC0, "CTOS ", "CTOS"},␊ |
151 | ␉{ 0xC1, "DRDOSs FAT12", "DRDOS/sec (FAT-12)"},␊ |
152 | ␉{ 0xC4, "DRDOSs < 32M", "DRDOS/sec (FAT-16, < 32M)"},␊ |
153 | ␉{ 0xC6, "DRDOSs >=32M", "DRDOS/sec (FAT-16, >= 32M)"},␊ |
154 | ␉{ 0xC7, "HPFS Disbled", "Syrinx (Cyrnix?) or HPFS disabled"},␊ |
155 | ␉{ 0xDB, "CPM/C.DOS/C*", "Concurrent CPM or C.DOS or CTOS"},␊ |
156 | ␉{ 0xE1, "SpeedStor ", "DOS access or SpeedStor 12-bit FAT extended partition"},␊ |
157 | ␉{ 0xE3, "SpeedStor ", "DOS R/O or SpeedStor or Storage Dimensions"},␊ |
158 | ␉{ 0xE4, "SpeedStor ", "SpeedStor 16-bit FAT extended partition < 1024 cyl."},␊ |
159 | ␉{ 0xEB, "BeOS/i386 ", "BeOS for Intel"},␊ |
160 | ␉{ 0xEE, "GPT ", "GPT protective partition"},␊ |
161 | ␉{ 0xF1, "SpeedStor ", "SpeedStor or Storage Dimensions"},␊ |
162 | ␉{ 0xF2, "DOS 3.3+ Sec", "DOS 3.3+ Secondary"},␊ |
163 | ␉{ 0xF4, "SpeedStor ", "SpeedStor >1024 cyl. or LANstep or IBM PS/2 IML"},␊ |
164 | ␉{ 0xFF, "Xenix BBT ", "Xenix Bad Block Table"},␊ |
165 | };␊ |
166 | ␊ |
167 | void␊ |
168 | PRT_printall()␊ |
169 | {␊ |
170 | ␉int i, idrows;␊ |
171 | ␊ |
172 | idrows = ((sizeof(part_types)/sizeof(struct part_type))+3)/4;␊ |
173 | ␊ |
174 | ␉printf("Choose from the following Partition id values:\n");␊ |
175 | ␉for (i = 0; i < idrows; i++) {␊ |
176 | ␉␉printf("%02X %s %02X %s %02X %s"␊ |
177 | , part_types[i ].type, part_types[i ].sname␊ |
178 | , part_types[i+idrows ].type, part_types[i+idrows ].sname␊ |
179 | , part_types[i+idrows*2].type, part_types[i+idrows*2].sname␊ |
180 | );␊ |
181 | if ((i+idrows*3) < (sizeof(part_types)/sizeof(struct part_type))) {␊ |
182 | ␉␉ printf(" %02X %s\n"␊ |
183 | , part_types[i+idrows*3].type, part_types[i+idrows*3].sname );␊ |
184 | }␊ |
185 | ␉␉else␊ |
186 | ␉␉ printf( "\n" );␊ |
187 | ␉}␊ |
188 | }␊ |
189 | ␊ |
190 | const char *␊ |
191 | PRT_ascii_id(id)␊ |
192 | ␉int id;␊ |
193 | {␊ |
194 | ␉static char unknown[] = "<Unknown ID>";␊ |
195 | ␉int i;␊ |
196 | ␊ |
197 | ␉for (i = 0; i < sizeof(part_types)/sizeof(struct part_type); i++) {␊ |
198 | ␉␉if (part_types[i].type == id)␊ |
199 | ␉␉␉return (part_types[i].sname);␊ |
200 | ␉}␊ |
201 | ␊ |
202 | ␉return (unknown);␊ |
203 | }␊ |
204 | ␊ |
205 | void␊ |
206 | PRT_parse(disk, prt, offset, reloff, partn, pn)␊ |
207 | ␉disk_t *disk;␊ |
208 | ␉void *prt;␊ |
209 | ␉off_t offset;␊ |
210 | ␉off_t reloff;␊ |
211 | ␉prt_t *partn;␊ |
212 | ␉int pn;␊ |
213 | {␊ |
214 | ␉unsigned char *p = prt;␊ |
215 | ␉off_t off;␊ |
216 | ␊ |
217 | ␉partn->flag = *p++;␊ |
218 | ␉partn->shead = *p++;␊ |
219 | ␊ |
220 | ␉partn->ssect = (*p) & 0x3F;␊ |
221 | ␉partn->scyl = ((*p << 2) & 0xFF00) | (*(p+1));␊ |
222 | ␉p += 2;␊ |
223 | ␊ |
224 | ␉partn->id = *p++;␊ |
225 | ␉partn->ehead = *p++;␊ |
226 | ␉partn->esect = (*p) & 0x3F;␊ |
227 | ␉partn->ecyl = ((*p << 2) & 0xFF00) | (*(p+1));␊ |
228 | ␉p += 2;␊ |
229 | ␊ |
230 | ␉if ((partn->id == DOSPTYP_EXTEND) || (partn->id == DOSPTYP_EXTENDL))␊ |
231 | ␉␉off = reloff;␊ |
232 | ␉else␊ |
233 | ␉␉off = offset;␊ |
234 | ␊ |
235 | ␉partn->bs = getlong(p) + off;␊ |
236 | ␉partn->ns = getlong(p+4);␊ |
237 | ␊ |
238 | ␊ |
239 | ␉/* Zero out entry if not used */␊ |
240 | if (partn->id == DOSPTYP_UNUSED ) {␊ |
241 | ␉ memset(partn, 0, sizeof(*partn));␊ |
242 | }␊ |
243 | }␊ |
244 | ␊ |
245 | int␊ |
246 | PRT_check_chs(partn)␊ |
247 | ␉prt_t *partn;␊ |
248 | {␊ |
249 | ␉if ( (partn->shead > 255) || ␊ |
250 | ␉␉(partn->ssect >63) || ␊ |
251 | ␉␉(partn->scyl > 1023) || ␊ |
252 | ␉␉(partn->ehead >255) || ␊ |
253 | ␉␉(partn->esect >63) || ␊ |
254 | ␉␉(partn->ecyl > 1023) )␊ |
255 | ␉{␊ |
256 | ␉␉return 0;␊ |
257 | ␉}␊ |
258 | ␉return 1;␊ |
259 | }␊ |
260 | void␊ |
261 | PRT_make(partn, offset, reloff, prt)␊ |
262 | ␉prt_t *partn;␊ |
263 | ␉off_t offset;␊ |
264 | ␉off_t reloff;␊ |
265 | ␉void *prt;␊ |
266 | {␊ |
267 | ␉unsigned char *p = prt;␊ |
268 | ␉prt_t tmp;␊ |
269 | ␉off_t off;␊ |
270 | ␊ |
271 | ␉tmp.shead = partn->shead;␊ |
272 | ␉tmp.ssect = partn->ssect;␊ |
273 | ␉tmp.scyl = (partn->scyl > 1023)? 1023: partn->scyl; ␊ |
274 | ␉tmp.ehead = partn->ehead;␊ |
275 | ␉tmp.esect = partn->esect;␊ |
276 | ␉tmp.ecyl = (partn->ecyl > 1023)? 1023: partn->ecyl; ␊ |
277 | ␉if (!PRT_check_chs(partn) && PRT_check_chs(&tmp)) {␊ |
278 | ␉␉partn->shead = tmp.shead;␊ |
279 | ␉␉partn->ssect = tmp.ssect;␊ |
280 | ␉␉partn->scyl = tmp.scyl;␊ |
281 | ␉␉partn->ehead = tmp.ehead;␊ |
282 | ␉␉partn->esect = tmp.esect;␊ |
283 | ␉␉partn->ecyl = tmp.ecyl;␊ |
284 | ␉␉printf("Cylinder values are modified to fit in CHS.\n");␊ |
285 | ␉}␊ |
286 | ␉if ((partn->id == DOSPTYP_EXTEND) || (partn->id == DOSPTYP_EXTENDL))␊ |
287 | ␉␉off = reloff;␊ |
288 | ␉else␊ |
289 | ␉␉off = offset;␊ |
290 | ␊ |
291 | ␉if (PRT_check_chs(partn)) {␊ |
292 | ␉␉*p++ = partn->flag & 0xFF;␊ |
293 | ␊ |
294 | ␉␉*p++ = partn->shead & 0xFF;␊ |
295 | ␉␉*p++ = (partn->ssect & 0x3F) | ((partn->scyl & 0x300) >> 2);␊ |
296 | ␉␉*p++ = partn->scyl & 0xFF;␊ |
297 | ␊ |
298 | ␉␉*p++ = partn->id & 0xFF;␊ |
299 | ␊ |
300 | ␉␉*p++ = partn->ehead & 0xFF;␊ |
301 | ␉␉*p++ = (partn->esect & 0x3F) | ((partn->ecyl & 0x300) >> 2);␊ |
302 | ␉␉*p++ = partn->ecyl & 0xFF;␊ |
303 | ␉} else {␊ |
304 | ␉␉/* should this really keep flag, id and set others to 0xff? */␊ |
305 | ␉␉*p++ = partn->flag & 0xFF;␊ |
306 | ␉␉*p++ = 0xFF;␊ |
307 | ␉␉*p++ = 0xFF;␊ |
308 | ␉␉*p++ = 0xFF;␊ |
309 | ␉␉*p++ = partn->id & 0xFF;␊ |
310 | ␉␉*p++ = 0xFF;␊ |
311 | ␉␉*p++ = 0xFF;␊ |
312 | ␉␉*p++ = 0xFF;␊ |
313 | ␉␉printf("Warning CHS values out of bounds only saving LBA values\n");␊ |
314 | ␉}␊ |
315 | ␊ |
316 | ␉putlong(p, partn->bs - off);␊ |
317 | ␉putlong(p+4, partn->ns);␊ |
318 | }␊ |
319 | ␊ |
320 | void␊ |
321 | PRT_print(num, partn)␊ |
322 | ␉int num;␊ |
323 | ␉prt_t *partn;␊ |
324 | {␊ |
325 | ␊ |
326 | ␉if (partn == NULL) {␊ |
327 | ␉␉printf(" Starting Ending\n");␊ |
328 | ␉␉printf(" #: id cyl hd sec - cyl hd sec [ start - size]\n");␊ |
329 | ␉␉printf("------------------------------------------------------------------------\n");␊ |
330 | ␉} else {␊ |
331 | ␉␉printf("%c%1d: %.2X %4d %3d %3d - %4d %3d %3d [%10d - %10d] %s\n",␊ |
332 | ␉␉␉(partn->flag == 0x80)?'*':' ',␊ |
333 | ␉␉␉num + 1, partn->id,␊ |
334 | ␉␉␉partn->scyl, partn->shead, partn->ssect,␊ |
335 | ␉␉␉partn->ecyl, partn->ehead, partn->esect,␊ |
336 | ␉␉␉partn->bs, partn->ns,␊ |
337 | ␉␉␉PRT_ascii_id(partn->id));␊ |
338 | ␉}␊ |
339 | }␊ |
340 | ␊ |
341 | void␊ |
342 | PRT_fix_BN(disk, part, pn)␊ |
343 | ␉disk_t *disk;␊ |
344 | ␉prt_t *part;␊ |
345 | ␉int pn;␊ |
346 | {␊ |
347 | ␉int spt, tpc, spc;␊ |
348 | ␉int start = 0;␊ |
349 | ␉int end = 0;␊ |
350 | ␊ |
351 | ␉/* Zero out entry if not used */␊ |
352 | ␉if (part->id == DOSPTYP_UNUSED ) {␊ |
353 | ␉␉memset(part, 0, sizeof(*part));␊ |
354 | ␉␉return;␊ |
355 | ␉}␊ |
356 | ␊ |
357 | ␉/* Disk metrics */␊ |
358 | ␉spt = disk->real->sectors;␊ |
359 | ␉tpc = disk->real->heads;␊ |
360 | ␉spc = spt * tpc;␊ |
361 | ␊ |
362 | ␉start += part->scyl * spc;␊ |
363 | ␉start += part->shead * spt;␊ |
364 | ␉start += part->ssect - 1;␊ |
365 | ␊ |
366 | ␉end += part->ecyl * spc;␊ |
367 | ␉end += part->ehead * spt;␊ |
368 | ␉end += part->esect - 1;␊ |
369 | ␊ |
370 | ␉/* XXX - Should handle this... */␊ |
371 | ␉if (start > end)␊ |
372 | ␉␉warn("Start of partition #%d after end!", pn);␊ |
373 | ␊ |
374 | ␉part->bs = start;␊ |
375 | ␉part->ns = (end - start) + 1;␊ |
376 | }␊ |
377 | ␊ |
378 | void␊ |
379 | PRT_fix_CHS(disk, part, pn)␊ |
380 | ␉disk_t *disk;␊ |
381 | ␉prt_t *part;␊ |
382 | ␉int pn;␊ |
383 | {␊ |
384 | int spt, tpc, spc;␊ |
385 | int start;␊ |
386 | ␉int cyl, head, sect;␊ |
387 | ␊ |
388 | ␉/* Zero out entry if not used */␊ |
389 | ␉if (part->id == DOSPTYP_UNUSED ) {␊ |
390 | ␉␉memset(part, 0, sizeof(*part));␊ |
391 | ␉␉return;␊ |
392 | ␉}␊ |
393 | ␊ |
394 | ␉/* Disk metrics */␊ |
395 | ␉spt = disk->real->sectors;␊ |
396 | ␉tpc = disk->real->heads;␊ |
397 | ␉spc = spt * tpc;␊ |
398 | ␊ |
399 | ␉start = part->bs;␊ |
400 | ␊ |
401 | ␉if(start <= spt) {␊ |
402 | ␉ /* Figure out "real" starting CHS values */␊ |
403 | ␉ cyl = (start / spc); start -= (cyl * spc);␊ |
404 | ␉ head = (start / spt); start -= (head * spt);␊ |
405 | ␉ sect = (start + 1);␊ |
406 | ␉} else {␊ |
407 | ␉ cyl = 1023;␊ |
408 | ␉ head = 254;␊ |
409 | ␉ sect = 63;␊ |
410 | ␉}␊ |
411 | ␊ |
412 | ␉part->scyl = cyl;␊ |
413 | ␉part->shead = head;␊ |
414 | ␉part->ssect = sect;␊ |
415 | ␊ |
416 | ␉/* use fake geometry to trigger LBA mode */␊ |
417 | ␊ |
418 | ␉cyl = 1023;␊ |
419 | ␉head = 254;␊ |
420 | ␉sect = 63;␊ |
421 | ␊ |
422 | ␉part->ecyl = cyl;␊ |
423 | ␉part->ehead = head;␊ |
424 | ␉part->esect = sect;␊ |
425 | }␊ |
426 | ␊ |
427 | |