1 /* fdisk - partition a hard disk Author: Jakob Schripsema */
5 * fdisk [-hheads] [-ssectors] [device]
9 * fdisk (to get the default)
10 * fdisk -h4 -s17 /dev/hd0 (MINIX default)
11 * fdisk -h4 -s17 c: (DOS default)
12 * fdisk -h6 -s25 /dev/hd5 (second drive, probably RLL)
13 * fdisk junkfile (to experiment safely)
15 * The device is opened in read-only mode if the file permissions do not
16 * permit read-write mode, so it is convenient to use a login account with
17 * only read permission to look at the partition table safely.
21 * cc -i -o fdisk fdisk.c (MINIX)
22 * cl -DDOS fdisk.c (DOS with MS C compiler)
24 * This was modified extensively by Bruce Evans 28 Dec 89.
25 * The new version has not been tried with DOS. The open modes are suspect
26 * (everyone should convert to use fcntl.h).
28 * Changed 18 Dec 92 by Kees J. Bot: Bootstrap code and geometry from device.
30 * modified 01 March 95 by asw: updated list of known partition types. Also
31 * changed display format slightly to allow for partition type names of
32 * up to 9 chars (previous format allowed for 7, but there were already
33 * some 8 char names in the list).
36 #include <sys/types.h>
37 #include <machine/partition.h>
38 #include <minix/partition.h>
39 #include <sys/ioctl.h>
50 #define DEFAULT_DEV "c:"
51 #define LOAD_OPEN_MODE 0x8000
52 #define SAVE_CREAT_MODE 0644
54 #define DEFAULT_DEV "/dev/hd0"
55 #define LOAD_OPEN_MODE 0
56 #define SAVE_CREAT_MODE 0644
57 #define UNIX /* for MINIX */
62 #define DEFAULT_NHEAD 4 /* # heads */
63 #define DEFAULT_NSEC 17 /* sectors / track */
64 #define SECSIZE 512 /* sector size */
68 #define CYL_MASK 0xc0 /* mask to extract cyl bits from sec field */
69 #define CYL_SHIFT 2 /* shift to extract cyl bits from sec field */
70 #define SEC_MASK 0x3f /* mask to extract sec bits from sec field */
73 char rawsecbuf
[SECSIZE
+ sizeof(long)];
85 int main(int argc
, char *argv
[]);
87 void getboot(char *buffer
);
88 void putboot(char *buffer
);
89 void load_from_file(void);
90 void save_to_file(void);
91 void dpl_partitions(int rawflag
);
93 void sec_to_hst(long logsec
, unsigned char *hd
, unsigned char *sec
,
95 void mark_partition(struct part_entry
*pe
);
96 void change_partition(struct part_entry
*entry
);
97 char get_a_char(void);
98 void print_menu(void);
99 void adj_base(struct part_entry
*pe
);
100 void adj_size(struct part_entry
*pe
);
101 struct part_entry
*ask_partition(void);
102 void footnotes(void);
103 int get_an_int(char *prompt
, int *intptr
);
104 void list_part_types(void);
105 void mark_npartition(struct part_entry
*pe
);
106 int mygets(char *buf
, int length
);
107 char *systype(int type
);
108 void toggle_active(struct part_entry
*pe
);
111 /* One featureful master bootstrap. */
113 0353,0001,0000,0061,0300,0216,0330,0216,0300,0372,0216,0320,0274,0000,0174,0373,
114 0275,0276,0007,0211,0346,0126,0277,0000,0006,0271,0000,0001,0374,0363,0245,0352,
115 0044,0006,0000,0000,0264,0002,0315,0026,0250,0010,0164,0033,0350,0071,0001,0174,
116 0007,0060,0344,0315,0026,0242,0205,0007,0054,0060,0074,0012,0163,0363,0120,0350,
117 0046,0001,0205,0007,0130,0353,0012,0240,0002,0006,0204,0300,0165,0003,0351,0147,
118 0000,0230,0262,0005,0366,0362,0262,0200,0000,0302,0210,0340,0120,0350,0234,0000,
119 0163,0003,0351,0147,0000,0130,0054,0001,0175,0003,0351,0141,0000,0276,0276,0175,
120 0211,0357,0271,0040,0000,0363,0245,0200,0301,0004,0211,0356,0215,0174,0020,0070,
121 0154,0004,0164,0016,0213,0135,0010,0053,0134,0010,0213,0135,0012,0033,0134,0012,
122 0163,0014,0212,0044,0206,0144,0020,0210,0044,0106,0071,0376,0162,0364,0211,0376,
123 0201,0376,0356,0007,0162,0326,0342,0322,0211,0356,0264,0020,0366,0344,0001,0306,
124 0200,0174,0004,0001,0162,0026,0353,0021,0204,0322,0175,0041,0211,0356,0200,0174,
125 0004,0000,0164,0013,0366,0004,0200,0164,0006,0350,0070,0000,0162,0053,0303,0203,
126 0306,0020,0201,0376,0376,0007,0162,0346,0350,0215,0000,0211,0007,0376,0302,0204,
127 0322,0174,0023,0315,0021,0321,0340,0321,0340,0200,0344,0003,0070,0342,0167,0355,
128 0350,0011,0000,0162,0350,0303,0350,0003,0000,0162,0146,0303,0211,0356,0214,0134,
129 0010,0214,0134,0012,0277,0003,0000,0122,0006,0127,0264,0010,0315,0023,0137,0007,
130 0200,0341,0077,0376,0306,0210,0310,0366,0346,0211,0303,0213,0104,0010,0213,0124,
131 0012,0367,0363,0222,0210,0325,0366,0361,0060,0322,0321,0352,0321,0352,0010,0342,
132 0210,0321,0376,0301,0132,0210,0306,0273,0000,0174,0270,0001,0002,0315,0023,0163,
133 0020,0200,0374,0200,0164,0011,0117,0174,0006,0060,0344,0315,0023,0163,0270,0371,
134 0303,0201,0076,0376,0175,0125,0252,0165,0001,0303,0350,0013,0000,0243,0007,0353,
135 0005,0350,0004,0000,0227,0007,0353,0376,0136,0255,0126,0211,0306,0254,0204,0300,
136 0164,0011,0264,0016,0273,0001,0000,0315,0020,0353,0362,0303,0057,0144,0145,0166,
137 0057,0150,0144,0077,0010,0000,0015,0012,0000,0116,0157,0156,0145,0040,0141,0143,
138 0164,0151,0166,0145,0015,0012,0000,0122,0145,0141,0144,0040,0145,0162,0162,0157,
139 0162,0040,0000,0116,0157,0164,0040,0142,0157,0157,0164,0141,0142,0154,0145,0040,
143 int main(int argc
, char *argv
[])
151 nhead
= DEFAULT_NHEAD
;
153 for (argn
= 1; argn
< argc
&& (argp
= argv
[argn
])[0] == '-'; ++argn
) {
155 nhead
= atoi(argp
+ 2);
157 if (argp
[1] == 's') nsec
= atoi(argp
+ 2);
164 dev_name
= DEFAULT_DEV
;
165 else if (argn
== argc
- 1)
166 dev_name
= argv
[argn
];
170 /* Align the sector buffer in such a way that the partition table is at
171 * a mod 4 offset in memory. Some weird people add alignment checks to
175 while ((long)(secbuf
+ PART_TABLE_OFF
) % sizeof(long) != 0) secbuf
++;
185 "\n(Enter 'h' for help. A null line will abort any operation) ");
189 case '+': footnotes(); break;
190 case 'a': toggle_active(ask_partition()); break;
191 case 'B': adj_base(ask_partition()); break;
192 case 'c': change_partition(ask_partition()); break;
193 case 'h': print_menu(); break;
194 case 'l': load_from_file(); break;
195 case 'm': mark_partition(ask_partition()); break;
196 case 'n': mark_npartition(ask_partition()); break;
197 case 'p': dpl_partitions(1); break;
200 case 'S': adj_size(ask_partition()); break;
201 case 's': save_to_file(); break;
202 case 't': list_part_types(); break;
204 printf("Partition table is %svalid\n",
205 chk_table() == OK
? "" : "in");
209 printf("Write disabled\n");
210 else if(chk_table() == OK
) {
213 "Partition table has been updated and the file system synced.\n");
214 printf("Please reboot now.\n");
217 printf("Not written\n");
219 default: printf(" %c ????\n", ch
); break;
230 struct part_geom geom
;
233 if (override
) return;
235 if ((fd
= open(dev_name
, O_RDONLY
)) < 0) return;
237 r
= ioctl(fd
, DIOCGETP
, &geom
);
243 ncyl
= geom
.cylinders
;
245 printf("Geometry of %s: %dx%dx%d\n", dev_name
, ncyl
, nhead
, nsec
);
250 void getboot(char *buffer
)
252 devfd
= open(dev_name
, 2);
254 printf("No write permission on %s\n", dev_name
);
256 devfd
= open(dev_name
, 0);
259 printf("Cannot open device %s\n", dev_name
);
262 if (read(devfd
, buffer
, SECSIZE
) != SECSIZE
) {
263 printf("Cannot read boot sector\n");
266 if (* (unsigned short *) &buffer
[510] != 0xAA55) {
267 printf("Invalid boot sector on %s.\n", dev_name
);
268 printf("Partition table reset and boot code installed.\n");
269 memset(buffer
, 0, 512);
270 memcpy(buffer
, bootstrap
, sizeof(bootstrap
));
271 * (unsigned short *) &buffer
[510] = 0xAA55;
275 void putboot(char *buffer
)
277 if (lseek(devfd
, 0L, 0) < 0) {
278 printf("Seek error during write\n");
281 if (write(devfd
, buffer
, SECSIZE
) != SECSIZE
) {
282 printf("Write error\n");
291 void load_from_file(void)
293 /* Load buffer from file */
298 printf("Enter name of file to load from: ");
299 if (!mygets(file
, (int) sizeof file
)) return;
300 fd
= open(file
, LOAD_OPEN_MODE
);
302 printf("Cannot open %s\n", file
);
305 if (read(fd
, secbuf
, SECSIZE
) != SECSIZE
|| close(fd
) != 0) {
306 printf("Read error\n");
309 printf("Loaded from %s OK\n", file
);
314 void save_to_file(void)
321 printf("Enter name of file to save to: ");
322 if (!mygets(file
, (int) sizeof file
)) return;
323 if(chk_table() != OK
) printf("Saving anyway\n");
324 fd
= creat(file
, SAVE_CREAT_MODE
);
327 printf("Cannot creat %s\n", file
);
331 fd
= open(file
, 0x8001);
334 printf("Cannot open %s\n", file
);
335 else if (write(fd
, secbuf
, SECSIZE
) != SECSIZE
|| close(fd
) != 0)
336 printf("Write error\n");
338 printf("Saved to %s OK\n", file
);
342 void dpl_partitions(int rawflag
)
344 /* Display partition table */
354 struct part_entry
*pe
;
355 struct part_entry
*pe1
;
364 cyl_mask
= 0; /* no contribution of cyl to sec */
367 "%2d %3d%c %4s %-9s x%02x %3d x%02x x%02x %3d x%02x %7ld%c%7ld %7ld%c\n";
372 "%2d %3d%c %4s %-9s %4d %3d %3d %4d %3d %3d %7ld%c%7ld %7ld%c\n";
375 " ----first---- -----last---- --------sectors-------\n"
378 "Num Sorted Act Type Cyl Head Sec Cyl Head Sec Base Last Size\n"
380 pe
= (struct part_entry
*) &secbuf
[PART_TABLE_OFF
];
381 for (i
= 1; i
<= NR_PARTITIONS
; i
++, pe
++) {
383 sprintf(active
, "0x%02x", pe
->bootind
);
384 sprintf(type
, "0x%02x", pe
->sysind
);
386 sprintf(active
, "%s", pe
->bootind
== ACTIVE_FLAG
? "A " : "");
387 sprintf(type
, "%s", systype(pe
->sysind
));
390 /* Prepare warnings about confusing setups from old versions. */
391 basefootnote
= orderfootnote
= sizefootnote
= ' ';
392 if (pe
->sysind
== MINIX_PART
&& pe
->lowsec
& 1) {
401 /* Calculate the "device numbers" resulting from the misguided sorting
402 * in the wini drivers. The drivers use this conditional for
403 * swapping wn[j] > wn[j+1]:
405 * if ((wn[j].wn_low == 0 && wn[j+1].wn_low != 0) ||
406 * (wn[j].wn_low > wn[j+1].wn_low && wn[j+1].wn_low != 0)) {
408 * which simplifies to:
410 * if (wn[j+1].wn_low != 0 &&
411 * (wn[j].wn_low == 0 || wn[j].wn_low > wn[j+1].wn_low)) {
414 for (i1
= 1, pe1
= (struct part_entry
*) &secbuf
[PART_TABLE_OFF
];
415 i1
<= NR_PARTITIONS
; ++i1
, ++pe1
)
416 if ((pe1
->lowsec
== 0 && pe
->lowsec
== 0 && pe1
< pe
) ||
418 (pe
->lowsec
== 0 || pe
->lowsec
> pe1
->lowsec
)))
419 ++devnum
; /* pe1 contents < pe contents */
431 pe
->start_cyl
+ ((pe
->start_sec
& cyl_mask
) << CYL_SHIFT
),
433 pe
->start_sec
& sec_mask
,
434 pe
->last_cyl
+ ((pe
->last_sec
& cyl_mask
) << CYL_SHIFT
),
436 pe
->last_sec
& sec_mask
,
439 pe
->lowsec
+ (pe
->size
== 0 ? 0 : pe
->size
- 1),
448 /* Check partition table */
451 unsigned char cylinder
;
457 struct part_entry
*pe
;
458 struct part_entry
*pe1
;
459 unsigned char sector
;
466 pe
= (struct part_entry
*) &secbuf
[PART_TABLE_OFF
];
469 for (i
= 1; i
<= NR_PARTITIONS
; i
++, ++pe
) {
470 if (pe
->bootind
== ACTIVE_FLAG
) active
++;
471 sec_to_hst(pe
->lowsec
, &head
, §or
, &cylinder
);
472 if (pe
->size
== 0 && pe
->lowsec
== 0) sector
= 0;
473 if (head
!= pe
->start_head
|| sector
!= pe
->start_sec
||
474 cylinder
!= pe
->start_cyl
) {
475 printf("Inconsistent base in partition %d.\n", i
);
476 printf("Suspect head and sector parameters.\n");
479 if (pe
->size
!= 0 || pe
->lowsec
!= 0)
480 sec_to_hst(pe
->lowsec
+ pe
->size
- 1, &head
, §or
, &cylinder
);
481 if (head
!= pe
->last_head
|| sector
!= pe
->last_sec
||
482 cylinder
!= pe
->last_cyl
) {
483 printf("Inconsistent size in partition %d.\n", i
);
484 printf("Suspect head and sector parameters.\n");
487 if (pe
->size
== 0) continue;
489 for (i1
= i
+ 1, pe1
= pe
+ 1; i1
<= NR_PARTITIONS
; ++i1
, ++pe1
) {
490 if ((pe
->lowsec
>= pe1
->lowsec
&&
491 pe
->lowsec
< pe1
->lowsec
+ pe1
->size
) ||
492 (pe
->lowsec
+ pe
->size
- 1 >= pe1
->lowsec
&&
493 pe
->lowsec
+ pe
->size
- 1 < pe1
->lowsec
+ pe1
->size
))
495 printf("Overlap between partitions %d and %d\n",
500 if (pe
->lowsec
+ pe
->size
< pe
->lowsec
) {
501 printf("Overflow from preposterous size in partition %d.\n",
505 if (maxhead
< pe
->start_head
) maxhead
= pe
->start_head
;
506 if (maxhead
< pe
->last_head
) maxhead
= pe
->last_head
;
507 if (maxsec
< (pe
->start_sec
& SEC_MASK
))
508 maxsec
= (pe
->start_sec
& SEC_MASK
);
509 if (maxsec
< (pe
->last_sec
& SEC_MASK
))
510 maxsec
= (pe
->last_sec
& SEC_MASK
);
513 if (maxhead
+ 1 != nhead
|| maxsec
!= nsec
) {
515 "Disk appears to have mis-specified number of heads or sectors.\n");
516 printf("Try fdisk -h%d -s%d %s instead of\n",
517 maxhead
+ 1, maxsec
, dev_name
);
518 printf(" fdisk -h%d -s%d %s\n", nhead
, nsec
, dev_name
);
523 "Empty table - skipping test on number of heads and sectors.\n");
524 printf("Assuming %d heads and %d sectors.\n", nhead
, nsec
);
526 if (!seenpart
) printf("Do not write the table if you are not sure!.\n");
528 printf("%d active partitions\n", active
);
534 void sec_to_hst(long logsec
, unsigned char *hd
, unsigned char *sec
,
537 /* Convert a logical sector number to head / sector / cylinder */
541 bigcyl
= logsec
/ (nhead
* nsec
);
542 *sec
= (logsec
% nsec
) + 1 + ((bigcyl
>> CYL_SHIFT
) & CYL_MASK
);
544 *hd
= (logsec
% (nhead
* nsec
)) / nsec
;
547 void mark_partition(struct part_entry
*pe
)
549 /* Mark a partition as being of type MINIX. */
552 pe
->sysind
= MINIX_PART
;
553 printf("Partition type is now MINIX\n");
557 void change_partition(struct part_entry
*entry
)
559 /* Get partition info : first & last cylinder */
565 if (entry
== NULL
) return;
567 if (!get_an_int("\tEnter first cylinder (an integer >= 0): ", &first
))
569 if (first
>= 0) break;
570 printf("\t\tThat looks like %d which is negative\n", first
);
574 "\tEnter last cylinder (an integer >= the first cylinder): ", &last
))
576 if (last
>= first
) break;
577 printf("\t\tThat looks like %d which is too small\n", last
);
579 if (first
== 0 && last
== 0) {
581 entry
->start_head
= 0;
582 entry
->start_sec
= 0;
583 entry
->start_cyl
= 0;
584 entry
->sysind
= NO_PART
;
585 entry
->last_head
= 0;
590 printf("Partition deleted\n");
593 low
= first
& 0xffff;
594 low
= low
* nsec
* nhead
;
595 if (low
== 0) low
= 1; /* sec0 is master boot record */
596 high
= last
& 0xffff;
597 high
= (high
+ 1) * nsec
* nhead
- 1;
599 entry
->size
= high
- low
+ 1;
600 if (entry
->size
& 1) {
601 /* Adjust size to even since Minix works with blocks of 2 sectors. */
604 printf("Size reduced by 1 to make it even\n");
606 sec_to_hst(low
, &entry
->start_head
, &entry
->start_sec
, &entry
->start_cyl
);
607 sec_to_hst(high
, &entry
->last_head
, &entry
->last_sec
, &entry
->last_cyl
);
608 printf("Base of partition changed to %u, size changed to %u\n",
609 entry
->lowsec
, entry
->size
);
611 /* Accept the MINIX partition type. Usually ignore foreign types, so this
612 * fdisk can be used on foreign partitions. Don't allow NO_PART, because
613 * many DOS fdisks crash on it.
615 if (entry
->sysind
== NO_PART
) {
616 entry
->sysind
= MINIX_PART
;
617 printf("Partition type changed from None to MINIX\n");
618 } else if (entry
->sysind
== MINIX_PART
)
619 printf("Leaving partition type as MINIX\n");
621 printf("\tChange partition type from %s to MINIX? (y/n) ",
622 systype(entry
->sysind
));
624 if (ch
== 0 || ch
== 'n') {
625 printf("Leaving partition type as %s\n",
626 systype(entry
->sysind
));
628 } else if (ch
== 'y') {
629 entry
->sysind
= MINIX_PART
;
630 printf("Partition type changed from %s to MINIX\n",
631 systype(entry
->sysind
));
636 if (entry
->bootind
== ACTIVE_FLAG
)
637 printf("Leaving partition active\n");
639 printf("\tChange partition to active? (y/n) ");
641 if (ch
== 0 || ch
== 'n') {
642 printf("Leaving partition inactive\n");
644 } else if (ch
== 'y') {
645 toggle_active(entry
);
651 char get_a_char(void)
653 /* Read 1 character and discard rest of line */
657 if (!mygets(buf
, (int) sizeof buf
)) return(0);
661 void print_menu(void)
663 printf("Type a command letter, then a carriage return:\n");
664 printf(" + - explain any footnotes (+, -, #)\n");
665 printf(" a - toggle an active flag\n");
666 printf(" B - adjust a base sector\n");
667 printf(" c - change a partition\n");
668 printf(" l - load boot block (including partition table) from a file\n");
669 printf(" m - mark a partition as a MINIX partition\n");
670 printf(" n - mark a partition as a non-MINIX partition\n");
671 printf(" p - print raw partition table\n");
672 printf(" q - quit without making any changes\n");
673 printf(" S - adjust a size (by changing the last sector)\n");
674 printf(" s - save boot block (including partition table) on a file\n");
675 printf(" t - print known partition types\n");
676 printf(" v - verify partition table\n");
678 printf(" w - write (disabled)\n");
680 printf(" w - write changed partition table back to disk and exit\n");
684 /* Here are the DOS routines for reading and writing the boot sector. */
692 void getboot(char *buffer
)
694 /* Read boot sector */
696 segread(&sregs
); /* get ds */
698 if (dev_name
[1] != ':') {
699 printf("Invalid drive %s\n", dev_name
);
702 if (*dev_name
>= 'a') *dev_name
+= 'A' - 'a';
703 drivenum
= (*dev_name
- 'C') & 0xff;
704 if (drivenum
< 0 || drivenum
> 7) {
705 printf("Funny drive number %d\n", drivenum
);
708 regs
.x
.ax
= 0x201; /* read 1 sectors */
709 regs
.h
.ch
= 0; /* cylinder */
710 regs
.h
.cl
= 1; /* first sector = 1 */
711 regs
.h
.dh
= 0; /* head = 0 */
712 regs
.h
.dl
= 0x80 + drivenum
; /* drive = 0 */
713 sregs
.es
= sregs
.ds
; /* buffer address */
714 regs
.x
.bx
= (int) buffer
;
716 int86x(0x13, ®s
, ®s
, &sregs
);
718 printf("Cannot read boot sector\n");
724 void putboot(char *buffer
)
726 /* Write boot sector */
728 regs
.x
.ax
= 0x301; /* read 1 sectors */
729 regs
.h
.ch
= 0; /* cylinder */
730 regs
.h
.cl
= 1; /* first sector = 1 */
731 regs
.h
.dh
= 0; /* head = 0 */
732 regs
.h
.dl
= 0x80 + drivenum
; /* drive = 0 */
733 sregs
.es
= sregs
.ds
; /* buffer address */
734 regs
.x
.bx
= (int) buffer
;
736 int86x(0x13, ®s
, ®s
, &sregs
);
738 printf("Cannot write boot sector\n");
745 void adj_base(struct part_entry
*pe
)
747 /* Adjust base sector of partition, usually to make it even. */
751 if (pe
== NULL
) return;
754 if (!get_an_int("\tEnter adjustment to base (an integer): ", &adj
))
756 if (pe
->lowsec
+ adj
< 1)
758 "\t\tThat would make the base %u and too small\n", pe
->lowsec
+ adj
);
759 else if (pe
->size
- adj
< 1)
761 "\t\tThat would make the size %u and too small\n", pe
->size
- adj
);
767 sec_to_hst(pe
->lowsec
, &pe
->start_head
, &pe
->start_sec
, &pe
->start_cyl
);
768 printf("Base of partition adjusted to %u, size adjusted to %u\n",
769 pe
->lowsec
, pe
->size
);
772 void adj_size(struct part_entry
*pe
)
774 /* Adjust size of partition by reducing high sector. */
778 if (pe
== NULL
) return;
780 if (!get_an_int("\tEnter adjustment to size (an integer): ", &adj
))
782 if (pe
->size
+ adj
>= 1) break;
783 printf("\t\tThat would make the size %u and too small \n",
787 sec_to_hst(pe
->lowsec
+ pe
->size
- 1,
788 &pe
->last_head
, &pe
->last_sec
, &pe
->last_cyl
);
789 printf("Size of partition adjusted to %u\n", pe
->size
);
792 struct part_entry
*ask_partition()
794 /* Ask for a valid partition number and return its entry. */
800 if (!get_an_int("Enter partition number (1 to 4): ", &num
))
802 if (num
>= 1 && num
<= NR_PARTITIONS
) break;
803 printf("\tThat does not look like 1 to 4\n");
805 printf("Partition %d\n", num
);
806 return((struct part_entry
*) &secbuf
[PART_TABLE_OFF
] + (num
- 1));
811 /* Explain the footnotes. */
815 "+ The old Minix wini drivers (before V1.5) discarded odd base sectors.\n");
817 " This causes some old (Minix) file systems to be offset by 1 sector.\n");
819 " To use these with the new drivers, increase the base by 1 using 'B'.\n");
823 if (badbases
!= 0) putchar('\n');
825 "- Minix cannot access the last sector on an odd-sized partition. This\n");
827 " causes trouble for programs like dosread. This program will by default\n");
829 " only create partitions with even sizes. If possible, the current odd\n");
831 " sizes should be decreased by 1 using 'S'. This is safe for all Minix\n");
833 " partitions, and may be safe for other partitions which are about to be\n");
838 if (badorders
!= 0 ) {
839 if (badbases
!= 0 || badsizes
!= 0) putchar('\n');
841 "# The partitions are in a funny order. This is normal if they were created\n");
843 " by DOS fdisks prior to DOS 3.3. The Minix wini drivers further confuse\n");
845 " the order by sorting the partitions on their base. Be careful if the\n");
847 " device numbers of unchanged partitions have changed.\n");
851 int get_an_int(char *prompt
, int *intptr
)
853 /* Read an int from the start of line of stdin, discard rest of line. */
858 printf("%s", prompt
);
859 if (!mygets(buf
, (int) sizeof buf
)) return(0);
860 if ((sscanf(buf
, "%d", intptr
)) == 1) return(1);
861 printf("\t\tThat does not look like an integer\n");
865 void list_part_types(void)
867 /* Print all known partition types. */
872 for (column
= 0, type
= 0; type
< 0x100; ++type
)
873 if (strcmp(systype(type
), "Unknown") != 0) {
874 printf("0x%02x: %-9s", type
, systype(type
));
883 if (column
!= 0) putchar('\n');
886 void mark_npartition(struct part_entry
*pe
)
888 /* Mark a partition with arbitrary type. */
893 if (pe
== NULL
) return;
894 printf("\nKnown partition types are:\n\n");
897 printf("\nEnter partition type (in 2-digit hex): ");
898 if (!mygets(buf
, (int) sizeof buf
)) return;
899 if (sscanf(buf
, "%x", &type
) != 1)
900 printf("Invalid hex number\n");
901 else if (type
>= 0x100)
902 printf("Hex number too large\n");
907 printf("Partition type changed to 0x%02x (%s)\n", type
, systype(type
));
910 int mygets(char *buf
, int length
)
912 /* Get a non-empty line of maximum length 'length'. */
916 if (fgets(buf
, length
, stdin
) == NULL
) {
920 if (strrchr(buf
, '\n') != NULL
) *strrchr(buf
, '\n') = 0;
921 if (*buf
!= 0) return(1);
922 printf("Use the EOF character to create a null line.\n");
923 printf("Otherwise, please type something before the newline: ");
927 char *systype(int type
)
929 /* Convert system indicator into system name. */
930 /* asw 01.03.95: added types based on info in kjb's part.c and output
931 * from Linux (1.0.8) fdisk. Note comments here, there are disagreements.
936 case 1: return("DOS-12");
937 case 2: return("XENIX");
938 case 3: return("XENIX usr");
939 case 4: return("DOS-16");
940 case 5: return("DOS-EXT");
941 case 6: return("DOS-BIG");
942 case 7: return("HPFS");
943 case 8: return("AIX");
944 case 9: return("COHERENT"); /* LINUX says AIX bootable */
945 case 0x0a: return("OS/2"); /* LINUX says OPUS */
946 case 0x10: return("OPUS");
947 case 0x40: return("VENIX286");
948 case 0x51: return("NOVELL?");
949 case 0x52: return("MICROPORT");
950 case 0x63: return("386/IX"); /*LINUX calls this GNU HURD */
951 case 0x64: return("NOVELL286");
952 case 0x65: return("NOVELL386");
953 case 0x75: return("PC/IX");
954 case 0x80: return("MINIX old");
955 case 0x81: return("MINIX");
956 case 0x82: return("LINUXswap");
957 case 0x83: return("LINUX");
958 case 0x93: return("AMOEBA");
959 case 0x94: return("AMOEBAbad");
960 case 0xa5: return("386BSD");
961 case 0xb7: return("BSDI");
962 case 0xb8: return("BSDIswap");
963 case 0xc7: return("Syrinx");
964 case 0xDB: return("CP/M");
965 case 0xe1: return("DOS acc");
966 case 0xe3: return("DOS r/o");
967 case 0xf2: return("DOS 2ary");
968 case 0xFF: return("Badblocks");
969 default: return("Unknown");
973 void toggle_active(struct part_entry
*pe
)
975 /* Toggle active flag of a partition. */
977 if (pe
== NULL
) return;
978 pe
->bootind
= (pe
->bootind
== ACTIVE_FLAG
) ? 0 : ACTIVE_FLAG
;
979 printf("Partition changed to %sactive\n", pe
->bootind
? "" : "in");
984 /* Print usage message and exit. */
986 printf("Usage: fdisk [-hheads] [-ssectors] [device]\n");