X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=super-gpt.c;h=8b080a0597a996b156eca036e427c9312e2e0bc4;hb=5e46202e4ade9b1c42b57d7e8566ac412d654d94;hp=b8c9aae9baeb7e1e0abaa2136bc0a0a5747a2daa;hpb=c9aaf5effb5e4afe5dd1e4d08188140bc596808e;p=thirdparty%2Fmdadm.git diff --git a/super-gpt.c b/super-gpt.c index b8c9aae9..8b080a05 100644 --- a/super-gpt.c +++ b/super-gpt.c @@ -73,36 +73,41 @@ static int load_gpt(struct supertype *st, int fd, char *devname) struct MBR *super; struct GPT *gpt_head; int to_read; + unsigned int sector_size; free_gpt(st); - if (posix_memalign((void**)&super, 512, 32*512) != 0) { - fprintf(stderr, Name ": %s could not allocate superblock\n", - __func__); + if (posix_memalign((void**)&super, 4096, 32*512) != 0) { + pr_err("could not allocate superblock\n"); return 1; } - ioctl(fd, BLKFLSBUF, 0); /* make sure we read current data */ + if (!get_dev_sector_size(fd, devname, §or_size)) { + free(super); + return 1; + } lseek(fd, 0, 0); if (read(fd, super, sizeof(*super)) != sizeof(*super)) { no_read: if (devname) - fprintf(stderr, Name ": Cannot read partition table on %s\n", + pr_err("Cannot read partition table on %s\n", devname); free(super); return 1; } - + if (super->magic != MBR_SIGNATURE_MAGIC || super->parts[0].part_type != MBR_GPT_PARTITION_TYPE) { not_found: if (devname) - fprintf(stderr, Name ": No partition table found on %s\n", + pr_err("No partition table found on %s\n", devname); free(super); return 1; } + /* Set offset to second block (GPT header) */ + lseek(fd, sector_size, SEEK_SET); /* Seem to have GPT, load the header */ gpt_head = (struct GPT*)(super+1); if (read(fd, gpt_head, sizeof(*gpt_head)) != sizeof(*gpt_head)) @@ -114,6 +119,8 @@ static int load_gpt(struct supertype *st, int fd, char *devname) to_read = __le32_to_cpu(gpt_head->part_cnt) * sizeof(struct GPT_part_entry); to_read = ((to_read+511)/512) * 512; + /* Set offset to third block (GPT entries) */ + lseek(fd, sector_size*2, SEEK_SET); if (read(fd, gpt_head+1, to_read) != to_read) goto no_read; @@ -175,7 +182,7 @@ static void getinfo_gpt(struct supertype *st, struct mdinfo *info, char *map) static struct supertype *match_metadata_desc(char *arg) { - struct supertype *st = malloc(sizeof(*st)); + struct supertype *st = xmalloc(sizeof(*st)); if (!st) return st; @@ -196,10 +203,11 @@ static struct supertype *match_metadata_desc(char *arg) static int validate_geometry(struct supertype *st, int level, int layout, int raiddisks, int *chunk, unsigned long long size, + unsigned long long data_offset, char *subdev, unsigned long long *freesize, int verbose) { - fprintf(stderr, Name ": gpt metadata cannot be used this way\n"); + pr_err("gpt metadata cannot be used this way\n"); return 0; } #endif