diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2016-01-18 02:16:07 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2016-01-18 02:16:07 +0000 |
commit | 9f8dcb1cb4acf6efec415fa779c537ef0008c42a (patch) | |
tree | e1c6e01d548739cad41d94415e9d30ff5f91c7dd /sbin/pdisk/pdisk.c | |
parent | f19703a3fcbc68b9d4d7192d994bae6183815ff1 (diff) |
Run indent(1) over it and tweak the results a bit manually to look more
KNF'ish.
Diffstat (limited to 'sbin/pdisk/pdisk.c')
-rw-r--r-- | sbin/pdisk/pdisk.c | 1154 |
1 files changed, 573 insertions, 581 deletions
diff --git a/sbin/pdisk/pdisk.c b/sbin/pdisk/pdisk.c index fa9ed91c840..6fd98ba2f96 100644 --- a/sbin/pdisk/pdisk.c +++ b/sbin/pdisk/pdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pdisk.c,v 1.46 2016/01/18 00:19:29 krw Exp $ */ +/* $OpenBSD: pdisk.c,v 1.47 2016/01/18 02:16:06 krw Exp $ */ /* * pdisk - an editor for Apple format partition tables @@ -29,7 +29,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/param.h> /* DEV_BSIZE */ +#include <sys/param.h> /* DEV_BSIZE */ #include <err.h> #include <stdio.h> @@ -45,705 +45,697 @@ #include "validate.h" #include "file_media.h" -int lflag; /* list the device */ -int dflag; /* turn on debugging commands and printout */ -int rflag; /* open device read Only */ - -static int first_get = 1; - -void do_change_map_size(struct partition_map_header *); -void do_create_partition(struct partition_map_header *, int); -void do_delete_partition(struct partition_map_header *); -void do_display_block(struct partition_map_header *, char *); -void do_display_entry(struct partition_map_header *); -void do_examine_patch_partition(struct partition_map_header *); -int do_expert(struct partition_map_header *, char *); -void do_rename_partition(struct partition_map_header *); -void do_change_type(struct partition_map_header *); -void do_reorder(struct partition_map_header *); -void do_write_partition_map(struct partition_map_header *); -void edit(char *); -int get_base_argument(long *, struct partition_map_header *); -int get_command_line(int *, char ***); -int get_size_argument(long *, struct partition_map_header *); -void print_edit_notes(void); -void print_expert_notes(void); +int lflag; /* list the device */ +int dflag; /* turn on debugging commands and printout */ +int rflag; /* open device read Only */ + +static int first_get = 1; + +void do_change_map_size(struct partition_map_header *); +void do_create_partition(struct partition_map_header *, int); +void do_delete_partition(struct partition_map_header *); +void do_display_block(struct partition_map_header *, char *); +void do_display_entry(struct partition_map_header *); +void do_examine_patch_partition(struct partition_map_header *); +int do_expert (struct partition_map_header *, char *); +void do_rename_partition(struct partition_map_header *); +void do_change_type(struct partition_map_header *); +void do_reorder(struct partition_map_header *); +void do_write_partition_map(struct partition_map_header *); +void edit(char *); +int get_base_argument(long *, struct partition_map_header *); +int get_command_line(int *, char ***); +int get_size_argument(long *, struct partition_map_header *); +void print_edit_notes(void); +void print_expert_notes(void); __dead static void usage(void); int main(int argc, char **argv) { - int c, name_index; - - if (sizeof(struct dpme) != DEV_BSIZE) { - errx(1, "Size of partition map entry (%zu) " - "is not equal to block size (%d)\n", - sizeof(struct dpme), DEV_BSIZE); - } - if (sizeof(struct block0) != DEV_BSIZE) { - errx(1, "Size of block zero structure (%zu) " - "is not equal to block size (%d)\n", - sizeof(struct block0), DEV_BSIZE); - } - - while ((c = getopt(argc, argv, "ldr")) != -1) { - switch (c) { - case 'l': - lflag = 1; - break; - case 'd': - dflag = 1; - break; - case 'r': - rflag = 1; - break; - default: - usage(); - break; - } - } - - name_index = optind; - - if (lflag) { - if (name_index < argc) { - while (name_index < argc) { - dump(argv[name_index++]); - } - } else { - usage(); + int c, name_index; + + if (sizeof(struct dpme) != DEV_BSIZE) { + errx(1, "Size of partition map entry (%zu) is not equal " + "to block size (%d)\n", sizeof(struct dpme), DEV_BSIZE); } - } else if (name_index < argc) { - while (name_index < argc) { - edit(argv[name_index++]); + if (sizeof(struct block0) != DEV_BSIZE) { + errx(1, "Size of block zero structure (%zu) is not equal " + "to block size (%d)\n", sizeof(struct block0), DEV_BSIZE); + } + while ((c = getopt(argc, argv, "ldr")) != -1) { + switch (c) { + case 'l': + lflag = 1; + break; + case 'd': + dflag = 1; + break; + case 'r': + rflag = 1; + break; + default: + usage(); + break; + } } - } else { - usage(); - } - return 0; -} + name_index = optind; + + if (lflag) { + if (name_index < argc) { + while (name_index < argc) { + dump(argv[name_index++]); + } + } else { + usage(); + } + } else if (name_index < argc) { + while (name_index < argc) { + edit(argv[name_index++]); + } + } else { + usage(); + } + return 0; +} void print_edit_notes() { - printf("Notes:\n"); - printf(" Base and length fields are blocks, which vary in size between media.\n"); - printf(" The base field can be <nth>p; i.e. use the base of the nth partition.\n"); - printf(" The length field can be a length followed by k, m, g or t to indicate\n"); - printf(" kilo, mega, giga, or tera bytes; also the length can be <nth>p; i.e. use\n"); - printf(" the length of the nth partition.\n"); - printf(" The name of a partition is descriptive text.\n"); - printf("\n"); + printf("Notes:\n"); + printf(" Base and length fields are blocks, which vary in size " + "between media.\n"); + printf(" The base field can be <nth>p; i.e. use the base of the " + "nth partition.\n"); + printf(" The length field can be a length followed by k, m, g or " + "t to indicate\n"); + printf(" kilo, mega, giga, or tera bytes; also the length can be " + "<nth>p; i.e. use\n"); + printf(" the length of the nth partition.\n"); + printf(" The name of a partition is descriptive text.\n"); + printf("\n"); } - /* * Edit the file */ void edit(char *name) { - struct partition_map_header *map; - int command; - int order; - int get_type; - int valid_file; - - map = open_partition_map(name, &valid_file); - if (!valid_file) { - return; - } - - printf("Edit %s -\n", name); - - while (get_command("Command (? for help): ", first_get, &command)) { - first_get = 0; - order = 1; - get_type = 0; - - switch (command) { - case '?': - print_edit_notes(); - /* fall through */ - case 'H': - case 'h': - printf("Commands are:\n"); - printf(" C (create with type also specified)\n"); - printf(" c create new partition (standard OpenBSD root)\n"); - printf(" d delete a partition\n"); - printf(" h help\n"); - printf(" i initialize partition map\n"); - printf(" n (re)name a partition\n"); - printf(" P (print ordered by base address)\n"); - printf(" p print the partition table\n"); - printf(" q quit editing\n"); - printf(" r reorder partition entry in map\n"); - printf(" s change size of partition map\n"); - printf(" t change a partition's type\n"); - if (!rflag) { - printf(" w write the partition table\n"); - } - if (dflag) { - printf(" x extra extensions for experts\n"); - } - break; - case 'P': - order = 0; - /* fall through */ - case 'p': - dump_partition_map(map, order); - break; - case 'Q': - case 'q': - if (map && map->changed) { - if (get_okay("Discard changes? [n/y]: ", 0) != 1) { - break; - } - } - flush_to_newline(1); - goto finis; - break; - case 'I': - case 'i': - map = init_partition_map(name, map); - break; - case 'C': - get_type = 1; - /* fall through */ - case 'c': - do_create_partition(map, get_type); - break; - case 'N': - case 'n': - do_rename_partition(map); - break; - case 'D': - case 'd': - do_delete_partition(map); - break; - case 'R': - case 'r': - do_reorder(map); - break; - case 'S': - case 's': - do_change_map_size(map); - break; - case 'T': - case 't': - do_change_type(map); - break; - case 'X': - case 'x': - if (!dflag) { - goto do_error; - } else if (do_expert(map, name)) { - flush_to_newline(1); - goto finis; - } - break; - case 'W': - case 'w': - if (!rflag) { - do_write_partition_map(map); - } else { - goto do_error; - } - break; - default: + struct partition_map_header *map; + int command, order, get_type, valid_file; + + map = open_partition_map(name, &valid_file); + if (!valid_file) { + return; + } + printf("Edit %s -\n", name); + + while (get_command("Command (? for help): ", first_get, &command)) { + first_get = 0; + order = 1; + get_type = 0; + + switch (command) { + case '?': + print_edit_notes(); + /* fall through */ + case 'H': + case 'h': + printf("Commands are:\n"); + printf(" C (create with type also specified)\n"); + printf(" c create new partition (standard OpenBSD " + "root)\n"); + printf(" d delete a partition\n"); + printf(" h help\n"); + printf(" i initialize partition map\n"); + printf(" n (re)name a partition\n"); + printf(" P (print ordered by base address)\n"); + printf(" p print the partition table\n"); + printf(" q quit editing\n"); + printf(" r reorder partition entry in map\n"); + printf(" s change size of partition map\n"); + printf(" t change a partition's type\n"); + if (!rflag) { + printf(" w write the partition table\n"); + } + if (dflag) { + printf(" x extra extensions for experts\n"); + } + break; + case 'P': + order = 0; + /* fall through */ + case 'p': + dump_partition_map(map, order); + break; + case 'Q': + case 'q': + if (map && map->changed) { + if (get_okay("Discard changes? [n/y]: ", 0) != + 1) { + break; + } + } + flush_to_newline(1); + goto finis; + break; + case 'I': + case 'i': + map = init_partition_map(name, map); + break; + case 'C': + get_type = 1; + /* fall through */ + case 'c': + do_create_partition(map, get_type); + break; + case 'N': + case 'n': + do_rename_partition(map); + break; + case 'D': + case 'd': + do_delete_partition(map); + break; + case 'R': + case 'r': + do_reorder(map); + break; + case 'S': + case 's': + do_change_map_size(map); + break; + case 'T': + case 't': + do_change_type(map); + break; + case 'X': + case 'x': + if (!dflag) { + goto do_error; + } else if (do_expert(map, name)) { + flush_to_newline(1); + goto finis; + } + break; + case 'W': + case 'w': + if (!rflag) { + do_write_partition_map(map); + } else { + goto do_error; + } + break; + default: do_error: - bad_input("No such command (%c)", command); - break; + bad_input("No such command (%c)", command); + break; + } } - } finis: - close_partition_map(map); + close_partition_map(map); } void -do_create_partition(struct partition_map_header *map, int get_type) +do_create_partition(struct partition_map_header * map, int get_type) { - long base; - long length; - char *name = 0; - char *type_name = 0; - - if (map == NULL) { - bad_input("No partition map exists"); - return; - } - if (!rflag && map->writable == 0) { - printf("The map is not writable.\n"); - } - if (get_base_argument(&base, map) == 0) { - return; - } - if (get_size_argument(&length, map) == 0) { - return; - } + long base, length; + char *name = NULL; + char *type_name = NULL; - if (get_string_argument("Name of partition: ", &name, 1) == 0) { - bad_input("Bad name"); - return; - } - if (get_type == 0) { - add_partition_to_map(name, kUnixType, base, length, map); - } else if (get_string_argument("Type of partition: ", &type_name, 1) == 0) { - bad_input("Bad type"); - goto xit1; - } else { - if (strncasecmp(type_name, kFreeType, DPISTRLEN) == 0) { - bad_input("Can't create a partition with the Free type"); - goto xit2; - } - if (strncasecmp(type_name, kMapType, DPISTRLEN) == 0) { - bad_input("Can't create a partition with the Map type"); - goto xit2; - } - add_partition_to_map(name, type_name, base, length, map); - } + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + if (!rflag && map->writable == 0) { + printf("The map is not writable.\n"); + } + if (get_base_argument(&base, map) == 0) { + return; + } + if (get_size_argument(&length, map) == 0) { + return; + } + if (get_string_argument("Name of partition: ", &name, 1) == 0) { + bad_input("Bad name"); + return; + } + if (get_type == 0) { + add_partition_to_map(name, kUnixType, base, length, map); + } else if (get_string_argument("Type of partition: ", &type_name, 1) == + 0) { + bad_input("Bad type"); + goto xit1; + } else { + if (strncasecmp(type_name, kFreeType, DPISTRLEN) == 0) { + bad_input("Can't create a partition with the Free " + "type"); + goto xit2; + } + if (strncasecmp(type_name, kMapType, DPISTRLEN) == 0) { + bad_input("Can't create a partition with the Map " + "type"); + goto xit2; + } + add_partition_to_map(name, type_name, base, length, map); + } xit2: - free(type_name); + free(type_name); xit1: - free(name); - return; + free(name); + return; } - int -get_base_argument(long *number, struct partition_map_header *map) +get_base_argument(long *number, struct partition_map_header * map) { - struct partition_map * entry; - int result = 0; - - if (get_number_argument("First block: ", number, kDefault) == 0) { - bad_input("Bad block number"); - } else { - result = 1; - if (get_partition_modifier()) { - entry = find_entry_by_disk_address(*number, map); - if (entry == NULL) { - bad_input("Bad partition number"); - result = 0; - } else { - *number = entry->data->dpme_pblock_start; - } + struct partition_map *entry; + int result = 0; + + if (get_number_argument("First block: ", number, kDefault) == 0) { + bad_input("Bad block number"); + } else { + result = 1; + if (get_partition_modifier()) { + entry = find_entry_by_disk_address(*number, map); + if (entry == NULL) { + bad_input("Bad partition number"); + result = 0; + } else { + *number = entry->data->dpme_pblock_start; + } + } } - } - return result; + return result; } int -get_size_argument(long *number, struct partition_map_header *map) +get_size_argument(long *number, struct partition_map_header * map) { - struct partition_map * entry; - int result = 0; - unsigned long multiple; - - if (get_number_argument("Length in blocks: ", number, kDefault) == 0) { - bad_input("Bad length"); - } else { - multiple = get_multiplier(map->logical_block); - if (multiple == 0) { - bad_input("Bad multiplier"); - } else if (multiple != 1) { - *number *= multiple; - result = 1; - } else if (get_partition_modifier()) { - entry = find_entry_by_disk_address(*number, map); - if (entry == NULL) { - bad_input("Bad partition number"); - } else { - *number = entry->data->dpme_pblocks; - result = 1; - } + struct partition_map *entry; + unsigned long multiple; + int result = 0; + + if (get_number_argument("Length in blocks: ", number, kDefault) == 0) { + bad_input("Bad length"); } else { - result = 1; + multiple = get_multiplier(map->logical_block); + if (multiple == 0) { + bad_input("Bad multiplier"); + } else if (multiple != 1) { + *number *= multiple; + result = 1; + } else if (get_partition_modifier()) { + entry = find_entry_by_disk_address(*number, map); + if (entry == NULL) { + bad_input("Bad partition number"); + } else { + *number = entry->data->dpme_pblocks; + result = 1; + } + } else { + result = 1; + } } - } - return result; + return result; } void -do_rename_partition(struct partition_map_header *map) +do_rename_partition(struct partition_map_header * map) { - struct partition_map * entry; - long ix; - char *name; - - if (map == NULL) { - bad_input("No partition map exists"); - return; - } - if (!rflag && map->writable == 0) { - printf("The map is not writable.\n"); - } - if (get_number_argument("Partition number: ", &ix, kDefault) == 0) { - bad_input("Bad partition number"); - return; - } - if (get_string_argument("New name of partition: ", &name, 1) == 0) { - bad_input("Bad name"); - return; - } + struct partition_map *entry; + char *name; + long ix; + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + if (!rflag && map->writable == 0) { + printf("The map is not writable.\n"); + } + if (get_number_argument("Partition number: ", &ix, kDefault) == 0) { + bad_input("Bad partition number"); + return; + } + if (get_string_argument("New name of partition: ", &name, 1) == 0) { + bad_input("Bad name"); + return; + } /* find partition and change it */ - entry = find_entry_by_disk_address(ix, map); - if (entry == NULL) { - printf("No such partition\n"); - } else { - /* stuff name into partition map entry data */ - strncpy(entry->data->dpme_name, name, DPISTRLEN); - map->changed = 1; - } - free(name); - return; + entry = find_entry_by_disk_address(ix, map); + if (entry == NULL) { + printf("No such partition\n"); + } else { + /* stuff name into partition map entry data */ + strncpy(entry->data->dpme_name, name, DPISTRLEN); + map->changed = 1; + } + free(name); + return; } void -do_change_type(struct partition_map_header *map) +do_change_type(struct partition_map_header * map) { - struct partition_map * entry; - long ix; - char *type = NULL; - - if (map == NULL) { - bad_input("No partition map exists"); - return; - } - - if (!rflag && map->writable == 0) { - printf("The map is not writable.\n"); - } + struct partition_map *entry; + char *type = NULL; + long ix; - if (get_number_argument("Partition number: ", &ix, kDefault) == 0) { - bad_input("Bad partition number"); - return; - } - - entry = find_entry_by_disk_address(ix, map); - - if (entry == NULL ) { - printf("No such partition\n"); - goto out; - } - - printf("Existing partition type ``%s''.\n", entry->data->dpme_type); - if (get_string_argument("New type of partition: ", &type, 1) == 0) { - bad_input("Bad type"); - goto out; - } + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + if (!rflag && map->writable == 0) { + printf("The map is not writable.\n"); + } + if (get_number_argument("Partition number: ", &ix, kDefault) == 0) { + bad_input("Bad partition number"); + return; + } + entry = find_entry_by_disk_address(ix, map); - strncpy(entry->data->dpme_type, type, DPISTRLEN); - map->changed = 1; + if (entry == NULL) { + printf("No such partition\n"); + goto out; + } + printf("Existing partition type ``%s''.\n", entry->data->dpme_type); + if (get_string_argument("New type of partition: ", &type, 1) == 0) { + bad_input("Bad type"); + goto out; + } + strncpy(entry->data->dpme_type, type, DPISTRLEN); + map->changed = 1; out: - free(type); - return; + free(type); + return; } void -do_delete_partition(struct partition_map_header *map) +do_delete_partition(struct partition_map_header * map) { - struct partition_map * cur; - long ix; - - if (map == NULL) { - bad_input("No partition map exists"); - return; - } - if (!rflag && map->writable == 0) { - printf("The map is not writable.\n"); - } - if (get_number_argument("Partition number: ", &ix, kDefault) == 0) { - bad_input("Bad partition number"); - return; - } + struct partition_map *cur; + long ix; + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + if (!rflag && map->writable == 0) { + printf("The map is not writable.\n"); + } + if (get_number_argument("Partition number: ", &ix, kDefault) == 0) { + bad_input("Bad partition number"); + return; + } /* find partition and delete it */ - cur = find_entry_by_disk_address(ix, map); - if (cur == NULL) { - printf("No such partition\n"); - } else { - delete_partition_from_map(cur); - } + cur = find_entry_by_disk_address(ix, map); + if (cur == NULL) { + printf("No such partition\n"); + } else { + delete_partition_from_map(cur); + } } void -do_reorder(struct partition_map_header *map) +do_reorder(struct partition_map_header * map) { - long old_index; - long ix; - - if (map == NULL) { - bad_input("No partition map exists"); - return; - } - if (!rflag && map->writable == 0) { - printf("The map is not writable.\n"); - } - if (get_number_argument("Partition number: ", &old_index, kDefault) == 0) { - bad_input("Bad partition number"); - return; - } - if (get_number_argument("New number: ", &ix, kDefault) == 0) { - bad_input("Bad partition number"); - return; - } + long ix, old_index; - move_entry_in_map(old_index, ix, map); + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + if (!rflag && map->writable == 0) { + printf("The map is not writable.\n"); + } + if (get_number_argument("Partition number: ", &old_index, kDefault) == + 0) { + bad_input("Bad partition number"); + return; + } + if (get_number_argument("New number: ", &ix, kDefault) == 0) { + bad_input("Bad partition number"); + return; + } + move_entry_in_map(old_index, ix, map); } void -do_write_partition_map(struct partition_map_header *map) +do_write_partition_map(struct partition_map_header * map) { - if (map == NULL) { - bad_input("No partition map exists"); - return; - } - if (map->changed == 0 && map->written == 0) { - bad_input("The map has not been changed."); - return; - } - if (map->writable == 0) { - bad_input("The map is not writable."); - return; - } - printf("Writing the map destroys what was there before. "); - if (get_okay("Is that okay? [n/y]: ", 0) != 1) { - return; - } - - write_partition_map(map); + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + if (map->changed == 0 && map->written == 0) { + bad_input("The map has not been changed."); + return; + } + if (map->writable == 0) { + bad_input("The map is not writable."); + return; + } + printf("Writing the map destroys what was there before. "); + if (get_okay("Is that okay? [n/y]: ", 0) != 1) { + return; + } + write_partition_map(map); - map->changed = 0; - map->written = 1; + map->changed = 0; + map->written = 1; } void print_expert_notes() { - printf("Notes:\n"); - printf(" The expert commands are for low level and experimental features.\n"); - printf(" These commands are available only when debug mode is on.\n"); - printf("\n"); + printf("Notes:\n"); + printf(" The expert commands are for low level and experimental " + "features.\n"); + printf(" These commands are available only when debug mode is on.\n"); + printf("\n"); } int -do_expert(struct partition_map_header *map, char *name) +do_expert(struct partition_map_header * map, char *name) { - int command; - int quit = 0; - - while (get_command("Expert command (? for help): ", first_get, &command)) { - first_get = 0; - - switch (command) { - case '?': - print_expert_notes(); - /* fall through */ - case 'H': - case 'h': - printf("Commands are:\n"); - printf(" h print help\n"); - printf(" d dump block n\n"); - printf(" p print the partition table\n"); - if (dflag) { - printf(" P (show data structures - debugging)\n"); - } - printf(" f full display of nth entry\n"); - printf(" v validate map\n"); - printf(" e examine patch partition\n"); - printf(" q return to main edit menu\n"); - printf(" Q quit editing\n"); - break; - case 'q': - flush_to_newline(1); - goto finis; - break; - case 'Q': - if (map->changed) { - if (get_okay("Discard changes? [n/y]: ", 0) != 1) { - break; + int command, quit = 0; + + while (get_command("Expert command (? for help): ", first_get, + &command)) { + first_get = 0; + + switch (command) { + case '?': + print_expert_notes(); + /* fall through */ + case 'H': + case 'h': + printf("Commands are:\n"); + printf(" h print help\n"); + printf(" d dump block n\n"); + printf(" p print the partition table\n"); + if (dflag) { + printf(" P (show data structures - " + "debugging)\n"); + } + printf(" f full display of nth entry\n"); + printf(" v validate map\n"); + printf(" e examine patch partition\n"); + printf(" q return to main edit menu\n"); + printf(" Q quit editing\n"); + break; + case 'q': + flush_to_newline(1); + goto finis; + break; + case 'Q': + if (map->changed) { + if (get_okay("Discard changes? [n/y]: ", 0) != + 1) { + break; + } + } + quit = 1; + goto finis; + break; + case 'P': + if (dflag) { + show_data_structures(map); + break; + } + /* fall through */ + case 'p': + dump_partition_map(map, 1); + break; + case 'D': + case 'd': + do_display_block(map, name); + break; + case 'F': + case 'f': + do_display_entry(map); + break; + case 'V': + case 'v': + validate_map(map); + break; + case 'E': + case 'e': + do_examine_patch_partition(map); + break; + default: + bad_input("No such command (%c)", command); + break; } - } - quit = 1; - goto finis; - break; - case 'P': - if (dflag) { - show_data_structures(map); - break; - } - /* fall through */ - case 'p': - dump_partition_map(map, 1); - break; - case 'D': - case 'd': - do_display_block(map, name); - break; - case 'F': - case 'f': - do_display_entry(map); - break; - case 'V': - case 'v': - validate_map(map); - break; - case 'E': - case 'e': - do_examine_patch_partition(map); - break; - default: - bad_input("No such command (%c)", command); - break; - } - } + } finis: - return quit; + return quit; } void -do_change_map_size(struct partition_map_header *map) +do_change_map_size(struct partition_map_header * map) { - long size; + long size; - if (map == NULL) { - bad_input("No partition map exists"); - return; - } - if (!rflag && map->writable == 0) { - printf("The map is not writable.\n"); - } - if (get_number_argument("New size: ", &size, kDefault) == 0) { - bad_input("Bad size"); - return; - } - resize_map(size, map); + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + if (!rflag && map->writable == 0) { + printf("The map is not writable.\n"); + } + if (get_number_argument("New size: ", &size, kDefault) == 0) { + bad_input("Bad size"); + return; + } + resize_map(size, map); } void -do_display_block(struct partition_map_header *map, char *alt_name) +do_display_block(struct partition_map_header * map, char *alt_name) { - struct file_media *m; - long number; - char *name; - static unsigned char *display_block; - static int display_g; - int g; - static long next_number = -1; - - if (map != NULL) { - name = 0; - m = map->m; - g = map->logical_block; - } else { - if (alt_name == 0) { - if (get_string_argument("Name of device: ", &name, 1) == 0) { - bad_input("Bad name"); - return; - } + struct file_media *m; + char *name; + long number; + int g; + static unsigned char *display_block; + static long next_number = -1; + static int display_g; + + if (map != NULL) { + name = 0; + m = map->m; + g = map->logical_block; } else { - if ((name = strdup(alt_name)) == NULL) { - warn("strdup failed"); - return; - } - } - m = open_file_as_media(name, O_RDONLY); - if (m == 0) { - warn("can't open file '%s'", name); - free(name); - return; - } - g = DEV_BSIZE; - } - if (get_number_argument("Block number: ", &number, next_number) == 0) { - bad_input("Bad block number"); - goto xit; - } - if (display_block == NULL || display_g < g) { - if (display_block != NULL) { - free(display_block); - display_g = 0; - } - display_block = malloc(g); - if (display_block == NULL) { - warn("can't allocate memory for display block buffer"); - goto xit; - } - display_g = g; - } - if (read_file_media(m, ((long long)number) * g, g, (char *)display_block) != 0) { - printf("block %ld -", number); - dump_block((unsigned char*) display_block, g); - next_number = number + 1; - } - + if (alt_name == 0) { + if (get_string_argument("Name of device: ", &name, 1) + == 0) { + bad_input("Bad name"); + return; + } + } else { + if ((name = strdup(alt_name)) == NULL) { + warn("strdup failed"); + return; + } + } + m = open_file_as_media(name, O_RDONLY); + if (m == 0) { + warn("can't open file '%s'", name); + free(name); + return; + } + g = DEV_BSIZE; + } + if (get_number_argument("Block number: ", &number, next_number) == 0) { + bad_input("Bad block number"); + goto xit; + } + if (display_block == NULL || display_g < g) { + if (display_block != NULL) { + free(display_block); + display_g = 0; + } + display_block = malloc(g); + if (display_block == NULL) { + warn("can't allocate memory for display block buffer"); + goto xit; + } + display_g = g; + } + if (read_file_media(m, ((long long) number) * g, g, + (char *)display_block) != 0) { + printf("block %ld -", number); + dump_block((unsigned char *)display_block, g); + next_number = number + 1; + } xit: - if (name) { - close_file_media(m); - free(name); - } - return; + if (name) { + close_file_media(m); + free(name); + } + return; } void -do_display_entry(struct partition_map_header *map) +do_display_entry(struct partition_map_header * map) { - long number; + long number; - if (map == NULL) { - bad_input("No partition map exists"); - return; - } - if (get_number_argument("Partition number: ", &number, kDefault) == 0) { - bad_input("Bad partition number"); - return; - } - if (number == 0) { - full_dump_block_zero(map); - } else { - full_dump_partition_entry(map, number); - } + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + if (get_number_argument("Partition number: ", &number, kDefault) == 0) { + bad_input("Bad partition number"); + return; + } + if (number == 0) { + full_dump_block_zero(map); + } else { + full_dump_partition_entry(map, number); + } } void -do_examine_patch_partition(struct partition_map_header *map) +do_examine_patch_partition(struct partition_map_header * map) { - struct partition_map * entry; + struct partition_map *entry; - if (map == NULL) { - bad_input("No partition map exists"); - return; - } - entry = find_entry_by_type(kPatchType, map); - if (entry == NULL) { - printf("No patch partition\n"); - } else { - display_patches(entry); - } + if (map == NULL) { + bad_input("No partition map exists"); + return; + } + entry = find_entry_by_type(kPatchType, map); + if (entry == NULL) { + printf("No patch partition\n"); + } else { + display_patches(entry); + } } __dead static void usage(void) { - extern char * __progname; + extern char *__progname; - fprintf(stderr, "usage: %s [-lr] disk\n", __progname); + fprintf(stderr, "usage: %s [-lr] disk\n", __progname); - exit(1); + exit(1); } |