]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super-gpt.c
imsm: Remove --dump/--restore implementation
[thirdparty/mdadm.git] / super-gpt.c
index 982b4e9b8c33d4b6f309b62face20501953427b2..a1e9aa9dc79a00bb01a5e28e9d779bf4fad3ab83 100644 (file)
@@ -47,7 +47,6 @@ static void free_gpt(struct supertype *st)
        st->sb = NULL;
 }
 
-#ifndef MDASSEMBLE
 static void examine_gpt(struct supertype *st, char *homehost)
 {
        struct GPT *gpt = st->sb + 512;
@@ -66,46 +65,47 @@ static void examine_gpt(struct supertype *st, char *homehost)
                        );
        }
 }
-#endif /* MDASSEMBLE */
 
 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 (st->subarray[0])
+       if (posix_memalign((void**)&super, 4096, 32*512) != 0) {
+               pr_err("could not allocate superblock\n");
                return 1;
+       }
 
-       if (posix_memalign((void**)&super, 512, 32*512) != 0) {
-               fprintf(stderr, Name ": %s could not allocate superblock\n",
-                       __func__);
+       if (!get_dev_sector_size(fd, devname, &sector_size)) {
+               free(super);
                return 1;
        }
 
-       ioctl(fd, BLKFLSBUF, 0); /* make sure we read current data */
-
        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))
@@ -117,6 +117,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;
 
@@ -156,7 +158,7 @@ static int store_gpt(struct supertype *st, int fd)
        return 0;
 }
 
-static void getinfo_gpt(struct supertype *st, struct mdinfo *info)
+static void getinfo_gpt(struct supertype *st, struct mdinfo *info, char *map)
 {
        struct GPT *gpt = st->sb + 512;
        struct GPT_part_entry *gpe = st->sb + 1024;
@@ -178,12 +180,14 @@ static void getinfo_gpt(struct supertype *st, struct mdinfo *info)
 
 static struct supertype *match_metadata_desc(char *arg)
 {
-       struct supertype *st = malloc(sizeof(*st));
+       struct supertype *st = xmalloc(sizeof(*st));
 
        if (!st)
                return st;
-       if (strcmp(arg, "gpt") != 0)
+       if (strcmp(arg, "gpt") != 0) {
+               free(st);
                return NULL;
+       }
 
        st->ss = &gpt;
        st->info = NULL;
@@ -193,22 +197,19 @@ static struct supertype *match_metadata_desc(char *arg)
        return st;
 }
 
-#ifndef MDASSEMBLE
 static int validate_geometry(struct supertype *st, int level,
                             int layout, int raiddisks,
-                            int chunk, unsigned long long size,
+                            int *chunk, unsigned long long size,
+                            unsigned long long data_offset,
                             char *subdev, unsigned long long *freesize,
-                            int verbose)
+                            int consistency_policy, 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
 
 struct superswitch gpt = {
-#ifndef MDASSEMBLE
        .examine_super = examine_gpt,
-#endif
        .validate_geometry = validate_geometry,
        .match_metadata_desc = match_metadata_desc,
        .load_super = load_gpt,