Example #1
0
static int bt_partition_list(BT_HANDLE hShell, int argc, char **argv) {

    if(argc != 1) {
        usage_list(hShell);
        return -1;
    }

    if(!device_path) {
        return no_disk(hShell);
    }

    BT_BLOCK_GEOMETRY oGeom;

    BT_u32 i;
    if(!p_partition_info) {
        BT_ERROR Error;
        BT_HANDLE hBlock = BT_Open(device_path, 0, &Error);
        if(!hBlock) {
            BT_PRSHELL("Error: Could not open %s\n", argv[1]);
            return -1;
        }

        BT_GetBlockGeometry(hBlock, &oGeom);

        g_partitions = BT_PartitionCount(hBlock);
        for(i = 0; i < g_partitions; i++) {
            BT_PartitionInfo(hBlock, i, &g_partition_info[i]);
        }

        p_partition_info = g_partition_info;

        BT_CloseHandle(hBlock);
    }

    BT_PRSHELL("Device %s contains %d partitions\n", device_path, g_partitions);
    BT_PRSHELL("BlockSize    : %lu\n", oGeom.ulBlockSize);
    BT_PRSHELL("Total Blocks : %lu\n", oGeom.ulTotalBlocks);

    for(i = 0; i < g_partitions; i++) {
        BT_PRSHELL("  %d : %lu : %lu\n", i, g_partition_info[i].ulStartLBA, g_partition_info[i].ulSectorCount);
    }

    return 0;
}
Example #2
0
static void usage(BT_HANDLE hShell) {
    BT_PRSHELL("Usage: partition [command] {[command args]}\n");
    BT_PRSHELL("Command documentation:\n");
    usage_disk(hShell);
    usage_close(hShell);
    usage_list(hShell);
    usage_select(hShell);

    usage_commit(hShell);
    /*BT_PRSHELL("     : %s select [partition-id]\n",  argv[0]);
    BT_PRSHELL("     +- Select a partition to modify.\n");
    BT_PRSHELL("     : %s clear\n",                  argv[0]);
    BT_PRSHELL("     : %s create [size]\n",          argv[0]);
    BT_PRSHELL("     +- Create a partition.\n");
    BT_PRSHELL("     : %s delete\n",                 argv[0]);
    BT_PRSHELL("     +- Delete the selcted partition\n");
    BT_PRSHELL("     : %s commit\n",                 argv[0]);
    BT_PRSHELL("     +- Commit the partition table to MBR\n");
    BT_PRSHELL("     : %s reset\n",                  argv[0]);*/
}
Example #3
0
static int bee_dep_list(int argc, char *argv[])
{
    int c, i, opt_count, help, files, packages, count,
        depending_on, required_by, removable, provider_of,
        not_cached, broken;
    struct hash *graph;
    char *name;
    struct option long_options[] = {
        {"help",         0, &help,         1},
        {"files",        0, &files,        1},
        {"packages",     0, &packages,     1},
        {"count",        0, &count,        1},
        {"depending-on", 0, &depending_on, 1},
        {"required-by",  0, &required_by,  1},
        {"removable",    0, &removable,    1},
        {"provider-of",  0, &provider_of,  1},
        {"not-cached",   0, &not_cached,   1},
        {"broken",       0, &broken,       1},
        {0, 0, 0, 0}
    };

    opt_count = help         = files       = packages  = provider_of =
    count     = depending_on = required_by = removable = not_cached  =
    broken    = 0;

    while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) {
        switch (c) {
            case '?':
                usage_list();
                return 1;

            default:
                opt_count++;
        }
    }

    if (help) {
        usage_list();
        return 0;
    }

    if (!opt_count && optind != argc) {
        fprintf(stderr, "bee-dep: too many arguments\n");
        return 1;
    }

    if (!opt_count)
        packages = 1;

    if (opt_count > 1 && !count) {
        fprintf(stderr, "bee-dep: too many options specified\n");
        return 1;
    }

    if (packages) {
        graph = get_cache();

        if (count)
            printf("%d\n", count_packages(graph));
        else
            list_packages(graph);

        hash_free(graph);
        return 0;
    }

    if (broken && optind < argc) {
        fprintf(stderr, "bee-dep: too many arguments\n");
        return 1;
    }

    if (optind == argc && !broken) {
        fprintf(stderr, "bee-dep: arguments needed\n");
        return 1;
    }

    if (count && (depending_on || required_by))
        fprintf(stderr, "bee-dep: ignoring option --count\n");

    graph = get_cache();

    for (i = optind; i < argc; i++) {
        name = argv[i];

        if (optind < argc - 1)
            printf("%s:\n", name);

        if (files) {
            if (count) {
                c = count_files(graph, name);

                if (c < 0) {
                    hash_free(graph);
                    return 1;
                }

                printf("%d\n", c);
            } else if (list_files(graph, name)) {
                 hash_free(graph);
                 return 1;
            }
        }

        if (removable) {
            if (count) {
                c = count_removable(graph, name);

                if (c < 0) {
                    hash_free(graph);
                    return 1;
                }

                printf("%d\n", c);
            } else if (print_removable(graph, name)) {
                hash_free(graph);
                return 1;
            }
        }

        if (depending_on && print_neededby(graph, name)) {
            hash_free(graph);
            return 1;
        }

        if (required_by && print_needs(graph, name)) {
            hash_free(graph);
            return 1;
        }

        if (provider_of) {
            if (count) {
                c = count_providers(graph, name);

                if (c < 0) {
                    hash_free(graph);
                    return 1;
                }

                printf("%d\n", c);
            } else if (print_providers(graph, name)) {
                hash_free(graph);
                return 1;
            }
        }

        if (not_cached) {
            c = print_not_cached(graph, name, !count);

            if (c < 0) {
                hash_free(graph);
                return 1;
            }

            if (count)
                printf("%d\n", c);
        }
    }

    if (broken) {
        c = print_broken(graph, !count);

        if (c < 0) {
            hash_free(graph);
            return 1;
        }

        if (count)
            printf("%d\n", c);
    }

    hash_free(graph);
    return 0;
}
Example #4
0
static int plooptool_list(int argc, char **argv)
{
	char fname[PATH_MAX];
	char image[PATH_MAX];
	char mnt[PATH_MAX] = "";
	char dev[64];
	DIR *dp;
	struct dirent *de;
	char cookie[PLOOP_COOKIE_SIZE];
	int all = 0;
	int i;

	while ((i = getopt(argc, argv, "a")) != EOF) {
		switch (i) {
		case 'a':
			all = 1;
			break;
		default:
			usage_list();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 0) {
		usage_list();
		return SYSEXIT_PARAM;
	}

	snprintf(fname, sizeof(fname) - 1, "/sys/block/");
	dp = opendir(fname);
	if (dp == NULL) {
		fprintf(stderr, "Can't opendir %s: %m", fname);
		return 1;
	}
	while ((de = readdir(dp)) != NULL) {
		if (strncmp("ploop", de->d_name, 5))
			continue;

		snprintf(fname, sizeof(fname), "/sys/block/%s/pdelta/0/image",
				de->d_name);
		if (access(fname, F_OK))
			continue;
		if (read_line(fname, image, sizeof(image)))
			continue;
		snprintf(fname, sizeof(fname), "/sys/block/%s/pstate/cookie",
				de->d_name);
		if (access(fname, F_OK) == 0) {
			if (read_line(fname, cookie, sizeof(cookie)))
				continue;
		}

		if (all) {
			mnt[0] = '\0';
			snprintf(dev, sizeof(dev), "/dev/%s", de->d_name);
			ploop_get_mnt_by_dev(dev, mnt, sizeof(mnt));
		}
		printf("%-12s %s %s %s\n", de->d_name, image, mnt, cookie);
	}
	closedir(dp);

	return 0;
}