struct MBR *super;
struct GPT *gpt_head;
int to_read;
+ unsigned int sector_size;
free_gpt(st);
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:
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))
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;
unsigned long long curr_part_end;
unsigned all_partitions, entry_size;
unsigned part_nr;
+ unsigned int sector_size = 0;
*endofpart = 0;
BUILD_BUG_ON(sizeof(gpt) != 512);
/* skip protective MBR */
- lseek(fd, 512, SEEK_SET);
+ if (!get_dev_sector_size(fd, NULL, §or_size))
+ return 0;
+ lseek(fd, sector_size, SEEK_SET);
/* read GPT header */
if (read(fd, &gpt, 512) != 512)
return 0;
part = (struct GPT_part_entry *)buf;
+ /* set offset to third block (GPT entries) */
+ lseek(fd, sector_size*2, SEEK_SET);
for (part_nr = 0; part_nr < all_partitions; part_nr++) {
/* read partition entry */
if (read(fd, buf, entry_size) != (ssize_t)entry_size)