From 8d4a7ef236ef139929e63d663b9a12871eb83dbb Mon Sep 17 00:00:00 2001 From: james Date: Wed, 6 May 2009 01:12:55 +0000 Subject: *** empty log message *** --- src/gpt.c | 14 +++++++---- src/gpt.h | 7 +++--- src/modify.c | 15 ++++++++++-- src/pmbr.c | 1 + src/prototypes.h | 74 +++++++++++++++++++++++++++++--------------------------- src/sync.c | 6 +++-- 6 files changed, 68 insertions(+), 49 deletions(-) diff --git a/src/gpt.c b/src/gpt.c index b15f5be..20bb552 100644 --- a/src/gpt.c +++ b/src/gpt.c @@ -6,10 +6,13 @@ * */ -static char rcsid[] = "$Id: gpt.c,v 1.14 2008/01/25 03:01:06 james Exp $"; +static char rcsid[] = "$Id: gpt.c,v 1.15 2009/05/06 01:12:55 james Exp $"; /* * $Log: gpt.c,v $ + * Revision 1.15 2009/05/06 01:12:55 james + * *** empty log message *** + * * Revision 1.14 2008/01/25 03:01:06 james * *** empty log message *** * @@ -75,7 +78,7 @@ usage (void) " parition n\n" "gpt -d disk-device -n write a new blank parition table to the disk\n" " the end of parition n\n" - "gpt -d disk-device -a n name type start end\n" + "gpt -d disk-device -a n name type start end [partition-guid]\n" " set partiton n, type can either be a named\n" " type or a hexadecimal GUID\n" "gpt -d disk-device -c fill the PMBR with entries taken from\n" @@ -98,7 +101,7 @@ main (int argc, char *argv[]) extern char *optarg; extern int optind; - fprintf(stderr,"sizeof(off_t)=%d\n",sizeof(off_t)); + fprintf (stderr, "sizeof(off_t)=%d\n", sizeof (off_t)); while ((c = getopt (argc, argv, "d:hlsef:unac")) != EOF) { @@ -168,7 +171,7 @@ main (int argc, char *argv[]) if (!d) usage (); - if ((argc - optind) != 5) + if (((argc - optind) != 5) && ((argc - optind) != 6)) usage (); start_lba = strtoll (argv[optind + 3], NULL, 0); @@ -177,7 +180,8 @@ main (int argc, char *argv[]) n = atoi (argv[optind]); - modify (d, n, argv[optind + 1], argv[optind + 2], start_lba, end_lba); + modify (d, n, argv[optind + 1], argv[optind + 2], start_lba, end_lba, + ((argc - optind) == 6) ? argv[optind + 5] : NULL); show (d); disk_reread_kernel_table (d); diff --git a/src/gpt.h b/src/gpt.h index dff9dc4..04f28d3 100644 --- a/src/gpt.h +++ b/src/gpt.h @@ -87,8 +87,7 @@ typedef struct } PACKED MBR; -typedef struct { - GPT_header header,alt_header; +typedef struct +{ + GPT_header header, alt_header; } GPT_headers; - - diff --git a/src/modify.c b/src/modify.c index 3632ec7..803fb75 100644 --- a/src/modify.c +++ b/src/modify.c @@ -4,7 +4,7 @@ int modify (DISK * d, int n, char *name, char *type_guid, uint64_t start, - uint64_t end) + uint64_t end, char *part_guid) { GPT_headers h; GPT_entry e = { 0 }; @@ -17,7 +17,18 @@ modify (DISK * d, int n, char *name, char *type_guid, uint64_t start, exit (1); } printf ("guid=%s became=%s\n", type_guid, guid_to_a (e.type)); - e.label = guid_random (); + if (part_guid) + { + if (a_to_guid (part_guid, &e.label)) + { + fprintf (stderr, "Partition GUID %s was not parsed\n", part_guid); + exit (1); + } + } + else + { + e.label = guid_random (); + } e.start = start; e.end = end; diff --git a/src/pmbr.c b/src/pmbr.c index b27b3b0..482e696 100644 --- a/src/pmbr.c +++ b/src/pmbr.c @@ -126,6 +126,7 @@ mbr_entry_from_gpt_entry (MBR_entry * m, GPT_header * h, GPT_entry * g, if (type == MBR_PARTITION_TYPE_EFI) { + m->size += m->start - 1; m->start = 1; } diff --git a/src/prototypes.h b/src/prototypes.h index 11b0a69..f740512 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -1,49 +1,51 @@ /* gpt.c */ -void usage(void); -int main(int argc, char *argv[]); +void usage (void); +int main (int argc, char *argv[]); /* version.c */ /* util.c */ -void hexdump(FILE *f, uint8_t *data, int s, int l); -void utf16_to_ascii(void *_u16, int u16_len, void *_u8, int u8_len); -void ascii_to_utf16(void *_u8, int u8_len, void *_u16, int u16_len); +void hexdump (FILE * f, uint8_t * data, int s, int l); +void utf16_to_ascii (void *_u16, int u16_len, void *_u8, int u8_len); +void ascii_to_utf16 (void *_u8, int u8_len, void *_u16, int u16_len); /* guid.c */ -int guid_cmp(GUID *a, GUID *b); -char *guid_to_a(GUID g); -int a_to_guid(char *a, GUID *g); -GUID guid_random(void); +int guid_cmp (GUID * a, GUID * b); +char *guid_to_a (GUID g); +int a_to_guid (char *a, GUID * g); +GUID guid_random (void); /* crc.c */ -uint32_t crc32(uint32_t crc, const void *_buf, int len); +uint32_t crc32 (uint32_t crc, const void *_buf, int len); /* header.c */ -void header_calc_crc(GPT_header *h); -GPT_header header_new(GUID disk_guid, uint64_t lbas, int alt); -uint32_t header_calc_ent_crc(DISK *d, GPT_header *h); -void header_show(DISK *d, GPT_header *h); -int header_validate(DISK *d, GPT_header *h); -void header_redo_ent_crc(DISK *d, GPT_header *h); -void header_write(DISK *d, GPT_header *h); -int headers_validate(DISK *d, GPT_headers *h); -GPT_headers headers_get(DISK *d); +void header_calc_crc (GPT_header * h); +GPT_header header_new (GUID disk_guid, uint64_t lbas, int alt); +uint32_t header_calc_ent_crc (DISK * d, GPT_header * h); +void header_show (DISK * d, GPT_header * h); +int header_validate (DISK * d, GPT_header * h); +void header_redo_ent_crc (DISK * d, GPT_header * h); +void header_write (DISK * d, GPT_header * h); +int headers_validate (DISK * d, GPT_headers * h); +GPT_headers headers_get (DISK * d); /* disk.c */ -DISK *disk_open(char *fn); -void disk_read(DISK *d, void *buf, uint64_t lba, int lbas); -void disk_write(DISK *d, void *buf, uint64_t lba, int lbas); -uint64_t disk_lbas(DISK *d); -int disk_reread_kernel_table(DISK *d); +DISK *disk_open (char *fn); +void disk_read (DISK * d, void *buf, uint64_t lba, int lbas); +void disk_write (DISK * d, void *buf, uint64_t lba, int lbas); +uint64_t disk_lbas (DISK * d); +int disk_reread_kernel_table (DISK * d); /* pmbr.c */ -void mbr_entry_show(MBR_entry *e); -void mbr_show(MBR *m); -MBR mbr_new(uint64_t lbas); -void mbr_entry_from_gpt_entry(MBR_entry *m, GPT_header *h, GPT_entry *g, int bootable, uint8_t type); +void mbr_entry_show (MBR_entry * e); +void mbr_show (MBR * m); +MBR mbr_new (uint64_t lbas); +void mbr_entry_from_gpt_entry (MBR_entry * m, GPT_header * h, GPT_entry * g, + int bootable, uint8_t type); /* show.c */ -void show(DISK *d); +void show (DISK * d); /* entry.c */ -void entry_write(DISK *d, GPT_header *h, int n, GPT_entry *e); -GPT_entry entry_read(DISK *d, GPT_header *h, int n); -int entry_empty(GPT_entry *e); -void entry_show(GPT_entry *e); +void entry_write (DISK * d, GPT_header * h, int n, GPT_entry * e); +GPT_entry entry_read (DISK * d, GPT_header * h, int n); +int entry_empty (GPT_entry * e); +void entry_show (GPT_entry * e); /* new.c */ -void new(DISK *d); +void new (DISK * d); /* modify.c */ -int modify(DISK *d, int n, char *name, char *type_guid, uint64_t start, uint64_t end); +int modify (DISK * d, int n, char *name, char *type_guid, uint64_t start, + uint64_t end, char *part_guid); /* sync.c */ -void sync_tables(DISK *d); +void sync_tables (DISK * d); diff --git a/src/sync.c b/src/sync.c index 4da2560..e98e4a0 100644 --- a/src/sync.c +++ b/src/sync.c @@ -26,8 +26,10 @@ sync_tables (DISK * d) GPT_entry e = entry_read (d, &h.header, i); uint8_t type = 0, bootable = 0; - if (e.start>=2147483648) continue; - if (e.end>=2147483648) continue; + if (e.start >= 2147483648U) + continue; + if (e.end >= 2147483648U) + continue; if (!guid_cmp (&e.type, &guid_efi)) { -- cgit v1.2.3