Esempio n. 1
0
File: ui.c Progetto: bcl/parted
int
command_line_get_part_flag (const char* prompt, const PedPartition* part,
                            PedPartitionFlag* flag)
{
        StrList*            opts = NULL;
        PedPartitionFlag    walk = 0;
        char*               flag_name;

        while ( (walk = ped_partition_flag_next (walk)) ) {
                if (ped_partition_is_flag_available (part, walk)) {
                        const char*        walk_name;

                        walk_name = ped_partition_flag_get_name (walk);
                        opts = str_list_append (opts, walk_name);
                        opts = str_list_append_unique (opts, _(walk_name));
                }
        }
        if (opts == NULL)
        {
                ped_exception_throw (PED_EXCEPTION_ERROR,
                                     PED_EXCEPTION_OK,
                                     _("No flags supported"));
        
                return 0;
        }
        flag_name = command_line_get_word (prompt, NULL, opts, 1);
        str_list_destroy (opts);

        if (flag_name) {
                *flag = ped_partition_flag_get_by_name (flag_name);
                free (flag_name);
                return 1;
        } else
                return 0;
}
Esempio n. 2
0
int
main(int argc, char *argv[])
{
    struct partition *parts[MAX_PARTS];
    int part_count, i;
    bool ignore_fs_type = false;
    bool colons = false;
    PedPartitionFlag require_flag = 0;

    int opt;
    struct option longopts[] = {
        { "ignore-fstype",  no_argument,        NULL, 'i' },
        { "colons",         no_argument,        NULL, 'c' },
        { "flag",           required_argument,  NULL, 'f' },
        { NULL, 0, NULL, 0 }
    };

    while ((opt = getopt_long(argc, argv, "icf:", longopts, NULL)) != EOF) {
        switch (opt) {
            case 'i':
                ignore_fs_type = true;
                break;
            case 'c':
                colons = true;
                break;
            case 'f':
                require_flag = ped_partition_flag_get_by_name(optarg);
                if (!require_flag) {
                    fprintf(stderr, "Unknown parted flag '%s'\n", optarg);
                    exit(1);
                }
                break;
        }
    }

    if ((part_count = get_all_partitions(parts, MAX_PARTS, ignore_fs_type, require_flag)) <= 0)
        return 1;
    for (i = 0; i < part_count; i++) {
        if (colons)
            printf("%s:%s:%lld\n",
                    parts[i]->path,
                    parts[i]->fstype != NULL ? parts[i]->fstype : "",
                    parts[i]->size);
        else
            printf("%s\t%s\t%s\n",
                    parts[i]->path,
                    parts[i]->fstype != NULL ? parts[i]->fstype : "",
                    parts[i]->size > 0 ? size_desc(parts[i]->size) : "");
    }
    return 0;
}