aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-02-25 03:46:10 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-02-25 03:46:10 +0000
commitae90983e5cd321a5ed0f1f05eede76af5a6b5590 (patch)
tree909a98a03b8c1223eb5338c3073ea82d8f7fc5a2
parentf00205b43697b870a199bce2b5a47b89913767ab (diff)
downloadbusybox-w32-ae90983e5cd321a5ed0f1f05eede76af5a6b5590.tar.gz
busybox-w32-ae90983e5cd321a5ed0f1f05eede76af5a6b5590.tar.bz2
busybox-w32-ae90983e5cd321a5ed0f1f05eede76af5a6b5590.zip
Another clean-up patch from Garrett.
git-svn-id: svn://busybox.net/trunk/busybox@14267 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--util-linux/fdisk.c257
1 files changed, 120 insertions, 137 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index a64515598..5d1b75b89 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -115,30 +115,10 @@ static char MBRbuffer[MAX_SECTOR_SIZE];
115# define MBRbuffer bb_common_bufsiz1 115# define MBRbuffer bb_common_bufsiz1
116#endif 116#endif
117 117
118#ifdef CONFIG_FEATURE_SUN_LABEL
119static int sun_label; /* looking at sun disklabel */
120#else
121#define sun_label 0
122#endif
123#ifdef CONFIG_FEATURE_SGI_LABEL
124static int sgi_label; /* looking at sgi disklabel */
125#else
126#define sgi_label 0
127#endif
128#ifdef CONFIG_FEATURE_AIX_LABEL
129static int aix_label; /* looking at aix disklabel */
130#else
131#define aix_label 0
132#endif
133#ifdef CONFIG_FEATURE_OSF_LABEL 118#ifdef CONFIG_FEATURE_OSF_LABEL
134static int osf_label; /* looking at OSF/1 disklabel */
135static int possibly_osf_label; 119static int possibly_osf_label;
136#else
137#define osf_label 0
138#endif 120#endif
139 121
140#define dos_label (!sun_label && !sgi_label && !aix_label && !osf_label)
141
142static uint heads, sectors, cylinders; 122static uint heads, sectors, cylinders;
143static void update_units(void); 123static void update_units(void);
144 124
@@ -200,8 +180,14 @@ enum failure {
200 unable_to_write 180 unable_to_write
201}; 181};
202 182
183enum label_type{
184 label_dos, label_sun, label_sgi, label_aix, label_osf
185};
186
203enum action { fdisk, require, try_only, create_empty_dos, create_empty_sun }; 187enum action { fdisk, require, try_only, create_empty_dos, create_empty_sun };
204 188
189static enum label_type current_label_type;
190
205static const char *disk_device; 191static const char *disk_device;
206static int fd; /* the disk */ 192static int fd; /* the disk */
207static int partitions = 4; /* maximum partition + 1 */ 193static int partitions = 4; /* maximum partition + 1 */
@@ -432,33 +418,23 @@ aix_info(void)
432 ); 418 );
433} 419}
434 420
435static void
436aix_nolabel(void)
437{
438 aixlabel->magic = 0;
439 aix_label = 0;
440 partitions = 4;
441 memset(MBRbuffer, 0, sizeof(MBRbuffer)); /* avoid fdisk cores */
442 return;
443}
444
445static int 421static int
446check_aix_label(void) 422check_aix_label(void)
447{ 423{
448 if (aixlabel->magic != AIX_LABEL_MAGIC && 424 if (aixlabel->magic != AIX_LABEL_MAGIC &&
449 aixlabel->magic != AIX_LABEL_MAGIC_SWAPPED) { 425 aixlabel->magic != AIX_LABEL_MAGIC_SWAPPED) {
450 aix_label = 0; 426 current_label_type = 0;
451 aix_other_endian = 0; 427 aix_other_endian = 0;
452 return 0; 428 return 0;
453 } 429 }
454 aix_other_endian = (aixlabel->magic == AIX_LABEL_MAGIC_SWAPPED); 430 aix_other_endian = (aixlabel->magic == AIX_LABEL_MAGIC_SWAPPED);
455 update_units(); 431 update_units();
456 aix_label = 1; 432 current_label_type = label_aix;
457 partitions = 1016; 433 partitions = 1016;
458 aix_volumes = 15; 434 aix_volumes = 15;
459 aix_info(); 435 aix_info();
460 aix_nolabel(); /* %% */ 436 /*aix_nolabel();*/ /* %% */
461 aix_label = 1; /* %% */ 437 /*aix_label = 1;*/ /* %% */
462 return 1; 438 return 1;
463} 439}
464#endif /* AIX_LABEL */ 440#endif /* AIX_LABEL */
@@ -1786,14 +1762,6 @@ sgi_get_ntrks(void)
1786 return SGI_SSWAP16(sgilabel->devparam.ntrks); 1762 return SGI_SSWAP16(sgilabel->devparam.ntrks);
1787} 1763}
1788 1764
1789static void
1790sgi_nolabel(void)
1791{
1792 sgilabel->magic = 0;
1793 sgi_label = 0;
1794 partitions = 4;
1795}
1796
1797static unsigned int 1765static unsigned int
1798two_s_complement_32bit_sum(unsigned int* base, int size /* in bytes */) 1766two_s_complement_32bit_sum(unsigned int* base, int size /* in bytes */)
1799{ 1767{
@@ -1818,8 +1786,7 @@ check_sgi_label(void)
1818 1786
1819 if (sgilabel->magic != SGI_LABEL_MAGIC 1787 if (sgilabel->magic != SGI_LABEL_MAGIC
1820 && sgilabel->magic != SGI_LABEL_MAGIC_SWAPPED) { 1788 && sgilabel->magic != SGI_LABEL_MAGIC_SWAPPED) {
1821 sgi_label = 0; 1789 current_label_type = label_dos;
1822 sgi_other_endian = 0;
1823 return 0; 1790 return 0;
1824 } 1791 }
1825 1792
@@ -1833,7 +1800,7 @@ check_sgi_label(void)
1833 _("Detected sgi disklabel with wrong checksum.\n")); 1800 _("Detected sgi disklabel with wrong checksum.\n"));
1834 } 1801 }
1835 update_units(); 1802 update_units();
1836 sgi_label = 1; 1803 current_label_type = label_sgi;
1837 partitions = 16; 1804 partitions = 16;
1838 sgi_volumes = 15; 1805 sgi_volumes = 15;
1839 return 1; 1806 return 1;
@@ -2445,7 +2412,7 @@ create_sgilabel(void)
2445 sgilabel->devparam.xylogics_writecont = SGI_SSWAP16(0); 2412 sgilabel->devparam.xylogics_writecont = SGI_SSWAP16(0);
2446 memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 ); 2413 memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 );
2447 memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16 ); 2414 memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16 );
2448 sgi_label = 1; 2415 current_label_type = label_sgi;
2449 partitions = 16; 2416 partitions = 16;
2450 sgi_volumes = 15; 2417 sgi_volumes = 15;
2451 sgi_set_entire(); 2418 sgi_set_entire();
@@ -2564,14 +2531,6 @@ set_sun_partition(int i, uint start, uint stop, int sysid)
2564 set_changed(i); 2531 set_changed(i);
2565} 2532}
2566 2533
2567static void
2568sun_nolabel(void)
2569{
2570 sun_label = 0;
2571 sunlabel->magic = 0;
2572 partitions = 4;
2573}
2574
2575static int 2534static int
2576check_sun_label(void) 2535check_sun_label(void)
2577{ 2536{
@@ -2580,7 +2539,7 @@ check_sun_label(void)
2580 2539
2581 if (sunlabel->magic != SUN_LABEL_MAGIC 2540 if (sunlabel->magic != SUN_LABEL_MAGIC
2582 && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) { 2541 && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) {
2583 sun_label = 0; 2542 current_label_type = label_dos;
2584 sun_other_endian = 0; 2543 sun_other_endian = 0;
2585 return 0; 2544 return 0;
2586 } 2545 }
@@ -2598,7 +2557,7 @@ check_sun_label(void)
2598 sectors = SUN_SSWAP16(sunlabel->nsect); 2557 sectors = SUN_SSWAP16(sunlabel->nsect);
2599 } 2558 }
2600 update_units(); 2559 update_units();
2601 sun_label = 1; 2560 current_label_type = label_sun;
2602 partitions = 8; 2561 partitions = 8;
2603 return 1; 2562 return 1;
2604} 2563}
@@ -3505,7 +3464,7 @@ static void
3505menu(void) 3464menu(void)
3506{ 3465{
3507#ifdef CONFIG_FEATURE_SUN_LABEL 3466#ifdef CONFIG_FEATURE_SUN_LABEL
3508 if (sun_label) { 3467 if (label_sun == current_label_type) {
3509 puts(_("Command action")); 3468 puts(_("Command action"));
3510 puts(_("\ta\ttoggle a read only flag")); /* sun */ 3469 puts(_("\ta\ttoggle a read only flag")); /* sun */
3511 puts(_("\tb\tedit bsd disklabel")); 3470 puts(_("\tb\tedit bsd disklabel"));
@@ -3528,7 +3487,7 @@ menu(void)
3528 } else 3487 } else
3529#endif 3488#endif
3530#ifdef CONFIG_FEATURE_SGI_LABEL 3489#ifdef CONFIG_FEATURE_SGI_LABEL
3531 if (sgi_label) { 3490 if (label_sgi == current_label_type) {
3532 puts(_("Command action")); 3491 puts(_("Command action"));
3533 puts(_("\ta\tselect bootable partition")); /* sgi flavour */ 3492 puts(_("\ta\tselect bootable partition")); /* sgi flavour */
3534 puts(_("\tb\tedit bootfile entry")); /* sgi */ 3493 puts(_("\tb\tedit bootfile entry")); /* sgi */
@@ -3548,7 +3507,7 @@ menu(void)
3548 } else 3507 } else
3549#endif 3508#endif
3550#ifdef CONFIG_FEATURE_AIX_LABEL 3509#ifdef CONFIG_FEATURE_AIX_LABEL
3551 if (aix_label) { 3510 if (label_aix == current_label_type) {
3552 puts(_("Command action")); 3511 puts(_("Command action"));
3553 puts(_("\tm\tprint this menu")); 3512 puts(_("\tm\tprint this menu"));
3554 puts(_("\to\tcreate a new empty DOS partition table")); 3513 puts(_("\to\tcreate a new empty DOS partition table"));
@@ -3586,7 +3545,7 @@ static void
3586xmenu(void) 3545xmenu(void)
3587{ 3546{
3588#ifdef CONFIG_FEATURE_SUN_LABEL 3547#ifdef CONFIG_FEATURE_SUN_LABEL
3589 if (sun_label) { 3548 if (label_sun == current_label_type) {
3590 puts(_("Command action")); 3549 puts(_("Command action"));
3591 puts(_("\ta\tchange number of alternate cylinders")); /*sun*/ 3550 puts(_("\ta\tchange number of alternate cylinders")); /*sun*/
3592 puts(_("\tc\tchange number of cylinders")); 3551 puts(_("\tc\tchange number of cylinders"));
@@ -3606,7 +3565,7 @@ xmenu(void)
3606 } else 3565 } else
3607#endif 3566#endif
3608#ifdef CONFIG_FEATURE_SGI_LABEL 3567#ifdef CONFIG_FEATURE_SGI_LABEL
3609 if (sgi_label) { 3568 if (label_sgi == current_label_type) {
3610 puts(_("Command action")); 3569 puts(_("Command action"));
3611 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */ 3570 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */
3612 puts(_("\tc\tchange number of cylinders")); 3571 puts(_("\tc\tchange number of cylinders"));
@@ -3624,7 +3583,7 @@ xmenu(void)
3624 } else 3583 } else
3625#endif 3584#endif
3626#ifdef CONFIG_FEATURE_AIX_LABEL 3585#ifdef CONFIG_FEATURE_AIX_LABEL
3627 if (aix_label) { 3586 if (label_aix == current_label_type) {
3628 puts(_("Command action")); 3587 puts(_("Command action"));
3629 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */ 3588 puts(_("\tb\tmove beginning of data in a partition")); /* !sun */
3630 puts(_("\tc\tchange number of cylinders")); 3589 puts(_("\tc\tchange number of cylinders"));
@@ -3669,10 +3628,10 @@ get_sys_types(void)
3669{ 3628{
3670 return ( 3629 return (
3671#ifdef CONFIG_FEATURE_SUN_LABEL 3630#ifdef CONFIG_FEATURE_SUN_LABEL
3672 sun_label ? sun_sys_types : 3631 label_sun == current_label_type ? sun_sys_types :
3673#endif 3632#endif
3674#ifdef CONFIG_FEATURE_SGI_LABEL 3633#ifdef CONFIG_FEATURE_SGI_LABEL
3675 sgi_label ? sgi_sys_types : 3634 label_sgi == current_label_type ? sgi_sys_types :
3676#endif 3635#endif
3677 i386_sys_types); 3636 i386_sys_types);
3678} 3637}
@@ -3699,10 +3658,10 @@ get_sysid(int i)
3699{ 3658{
3700 return ( 3659 return (
3701#ifdef CONFIG_FEATURE_SUN_LABEL 3660#ifdef CONFIG_FEATURE_SUN_LABEL
3702 sun_label ? sunlabel->infos[i].id : 3661 label_sun == current_label_type ? sunlabel->infos[i].id :
3703#endif 3662#endif
3704#ifdef CONFIG_FEATURE_SGI_LABEL 3663#ifdef CONFIG_FEATURE_SGI_LABEL
3705 sgi_label ? sgi_get_sysid(i) : 3664 label_sgi == current_label_type ? sgi_get_sysid(i) :
3706#endif 3665#endif
3707 ptes[i].part_table->sys_ind); 3666 ptes[i].part_table->sys_ind);
3708} 3667}
@@ -3829,7 +3788,7 @@ static void update_units(void)
3829static void 3788static void
3830warn_cylinders(void) 3789warn_cylinders(void)
3831{ 3790{
3832 if (dos_label && cylinders > 1024 && !nowarn) 3791 if (label_dos == current_label_type && cylinders > 1024 && !nowarn)
3833 fprintf(stderr, _("\n" 3792 fprintf(stderr, _("\n"
3834"The number of cylinders for this disk is set to %d.\n" 3793"The number of cylinders for this disk is set to %d.\n"
3835"There is nothing wrong with that, but this is larger than 1024,\n" 3794"There is nothing wrong with that, but this is larger than 1024,\n"
@@ -3947,17 +3906,10 @@ create_doslabel(void)
3947 _("Building a new DOS disklabel. Changes will remain in memory only,\n" 3906 _("Building a new DOS disklabel. Changes will remain in memory only,\n"
3948 "until you decide to write them. After that, of course, the previous\n" 3907 "until you decide to write them. After that, of course, the previous\n"
3949 "content won't be recoverable.\n\n")); 3908 "content won't be recoverable.\n\n"));
3950#ifdef CONFIG_FEATURE_SUN_LABEL 3909
3951 sun_nolabel(); /* otherwise always recognised as sun */ 3910 current_label_type = label_dos;
3952#endif 3911
3953#ifdef CONFIG_FEATURE_SGI_LABEL
3954 sgi_nolabel(); /* otherwise always recognised as sgi */
3955#endif
3956#ifdef CONFIG_FEATURE_AIX_LABEL
3957 aix_label = 0;
3958#endif
3959#ifdef CONFIG_FEATURE_OSF_LABEL 3912#ifdef CONFIG_FEATURE_OSF_LABEL
3960 osf_label = 0;
3961 possibly_osf_label = 0; 3913 possibly_osf_label = 0;
3962#endif 3914#endif
3963 partitions = 4; 3915 partitions = 4;
@@ -4156,7 +4108,7 @@ get_boot(enum action what)
4156 if (check_osf_label()) { 4108 if (check_osf_label()) {
4157 possibly_osf_label = 1; 4109 possibly_osf_label = 1;
4158 if (!valid_part_table_flag(MBRbuffer)) { 4110 if (!valid_part_table_flag(MBRbuffer)) {
4159 osf_label = 1; 4111 current_label_type = label_osf;
4160 return 0; 4112 return 0;
4161 } 4113 }
4162 printf(_("This disk has both DOS and BSD magic.\n" 4114 printf(_("This disk has both DOS and BSD magic.\n"
@@ -4344,19 +4296,33 @@ get_partition(int warn, int max)
4344 pe = &ptes[i]; 4296 pe = &ptes[i];
4345 4297
4346 if (warn) { 4298 if (warn) {
4347 if ((!sun_label && !sgi_label && !pe->part_table->sys_ind) 4299 if (
4300 (
4301 label_sun != current_label_type &&
4302 label_sgi != current_label_type &&
4303 !pe->part_table->sys_ind
4304 )
4348#ifdef CONFIG_FEATURE_SUN_LABEL 4305#ifdef CONFIG_FEATURE_SUN_LABEL
4349 || (sun_label && 4306 || (
4350 (!sunlabel->partitions[i].num_sectors || 4307 label_sun == current_label_type &&
4351 !sunlabel->infos[i].id)) 4308 (
4309 !sunlabel->partitions[i].num_sectors
4310 || !sunlabel->infos[i].id
4311 )
4312 )
4352#endif 4313#endif
4353#ifdef CONFIG_FEATURE_SGI_LABEL 4314#ifdef CONFIG_FEATURE_SGI_LABEL
4354 || (sgi_label && (!sgi_get_num_sectors(i))) 4315 || (
4316 label_sgi == current_label_type &&
4317 !sgi_get_num_sectors(i)
4318 )
4355#endif 4319#endif
4356 ) 4320 ){
4357 fprintf(stderr, 4321 fprintf(stderr,
4358 _("Warning: partition %d has empty type\n"), 4322 _("Warning: partition %d has empty type\n"),
4359 i+1); 4323 i+1
4324 );
4325 }
4360 } 4326 }
4361 return i; 4327 return i;
4362} 4328}
@@ -4468,13 +4434,13 @@ delete_partition(int i)
4468 pe->changed = 1; 4434 pe->changed = 1;
4469 4435
4470#ifdef CONFIG_FEATURE_SUN_LABEL 4436#ifdef CONFIG_FEATURE_SUN_LABEL
4471 if (sun_label) { 4437 if (label_sun == current_label_type) {
4472 sun_delete_partition(i); 4438 sun_delete_partition(i);
4473 return; 4439 return;
4474 } 4440 }
4475#endif 4441#endif
4476#ifdef CONFIG_FEATURE_SGI_LABEL 4442#ifdef CONFIG_FEATURE_SGI_LABEL
4477 if (sgi_label) { 4443 if (label_sgi == current_label_type) {
4478 sgi_delete_partition(i); 4444 sgi_delete_partition(i);
4479 return; 4445 return;
4480 } 4446 }
@@ -4539,7 +4505,7 @@ change_sysid(void)
4539 /* If sgi_label then don't use get_existing_partition, 4505 /* If sgi_label then don't use get_existing_partition,
4540 let the user select a partition, since get_existing_partition() 4506 let the user select a partition, since get_existing_partition()
4541 only works for Linux like partition tables. */ 4507 only works for Linux like partition tables. */
4542 if (!sgi_label) { 4508 if (label_sgi != current_label_type) {
4543 i = get_existing_partition(0, partitions); 4509 i = get_existing_partition(0, partitions);
4544 } else { 4510 } else {
4545 i = get_partition(0, partitions); 4511 i = get_partition(0, partitions);
@@ -4554,12 +4520,17 @@ change_sysid(void)
4554 4520
4555 /* if changing types T to 0 is allowed, then 4521 /* if changing types T to 0 is allowed, then
4556 the reverse change must be allowed, too */ 4522 the reverse change must be allowed, too */
4557 if (!sys && !sgi_label && !sun_label && !get_nr_sects(p)) 4523 if (!sys && label_sgi != current_label_type &&
4524 label_sun != current_label_type && !get_nr_sects(p))
4525 {
4558 printf(_("Partition %d does not exist yet!\n"), i + 1); 4526 printf(_("Partition %d does not exist yet!\n"), i + 1);
4559 else while (1) { 4527 }else{
4528 while (1) {
4560 sys = read_hex (get_sys_types()); 4529 sys = read_hex (get_sys_types());
4561 4530
4562 if (!sys && !sgi_label && !sun_label) { 4531 if (!sys && label_sgi != current_label_type &&
4532 label_sun != current_label_type)
4533 {
4563 printf(_("Type 0 means free space to many systems\n" 4534 printf(_("Type 0 means free space to many systems\n"
4564 "(but not to Linux). Having partitions of\n" 4535 "(but not to Linux). Having partitions of\n"
4565 "type 0 is probably unwise. You can delete\n" 4536 "type 0 is probably unwise. You can delete\n"
@@ -4567,7 +4538,7 @@ change_sysid(void)
4567 /* break; */ 4538 /* break; */
4568 } 4539 }
4569 4540
4570 if (!sun_label && !sgi_label) { 4541 if (label_sun != current_label_type && label_sgi != current_label_type) {
4571 if (IS_EXTENDED(sys) != IS_EXTENDED(p->sys_ind)) { 4542 if (IS_EXTENDED(sys) != IS_EXTENDED(p->sys_ind)) {
4572 printf(_("You cannot change a partition into" 4543 printf(_("You cannot change a partition into"
4573 " an extended one or vice versa\n" 4544 " an extended one or vice versa\n"
@@ -4578,33 +4549,39 @@ change_sysid(void)
4578 4549
4579 if (sys < 256) { 4550 if (sys < 256) {
4580#ifdef CONFIG_FEATURE_SUN_LABEL 4551#ifdef CONFIG_FEATURE_SUN_LABEL
4581 if (sun_label && i == 2 && sys != WHOLE_DISK) 4552 if (label_sun == current_label_type && i == 2 && sys != WHOLE_DISK)
4582 printf(_("Consider leaving partition 3 " 4553 printf(_("Consider leaving partition 3 "
4583 "as Whole disk (5),\n" 4554 "as Whole disk (5),\n"
4584 "as SunOS/Solaris expects it and " 4555 "as SunOS/Solaris expects it and "
4585 "even Linux likes it.\n\n")); 4556 "even Linux likes it.\n\n"));
4586#endif 4557#endif
4587#ifdef CONFIG_FEATURE_SGI_LABEL 4558#ifdef CONFIG_FEATURE_SGI_LABEL
4588 if (sgi_label && ((i == 10 && sys != ENTIRE_DISK) 4559 if (label_sgi == current_label_type &&
4589 || (i == 8 && sys != 0))) 4560 (
4561 (i == 10 && sys != ENTIRE_DISK) ||
4562 (i == 8 && sys != 0)
4563 )
4564 ){
4590 printf(_("Consider leaving partition 9 " 4565 printf(_("Consider leaving partition 9 "
4591 "as volume header (0),\nand " 4566 "as volume header (0),\nand "
4592 "partition 11 as entire volume (6)" 4567 "partition 11 as entire volume (6)"
4593 "as IRIX expects it.\n\n")); 4568 "as IRIX expects it.\n\n"));
4569 }
4594#endif 4570#endif
4595 if (sys == origsys) 4571 if (sys == origsys)
4596 break; 4572 break;
4597#ifdef CONFIG_FEATURE_SUN_LABEL 4573#ifdef CONFIG_FEATURE_SUN_LABEL
4598 if (sun_label) { 4574 if (label_sun == current_label_type) {
4599 sun_change_sysid(i, sys); 4575 sun_change_sysid(i, sys);
4600 } else 4576 } else
4601#endif 4577#endif
4602#ifdef CONFIG_FEATURE_SGI_LABEL 4578#ifdef CONFIG_FEATURE_SGI_LABEL
4603 if (sgi_label) { 4579 if (label_sgi == current_label_type) {
4604 sgi_change_sysid(i, sys); 4580 sgi_change_sysid(i, sys);
4605 } else 4581 } else
4606#endif 4582#endif
4607 p->sys_ind = sys; 4583 p->sys_ind = sys;
4584
4608 printf(_("Changed system type of partition %d " 4585 printf(_("Changed system type of partition %d "
4609 "to %x (%s)\n"), i + 1, sys, 4586 "to %x (%s)\n"), i + 1, sys,
4610 partition_type(sys)); 4587 partition_type(sys));
@@ -4614,6 +4591,7 @@ change_sysid(void)
4614 dos_changed = 1; 4591 dos_changed = 1;
4615 break; 4592 break;
4616 } 4593 }
4594 }
4617 } 4595 }
4618} 4596}
4619#endif /* CONFIG_FEATURE_FDISK_WRITABLE */ 4597#endif /* CONFIG_FEATURE_FDISK_WRITABLE */
@@ -4870,14 +4848,14 @@ list_table(int xtra)
4870 int i, w; 4848 int i, w;
4871 4849
4872#ifdef CONFIG_FEATURE_SUN_LABEL 4850#ifdef CONFIG_FEATURE_SUN_LABEL
4873 if (sun_label) { 4851 if (label_sun == current_label_type) {
4874 sun_list_table(xtra); 4852 sun_list_table(xtra);
4875 return; 4853 return;
4876 } 4854 }
4877#endif 4855#endif
4878 4856
4879#ifdef CONFIG_FEATURE_SGI_LABEL 4857#ifdef CONFIG_FEATURE_SGI_LABEL
4880 if (sgi_label) { 4858 if (label_sgi == current_label_type) {
4881 sgi_list_table(xtra); 4859 sgi_list_table(xtra);
4882 return; 4860 return;
4883 } 4861 }
@@ -4886,7 +4864,7 @@ list_table(int xtra)
4886 list_disk_geometry(); 4864 list_disk_geometry();
4887 4865
4888#ifdef CONFIG_FEATURE_OSF_LABEL 4866#ifdef CONFIG_FEATURE_OSF_LABEL
4889 if (osf_label) { 4867 if (label_osf == current_label_type) {
4890 xbsd_print_disklabel(xtra); 4868 xbsd_print_disklabel(xtra);
4891 return; 4869 return;
4892 } 4870 }
@@ -4937,7 +4915,8 @@ list_table(int xtra)
4937 /* Is partition table in disk order? It need not be, but... */ 4915 /* Is partition table in disk order? It need not be, but... */
4938 /* partition table entries are not checked for correct order if this 4916 /* partition table entries are not checked for correct order if this
4939 is a sgi, sun or aix labeled disk... */ 4917 is a sgi, sun or aix labeled disk... */
4940 if (dos_label && wrong_p_order(NULL)) { 4918 if (label_dos == current_label_type && wrong_p_order(NULL)) {
4919 /* FIXME */
4941 printf(_("\nPartition table entries are not in disk order\n")); 4920 printf(_("\nPartition table entries are not in disk order\n"));
4942 } 4921 }
4943} 4922}
@@ -5029,13 +5008,13 @@ verify(void)
5029 return; 5008 return;
5030 5009
5031#ifdef CONFIG_FEATURE_SUN_LABEL 5010#ifdef CONFIG_FEATURE_SUN_LABEL
5032 if (sun_label) { 5011 if (label_sun == current_label_type) {
5033 verify_sun(); 5012 verify_sun();
5034 return; 5013 return;
5035 } 5014 }
5036#endif 5015#endif
5037#ifdef CONFIG_FEATURE_SGI_LABEL 5016#ifdef CONFIG_FEATURE_SGI_LABEL
5038 if (sgi_label) { 5017 if (label_sgi == current_label_type) {
5039 verify_sgi(1); 5018 verify_sgi(1);
5040 return; 5019 return;
5041 } 5020 }
@@ -5249,19 +5228,19 @@ new_partition(void)
5249 return; 5228 return;
5250 5229
5251#ifdef CONFIG_FEATURE_SUN_LABEL 5230#ifdef CONFIG_FEATURE_SUN_LABEL
5252 if (sun_label) { 5231 if (label_sun == current_label_type) {
5253 add_sun_partition(get_partition(0, partitions), LINUX_NATIVE); 5232 add_sun_partition(get_partition(0, partitions), LINUX_NATIVE);
5254 return; 5233 return;
5255 } 5234 }
5256#endif 5235#endif
5257#ifdef CONFIG_FEATURE_SGI_LABEL 5236#ifdef CONFIG_FEATURE_SGI_LABEL
5258 if (sgi_label) { 5237 if (label_sgi == current_label_type) {
5259 sgi_add_partition(get_partition(0, partitions), LINUX_NATIVE); 5238 sgi_add_partition(get_partition(0, partitions), LINUX_NATIVE);
5260 return; 5239 return;
5261 } 5240 }
5262#endif 5241#endif
5263#ifdef CONFIG_FEATURE_AIX_LABEL 5242#ifdef CONFIG_FEATURE_AIX_LABEL
5264 if (aix_label) { 5243 if (label_aix == current_label_type) {
5265 printf(_("\tSorry - this fdisk cannot handle AIX disk labels." 5244 printf(_("\tSorry - this fdisk cannot handle AIX disk labels."
5266 "\n\tIf you want to add DOS-type partitions, create" 5245 "\n\tIf you want to add DOS-type partitions, create"
5267 "\n\ta new empty DOS partition table first. (Use o.)" 5246 "\n\ta new empty DOS partition table first. (Use o.)"
@@ -5320,7 +5299,7 @@ write_table(void)
5320{ 5299{
5321 int i; 5300 int i;
5322 5301
5323 if (dos_label) { 5302 if (label_dos == current_label_type) {
5324 for (i = 0; i < 3; i++) 5303 for (i = 0; i < 3; i++)
5325 if (ptes[i].changed) 5304 if (ptes[i].changed)
5326 ptes[3].changed = 1; 5305 ptes[3].changed = 1;
@@ -5334,13 +5313,13 @@ write_table(void)
5334 } 5313 }
5335 } 5314 }
5336#ifdef CONFIG_FEATURE_SGI_LABEL 5315#ifdef CONFIG_FEATURE_SGI_LABEL
5337 else if (sgi_label) { 5316 else if (label_sgi == current_label_type) {
5338 /* no test on change? the printf below might be mistaken */ 5317 /* no test on change? the printf below might be mistaken */
5339 sgi_write_table(); 5318 sgi_write_table();
5340 } 5319 }
5341#endif 5320#endif
5342#ifdef CONFIG_FEATURE_SUN_LABEL 5321#ifdef CONFIG_FEATURE_SUN_LABEL
5343 else if (sun_label) { 5322 else if (label_sun == current_label_type) {
5344 int needw = 0; 5323 int needw = 0;
5345 5324
5346 for (i = 0; i < 8; i++) 5325 for (i = 0; i < 8; i++)
@@ -5431,7 +5410,7 @@ print_raw(void)
5431 5410
5432 printf(_("Device: %s\n"), disk_device); 5411 printf(_("Device: %s\n"), disk_device);
5433#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL) 5412#if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL)
5434 if (sun_label || sgi_label) 5413 if (label_sun == current_label_type || label_sgi == current_label_type)
5435 print_buffer(MBRbuffer); 5414 print_buffer(MBRbuffer);
5436 else 5415 else
5437#endif 5416#endif
@@ -5475,12 +5454,12 @@ xselect(void)
5475 switch (c) { 5454 switch (c) {
5476 case 'a': 5455 case 'a':
5477#ifdef CONFIG_FEATURE_SUN_LABEL 5456#ifdef CONFIG_FEATURE_SUN_LABEL
5478 if (sun_label) 5457 if (label_sun == current_label_type)
5479 sun_set_alt_cyl(); 5458 sun_set_alt_cyl();
5480#endif 5459#endif
5481 break; 5460 break;
5482 case 'b': 5461 case 'b':
5483 if (dos_label) 5462 if (label_dos == current_label_type)
5484 move_begin(get_partition(0, partitions)); 5463 move_begin(get_partition(0, partitions));
5485 break; 5464 break;
5486 case 'c': 5465 case 'c':
@@ -5488,10 +5467,10 @@ xselect(void)
5488 read_int(1, cylinders, 1048576, 0, 5467 read_int(1, cylinders, 1048576, 0,
5489 _("Number of cylinders")); 5468 _("Number of cylinders"));
5490#ifdef CONFIG_FEATURE_SUN_LABEL 5469#ifdef CONFIG_FEATURE_SUN_LABEL
5491 if (sun_label) 5470 if (label_sun == current_label_type)
5492 sun_set_ncyl(cylinders); 5471 sun_set_ncyl(cylinders);
5493#endif 5472#endif
5494 if (dos_label) 5473 if (label_dos == current_label_type)
5495 warn_cylinders(); 5474 warn_cylinders();
5496 break; 5475 break;
5497 case 'd': 5476 case 'd':
@@ -5499,20 +5478,20 @@ xselect(void)
5499 break; 5478 break;
5500 case 'e': 5479 case 'e':
5501#ifdef CONFIG_FEATURE_SGI_LABEL 5480#ifdef CONFIG_FEATURE_SGI_LABEL
5502 if (sgi_label) 5481 if (label_sgi == current_label_type)
5503 sgi_set_xcyl(); 5482 sgi_set_xcyl();
5504 else 5483 else
5505#endif 5484#endif
5506#ifdef CONFIG_FEATURE_SUN_LABEL 5485#ifdef CONFIG_FEATURE_SUN_LABEL
5507 if (sun_label) 5486 if (label_sun == current_label_type)
5508 sun_set_xcyl(); 5487 sun_set_xcyl();
5509 else 5488 else
5510#endif 5489#endif
5511 if (dos_label) 5490 if (label_dos == current_label_type)
5512 x_list_table(1); 5491 x_list_table(1);
5513 break; 5492 break;
5514 case 'f': 5493 case 'f':
5515 if (dos_label) 5494 if (label_dos == current_label_type)
5516 fix_partition_table_order(); 5495 fix_partition_table_order();
5517 break; 5496 break;
5518 case 'g': 5497 case 'g':
@@ -5527,19 +5506,19 @@ xselect(void)
5527 break; 5506 break;
5528 case 'i': 5507 case 'i':
5529#ifdef CONFIG_FEATURE_SUN_LABEL 5508#ifdef CONFIG_FEATURE_SUN_LABEL
5530 if (sun_label) 5509 if (label_sun == current_label_type)
5531 sun_set_ilfact(); 5510 sun_set_ilfact();
5532#endif 5511#endif
5533 break; 5512 break;
5534 case 'o': 5513 case 'o':
5535#ifdef CONFIG_FEATURE_SUN_LABEL 5514#ifdef CONFIG_FEATURE_SUN_LABEL
5536 if (sun_label) 5515 if (label_sun == current_label_type)
5537 sun_set_rspeed(); 5516 sun_set_rspeed();
5538#endif 5517#endif
5539 break; 5518 break;
5540 case 'p': 5519 case 'p':
5541#ifdef CONFIG_FEATURE_SUN_LABEL 5520#ifdef CONFIG_FEATURE_SUN_LABEL
5542 if (sun_label) 5521 if (label_sun == current_label_type)
5543 list_table(1); 5522 list_table(1);
5544 else 5523 else
5545#endif 5524#endif
@@ -5570,7 +5549,7 @@ xselect(void)
5570 break; 5549 break;
5571 case 'y': 5550 case 'y':
5572#ifdef CONFIG_FEATURE_SUN_LABEL 5551#ifdef CONFIG_FEATURE_SUN_LABEL
5573 if (sun_label) 5552 if (label_sun == current_label_type)
5574 sun_set_pcylcount(); 5553 sun_set_pcylcount();
5575#endif 5554#endif
5576 break; 5555 break;
@@ -5615,6 +5594,7 @@ is_ide_cdrom_or_tape(const char *device)
5615 return is_ide; 5594 return is_ide;
5616} 5595}
5617 5596
5597
5618static void 5598static void
5619try(const char *device, int user_specified) 5599try(const char *device, int user_specified)
5620{ 5600{
@@ -5632,8 +5612,9 @@ try(const char *device, int user_specified)
5632 close(fd); 5612 close(fd);
5633 } else if (gb < 0) { /* no DOS signature */ 5613 } else if (gb < 0) { /* no DOS signature */
5634 list_disk_geometry(); 5614 list_disk_geometry();
5635 if (aix_label) 5615 if (label_aix == current_label_type){
5636 return; 5616 return;
5617 }
5637#ifdef CONFIG_FEATURE_OSF_LABEL 5618#ifdef CONFIG_FEATURE_OSF_LABEL
5638 if (btrydev(device) < 0) 5619 if (btrydev(device) < 0)
5639#endif 5620#endif
@@ -5645,8 +5626,9 @@ try(const char *device, int user_specified)
5645 close(fd); 5626 close(fd);
5646 list_table(0); 5627 list_table(0);
5647#ifdef CONFIG_FEATURE_FDISK_WRITABLE 5628#ifdef CONFIG_FEATURE_FDISK_WRITABLE
5648 if (!sun_label && partitions > 4) 5629 if (label_sun != current_label_type && partitions > 4){
5649 delete_partition(ext_index); 5630 delete_partition(ext_index);
5631 }
5650#endif 5632#endif
5651 } 5633 }
5652 } else { 5634 } else {
@@ -5837,13 +5819,14 @@ int fdisk_main(int argc, char **argv)
5837 get_boot(fdisk); 5819 get_boot(fdisk);
5838 5820
5839#ifdef CONFIG_FEATURE_OSF_LABEL 5821#ifdef CONFIG_FEATURE_OSF_LABEL
5840 if (osf_label) { 5822 if (label_osf == current_label_type) {
5841 /* OSF label, and no DOS label */ 5823 /* OSF label, and no DOS label */
5842 printf(_("Detected an OSF/1 disklabel on %s, entering " 5824 printf(_("Detected an OSF/1 disklabel on %s, entering "
5843 "disklabel mode.\n"), 5825 "disklabel mode.\n"),
5844 disk_device); 5826 disk_device);
5845 bselect(); 5827 bselect();
5846 osf_label = 0; 5828 /*Why do we do this? It seems to be counter-intuitive*/
5829 current_label_type = label_dos;
5847 /* If we return we may want to make an empty DOS label? */ 5830 /* If we return we may want to make an empty DOS label? */
5848 } 5831 }
5849#endif 5832#endif
@@ -5853,15 +5836,15 @@ int fdisk_main(int argc, char **argv)
5853 c = tolower(read_char(_("Command (m for help): "))); 5836 c = tolower(read_char(_("Command (m for help): ")));
5854 switch (c) { 5837 switch (c) {
5855 case 'a': 5838 case 'a':
5856 if (dos_label) 5839 if (label_dos == current_label_type)
5857 toggle_active(get_partition(1, partitions)); 5840 toggle_active(get_partition(1, partitions));
5858#ifdef CONFIG_FEATURE_SUN_LABEL 5841#ifdef CONFIG_FEATURE_SUN_LABEL
5859 else if (sun_label) 5842 else if (label_sun == current_label_type)
5860 toggle_sunflags(get_partition(1, partitions), 5843 toggle_sunflags(get_partition(1, partitions),
5861 0x01); 5844 0x01);
5862#endif 5845#endif
5863#ifdef CONFIG_FEATURE_SGI_LABEL 5846#ifdef CONFIG_FEATURE_SGI_LABEL
5864 else if (sgi_label) 5847 else if (label_sgi == current_label_type)
5865 sgi_set_bootpartition( 5848 sgi_set_bootpartition(
5866 get_partition(1, partitions)); 5849 get_partition(1, partitions));
5867#endif 5850#endif
@@ -5870,7 +5853,7 @@ int fdisk_main(int argc, char **argv)
5870 break; 5853 break;
5871 case 'b': 5854 case 'b':
5872#ifdef CONFIG_FEATURE_SGI_LABEL 5855#ifdef CONFIG_FEATURE_SGI_LABEL
5873 if (sgi_label) { 5856 if (label_sgi == current_label_type) {
5874 printf(_("\nThe current boot file is: %s\n"), 5857 printf(_("\nThe current boot file is: %s\n"),
5875 sgi_get_bootfile()); 5858 sgi_get_bootfile());
5876 if (read_chars(_("Please enter the name of the " 5859 if (read_chars(_("Please enter the name of the "
@@ -5885,15 +5868,15 @@ int fdisk_main(int argc, char **argv)
5885#endif 5868#endif
5886 break; 5869 break;
5887 case 'c': 5870 case 'c':
5888 if (dos_label) 5871 if (label_dos == current_label_type)
5889 toggle_dos_compatibility_flag(); 5872 toggle_dos_compatibility_flag();
5890#ifdef CONFIG_FEATURE_SUN_LABEL 5873#ifdef CONFIG_FEATURE_SUN_LABEL
5891 else if (sun_label) 5874 else if (label_sun == current_label_type)
5892 toggle_sunflags(get_partition(1, partitions), 5875 toggle_sunflags(get_partition(1, partitions),
5893 0x10); 5876 0x10);
5894#endif 5877#endif
5895#ifdef CONFIG_FEATURE_SGI_LABEL 5878#ifdef CONFIG_FEATURE_SGI_LABEL
5896 else if (sgi_label) 5879 else if (label_sgi == current_label_type)
5897 sgi_set_swappartition( 5880 sgi_set_swappartition(
5898 get_partition(1, partitions)); 5881 get_partition(1, partitions));
5899#endif 5882#endif
@@ -5908,7 +5891,7 @@ int fdisk_main(int argc, char **argv)
5908 let the user select a partition, since 5891 let the user select a partition, since
5909 get_existing_partition() only works for Linux-like 5892 get_existing_partition() only works for Linux-like
5910 partition tables */ 5893 partition tables */
5911 if (!sgi_label) { 5894 if (label_sgi != current_label_type) {
5912 j = get_existing_partition(1, partitions); 5895 j = get_existing_partition(1, partitions);
5913 } else { 5896 } else {
5914 j = get_partition(1, partitions); 5897 j = get_partition(1, partitions);
@@ -5922,7 +5905,7 @@ int fdisk_main(int argc, char **argv)
5922 break; 5905 break;
5923 case 'i': 5906 case 'i':
5924#ifdef CONFIG_FEATURE_SGI_LABEL 5907#ifdef CONFIG_FEATURE_SGI_LABEL
5925 if (sgi_label) 5908 if (label_sgi == current_label_type)
5926 create_sgiinfo(); 5909 create_sgiinfo();
5927 else 5910 else
5928#endif 5911#endif
@@ -5966,7 +5949,7 @@ int fdisk_main(int argc, char **argv)
5966#ifdef CONFIG_FEATURE_FDISK_ADVANCED 5949#ifdef CONFIG_FEATURE_FDISK_ADVANCED
5967 case 'x': 5950 case 'x':
5968#ifdef CONFIG_FEATURE_SGI_LABEL 5951#ifdef CONFIG_FEATURE_SGI_LABEL
5969 if (sgi_label) { 5952 if (label_sgi == current_label_type) {
5970 fprintf(stderr, 5953 fprintf(stderr,
5971 _("\n\tSorry, no experts menu for SGI " 5954 _("\n\tSorry, no experts menu for SGI "
5972 "partition tables available.\n\n")); 5955 "partition tables available.\n\n"));