X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=util-linux%2Ffdisk.c;h=310bd555e9224625fa36b1420ef2abd881339744;hb=6ced427a6debb71967a8b9cebc12e31c08de0f6a;hp=a64515598bb91e33fc1c00c1de13c4cc61fdbdee;hpb=736e52532efe56298df665322a69b3014f4dc660;p=oweals%2Fbusybox.git diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index a64515598..310bd555e 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c @@ -1,13 +1,18 @@ +/* vi: set sw=4 ts=4: */ /* fdisk.c -- Partition table manipulator for Linux. * * Copyright (C) 1992 A. V. Le Blanc (LeBlanc@mcc.ac.uk) - * Copyright (C) 2001,2002 Vladimir Oleynik (Busybox port) + * Copyright (C) 2001,2002 Vladimir Oleynik (initial bb port) * * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. */ +/* Current changes have not compatibility with this version */ #define UTIL_LINUX_VERSION "2.12" + +#define _(x) x + #define PROC_PARTITIONS "/proc/partitions" #include @@ -39,17 +44,6 @@ #define DKTYPENAMES -#define BLKRRPART _IO(0x12,95) /* re-read partition table */ -#define BLKGETSIZE _IO(0x12,96) /* return device size */ -#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ -#define BLKSSZGET _IO(0x12,104) /* get block device sector size */ - -/* Avoid conflicts with the 2.6 kernel headers, which define - * _IOR rather differently */ -#undef _IOR -#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) -#define BLKGETSIZE64 _IOR(0x12,114,uint64_t) - /* fdisk.h */ @@ -115,30 +109,10 @@ static char MBRbuffer[MAX_SECTOR_SIZE]; # define MBRbuffer bb_common_bufsiz1 #endif -#ifdef CONFIG_FEATURE_SUN_LABEL -static int sun_label; /* looking at sun disklabel */ -#else -#define sun_label 0 -#endif -#ifdef CONFIG_FEATURE_SGI_LABEL -static int sgi_label; /* looking at sgi disklabel */ -#else -#define sgi_label 0 -#endif -#ifdef CONFIG_FEATURE_AIX_LABEL -static int aix_label; /* looking at aix disklabel */ -#else -#define aix_label 0 -#endif #ifdef CONFIG_FEATURE_OSF_LABEL -static int osf_label; /* looking at OSF/1 disklabel */ static int possibly_osf_label; -#else -#define osf_label 0 #endif -#define dos_label (!sun_label && !sgi_label && !aix_label && !osf_label) - static uint heads, sectors, cylinders; static void update_units(void); @@ -200,8 +174,14 @@ enum failure { unable_to_write }; +enum label_type{ + label_dos, label_sun, label_sgi, label_aix, label_osf +}; + enum action { fdisk, require, try_only, create_empty_dos, create_empty_sun }; +static enum label_type current_label_type; + static const char *disk_device; static int fd; /* the disk */ static int partitions = 4; /* maximum partition + 1 */ @@ -432,33 +412,23 @@ aix_info(void) ); } -static void -aix_nolabel(void) -{ - aixlabel->magic = 0; - aix_label = 0; - partitions = 4; - memset(MBRbuffer, 0, sizeof(MBRbuffer)); /* avoid fdisk cores */ - return; -} - static int check_aix_label(void) { if (aixlabel->magic != AIX_LABEL_MAGIC && aixlabel->magic != AIX_LABEL_MAGIC_SWAPPED) { - aix_label = 0; + current_label_type = 0; aix_other_endian = 0; return 0; } aix_other_endian = (aixlabel->magic == AIX_LABEL_MAGIC_SWAPPED); update_units(); - aix_label = 1; + current_label_type = label_aix; partitions = 1016; aix_volumes = 15; aix_info(); - aix_nolabel(); /* %% */ - aix_label = 1; /* %% */ + /*aix_nolabel();*/ /* %% */ + /*aix_label = 1;*/ /* %% */ return 1; } #endif /* AIX_LABEL */ @@ -508,7 +478,7 @@ check_aix_label(void) #define BSD_LINUX_BOOTDIR "/usr/ucb/mdec" -#if defined (i386) || defined (__sparc__) || defined (__arm__) || defined (__mips__) || defined (__s390__) || defined (__sh__) || defined(__x86_64__) +#if defined (i386) || defined (__sparc__) || defined (__arm__) || defined (__m68k__) || defined (__mips__) || defined (__s390__) || defined (__sh__) || defined(__x86_64__) #define BSD_LABELSECTOR 1 #define BSD_LABELOFFSET 0 #elif defined (__alpha__) || defined (__powerpc__) || defined (__ia64__) || defined (__hppa__) @@ -1344,7 +1314,7 @@ xbsd_write_bootstrap(void) /* We need a backup of the disklabel (xbsd_dlabel might have changed). */ d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE]; - bcopy(d, &dl, sizeof(struct xbsd_disklabel)); + memmove(&dl, d, sizeof(struct xbsd_disklabel)); /* The disklabel will be overwritten by 0's from bootxx anyway */ memset(d, 0, sizeof(struct xbsd_disklabel)); @@ -1361,7 +1331,7 @@ xbsd_write_bootstrap(void) exit(EXIT_FAILURE); } - bcopy(&dl, d, sizeof(struct xbsd_disklabel)); + memmove(d, &dl, sizeof(struct xbsd_disklabel)); #if defined (__powerpc__) || defined (__hppa__) sector = 0; @@ -1474,10 +1444,6 @@ xbsd_initlabel(struct partition *p, struct xbsd_disklabel *d) else d->d_type = BSD_DTYPE_ST506; -#if 0 /* not used (at least not written to disk) by NetBSD/i386 1.0 */ - d->d_subtype = BSD_DSTYPE_INDOSPART & pindex; -#endif - #if !defined (__alpha__) d->d_flags = BSD_D_DOSPART; #else @@ -1548,8 +1514,8 @@ xbsd_readlabel (struct partition *p, struct xbsd_disklabel *d) if (BSD_BBSIZE != read(fd, disklabelbuffer, BSD_BBSIZE)) fdisk_fatal(unable_to_read); - bcopy(&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], - d, sizeof(struct xbsd_disklabel)); + memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], + sizeof(struct xbsd_disklabel)); if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC) return 0; @@ -1584,8 +1550,8 @@ xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d) /* This is necessary if we want to write the bootstrap later, otherwise we'd write the old disklabel with the bootstrap. */ - bcopy(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], - sizeof(struct xbsd_disklabel)); + memmove(&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], + d, sizeof(struct xbsd_disklabel)); #if defined (__alpha__) && BSD_LABELSECTOR == 0 alpha_bootblock_checksum (disklabelbuffer); @@ -1786,14 +1752,6 @@ sgi_get_ntrks(void) return SGI_SSWAP16(sgilabel->devparam.ntrks); } -static void -sgi_nolabel(void) -{ - sgilabel->magic = 0; - sgi_label = 0; - partitions = 4; -} - static unsigned int two_s_complement_32bit_sum(unsigned int* base, int size /* in bytes */) { @@ -1818,8 +1776,7 @@ check_sgi_label(void) if (sgilabel->magic != SGI_LABEL_MAGIC && sgilabel->magic != SGI_LABEL_MAGIC_SWAPPED) { - sgi_label = 0; - sgi_other_endian = 0; + current_label_type = label_dos; return 0; } @@ -1833,7 +1790,7 @@ check_sgi_label(void) _("Detected sgi disklabel with wrong checksum.\n")); } update_units(); - sgi_label = 1; + current_label_type = label_sgi; partitions = 16; sgi_volumes = 15; return 1; @@ -2014,7 +1971,7 @@ create_sgiinfo(void) /* I keep SGI's habit to write the sgilabel to the second block */ sgilabel->directory[0].vol_file_start = SGI_SSWAP32(2); sgilabel->directory[0].vol_file_size = SGI_SSWAP32(sizeof(sgiinfo)); - strncpy((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8); + strcpy((char*)sgilabel->directory[0].vol_file_name, "sgilabel"); } static sgiinfo *fill_sgiinfo(void); @@ -2374,7 +2331,7 @@ create_sgilabel(void) "until you decide to write them. After that, of course, the previous\n" "content will be unrecoverably lost.\n\n")); - sgi_other_endian = (BYTE_ORDER == LITTLE_ENDIAN); + sgi_other_endian = (BB_LITTLE_ENDIAN); res = ioctl(fd, BLKGETSIZE, &longsectors); if (!ioctl(fd, HDIO_GETGEO, &geometry)) { heads = geometry.heads; @@ -2445,7 +2402,7 @@ create_sgilabel(void) sgilabel->devparam.xylogics_writecont = SGI_SSWAP16(0); memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 ); memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16 ); - sgi_label = 1; + current_label_type = label_sgi; partitions = 16; sgi_volumes = 15; sgi_set_entire(); @@ -2564,14 +2521,6 @@ set_sun_partition(int i, uint start, uint stop, int sysid) set_changed(i); } -static void -sun_nolabel(void) -{ - sun_label = 0; - sunlabel->magic = 0; - partitions = 4; -} - static int check_sun_label(void) { @@ -2580,7 +2529,7 @@ check_sun_label(void) if (sunlabel->magic != SUN_LABEL_MAGIC && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) { - sun_label = 0; + current_label_type = label_dos; sun_other_endian = 0; return 0; } @@ -2598,7 +2547,7 @@ check_sun_label(void) sectors = SUN_SSWAP16(sunlabel->nsect); } update_units(); - sun_label = 1; + current_label_type = label_sun; partitions = 8; return 1; } @@ -2653,14 +2602,10 @@ sun_autoconfigure_scsi(void) if (!ioctl(fd, SCSI_IOCTL_GET_IDLUN, &id)) { sprintf(buffer, "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n", -#if 0 - ((id[0]>>24)&0xff)-/*PROC_SCSI_SCSI+PROC_SCSI_FILE*/33, -#else /* This is very wrong (works only if you have one HBA), but I haven't found a way how to get hostno from the current kernel */ 0, -#endif (id[0]>>16) & 0xff, id[0] & 0xff, (id[0]>>8) & 0xff @@ -2720,11 +2665,7 @@ create_sunlabel(void) _("Building a new sun disklabel. Changes will remain in memory only,\n" "until you decide to write them. After that, of course, the previous\n" "content won't be recoverable.\n\n")); -#if BYTE_ORDER == LITTLE_ENDIAN - sun_other_endian = 1; -#else - sun_other_endian = 0; -#endif + sun_other_endian = BB_LITTLE_ENDIAN; memset(MBRbuffer, 0, sizeof(MBRbuffer)); sunlabel->magic = SUN_SSWAP16(SUN_LABEL_MAGIC); if (!floppy) { @@ -3505,7 +3446,7 @@ static void menu(void) { #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) { + if (label_sun == current_label_type) { puts(_("Command action")); puts(_("\ta\ttoggle a read only flag")); /* sun */ puts(_("\tb\tedit bsd disklabel")); @@ -3528,7 +3469,7 @@ menu(void) } else #endif #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) { + if (label_sgi == current_label_type) { puts(_("Command action")); puts(_("\ta\tselect bootable partition")); /* sgi flavour */ puts(_("\tb\tedit bootfile entry")); /* sgi */ @@ -3548,7 +3489,7 @@ menu(void) } else #endif #ifdef CONFIG_FEATURE_AIX_LABEL - if (aix_label) { + if (label_aix == current_label_type) { puts(_("Command action")); puts(_("\tm\tprint this menu")); puts(_("\to\tcreate a new empty DOS partition table")); @@ -3586,7 +3527,7 @@ static void xmenu(void) { #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) { + if (label_sun == current_label_type) { puts(_("Command action")); puts(_("\ta\tchange number of alternate cylinders")); /*sun*/ puts(_("\tc\tchange number of cylinders")); @@ -3606,7 +3547,7 @@ xmenu(void) } else #endif #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) { + if (label_sgi == current_label_type) { puts(_("Command action")); puts(_("\tb\tmove beginning of data in a partition")); /* !sun */ puts(_("\tc\tchange number of cylinders")); @@ -3624,7 +3565,7 @@ xmenu(void) } else #endif #ifdef CONFIG_FEATURE_AIX_LABEL - if (aix_label) { + if (label_aix == current_label_type) { puts(_("Command action")); puts(_("\tb\tmove beginning of data in a partition")); /* !sun */ puts(_("\tc\tchange number of cylinders")); @@ -3669,10 +3610,10 @@ get_sys_types(void) { return ( #ifdef CONFIG_FEATURE_SUN_LABEL - sun_label ? sun_sys_types : + label_sun == current_label_type ? sun_sys_types : #endif #ifdef CONFIG_FEATURE_SGI_LABEL - sgi_label ? sgi_sys_types : + label_sgi == current_label_type ? sgi_sys_types : #endif i386_sys_types); } @@ -3699,10 +3640,10 @@ get_sysid(int i) { return ( #ifdef CONFIG_FEATURE_SUN_LABEL - sun_label ? sunlabel->infos[i].id : + label_sun == current_label_type ? sunlabel->infos[i].id : #endif #ifdef CONFIG_FEATURE_SGI_LABEL - sgi_label ? sgi_get_sysid(i) : + label_sgi == current_label_type ? sgi_get_sysid(i) : #endif ptes[i].part_table->sys_ind); } @@ -3829,7 +3770,7 @@ static void update_units(void) static void warn_cylinders(void) { - if (dos_label && cylinders > 1024 && !nowarn) + if (label_dos == current_label_type && cylinders > 1024 && !nowarn) fprintf(stderr, _("\n" "The number of cylinders for this disk is set to %d.\n" "There is nothing wrong with that, but this is larger than 1024,\n" @@ -3947,17 +3888,10 @@ create_doslabel(void) _("Building a new DOS disklabel. Changes will remain in memory only,\n" "until you decide to write them. After that, of course, the previous\n" "content won't be recoverable.\n\n")); -#ifdef CONFIG_FEATURE_SUN_LABEL - sun_nolabel(); /* otherwise always recognised as sun */ -#endif -#ifdef CONFIG_FEATURE_SGI_LABEL - sgi_nolabel(); /* otherwise always recognised as sgi */ -#endif -#ifdef CONFIG_FEATURE_AIX_LABEL - aix_label = 0; -#endif + + current_label_type = label_dos; + #ifdef CONFIG_FEATURE_OSF_LABEL - osf_label = 0; possibly_osf_label = 0; #endif partitions = 4; @@ -4156,7 +4090,7 @@ get_boot(enum action what) if (check_osf_label()) { possibly_osf_label = 1; if (!valid_part_table_flag(MBRbuffer)) { - osf_label = 1; + current_label_type = label_osf; return 0; } printf(_("This disk has both DOS and BSD magic.\n" @@ -4344,19 +4278,33 @@ get_partition(int warn, int max) pe = &ptes[i]; if (warn) { - if ((!sun_label && !sgi_label && !pe->part_table->sys_ind) + if ( + ( + label_sun != current_label_type && + label_sgi != current_label_type && + !pe->part_table->sys_ind + ) #ifdef CONFIG_FEATURE_SUN_LABEL - || (sun_label && - (!sunlabel->partitions[i].num_sectors || - !sunlabel->infos[i].id)) + || ( + label_sun == current_label_type && + ( + !sunlabel->partitions[i].num_sectors + || !sunlabel->infos[i].id + ) + ) #endif #ifdef CONFIG_FEATURE_SGI_LABEL - || (sgi_label && (!sgi_get_num_sectors(i))) + || ( + label_sgi == current_label_type && + !sgi_get_num_sectors(i) + ) #endif - ) + ){ fprintf(stderr, _("Warning: partition %d has empty type\n"), - i+1); + i+1 + ); + } } return i; } @@ -4468,13 +4416,13 @@ delete_partition(int i) pe->changed = 1; #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) { + if (label_sun == current_label_type) { sun_delete_partition(i); return; } #endif #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) { + if (label_sgi == current_label_type) { sgi_delete_partition(i); return; } @@ -4539,7 +4487,7 @@ change_sysid(void) /* If sgi_label then don't use get_existing_partition, let the user select a partition, since get_existing_partition() only works for Linux like partition tables. */ - if (!sgi_label) { + if (label_sgi != current_label_type) { i = get_existing_partition(0, partitions); } else { i = get_partition(0, partitions); @@ -4554,12 +4502,17 @@ change_sysid(void) /* if changing types T to 0 is allowed, then the reverse change must be allowed, too */ - if (!sys && !sgi_label && !sun_label && !get_nr_sects(p)) + if (!sys && label_sgi != current_label_type && + label_sun != current_label_type && !get_nr_sects(p)) + { printf(_("Partition %d does not exist yet!\n"), i + 1); - else while (1) { + }else{ + while (1) { sys = read_hex (get_sys_types()); - if (!sys && !sgi_label && !sun_label) { + if (!sys && label_sgi != current_label_type && + label_sun != current_label_type) + { printf(_("Type 0 means free space to many systems\n" "(but not to Linux). Having partitions of\n" "type 0 is probably unwise. You can delete\n" @@ -4567,7 +4520,7 @@ change_sysid(void) /* break; */ } - if (!sun_label && !sgi_label) { + if (label_sun != current_label_type && label_sgi != current_label_type) { if (IS_EXTENDED(sys) != IS_EXTENDED(p->sys_ind)) { printf(_("You cannot change a partition into" " an extended one or vice versa\n" @@ -4578,33 +4531,39 @@ change_sysid(void) if (sys < 256) { #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label && i == 2 && sys != WHOLE_DISK) + if (label_sun == current_label_type && i == 2 && sys != WHOLE_DISK) printf(_("Consider leaving partition 3 " "as Whole disk (5),\n" "as SunOS/Solaris expects it and " "even Linux likes it.\n\n")); #endif #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label && ((i == 10 && sys != ENTIRE_DISK) - || (i == 8 && sys != 0))) + if (label_sgi == current_label_type && + ( + (i == 10 && sys != ENTIRE_DISK) || + (i == 8 && sys != 0) + ) + ){ printf(_("Consider leaving partition 9 " "as volume header (0),\nand " "partition 11 as entire volume (6)" "as IRIX expects it.\n\n")); + } #endif if (sys == origsys) break; #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) { + if (label_sun == current_label_type) { sun_change_sysid(i, sys); } else #endif #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) { + if (label_sgi == current_label_type) { sgi_change_sysid(i, sys); } else #endif p->sys_ind = sys; + printf(_("Changed system type of partition %d " "to %x (%s)\n"), i + 1, sys, partition_type(sys)); @@ -4614,6 +4573,7 @@ change_sysid(void) dos_changed = 1; break; } + } } } #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ @@ -4678,25 +4638,10 @@ check_consistency(const struct partition *p, int partition) printf(_("logical=(%d, %d, %d)\n"),lec, leh, les); } -#if 0 -/* Beginning on cylinder boundary? */ - if (pbh != !pbc || pbs != 1) { - printf(_("Partition %i does not start on cylinder " - "boundary:\n"), partition + 1); - printf(_(" phys=(%d, %d, %d) "), pbc, pbh, pbs); - printf(_("should be (%d, %d, 1)\n"), pbc, !pbc); - } -#endif - /* Ending on cylinder boundary? */ if (peh != (heads - 1) || pes != sectors) { printf(_("Partition %i does not end on cylinder boundary.\n"), partition + 1); -#if 0 - printf(_(" phys=(%d, %d, %d) "), pec, peh, pes); - printf(_("should be (%d, %d, %d)\n"), - pec, heads - 1, sectors); -#endif } } @@ -4870,14 +4815,14 @@ list_table(int xtra) int i, w; #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) { + if (label_sun == current_label_type) { sun_list_table(xtra); return; } #endif #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) { + if (label_sgi == current_label_type) { sgi_list_table(xtra); return; } @@ -4886,7 +4831,7 @@ list_table(int xtra) list_disk_geometry(); #ifdef CONFIG_FEATURE_OSF_LABEL - if (osf_label) { + if (label_osf == current_label_type) { xbsd_print_disklabel(xtra); return; } @@ -4937,7 +4882,8 @@ list_table(int xtra) /* Is partition table in disk order? It need not be, but... */ /* partition table entries are not checked for correct order if this is a sgi, sun or aix labeled disk... */ - if (dos_label && wrong_p_order(NULL)) { + if (label_dos == current_label_type && wrong_p_order(NULL)) { + /* FIXME */ printf(_("\nPartition table entries are not in disk order\n")); } } @@ -5029,13 +4975,13 @@ verify(void) return; #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) { + if (label_sun == current_label_type) { verify_sun(); return; } #endif #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) { + if (label_sgi == current_label_type) { verify_sgi(1); return; } @@ -5098,7 +5044,7 @@ static void add_partition(int n, int sys) { char mesg[256]; /* 48 does not suffice in Japanese */ - int i, readed = 0; + int i, num_read = 0; struct partition *p = ptes[n].part_table; struct partition *q = ptes[ext_index].part_table; long long llimit; @@ -5147,12 +5093,12 @@ add_partition(int n, int sys) } if (start > limit) break; - if (start >= temp+units_per_sector && readed) { + if (start >= temp+units_per_sector && num_read) { printf(_("Sector %llu is already allocated\n"), (unsigned long long)temp); temp = start; - readed = 0; + num_read = 0; } - if (!readed && start == temp) { + if (!num_read && start == temp) { off_t saved_start; saved_start = start; @@ -5162,9 +5108,9 @@ add_partition(int n, int sys) start = (start - 1) * units_per_sector; if (start < saved_start) start = saved_start; } - readed = 1; + num_read = 1; } - } while (start != temp || !readed); + } while (start != temp || !num_read); if (n > 4) { /* NOT for fifth partition */ struct pte *pe = &ptes[n]; @@ -5216,7 +5162,7 @@ add_partition(int n, int sys) ext_index = n; pen->ext_pointer = p; pe4->offset = extended_offset = start; - pe4->sectorbuffer = xcalloc(1, sector_size); + pe4->sectorbuffer = xzalloc(sector_size); pe4->part_table = pt_offset(pe4->sectorbuffer, 0); pe4->ext_pointer = pe4->part_table + 1; pe4->changed = 1; @@ -5230,7 +5176,7 @@ add_logical(void) if (partitions > 5 || ptes[4].part_table->sys_ind) { struct pte *pe = &ptes[partitions]; - pe->sectorbuffer = xcalloc(1, sector_size); + pe->sectorbuffer = xzalloc(sector_size); pe->part_table = pt_offset(pe->sectorbuffer, 0); pe->ext_pointer = pe->part_table + 1; pe->offset = 0; @@ -5249,19 +5195,19 @@ new_partition(void) return; #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) { + if (label_sun == current_label_type) { add_sun_partition(get_partition(0, partitions), LINUX_NATIVE); return; } #endif #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) { + if (label_sgi == current_label_type) { sgi_add_partition(get_partition(0, partitions), LINUX_NATIVE); return; } #endif #ifdef CONFIG_FEATURE_AIX_LABEL - if (aix_label) { + if (label_aix == current_label_type) { printf(_("\tSorry - this fdisk cannot handle AIX disk labels." "\n\tIf you want to add DOS-type partitions, create" "\n\ta new empty DOS partition table first. (Use o.)" @@ -5320,7 +5266,7 @@ write_table(void) { int i; - if (dos_label) { + if (label_dos == current_label_type) { for (i = 0; i < 3; i++) if (ptes[i].changed) ptes[3].changed = 1; @@ -5334,13 +5280,13 @@ write_table(void) } } #ifdef CONFIG_FEATURE_SGI_LABEL - else if (sgi_label) { + else if (label_sgi == current_label_type) { /* no test on change? the printf below might be mistaken */ sgi_write_table(); } #endif #ifdef CONFIG_FEATURE_SUN_LABEL - else if (sun_label) { + else if (label_sun == current_label_type) { int needw = 0; for (i = 0; i < 8; i++) @@ -5431,7 +5377,7 @@ print_raw(void) printf(_("Device: %s\n"), disk_device); #if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_SUN_LABEL) - if (sun_label || sgi_label) + if (label_sun == current_label_type || label_sgi == current_label_type) print_buffer(MBRbuffer); else #endif @@ -5475,12 +5421,12 @@ xselect(void) switch (c) { case 'a': #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) + if (label_sun == current_label_type) sun_set_alt_cyl(); #endif break; case 'b': - if (dos_label) + if (label_dos == current_label_type) move_begin(get_partition(0, partitions)); break; case 'c': @@ -5488,10 +5434,10 @@ xselect(void) read_int(1, cylinders, 1048576, 0, _("Number of cylinders")); #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) + if (label_sun == current_label_type) sun_set_ncyl(cylinders); #endif - if (dos_label) + if (label_dos == current_label_type) warn_cylinders(); break; case 'd': @@ -5499,20 +5445,20 @@ xselect(void) break; case 'e': #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) + if (label_sgi == current_label_type) sgi_set_xcyl(); - else + else #endif #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) + if (label_sun == current_label_type) sun_set_xcyl(); else #endif - if (dos_label) + if (label_dos == current_label_type) x_list_table(1); break; case 'f': - if (dos_label) + if (label_dos == current_label_type) fix_partition_table_order(); break; case 'g': @@ -5527,19 +5473,19 @@ xselect(void) break; case 'i': #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) + if (label_sun == current_label_type) sun_set_ilfact(); #endif break; case 'o': #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) + if (label_sun == current_label_type) sun_set_rspeed(); #endif break; case 'p': #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) + if (label_sun == current_label_type) list_table(1); else #endif @@ -5570,7 +5516,7 @@ xselect(void) break; case 'y': #ifdef CONFIG_FEATURE_SUN_LABEL - if (sun_label) + if (label_sun == current_label_type) sun_set_pcylcount(); #endif break; @@ -5615,6 +5561,7 @@ is_ide_cdrom_or_tape(const char *device) return is_ide; } + static void try(const char *device, int user_specified) { @@ -5632,8 +5579,9 @@ try(const char *device, int user_specified) close(fd); } else if (gb < 0) { /* no DOS signature */ list_disk_geometry(); - if (aix_label) + if (label_aix == current_label_type){ return; + } #ifdef CONFIG_FEATURE_OSF_LABEL if (btrydev(device) < 0) #endif @@ -5645,8 +5593,9 @@ try(const char *device, int user_specified) close(fd); list_table(0); #ifdef CONFIG_FEATURE_FDISK_WRITABLE - if (!sun_label && partitions > 4) + if (label_sun != current_label_type && partitions > 4){ delete_partition(ext_index); + } #endif } } else { @@ -5766,14 +5715,9 @@ int fdisk_main(int argc, char **argv) } } -#if 0 - printf(_("This kernel finds the sector size itself - " - "-b option ignored\n")); -#else if (user_set_sector_size && argc-optind != 1) printf(_("Warning: the -b (set sector size) option should" " be used with one specified device\n")); -#endif #ifdef CONFIG_FEATURE_FDISK_WRITABLE if (optl) { @@ -5837,13 +5781,14 @@ int fdisk_main(int argc, char **argv) get_boot(fdisk); #ifdef CONFIG_FEATURE_OSF_LABEL - if (osf_label) { + if (label_osf == current_label_type) { /* OSF label, and no DOS label */ printf(_("Detected an OSF/1 disklabel on %s, entering " "disklabel mode.\n"), disk_device); bselect(); - osf_label = 0; + /*Why do we do this? It seems to be counter-intuitive*/ + current_label_type = label_dos; /* If we return we may want to make an empty DOS label? */ } #endif @@ -5853,15 +5798,15 @@ int fdisk_main(int argc, char **argv) c = tolower(read_char(_("Command (m for help): "))); switch (c) { case 'a': - if (dos_label) + if (label_dos == current_label_type) toggle_active(get_partition(1, partitions)); #ifdef CONFIG_FEATURE_SUN_LABEL - else if (sun_label) + else if (label_sun == current_label_type) toggle_sunflags(get_partition(1, partitions), 0x01); #endif #ifdef CONFIG_FEATURE_SGI_LABEL - else if (sgi_label) + else if (label_sgi == current_label_type) sgi_set_bootpartition( get_partition(1, partitions)); #endif @@ -5870,7 +5815,7 @@ int fdisk_main(int argc, char **argv) break; case 'b': #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) { + if (label_sgi == current_label_type) { printf(_("\nThe current boot file is: %s\n"), sgi_get_bootfile()); if (read_chars(_("Please enter the name of the " @@ -5885,15 +5830,15 @@ int fdisk_main(int argc, char **argv) #endif break; case 'c': - if (dos_label) + if (label_dos == current_label_type) toggle_dos_compatibility_flag(); #ifdef CONFIG_FEATURE_SUN_LABEL - else if (sun_label) + else if (label_sun == current_label_type) toggle_sunflags(get_partition(1, partitions), 0x10); #endif #ifdef CONFIG_FEATURE_SGI_LABEL - else if (sgi_label) + else if (label_sgi == current_label_type) sgi_set_swappartition( get_partition(1, partitions)); #endif @@ -5908,7 +5853,7 @@ int fdisk_main(int argc, char **argv) let the user select a partition, since get_existing_partition() only works for Linux-like partition tables */ - if (!sgi_label) { + if (label_sgi != current_label_type) { j = get_existing_partition(1, partitions); } else { j = get_partition(1, partitions); @@ -5922,7 +5867,7 @@ int fdisk_main(int argc, char **argv) break; case 'i': #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) + if (label_sgi == current_label_type) create_sgiinfo(); else #endif @@ -5966,7 +5911,7 @@ int fdisk_main(int argc, char **argv) #ifdef CONFIG_FEATURE_FDISK_ADVANCED case 'x': #ifdef CONFIG_FEATURE_SGI_LABEL - if (sgi_label) { + if (label_sgi == current_label_type) { fprintf(stderr, _("\n\tSorry, no experts menu for SGI " "partition tables available.\n\n"));