diff options
author | Mariusz Dabrowski <mariusz.dabrowski@intel.com> | 2016-12-08 12:13:15 +0100 |
---|---|---|
committer | Jes Sorensen <Jes.Sorensen@redhat.com> | 2016-12-12 20:26:22 +0100 |
commit | 41b06495ba3c6da9bddef7ae89c2c633c4c21c5c (patch) | |
tree | dd3740573d3037a4b715f8cd51bcaac07a3c640e /super-gpt.c | |
parent | imsm: set generation number when reading superblock (diff) | |
download | mdadm-41b06495ba3c6da9bddef7ae89c2c633c4c21c5c.tar.xz mdadm-41b06495ba3c6da9bddef7ae89c2c633c4c21c5c.zip |
Use disk sector size value to set offset for reading GPT
mdadm is using invalid byte-offset while reading GPT header to get
partition info (size, first sector, last sector etc.). Now this offset
is hardcoded to 512 bytes and it is not valid for disks with sector
size different than 512 bytes because MBR and GPT headers are aligned
to LBA, so valid offset for 4k drives is 4096 bytes.
Signed-off-by: Mariusz Dabrowski <mariusz.dabrowski@intel.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Diffstat (limited to 'super-gpt.c')
-rw-r--r-- | super-gpt.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/super-gpt.c b/super-gpt.c index 1a2adce0..8b080a05 100644 --- a/super-gpt.c +++ b/super-gpt.c @@ -73,6 +73,7 @@ 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); @@ -81,6 +82,11 @@ static int load_gpt(struct supertype *st, int fd, char *devname) return 1; } + 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: @@ -100,6 +106,8 @@ static int load_gpt(struct supertype *st, int fd, char *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)) @@ -111,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; |