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 int getboot(char *buffer
);
88 int putboot(char *buffer
);
89 void load_from_file(void);
90 void save_to_file(void);
91 int dpl_partitions(int rawflag
);
93 int sec_to_hst(long logsec
, unsigned char *hd
, unsigned char *sec
,
95 int mark_partition(struct part_entry
*pe
);
96 void change_partition(struct part_entry
*entry
);
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,
153 nhead
= DEFAULT_NHEAD
;
155 for (argn
= 1; argn
< argc
&& (argp
= argv
[argn
])[0] == '-'; ++argn
) {
157 nhead
= atoi(argp
+ 2);
159 if (argp
[1] == 's') nsec
= atoi(argp
+ 2);
166 devname
= DEFAULT_DEV
;
167 else if (argn
== argc
- 1)
168 devname
= argv
[argn
];
172 /* Align the sector buffer in such a way that the partition table is at
173 * a mod 4 offset in memory. Some weird people add alignment checks to
177 while ((long)(secbuf
+ PART_TABLE_OFF
) % sizeof(long) != 0) secbuf
++;
187 "\n(Enter 'h' for help. A null line will abort any operation) ");
191 case '+': footnotes(); break;
192 case 'a': toggle_active(ask_partition()); break;
193 case 'B': adj_base(ask_partition()); break;
194 case 'c': change_partition(ask_partition()); break;
195 case 'h': print_menu(); break;
196 case 'l': load_from_file(); break;
197 case 'm': mark_partition(ask_partition()); break;
198 case 'n': mark_npartition(ask_partition()); break;
199 case 'p': dpl_partitions(1); break;
202 case 'S': adj_size(ask_partition()); break;
203 case 's': save_to_file(); break;
204 case 't': list_part_types(); break;
206 printf("Partition table is %svalid\n",
207 chk_table() == OK
? "" : "in");
211 printf("Write disabled\n");
212 else if(chk_table() == OK
) {
215 "Partition table has been updated and the file system synced.\n");
216 printf("Please reboot now.\n");
219 printf("Not written\n");
221 default: printf(" %c ????\n", ch
); break;
232 struct partition geom
;
235 if (override
) return;
237 if ((fd
= open(devname
, O_RDONLY
)) < 0) return;
239 r
= ioctl(fd
, DIOCGETP
, &geom
);
245 ncyl
= geom
.cylinders
;
247 printf("Geometry of %s: %dx%dx%d\n", devname
, ncyl
, nhead
, nsec
);
255 devfd
= open(devname
, 2);
257 printf("No write permission on %s\n", devname
);
259 devfd
= open(devname
, 0);
262 printf("Cannot open device %s\n", devname
);
265 if (read(devfd
, buffer
, SECSIZE
) != SECSIZE
) {
266 printf("Cannot read boot sector\n");
269 if (* (unsigned short *) &buffer
[510] != 0xAA55) {
270 printf("Invalid boot sector on %s.\n", devname
);
271 printf("Partition table reset and boot code installed.\n");
272 memset(buffer
, 0, 512);
273 memcpy(buffer
, bootstrap
, sizeof(bootstrap
));
274 * (unsigned short *) &buffer
[510] = 0xAA55;
281 if (lseek(devfd
, 0L, 0) < 0) {
282 printf("Seek error during write\n");
285 if (write(devfd
, buffer
, SECSIZE
) != SECSIZE
) {
286 printf("Write error\n");
295 void load_from_file()
297 /* Load buffer from file */
302 printf("Enter name of file to load from: ");
303 if (!mygets(file
, (int) sizeof file
)) return;
304 fd
= open(file
, LOAD_OPEN_MODE
);
306 printf("Cannot open %s\n", file
);
309 if (read(fd
, secbuf
, SECSIZE
) != SECSIZE
|| close(fd
) != 0) {
310 printf("Read error\n");
313 printf("Loaded from %s OK\n", file
);
325 printf("Enter name of file to save to: ");
326 if (!mygets(file
, (int) sizeof file
)) return;
327 if(chk_table() != OK
) printf("Saving anyway\n");
328 fd
= creat(file
, SAVE_CREAT_MODE
);
331 printf("Cannot creat %s\n", file
);
335 fd
= open(file
, 0x8001);
338 printf("Cannot open %s\n", file
);
339 else if (write(fd
, secbuf
, SECSIZE
) != SECSIZE
|| close(fd
) != 0)
340 printf("Write error\n");
342 printf("Saved to %s OK\n", file
);
346 dpl_partitions(rawflag
)
349 /* Display partition table */
359 struct part_entry
*pe
;
360 struct part_entry
*pe1
;
369 cyl_mask
= 0; /* no contribution of cyl to sec */
372 "%2d %3d%c %4s %-9s x%02x %3d x%02x x%02x %3d x%02x %7ld%c%7ld %7ld%c\n";
377 "%2d %3d%c %4s %-9s %4d %3d %3d %4d %3d %3d %7ld%c%7ld %7ld%c\n";
380 " ----first---- -----last---- --------sectors-------\n"
383 "Num Sorted Act Type Cyl Head Sec Cyl Head Sec Base Last Size\n"
385 pe
= (struct part_entry
*) &secbuf
[PART_TABLE_OFF
];
386 for (i
= 1; i
<= NR_PARTITIONS
; i
++, pe
++) {
388 sprintf(active
, "0x%02x", pe
->bootind
);
389 sprintf(type
, "0x%02x", pe
->sysind
);
391 sprintf(active
, "%s", pe
->bootind
== ACTIVE_FLAG
? "A " : "");
392 sprintf(type
, "%s", systype(pe
->sysind
));
395 /* Prepare warnings about confusing setups from old versions. */
396 basefootnote
= orderfootnote
= sizefootnote
= ' ';
397 if (pe
->sysind
== MINIX_PART
&& pe
->lowsec
& 1) {
406 /* Calculate the "device numbers" resulting from the misguided sorting
407 * in the wini drivers. The drivers use this conditional for
408 * swapping wn[j] > wn[j+1]:
410 * if ((wn[j].wn_low == 0 && wn[j+1].wn_low != 0) ||
411 * (wn[j].wn_low > wn[j+1].wn_low && wn[j+1].wn_low != 0)) {
413 * which simplifies to:
415 * if (wn[j+1].wn_low != 0 &&
416 * (wn[j].wn_low == 0 || wn[j].wn_low > wn[j+1].wn_low)) {
419 for (i1
= 1, pe1
= (struct part_entry
*) &secbuf
[PART_TABLE_OFF
];
420 i1
<= NR_PARTITIONS
; ++i1
, ++pe1
)
421 if (pe1
->lowsec
== 0 && pe
->lowsec
== 0 && pe1
< pe
||
423 (pe
->lowsec
== 0 || pe
->lowsec
> pe1
->lowsec
))
424 ++devnum
; /* pe1 contents < pe contents */
436 pe
->start_cyl
+ ((pe
->start_sec
& cyl_mask
) << CYL_SHIFT
),
438 pe
->start_sec
& sec_mask
,
439 pe
->last_cyl
+ ((pe
->last_sec
& cyl_mask
) << CYL_SHIFT
),
441 pe
->last_sec
& sec_mask
,
444 pe
->lowsec
+ (pe
->size
== 0 ? 0 : pe
->size
- 1),
453 /* Check partition table */
456 unsigned char cylinder
;
462 struct part_entry
*pe
;
463 struct part_entry
*pe1
;
464 unsigned char sector
;
471 pe
= (struct part_entry
*) &secbuf
[PART_TABLE_OFF
];
474 for (i
= 1; i
<= NR_PARTITIONS
; i
++, ++pe
) {
475 if (pe
->bootind
== ACTIVE_FLAG
) active
++;
476 sec_to_hst(pe
->lowsec
, &head
, §or
, &cylinder
);
477 if (pe
->size
== 0 && pe
->lowsec
== 0) sector
= 0;
478 if (head
!= pe
->start_head
|| sector
!= pe
->start_sec
||
479 cylinder
!= pe
->start_cyl
) {
480 printf("Inconsistent base in partition %d.\n", i
);
481 printf("Suspect head and sector parameters.\n");
484 if (pe
->size
!= 0 || pe
->lowsec
!= 0)
485 sec_to_hst(pe
->lowsec
+ pe
->size
- 1, &head
, §or
, &cylinder
);
486 if (head
!= pe
->last_head
|| sector
!= pe
->last_sec
||
487 cylinder
!= pe
->last_cyl
) {
488 printf("Inconsistent size in partition %d.\n", i
);
489 printf("Suspect head and sector parameters.\n");
492 if (pe
->size
== 0) continue;
494 for (i1
= i
+ 1, pe1
= pe
+ 1; i1
<= NR_PARTITIONS
; ++i1
, ++pe1
) {
495 if (pe
->lowsec
>= pe1
->lowsec
&&
496 pe
->lowsec
< pe1
->lowsec
+ pe1
->size
||
497 pe
->lowsec
+ pe
->size
- 1 >= pe1
->lowsec
&&
498 pe
->lowsec
+ pe
->size
- 1 < pe1
->lowsec
+ pe1
->size
)
500 printf("Overlap between partitions %d and %d\n",
505 if (pe
->lowsec
+ pe
->size
< pe
->lowsec
) {
506 printf("Overflow from preposterous size in partition %d.\n",
510 if (maxhead
< pe
->start_head
) maxhead
= pe
->start_head
;
511 if (maxhead
< pe
->last_head
) maxhead
= pe
->last_head
;
512 if (maxsec
< (pe
->start_sec
& SEC_MASK
))
513 maxsec
= (pe
->start_sec
& SEC_MASK
);
514 if (maxsec
< (pe
->last_sec
& SEC_MASK
))
515 maxsec
= (pe
->last_sec
& SEC_MASK
);
518 if (maxhead
+ 1 != nhead
|| maxsec
!= nsec
) {
520 "Disk appears to have mis-specified number of heads or sectors.\n");
521 printf("Try fdisk -h%d -s%d %s instead of\n",
522 maxhead
+ 1, maxsec
, devname
);
523 printf(" fdisk -h%d -s%d %s\n", nhead
, nsec
, devname
);
528 "Empty table - skipping test on number of heads and sectors.\n");
529 printf("Assuming %d heads and %d sectors.\n", nhead
, nsec
);
531 if (!seenpart
) printf("Do not write the table if you are not sure!.\n");
533 printf("%d active partitions\n", active
);
539 sec_to_hst(logsec
, hd
, sec
, cyl
)
541 unsigned char *hd
, *sec
, *cyl
;
543 /* Convert a logical sector number to head / sector / cylinder */
547 bigcyl
= logsec
/ (nhead
* nsec
);
548 *sec
= (logsec
% nsec
) + 1 + ((bigcyl
>> CYL_SHIFT
) & CYL_MASK
);
550 *hd
= (logsec
% (nhead
* nsec
)) / nsec
;
554 struct part_entry
*pe
;
556 /* Mark a partition as being of type MINIX. */
559 pe
->sysind
= MINIX_PART
;
560 printf("Partition type is now MINIX\n");
564 void change_partition(entry
)
565 struct part_entry
*entry
;
567 /* Get partition info : first & last cylinder */
573 if (entry
== NULL
) return;
575 if (!get_an_int("\tEnter first cylinder (an integer >= 0): ", &first
))
577 if (first
>= 0) break;
578 printf("\t\tThat looks like %d which is negative\n", first
);
582 "\tEnter last cylinder (an integer >= the first cylinder): ", &last
))
584 if (last
>= first
) break;
585 printf("\t\tThat looks like %d which is too small\n", last
);
587 if (first
== 0 && last
== 0) {
589 entry
->start_head
= 0;
590 entry
->start_sec
= 0;
591 entry
->start_cyl
= 0;
592 entry
->sysind
= NO_PART
;
593 entry
->last_head
= 0;
598 printf("Partition deleted\n");
601 low
= first
& 0xffff;
602 low
= low
* nsec
* nhead
;
603 if (low
== 0) low
= 1; /* sec0 is master boot record */
604 high
= last
& 0xffff;
605 high
= (high
+ 1) * nsec
* nhead
- 1;
607 entry
->size
= high
- low
+ 1;
608 if (entry
->size
& 1) {
609 /* Adjust size to even since Minix works with blocks of 2 sectors. */
612 printf("Size reduced by 1 to make it even\n");
614 sec_to_hst(low
, &entry
->start_head
, &entry
->start_sec
, &entry
->start_cyl
);
615 sec_to_hst(high
, &entry
->last_head
, &entry
->last_sec
, &entry
->last_cyl
);
616 printf("Base of partition changed to %ld, size changed to %ld\n",
617 entry
->lowsec
, entry
->size
);
619 /* Accept the MINIX partition type. Usually ignore foreign types, so this
620 * fdisk can be used on foreign partitions. Don't allow NO_PART, because
621 * many DOS fdisks crash on it.
623 if (entry
->sysind
== NO_PART
) {
624 entry
->sysind
= MINIX_PART
;
625 printf("Partition type changed from None to MINIX\n");
626 } else if (entry
->sysind
== MINIX_PART
)
627 printf("Leaving partition type as MINIX\n");
629 printf("\tChange partition type from %s to MINIX? (y/n) ",
630 systype(entry
->sysind
));
632 if (ch
== 0 || ch
== 'n') {
633 printf("Leaving partition type as %s\n",
634 systype(entry
->sysind
));
636 } else if (ch
== 'y') {
637 entry
->sysind
= MINIX_PART
;
638 printf("Partition type changed from %s to MINIX\n",
639 systype(entry
->sysind
));
644 if (entry
->bootind
== ACTIVE_FLAG
)
645 printf("Leaving partition active\n");
647 printf("\tChange partition to active? (y/n) ");
649 if (ch
== 0 || ch
== 'n') {
650 printf("Leaving partition inactive\n");
652 } else if (ch
== 'y') {
653 toggle_active(entry
);
661 /* Read 1 character and discard rest of line */
666 if (!mygets(buf
, (int) sizeof buf
)) return(0);
672 printf("Type a command letter, then a carriage return:\n");
673 printf(" + - explain any footnotes (+, -, #)\n");
674 printf(" a - toggle an active flag\n");
675 printf(" B - adjust a base sector\n");
676 printf(" c - change a partition\n");
677 printf(" l - load boot block (including partition table) from a file\n");
678 printf(" m - mark a partition as a MINIX partition\n");
679 printf(" n - mark a partition as a non-MINIX partition\n");
680 printf(" p - print raw partition table\n");
681 printf(" q - quit without making any changes\n");
682 printf(" S - adjust a size (by changing the last sector)\n");
683 printf(" s - save boot block (including partition table) on a file\n");
684 printf(" t - print known partition types\n");
685 printf(" v - verify partition table\n");
687 printf(" w - write (disabled)\n");
689 printf(" w - write changed partition table back to disk and exit\n");
693 /* Here are the DOS routines for reading and writing the boot sector. */
704 /* Read boot sector */
706 segread(&sregs
); /* get ds */
708 if (devname
[1] != ':') {
709 printf("Invalid drive %s\n", devname
);
712 if (*devname
>= 'a') *devname
+= 'A' - 'a';
713 drivenum
= (*devname
- 'C') & 0xff;
714 if (drivenum
< 0 || drivenum
> 7) {
715 printf("Funny drive number %d\n", drivenum
);
718 regs
.x
.ax
= 0x201; /* read 1 sectors */
719 regs
.h
.ch
= 0; /* cylinder */
720 regs
.h
.cl
= 1; /* first sector = 1 */
721 regs
.h
.dh
= 0; /* head = 0 */
722 regs
.h
.dl
= 0x80 + drivenum
; /* drive = 0 */
723 sregs
.es
= sregs
.ds
; /* buffer address */
724 regs
.x
.bx
= (int) buffer
;
726 int86x(0x13, ®s
, ®s
, &sregs
);
728 printf("Cannot read boot sector\n");
737 /* Write boot sector */
739 regs
.x
.ax
= 0x301; /* read 1 sectors */
740 regs
.h
.ch
= 0; /* cylinder */
741 regs
.h
.cl
= 1; /* first sector = 1 */
742 regs
.h
.dh
= 0; /* head = 0 */
743 regs
.h
.dl
= 0x80 + drivenum
; /* drive = 0 */
744 sregs
.es
= sregs
.ds
; /* buffer address */
745 regs
.x
.bx
= (int) buffer
;
747 int86x(0x13, ®s
, ®s
, &sregs
);
749 printf("Cannot write boot sector\n");
757 struct part_entry
*pe
;
759 /* Adjust base sector of partition, usually to make it even. */
763 if (pe
== NULL
) return;
766 if (!get_an_int("\tEnter adjustment to base (an integer): ", &adj
))
768 if (pe
->lowsec
+ adj
< 1)
770 "\t\tThat would make the base %d and too small\n", pe
->lowsec
+ adj
);
771 else if (pe
->size
- adj
< 1)
773 "\t\tThat would make the size %d and too small\n", pe
->size
- adj
);
779 sec_to_hst(pe
->lowsec
, &pe
->start_head
, &pe
->start_sec
, &pe
->start_cyl
);
780 printf("Base of partition adjusted to %ld, size adjusted to %ld\n",
781 pe
->lowsec
, pe
->size
);
785 struct part_entry
*pe
;
787 /* Adjust size of partition by reducing high sector. */
791 if (pe
== NULL
) return;
793 if (!get_an_int("\tEnter adjustment to size (an integer): ", &adj
))
795 if (pe
->size
+ adj
>= 1) break;
796 printf("\t\tThat would make the size %d and too small \n",
800 sec_to_hst(pe
->lowsec
+ pe
->size
- 1,
801 &pe
->last_head
, &pe
->last_sec
, &pe
->last_cyl
);
802 printf("Size of partition adjusted to %ld\n", pe
->size
);
805 struct part_entry
*ask_partition()
807 /* Ask for a valid partition number and return its entry. */
813 if (!get_an_int("Enter partition number (1 to 4): ", &num
))
815 if (num
>= 1 && num
<= NR_PARTITIONS
) break;
816 printf("\tThat does not look like 1 to 4\n");
818 printf("Partition %d\n", num
);
819 return((struct part_entry
*) &secbuf
[PART_TABLE_OFF
] + (num
- 1));
824 /* Explain the footnotes. */
828 "+ The old Minix wini drivers (before V1.5) discarded odd base sectors.\n");
830 " This causes some old (Minix) file systems to be offset by 1 sector.\n");
832 " To use these with the new drivers, increase the base by 1 using 'B'.\n");
836 if (badbases
!= 0) putchar('\n');
838 "- Minix cannot access the last sector on an odd-sized partition. This\n");
840 " causes trouble for programs like dosread. This program will by default\n");
842 " only create partitions with even sizes. If possible, the current odd\n");
844 " sizes should be decreased by 1 using 'S'. This is safe for all Minix\n");
846 " partitions, and may be safe for other partitions which are about to be\n");
851 if (badorders
!= 0 ) {
852 if (badbases
!= 0 || badsizes
!= 0) putchar('\n');
854 "# The partitions are in a funny order. This is normal if they were created\n");
856 " by DOS fdisks prior to DOS 3.3. The Minix wini drivers further confuse\n");
858 " the order by sorting the partitions on their base. Be careful if the\n");
860 " device numbers of unchanged partitions have changed.\n");
864 int get_an_int(prompt
, intptr
)
868 /* Read an int from the start of line of stdin, discard rest of line. */
873 printf("%s", prompt
);
874 if (!mygets(buf
, (int) sizeof buf
)) return(0);
875 if ((sscanf(buf
, "%d", intptr
)) == 1) return(1);
876 printf("\t\tThat does not look like an integer\n");
880 void list_part_types()
882 /* Print all known partition types. */
887 for (column
= 0, type
= 0; type
< 0x100; ++type
)
888 if (strcmp(systype(type
), "Unknown") != 0) {
889 printf("0x%02x: %-9s", type
, systype(type
));
898 if (column
!= 0) putchar('\n');
901 void mark_npartition(pe
)
902 struct part_entry
*pe
;
904 /* Mark a partition with arbitrary type. */
909 if (pe
== NULL
) return;
910 printf("\nKnown partition types are:\n\n");
913 printf("\nEnter partition type (in 2-digit hex): ");
914 if (!mygets(buf
, (int) sizeof buf
)) return;
915 if (sscanf(buf
, "%x", &type
) != 1)
916 printf("Invalid hex number\n");
917 else if (type
>= 0x100)
918 printf("Hex number too large\n");
923 printf("Partition type changed to 0x%02x (%s)\n", type
, systype(type
));
926 int mygets(buf
, length
)
928 int length
; /* as for fgets(), but must be >= 2 */
930 /* Get a non-empty line of maximum length 'length'. */
934 if (fgets(buf
, length
, stdin
) == NULL
) {
938 if (strrchr(buf
, '\n') != NULL
) *strrchr(buf
, '\n') = 0;
939 if (*buf
!= 0) return(1);
940 printf("Use the EOF character to create a null line.\n");
941 printf("Otherwise, please type something before the newline: ");
948 /* Convert system indicator into system name. */
949 /* asw 01.03.95: added types based on info in kjb's part.c and output
950 * from Linux (1.0.8) fdisk. Note comments here, there are disagreements.
955 case 1: return("DOS-12");
956 case 2: return("XENIX");
957 case 3: return("XENIX usr");
958 case 4: return("DOS-16");
959 case 5: return("DOS-EXT");
960 case 6: return("DOS-BIG");
961 case 7: return("HPFS");
962 case 8: return("AIX");
963 case 9: return("COHERENT"); /* LINUX says AIX bootable */
964 case 0x0a: return("OS/2"); /* LINUX says OPUS */
965 case 0x10: return("OPUS");
966 case 0x40: return("VENIX286");
967 case 0x51: return("NOVELL?");
968 case 0x52: return("MICROPORT");
969 case 0x63: return("386/IX"); /*LINUX calls this GNU HURD */
970 case 0x64: return("NOVELL286");
971 case 0x65: return("NOVELL386");
972 case 0x75: return("PC/IX");
973 case 0x80: return("MINIX old");
974 case 0x81: return("MINIX");
975 case 0x82: return("LINUXswap");
976 case 0x83: return("LINUX");
977 case 0x93: return("AMOEBA");
978 case 0x94: return("AMOEBAbad");
979 case 0xa5: return("386BSD");
980 case 0xb7: return("BSDI");
981 case 0xb8: return("BSDIswap");
982 case 0xc7: return("Syrinx");
983 case 0xDB: return("CP/M");
984 case 0xe1: return("DOS acc");
985 case 0xe3: return("DOS r/o");
986 case 0xf2: return("DOS 2ary");
987 case 0xFF: return("Badblocks");
988 default: return("Unknown");
992 void toggle_active(pe
)
993 struct part_entry
*pe
;
995 /* Toggle active flag of a partition. */
997 if (pe
== NULL
) return;
998 pe
->bootind
= (pe
->bootind
== ACTIVE_FLAG
) ? 0 : ACTIVE_FLAG
;
999 printf("Partition changed to %sactive\n", pe
->bootind
? "" : "in");
1004 /* Print usage message and exit. */
1006 printf("Usage: fdisk [-hheads] [-ssectors] [device]\n");