Esempio n. 1
0
partition_info_t *create_partition(const char *device_name, partition_info_t **new_part_info)
{
	partition_info_t *follow_part_info;
	u32 partition_order;
	u64 size_in_kilobytes = 0, total_kilobytes = 0, used_kilobytes = 0;
	char buf1[PATH_MAX], buf2[64], buf3[PATH_MAX]; // options of mount info needs more buffer size.
	int len;

	if(new_part_info == NULL)
		return NULL;

	*new_part_info = NULL; // initial value.

	if(device_name == NULL || get_device_type_by_device(device_name) != DEVICE_TYPE_DISK)
		return NULL;

	if(!is_disk_name(device_name) && !is_partition_name(device_name, &partition_order))
		return NULL;

	if(initial_part_data(&follow_part_info) == NULL)
		return NULL;

	len = strlen(device_name);
	follow_part_info->device = (char *)malloc(len+1);
	if(!follow_part_info->device){
		free_partition_data(&follow_part_info);
		return NULL;
	}
	strncpy(follow_part_info->device, device_name, len);
	follow_part_info->device[len] = 0;

	follow_part_info->partition_order = partition_order;

	if(read_mount_data(device_name, buf1, buf2, buf3)){
		len = strlen(buf1);
		follow_part_info->mount_point = (char *)malloc(len+1);
		if(!follow_part_info->mount_point){
			free_partition_data(&follow_part_info);
			return NULL;
		}
		strncpy(follow_part_info->mount_point, buf1, len);
		follow_part_info->mount_point[len] = 0;

		len = strlen(buf2);
		follow_part_info->file_system = (char *)malloc(len+1);
		if(!follow_part_info->file_system){
			free_partition_data(&follow_part_info);
			return NULL;
		}
		strncpy(follow_part_info->file_system, buf2, len);
		follow_part_info->file_system[len] = 0;

		len = strlen(buf3);
		follow_part_info->permission = (char *)malloc(len+1);
		if(!follow_part_info->permission){
			free_partition_data(&follow_part_info);
			return NULL;
		}
		strncpy(follow_part_info->permission, buf3, len);
		follow_part_info->permission[len] = 0;

		if(get_mount_size(follow_part_info->mount_point, &total_kilobytes, &used_kilobytes)){
			follow_part_info->size_in_kilobytes = total_kilobytes;
			follow_part_info->used_kilobytes = used_kilobytes;
		}
	}
	else{
		if(is_disk_name(device_name)){	// Disk
			free_partition_data(&follow_part_info);
			return NULL;
		}
		else{
			len = strlen(PARTITION_TYPE_UNKNOWN);
			follow_part_info->file_system = (char *)malloc(len+1);
			if(!follow_part_info->file_system){
				free_partition_data(&follow_part_info);
				return NULL;
			}
			strncpy(follow_part_info->file_system, PARTITION_TYPE_UNKNOWN, len);
			follow_part_info->file_system[len] = 0;
			
			get_partition_size(device_name, &size_in_kilobytes);
			follow_part_info->size_in_kilobytes = size_in_kilobytes;
		}
	}

	*new_part_info = follow_part_info;

	return *new_part_info;
}
Esempio n. 2
0
partition_info_t *create_partition(const char *device_name, partition_info_t **new_part_info){
	partition_info_t *follow_part_info;
	char label[128];
	u32 partition_order = 0;
	u64 size_in_kilobytes = 0, total_kilobytes = 0, used_kilobytes = 0;
	char buf1[PATH_MAX], buf2[64], buf3[PATH_MAX]; // options of mount info needs more buffer size.
	int len;

	if(new_part_info == NULL){
		usb_dbg("Bad input!!\n");
		return NULL;
	}

	*new_part_info = NULL; // initial value.

	if(device_name == NULL || get_device_type_by_device(device_name) != DEVICE_TYPE_DISK)
		return NULL;

	if(!is_disk_name(device_name) && !is_partition_name(device_name, &partition_order))
		return NULL;

	if(initial_part_data(&follow_part_info) == NULL){
		usb_dbg("No memory!!(follow_part_info)\n");
		return NULL;
	}

	len = strlen(device_name);
	follow_part_info->device = (char *)malloc(len+1);
	if(follow_part_info->device == NULL){
		usb_dbg("No memory!!(follow_part_info->device)\n");
		free_partition_data(&follow_part_info);
		return NULL;
	}
	strncpy(follow_part_info->device, device_name, len);
	follow_part_info->device[len] = 0;

	if(find_partition_label(device_name, label)){
		strntrim(label);
		len = strlen(label);
		follow_part_info->label = (char *)malloc(len+1);
		if(follow_part_info->label == NULL){
			usb_dbg("No memory!!(follow_part_info->label)\n");
			free_partition_data(&follow_part_info);
			return NULL;
		}
		strncpy(follow_part_info->label, label, len);
		follow_part_info->label[len] = 0;
	}

	follow_part_info->partition_order = partition_order;

	if(read_mount_data(device_name, buf1, PATH_MAX, buf2, 64, buf3, PATH_MAX)){
		len = strlen(buf1);
		follow_part_info->mount_point = (char *)malloc(len+1);
		if(follow_part_info->mount_point == NULL){
			usb_dbg("No memory!!(follow_part_info->mount_point)\n");
			free_partition_data(&follow_part_info);
			return NULL;
		}
		strncpy(follow_part_info->mount_point, buf1, len);
		follow_part_info->mount_point[len] = 0;

		len = strlen(buf2);
		follow_part_info->file_system = (char *)malloc(len+1);
		if(follow_part_info->file_system == NULL){
			usb_dbg("No memory!!(follow_part_info->file_system)\n");
			free_partition_data(&follow_part_info);
			return NULL;
		}
		strncpy(follow_part_info->file_system, buf2, len);
		follow_part_info->file_system[len] = 0;

		len = strlen(buf3);
		follow_part_info->permission = (char *)malloc(len+1);
		if(follow_part_info->permission == NULL){
			usb_dbg("No memory!!(follow_part_info->permission)\n");
			free_partition_data(&follow_part_info);
			return NULL;
		}
		strncpy(follow_part_info->permission, buf3, len);
		follow_part_info->permission[len] = 0;

		if(get_mount_size(follow_part_info->mount_point, &total_kilobytes, &used_kilobytes)){
			follow_part_info->size_in_kilobytes = total_kilobytes;
			follow_part_info->used_kilobytes = used_kilobytes;
		}
	}
	else{
		/*if(is_disk_name(device_name)){	// Disk
			free_partition_data(&follow_part_info);
			return NULL;
		}
		else{//*/
			len = strlen(PARTITION_TYPE_UNKNOWN);
			follow_part_info->file_system = (char *)malloc(len+1);
			if(follow_part_info->file_system == NULL){
				usb_dbg("No memory!!(follow_part_info->file_system)\n");
				free_partition_data(&follow_part_info);
				return NULL;
			}
			strncpy(follow_part_info->file_system, PARTITION_TYPE_UNKNOWN, len);
			follow_part_info->file_system[len] = 0;

			get_partition_size(device_name, &size_in_kilobytes);
			follow_part_info->size_in_kilobytes = size_in_kilobytes;
		//}
	}

	*new_part_info = follow_part_info;

	return *new_part_info;
}