You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
2.9 KiB
142 lines
2.9 KiB
14 years ago
|
#include "libparted.h"
|
||
|
|
||
|
#include <QStringList>
|
||
|
|
||
|
LibParted::LibParted(QObject *parent)
|
||
|
: QObject(parent)
|
||
|
{
|
||
|
// ped_exception_set_handler( )
|
||
|
|
||
|
Init();
|
||
|
}
|
||
|
|
||
|
LibParted::~LibParted()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
QString LibParted::getVersion()
|
||
|
{
|
||
|
return QString( ped_get_version() );
|
||
|
}
|
||
|
|
||
|
void LibParted::Init()
|
||
|
{
|
||
|
ped_device_probe_all();
|
||
|
|
||
|
PedDevice* dsk = NULL;
|
||
|
|
||
|
while ( (dsk = ped_device_get_next(dsk)) != NULL )
|
||
|
{
|
||
|
m_DeviceList[ QString(dsk->path) ] = dsk;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
QStringList LibParted::getDevices()
|
||
|
{
|
||
|
QStringList res;
|
||
|
|
||
|
Devices::const_iterator i = m_DeviceList.begin();
|
||
|
while ( i != m_DeviceList.constEnd() )
|
||
|
{
|
||
|
res << i.key();
|
||
|
++i;
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
DeviceInfo LibParted::getDeviceInfo(const QString& path) throw(LibPartedError)
|
||
|
{
|
||
|
if ( m_DeviceList.find(path) == m_DeviceList.end() )
|
||
|
throw LibPartedError();
|
||
|
|
||
|
return convertPedDevice(m_DeviceList[path]);
|
||
|
}
|
||
|
|
||
|
QList<PartitionInfo> LibParted::getPartitionList(const QString& path) throw(LibPartedError)
|
||
|
{
|
||
|
QList<PartitionInfo> PartInfo;
|
||
|
|
||
|
if ( m_DeviceList.find(path) == m_DeviceList.end() )
|
||
|
throw LibPartedError();
|
||
|
|
||
|
PedDevice* dev = m_DeviceList[path];
|
||
|
|
||
|
PedDisk* disk = NULL;
|
||
|
disk = ped_disk_new( dev );
|
||
|
if (!disk)
|
||
|
throw LibPartedError();
|
||
|
|
||
|
bool has_extended = ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED);
|
||
|
bool has_name = ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_PARTITION_NAME);
|
||
|
|
||
|
PedPartition* part = NULL;
|
||
|
|
||
|
while ( part = ped_disk_next_partition (disk, part) )
|
||
|
{
|
||
|
PartitionInfo part_inf;
|
||
|
|
||
|
if (part->type & PED_PARTITION_METADATA)
|
||
|
continue;
|
||
|
|
||
|
if ( part->num >= 0)
|
||
|
part_inf.num = part->num;
|
||
|
|
||
|
part_inf.begin = part->geom.start;
|
||
|
part_inf.end = (part->geom.end + 1) * dev->sector_size - 1;
|
||
|
part_inf.size = part->geom.length;
|
||
|
|
||
|
if (!(part->type & PED_PARTITION_FREESPACE))
|
||
|
{
|
||
|
if (has_extended)
|
||
|
{
|
||
|
char* type = const_cast<char*>( ped_partition_type_get_name(part->type) );
|
||
|
part_inf.type = QString(type);
|
||
|
//free(name);
|
||
|
}
|
||
|
|
||
|
part_inf.fs = part->fs_type ? QString(part->fs_type->name) : "";
|
||
|
|
||
|
if (has_name)
|
||
|
{
|
||
|
char* name = const_cast<char*>( ped_partition_get_name(part) );
|
||
|
part_inf.name = QString(name);
|
||
|
}
|
||
|
//part_inf. = QString(name);
|
||
|
//free(name);
|
||
|
|
||
|
//char *flags = const_cast<char*>( partition_print_flags(part) );
|
||
|
//Flags = QString(flags);
|
||
|
//free(flags);
|
||
|
|
||
|
} else {
|
||
|
part_inf.type = "Free space";
|
||
|
}
|
||
|
|
||
|
PartInfo << part_inf;
|
||
|
}
|
||
|
|
||
|
return PartInfo;
|
||
|
}
|
||
|
|
||
|
DeviceInfo LibParted::convertPedDevice(const PedDevice* dev)
|
||
|
{
|
||
|
DeviceInfo part_dev;
|
||
|
|
||
|
const char *const transport[] = {"unknown", "scsi", "ide", "dac960",
|
||
|
"cpqarray", "file", "ataraid", "i2o",
|
||
|
"ubd", "dasd", "viodasd", "sx8", "dm",
|
||
|
"xvd", "sd/mmc", "virtblk"};
|
||
|
|
||
|
part_dev.model = QString(dev->model);
|
||
|
part_dev.transport = QString("%1").arg(transport[dev->type]);
|
||
|
|
||
|
part_dev.size = dev->length * dev->sector_size;
|
||
|
part_dev.sec_ph = dev->phys_sector_size;
|
||
|
part_dev.sec_log = dev->sector_size;
|
||
|
|
||
|
return part_dev;
|
||
|
}
|
||
|
|