| OLD | NEW |
| 1 /*- | 1 /*- |
| 2 * Copyright (c) 2002 Marcel Moolenaar | 2 * Copyright (c) 2002 Marcel Moolenaar |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "gpt.h" | 53 #include "gpt.h" |
| 54 | 54 |
| 55 char device_path[MAXPATHLEN]; | 55 char device_path[MAXPATHLEN]; |
| 56 char *device_name; | 56 char *device_name; |
| 57 | 57 |
| 58 off_t mediasz; | 58 off_t mediasz; |
| 59 | 59 |
| 60 u_int parts; | 60 u_int parts; |
| 61 u_int secsz; | 61 u_int secsz; |
| 62 | 62 |
| 63 int» readonly, verbose; | 63 int» readonly, exclusive = O_EXCL, verbose; |
| 64 | 64 |
| 65 static uint32_t crc32_tab[] = { | 65 static uint32_t crc32_tab[] = { |
| 66 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, | 66 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, |
| 67 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, | 67 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, |
| 68 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, | 68 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, |
| 69 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, | 69 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, |
| 70 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | 70 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, |
| 71 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, | 71 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, |
| 72 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, | 72 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, |
| 73 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, | 73 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 free(hdr); | 550 free(hdr); |
| 551 return (0); | 551 return (0); |
| 552 } | 552 } |
| 553 | 553 |
| 554 int | 554 int |
| 555 gpt_open(const char *dev) | 555 gpt_open(const char *dev) |
| 556 { | 556 { |
| 557 struct stat sb; | 557 struct stat sb; |
| 558 int fd, mode; | 558 int fd, mode; |
| 559 | 559 |
| 560 » mode = readonly ? O_RDONLY : O_RDWR|O_EXCL; | 560 » mode = readonly ? O_RDONLY : O_RDWR|exclusive; |
| 561 | 561 |
| 562 strlcpy(device_path, dev, sizeof(device_path)); | 562 strlcpy(device_path, dev, sizeof(device_path)); |
| 563 device_name = device_path; | 563 device_name = device_path; |
| 564 | 564 |
| 565 if ((fd = open(device_path, mode)) != -1) | 565 if ((fd = open(device_path, mode)) != -1) |
| 566 goto found; | 566 goto found; |
| 567 | 567 |
| 568 snprintf(device_path, sizeof(device_path), "%s%s", _PATH_DEV, dev); | 568 snprintf(device_path, sizeof(device_path), "%s%s", _PATH_DEV, dev); |
| 569 device_name = device_path + strlen(_PATH_DEV); | 569 device_name = device_path + strlen(_PATH_DEV); |
| 570 if ((fd = open(device_path, mode)) != -1) | 570 if ((fd = open(device_path, mode)) != -1) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 { cmd_show, "show" }, | 659 { cmd_show, "show" }, |
| 660 { NULL, "verify" }, | 660 { NULL, "verify" }, |
| 661 { NULL, NULL } | 661 { NULL, NULL } |
| 662 }; | 662 }; |
| 663 | 663 |
| 664 static void | 664 static void |
| 665 usage(void) | 665 usage(void) |
| 666 { | 666 { |
| 667 | 667 |
| 668 fprintf(stderr, | 668 fprintf(stderr, |
| 669 » "usage: %s [-rv] [-p nparts] command [options] device ...\n", | 669 » "usage: %s [-rSv] [-p nparts] command [options] device ...\n", |
| 670 getprogname()); | 670 getprogname()); |
| 671 exit(1); | 671 exit(1); |
| 672 } | 672 } |
| 673 | 673 |
| 674 static void | 674 static void |
| 675 prefix(const char *cmd) | 675 prefix(const char *cmd) |
| 676 { | 676 { |
| 677 char *pfx; | 677 char *pfx; |
| 678 const char *prg; | 678 const char *prg; |
| 679 | 679 |
| 680 prg = getprogname(); | 680 prg = getprogname(); |
| 681 pfx = malloc(strlen(prg) + strlen(cmd) + 2); | 681 pfx = malloc(strlen(prg) + strlen(cmd) + 2); |
| 682 /* Don't bother failing. It's not important */ | 682 /* Don't bother failing. It's not important */ |
| 683 if (pfx == NULL) | 683 if (pfx == NULL) |
| 684 return; | 684 return; |
| 685 | 685 |
| 686 sprintf(pfx, "%s %s", prg, cmd); | 686 sprintf(pfx, "%s %s", prg, cmd); |
| 687 setprogname(pfx); | 687 setprogname(pfx); |
| 688 } | 688 } |
| 689 | 689 |
| 690 int | 690 int |
| 691 main(int argc, char *argv[]) | 691 main(int argc, char *argv[]) |
| 692 { | 692 { |
| 693 char *cmd, *p; | 693 char *cmd, *p; |
| 694 int ch, i; | 694 int ch, i; |
| 695 | 695 |
| 696 /* Get the generic options */ | 696 /* Get the generic options */ |
| 697 » while ((ch = getopt(argc, argv, "+p:rv")) != -1) { | 697 » while ((ch = getopt(argc, argv, "+p:rSv")) != -1) { |
| 698 switch(ch) { | 698 switch(ch) { |
| 699 case 'p': | 699 case 'p': |
| 700 if (parts > 0) | 700 if (parts > 0) |
| 701 usage(); | 701 usage(); |
| 702 parts = strtol(optarg, &p, 10); | 702 parts = strtol(optarg, &p, 10); |
| 703 if (*p != 0 || parts < 1) | 703 if (*p != 0 || parts < 1) |
| 704 usage(); | 704 usage(); |
| 705 break; | 705 break; |
| 706 case 'r': | 706 case 'r': |
| 707 readonly = 1; | 707 readonly = 1; |
| 708 break; | 708 break; |
| 709 case 'S': |
| 710 exclusive = 0; |
| 711 break; |
| 709 case 'v': | 712 case 'v': |
| 710 verbose++; | 713 verbose++; |
| 711 break; | 714 break; |
| 712 default: | 715 default: |
| 713 usage(); | 716 usage(); |
| 714 } | 717 } |
| 715 } | 718 } |
| 716 if (!parts) | 719 if (!parts) |
| 717 parts = 128; | 720 parts = 128; |
| 718 | 721 |
| 719 if (argc == optind) | 722 if (argc == optind) |
| 720 usage(); | 723 usage(); |
| 721 | 724 |
| 722 cmd = argv[optind++]; | 725 cmd = argv[optind++]; |
| 723 for (i = 0; cmdsw[i].name != NULL && strcmp(cmd, cmdsw[i].name); i++); | 726 for (i = 0; cmdsw[i].name != NULL && strcmp(cmd, cmdsw[i].name); i++); |
| 724 | 727 |
| 725 if (cmdsw[i].fptr == NULL) | 728 if (cmdsw[i].fptr == NULL) |
| 726 errx(1, "unknown command: %s", cmd); | 729 errx(1, "unknown command: %s", cmd); |
| 727 | 730 |
| 728 prefix(cmd); | 731 prefix(cmd); |
| 729 return ((*cmdsw[i].fptr)(argc, argv)); | 732 return ((*cmdsw[i].fptr)(argc, argv)); |
| 730 } | 733 } |
| OLD | NEW |