From 8f64ebd6c137cdcb8a38742b2a70ab57c87ede22 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 10 Sep 2007 11:23:08 +0000 Subject: *** empty log message *** --- src/Makefile.am | 4 +-- src/gpt.c | 104 ++++++++++++++++++++++++++++++++++++++++--------------- src/guid.c | 17 +++++---- src/prototypes.h | 5 +-- 4 files changed, 92 insertions(+), 38 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 86080d0..207f842 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,10 +5,10 @@ # Copyright (c) 2007 James McKenzie , # All rights reserved. # -# $Id: Makefile.am,v 1.4 2007/09/10 09:53:07 root Exp $ +# $Id: Makefile.am,v 1.5 2007/09/10 11:23:08 root Exp $ # # $Log: Makefile.am,v $ -# Revision 1.4 2007/09/10 09:53:07 root +# Revision 1.5 2007/09/10 11:23:08 root # *** empty log message *** # # Revision 1.3 2007/09/09 22:29:50 root diff --git a/src/gpt.c b/src/gpt.c index 1b93dc1..61feb7a 100644 --- a/src/gpt.c +++ b/src/gpt.c @@ -6,11 +6,11 @@ * */ -static char rcsid[] = "$Id: gpt.c,v 1.5 2007/09/10 09:53:07 root Exp $"; +static char rcsid[] = "$Id: gpt.c,v 1.6 2007/09/10 11:23:08 root Exp $"; /* * $Log: gpt.c,v $ - * Revision 1.5 2007/09/10 09:53:07 root + * Revision 1.6 2007/09/10 11:23:08 root * *** empty log message *** * * Revision 1.4 2007/09/09 22:30:05 root @@ -35,41 +35,91 @@ void usage(void) { fprintf(stderr, "Usage:\n" -"gpt disk-device [-l] [-e n] [-m n - +"gpt -h show help\n" +"gpt -d disk-device -l list partitions\n" +"gpt -d disk-device -s print the address of frist usable sector\n" +" on the disk\n" +" the last usable sector on the disk\n" +"gpt -d disk-device -e print the address of the sector after the\n" +" the last usable sector on the disk\n" +"gpt -d disk-device -f n print the lba of sector immediately after\n" +" the end of 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" +" set partiton n, type can either be a named\n" +" type or a hexadecimal GUID\n" +); +exit(1); +} int main (int argc, char *argv[]) { - DISK *d; - - - d = disk_open ("/dev/sda"); - - - new(d); - add (d, 1, "linux-boot","linux-ext3", 10 * 1024 * 2, 30 * 1024 * 2); - show (d); - -#if 0 - + DISK *d=NULL; + GPT_headers h; + GPT_entry e; + int c; + int n; + int aflag=0; + uint64_t start_lba,end_lba; + extern char *optarg; + extern int optind; + + + while ((c=getopt(argc,argv,"d:hlsef:na"))!=EOF) { + switch(c) { + case 'd': + d=disk_open(optarg); + if (!d) { + fprintf(stderr,"failed to open disk %s\n",optarg); + perror("open"); + return -1; + } + break; + case 'e': + if (!d) usage(); + printf("%lld\n",(long long) disk_lbas(d)); + return 0; + case 's': + if (!d) usage(); + h=headers_get(d); + printf("%lld\n",(long long) h.header.first_usable_lba); + return 0; + case 'f': + h=headers_get(d); + n=atoi(optarg); + e=entry_read(d,&h.header,n); + printf("%lld\n",e.end); + return 0; + case 'n': + new(d); + return 0; + case 'a': + aflag++; + break; + case 'l': + show(d); + return 0; + default: + usage(); + } +} - printf ("hecrc=%08x\n", header_calc_ent_crc (d, h)); + if (!aflag) usage(); +if (!d) usage(); +if ((argc-optind)!=5) usage(); - return 0; +start_lba=strtoll(argv[optind+3],NULL,0); +end_lba=strtoll(argv[optind+4],NULL,0); +//printf("%lld %lld\n",(long long)start_lba,(long long) end_lba); -//hexdump(stderr,buf,0,512); - for (j = 0; j < 4; ++j) - { - e = (GPT_entry *) buf; - e += j; - printf ("%d,%d: %s\n", i, j, guid_to_a (e->type)); - } -} +n=atoi(argv[optind]); +modify(d,n,argv[optind+1] ,argv[optind+2],start_lba,end_lba); -#endif +show(d); return 0; } diff --git a/src/guid.c b/src/guid.c index 31fbf00..1cd4642 100644 --- a/src/guid.c +++ b/src/guid.c @@ -66,14 +66,15 @@ a_to_guid (char *a, GUID * g) while (ptr->name) { - if (!strcmp (a, ptr->name)) { - memcpy (g, &ptr->g, sizeof (GUID)); - return 0; - } - ptr++; + if (!strcmp (a, ptr->name)) + { + memcpy (g, &ptr->g, sizeof (GUID)); + return 0; + } + ptr++; } - while ((*a) && (ndigits != 32)) + while (ndigits != 32) { switch (*a) { @@ -112,9 +113,11 @@ a_to_guid (char *a, GUID * g) case 'f': digit[ndigits++] = ((*a) - 'a') + 0xa; break; - defalt: + + default: return -1; } + a++; } for (i = 0; i < 16; ++i) diff --git a/src/prototypes.h b/src/prototypes.h index c4b853a..28fd0fa 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -1,4 +1,5 @@ /* gpt.c */ +void usage(void); int main(int argc, char *argv[]); /* version.c */ /* util.c */ @@ -40,5 +41,5 @@ int entry_empty(GPT_entry *e); void entry_show(GPT_entry *e); /* new.c */ void new(DISK *d); -/* add.c */ -int add(DISK *d, int n, char *name, char *type_guid, int start, int end); +/* modify.c */ +int modify(DISK *d, int n, char *name, char *type_guid, uint64_t start, uint64_t end); -- cgit v1.2.3