mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-24 02:42:52 +00:00
partitionmanager: use PedDevice::phys_sector_size member instead of Linux-specifiec code for it
making it slightly more portable, FreeBSD has no parted port tho Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
340ee3a7cf
commit
64fa811282
5 changed files with 7 additions and 57 deletions
|
@ -29,56 +29,6 @@
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
#include <klocale.h>
|
#include <klocale.h>
|
||||||
|
|
||||||
#include <QFile>
|
|
||||||
#include <QByteArray>
|
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <linux/fs.h>
|
|
||||||
|
|
||||||
#if !defined(BLKPBSZGET)
|
|
||||||
#define BLKPBSZGET _IO(0x12,123)/* get block physical sector size */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static qint32 getPhysicalSectorSize(const QString& device_node)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* possible ways of getting the physical sector size for a drive:
|
|
||||||
* - ioctl(BLKPBSZGET) -- supported with Linux 2.6.32 and later
|
|
||||||
* - /sys/block/sda/queue/physical_block_size
|
|
||||||
* - libblkid from util-linux-ng 2.17 or later
|
|
||||||
* TODO: implement the blkid method
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(BLKPBSZGET)
|
|
||||||
int phSectorSize = -1;
|
|
||||||
int fd = open(device_node.toLocal8Bit(), O_RDONLY);
|
|
||||||
if (fd != -1)
|
|
||||||
{
|
|
||||||
if (ioctl(fd, BLKPBSZGET, &phSectorSize) >= 0)
|
|
||||||
{
|
|
||||||
close(fd);
|
|
||||||
return phSectorSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
close (fd);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QFile f(QString("/sys/block/%1/queue/physical_block_size").arg(QString(device_node).remove("/dev/")));
|
|
||||||
|
|
||||||
if (f.open(QIODevice::ReadOnly))
|
|
||||||
{
|
|
||||||
QByteArray a = f.readLine();
|
|
||||||
return a.simplified().toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Constructs a Device with an empty PartitionTable.
|
/** Constructs a Device with an empty PartitionTable.
|
||||||
@param name the Device's name, usually some string defined by the manufacturer
|
@param name the Device's name, usually some string defined by the manufacturer
|
||||||
@param devicenode the Device's node, for example "/dev/sda"
|
@param devicenode the Device's node, for example "/dev/sda"
|
||||||
|
@ -86,8 +36,9 @@ static qint32 getPhysicalSectorSize(const QString& device_node)
|
||||||
@param numSectors the number of sectors in CHS notation
|
@param numSectors the number of sectors in CHS notation
|
||||||
@param cylinders the number of cylinders in CHS notation
|
@param cylinders the number of cylinders in CHS notation
|
||||||
@param sectorSize the size of a sector in bytes
|
@param sectorSize the size of a sector in bytes
|
||||||
|
@param physicalSize the physical size of a sector in bytes
|
||||||
*/
|
*/
|
||||||
Device::Device(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize, const QString& iconname) :
|
Device::Device(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize, qint64 physicalSize, const QString& iconname) :
|
||||||
QObject(),
|
QObject(),
|
||||||
m_Name(name.length() > 0 ? name : i18n("Unknown Device")),
|
m_Name(name.length() > 0 ? name : i18n("Unknown Device")),
|
||||||
m_DeviceNode(devicenode),
|
m_DeviceNode(devicenode),
|
||||||
|
@ -96,7 +47,7 @@ Device::Device(const QString& name, const QString& devicenode, qint32 heads, qin
|
||||||
m_SectorsPerTrack(numSectors),
|
m_SectorsPerTrack(numSectors),
|
||||||
m_Cylinders(cylinders),
|
m_Cylinders(cylinders),
|
||||||
m_LogicalSectorSize(sectorSize),
|
m_LogicalSectorSize(sectorSize),
|
||||||
m_PhysicalSectorSize(getPhysicalSectorSize(devicenode)),
|
m_PhysicalSectorSize(physicalSize),
|
||||||
m_IconName(iconname.isEmpty() ? "drive-harddisk" : iconname)
|
m_IconName(iconname.isEmpty() ? "drive-harddisk" : iconname)
|
||||||
#if defined(HAVE_LIBATASMART)
|
#if defined(HAVE_LIBATASMART)
|
||||||
, m_SmartStatus(new SmartStatus(devicenode))
|
, m_SmartStatus(new SmartStatus(devicenode))
|
||||||
|
|
|
@ -49,7 +49,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT Device : public QObject
|
||||||
friend class CoreBackend;
|
friend class CoreBackend;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Device(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize, const QString& iconname = QString());
|
Device(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint64 sectorSize, qint64 physicalSize, const QString& iconname = QString());
|
||||||
~Device();
|
~Device();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -81,7 +81,7 @@ QList<Device*> DummyBackend::scanDevices()
|
||||||
|
|
||||||
Device* DummyBackend::scanDevice(const QString& device_node)
|
Device* DummyBackend::scanDevice(const QString& device_node)
|
||||||
{
|
{
|
||||||
Device* d = new Device("Dummy Device", QString("/tmp" + device_node), 255, 30, 63, 512);
|
Device* d = new Device("Dummy Device", QString("/tmp" + device_node), 255, 30, 63, 512, 512);
|
||||||
CoreBackend::setPartitionTableForDevice(*d, new PartitionTable(PartitionTable::msdos_sectorbased, 2048, d->totalSectors() - 2048));
|
CoreBackend::setPartitionTableForDevice(*d, new PartitionTable(PartitionTable::msdos_sectorbased, 2048, d->totalSectors() - 2048));
|
||||||
CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), 128);
|
CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), 128);
|
||||||
d->partitionTable()->updateUnallocated(*d);
|
d->partitionTable()->updateUnallocated(*d);
|
||||||
|
|
|
@ -421,7 +421,7 @@ Device* LibPartedBackend::scanDevice(const QString& device_node)
|
||||||
|
|
||||||
Log(Log::information) << i18nc("@info/plain", "Device found: %1", pedDevice->model);
|
Log(Log::information) << i18nc("@info/plain", "Device found: %1", pedDevice->model);
|
||||||
|
|
||||||
Device* d = new Device(pedDevice->model, pedDevice->path, pedDevice->bios_geom.heads, pedDevice->bios_geom.sectors, pedDevice->bios_geom.cylinders, pedDevice->sector_size);
|
Device* d = new Device(pedDevice->model, pedDevice->path, pedDevice->bios_geom.heads, pedDevice->bios_geom.sectors, pedDevice->bios_geom.cylinders, pedDevice->sector_size, pedDevice->phys_sector_size);
|
||||||
|
|
||||||
PedDisk* pedDisk = ped_disk_new(pedDevice);
|
PedDisk* pedDisk = ped_disk_new(pedDevice);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <qglobal.h>
|
#include <QString>
|
||||||
|
|
||||||
class LibPartedDevice;
|
class LibPartedDevice;
|
||||||
class LibPartedPartitionTable;
|
class LibPartedPartitionTable;
|
||||||
|
@ -40,7 +40,6 @@ class OperationStack;
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class KPluginFactory;
|
class KPluginFactory;
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
/** Backend plugin for libparted.
|
/** Backend plugin for libparted.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue