]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: move partition types to label specific part
authorKarel Zak <kzak@redhat.com>
Mon, 24 Sep 2012 09:30:26 +0000 (11:30 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 27 Sep 2012 11:38:13 +0000 (13:38 +0200)
 - move MBR partition types to dos_part_types.h
 - make dos_part_types.h independent on datetypes to keep it useful in
   all fdisks
 - add struct fdisk_parrtype
 - move label specific partition types to context->label

Signed-off-by: Karel Zak <kzak@redhat.com>
16 files changed:
fdisks/Makemodule.am
fdisks/cfdisk.c
fdisks/common.h
fdisks/dos_part_types.h [moved from fdisks/i386_sys_types.c with 97% similarity]
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/fdiskaixlabel.h
fdisks/fdiskbsdlabel.c
fdisks/fdiskbsdlabel.h
fdisks/fdiskdoslabel.c
fdisks/fdiskmaclabel.h
fdisks/fdisksgilabel.c
fdisks/fdisksgilabel.h
fdisks/fdisksunlabel.c
fdisks/fdisksunlabel.h
fdisks/sfdisk.c

index f586769125be9ad403b294517a756675d37bb226..26b47b0a72f0fdbfed6fb8d63eec0a05282280b7 100644 (file)
@@ -2,8 +2,7 @@
 fdisk_common_sources = \
        fdisks/common.h \
        fdisks/gpt.c \
-       fdisks/gpt.h \
-       fdisks/i386_sys_types.c
+       fdisks/gpt.h
 
 if !ARCH_M68K
 
index 0ceed33ba735dc380c7b8cb42a0c5df058cea071..9dda1d4f40eaa1282e8bb3d6943fe4617d91c54a 100644 (file)
 #include "mbsalign.h"
 #include "widechar.h"
 
+struct systypes {
+       unsigned char type;
+       char *name;
+};
+
+static struct systypes i386_sys_types[] = {
+       #include "dos_part_types.h"
+};
+
 #ifdef __GNU__
 #define DEFAULT_DEVICE "/dev/hd0"
 #define ALTERNATE_DEVICE "/dev/sd0"
index 352b9a597b58255ebd1ba836d4e1daa050a0b887..9b98f9e5a97daf5e679b418f3420647f438a66c5 100644 (file)
@@ -3,13 +3,6 @@
 
 /* common stuff for fdisk, cfdisk, sfdisk */
 
-struct systypes {
-       unsigned char type;
-       char *name;
-};
-
-extern struct systypes i386_sys_types[];
-
 extern char *partname(char *dev, int pno, int lth);
 
 #endif /* FDISK_COMMON_H */
similarity index 97%
rename from fdisks/i386_sys_types.c
rename to fdisks/dos_part_types.h
index 916daf68bc647a3e88d4b22041e1a7d5b147a930..282adba9133f6918f6fdd3f1129337e34fd7c3e3 100644 (file)
@@ -1,8 +1,3 @@
-/* DOS partition types */
-#include "common.h"
-#include "nls.h"
-
-struct systypes i386_sys_types[] = {
        {0x00, N_("Empty")},
        {0x01, N_("FAT12")},
        {0x02, N_("XENIX root")},
@@ -106,5 +101,5 @@ struct systypes i386_sys_types[] = {
                                               superblock */
        {0xfe, N_("LANstep")},          /* SpeedStor >1024 cyl. or LANstep */
        {0xff, N_("BBT")},              /* Xenix Bad Block Table */
+
        { 0, 0 }
-};
index 3a16c5f22068182c10e737d50df5ab2d73115be0..fe199669807c9a9b1a4fc85319b96cbffcc467d2 100644 (file)
@@ -117,6 +117,8 @@ static const struct menulist_descr menulist[] = {
        {'y', N_("change number of physical cylinders"), {0, SUN_LABEL}},
 };
 
+
+
 sector_t get_nr_sects(struct partition *p) {
        return read4_little_endian(p->size4);
 }
@@ -226,18 +228,11 @@ get_sysid(struct fdisk_context *cxt, int i) {
                ptes[i].part_table->sys_ind);
 }
 
-static struct systypes *
-get_sys_types(void) {
-       return (
-               disklabel == SUN_LABEL ? sun_sys_types :
-               disklabel == SGI_LABEL ? sgi_sys_types :
-               i386_sys_types);
-}
 
-char *partition_type(unsigned char type)
+char *partition_type(struct fdisk_context *cxt, unsigned char type)
 {
        int i;
-       struct systypes *types = get_sys_types();
+       struct fdisk_parttype *types = cxt->label->parttypes;
 
        for (i=0; types[i].name; i++)
                if (types[i].type == type)
@@ -246,8 +241,9 @@ char *partition_type(unsigned char type)
        return NULL;
 }
 
-void list_types(struct systypes *sys)
+void list_types(struct fdisk_context *cxt)
 {
+       struct fdisk_parttype *sys = cxt->label->parttypes;
        unsigned int last[4], done = 0, next = 0, size;
        int i;
 
@@ -563,7 +559,7 @@ read_chars(char *mesg)
 }
 
 int
-read_hex(struct systypes *sys)
+read_hex(struct fdisk_context *cxt)
 {
         int hex;
 
@@ -571,7 +567,7 @@ read_hex(struct systypes *sys)
         {
            read_char(_("Hex code (type L to list codes): "));
            if (tolower(*line_ptr) == 'l')
-               list_types(sys);
+               list_types(cxt);
           else if (isxdigit (*line_ptr))
           {
              hex = 0;
@@ -843,7 +839,7 @@ static void delete_partition(struct fdisk_context *cxt, int partnum)
 
 static void change_sysid(struct fdisk_context *cxt)
 {
-       char *temp;
+       const char *temp;
        int i, sys, origsys;
        struct partition *p;
 
@@ -859,7 +855,7 @@ static void change_sysid(struct fdisk_context *cxt)
        if (!sys && disklabel != SGI_LABEL && disklabel != SUN_LABEL && !get_nr_sects(p))
                 printf(_("Partition %d does not exist yet!\n"), i + 1);
         else while (1) {
-               sys = read_hex (get_sys_types());
+               sys = read_hex (cxt);
 
                if (!sys && disklabel != SGI_LABEL && disklabel != SUN_LABEL) {
                        printf(_("Type 0 means free space to many systems\n"
@@ -901,7 +897,7 @@ static void change_sysid(struct fdisk_context *cxt)
                                p->sys_ind = sys;
                                ptes[i].changed = 1;
                        }
-                       temp = partition_type(sys) ? : _("Unknown");
+                       temp = partition_type(cxt, sys) ? : _("Unknown");
                        if (ptes[i].changed)
                                printf (_("Changed system type of partition %d "
                                        "to %x (%s)\n"), i + 1, sys, temp);
@@ -1223,7 +1219,7 @@ list_table(struct fdisk_context *cxt, int xtra) {
                                - (psects ? 1 : 0)),
 /* odd flag on end */  (unsigned long) pblocks, podd ? '+' : ' ',
 /* type id */          p->sys_ind,
-/* type name */                (type = partition_type(p->sys_ind)) ?
+/* type name */                (type = partition_type(cxt, p->sys_ind)) ?
                        type : _("Unknown"));
                        check_consistency(cxt, p, i);
                        check_alignment(cxt, get_partition_start(pe), i);
@@ -1325,7 +1321,7 @@ void print_partition_size(struct fdisk_context *cxt,
 {
        char *str = size_to_human_string(SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE,
                                     (uint64_t)(stop - start + 1) * cxt->sector_size);
-       printf(_("Partition %d of type %s and of size %s is set\n"), num, partition_type(sysid), str);
+       printf(_("Partition %d of type %s and of size %s is set\n"), num, partition_type(cxt, sysid), str);
        free(str);
 }
 
@@ -1744,7 +1740,7 @@ static void command_prompt(struct fdisk_context *cxt)
                                unknown_command(c);
                        break;
                case 'l':
-                       list_types(get_sys_types());
+                       list_types(cxt);
                        break;
                case 'm':
                        print_menu(MAIN_MENU);
index 05dc8a8e0a13d2c4de28dd6e68a17cdc4a179e34..8221cd9a3868c3cf131d07af104778c24e17a0a2 100644 (file)
@@ -99,6 +99,14 @@ enum failure {
 
 typedef unsigned long long sector_t;
 
+/*
+ * Partition types
+ */
+struct fdisk_parttype {
+       unsigned int    type;           /* type as number or zero */
+       char    *name;                  /* description */
+};
+
 /*
  * Legacy CHS based geometry
  */
@@ -137,6 +145,9 @@ struct fdisk_context {
 struct fdisk_label {
        const char *name;
 
+       /* array with partition types */
+       struct fdisk_parttype   *parttypes;
+
        /* probe disk label */
        int (*probe)(struct fdisk_context *cxt);
        /* write in-memory changes to disk */
@@ -189,10 +200,10 @@ extern void check(struct fdisk_context *cxt, int n, unsigned int h, unsigned int
 extern void change_units(struct fdisk_context *cxt);
 extern void fatal(struct fdisk_context *cxt, enum failure why);
 extern int  get_partition(struct fdisk_context *cxt, int warn, int max);
-extern void list_types(struct systypes *sys);
+extern void list_types(struct fdisk_context *cxt);
 extern int read_line (int *asked);
 extern char read_char(char *mesg);
-extern int read_hex(struct systypes *sys);
+extern int read_hex(struct fdisk_context *cxt);
 extern void reread_partition_table(struct fdisk_context *cxt, int leave);
 extern struct partition *get_part_table(int);
 extern unsigned int read_int(struct fdisk_context *cxt,
@@ -203,7 +214,7 @@ extern void print_partition_size(struct fdisk_context *cxt, int num, sector_t st
 
 extern void fill_bounds(sector_t *first, sector_t *last);
 
-extern char *partition_type(unsigned char type);
+extern char *partition_type(struct fdisk_context *cxt, unsigned char type);
 extern void update_units(struct fdisk_context *cxt);
 extern char read_chars(char *mesg);
 extern void set_changed(int);
index c3af9a0e3edb14533b52216f6e8453ad0df990fb..d0818e7c6b6eae49e6e7ebcc511f52326d9a3ce6 100644 (file)
@@ -20,6 +20,4 @@ struct aix_partition {
 #define        AIX_INFO_MAGIC          0x00072959
 #define        AIX_INFO_MAGIC_SWAPPED  0x59290700
 
-/* fdiskaixlabel.c */
-extern struct  systypes aix_sys_types[];
 #endif /* FDISK_AIX_LABEL_H */
index 442a79f2dd0e5b2200e299e5fee5fb108b391660..c7c13b1b12ab96af1629eb8c7c34f1470f966406 100644 (file)
 static void xbsd_delete_part (struct fdisk_context *cxt, int partnum);
 static void xbsd_edit_disklabel (void);
 static void xbsd_write_bootstrap (struct fdisk_context *cxt);
-static void xbsd_change_fstype (void);
+static void xbsd_change_fstype (struct fdisk_context *cxt);
 static int xbsd_get_part_index (int max);
 static int xbsd_check_new_partition (int *i);
-static void xbsd_list_types (void);
 static unsigned short xbsd_dkcksum (struct xbsd_disklabel *lp);
 static int xbsd_initlabel  (struct fdisk_context *cxt,
                            struct partition *p, struct xbsd_disklabel *d,
@@ -275,7 +274,7 @@ bsd_command_prompt (struct fdisk_context *cxt)
        xbsd_write_bootstrap (cxt);
        break;
       case 'l':
-       xbsd_list_types ();
+       list_types (cxt);
        break;
       case 'n':
              xbsd_add_part (cxt, 0, 0);
@@ -292,7 +291,7 @@ bsd_command_prompt (struct fdisk_context *cxt)
              xbsd_print_disklabel (cxt, 1);
        break;
       case 't':
-       xbsd_change_fstype ();
+       xbsd_change_fstype (cxt);
        break;
       case 'u':
        change_units(cxt);
@@ -560,12 +559,12 @@ xbsd_write_bootstrap (struct fdisk_context *cxt)
 }
 
 static void
-xbsd_change_fstype (void)
+xbsd_change_fstype (struct fdisk_context *cxt)
 {
   int i;
 
   i = xbsd_get_part_index (xbsd_dlabel.d_npartitions);
-  xbsd_dlabel.d_partitions[i].p_fstype = read_hex (xbsd_fstypes);
+  xbsd_dlabel.d_partitions[i].p_fstype = read_hex (cxt);
 }
 
 static int
@@ -612,11 +611,6 @@ xbsd_check_new_partition (int *i) {
        return 1;
 }
 
-static void
-xbsd_list_types (void) {
-       list_types (xbsd_fstypes);
-}
-
 static unsigned short
 xbsd_dkcksum (struct xbsd_disklabel *lp) {
        unsigned short *start, *end;
@@ -846,6 +840,8 @@ alpha_bootblock_checksum (char *boot)
 const struct fdisk_label bsd_label =
 {
        .name = "bsd",
+       .parttypes = xbsd_fstypes,
+
        .probe = osf_probe_label,
        .write = xbsd_write_disklabel,
        .verify = NULL,
index ab6877eaac41ddc4d3760b0d855b4e07f77ac721..9a60c61725d4acab8b7b533ad5583e4574868a2c 100644 (file)
@@ -200,7 +200,7 @@ static char *xbsd_dktypenames[] = {
 #endif
 
 #ifdef DKTYPENAMES
-static struct systypes xbsd_fstypes[] = {
+static struct fdisk_parttype xbsd_fstypes[] = {
         {BSD_FS_UNUSED, "unused"},
        {BSD_FS_SWAP,   "swap"},
        {BSD_FS_V6,     "Version 6"},
index cc17a036d18ff40702fe04cac53bfdf22b1e2c3a..9c08b98697c72f8aaaa1f6cc4058b2c33bfd60dc 100644 (file)
 #include "fdisk.h"
 #include "fdiskdoslabel.h"
 
+static struct fdisk_parttype dos_parttypes[] = {
+       #include "dos_part_types.h"
+};
+
 #define set_hsc(h,s,c,sector) { \
                s = sector % cxt->geom.sectors + 1;                     \
                sector /= cxt->geom.sectors;                            \
@@ -824,6 +828,7 @@ done:
 const struct fdisk_label dos_label =
 {
        .name = "dos",
+       .parttypes = dos_parttypes,
        .probe = dos_probe_label,
        .write = dos_write_disklabel,
        .verify = dos_verify_disklabel,
index 4aaaadd1c674441e51ab856db47f09f5645a703a..4e6fef130344b597bfe60a573f8f35d775fff648 100644 (file)
@@ -28,7 +28,6 @@ struct mac_partition {
 #define        MAC_LABEL_MAGIC_3_SWAPPED       0x0000d405
 
 /* fdiskmaclabel.c */
-extern struct  systypes mac_sys_types[];
 extern void    mac_nolabel(struct fdisk_context *cxt);
 
 #endif /* FDISK_MAC_LABEL_H */
index 7253d21fab035b1b7be986871ee2638f1d63c9c5..d8aabd05db964c1e07e980a68b23211f03dc48bf 100644 (file)
@@ -87,7 +87,7 @@ isinfreelist(unsigned int b) {
 /*
  * end of free blocks section
  */
-struct systypes sgi_sys_types[] = {
+static struct fdisk_parttype sgi_parttypes[] = {
        {SGI_VOLHDR,    N_("SGI volhdr")},
        {0x01,          N_("SGI trkrepl")},
        {0x02,          N_("SGI secrepl")},
@@ -206,7 +206,7 @@ sgi_list_table(struct fdisk_context *cxt, int xtra) {
 /* end */                 (long) scround(start+len)-1,
 /* no odd flag on end */  (long) len,
 /* type id */             sgi_get_sysid(cxt, i),
-/* type name */           (type = partition_type(sgi_get_sysid(cxt, i)))
+/* type name */           (type = partition_type(cxt, sgi_get_sysid(cxt, i)))
                                ? type : _("Unknown"));
                }
        }
@@ -898,6 +898,8 @@ static sgiinfo *fill_sgiinfo(void)
 const struct fdisk_label sgi_label =
 {
        .name = "sgi",
+       .parttypes = sgi_parttypes,
+
        .probe = sgi_probe_label,
        .write = sgi_write_disklabel,
        .verify = sgi_verify_disklabel,
index 4d511139dd0af5e6a6106ac2a7f7938900a9a969..9155a2400d6cf9ee6644b0d5aade38df9dafd5ca 100644 (file)
@@ -110,7 +110,6 @@ typedef struct {
 #define sgiparam (sgilabel->devparam)
 
 /* fdisksgilabel.c */
-extern struct  systypes sgi_sys_types[];
 extern void    sgi_list_table( struct fdisk_context *cxt, int xtra );
 extern int  sgi_change_sysid(struct fdisk_context *cxt, int i, int sys);
 extern unsigned int    sgi_get_start_sector(struct fdisk_context *cxt, int i );
index 9d17ed22ed3ec92dd54b248d77987270124062b7..7ec2d5783a71e7194a0ef5a2e4c0167b6b7df83e 100644 (file)
@@ -27,7 +27,7 @@
 
 static int     other_endian = 0;
 
-struct systypes sun_sys_types[] = {
+static struct fdisk_parttype sun_parttypes[] = {
        {SUN_TAG_UNASSIGNED, N_("Unassigned")},
        {SUN_TAG_BOOT, N_("Boot")},
        {SUN_TAG_ROOT, N_("SunOS root")},
@@ -582,7 +582,7 @@ void sun_list_table(struct fdisk_context *cxt, int xtra)
 /* end */                (unsigned long) scround(start+len),
 /* odd flag on end */    (unsigned long) len / 2, len & 1 ? '+' : ' ',
 /* type id */            SSWAP16(tag->tag),
-/* type name */                  (type = partition_type(SSWAP16(tag->tag)))
+/* type name */                  (type = partition_type(cxt, SSWAP16(tag->tag)))
                                ? type : _("Unknown"));
                }
        }
@@ -652,6 +652,8 @@ int sun_get_sysid(struct fdisk_context *cxt, int i)
 const struct fdisk_label sun_label =
 {
        .name = "sun",
+       .parttypes = sun_parttypes,
+
        .probe = sun_probe_label,
        .write = sun_write_disklabel,
        .verify = sun_verify_disklabel,
index 12cccb146773939267ac0288013f2e113b3379b7..31cb7e89d92d25d2422799a075a11a657a878e75 100644 (file)
@@ -76,7 +76,6 @@ struct sun_disk_label {
 #define sunlabel ((struct sun_disk_label *)cxt->firstsector)
 
 /* fdisksunlabel.c */
-extern struct systypes sun_sys_types[];
 extern int sun_change_sysid(struct fdisk_context *cxt, int i, uint16_t sys);
 extern void sun_list_table(struct fdisk_context *cxt, int xtra);
 extern void sun_set_alt_cyl(struct fdisk_context *cxt);
index da5c60612ae3d340c6d3adeb29415ff4ac46f7d2..28ce2daa8a56e1dc0feefb8a09948f0378fe5c25 100644 (file)
 #include "closestream.h"
 #include "strutils.h"
 
+struct systypes {
+       unsigned char type;
+       char *name;
+};
+
+static struct systypes i386_sys_types[] = {
+       #include "dos_part_types.h"
+};
+
 /*
  * Table of contents:
  *  A. About seeking
@@ -597,7 +606,7 @@ chs_ok(chs a, char *v, char *w) {
 #define BSD_PARTITION          0xa5
 #define NETBSD_PARTITION       0xa9
 
-/* List of partition types now in i386_sys_types.c */
+/* List of partition types */
 
 static const char *
 sysname(unsigned char type) {