From 762907fd59a7458bea74109d37e0f12e8c937a93 Mon Sep 17 00:00:00 2001 From: james Date: Sun, 11 Mar 2012 11:30:50 +0000 Subject: *** empty log message *** --- src/gpt.c | 6 +++++- src/header.c | 33 ++++++++++++++++++++++++++------- src/prototypes.h | 1 + 3 files changed, 32 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/gpt.c b/src/gpt.c index 4a03379..bcdebaa 100644 --- a/src/gpt.c +++ b/src/gpt.c @@ -6,10 +6,13 @@ * */ -static char rcsid[] = "$Id: gpt.c,v 1.21 2012/03/11 11:30:50 james Exp $"; +static char rcsid[] = "$Id: gpt.c,v 1.22 2012/03/11 11:31:24 james Exp $"; /* * $Log: gpt.c,v $ + * Revision 1.22 2012/03/11 11:31:24 james + * *** empty log message *** + * * Revision 1.21 2012/03/11 11:30:50 james * *** empty log message *** * @@ -139,6 +142,7 @@ main (int argc, char *argv[]) if (n) n = header_check_crc (d, &h.header); } + printf("%d\n",n); return n ? 0 : -1; case 'd': diff --git a/src/header.c b/src/header.c index e4a7e15..1d5ef3e 100644 --- a/src/header.c +++ b/src/header.c @@ -67,6 +67,25 @@ header_calc_ent_crc (DISK * d, GPT_header * h) } +int +header_check_crc (DISK * d, GPT_header * h) +{ + GPT_header c = *h; + uint32_t crc; + + c.header_crc = 0; + crc = crc32 (0, &c, sizeof (c)); + + if (crc != h->header_crc) + return 0; + + crc = header_calc_ent_crc (d, h); + + + + return ! !(crc == h->partition_entry_crc); +} + void header_show (DISK * d, GPT_header * h) { @@ -211,17 +230,17 @@ headers_get_one (DISK * d) disk_read (d, buf, 1, 1); memcpy (&ret.header, buf, sizeof (ret.header)); - table_size=ret.header.first_usable_lba; + table_size = ret.header.first_usable_lba; - ret.header.last_usable_lba=lbas-table_size; + ret.header.last_usable_lba = lbas - table_size; - ret.alt_header=ret.header; + ret.alt_header = ret.header; - ret.header.alternate_lba=lbas-1; + ret.header.alternate_lba = lbas - 1; - ret.alt_header.alternate_lba=1; - ret.alt_header.my_lba=lbas-1; - ret.alt_header.partition_entry_lba = (lbas - table_size)+1; + ret.alt_header.alternate_lba = 1; + ret.alt_header.my_lba = lbas - 1; + ret.alt_header.partition_entry_lba = (lbas - table_size) + 1; diff --git a/src/prototypes.h b/src/prototypes.h index 0f4144e..64545b5 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -18,6 +18,7 @@ uint32_t crc32(uint32_t crc, const void *_buf, int len); 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); +int header_check_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); -- cgit v1.2.3