2 * Mach Operating System
3 * Copyright (c) 1992 Carnegie Mellon University
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
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
28 static const char rcsid[] =
32 #include <sys/disklabel.h>
46 static char lbuf[LBUF];
50 * Ported to 386bsd by Julian Elischer Thu Oct 15 20:26:46 PDT 1992
52 * 14-Dec-89 Robert Baron (rvb) at Carnegie-Mellon University
53 * Copyright (c) 1989 Robert. V. Baron
57 #define Decimal(str, ans, tmp) if (decimal(str, &tmp, ans)) ans = tmp
58 #define Hex(str, ans, tmp) if (hex(str, &tmp, ans)) ans = tmp
59 #define String(str, ans, len) {char *z = ans; char **dflt = &z; if (string(str, dflt)) strncpy(ans, *dflt, len); }
61 #define RoundCyl(x) ((((x) + cylsecs - 1) / cylsecs) * cylsecs)
63 #define MAX_SEC_SIZE 2048 /* maximum section size that is supported */
64 #define MIN_SEC_SIZE 512 /* the sector size to start sensing at */
65 int secsize = 0; /* the sensed sector size */
70 "/dev/rad0", "/dev/rwd0", "/dev/rda0", "/dev/rod0", 0
73 struct disklabel disklabel; /* disk parameters */
75 int cyls, sectors, heads, cylsecs, disksecs;
79 unsigned char padding[2]; /* force the longs to be long aligned */
80 unsigned char bootinst[DOSPARTOFF];
81 struct dos_partition parts[4];
82 unsigned short int signature;
83 /* room to read in MBRs that are bigger then DEV_BSIZE */
84 unsigned char large_sector_overflow[MAX_SEC_SIZE-MIN_SEC_SIZE];
89 #define BOOT_MAGIC 0xAA55
96 #define DOSSECT(s,c) ((s & 0x3f) | ((c >> 2) & 0xc0))
97 #define DOSCYL(c) (c & 0xff)
98 static int partition = -1;
103 static int current_line_number;
105 static int geom_processed = 0;
106 static int part_processed = 0;
107 static int active_processed = 0;
120 static int B_flag = 0; /* replace boot code */
121 static int I_flag = 0; /* use entire disk for FreeBSD */
122 static int a_flag = 0; /* set active partition */
123 static char *b_flag = NULL; /* path to boot code */
124 static int i_flag = 0; /* replace partition data */
125 static int u_flag = 0; /* update partition data */
126 static int s_flag = 0; /* Print a summary and exit */
127 static int t_flag = 0; /* test only, if f_flag is given */
128 static char *f_flag = NULL; /* Read config info from file */
129 static int v_flag = 0; /* Be verbose */
138 ,{0x01, "Primary DOS with 12 bit FAT"}
139 ,{0x02, "XENIX / filesystem"}
140 ,{0x03, "XENIX /usr filesystem"}
141 ,{0x04, "Primary DOS with 16 bit FAT (<= 32MB)"}
142 ,{0x05, "Extended DOS"}
143 ,{0x06, "Primary 'big' DOS (> 32MB)"}
144 ,{0x07, "OS/2 HPFS, NTFS, QNX or Advanced UNIX"}
145 ,{0x08, "AIX filesystem"}
146 ,{0x09, "AIX boot partition or Coherent"}
147 ,{0x0A, "OS/2 Boot Manager or OPUS"}
148 ,{0x0B, "DOS or Windows 95 with 32 bit FAT"}
149 ,{0x0C, "DOS or Windows 95 with 32 bit FAT, LBA"}
150 ,{0x0E, "Primary 'big' DOS (> 32MB, LBA)"}
151 ,{0x0F, "Extended DOS, LBA"}
156 ,{0x52, "CP/M or Microport SysV/AT"}
159 ,{0x63, "ISC UNIX, other System V/386, GNU HURD or Mach"}
160 ,{0x64, "Novell Netware 2.xx"}
161 ,{0x65, "Novell Netware 3.xx"}
163 ,{0x80, "Minix 1.1 ... 1.4a"}
164 ,{0x81, "Minix 1.4b ... 1.5.10"}
165 ,{0x82, "Linux swap or Solaris x86"}
166 ,{0x83, "Linux filesystem"}
167 ,{0x93, "Amoeba filesystem"}
168 ,{0x94, "Amoeba bad block table"}
170 ,{0xA5, "FreeBSD/NetBSD/386BSD"}
174 ,{0xB7, "BSDI BSD/386 filesystem"}
175 ,{0xB8, "BSDI BSD/386 swap"}
176 ,{0xDB, "Concurrent CPM or C.DOS or CTOS"}
181 ,{0xF2, "DOS 3.3+ Secondary"}
183 ,{0xFF, "BBT (Bad Blocks Table)"}
186 static void print_s0(int which);
187 static void print_part(int i);
188 static void init_sector0(unsigned long start);
189 static void init_boot(void);
190 static void change_part(int i);
191 static void print_params();
192 static void change_active(int which);
193 static void change_code();
194 static void get_params_to_use();
195 static void dos(int sec, int size, unsigned char *c, unsigned char *s,
197 static int open_disk(int u_flag);
198 static ssize_t read_disk(off_t sector, void *buf);
199 static ssize_t write_disk(off_t sector, void *buf);
200 static int get_params();
201 static int read_s0();
202 static int write_s0();
203 static int ok(char *str);
204 static int decimal(char *str, int *num, int deflt);
205 static char *get_type(int type);
206 static int read_config(char *config_file);
207 static void reset_boot(void);
208 static void usage(void);
210 static int hex(char *str, int *num, int deflt);
211 static int string(char *str, char **ans);
216 main(int argc, char *argv[])
220 while ((c = getopt(argc, argv, "BIab:f:istuv1234")) != -1)
261 if (f_flag || i_flag)
270 static char realname[12];
272 if(strncmp(argv[0], "/dev", 4) == 0)
276 snprintf(realname, 12, "/dev/%s", argv[0]);
280 if (open_disk(u_flag) < 0)
281 err(1, "cannot open disk %s", disk);
287 for(i = 0; disks[i]; i++)
290 rv = open_disk(u_flag);
294 err(1, "cannot open any disk");
299 struct dos_partition *partp;
303 printf("%s: %d cyl %d hd %d sec\n", disk, dos_cyls, dos_heads,
305 printf("Part %11s %11s Type Flags\n", "Start", "Size");
306 for (i = 0; i < NDOSPART; i++) {
307 partp = ((struct dos_partition *) &mboot.parts) + i;
308 if (partp->dp_start == 0 && partp->dp_size == 0)
310 printf("%4d: %11lu %11lu 0x%02x 0x%02x\n", i + 1,
311 (u_long) partp->dp_start,
312 (u_long) partp->dp_size, partp->dp_typ,
318 printf("******* Working on device %s *******\n",disk);
322 struct dos_partition *partp;
326 partp = (struct dos_partition *) (&mboot.parts[0]);
327 partp->dp_typ = DOSPTYP_386BSD;
328 partp->dp_flag = ACTIVE;
329 partp->dp_start = dos_sectors;
330 partp->dp_size = disksecs - dos_sectors;
332 dos(partp->dp_start, partp->dp_size,
333 &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd);
334 dos(partp->dp_start + partp->dp_size - 1, partp->dp_size,
335 &partp->dp_ecyl, &partp->dp_esect, &partp->dp_ehd);
343 if (read_s0() || i_flag)
348 if (!read_config(f_flag))
375 printf("Media sector size is %d\n", secsize);
376 printf("Warning: BIOS sector numbering starts with sector 1\n");
377 printf("Information from DOS bootblock is:\n");
379 for (i = 1; i <= NDOSPART; i++)
382 change_part(partition);
384 if (u_flag || a_flag)
385 change_active(partition);
390 if (u_flag || a_flag || B_flag) {
393 printf("\nWe haven't changed the partition table yet. ");
394 printf("This is your last chance.\n");
399 if (ok("Should we write new partition table?"))
404 printf("\n-t flag specified -- partition table not written.\n");
415 fprintf(stderr, "%s%s",
416 "usage: fdisk [-Baeitu] [-b bootcode] [-1234] [disk]\n",
417 " fdisk -f configfile [-itv] [disk]\n");
427 printf("Information from DOS bootblock is:\n");
429 for (i = 1; i <= NDOSPART; i++)
430 printf("%d: ", i), print_part(i);
435 static struct dos_partition mtpart = { 0 };
440 struct dos_partition *partp;
443 partp = ((struct dos_partition *) &mboot.parts) + i - 1;
445 if (!bcmp(partp, &mtpart, sizeof (struct dos_partition))) {
446 printf("<UNUSED>\n");
450 * Be careful not to overflow.
452 part_mb = partp->dp_size;
454 part_mb /= (1024 * 1024);
455 printf("sysid %d,(%s)\n", partp->dp_typ, get_type(partp->dp_typ));
456 printf(" start %lu, size %lu (%qd Meg), flag %x%s\n",
457 (u_long)partp->dp_start,
458 (u_long)partp->dp_size,
461 partp->dp_flag == ACTIVE ? " (active)" : "");
462 printf("\tbeg: cyl %d/ sector %d/ head %d;\n\tend: cyl %d/ sector %d/ head %d\n"
463 ,DPCYL(partp->dp_scyl, partp->dp_ssect)
464 ,DPSECT(partp->dp_ssect)
466 ,DPCYL(partp->dp_ecyl, partp->dp_esect)
467 ,DPSECT(partp->dp_esect)
478 fname = b_flag ? b_flag : "/boot/mbr";
479 if ((fd = open(fname, O_RDONLY)) == -1 ||
480 read(fd, mboot.bootinst, DOSPARTOFF) == -1 ||
483 mboot.signature = BOOT_MAGIC;
488 init_sector0(unsigned long start)
490 struct dos_partition *partp = (struct dos_partition *) (&mboot.parts[3]);
491 unsigned long size = disksecs - start;
495 partp->dp_typ = DOSPTYP_386BSD;
496 partp->dp_flag = ACTIVE;
497 partp->dp_start = start;
498 partp->dp_size = size;
500 dos(partp->dp_start, partp->dp_size,
501 &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd);
502 dos(partp->dp_start + partp->dp_size - 1, partp->dp_size,
503 &partp->dp_ecyl, &partp->dp_esect, &partp->dp_ehd);
509 struct dos_partition *partp = ((struct dos_partition *) &mboot.parts) + i - 1;
511 printf("The data for partition %d is:\n", i);
514 if (u_flag && ok("Do you want to change it?")) {
518 bzero((char *)partp, sizeof (struct dos_partition));
521 printf("\nThe static data for the DOS partition 4 has been reinitialized to:\n");
527 Decimal("sysid (165=FreeBSD)", partp->dp_typ, tmp);
528 Decimal("start", partp->dp_start, tmp);
529 Decimal("size", partp->dp_size, tmp);
531 if (ok("Explicitly specify beg/end address ?"))
534 tcyl = DPCYL(partp->dp_scyl,partp->dp_ssect);
536 tsec = DPSECT(partp->dp_ssect);
537 Decimal("beginning cylinder", tcyl, tmp);
538 Decimal("beginning head", thd, tmp);
539 Decimal("beginning sector", tsec, tmp);
540 partp->dp_scyl = DOSCYL(tcyl);
541 partp->dp_ssect = DOSSECT(tsec,tcyl);
544 tcyl = DPCYL(partp->dp_ecyl,partp->dp_esect);
546 tsec = DPSECT(partp->dp_esect);
547 Decimal("ending cylinder", tcyl, tmp);
548 Decimal("ending head", thd, tmp);
549 Decimal("ending sector", tsec, tmp);
550 partp->dp_ecyl = DOSCYL(tcyl);
551 partp->dp_esect = DOSSECT(tsec,tcyl);
554 dos(partp->dp_start, partp->dp_size,
555 &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd);
556 dos(partp->dp_start + partp->dp_size - 1, partp->dp_size,
557 &partp->dp_ecyl, &partp->dp_esect, &partp->dp_ehd);
561 } while (!ok("Are we happy with this entry?"));
568 printf("parameters extracted from in-core disklabel are:\n");
569 printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n"
570 ,cyls,heads,sectors,cylsecs);
571 if((dos_sectors > 63) || (dos_cyls > 1023) || (dos_heads > 255))
572 printf("Figures below won't work with BIOS for partitions not in cyl 1\n");
573 printf("parameters to be used for BIOS calculations are:\n");
574 printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n"
575 ,dos_cyls,dos_heads,dos_sectors,dos_cylsecs);
579 change_active(int which)
583 struct dos_partition *partp = ((struct dos_partition *) &mboot.parts);
585 if (a_flag && which != -1)
587 if (!ok("Do you want to change the active partition?"))
592 Decimal("active partition", active, tmp);
593 if (active < 1 || 4 < active) {
594 printf("Active partition number must be in range 1-4."
598 } while (!ok("Are you happy with this choice"));
599 for (i = 0; i < NDOSPART; i++)
600 partp[i].dp_flag = 0;
601 if (active > 0 && active <= NDOSPART)
602 partp[active-1].dp_flag = ACTIVE;
608 if (ok("Do you want to change the boot code?"))
618 if (ok("Do you want to change our idea of what BIOS thinks ?"))
622 Decimal("BIOS's idea of #cylinders", dos_cyls, tmp);
623 Decimal("BIOS's idea of #heads", dos_heads, tmp);
624 Decimal("BIOS's idea of #sectors", dos_sectors, tmp);
625 dos_cylsecs = dos_heads * dos_sectors;
628 while(!ok("Are you happy with this choice"));
633 /***********************************************\
634 * Change real numbers into strange dos numbers *
635 \***********************************************/
637 dos(sec, size, c, s, h)
639 unsigned char *c, *s, *h;
644 if (sec == 0 && size == 0) {
649 cy = sec / ( dos_cylsecs );
650 sec = sec - cy * ( dos_cylsecs );
652 hd = sec / dos_sectors;
653 sec = (sec - hd * dos_sectors) + 1;
657 *s = (sec & 0x3f) | ( (cy & 0x300) >> 2);
662 /* Getting device status */
665 open_disk(int u_flag)
669 if (stat(disk, &st) == -1) {
670 warnx("can't get file status of %s", disk);
673 if ( !(st.st_mode & S_IFCHR) )
674 warnx("device %s is not character special", disk);
676 a_flag || I_flag || B_flag || u_flag ? O_RDWR : O_RDONLY)) == -1) {
679 warnx("can't open device %s", disk);
682 if (get_params(0) == -1) {
683 warnx("can't get disk parameters on %s", disk);
690 read_disk(off_t sector, void *buf)
692 lseek(fd,(sector * 512), 0);
694 for( secsize = MIN_SEC_SIZE; secsize <= MAX_SEC_SIZE; secsize *= 2 )
697 int size = read(fd, buf, secsize);
698 if( size == secsize )
699 /* it worked so return */
703 return read( fd, buf, secsize );
705 /* we failed to read at any of the sizes */
710 write_disk(off_t sector, void *buf)
712 lseek(fd,(sector * 512), 0);
713 /* write out in the size that the read_disk found worked */
714 return write(fd, buf, secsize);
721 if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
722 warnx("can't get disk parameters on %s; supplying dummy ones", disk);
724 dos_heads = heads = 1;
725 dos_sectors = sectors = 1;
726 dos_cylsecs = cylsecs = heads * sectors;
727 disksecs = cyls * heads * sectors;
731 dos_cyls = cyls = disklabel.d_ncylinders;
732 dos_heads = heads = disklabel.d_ntracks;
733 dos_sectors = sectors = disklabel.d_nsectors;
734 dos_cylsecs = cylsecs = heads * sectors;
735 disksecs = cyls * heads * sectors;
744 if (read_disk(0, (char *) mboot.bootinst) == -1) {
745 warnx("can't read fdisk partition table");
748 if (mboot.signature != BOOT_MAGIC) {
749 warnx("invalid fdisk partition table found");
750 /* So should we initialize things */
767 * write enable label sector before write (if necessary),
768 * disable after writing.
769 * needed if the disklabel protected area also protects
770 * sector 0. (e.g. empty disk)
774 if (ioctl(fd, DIOCWLABEL, &flag) < 0)
775 warn("ioctl DIOCWLABEL");
777 if (write_disk(0, (char *) mboot.bootinst) == -1) {
778 warn("can't write fdisk partition table");
782 (void) ioctl(fd, DIOCWLABEL, &flag);
793 printf("%s [n] ", str);
794 fgets(lbuf, LBUF, stdin);
795 lbuf[strlen(lbuf)-1] = 0;
798 (!strcmp(lbuf, "yes") || !strcmp(lbuf, "YES") ||
799 !strcmp(lbuf, "y") || !strcmp(lbuf, "Y")))
806 decimal(char *str, int *num, int deflt)
812 printf("Supply a decimal value for \"%s\" [%d] ", str, deflt);
813 fgets(lbuf, LBUF, stdin);
814 lbuf[strlen(lbuf)-1] = 0;
820 while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
823 while ((c = *cp++)) {
824 if (c <= '9' && c >= '0')
825 acc = acc * 10 + c - '0';
829 if (c == ' ' || c == '\t')
830 while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
835 printf("%s is an invalid decimal number. Try again.\n",
843 hex(char *str, int *num, int deflt)
849 printf("Supply a hex value for \"%s\" [%x] ", str, deflt);
850 fgets(lbuf, LBUF, stdin);
851 lbuf[strlen(lbuf)-1] = 0;
857 while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
860 while ((c = *cp++)) {
861 if (c <= '9' && c >= '0')
862 acc = (acc << 4) + c - '0';
863 else if (c <= 'f' && c >= 'a')
864 acc = (acc << 4) + c - 'a' + 10;
865 else if (c <= 'F' && c >= 'A')
866 acc = (acc << 4) + c - 'A' + 10;
870 if (c == ' ' || c == '\t')
871 while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
876 printf("%s is an invalid hex number. Try again.\n",
883 string(char *str, char **ans)
889 printf("Supply a string value for \"%s\" [%s] ", str, *ans);
890 fgets(lbuf, LBUF, stdin);
891 lbuf[strlen(lbuf)-1] = 0;
896 while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
900 while ((c = *cp) && c != '"') cp++;
903 while ((c = *cp) && c != ' ' && c != '\t') cp++;
916 int numentries = (sizeof(part_types)/sizeof(struct part_type));
918 struct part_type *ptr = part_types;
921 while(counter < numentries)
923 if(ptr->type == type)
935 parse_config_line(line, command)
942 while (1) /* dirty trick used to insure one exit point for this
945 memset(command, 0, sizeof(*command));
947 while (isspace(*cp)) ++cp;
948 if (*cp == '\0' || *cp == '#')
952 command->cmd = *cp++;
959 while (isspace(*cp)) ++cp;
962 break; /* found comment */
966 command->args[command->n_args].argtype = *cp++;
970 break; /* assume end of line */
973 command->args[command->n_args].arg_val = strtol(cp, &end, 0);
976 break; /* couldn't parse number */
987 process_geometry(command)
998 "ERROR line %d: the geometry specification line must occur before\n\
999 all partition specifications",
1000 current_line_number);
1004 if (command->n_args != 3)
1006 warnx("ERROR line %d: incorrect number of geometry args",
1007 current_line_number);
1014 for (i = 0; i < 3; ++i)
1016 switch (command->args[i].argtype)
1019 dos_cyls = command->args[i].arg_val;
1022 dos_heads = command->args[i].arg_val;
1025 dos_sectors = command->args[i].arg_val;
1029 "ERROR line %d: unknown geometry arg type: '%c' (0x%02x)",
1030 current_line_number, command->args[i].argtype,
1031 command->args[i].argtype);
1041 dos_cylsecs = dos_heads * dos_sectors;
1044 * Do sanity checks on parameter values
1048 warnx("ERROR line %d: number of cylinders not specified",
1049 current_line_number);
1052 if (dos_cyls == 0 || dos_cyls > 1024)
1055 "WARNING line %d: number of cylinders (%d) may be out-of-range\n\
1056 (must be within 1-1024 for normal BIOS operation, unless the entire disk\n\
1057 is dedicated to FreeBSD)",
1058 current_line_number, dos_cyls);
1063 warnx("ERROR line %d: number of heads not specified",
1064 current_line_number);
1067 else if (dos_heads < 1 || dos_heads > 256)
1069 warnx("ERROR line %d: number of heads must be within (1-256)",
1070 current_line_number);
1074 if (dos_sectors < 0)
1076 warnx("ERROR line %d: number of sectors not specified",
1077 current_line_number);
1080 else if (dos_sectors < 1 || dos_sectors > 63)
1082 warnx("ERROR line %d: number of sectors must be within (1-63)",
1083 current_line_number);
1094 process_partition(command)
1097 int status = 0, partition;
1098 unsigned long chunks, adj_size, max_end;
1099 struct dos_partition *partp;
1104 if (command->n_args != 4)
1106 warnx("ERROR line %d: incorrect number of partition args",
1107 current_line_number);
1110 partition = command->args[0].arg_val;
1111 if (partition < 1 || partition > 4)
1113 warnx("ERROR line %d: invalid partition number %d",
1114 current_line_number, partition);
1117 partp = ((struct dos_partition *) &mboot.parts) + partition - 1;
1118 bzero((char *)partp, sizeof (struct dos_partition));
1119 partp->dp_typ = command->args[1].arg_val;
1120 partp->dp_start = command->args[2].arg_val;
1121 partp->dp_size = command->args[3].arg_val;
1122 max_end = partp->dp_start + partp->dp_size;
1124 if (partp->dp_typ == 0)
1127 * Get out, the partition is marked as unused.
1130 * Insure that it's unused.
1132 bzero((char *)partp, sizeof (struct dos_partition));
1138 * Adjust start upwards, if necessary, to fall on an head boundary.
1140 if (partp->dp_start % dos_sectors != 0)
1143 (partp->dp_start / dos_sectors + 1) * dos_sectors;
1144 if (adj_size > max_end)
1147 * Can't go past end of partition
1150 "ERROR line %d: unable to adjust start of partition %d to fall on\n\
1151 a cylinder boundary",
1152 current_line_number, partition);
1156 "WARNING: adjusting start offset of partition '%d' from %lu\n\
1157 to %lu, to round to an head boundary",
1158 partition, (u_long)partp->dp_start, adj_size);
1159 partp->dp_start = adj_size;
1163 * Adjust size downwards, if necessary, to fall on a cylinder
1167 ((partp->dp_start + partp->dp_size) / dos_cylsecs) * dos_cylsecs;
1168 adj_size = chunks - partp->dp_start;
1169 if (adj_size != partp->dp_size)
1172 "WARNING: adjusting size of partition '%d' from %lu to %lu,\n\
1173 to round to a cylinder boundary",
1174 partition, (u_long)partp->dp_size, adj_size);
1177 partp->dp_size = adj_size;
1184 if (partp->dp_size < 1)
1186 warnx("ERROR line %d: size for partition '%d' is zero",
1187 current_line_number, partition);
1191 dos(partp->dp_start, partp->dp_size,
1192 &partp->dp_scyl, &partp->dp_ssect, &partp->dp_shd);
1193 dos(partp->dp_start+partp->dp_size - 1, partp->dp_size,
1194 &partp->dp_ecyl, &partp->dp_esect, &partp->dp_ehd);
1203 process_active(command)
1206 int status = 0, partition, i;
1207 struct dos_partition *partp;
1211 active_processed = 1;
1212 if (command->n_args != 1)
1214 warnx("ERROR line %d: incorrect number of active args",
1215 current_line_number);
1219 partition = command->args[0].arg_val;
1220 if (partition < 1 || partition > 4)
1222 warnx("ERROR line %d: invalid partition number %d",
1223 current_line_number, partition);
1227 * Reset active partition
1229 partp = ((struct dos_partition *) &mboot.parts);
1230 for (i = 0; i < NDOSPART; i++)
1231 partp[i].dp_flag = 0;
1232 partp[partition-1].dp_flag = ACTIVE;
1250 parse_config_line(line, &command);
1251 switch (command.cmd)
1255 * Comment or blank line
1262 status = process_geometry(&command);
1265 status = process_partition(&command);
1268 status = process_active(&command);
1281 read_config(config_file)
1288 while (1) /* dirty trick used to insure one exit point for this
1291 if (strcmp(config_file, "-") != 0)
1294 * We're not reading from stdin
1296 if ((fp = fopen(config_file, "r")) == NULL)
1306 current_line_number = 0;
1309 if (fgets(buf, sizeof(buf), fp) == NULL)
1313 ++current_line_number;
1314 status = process_line(buf);
1325 * It doesn't matter if we're reading from stdin, as we've reached EOF
1337 struct dos_partition *partp;
1340 for (i = 0; i < 4; ++i)
1342 partp = ((struct dos_partition *) &mboot.parts) + i;
1343 bzero((char *)partp, sizeof (struct dos_partition));