Deleted Added
full compact
fdisk.c (145748) fdisk.c (145765)
1/*
2 * Mach Operating System
3 * Copyright (c) 1992 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the

--- 11 unchanged lines hidden (view full) ---

20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26
27#include <sys/cdefs.h>
1/*
2 * Mach Operating System
3 * Copyright (c) 1992 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the

--- 11 unchanged lines hidden (view full) ---

20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sbin/fdisk_pc98/fdisk.c 145748 2005-05-01 05:04:05Z nyan $");
28__FBSDID("$FreeBSD: head/sbin/fdisk_pc98/fdisk.c 145765 2005-05-01 10:08:35Z nyan $");
29
30#include <sys/disk.h>
31#include <sys/disklabel.h>
32#include <sys/diskpc98.h>
33#include <sys/param.h>
34#include <sys/stat.h>
35#include <sys/mount.h>
36#include <ctype.h>

--- 8 unchanged lines hidden (view full) ---

45#include <string.h>
46#include <unistd.h>
47
48int iotest;
49
50#define LBUF 100
51static char lbuf[LBUF];
52
29
30#include <sys/disk.h>
31#include <sys/disklabel.h>
32#include <sys/diskpc98.h>
33#include <sys/param.h>
34#include <sys/stat.h>
35#include <sys/mount.h>
36#include <ctype.h>

--- 8 unchanged lines hidden (view full) ---

45#include <string.h>
46#include <unistd.h>
47
48int iotest;
49
50#define LBUF 100
51static char lbuf[LBUF];
52
53#ifndef PC98
54#define MBRSIGOFF 510
55#endif
56
57/*
58 *
59 * Ported to 386bsd by Julian Elischer Thu Oct 15 20:26:46 PDT 1992
60 *
61 * 14-Dec-89 Robert Baron (rvb) at Carnegie-Mellon University
62 * Copyright (c) 1989 Robert. V. Baron
63 * Created.
64 */

--- 6 unchanged lines hidden (view full) ---

71#define MAX_SEC_SIZE 2048 /* maximum section size that is supported */
72#define MIN_SEC_SIZE 512 /* the sector size to start sensing at */
73static int secsize = 0; /* the sensed sector size */
74
75static char *disk;
76
77static int cyls, sectors, heads, cylsecs, disksecs;
78
53/*
54 *
55 * Ported to 386bsd by Julian Elischer Thu Oct 15 20:26:46 PDT 1992
56 *
57 * 14-Dec-89 Robert Baron (rvb) at Carnegie-Mellon University
58 * Copyright (c) 1989 Robert. V. Baron
59 * Created.
60 */

--- 6 unchanged lines hidden (view full) ---

67#define MAX_SEC_SIZE 2048 /* maximum section size that is supported */
68#define MIN_SEC_SIZE 512 /* the sector size to start sensing at */
69static int secsize = 0; /* the sensed sector size */
70
71static char *disk;
72
73static int cyls, sectors, heads, cylsecs, disksecs;
74
79#ifdef PC98
80struct mboot {
81 unsigned char padding[2]; /* force the longs to be long aligned */
82 unsigned char bootinst[510];
83 unsigned short int signature;
84 struct pc98_partition parts[8];
85 unsigned char large_sector_overflow[MAX_SEC_SIZE-MIN_SEC_SIZE];
86};
75struct mboot {
76 unsigned char padding[2]; /* force the longs to be long aligned */
77 unsigned char bootinst[510];
78 unsigned short int signature;
79 struct pc98_partition parts[8];
80 unsigned char large_sector_overflow[MAX_SEC_SIZE-MIN_SEC_SIZE];
81};
87#else /* PC98 */
88struct mboot {
89 unsigned char padding[2]; /* force the longs to be long aligned */
90 unsigned char *bootinst; /* boot code */
91 off_t bootinst_size;
92 struct dos_partition parts[4];
93};
94#endif /* PC98 */
95
96static struct mboot mboot;
97static int fd, fdw;
98
99#define ACTIVE 0x80
82
83static struct mboot mboot;
84static int fd, fdw;
85
86#define ACTIVE 0x80
100#define BOOT_MAGIC 0xAA55
101
102static uint dos_cyls;
103static uint dos_heads;
104static uint dos_sectors;
105static uint dos_cylsecs;
106
87
88static uint dos_cyls;
89static uint dos_heads;
90static uint dos_sectors;
91static uint dos_cylsecs;
92
107#ifndef PC98
108#define DOSSECT(s,c) ((s & 0x3f) | ((c >> 2) & 0xc0))
109#define DOSCYL(c) (c & 0xff)
110#endif
111
112#define MAX_ARGS 10
113
93#define MAX_ARGS 10
94
114static int current_line_number;
115
116typedef struct cmd {
117 char cmd;
118 int n_args;
119 struct arg {
120 char argtype;
121 int arg_val;
122 } args[MAX_ARGS];
123} CMD;
124
125static int B_flag = 0; /* replace boot code */
95typedef struct cmd {
96 char cmd;
97 int n_args;
98 struct arg {
99 char argtype;
100 int arg_val;
101 } args[MAX_ARGS];
102} CMD;
103
104static int B_flag = 0; /* replace boot code */
126#ifndef PC98
127static int I_flag = 0; /* use entire disk for FreeBSD */
128#endif
129static int a_flag = 0; /* set active partition */
105static int a_flag = 0; /* set active partition */
130#ifndef PC98
131static char *b_flag = NULL; /* path to boot code */
132#endif
133static int i_flag = 0; /* replace partition data */
134static int u_flag = 0; /* update partition data */
135static int s_flag = 0; /* Print a summary and exit */
136static int t_flag = 0; /* test only */
137static char *f_flag = NULL; /* Read config info from file */
138static int v_flag = 0; /* Be verbose */
139
140static struct part_type
141{
142 unsigned char type;
143 const char *name;
144} part_types[] = {
106static int i_flag = 0; /* replace partition data */
107static int u_flag = 0; /* update partition data */
108static int s_flag = 0; /* Print a summary and exit */
109static int t_flag = 0; /* test only */
110static char *f_flag = NULL; /* Read config info from file */
111static int v_flag = 0; /* Be verbose */
112
113static struct part_type
114{
115 unsigned char type;
116 const char *name;
117} part_types[] = {
145#ifdef PC98
146 {0x00, "unused"}
147 ,{0x01, "Primary DOS with 12 bit FAT"}
148 ,{0x11, "MSDOS"}
149 ,{0x20, "MSDOS"}
150 ,{0x21, "MSDOS"}
151 ,{0x22, "MSDOS"}
152 ,{0x23, "MSDOS"}
153 ,{0x02, "XENIX / file system"}

--- 14 unchanged lines hidden (view full) ---

168 ,{0x52, "CP/M or Microport SysV/AT"}
169 ,{0x56, "GB"}
170 ,{0x61, "Speed"}
171 ,{0x63, "ISC UNIX, other System V/386, GNU HURD or Mach"}
172 ,{0x64, "Novell Netware 2.xx"}
173 ,{0x65, "Novell Netware 3.xx"}
174 ,{0x75, "PCIX"}
175 ,{0x40, "Minix"}
118 {0x00, "unused"}
119 ,{0x01, "Primary DOS with 12 bit FAT"}
120 ,{0x11, "MSDOS"}
121 ,{0x20, "MSDOS"}
122 ,{0x21, "MSDOS"}
123 ,{0x22, "MSDOS"}
124 ,{0x23, "MSDOS"}
125 ,{0x02, "XENIX / file system"}

--- 14 unchanged lines hidden (view full) ---

140 ,{0x52, "CP/M or Microport SysV/AT"}
141 ,{0x56, "GB"}
142 ,{0x61, "Speed"}
143 ,{0x63, "ISC UNIX, other System V/386, GNU HURD or Mach"}
144 ,{0x64, "Novell Netware 2.xx"}
145 ,{0x65, "Novell Netware 3.xx"}
146 ,{0x75, "PCIX"}
147 ,{0x40, "Minix"}
176#endif
177};
178
179static void print_s0(int which);
180static void print_part(int i);
181static void init_sector0(unsigned long start);
182static void init_boot(void);
183static void change_part(int i);
184static void print_params(void);
185static void change_active(int which);
186static void change_code(void);
187static void get_params_to_use(void);
188static char *get_rootdisk(void);
148};
149
150static void print_s0(int which);
151static void print_part(int i);
152static void init_sector0(unsigned long start);
153static void init_boot(void);
154static void change_part(int i);
155static void print_params(void);
156static void change_active(int which);
157static void change_code(void);
158static void get_params_to_use(void);
159static char *get_rootdisk(void);
189#ifdef PC98
190static void dos(int sec, int size,
191 unsigned short *c, unsigned char *s, unsigned char *h);
192#else
193static void dos(struct dos_partition *partp);
194#endif
160static void dos(u_int32_t start, u_int32_t size, struct pc98_partition *partp);
195static int open_disk(int flag);
196static ssize_t read_disk(off_t sector, void *buf);
197static ssize_t write_disk(off_t sector, void *buf);
198static int get_params(void);
199static int read_s0(void);
200static int write_s0(void);
201static int ok(const char *str);
202static int decimal(const char *str, int *num, int deflt);
203static const char *get_type(int type);
161static int open_disk(int flag);
162static ssize_t read_disk(off_t sector, void *buf);
163static ssize_t write_disk(off_t sector, void *buf);
164static int get_params(void);
165static int read_s0(void);
166static int write_s0(void);
167static int ok(const char *str);
168static int decimal(const char *str, int *num, int deflt);
169static const char *get_type(int type);
204static int read_config(char *config_file);
205static void reset_boot(void);
206#ifndef PC98
207static int sanitize_partition(struct dos_partition *);
208#endif
209static void usage(void);
170static void usage(void);
210#ifdef PC98
211static int string(char *str, char **ans);
212#endif
171static int string(const char *str, char **ans);
213
214int
215main(int argc, char *argv[])
216{
217 struct stat sb;
218 int c, i;
219 int partition = -1;
220 struct pc98_partition *partp;
221
172
173int
174main(int argc, char *argv[])
175{
176 struct stat sb;
177 int c, i;
178 int partition = -1;
179 struct pc98_partition *partp;
180
222#ifdef PC98
223 while ((c = getopt(argc, argv, "Ba:f:istuv12345678")) != -1)
181 while ((c = getopt(argc, argv, "Ba:f:istuv12345678")) != -1)
224#else
225 while ((c = getopt(argc, argv, "BIab:f:istuv1234")) != -1)
226#endif
227 switch (c) {
228 case 'B':
229 B_flag = 1;
230 break;
182 switch (c) {
183 case 'B':
184 B_flag = 1;
185 break;
231#ifndef PC98
232 case 'I':
233 I_flag = 1;
234 break;
235#endif
236 case 'a':
237 a_flag = 1;
238 break;
186 case 'a':
187 a_flag = 1;
188 break;
239#ifndef PC98
240 case 'b':
241 b_flag = optarg;
242 break;
243#endif
244 case 'f':
245 f_flag = optarg;
246 break;
247 case 'i':
248 i_flag = 1;
249 break;
250 case 's':
251 s_flag = 1;

--- 6 unchanged lines hidden (view full) ---

258 break;
259 case 'v':
260 v_flag = 1;
261 break;
262 case '1':
263 case '2':
264 case '3':
265 case '4':
189 case 'f':
190 f_flag = optarg;
191 break;
192 case 'i':
193 i_flag = 1;
194 break;
195 case 's':
196 s_flag = 1;

--- 6 unchanged lines hidden (view full) ---

203 break;
204 case 'v':
205 v_flag = 1;
206 break;
207 case '1':
208 case '2':
209 case '3':
210 case '4':
266#ifdef PC98
267 case '5':
268 case '6':
269 case '7':
270 case '8':
211 case '5':
212 case '6':
213 case '7':
214 case '8':
271#endif
272 partition = c - '0';
273 break;
274 default:
275 usage();
276 }
277 if (f_flag || i_flag)
278 u_flag = 1;
279 if (t_flag)

--- 15 unchanged lines hidden (view full) ---

295 } else {
296 /* other stat error, let it fail below */
297 disk = argv[0];
298 }
299 }
300 if (open_disk(u_flag) < 0)
301 err(1, "cannot open disk %s", disk);
302
215 partition = c - '0';
216 break;
217 default:
218 usage();
219 }
220 if (f_flag || i_flag)
221 u_flag = 1;
222 if (t_flag)

--- 15 unchanged lines hidden (view full) ---

238 } else {
239 /* other stat error, let it fail below */
240 disk = argv[0];
241 }
242 }
243 if (open_disk(u_flag) < 0)
244 err(1, "cannot open disk %s", disk);
245
303#ifndef PC98
304 /* (abu)use mboot.bootinst to probe for the sector size */
305 if ((mboot.bootinst = malloc(MAX_SEC_SIZE)) == NULL)
306 err(1, "cannot allocate buffer to determine disk sector size");
307 read_disk(0, mboot.bootinst);
308 free(mboot.bootinst);
309 mboot.bootinst = NULL;
310#endif
311
312 if (s_flag) {
313 if (read_s0())
314 err(1, "read_s0");
315 printf("%s: %d cyl %d hd %d sec\n", disk, dos_cyls, dos_heads,
316 dos_sectors);
246 if (s_flag) {
247 if (read_s0())
248 err(1, "read_s0");
249 printf("%s: %d cyl %d hd %d sec\n", disk, dos_cyls, dos_heads,
250 dos_sectors);
317#ifdef PC98
318 printf("Part %11s %11s SID\n", "Start", "Size");
319 for (i = 0; i < NDOSPART; i++) {
320 partp = ((struct pc98_partition *) &mboot.parts) + i;
321 if (partp->dp_sid == 0)
322 continue;
251 printf("Part %11s %11s SID\n", "Start", "Size");
252 for (i = 0; i < NDOSPART; i++) {
253 partp = ((struct pc98_partition *) &mboot.parts) + i;
254 if (partp->dp_sid == 0)
255 continue;
323 printf("%4d: %11lu %11lu 0x%02x\n", i + 1,
256 printf("%4d: %11u %11u 0x%02x\n", i + 1,
324 partp->dp_scyl * cylsecs,
325 (partp->dp_ecyl - partp->dp_scyl + 1) * cylsecs,
326 partp->dp_sid);
257 partp->dp_scyl * cylsecs,
258 (partp->dp_ecyl - partp->dp_scyl + 1) * cylsecs,
259 partp->dp_sid);
327#else
328 printf("Part %11s %11s Type Flags\n", "Start", "Size");
329 for (i = 0; i < NDOSPART; i++) {
330 partp = ((struct dos_partition *) &mboot.parts) + i;
331 if (partp->dp_start == 0 && partp->dp_size == 0)
332 continue;
333 printf("%4d: %11lu %11lu 0x%02x 0x%02x\n", i + 1,
334 (u_long) partp->dp_start,
335 (u_long) partp->dp_size, partp->dp_typ,
336 partp->dp_flag);
337#endif
338 }
339 exit(0);
340 }
341
342 printf("******* Working on device %s *******\n",disk);
343
260 }
261 exit(0);
262 }
263
264 printf("******* Working on device %s *******\n",disk);
265
344#ifndef PC98
345 if (I_flag) {
346 read_s0();
347 reset_boot();
348 partp = (struct dos_partition *) (&mboot.parts[0]);
349 partp->dp_typ = DOSPTYP_386BSD;
350 partp->dp_flag = ACTIVE;
351 partp->dp_start = dos_sectors;
352 partp->dp_size = (disksecs / dos_cylsecs) * dos_cylsecs -
353 dos_sectors;
354 dos(partp);
355 if (v_flag)
356 print_s0(-1);
357 if (!t_flag)
358 write_s0();
359 exit(0);
360 }
361#endif
362 if (f_flag) {
266 if (f_flag) {
363#ifndef PC98
364 if (read_s0() || i_flag)
365 reset_boot();
366 if (!read_config(f_flag))
367 exit(1);
368#endif
369 if (v_flag)
370 print_s0(-1);
371 if (!t_flag)
372 write_s0();
373 } else {
374 if(u_flag)
375 get_params_to_use();
376 else

--- 70 unchanged lines hidden (view full) ---

447
448 if (!bcmp(partp, &mtpart, sizeof (struct pc98_partition))) {
449 printf("<UNUSED>\n");
450 return;
451 }
452 /*
453 * Be careful not to overflow.
454 */
267 if (v_flag)
268 print_s0(-1);
269 if (!t_flag)
270 write_s0();
271 } else {
272 if(u_flag)
273 get_params_to_use();
274 else

--- 70 unchanged lines hidden (view full) ---

345
346 if (!bcmp(partp, &mtpart, sizeof (struct pc98_partition))) {
347 printf("<UNUSED>\n");
348 return;
349 }
350 /*
351 * Be careful not to overflow.
352 */
455#ifdef PC98
456 part_sz = (partp->dp_ecyl - partp->dp_scyl + 1) * cylsecs;
457 part_mb = part_sz * secsize;
458 part_mb /= (1024 * 1024);
459 printf("sysmid %d (%#04x),(%s)\n", partp->dp_mid, partp->dp_mid,
460 get_type(partp->dp_mid));
461 printf(" start %lu, size %lu (%ju Meg), sid %d\n",
462 (u_long)(partp->dp_scyl * cylsecs), (u_long)part_sz,
463 (uintmax_t)part_mb, partp->dp_sid);
353 part_sz = (partp->dp_ecyl - partp->dp_scyl + 1) * cylsecs;
354 part_mb = part_sz * secsize;
355 part_mb /= (1024 * 1024);
356 printf("sysmid %d (%#04x),(%s)\n", partp->dp_mid, partp->dp_mid,
357 get_type(partp->dp_mid));
358 printf(" start %lu, size %lu (%ju Meg), sid %d\n",
359 (u_long)(partp->dp_scyl * cylsecs), (u_long)part_sz,
360 (uintmax_t)part_mb, partp->dp_sid);
464#else
465 part_mb = partp->dp_size;
466 part_mb *= secsize;
467 part_mb /= (1024 * 1024);
468 printf("sysid %d (%#04x),(%s)\n", partp->dp_typ, partp->dp_typ,
469 get_type(partp->dp_typ));
470 printf(" start %lu, size %lu (%ju Meg), flag %x%s\n",
471 (u_long)partp->dp_start,
472 (u_long)partp->dp_size,
473 (uintmax_t)part_mb,
474 partp->dp_flag,
475 partp->dp_flag == ACTIVE ? " (active)" : "");
476#endif
477 printf("\tbeg: cyl %d/ head %d/ sector %d;\n\tend: cyl %d/ head %d/ sector %d\n"
478 ,partp->dp_scyl
479 ,partp->dp_shd
480 ,partp->dp_ssect
481 ,partp->dp_ecyl
482 ,partp->dp_ehd
483 ,partp->dp_esect);
361 printf("\tbeg: cyl %d/ head %d/ sector %d;\n\tend: cyl %d/ head %d/ sector %d\n"
362 ,partp->dp_scyl
363 ,partp->dp_shd
364 ,partp->dp_ssect
365 ,partp->dp_ecyl
366 ,partp->dp_ehd
367 ,partp->dp_esect);
484#ifdef PC98
485 printf ("\tsystem Name %.16s\n",partp->dp_name);
486#endif
368 printf ("\tsystem Name %.16s\n", partp->dp_name);
487}
488
489
490static void
491init_boot(void)
492{
369}
370
371
372static void
373init_boot(void)
374{
493#ifdef PC98
494 mboot.signature = BOOT_MAGIC;
495#else
496 const char *fname;
497 int fdesc, n;
498 struct stat sb;
499
375
500 fname = b_flag ? b_flag : "/boot/mbr";
501 if ((fdesc = open(fname, O_RDONLY)) == -1 ||
502 fstat(fdesc, &sb) == -1)
503 err(1, "%s", fname);
504 if ((mboot.bootinst_size = sb.st_size) % secsize != 0)
505 errx(1, "%s: length must be a multiple of sector size", fname);
506 if (mboot.bootinst != NULL)
507 free(mboot.bootinst);
508 if ((mboot.bootinst = malloc(mboot.bootinst_size = sb.st_size)) == NULL)
509 errx(1, "%s: unable to allocate read buffer", fname);
510 if ((n = read(fdesc, mboot.bootinst, mboot.bootinst_size)) == -1 ||
511 close(fdesc))
512 err(1, "%s", fname);
513 if (n != mboot.bootinst_size)
514 errx(1, "%s: short read", fname);
515#endif
376 mboot.signature = DOSMAGIC;
516}
517
518
519static void
520init_sector0(unsigned long start)
521{
377}
378
379
380static void
381init_sector0(unsigned long start)
382{
522#ifdef PC98
523 struct pc98_partition *partp =
383 struct pc98_partition *partp =
524 (struct pc98_partition *)(&mboot.parts[3]);
525 unsigned long size = disksecs - start;
384 (struct pc98_partition *)(&mboot.parts[0]);
526
527 init_boot();
528
529 partp->dp_mid = DOSMID_386BSD;
530 partp->dp_sid = DOSSID_386BSD;
531
385
386 init_boot();
387
388 partp->dp_mid = DOSMID_386BSD;
389 partp->dp_sid = DOSSID_386BSD;
390
532 dos(start, size, &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd);
533 partp->dp_ipl_cyl = partp->dp_scyl;
534 partp->dp_ipl_sct = partp->dp_ssect;
535 partp->dp_ipl_head = partp->dp_shd;
536 dos(start+size-cylsecs, size,
537 &partp->dp_ecyl, &partp->dp_esect, &partp->dp_ehd);
538#else
539 struct dos_partition *partp = (struct dos_partition *) (&mboot.parts[3]);
540
541 init_boot();
542
543 partp->dp_typ = DOSPTYP_386BSD;
544 partp->dp_flag = ACTIVE;
545 start = ((start + dos_sectors - 1) / dos_sectors) * dos_sectors;
546 if(start == 0)
547 start = dos_sectors;
548 partp->dp_start = start;
549 partp->dp_size = (disksecs / dos_cylsecs) * dos_cylsecs - start;
550
551 dos(partp);
552#endif
391 dos(start, disksecs - start, partp);
553}
554
555static void
556change_part(int i)
557{
558 struct pc98_partition *partp =
559 ((struct pc98_partition *) &mboot.parts) + i - 1;
560
561 printf("The data for partition %d is:\n", i);
562 print_part(i);
563
564 if (u_flag && ok("Do you want to change it?")) {
565 int tmp;
566
567 if (i_flag) {
568 bzero((char *)partp, sizeof (struct pc98_partition));
392}
393
394static void
395change_part(int i)
396{
397 struct pc98_partition *partp =
398 ((struct pc98_partition *) &mboot.parts) + i - 1;
399
400 printf("The data for partition %d is:\n", i);
401 print_part(i);
402
403 if (u_flag && ok("Do you want to change it?")) {
404 int tmp;
405
406 if (i_flag) {
407 bzero((char *)partp, sizeof (struct pc98_partition));
569 if (i == 4) {
408 if (i == 1) {
570 init_sector0(1);
409 init_sector0(1);
571 printf("\nThe static data for the DOS partition 4 has been reinitialized to:\n");
410 printf("\nThe static data for the slice 1 has been reinitialized to:\n");
572 print_part(i);
573 }
574 }
575
576 do {
411 print_part(i);
412 }
413 }
414
415 do {
577#ifdef PC98
578 int x_start = partp->dp_scyl * cylsecs ;
579 int x_size = (partp->dp_ecyl - partp->dp_scyl + 1) * cylsecs;
580 Decimal("sysmid", partp->dp_mid, tmp);
581 Decimal("syssid", partp->dp_sid, tmp);
582 String ("system name", partp->dp_name, 16);
583 Decimal("start", x_start, tmp);
584 Decimal("size", x_size, tmp);
416 int x_start = partp->dp_scyl * cylsecs ;
417 int x_size = (partp->dp_ecyl - partp->dp_scyl + 1) * cylsecs;
418 Decimal("sysmid", partp->dp_mid, tmp);
419 Decimal("syssid", partp->dp_sid, tmp);
420 String ("system name", partp->dp_name, 16);
421 Decimal("start", x_start, tmp);
422 Decimal("size", x_size, tmp);
585#else
586 Decimal("sysid (165=FreeBSD)", partp->dp_typ, tmp);
587 Decimal("start", partp->dp_start, tmp);
588 Decimal("size", partp->dp_size, tmp);
589 if (!sanitize_partition(partp)) {
590 warnx("ERROR: failed to adjust; setting sysid to 0");
591 partp->dp_typ = 0;
592 }
593#endif
594
595 if (ok("Explicitly specify beg/end address ?"))
596 {
597 int tsec,tcyl,thd;
598 tcyl = partp->dp_scyl;
599 thd = partp->dp_shd;
600 tsec = partp->dp_ssect;
601 Decimal("beginning cylinder", tcyl, tmp);
602 Decimal("beginning head", thd, tmp);
603 Decimal("beginning sector", tsec, tmp);
423
424 if (ok("Explicitly specify beg/end address ?"))
425 {
426 int tsec,tcyl,thd;
427 tcyl = partp->dp_scyl;
428 thd = partp->dp_shd;
429 tsec = partp->dp_ssect;
430 Decimal("beginning cylinder", tcyl, tmp);
431 Decimal("beginning head", thd, tmp);
432 Decimal("beginning sector", tsec, tmp);
604#ifdef PC98
605 partp->dp_scyl = tcyl;
606 partp->dp_ssect = tsec;
607 partp->dp_shd = thd;
608 partp->dp_ipl_cyl = partp->dp_scyl;
609 partp->dp_ipl_sct = partp->dp_ssect;
610 partp->dp_ipl_head = partp->dp_shd;
433 partp->dp_scyl = tcyl;
434 partp->dp_ssect = tsec;
435 partp->dp_shd = thd;
436 partp->dp_ipl_cyl = partp->dp_scyl;
437 partp->dp_ipl_sct = partp->dp_ssect;
438 partp->dp_ipl_head = partp->dp_shd;
611#else
612 partp->dp_scyl = DOSCYL(tcyl);
613 partp->dp_ssect = DOSSECT(tsec,tcyl);
614 partp->dp_shd = thd;
615#endif
616
617 tcyl = partp->dp_ecyl;
618 thd = partp->dp_ehd;
619 tsec = partp->dp_esect;
620 Decimal("ending cylinder", tcyl, tmp);
621 Decimal("ending head", thd, tmp);
622 Decimal("ending sector", tsec, tmp);
439
440 tcyl = partp->dp_ecyl;
441 thd = partp->dp_ehd;
442 tsec = partp->dp_esect;
443 Decimal("ending cylinder", tcyl, tmp);
444 Decimal("ending head", thd, tmp);
445 Decimal("ending sector", tsec, tmp);
623#ifdef PC98
624 partp->dp_ecyl = tcyl;
625 partp->dp_esect = tsec;
626 partp->dp_ehd = thd;
446 partp->dp_ecyl = tcyl;
447 partp->dp_esect = tsec;
448 partp->dp_ehd = thd;
627#else
628 partp->dp_ecyl = DOSCYL(tcyl);
629 partp->dp_esect = DOSSECT(tsec,tcyl);
630 partp->dp_ehd = thd;
631#endif
632#ifdef PC98
633 } else {
634 dos(x_start, x_size, &partp->dp_scyl,
635 &partp->dp_ssect, &partp->dp_shd);
636 partp->dp_ipl_cyl = partp->dp_scyl;
637 partp->dp_ipl_sct = partp->dp_ssect;
638 partp->dp_ipl_head = partp->dp_shd;
639 dos(x_start+x_size - cylsecs, x_size, &partp->dp_ecyl,
640 &partp->dp_esect, &partp->dp_ehd);
641 }
642#else
643 } else
449 } else
644 dos(partp);
645#endif
450 dos(x_start, x_size, partp);
646
647 print_part(i);
648 } while (!ok("Are we happy with this entry?"));
649 }
650}
651
652static void
653print_params()
654{
655 printf("parameters extracted from in-core disklabel are:\n");
656 printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n"
657 ,cyls,heads,sectors,cylsecs);
451
452 print_part(i);
453 } while (!ok("Are we happy with this entry?"));
454 }
455}
456
457static void
458print_params()
459{
460 printf("parameters extracted from in-core disklabel are:\n");
461 printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n"
462 ,cyls,heads,sectors,cylsecs);
658#ifndef PC98
659 if((dos_sectors > 63) || (dos_cyls > 1023) || (dos_heads > 255))
463 if (dos_cyls > 65535 || dos_heads > 255 || dos_sectors > 255)
660 printf("Figures below won't work with BIOS for partitions not in cyl 1\n");
464 printf("Figures below won't work with BIOS for partitions not in cyl 1\n");
661#endif
662 printf("parameters to be used for BIOS calculations are:\n");
663 printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n"
664 ,dos_cyls,dos_heads,dos_sectors,dos_cylsecs);
665}
666
667static void
668change_active(int which)
669{
465 printf("parameters to be used for BIOS calculations are:\n");
466 printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n"
467 ,dos_cyls,dos_heads,dos_sectors,dos_cylsecs);
468}
469
470static void
471change_active(int which)
472{
670#ifdef PC98
671 struct pc98_partition *partp = ((struct pc98_partition *) &mboot.parts);
672 int active, i, tmp;
673
674 active = 8;
675#else
676 struct dos_partition *partp = &mboot.parts[0];
473 struct pc98_partition *partp = &mboot.parts[0];
677 int active, i, new, tmp;
678
679 active = -1;
680 for (i = 0; i < NDOSPART; i++) {
474 int active, i, new, tmp;
475
476 active = -1;
477 for (i = 0; i < NDOSPART; i++) {
681 if ((partp[i].dp_flag & ACTIVE) == 0)
478 if ((partp[i].dp_sid & ACTIVE) == 0)
682 continue;
683 printf("Partition %d is marked active\n", i + 1);
684 if (active == -1)
685 active = i + 1;
686 }
479 continue;
480 printf("Partition %d is marked active\n", i + 1);
481 if (active == -1)
482 active = i + 1;
483 }
687#endif
688 if (a_flag && which != -1)
689 active = which;
484 if (a_flag && which != -1)
485 active = which;
690#ifndef PC98
691 else if (active == -1)
692 active = 1;
486 else if (active == -1)
487 active = 1;
693#endif
694
695 if (!ok("Do you want to change the active partition?"))
696 return;
697setactive:
488
489 if (!ok("Do you want to change the active partition?"))
490 return;
491setactive:
698#ifdef PC98
699 active = 4;
700 do {
492 do {
701 Decimal("active partition", active, tmp);
702 if (active < 1 || 8 < active) {
703 printf("Active partition number must be in range 1-8."
704 " Try again.\n");
705 goto setactive;
706 }
707 } while (!ok("Are you happy with this choice"));
708 partp[active].dp_sid |= ACTIVE;
709#else
710 do {
711 new = active;
712 Decimal("active partition", new, tmp);
493 new = active;
494 Decimal("active partition", new, tmp);
713 if (new < 1 || new > 4) {
714 printf("Active partition number must be in range 1-4."
495 if (new < 1 || new > 8) {
496 printf("Active partition number must be in range 1-8."
715 " Try again.\n");
716 goto setactive;
717 }
718 active = new;
719 } while (!ok("Are you happy with this choice"));
497 " Try again.\n");
498 goto setactive;
499 }
500 active = new;
501 } while (!ok("Are you happy with this choice"));
720 for (i = 0; i < NDOSPART; i++)
721 partp[i].dp_flag = 0;
722 if (active > 0 && active <= NDOSPART)
723 partp[active-1].dp_flag = ACTIVE;
724#endif
502 if (active > 0 && active <= 8)
503 partp[active-1].dp_sid |= ACTIVE;
725}
726
727static void
728change_code()
729{
730 if (ok("Do you want to change the boot code?"))
731 init_boot();
732}

--- 16 unchanged lines hidden (view full) ---

749 while(!ok("Are you happy with this choice"));
750 }
751}
752
753
754/***********************************************\
755* Change real numbers into strange dos numbers *
756\***********************************************/
504}
505
506static void
507change_code()
508{
509 if (ok("Do you want to change the boot code?"))
510 init_boot();
511}

--- 16 unchanged lines hidden (view full) ---

528 while(!ok("Are you happy with this choice"));
529 }
530}
531
532
533/***********************************************\
534* Change real numbers into strange dos numbers *
535\***********************************************/
757#ifdef PC98
758static void
536static void
759dos(int sec, int size, unsigned short *c, unsigned char *s, unsigned char *h)
537dos(u_int32_t start, u_int32_t size, struct pc98_partition *partp)
760{
538{
761 int cy, hd;
762
763 if (sec == 0 && size == 0) {
764 *s = *c = *h = 0;
765 return;
766 }
767
768 cy = sec / ( dos_cylsecs );
769 sec = sec - cy * ( dos_cylsecs );
770
771 hd = sec / dos_sectors;
772 sec = (sec - hd * dos_sectors);
773
774 *h = hd;
775 *c = cy;
776 *s = sec;
777}
778#else
779static void
780dos(struct dos_partition *partp)
781{
782 int cy, sec;
783 u_int32_t end;
784
539 u_int32_t end;
540
785 if (partp->dp_typ == 0 && partp->dp_start == 0 && partp->dp_size == 0) {
541 if (partp->dp_mid == 0 && partp->dp_sid == 0 &&
542 start == 0 && size == 0) {
786 memcpy(partp, &mtpart, sizeof(*partp));
787 return;
788 }
789
790 /* Start c/h/s. */
543 memcpy(partp, &mtpart, sizeof(*partp));
544 return;
545 }
546
547 /* Start c/h/s. */
791 partp->dp_shd = partp->dp_start % dos_cylsecs / dos_sectors;
792 cy = partp->dp_start / dos_cylsecs;
793 sec = partp->dp_start % dos_sectors + 1;
794 partp->dp_scyl = DOSCYL(cy);
795 partp->dp_ssect = DOSSECT(sec, cy);
548 partp->dp_scyl = partp->dp_ipl_cyl = start / dos_cylsecs;
549 partp->dp_shd = partp->dp_ipl_head = start % dos_cylsecs / dos_sectors;
550 partp->dp_ssect = partp->dp_ipl_sct = start % dos_sectors;
796
797 /* End c/h/s. */
551
552 /* End c/h/s. */
798 end = partp->dp_start + partp->dp_size - 1;
553 end = start + size - cylsecs;
554 partp->dp_ecyl = end / dos_cylsecs;
799 partp->dp_ehd = end % dos_cylsecs / dos_sectors;
555 partp->dp_ehd = end % dos_cylsecs / dos_sectors;
800 cy = end / dos_cylsecs;
801 sec = end % dos_sectors + 1;
802 partp->dp_ecyl = DOSCYL(cy);
803 partp->dp_esect = DOSSECT(sec, cy);
556 partp->dp_esect = end % dos_sectors;
804}
557}
805#endif
806
807static int
808open_disk(int flag)
809{
810 struct stat st;
811 int rwmode, p;
812 char *s;
813
814 fdw = -1;
815 if (stat(disk, &st) == -1) {
816 if (errno == ENOENT)
817 return -2;
818 warnx("can't get file status of %s", disk);
819 return -1;
820 }
821 if ( !(st.st_mode & S_IFCHR) )
822 warnx("device %s is not character special", disk);
558
559static int
560open_disk(int flag)
561{
562 struct stat st;
563 int rwmode, p;
564 char *s;
565
566 fdw = -1;
567 if (stat(disk, &st) == -1) {
568 if (errno == ENOENT)
569 return -2;
570 warnx("can't get file status of %s", disk);
571 return -1;
572 }
573 if ( !(st.st_mode & S_IFCHR) )
574 warnx("device %s is not character special", disk);
823#ifdef PC98
824 rwmode = a_flag || B_flag || flag ? O_RDWR : O_RDONLY;
575 rwmode = a_flag || B_flag || flag ? O_RDWR : O_RDONLY;
825#else
826 rwmode = a_flag || I_flag || B_flag || flag ? O_RDWR : O_RDONLY;
827#endif
828 fd = open(disk, rwmode);
829 if (fd == -1 && errno == ENXIO)
830 return -2;
831 if (fd == -1 && errno == EPERM && rwmode == O_RDWR) {
832 fd = open(disk, O_RDONLY);
833 if (fd == -1)
834 return -3;
835 for (p = 0; p < NDOSPART; p++) {

--- 16 unchanged lines hidden (view full) ---

852 return -1;
853 }
854 return fd;
855}
856
857static ssize_t
858read_disk(off_t sector, void *buf)
859{
576 fd = open(disk, rwmode);
577 if (fd == -1 && errno == ENXIO)
578 return -2;
579 if (fd == -1 && errno == EPERM && rwmode == O_RDWR) {
580 fd = open(disk, O_RDONLY);
581 if (fd == -1)
582 return -3;
583 for (p = 0; p < NDOSPART; p++) {

--- 16 unchanged lines hidden (view full) ---

600 return -1;
601 }
602 return fd;
603}
604
605static ssize_t
606read_disk(off_t sector, void *buf)
607{
860 lseek(fd,(sector * 512), 0);
861#ifdef PC98
608
609 lseek(fd, (sector * 512), 0);
862 return read(fd, buf,
863 secsize > MIN_SEC_SIZE ? secsize : MIN_SEC_SIZE * 2);
610 return read(fd, buf,
611 secsize > MIN_SEC_SIZE ? secsize : MIN_SEC_SIZE * 2);
864#else
865 if( secsize == 0 )
866 for( secsize = MIN_SEC_SIZE; secsize <= MAX_SEC_SIZE; secsize *= 2 )
867 {
868 /* try the read */
869 int size = read(fd, buf, secsize);
870 if( size == secsize )
871 /* it worked so return */
872 return secsize;
873 }
874 else
875 return read( fd, buf, secsize );
876
877 /* we failed to read at any of the sizes */
878 return -1;
879#endif
880}
881
882static ssize_t
883write_disk(off_t sector, void *buf)
884{
885
612}
613
614static ssize_t
615write_disk(off_t sector, void *buf)
616{
617
886#ifdef PC98
887 if (fdw != -1) {
888 return ioctl(fdw, DIOCSPC98, buf);
889 } else {
618 if (fdw != -1) {
619 return ioctl(fdw, DIOCSPC98, buf);
620 } else {
890 lseek(fd,(sector * 512), 0);
621 lseek(fd, (sector * 512), 0);
891 /* write out in the size that the read_disk found worked */
892 return write(fd, buf,
893 secsize > MIN_SEC_SIZE ? secsize : MIN_SEC_SIZE * 2);
894 }
622 /* write out in the size that the read_disk found worked */
623 return write(fd, buf,
624 secsize > MIN_SEC_SIZE ? secsize : MIN_SEC_SIZE * 2);
625 }
895#else
896 if (fdw != -1) {
897 return ioctl(fdw, DIOCSMBR, buf);
898 } else {
899 lseek(fd,(sector * 512), 0);
900 /* write out in the size that the read_disk found worked */
901 return write(fd, buf, secsize);
902 }
903#endif
904}
905
906static int
907get_params()
908{
909 int error;
910 u_int u;
911 off_t o;
912
913 error = ioctl(fd, DIOCGFWSECTORS, &u);
914 if (error == 0)
915 sectors = dos_sectors = u;
916 else
626}
627
628static int
629get_params()
630{
631 int error;
632 u_int u;
633 off_t o;
634
635 error = ioctl(fd, DIOCGFWSECTORS, &u);
636 if (error == 0)
637 sectors = dos_sectors = u;
638 else
917 sectors = dos_sectors = 63;
639 sectors = dos_sectors = 17;
918
919 error = ioctl(fd, DIOCGFWHEADS, &u);
920 if (error == 0)
921 heads = dos_heads = u;
922 else
640
641 error = ioctl(fd, DIOCGFWHEADS, &u);
642 if (error == 0)
643 heads = dos_heads = u;
644 else
923 heads = dos_heads = 255;
645 heads = dos_heads = 8;
924
925 dos_cylsecs = cylsecs = heads * sectors;
926 disksecs = cyls * heads * sectors;
927
928 error = ioctl(fd, DIOCGSECTORSIZE, &u);
929 if (error != 0 || u == 0)
930 u = 512;
646
647 dos_cylsecs = cylsecs = heads * sectors;
648 disksecs = cyls * heads * sectors;
649
650 error = ioctl(fd, DIOCGSECTORSIZE, &u);
651 if (error != 0 || u == 0)
652 u = 512;
931#ifdef PC98
932 secsize = u;
653 secsize = u;
933#endif
934
935 error = ioctl(fd, DIOCGMEDIASIZE, &o);
936 if (error == 0) {
937 disksecs = o / u;
938 cyls = dos_cyls = o / (u * dos_heads * dos_sectors);
939 }
940
941 return (disksecs);
942}
943
944
945static int
946read_s0()
947{
654
655 error = ioctl(fd, DIOCGMEDIASIZE, &o);
656 if (error == 0) {
657 disksecs = o / u;
658 cyls = dos_cyls = o / (u * dos_heads * dos_sectors);
659 }
660
661 return (disksecs);
662}
663
664
665static int
666read_s0()
667{
948#ifdef PC98
668
949 if (read_disk(0, (char *) mboot.bootinst) == -1) {
950 warnx("can't read fdisk partition table");
951 return -1;
952 }
669 if (read_disk(0, (char *) mboot.bootinst) == -1) {
670 warnx("can't read fdisk partition table");
671 return -1;
672 }
953 if (mboot.signature != BOOT_MAGIC) {
673 if (mboot.signature != DOSMAGIC) {
954 warnx("invalid fdisk partition table found");
955 /* So should we initialize things */
956 return -1;
957 }
674 warnx("invalid fdisk partition table found");
675 /* So should we initialize things */
676 return -1;
677 }
958#else
959 mboot.bootinst_size = secsize;
960 if (mboot.bootinst != NULL)
961 free(mboot.bootinst);
962 if ((mboot.bootinst = malloc(mboot.bootinst_size)) == NULL) {
963 warnx("unable to allocate buffer to read fdisk "
964 "partition table");
965 return -1;
966 }
967 if (read_disk(0, mboot.bootinst) == -1) {
968 warnx("can't read fdisk partition table");
969 return -1;
970 }
971 if (*(uint16_t *)(void *)&mboot.bootinst[MBRSIGOFF] != BOOT_MAGIC) {
972 warnx("invalid fdisk partition table found");
973 /* So should we initialize things */
974 return -1;
975 }
976 memcpy(mboot.parts, &mboot.bootinst[DOSPARTOFF], sizeof(mboot.parts));
977#endif
678
978 return 0;
979}
980
981static int
982write_s0()
983{
679 return 0;
680}
681
682static int
683write_s0()
684{
984#ifndef PC98
985 int sector;
986#endif
987
988 if (iotest) {
989 print_s0(-1);
990 return 0;
991 }
685
686 if (iotest) {
687 print_s0(-1);
688 return 0;
689 }
992#ifndef PC98
993 memcpy(&mboot.bootinst[DOSPARTOFF], mboot.parts, sizeof(mboot.parts));
994#endif
690
995 /*
996 * write enable label sector before write (if necessary),
997 * disable after writing.
998 * needed if the disklabel protected area also protects
999 * sector 0. (e.g. empty disk)
1000 */
691 /*
692 * write enable label sector before write (if necessary),
693 * disable after writing.
694 * needed if the disklabel protected area also protects
695 * sector 0. (e.g. empty disk)
696 */
1001#ifdef PC98
1002 if (write_disk(0, (char *) mboot.bootinst) == -1) {
1003 warn("can't write fdisk partition table");
1004 return -1;
1005 }
697 if (write_disk(0, (char *) mboot.bootinst) == -1) {
698 warn("can't write fdisk partition table");
699 return -1;
700 }
1006#else
1007 for(sector = 0; sector < mboot.bootinst_size / secsize; sector++)
1008 if (write_disk(sector,
1009 &mboot.bootinst[sector * secsize]) == -1) {
1010 warn("can't write fdisk partition table");
1011 return -1;
1012 }
1013#endif
701
1014 return(0);
1015}
1016
1017
1018static int
1019ok(const char *str)
1020{
1021 printf("%s [n] ", str);

--- 43 unchanged lines hidden (view full) ---

1065 return 1;
1066 } else
1067 printf("%s is an invalid decimal number. Try again.\n",
1068 lbuf);
1069 }
1070
1071}
1072
702 return(0);
703}
704
705
706static int
707ok(const char *str)
708{
709 printf("%s [n] ", str);

--- 43 unchanged lines hidden (view full) ---

753 return 1;
754 } else
755 printf("%s is an invalid decimal number. Try again.\n",
756 lbuf);
757 }
758
759}
760
1073#ifdef PC98
1074static int
761static int
1075string(char *str, char **ans)
762string(const char *str, char **ans)
1076{
1077 int i, c;
1078 char *cp = lbuf;
1079
1080 while (1) {
1081 printf("Supply a string value for \"%s\" [%s] ", str, *ans);
1082 fgets(lbuf, LBUF, stdin);
1083 lbuf[strlen(lbuf)-1] = 0;

--- 13 unchanged lines hidden (view full) ---

1097
1098 for (i = strlen(*ans); i < 16; i++)
1099 (*ans)[i] = ' ';
1100 (*ans)[16] = 0;
1101
1102 return 1;
1103 }
1104}
763{
764 int i, c;
765 char *cp = lbuf;
766
767 while (1) {
768 printf("Supply a string value for \"%s\" [%s] ", str, *ans);
769 fgets(lbuf, LBUF, stdin);
770 lbuf[strlen(lbuf)-1] = 0;

--- 13 unchanged lines hidden (view full) ---

784
785 for (i = strlen(*ans); i < 16; i++)
786 (*ans)[i] = ' ';
787 (*ans)[16] = 0;
788
789 return 1;
790 }
791}
1105#endif
1106
1107static const char *
1108get_type(int type)
1109{
1110 int numentries = (sizeof(part_types)/sizeof(struct part_type));
1111 int counter = 0;
1112 struct part_type *ptr = part_types;
1113
1114
1115 while(counter < numentries) {
792
793static const char *
794get_type(int type)
795{
796 int numentries = (sizeof(part_types)/sizeof(struct part_type));
797 int counter = 0;
798 struct part_type *ptr = part_types;
799
800
801 while(counter < numentries) {
1116#ifdef PC98
1117 if(ptr->type == (type & 0x7f))
1118 return(ptr->name);
802 if(ptr->type == (type & 0x7f))
803 return(ptr->name);
1119#else
1120 if(ptr->type == type)
1121 return(ptr->name);
1122#endif
1123 ptr++;
1124 counter++;
1125 }
1126 return("unknown");
1127}
1128
804 ptr++;
805 counter++;
806 }
807 return("unknown");
808}
809
1129#ifndef PC98
1130static int
1131sanitize_partition(struct dos_partition *partp)
1132{
1133 u_int32_t prev_head_boundary, prev_cyl_boundary;
1134 u_int32_t max_end, size, start;
1135
1136 start = partp->dp_start;
1137 size = partp->dp_size;
1138 max_end = start + size;
1139 /* Only allow a zero size if the partition is being marked unused. */
1140 if (size == 0) {
1141 if (start == 0 && partp->dp_typ == 0)
1142 return (1);
1143 warnx("ERROR: size of partition is zero");
1144 return (0);
1145 }
1146 /* Return if no adjustment is necessary. */
1147 if (start % dos_sectors == 0 && (start + size) % dos_sectors == 0)
1148 return (1);
1149
1150 if (start % dos_sectors != 0)
1151 warnx("WARNING: partition does not start on a head boundary");
1152 if ((start +size) % dos_sectors != 0)
1153 warnx("WARNING: partition does not end on a cylinder boundary");
1154 warnx("WARNING: this may confuse the BIOS or some operating systems");
1155 if (!ok("Correct this automatically?"))
1156 return (1);
1157
1158 /*
1159 * Adjust start upwards, if necessary, to fall on a head boundary.
1160 */
1161 if (start % dos_sectors != 0) {
1162 prev_head_boundary = start / dos_sectors * dos_sectors;
1163 if (max_end < dos_sectors ||
1164 prev_head_boundary >= max_end - dos_sectors) {
1165 /*
1166 * Can't go past end of partition
1167 */
1168 warnx(
1169 "ERROR: unable to adjust start of partition to fall on a head boundary");
1170 return (0);
1171 }
1172 start = prev_head_boundary + dos_sectors;
1173 }
1174
1175 /*
1176 * Adjust size downwards, if necessary, to fall on a cylinder
1177 * boundary.
1178 */
1179 prev_cyl_boundary = ((start + size) / dos_cylsecs) * dos_cylsecs;
1180 if (prev_cyl_boundary > start)
1181 size = prev_cyl_boundary - start;
1182 else {
1183 warnx("ERROR: could not adjust partition to start on a head boundary\n\
1184 and end on a cylinder boundary.");
1185 return (0);
1186 }
1187
1188 /* Finally, commit any changes to partp and return. */
1189 if (start != partp->dp_start) {
1190 warnx("WARNING: adjusting start offset of partition to %u",
1191 (u_int)start);
1192 partp->dp_start = start;
1193 }
1194 if (size != partp->dp_size) {
1195 warnx("WARNING: adjusting size of partition to %u", (u_int)size);
1196 partp->dp_size = size;
1197 }
1198
1199 return (1);
1200}
1201#endif /* PC98 */
1202
1203/*
1204 * Try figuring out the root device's canonical disk name.
1205 * The following choices are considered:
1206 * /dev/ad0s1a => /dev/ad0
1207 * /dev/da0a => /dev/da0
1208 * /dev/vinum/root => /dev/vinum/root
1209 */
1210static char *

--- 27 unchanged lines hidden ---
810/*
811 * Try figuring out the root device's canonical disk name.
812 * The following choices are considered:
813 * /dev/ad0s1a => /dev/ad0
814 * /dev/da0a => /dev/da0
815 * /dev/vinum/root => /dev/vinum/root
816 */
817static char *

--- 27 unchanged lines hidden ---