]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super-gpt.c
mdadm:it doesn't make sense to set --bitmap twice
[thirdparty/mdadm.git] / super-gpt.c
index 1a2adce075be923fbe8010e6d5f5f52112e1eded..8b080a0597a996b156eca036e427c9312e2e0bc4 100644 (file)
@@ -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, &sector_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;