Ejemplo n.º 1
0
/*
 * The operation to apply to each file ...
 */
void
process(char *filename)
{
    char *s;
    int index;
    partition_map_header *map;
    int valid_file;
    partition_map * entry;

    //printf("Processing %s\n", filename);

    // 1)       strip off number from end of filename
    s = strdup(filename);
    index = trim_num(s);

    if (index < 0) {
        fatal(-1, "%s does not end in a number", filename);
    }

    // 2)       open prefix of filename as partition map
    map = open_partition_map(s, &valid_file, 0);
    if (!valid_file) {
        fatal(-1, "%s does not have a partition map", s);
        return;
    }

    // 3)       verify the type for the partition;

    if (map->writeable == 0) {
	fatal(-1, "The map is not writeable");
        return;
    }

    // 4) find partition and change it
    entry = find_entry_by_disk_address(index, map);
    if (entry == NULL) {
	fatal(-1, "No such partition");
    } else if (strcmp(entry->data->dpme_type, kHFSType) != 0) {
	fatal(-1, "Can't convert a partition with type %s",
		entry->data->dpme_type);
    } else {
	// 4a)       modify the type
	strncpy(entry->data->dpme_type, kUnixType, DPISTRLEN);
	
	// 5)       and write back.
	write_partition_map(map);
    }
}
Ejemplo n.º 2
0
//
// Routines
//
int
dump(char *name)
{
    partition_map_header *map;
    int junk;

    map = open_partition_map(name, &junk, 0);
    if (map == NULL) {
	//error(-1, "No partition map in '%s'", name);
	return 0;
    }

    dump_partition_map(map, 1);

    close_partition_map(map);
    
    return 1;
}
Ejemplo n.º 3
0
//
// Edit the file
//
void
edit(char *name, int ask_logical_size)
{
    partition_map_header *map;
    int command;
    int order;
    int get_type;
    int valid_file;

    map = open_partition_map(name, &valid_file, ask_logical_size);
    if (!valid_file) {
    	return;
    }

    printf("Edit %s -\n", name);
    
#if 0 /* this check is not found in linux fdisk-0.1 */
    if (map != NULL && map->blocks_in_map > MAX_LINUX_MAP) {
	error(-1, "Map contains more than %d blocks - Linux may have trouble", MAX_LINUX_MAP);
    }
#endif

    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 unix 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;
	}
    }
finis:

    close_partition_map(map);
}