From: Karel Zak Date: Wed, 29 May 2013 11:54:34 +0000 (+0200) Subject: fdisk: (sgi) share disk label definition with libblkid X-Git-Tag: v2.24-rc1~227 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a78651d77883aa123844c7435303789254279ffc;p=thirdparty%2Futil-linux.git fdisk: (sgi) share disk label definition with libblkid Signed-off-by: Karel Zak --- diff --git a/fdisks/fdisksgilabel.c b/fdisks/fdisksgilabel.c index c39d43b30e..335264d52a 100644 --- a/fdisks/fdisksgilabel.c +++ b/fdisks/fdisksgilabel.c @@ -43,7 +43,6 @@ struct fdisk_sgi_label { struct fdisk_label head; /* generic part */ }; - static int other_endian = 0; static short volumes=1; @@ -95,25 +94,26 @@ isinfreelist(unsigned int b) { /* * end of free blocks section */ -static struct fdisk_parttype sgi_parttypes[] = { - {SGI_VOLHDR, N_("SGI volhdr")}, - {0x01, N_("SGI trkrepl")}, - {0x02, N_("SGI secrepl")}, - {SGI_SWAP, N_("SGI raw")}, - {0x04, N_("SGI bsd")}, - {0x05, N_("SGI sysv")}, - {ENTIRE_DISK, N_("SGI volume")}, - {SGI_EFS, N_("SGI efs")}, - {0x08, N_("SGI lvol")}, - {0x09, N_("SGI rlvol")}, - {SGI_XFS, N_("SGI xfs")}, - {SGI_XFSLOG, N_("SGI xfslog")}, - {SGI_XLV, N_("SGI xlv")}, - {SGI_XVM, N_("SGI xvm")}, - {LINUX_SWAP, N_("Linux swap")}, - {LINUX_NATIVE, N_("Linux native")}, - {LINUX_LVM, N_("Linux LVM")}, - {LINUX_RAID, N_("Linux RAID")}, +static struct fdisk_parttype sgi_parttypes[] = +{ + {SGI_TYPE_VOLHDR, N_("SGI volhdr")}, + {SGI_TYPE_TRKREPL, N_("SGI trkrepl")}, + {SGI_TYPE_SECREPL, N_("SGI secrepl")}, + {SGI_TYPE_SWAP, N_("SGI raw")}, + {SGI_TYPE_BSD, N_("SGI bsd")}, + {SGI_TYPE_SYSV, N_("SGI sysv")}, + {SGI_TYPE_ENTIRE_DISK, N_("SGI volume")}, + {SGI_TYPE_EFS, N_("SGI efs")}, + {SGI_TYPE_LVOL, N_("SGI lvol")}, + {SGI_TYPE_RLVOL, N_("SGI rlvol")}, + {SGI_TYPE_XFS, N_("SGI xfs")}, + {SGI_TYPE_XFSLOG, N_("SGI xfslog")}, + {SGI_TYPE_XLV, N_("SGI xlv")}, + {SGI_TYPE_XVM, N_("SGI xvm")}, + {LINUX_SWAP, N_("Linux swap")}, + {LINUX_NATIVE, N_("Linux native")}, + {LINUX_LVM, N_("Linux LVM")}, + {LINUX_RAID, N_("Linux RAID")}, {0, NULL } }; @@ -234,10 +234,10 @@ sgi_list_table(struct fdisk_context *cxt, int xtra) { "----- Directory Entries -----\n"), sgilabel->boot_file); for (i = 0 ; i < (size_t) volumes; i++) { - if (sgilabel->directory[i].vol_file_size) { - uint32_t start = SSWAP32(sgilabel->directory[i].vol_file_start); - uint32_t len = SSWAP32(sgilabel->directory[i].vol_file_size); - unsigned char *name = sgilabel->directory[i].vol_file_name; + if (sgilabel->volume[i].num_bytes) { + uint32_t start = SSWAP32(sgilabel->volume[i].block_num); + uint32_t len = SSWAP32(sgilabel->volume[i].num_bytes); + unsigned char *name = sgilabel->volume[i].name; printf(_("%2zd: %-10s sector%5u size%8u\n"), i, name, (unsigned int) start, (unsigned int) len); @@ -247,30 +247,30 @@ sgi_list_table(struct fdisk_context *cxt, int xtra) { unsigned int sgi_get_start_sector(struct fdisk_context *cxt, int i) { - return SSWAP32(sgilabel->partitions[i].start_sector); + return SSWAP32(sgilabel->partitions[i].first_block); } unsigned int sgi_get_num_sectors(struct fdisk_context *cxt, int i) { - return SSWAP32(sgilabel->partitions[i].num_sectors); + return SSWAP32(sgilabel->partitions[i].num_blocks); } static int sgi_get_sysid(struct fdisk_context *cxt, int i) { - return SSWAP32(sgilabel->partitions[i].id); + return SSWAP32(sgilabel->partitions[i].type); } int sgi_get_bootpartition(struct fdisk_context *cxt) { - return (short) SSWAP16(sgilabel->boot_part); + return (short) SSWAP16(sgilabel->root_part_num); } int sgi_get_swappartition(struct fdisk_context *cxt) { - return (short) SSWAP16(sgilabel->swap_part); + return (short) SSWAP16(sgilabel->swap_part_num); } static unsigned int @@ -337,9 +337,9 @@ sgi_set_bootfile(struct fdisk_context *cxt) void create_sgiinfo(struct fdisk_context *cxt) { /* I keep SGI's habit to write the sgilabel to the second block */ - sgilabel->directory[0].vol_file_start = SSWAP32(2); - sgilabel->directory[0].vol_file_size = SSWAP32(sizeof(sgiinfo)); - strncpy((char *) sgilabel->directory[0].vol_file_name, "sgilabel", 8); + sgilabel->volume[0].block_num = SSWAP32(2); + sgilabel->volume[0].num_bytes = SSWAP32(sizeof(sgiinfo)); + strncpy((char *) sgilabel->volume[0].name, "sgilabel", 8); } @@ -362,13 +362,13 @@ static int sgi_write_disklabel(struct fdisk_context *cxt) goto err; if (write(cxt->dev_fd, sgilabel, SECTOR_SIZE) != SECTOR_SIZE) goto err; - if (!strncmp((char *) sgilabel->directory[0].vol_file_name, "sgilabel", 8)) { + if (!strncmp((char *) sgilabel->volume[0].name, "sgilabel", 8)) { /* * keep this habit of first writing the "sgilabel". * I never tested whether it works without (AN 981002). */ int infostartblock - = SSWAP32(sgilabel->directory[0].vol_file_start); + = SSWAP32(sgilabel->volume[0].block_num); if (lseek(cxt->dev_fd, (off_t) infostartblock * SECTOR_SIZE, SEEK_SET) < 0) @@ -474,7 +474,7 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose) for (i=0; i<16; i++) { if (sgi_get_num_sectors(cxt, i) != 0) { Index[sortcount++]=i; - if (sgi_get_sysid(cxt, i) == ENTIRE_DISK + if (sgi_get_sysid(cxt, i) == SGI_TYPE_ENTIRE_DISK && entire++ == 1) { if (verbose) fdisk_info(cxt, _("More than one entire " @@ -490,7 +490,7 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose) sort(Index, sortcount, sizeof(Index[0]), cxt, compare_start); - if (sgi_get_sysid(cxt, Index[0]) == ENTIRE_DISK) { + if (sgi_get_sysid(cxt, Index[0]) == SGI_TYPE_ENTIRE_DISK) { if (verbose && Index[0] != 10) fdisk_info(cxt, _("IRIX likes when Partition 11 " "covers the entire disk.")); @@ -525,7 +525,7 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose) "cylinder boundary.", Index[i]+1)); /* We cannot handle several "entire disk" entries. */ - if (sgi_get_sysid(cxt, Index[i]) == ENTIRE_DISK) + if (sgi_get_sysid(cxt, Index[i]) == SGI_TYPE_ENTIRE_DISK) continue; if (start > sgi_get_start_sector(cxt, Index[i])) { if (verbose) @@ -575,7 +575,7 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose) || !sgi_get_num_sectors(cxt, sgi_get_swappartition(cxt))) fdisk_info(cxt, _("The swap partition does not exist.")); - else if (sgi_get_sysid(cxt, sgi_get_swappartition(cxt)) != SGI_SWAP + else if (sgi_get_sysid(cxt, sgi_get_swappartition(cxt)) != SGI_TYPE_SWAP && sgi_get_sysid(cxt, sgi_get_swappartition(cxt)) != LINUX_SWAP) fdisk_info(cxt, _("The swap partition has no swap type.")); @@ -610,7 +610,7 @@ sgi_entire(struct fdisk_context *cxt) { int i; for (i=0; i<16; i++) - if (sgi_get_sysid(cxt, i) == SGI_VOLUME) + if (sgi_get_sysid(cxt, i) == SGI_TYPE_ENTIRE_DISK) return i; return -1; } @@ -622,9 +622,9 @@ static int sgi_set_partition(struct fdisk_context *cxt, size_t i, assert(cxt->label); assert(fdisk_is_disklabel(cxt, SGI)); - sgilabel->partitions[i].id = SSWAP32(sys); - sgilabel->partitions[i].num_sectors = SSWAP32(length); - sgilabel->partitions[i].start_sector = SSWAP32(start); + sgilabel->partitions[i].type = SSWAP32(sys); + sgilabel->partitions[i].num_blocks = SSWAP32(length); + sgilabel->partitions[i].first_block = SSWAP32(start); fdisk_label_set_changed(cxt->label, 1); @@ -644,7 +644,7 @@ sgi_set_entire(struct fdisk_context *cxt) { for (n = 10; n < cxt->label->nparts_max; n++) { if (!sgi_get_num_sectors(cxt, n)) { - sgi_set_partition(cxt, n, 0, sgi_get_lastblock(cxt), SGI_VOLUME); + sgi_set_partition(cxt, n, 0, sgi_get_lastblock(cxt), SGI_TYPE_ENTIRE_DISK); break; } } @@ -663,7 +663,7 @@ sgi_set_volhdr(struct fdisk_context *cxt) * as IRIX fx uses. */ if (4096 < sgi_get_lastblock(cxt)) - sgi_set_partition(cxt, n, 0, 4096, SGI_VOLHDR); + sgi_set_partition(cxt, n, 0, 4096, SGI_TYPE_VOLHDR); break; } } @@ -692,14 +692,14 @@ static int sgi_add_partition(struct fdisk_context *cxt, { char mesg[256]; unsigned int first=0, last=0; - int sys = t ? t->type : SGI_XFS; + int sys = t ? t->type : SGI_TYPE_XFS; assert(cxt); assert(cxt->label); assert(fdisk_is_disklabel(cxt, SGI)); if (n == 10) - sys = SGI_VOLUME; + sys = SGI_TYPE_ENTIRE_DISK; else if (n == 8) sys = 0; @@ -708,12 +708,12 @@ static int sgi_add_partition(struct fdisk_context *cxt, "it before re-adding it."), n + 1); return -EINVAL; } - if (sgi_entire(cxt) == -1 && sys != SGI_VOLUME) { + if (sgi_entire(cxt) == -1 && sys != SGI_TYPE_ENTIRE_DISK) { fdisk_info(cxt, _("Attempting to generate entire disk entry automatically.")); sgi_set_entire(cxt); sgi_set_volhdr(cxt); } - if (sgi_gaps(cxt) == 0 && sys != SGI_VOLUME) { + if (sgi_gaps(cxt) == 0 && sys != SGI_TYPE_ENTIRE_DISK) { fdisk_warnx(cxt, _("The entire disk is already covered with partitions.")); return -EINVAL; } @@ -724,7 +724,7 @@ static int sgi_add_partition(struct fdisk_context *cxt, snprintf(mesg, sizeof(mesg), _("First %s"), fdisk_context_get_unit(cxt, SINGULAR)); for (;;) { - if (sys == SGI_VOLUME) { + if (sys == SGI_TYPE_ENTIRE_DISK) { last = sgi_get_lastblock(cxt); first = read_int(cxt, 0, 0, last-1, 0, mesg); if (first != 0) @@ -761,7 +761,7 @@ static int sgi_add_partition(struct fdisk_context *cxt, last *= fdisk_context_get_units_per_sector(cxt); /*else last = last; * align to cylinder if You know how ... */ - if (sys == SGI_VOLUME && (first != 0 || last != sgi_get_lastblock(cxt))) + if (sys == SGI_TYPE_ENTIRE_DISK && (first != 0 || last != sgi_get_lastblock(cxt))) fdisk_info(cxt, _("It is highly recommended that eleventh " "partition covers the entire disk and is of type " "`SGI volume'")); @@ -848,8 +848,8 @@ static int sgi_create_disklabel(struct fdisk_context *cxt) fdisk_zeroize_firstsector(cxt); sgilabel->magic = SSWAP32(SGI_LABEL_MAGIC); - sgilabel->boot_part = SSWAP16(0); - sgilabel->swap_part = SSWAP16(1); + sgilabel->root_part_num = SSWAP16(0); + sgilabel->swap_part_num = SSWAP16(1); /* sizeof(sgilabel->boot_file) = 16 > 6 */ memset(sgilabel->boot_file, 0, 16); @@ -881,7 +881,7 @@ static int sgi_create_disklabel(struct fdisk_context *cxt) sgilabel->devparam.xylogics_gap2 = SSWAP16(0); sgilabel->devparam.xylogics_readgate = SSWAP16(0); sgilabel->devparam.xylogics_writecont = SSWAP16(0); - memset(&(sgilabel->directory), 0, sizeof(struct volume_directory)*15); + memset(&(sgilabel->volume), 0, sizeof(struct sgi_volume) * 15); memset(&(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16); cxt->label->nparts_max = 16; volumes = 15; @@ -974,12 +974,13 @@ static int sgi_set_parttype(struct fdisk_context *cxt, return -EINVAL; } - if ((i == 10 && t->type != ENTIRE_DISK) || (i == 8 && t->type != 0)) + if ((i == 10 && t->type != SGI_TYPE_ENTIRE_DISK) + || (i == 8 && t->type != 0)) fdisk_info(cxt, _("Consider leaving partition 9 as volume header (0), " "and partition 11 as entire volume (6), as IRIX " "expects it.")); - if (((t->type != ENTIRE_DISK) && (t->type != SGI_VOLHDR)) + if (((t->type != SGI_TYPE_ENTIRE_DISK) && (t->type != SGI_TYPE_VOLHDR)) && (sgi_get_start_sector(cxt, i) < 1)) { read_chars(cxt, _("It is highly recommended that the partition at offset 0\n" @@ -990,7 +991,7 @@ static int sgi_set_parttype(struct fdisk_context *cxt, if (strcmp (line_ptr, _("YES\n"))) return 1; } - sgilabel->partitions[i].id = SSWAP32(t->type); + sgilabel->partitions[i].type = SSWAP32(t->type); return 0; } @@ -1026,12 +1027,12 @@ static int sgi_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsign switch (flag) { case SGI_FLAG_BOOT: - sgilabel->boot_part = - (uint16_t) sgilabel->boot_part == SSWAP16(i) ? 0 : SSWAP16(i); + sgilabel->root_part_num = + (uint16_t) sgilabel->root_part_num == SSWAP16(i) ? 0 : SSWAP16(i); break; case SGI_FLAG_SWAP: - sgilabel->swap_part = - (uint16_t) sgilabel->swap_part == SSWAP16(i) ? 0 : SSWAP16(i); + sgilabel->swap_part_num = + (uint16_t) sgilabel->swap_part_num == SSWAP16(i) ? 0 : SSWAP16(i); break; default: return 1; diff --git a/fdisks/fdisksgilabel.h b/fdisks/fdisksgilabel.h index b89012d099..5aaa76df79 100644 --- a/fdisks/fdisksgilabel.h +++ b/fdisks/fdisksgilabel.h @@ -1,55 +1,9 @@ #ifndef FDISK_SGI_LABEL_H #define FDISK_SGI_LABEL_H -#include - #include "bitops.h" +#include "pt-sgi.h" -/* - * Copyright (C) Andreas Neuper, Sep 1998. - * This file may be modified and redistributed under - * the terms of the GNU Public License. - */ - -struct device_parameter { /* 48 bytes */ - unsigned char skew; - unsigned char gap1; - unsigned char gap2; - unsigned char sparecyl; - unsigned short pcylcount; - unsigned short head_vol0; - unsigned short ntrks; /* tracks in cyl 0 or vol 0 */ - unsigned char cmd_tag_queue_depth; - unsigned char unused0; - unsigned short unused1; - unsigned short nsect; /* sectors/tracks in cyl 0 or vol 0 */ - unsigned short bytes; - unsigned short ilfact; - unsigned int flags; /* controller flags */ - unsigned int datarate; - unsigned int retries_on_error; - unsigned int ms_per_word; - unsigned short xylogics_gap1; - unsigned short xylogics_syncdelay; - unsigned short xylogics_readdelay; - unsigned short xylogics_gap2; - unsigned short xylogics_readgate; - unsigned short xylogics_writecont; -}; - -#define SGI_VOLHDR 0x00 -/* 1 and 2 were used for drive types no longer supported by SGI */ -#define SGI_SWAP 0x03 -/* 4 and 5 were for filesystem types SGI haven't ever supported on MIPS CPUs */ -#define SGI_VOLUME 0x06 -#define SGI_EFS 0x07 -#define SGI_LVOL 0x08 -#define SGI_RLVOL 0x09 -#define SGI_XFS 0x0a -#define SGI_XFSLOG 0x0b -#define SGI_XLV 0x0c -#define SGI_XVM 0x0d -#define ENTIRE_DISK SGI_VOLUME /* * controller flags */ @@ -61,26 +15,6 @@ struct device_parameter { /* 48 bytes */ #define RESEEK 0x20 #define CMDTAGQ_ENABLE 0x40 -typedef struct { - unsigned int magic; /* expect SGI_LABEL_MAGIC */ - short boot_part; /* active boot partition */ - short swap_part; /* active swap partition */ - unsigned char boot_file[16]; /* name of the bootfile */ - struct device_parameter devparam; /* 1 * 48 bytes */ - struct volume_directory { /* 15 * 16 bytes */ - unsigned char vol_file_name[8]; /* a character array */ - unsigned int vol_file_start; /* number of logical block */ - unsigned int vol_file_size; /* number of bytes */ - } directory[15]; - struct sgi_partition { /* 16 * 12 bytes */ - unsigned int num_sectors; /* number of blocks */ - unsigned int start_sector; /* must be cylinder aligned */ - unsigned int id; - } partitions[16]; - unsigned int csum; - unsigned int fillbytes; -} sgi_partition; - typedef struct { unsigned int magic; /* looks like a magic number */ unsigned int a2; @@ -110,7 +44,7 @@ typedef struct { #define SGI_FLAG_SWAP 2 /* fdisk.c */ -#define sgilabel ((sgi_partition *)cxt->firstsector) +#define sgilabel ((struct sgi_disklabel *)cxt->firstsector) #define sgiparam (sgilabel->devparam) /* fdisksgilabel.c */ diff --git a/include/pt-sgi.h b/include/pt-sgi.h index 60df11bf39..ec48b7e39b 100644 --- a/include/pt-sgi.h +++ b/include/pt-sgi.h @@ -8,7 +8,11 @@ /* partition types */ enum { SGI_TYPE_VOLHDR = 0x00, + SGI_TYPE_TRKREPL = 0x01, + SGI_TYPE_SECREPL = 0x02, SGI_TYPE_SWAP = 0x03, + SGI_TYPE_BSD = 0x04, + SGI_TYPE_SYSV = 0x05, SGI_TYPE_ENTIRE_DISK = 0x06, SGI_TYPE_EFS = 0x07, SGI_TYPE_LVOL = 0x08,