aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpt.c')
-rw-r--r--src/gpt.c200
1 files changed, 109 insertions, 91 deletions
diff --git a/src/gpt.c b/src/gpt.c
index b81964d..7824fef 100644
--- a/src/gpt.c
+++ b/src/gpt.c
@@ -6,10 +6,13 @@
*
*/
-static char rcsid[] = "$Id: gpt.c,v 1.12 2007/11/12 13:28:04 james Exp $";
+static char rcsid[] = "$Id: gpt.c,v 1.13 2007/11/13 15:18:30 james Exp $";
/*
* $Log: gpt.c,v $
+ * Revision 1.13 2007/11/13 15:18:30 james
+ * *** empty log message ***
+ *
* Revision 1.12 2007/11/12 13:28:04 james
* *** empty log message ***
*
@@ -49,115 +52,130 @@ static char rcsid[] = "$Id: gpt.c,v 1.12 2007/11/12 13:28:04 james Exp $";
#include "project.h"
-void usage(void)
+void
+usage (void)
{
-fprintf(stderr,
-"Usage:\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"
+ fprintf (stderr,
+ "Usage:\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"
#if 0
-"gpt -d disk-device -e print the address of the sector after the\n"
-" the last addressable sector on the disk\n"
+ "gpt -d disk-device -e print the address of the sector after the\n"
+ " the last addressable sector on the disk\n"
#endif
-"gpt -d disk-device -e print the address of the last sector\n"
-" usable in a partition\n"
-"gpt -d disk-device -f n print the lba of the last sector in\n"
-" 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"
-"gpt -d disk-device -c fill the PMBR with entries taken from\n"
-" the first few GPT entries, using dark\n"
-" voodoo\n"
-);
-exit(1);
+ "gpt -d disk-device -e print the address of the last sector\n"
+ " usable in a partition\n"
+ "gpt -d disk-device -f n print the lba of the last sector in\n"
+ " 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"
+ "gpt -d disk-device -c fill the PMBR with entries taken from\n"
+ " the first few GPT entries, using dark\n"
+ " voodoo\n");
+ exit (1);
}
int
main (int argc, char *argv[])
{
- DISK *d=NULL;
+ DISK *d = NULL;
GPT_headers h;
GPT_entry e;
int c;
int n;
- int aflag=0;
- uint64_t start_lba,end_lba;
+ int aflag = 0;
+ uint64_t start_lba, end_lba;
extern char *optarg;
extern int optind;
- while ((c=getopt(argc,argv,"d:hlsef:unac"))!=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();
- h=headers_get(d);
- printf("%lld\n",(long long) h.header.last_usable_lba);
- return 0;
- case 's':
- if (!d) usage();
- h=headers_get(d);
- printf("%lld\n",(long long) h.header.first_usable_lba);
- return 0;
- case 'u':
- if (!d) usage();
- h=headers_get(d);
- printf("%lld\n",(long long) h.header.last_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':
- if (!d) usage();
- new(d);
- return 0;
- case 'a':
- aflag++;
- break;
- case 'l':
- if (!d) usage();
- show(d);
- return 0;
- case 'c':
- if (!d) usage();
- sync_tables(d);
- //show(d);
- return 0;
- default:
- usage();
- }
-}
-
- if (!aflag) usage();
-if (!d) usage();
-
-if ((argc-optind)!=5) usage();
-
-start_lba=strtoll(argv[optind+3],NULL,0);
-end_lba=strtoll(argv[optind+4],NULL,0);
+ while ((c = getopt (argc, argv, "d:hlsef:unac")) != 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 ();
+ h = headers_get (d);
+ printf ("%lld\n", (long long) h.header.last_usable_lba);
+ return 0;
+ case 's':
+ if (!d)
+ usage ();
+ h = headers_get (d);
+ printf ("%lld\n", (long long) h.header.first_usable_lba);
+ return 0;
+ case 'u':
+ if (!d)
+ usage ();
+ h = headers_get (d);
+ printf ("%lld\n", (long long) h.header.last_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':
+ if (!d)
+ usage ();
+ new (d);
+ disk_reread_kernel_table (d);
+ return 0;
+ case 'a':
+ aflag++;
+ break;
+ case 'l':
+ if (!d)
+ usage ();
+ show (d);
+ return 0;
+ case 'c':
+ if (!d)
+ usage ();
+ sync_tables (d);
+ show (d);
+ disk_reread_kernel_table (d);
+ return 0;
+ default:
+ usage ();
+ }
+ }
+
+ if (!aflag)
+ usage ();
+ if (!d)
+ usage ();
+
+ if ((argc - optind) != 5)
+ usage ();
+
+ 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);
-n=atoi(argv[optind]);
+ 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);
-show(d);
-return 0;
+ show (d);
+ disk_reread_kernel_table (d);
+ return 0;
}