use libblkid api for UUID too.

no static functions for reading labels and uuids: that doesn't make any sense.
just use methods in FileSystem and its implementations. this means no more
distinction between internal and external support (for reading labels and UUIDs
that is), but I don't see that this will be missed.


svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1073165
This commit is contained in:
Volker Lanz 2010-01-11 18:50:38 +00:00
parent eb961b06c3
commit bab4194a10
8 changed files with 26 additions and 64 deletions

View File

@ -226,12 +226,10 @@ static void scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDi
readSectorsUsed(pedDisk, *part, mountInfo);
if (fs->supportGetLabel() == FileSystem::SupportInternal)
fs->setLabel(FileSystem::readLabelInternal(part->deviceNode()));
else if (fs->supportGetLabel() == FileSystem::SupportExternal)
if (fs->supportGetLabel() != FileSystem::SupportNone)
fs->setLabel(fs->readLabel(part->deviceNode()));
if (fs->supportGetUUID() == FileSystem::SupportExternal)
if (fs->supportGetUUID() != FileSystem::SupportNone)
fs->setUUID(fs->readUUID(part->deviceNode()));
parent->append(part);

View File

@ -58,7 +58,7 @@ namespace FS
m_Copy = (m_Check != SupportNone) ? SupportInternal : SupportNone;
m_Move = (m_Check != SupportNone) ? SupportInternal : SupportNone;
m_Backup = SupportInternal;
m_GetUUID = findIdUtil() ? SupportExternal : SupportNone;
m_GetUUID = SupportInternal;
}
qint64 ext2::maxCapacity() const

View File

@ -65,7 +65,7 @@ namespace FS
m_Copy = SupportInternal;
m_Backup = SupportInternal;
m_UpdateUUID = findExternal("dd") ? SupportExternal : SupportNone;
m_GetUUID = findIdUtil() ? SupportExternal : SupportNone;
m_GetUUID = SupportInternal;
}
qint64 fat16::minCapacity() const

View File

@ -54,19 +54,27 @@ qint64 FileSystem::readUsedCapacity(const QString& deviceNode) const
return -1;
}
static QString invokeIdUtil(const QString& util, const QString& deviceNode, const QString& rx)
static QString readBlkIdValue(const QString& deviceNode, const QString& tag)
{
ExternalCommand cmd(util, QStringList() << deviceNode);
blkid_cache cache;
QString rval;
if (cmd.run())
if (blkid_get_cache(&cache, NULL) == 0)
{
QRegExp rxLabel(rx);
blkid_dev dev;
if (rxLabel.indexIn(cmd.output()) != -1)
return rxLabel.cap(1).simplified();
char* label = NULL;
if ((dev = blkid_get_dev(cache, deviceNode.toLocal8Bit(), BLKID_DEV_NORMAL)) != NULL &&
(label = blkid_get_tag_value(cache, tag.toLocal8Bit(), deviceNode.toLocal8Bit())))
{
rval = label;
free(label);
}
blkid_put_cache(cache);
}
return QString();
return rval;
}
/** Reads the label for this FileSystem
@ -75,9 +83,7 @@ static QString invokeIdUtil(const QString& util, const QString& deviceNode, cons
*/
QString FileSystem::readLabel(const QString& deviceNode) const
{
Q_UNUSED(deviceNode);
return QString();
return readBlkIdValue(deviceNode, "LABEL");
}
/** Creates a new FileSystem
@ -181,18 +187,13 @@ bool FileSystem::updateUUID(Report& report, const QString& deviceNode) const
return true;
}
/** Returns the FileSystem UUID (or an empty string, if not supported).
/** Returns the FileSystem UUID by calling a FileSystem-specific helper program
@param deviceNode the device node for the Partition the FileSystem is on
@return the UUID or an empty string if the FileSystem does not support UUIDs
*/
QString FileSystem::readUUID(const QString& deviceNode) const
{
QString rval = invokeIdUtil("vol_id", deviceNode, "ID_FS_UUID=([^\\s]+)");
if (rval.isEmpty())
rval = invokeIdUtil("blkid", deviceNode, "UUID=\"([^\"]+)\"");
return rval;
return readBlkIdValue(deviceNode, "UUID");
}
/** Give implementations of FileSystem a chance to update the boot sector after the
@ -337,33 +338,6 @@ bool FileSystem::unmount(const QString& mountPoint)
return false;
}
/** Reads the label for a device's FileSystem
@param deviceNode the device node for the Partition the FileSystem is on
@return the FileSystem label or an empty string in case of error
*/
QString FileSystem::readLabelInternal(const QString& deviceNode)
{
blkid_cache cache;
QString rval;
if (blkid_get_cache(&cache, NULL) == 0)
{
blkid_dev dev;
char* label = NULL;
if ((dev = blkid_get_dev(cache, deviceNode.toLocal8Bit(), BLKID_DEV_NORMAL)) != NULL &&
(label = blkid_get_tag_value(cache, "LABEL", deviceNode.toLocal8Bit())))
{
rval = label;
free(label);
}
blkid_put_cache(cache);
}
return rval;
}
bool FileSystem::findExternal(const QString& cmdName, const QStringList& args, int expectedCode)
{
ExternalCommand cmd(cmdName, args);
@ -372,9 +346,3 @@ bool FileSystem::findExternal(const QString& cmdName, const QStringList& args, i
return cmd.exitCode() == 0 || cmd.exitCode() == expectedCode;
}
bool FileSystem::findIdUtil()
{
return findExternal("vol_id") || findExternal("blkid");
}

View File

@ -145,12 +145,8 @@ class FileSystem
void setLabel(const QString& s) { m_Label = s; } /**< @param s the new label */
void setUUID(const QString& s) { m_UUID = s; } /**< @param s the new UUID */
public:
static QString readLabelInternal(const QString& deviceNode);
protected:
static bool findExternal(const QString& cmdName, const QStringList& args = QStringList(), int exptectedCode = 1);
static bool findIdUtil();
protected:
FileSystem::Type m_Type;

View File

@ -45,7 +45,7 @@ namespace FS
m_GetLabel = SupportInternal;
m_Copy = SupportInternal;
m_Move = SupportInternal;
m_GetUUID = findIdUtil() ? SupportExternal : SupportNone;
m_GetUUID = SupportInternal;
}
bool linuxswap::create(Report& report, const QString& deviceNode) const
@ -55,7 +55,7 @@ namespace FS
bool linuxswap::resize(Report& report, const QString& deviceNode, qint64) const
{
const QString label = readLabelInternal(deviceNode);
const QString label = readLabel(deviceNode);
QStringList args;
if (!label.isEmpty())

View File

@ -65,7 +65,7 @@ namespace FS
m_Backup = SupportInternal;
m_UpdateUUID = findExternal("dd") ? SupportExternal : SupportNone;
m_Move = (m_Check != SupportNone) ? SupportInternal : SupportNone;
m_GetUUID = findIdUtil() ? SupportExternal : SupportNone;
m_GetUUID = SupportInternal;
}
qint64 ntfs::maxCapacity() const

View File

@ -59,7 +59,7 @@ namespace FS
m_Shrink = (m_GetUsed != SupportNone && m_Grow != SupportNone) ? SupportExternal : SupportNone;
m_Backup = SupportInternal;
m_UpdateUUID = findExternal("reiserfstune") ? SupportExternal : SupportNone;
m_GetUUID = findIdUtil() ? SupportExternal : SupportNone;
m_GetUUID = SupportInternal;
}
qint64 reiserfs::minCapacity() const