Add support for getting fat16 and fat32 volume labels (no support for setting,

still).

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=964225
This commit is contained in:
Volker Lanz 2009-05-06 11:12:19 +00:00
parent 9a1a21f3e7
commit 9c5580d1e2
2 changed files with 29 additions and 7 deletions

View File

@ -22,6 +22,8 @@
#include "util/externalcommand.h"
#include "util/capacity.h"
#include <kdebug.h>
#include <QString>
#include <QStringList>
#include <QRegExp>
@ -31,6 +33,7 @@
namespace FS
{
FileSystem::SupportType fat16::m_GetUsed = FileSystem::SupportNone;
FileSystem::SupportType fat16::m_GetLabel = FileSystem::SupportNone;
FileSystem::SupportType fat16::m_Create = FileSystem::SupportNone;
FileSystem::SupportType fat16::m_Grow = FileSystem::SupportNone;
FileSystem::SupportType fat16::m_Shrink = FileSystem::SupportNone;
@ -39,7 +42,7 @@ namespace FS
FileSystem::SupportType fat16::m_Copy = FileSystem::SupportNone;
FileSystem::SupportType fat16::m_Backup = FileSystem::SupportNone;
FileSystem::SupportType fat16::m_UpdateUUID = FileSystem::SupportNone;
fat16::fat16(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label, FileSystem::Type t) :
FileSystem(firstsector, lastsector, sectorsused, label, t)
@ -48,13 +51,14 @@ namespace FS
void fat16::init()
{
// There is no support for getting or setting labels for FAT16 and FAT32 right now.
// There is no support for setting labels for FAT16 and FAT32 right now.
// The mtools package is able to do that, but requires mappings from Unix device nodes
// to Windows-like drive letters -- something we cannot support. It would, however,
// probably be possible to implement the file system label stuff ourselves here.
m_Create = findExternal("mkfs.msdos") ? SupportExternal : SupportNone;
m_GetUsed = m_Check = findExternal("fsck.msdos", QStringList(), 2) ? SupportExternal : SupportNone;
m_GetLabel = findExternal("vol_id") ? SupportExternal : SupportNone;
m_Grow = SupportLibParted;
m_Shrink = SupportLibParted;
m_Move = SupportInternal;
@ -72,7 +76,7 @@ namespace FS
{
return 4 * Capacity::unitFactor(Capacity::Byte, Capacity::GiB);
}
qint64 fat16::readUsedCapacity(const QString& deviceNode) const
{
ExternalCommand cmd("fsck.msdos", QStringList() << "-v" << deviceNode);
@ -118,7 +122,7 @@ namespace FS
char uuid[4];
for (quint32 i = 0; i < sizeof(uuid); i++, t >>= 8)
uuid[i] = t & 0xff;
ExternalCommand cmd(report, "dd", QStringList() << "of=" + deviceNode << "bs=1" << "count=4" << "seek=39");
if (!cmd.start())
@ -126,7 +130,22 @@ namespace FS
if (cmd.write(uuid, sizeof(uuid)) != sizeof(uuid))
return false;
return cmd.waitFor(-1);
}
QString fat16::readLabel(const QString& deviceNode) const
{
ExternalCommand cmd("vol_id", QStringList() << deviceNode);
if (cmd.run())
{
QRegExp rxLabel("ID_FS_LABEL=(\\w+)");
if (rxLabel.indexIn(cmd.output()) != -1)
return rxLabel.cap(1).simplified();
}
return QString();
}
}

View File

@ -43,11 +43,13 @@ namespace FS
static void init();
virtual qint64 readUsedCapacity(const QString& deviceNode) const;
virtual QString readLabel(const QString& deviceNode) const;
virtual bool check(Report& report, const QString& deviceNode) const;
virtual bool create(Report& report, const QString& deviceNode) const;
virtual bool updateUUID(Report& report, const QString& deviceNode) const;
virtual SupportType supportGetUsed() const { return m_GetUsed; }
virtual SupportType supportGetLabel() const { return m_GetLabel; }
virtual SupportType supportCreate() const { return m_Create; }
virtual SupportType supportGrow() const { return m_Grow; }
virtual SupportType supportShrink() const { return m_Shrink; }
@ -56,12 +58,13 @@ namespace FS
virtual SupportType supportCopy() const { return m_Copy; }
virtual SupportType supportBackup() const { return m_Backup; }
virtual SupportType supportUpdateUUID() const { return m_UpdateUUID; }
virtual qint64 minCapacity() const;
virtual qint64 maxCapacity() const;
protected:
static SupportType m_GetUsed;
static SupportType m_GetLabel;
static SupportType m_Create;
static SupportType m_Grow;
static SupportType m_Shrink;