make first and last usable sector methods static to libparted, no one else is
using them move the code used to map libparted partition flags to our own flags from the job to LibParted svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1090002
This commit is contained in:
parent
bfbe3eed58
commit
95ace6b7d3
|
@ -43,6 +43,21 @@
|
||||||
#include <parted/parted.h>
|
#include <parted/parted.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static const LibParted::FlagMap flagmap[] =
|
||||||
|
{
|
||||||
|
{ PED_PARTITION_BOOT, PartitionTable::FlagBoot },
|
||||||
|
{ PED_PARTITION_ROOT, PartitionTable::FlagRoot },
|
||||||
|
{ PED_PARTITION_SWAP, PartitionTable::FlagSwap },
|
||||||
|
{ PED_PARTITION_HIDDEN, PartitionTable::FlagHidden },
|
||||||
|
{ PED_PARTITION_RAID, PartitionTable::FlagRaid },
|
||||||
|
{ PED_PARTITION_LVM, PartitionTable::FlagLvm },
|
||||||
|
{ PED_PARTITION_LBA, PartitionTable::FlagLba },
|
||||||
|
{ PED_PARTITION_HPSERVICE, PartitionTable::FlagHpService },
|
||||||
|
{ PED_PARTITION_PALO, PartitionTable::FlagPalo },
|
||||||
|
{ PED_PARTITION_PREP, PartitionTable::FlagPrep },
|
||||||
|
{ PED_PARTITION_MSFT_RESERVED, PartitionTable::FlagMsftReserved }
|
||||||
|
};
|
||||||
|
|
||||||
/** Callback to handle exceptions from libparted
|
/** Callback to handle exceptions from libparted
|
||||||
@param e the libparted exception to handle
|
@param e the libparted exception to handle
|
||||||
*/
|
*/
|
||||||
|
@ -86,7 +101,7 @@ typedef struct _GPTDiskData GPTDiskData;
|
||||||
@param d the Device in question
|
@param d the Device in question
|
||||||
@return the first sector usable by a Partition
|
@return the first sector usable by a Partition
|
||||||
*/
|
*/
|
||||||
quint64 LibParted::firstUsableSector(const Device& d)
|
static quint64 firstUsableSector(const Device& d)
|
||||||
{
|
{
|
||||||
PedDevice* pedDevice = ped_device_get(d.deviceNode().toAscii());
|
PedDevice* pedDevice = ped_device_get(d.deviceNode().toAscii());
|
||||||
PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : NULL;
|
PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : NULL;
|
||||||
|
@ -111,7 +126,7 @@ quint64 LibParted::firstUsableSector(const Device& d)
|
||||||
@param d the Device in question
|
@param d the Device in question
|
||||||
@return the last sector usable by a Partition
|
@return the last sector usable by a Partition
|
||||||
*/
|
*/
|
||||||
quint64 LibParted::lastUsableSector(const Device& d)
|
static quint64 lastUsableSector(const Device& d)
|
||||||
{
|
{
|
||||||
PedDevice* pedDevice = ped_device_get(d.deviceNode().toAscii());
|
PedDevice* pedDevice = ped_device_get(d.deviceNode().toAscii());
|
||||||
PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : NULL;
|
PedDisk* pedDisk = pedDevice ? ped_disk_new(pedDevice) : NULL;
|
||||||
|
@ -183,6 +198,44 @@ static void readSectorsUsed(PedDisk* pedDisk, Partition& p, const QString& mount
|
||||||
p.fileSystem().setSectorsUsed(readSectorsUsedLibParted(pedDisk, p));
|
p.fileSystem().setSectorsUsed(readSectorsUsedLibParted(pedDisk, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PartitionTable::Flags activeFlags(PedPartition* p)
|
||||||
|
{
|
||||||
|
PartitionTable::Flags flags = PartitionTable::FlagNone;
|
||||||
|
|
||||||
|
// We might get here with a pedPartition just picked up from libparted that is
|
||||||
|
// unallocated. Libparted doesn't like it if we ask for flags for unallocated
|
||||||
|
// space.
|
||||||
|
if (p->num <= 0)
|
||||||
|
return flags;
|
||||||
|
|
||||||
|
for (quint32 i = 0; i < sizeof(flagmap) / sizeof(flagmap[0]); i++)
|
||||||
|
if (ped_partition_is_flag_available(p, flagmap[i].pedFlag) && ped_partition_get_flag(p, flagmap[i].pedFlag))
|
||||||
|
flags |= flagmap[i].flag;
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PartitionTable::Flags availableFlags(PedPartition* p)
|
||||||
|
{
|
||||||
|
PartitionTable::Flags flags;
|
||||||
|
|
||||||
|
// see above.
|
||||||
|
if (p->num <= 0)
|
||||||
|
return flags;
|
||||||
|
|
||||||
|
for (quint32 i = 0; i < sizeof(flagmap) / sizeof(flagmap[0]); i++)
|
||||||
|
if (ped_partition_is_flag_available(p, flagmap[i].pedFlag))
|
||||||
|
{
|
||||||
|
// workaround:: see above
|
||||||
|
if (p->type != PED_PARTITION_EXTENDED || flagmap[i].flag != PartitionTable::FlagHidden)
|
||||||
|
flags |= flagmap[i].flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Scans a Device for Partitions.
|
/** Scans a Device for Partitions.
|
||||||
|
|
||||||
This function will scan a Device for all Partitions on it, detect the FileSystem for each Partition,
|
This function will scan a Device for all Partitions on it, detect the FileSystem for each Partition,
|
||||||
|
@ -243,9 +296,7 @@ static void scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDi
|
||||||
|
|
||||||
const QString mountPoint = mountPoints.findByDevice(node) ? mountPoints.findByDevice(node)->mountPoint() : QString();
|
const QString mountPoint = mountPoints.findByDevice(node) ? mountPoints.findByDevice(node)->mountPoint() : QString();
|
||||||
|
|
||||||
Partition* part = new Partition(parent, d, PartitionRole(r), fs, pedPartition->geom.start, pedPartition->geom.end,
|
Partition* part = new Partition(parent, d, PartitionRole(r), fs, pedPartition->geom.start, pedPartition->geom.end, pedPartition->num, availableFlags(pedPartition), QStringList() << mountPoint, ped_partition_is_busy(pedPartition), activeFlags(pedPartition));
|
||||||
pedPartition->num, SetPartFlagsJob::availableFlags(pedPartition),
|
|
||||||
QStringList() << mountPoint, ped_partition_is_busy(pedPartition), SetPartFlagsJob::activeFlags(pedPartition));
|
|
||||||
|
|
||||||
readSectorsUsed(pedDisk, *part, mountPoint);
|
readSectorsUsed(pedDisk, *part, mountPoint);
|
||||||
|
|
||||||
|
@ -274,6 +325,14 @@ LibParted::LibParted()
|
||||||
ped_exception_set_handler(pedExceptionHandler);
|
ped_exception_set_handler(pedExceptionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return a map of partition flags from libparted flags to PartitionTable::Flags
|
||||||
|
@return the map
|
||||||
|
*/
|
||||||
|
const LibParted::FlagMap* LibParted::flagMap()
|
||||||
|
{
|
||||||
|
return flagmap;
|
||||||
|
}
|
||||||
|
|
||||||
/** Create a Device for the given device_node and scan it for partitions.
|
/** Create a Device for the given device_node and scan it for partitions.
|
||||||
@param device_node the device node (e.g. "/dev/sda")
|
@param device_node the device node (e.g. "/dev/sda")
|
||||||
@return the created Device object. callers need to free this.
|
@return the created Device object. callers need to free this.
|
||||||
|
|
|
@ -21,16 +21,17 @@
|
||||||
|
|
||||||
#define LIBPARTED__H
|
#define LIBPARTED__H
|
||||||
|
|
||||||
|
#include "core/partitiontable.h"
|
||||||
|
|
||||||
|
#include <parted/parted.h>
|
||||||
|
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
|
|
||||||
class OperationStack;
|
|
||||||
class Device;
|
class Device;
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
/** @brief Scanning for Devices.
|
/** @brief Device scanning done by libparted.
|
||||||
|
|
||||||
Encapsulates Device scanning done by libparted.
|
|
||||||
|
|
||||||
More libparted-related stuff is in the @link Job Job-derived @endlink classes.
|
More libparted-related stuff is in the @link Job Job-derived @endlink classes.
|
||||||
|
|
||||||
|
@ -40,13 +41,19 @@ class LibParted
|
||||||
{
|
{
|
||||||
Q_DISABLE_COPY(LibParted)
|
Q_DISABLE_COPY(LibParted)
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
PedPartitionFlag pedFlag;
|
||||||
|
PartitionTable::Flag flag;
|
||||||
|
} FlagMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LibParted();
|
LibParted();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static quint64 firstUsableSector(const Device& d);
|
|
||||||
static quint64 lastUsableSector(const Device& d);
|
|
||||||
static Device* scanDevice(const QString& device_node);
|
static Device* scanDevice(const QString& device_node);
|
||||||
|
static const FlagMap* flagMap();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,30 +23,12 @@
|
||||||
#include "core/partition.h"
|
#include "core/partition.h"
|
||||||
#include "core/partitionrole.h"
|
#include "core/partitionrole.h"
|
||||||
#include "core/partitiontable.h"
|
#include "core/partitiontable.h"
|
||||||
|
#include "core/libparted.h"
|
||||||
|
|
||||||
#include "util/report.h"
|
#include "util/report.h"
|
||||||
|
|
||||||
#include <klocale.h>
|
#include <klocale.h>
|
||||||
|
|
||||||
static const struct
|
|
||||||
{
|
|
||||||
PedPartitionFlag pedFlag;
|
|
||||||
PartitionTable::Flag flag;
|
|
||||||
} flagmap[] =
|
|
||||||
{
|
|
||||||
{ PED_PARTITION_BOOT, PartitionTable::FlagBoot },
|
|
||||||
{ PED_PARTITION_ROOT, PartitionTable::FlagRoot },
|
|
||||||
{ PED_PARTITION_SWAP, PartitionTable::FlagSwap },
|
|
||||||
{ PED_PARTITION_HIDDEN, PartitionTable::FlagHidden },
|
|
||||||
{ PED_PARTITION_RAID, PartitionTable::FlagRaid },
|
|
||||||
{ PED_PARTITION_LVM, PartitionTable::FlagLvm },
|
|
||||||
{ PED_PARTITION_LBA, PartitionTable::FlagLba },
|
|
||||||
{ PED_PARTITION_HPSERVICE, PartitionTable::FlagHpService },
|
|
||||||
{ PED_PARTITION_PALO, PartitionTable::FlagPalo },
|
|
||||||
{ PED_PARTITION_PREP, PartitionTable::FlagPrep },
|
|
||||||
{ PED_PARTITION_MSFT_RESERVED, PartitionTable::FlagMsftReserved }
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Creates a new SetPartFlagsJob
|
/** Creates a new SetPartFlagsJob
|
||||||
@param d the Device the Partition whose flags are to be set is on
|
@param d the Device the Partition whose flags are to be set is on
|
||||||
@param p the Partition whose flags are to be set
|
@param p the Partition whose flags are to be set
|
||||||
|
@ -62,7 +44,7 @@ SetPartFlagsJob::SetPartFlagsJob(Device& d, Partition& p, PartitionTable::Flags
|
||||||
|
|
||||||
qint32 SetPartFlagsJob::numSteps() const
|
qint32 SetPartFlagsJob::numSteps() const
|
||||||
{
|
{
|
||||||
return sizeof(flagmap) / sizeof(flagmap[0]);
|
return sizeof(LibParted::flagMap()) / sizeof(LibParted::flagMap()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetPartFlagsJob::run(Report& parent)
|
bool SetPartFlagsJob::run(Report& parent)
|
||||||
|
@ -77,27 +59,27 @@ bool SetPartFlagsJob::run(Report& parent)
|
||||||
|
|
||||||
if (pedPartition)
|
if (pedPartition)
|
||||||
{
|
{
|
||||||
for (quint32 i = 0; i < sizeof(flagmap) / sizeof(flagmap[0]); i++)
|
for (quint32 i = 0; i < sizeof(LibParted::flagMap()) / sizeof(LibParted::flagMap()[0]); i++)
|
||||||
{
|
{
|
||||||
emit progress(i + 1);
|
emit progress(i + 1);
|
||||||
|
|
||||||
if (!ped_partition_is_flag_available(pedPartition, flagmap[i].pedFlag))
|
if (!ped_partition_is_flag_available(pedPartition, LibParted::flagMap()[i].pedFlag))
|
||||||
{
|
{
|
||||||
report->line() << i18nc("@info/plain", "The flag \"%1\" is not available on the partition's partition table.", PartitionTable::flagName(flagmap[i].flag));
|
report->line() << i18nc("@info/plain", "The flag \"%1\" is not available on the partition's partition table.", PartitionTable::flagName(LibParted::flagMap()[i].flag));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround: libparted claims the hidden flag is available for extended partitions, but
|
// Workaround: libparted claims the hidden flag is available for extended partitions, but
|
||||||
// throws an error when we try to set or clear it. So skip this combination (also see below in
|
// throws an error when we try to set or clear it. So skip this combination (also see below in
|
||||||
// availableFlags()).
|
// availableFlags()).
|
||||||
if (pedPartition->type == PED_PARTITION_EXTENDED && flagmap[i].flag == PartitionTable::FlagHidden)
|
if (pedPartition->type == PED_PARTITION_EXTENDED && LibParted::flagMap()[i].flag == PartitionTable::FlagHidden)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int state = (flags() & flagmap[i].flag) ? 1 : 0;
|
int state = (flags() & LibParted::flagMap()[i].flag) ? 1 : 0;
|
||||||
|
|
||||||
if (!ped_partition_set_flag(pedPartition, flagmap[i].pedFlag, state))
|
if (!ped_partition_set_flag(pedPartition, LibParted::flagMap()[i].pedFlag, state))
|
||||||
{
|
{
|
||||||
report->line() << i18nc("@info/plain", "There was an error setting flag %1 for partition <filename>%2</filename> to state %3.", PartitionTable::flagName(flagmap[i].flag), partition().deviceNode(), state ? i18nc("@info flag turned on, active", "on") : i18nc("@info flag turned off, inactive", "off"));
|
report->line() << i18nc("@info/plain", "There was an error setting flag %1 for partition <filename>%2</filename> to state %3.", PartitionTable::flagName(LibParted::flagMap()[i].flag), partition().deviceNode(), state ? i18nc("@info flag turned on, active", "on") : i18nc("@info flag turned off, inactive", "off"));
|
||||||
|
|
||||||
rval = false;
|
rval = false;
|
||||||
}
|
}
|
||||||
|
@ -122,42 +104,6 @@ bool SetPartFlagsJob::run(Report& parent)
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionTable::Flags SetPartFlagsJob::activeFlags(PedPartition* p)
|
|
||||||
{
|
|
||||||
PartitionTable::Flags flags = PartitionTable::FlagNone;
|
|
||||||
|
|
||||||
// We might get here with a pedPartition just picked up from libparted that is
|
|
||||||
// unallocated. Libparted doesn't like it if we ask for flags for unallocated
|
|
||||||
// space.
|
|
||||||
if (p->num <= 0)
|
|
||||||
return flags;
|
|
||||||
|
|
||||||
for (quint32 i = 0; i < sizeof(flagmap) / sizeof(flagmap[0]); i++)
|
|
||||||
if (ped_partition_is_flag_available(p, flagmap[i].pedFlag) && ped_partition_get_flag(p, flagmap[i].pedFlag))
|
|
||||||
flags |= flagmap[i].flag;
|
|
||||||
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
PartitionTable::Flags SetPartFlagsJob::availableFlags(PedPartition* p)
|
|
||||||
{
|
|
||||||
PartitionTable::Flags flags;
|
|
||||||
|
|
||||||
// see above.
|
|
||||||
if (p->num <= 0)
|
|
||||||
return flags;
|
|
||||||
|
|
||||||
for (quint32 i = 0; i < sizeof(flagmap) / sizeof(flagmap[0]); i++)
|
|
||||||
if (ped_partition_is_flag_available(p, flagmap[i].pedFlag))
|
|
||||||
{
|
|
||||||
// workaround:: see above
|
|
||||||
if (p->type != PED_PARTITION_EXTENDED || flagmap[i].flag != PartitionTable::FlagHidden)
|
|
||||||
flags |= flagmap[i].flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString SetPartFlagsJob::description() const
|
QString SetPartFlagsJob::description() const
|
||||||
{
|
{
|
||||||
if (PartitionTable::flagNames(flags()).size() == 0)
|
if (PartitionTable::flagNames(flags()).size() == 0)
|
||||||
|
|
|
@ -49,9 +49,6 @@ class SetPartFlagsJob : public Job
|
||||||
virtual qint32 numSteps() const;
|
virtual qint32 numSteps() const;
|
||||||
virtual QString description() const;
|
virtual QString description() const;
|
||||||
|
|
||||||
static PartitionTable::Flags activeFlags(PedPartition* p);
|
|
||||||
static PartitionTable::Flags availableFlags(PedPartition* p);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Device& device() { return m_Device; }
|
Device& device() { return m_Device; }
|
||||||
const Device& device() const { return m_Device; }
|
const Device& device() const { return m_Device; }
|
||||||
|
|
Loading…
Reference in New Issue