diff --git a/src/fs/fat16.cpp b/src/fs/fat16.cpp index 5536892..7d6ce94 100644 --- a/src/fs/fat16.cpp +++ b/src/fs/fat16.cpp @@ -22,6 +22,8 @@ #include "util/externalcommand.h" #include "util/capacity.h" +#include + #include #include #include @@ -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(); + } } diff --git a/src/fs/fat16.h b/src/fs/fat16.h index fff923a..466c912 100644 --- a/src/fs/fat16.h +++ b/src/fs/fat16.h @@ -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;