コード例 #1
0
ファイル: ext2.c プロジェクト: will-Do/libguestfs
char *
do_get_e2uuid (const char *device)
{
    const mountable_t mountable = {
        .type = MOUNTABLE_DEVICE,
        .device = /* not really ... */ (char *) device,
        .volume = NULL,
    };
    return do_vfs_uuid (&mountable);
}

/* If the filesystem is not mounted, run e2fsck -f on it unconditionally. */
static int
if_not_mounted_run_e2fsck (const char *device)
{
    CLEANUP_FREE char *err = NULL;
    int r, mounted;

    mounted = is_device_mounted (device);
    if (mounted == -1)
        return -1;

    if (!mounted) {
        r = commandf (NULL, &err,
                      COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
                      str_e2fsck, "-fy", device, NULL);
        if (r == -1) {
            reply_with_error ("%s", err);
            return -1;
        }
    }

    return 0;
}
コード例 #2
0
int get_disk_partitionnumber(const char *string, u32 *partition_number, u32 *mounted_number)
{
	DIR *dp;
	char disk_name[8];
	char target_path[64];
	struct dirent *file;
	int len;

	if(partition_number == NULL)
		return 0;

	*partition_number = 0; // initial value.
	if(mounted_number != NULL)
		*mounted_number = 0; // initial value.

	if(string == NULL)
		return 0;

	len = strlen(string);
	if(!is_disk_name(string)){
		while(isdigit(string[len-1]))
			--len;
	}
	memset(disk_name, 0, sizeof(disk_name));
	strncpy(disk_name, string, len);

	sprintf(target_path, "%s/%s", SYS_BLOCK, disk_name);
	if((dp = opendir(target_path)) == NULL)
		return 0;

	len = strlen(disk_name);
	while((file = readdir(dp)) != NULL){
		if(file->d_name[0] == '.')
			continue;
		
		if(!strncmp(file->d_name, disk_name, len)){
			++(*partition_number);
			
			if(mounted_number == NULL)
				continue;
			
			if (is_device_mounted(file->d_name))
				++(*mounted_number);
		}
	}
	closedir(dp);

	return 1;
}