Add ext4 support.
svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=901473
This commit is contained in:
parent
577ffb39f5
commit
7ebf6816ce
|
@ -34,6 +34,7 @@ FIND_PACKAGE(KDE4 REQUIRED)
|
|||
FIND_PACKAGE(MSGFMT REQUIRED)
|
||||
FIND_PACKAGE(PkgConfig REQUIRED)
|
||||
PKG_CHECK_MODULES(UUID REQUIRED uuid)
|
||||
PKG_CHECK_MODULES(BLKID REQUIRED blkid)
|
||||
FIND_PACKAGE(LIBPARTED REQUIRED)
|
||||
|
||||
ADD_DEFINITIONS(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
|
||||
|
@ -42,7 +43,7 @@ ADD_DEFINITIONS(${KDE4_ENABLE_EXCEPTIONS})
|
|||
INCLUDE(KDE4Defaults)
|
||||
INCLUDE(MacroLibrary)
|
||||
|
||||
INCLUDE_DIRECTORIES(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} src/)
|
||||
INCLUDE_DIRECTORIES(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} ${UUID_INCLUDE_DIRS} ${BLKID_INCLUDE_DIRS} src/)
|
||||
|
||||
ADD_SUBDIRECTORY(src)
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ KDE4_ADD_KCFG_FILES(partitionmanager_SRCS config.kcfgc)
|
|||
|
||||
KDE4_ADD_EXECUTABLE(partitionmanager ${partitionmanager_SRCS})
|
||||
|
||||
TARGET_LINK_LIBRARIES(partitionmanager ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KFILE_LIBS} ${LIBPARTED_LIBS} ${UUID_LIBS})
|
||||
TARGET_LINK_LIBRARIES(partitionmanager ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KFILE_LIBS} ${LIBPARTED_LIBS} ${UUID_LIBRARIES} ${BLKID_LIBRARIES})
|
||||
|
||||
INSTALL(TARGETS partitionmanager ${INSTALL_TARGETS_DEFAULT_ARGS})
|
||||
INSTALL(FILES gui/partitionmanagerui.rc DESTINATION ${DATA_INSTALL_DIR}/partitionmanager)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include "fs/ext4.h"
|
||||
|
||||
#include "util/externalcommand.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
namespace FS
|
||||
{
|
||||
ext4::ext4(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label) :
|
||||
ext2(firstsector, lastsector, sectorsused, label, FileSystem::Ext4)
|
||||
{
|
||||
}
|
||||
|
||||
bool ext4::create(Report& report, const QString& deviceNode) const
|
||||
{
|
||||
return ExternalCommand(report, "mkfs.ext4", QStringList() << deviceNode).run(-1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#if !defined(EXT4__H)
|
||||
|
||||
#define EXT4__H
|
||||
|
||||
#include "fs/ext2.h"
|
||||
|
||||
#include <qglobal.h>
|
||||
|
||||
class Report;
|
||||
|
||||
class QString;
|
||||
|
||||
namespace FS
|
||||
{
|
||||
/** @brief An ext4 file system.
|
||||
|
||||
Basically the same as ext2.
|
||||
|
||||
@author vl@fidra.de
|
||||
*/
|
||||
class ext4 : public ext2
|
||||
{
|
||||
public:
|
||||
ext4(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QString& label);
|
||||
|
||||
public:
|
||||
static void init() {}
|
||||
virtual bool create(Report& report, const QString& deviceNode) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -48,7 +48,7 @@ FileSystem::FileSystem(qint64 firstsector, qint64 lastsector, qint64 sectorsused
|
|||
qint64 FileSystem::readUsedCapacity(const QString& deviceNode) const
|
||||
{
|
||||
Q_UNUSED(deviceNode);
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ bool FileSystem::create(Report& report, const QString& deviceNode) const
|
|||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(deviceNode);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ bool FileSystem::resize(Report& report, const QString& deviceNode, qint64 newLen
|
|||
Q_UNUSED(report);
|
||||
Q_UNUSED(deviceNode);
|
||||
Q_UNUSED(newLength);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ bool FileSystem::writeLabel(Report& report, const QString& deviceNode, const QSt
|
|||
Q_UNUSED(report);
|
||||
Q_UNUSED(deviceNode);
|
||||
Q_UNUSED(newLabel);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ bool FileSystem::copy(Report& report, const QString& targetDeviceNode, const QSt
|
|||
Q_UNUSED(report);
|
||||
Q_UNUSED(targetDeviceNode);
|
||||
Q_UNUSED(sourceDeviceNode);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ bool FileSystem::backup(Report& report, const Device& sourceDevice, const QStrin
|
|||
@param report Report to write status information to
|
||||
@param deviceNode the device node for the Partition the FileSystem is on
|
||||
@return true if FileSystem is error-free
|
||||
*/
|
||||
*/
|
||||
bool FileSystem::check(Report& report, const QString& deviceNode) const
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
|
@ -195,6 +195,7 @@ static const QString* typeNames()
|
|||
|
||||
i18nc("@item/plain filesystem name", "ext2"),
|
||||
i18nc("@item/plain filesystem name", "ext3"),
|
||||
i18nc("@item/plain filesystem name", "ext4"),
|
||||
i18nc("@item/plain filesystem name", "linuxswap"),
|
||||
i18nc("@item/plain filesystem name", "fat16"),
|
||||
i18nc("@item/plain filesystem name", "fat32"),
|
||||
|
@ -219,7 +220,7 @@ QString FileSystem::nameForType(FileSystem::Type t)
|
|||
{
|
||||
Q_ASSERT(t >= 0);
|
||||
Q_ASSERT(t < __lastType);
|
||||
|
||||
|
||||
return typeNames()[t];
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ class Report;
|
|||
class FileSystem
|
||||
{
|
||||
Q_DISABLE_COPY(FileSystem)
|
||||
|
||||
|
||||
public:
|
||||
/** Supported FileSystem types */
|
||||
enum Type
|
||||
|
@ -49,6 +49,7 @@ class FileSystem
|
|||
|
||||
Ext2,
|
||||
Ext3,
|
||||
Ext4,
|
||||
LinuxSwap,
|
||||
Fat16,
|
||||
Fat32,
|
||||
|
@ -117,28 +118,28 @@ class FileSystem
|
|||
|
||||
virtual bool canMount(const QString&) const { return false; } /**< @return true if this FileSystem can be mounted */
|
||||
virtual bool canUnmount(const QString&) const { return false; } /**< @return true if this FileSystem can be unmounted */
|
||||
|
||||
|
||||
virtual QString mountTitle() const;
|
||||
virtual QString unmountTitle() const;
|
||||
|
||||
|
||||
virtual bool mount(const QString& mountPoint);
|
||||
virtual bool unmount(const QString& mountPoint);
|
||||
|
||||
qint64 firstSector() const { return m_FirstSector; } /**< @return the FileSystem's first sector */
|
||||
qint64 lastSector() const { return m_LastSector; } /**< @return the FileSystem's last sector */
|
||||
qint64 length() const { return lastSector() - firstSector() + 1; } /**< @return the FileSystem's length */
|
||||
|
||||
|
||||
void setFirstSector(qint64 s) { m_FirstSector = s; } /**< @param s the new first sector */
|
||||
void setLastSector(qint64 s) { m_LastSector = s; } /**< @param s the new last sector */
|
||||
|
||||
void move(qint64 newStartSector);
|
||||
|
||||
|
||||
const QString& label() const { return m_Label; } /**< @return the FileSystem's label */
|
||||
qint64 sectorsUsed() const { return m_SectorsUsed; } /**< @return the sectors in use on the FileSystem */
|
||||
|
||||
|
||||
void setSectorsUsed(qint64 s) { m_SectorsUsed = s; } /**< @param s the new value for sectors in use */
|
||||
void setLabel(const QString& s) { m_Label = s; } /**< @param s the new label */
|
||||
|
||||
|
||||
protected:
|
||||
static bool findExternal(const QString& cmdName, const QStringList& args = QStringList(), int exptectedCode = 1);
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "fs/ext2.h"
|
||||
#include "fs/ext3.h"
|
||||
#include "fs/ext4.h"
|
||||
#include "fs/extended.h"
|
||||
#include "fs/fat16.h"
|
||||
#include "fs/fat32.h"
|
||||
|
@ -46,9 +47,10 @@ void FileSystemFactory::init()
|
|||
delete fs;
|
||||
|
||||
m_FileSystems.clear();
|
||||
|
||||
|
||||
m_FileSystems.insert(FileSystem::Ext2, new FS::ext2(-1, -1, -1, QString()));
|
||||
m_FileSystems.insert(FileSystem::Ext3, new FS::ext3(-1, -1, -1, QString()));
|
||||
m_FileSystems.insert(FileSystem::Ext4, new FS::ext4(-1, -1, -1, QString()));
|
||||
m_FileSystems.insert(FileSystem::Extended, new FS::extended(-1, -1, -1, QString()));
|
||||
m_FileSystems.insert(FileSystem::Fat16, new FS::fat16(-1, -1, -1, QString()));
|
||||
m_FileSystems.insert(FileSystem::Fat32, new FS::fat32(-1, -1, -1, QString()));
|
||||
|
@ -63,9 +65,10 @@ void FileSystemFactory::init()
|
|||
m_FileSystems.insert(FileSystem::Unformatted, new FS::unformatted(-1, -1, -1, QString()));
|
||||
m_FileSystems.insert(FileSystem::Unknown, new FS::unknown(-1, -1, -1, QString()));
|
||||
m_FileSystems.insert(FileSystem::Xfs, new FS::xfs(-1, -1, -1, QString()));
|
||||
|
||||
|
||||
FS::ext2::init();
|
||||
FS::ext3::init();
|
||||
FS::ext4::init();
|
||||
FS::extended::init();
|
||||
FS::fat16::init();
|
||||
FS::fat32::init();
|
||||
|
@ -96,6 +99,7 @@ FileSystem* FileSystemFactory::create(FileSystem::Type t, qint64 firstsector, qi
|
|||
{
|
||||
case FileSystem::Ext2: return new FS::ext2(firstsector, lastsector, sectorsused, label);
|
||||
case FileSystem::Ext3: return new FS::ext3(firstsector, lastsector, sectorsused, label);
|
||||
case FileSystem::Ext4: return new FS::ext4(firstsector, lastsector, sectorsused, label);
|
||||
case FileSystem::Extended: return new FS::extended(firstsector, lastsector, sectorsused, label);
|
||||
case FileSystem::Fat16: return new FS::fat16(firstsector, lastsector, sectorsused, label);
|
||||
case FileSystem::Fat32: return new FS::fat32(firstsector, lastsector, sectorsused, label);
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <kiconloader.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <blkid/blkid.h>
|
||||
|
||||
static const struct
|
||||
{
|
||||
|
@ -44,6 +45,7 @@ static const struct
|
|||
{
|
||||
{ FileSystem::Ext2, "ext2" },
|
||||
{ FileSystem::Ext3, "ext3" },
|
||||
{ FileSystem::Ext3, "ext4" },
|
||||
{ FileSystem::LinuxSwap, "linux-swap" },
|
||||
{ FileSystem::Fat16, "fat16" },
|
||||
{ FileSystem::Fat32, "fat32" },
|
||||
|
@ -73,7 +75,7 @@ bool Job::openPed(const QString& path, bool diskFailOk)
|
|||
{
|
||||
m_PedDevice = ped_device_get(path.toAscii());
|
||||
m_PedDisk = m_PedDevice ? ped_disk_new(m_PedDevice) : NULL;
|
||||
|
||||
|
||||
return m_PedDevice != NULL && (diskFailOk || m_PedDisk != NULL);
|
||||
}
|
||||
|
||||
|
@ -81,7 +83,7 @@ void Job::closePed()
|
|||
{
|
||||
if (m_PedDisk)
|
||||
ped_disk_destroy(m_PedDisk);
|
||||
|
||||
|
||||
m_PedDisk = NULL;
|
||||
m_PedDevice = NULL;
|
||||
}
|
||||
|
@ -99,7 +101,7 @@ bool Job::commit(PedDisk* disk, quint32 timeout)
|
|||
bool rval = ped_disk_commit_to_dev(disk);
|
||||
|
||||
rval = ped_disk_commit_to_os(disk) && rval;
|
||||
|
||||
|
||||
if (!ExternalCommand("udevadm", QStringList() << "settle" << "--timeout=" + QString::number(timeout)).run() &&
|
||||
!ExternalCommand("udevsettle", QStringList() << "--timeout=" + QString::number(timeout)).run())
|
||||
sleep(timeout);
|
||||
|
@ -120,7 +122,7 @@ PedFileSystemType* Job::getPedFileSystemType(FileSystem::Type t)
|
|||
bool Job::copyBlocks(Report& report, CopyTarget& target, CopySource& source)
|
||||
{
|
||||
/** @todo copyBlocks() assumes that source.sectorSize() == target.sectorSize(). */
|
||||
|
||||
|
||||
if (source.sectorSize() != target.sectorSize())
|
||||
{
|
||||
report.line() << i18nc("@info/plain", "The sector size in the source and target for copying are not the same. This is currently unsupported.");
|
||||
|
@ -143,9 +145,9 @@ bool Job::copyBlocks(Report& report, CopyTarget& target, CopySource& source)
|
|||
}
|
||||
|
||||
report.line() << i18nc("@info/plain", "Copying %1 blocks (%2 sectors) from %3 to %4, direction: %5.", blocksToCopy, source.length(), readOffset, writeOffset, copyDir);
|
||||
|
||||
|
||||
qint64 blocksCopied = 0;
|
||||
|
||||
|
||||
void* buffer = malloc(blockSize * source.sectorSize());
|
||||
int percent = 0;
|
||||
|
||||
|
@ -165,7 +167,7 @@ bool Job::copyBlocks(Report& report, CopyTarget& target, CopySource& source)
|
|||
}
|
||||
|
||||
const qint64 lastBlock = source.length() % blockSize;
|
||||
|
||||
|
||||
// copy the remainder
|
||||
if (rval && lastBlock > 0)
|
||||
{
|
||||
|
@ -176,9 +178,9 @@ bool Job::copyBlocks(Report& report, CopyTarget& target, CopySource& source)
|
|||
|
||||
const qint64 lastBlockReadOffset = copyDir > 0 ? readOffset + blockSize * blocksCopied : source.firstSector();
|
||||
const qint64 lastBlockWriteOffset = copyDir > 0 ? writeOffset + blockSize * blocksCopied : target.firstSector();
|
||||
|
||||
|
||||
report.line() << i18nc("@info/plain", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset);
|
||||
|
||||
|
||||
rval = source.readSectors(buffer, lastBlockReadOffset, lastBlock);
|
||||
|
||||
if (rval)
|
||||
|
@ -202,7 +204,7 @@ bool Job::rollbackCopyBlocks(Report& report, CopyTarget& origTarget, CopySource&
|
|||
report.line() << i18nc("@info/plain", "Source and target for copying do not overlap: Rollback is not required.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
CopySourceDevice& csd = dynamic_cast<CopySourceDevice&>(origSource);
|
||||
|
@ -211,7 +213,7 @@ bool Job::rollbackCopyBlocks(Report& report, CopyTarget& origTarget, CopySource&
|
|||
// default: use values as if we were copying from front to back.
|
||||
qint64 undoSourceFirstSector = origTarget.firstSector();
|
||||
qint64 undoSourceLastSector = origTarget.firstSector() + origTarget.sectorsWritten() - 1;
|
||||
|
||||
|
||||
qint64 undoTargetFirstSector = origSource.firstSector();
|
||||
qint64 undoTargetLastSector = origSource.firstSector() + origTarget.sectorsWritten() - 1;
|
||||
|
||||
|
@ -234,14 +236,14 @@ bool Job::rollbackCopyBlocks(Report& report, CopyTarget& origTarget, CopySource&
|
|||
report.line() << i18nc("@info/plain", "Could not open device <filename>%1</filename> to rollback copying.", ctd.device().deviceNode());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
CopyTargetDevice undoTarget(csd.device(), undoTargetFirstSector, undoTargetLastSector);
|
||||
if (!undoTarget.open())
|
||||
{
|
||||
report.line() << i18nc("@info/plain", "Could not open device <filename>%1</filename> to rollback copying.", csd.device().deviceNode());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return copyBlocks(report, undoTarget, undoSource);
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -260,12 +262,12 @@ FileSystem::Type Job::detectFileSystemBySector(Report& report, Device& device, q
|
|||
PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk(), sector);
|
||||
|
||||
FileSystem::Type rval = FileSystem::Unknown;
|
||||
|
||||
|
||||
if (pedPartition)
|
||||
rval = detectFileSystem(pedDevice(), pedPartition);
|
||||
else
|
||||
report.line() << i18nc("@info/plain", "Could not determine file system of partition at sector %1 on device <filename>%2</filename>.", sector, device.deviceNode());
|
||||
|
||||
|
||||
closePed();
|
||||
|
||||
return rval;
|
||||
|
@ -312,7 +314,29 @@ FileSystem::Type Job::detectFileSystem(PedDevice* pedDevice, PedPartition* pedPa
|
|||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (rval == FileSystem::Ext3)
|
||||
{
|
||||
blkid_cache cache;
|
||||
char* pedPath = NULL;
|
||||
|
||||
if (blkid_get_cache(&cache, NULL) == 0 && (pedPath = ped_partition_get_path(pedPartition)))
|
||||
{
|
||||
blkid_dev dev;
|
||||
|
||||
if ((dev = blkid_get_dev(cache, pedPath, BLKID_DEV_NORMAL)) != NULL &&
|
||||
(blkid_dev_has_tag(dev, "TYPE", "ext4")
|
||||
|| blkid_dev_has_tag(dev, "TYPE", "ext4dev")
|
||||
)
|
||||
)
|
||||
rval = FileSystem::Ext4;
|
||||
|
||||
blkid_put_cache(cache);
|
||||
|
||||
free(pedPath);
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
@ -335,7 +359,7 @@ void Job::pedTimerHandler(PedTimer* pedTimer, void* ctx)
|
|||
Report* Job::jobStarted(Report& parent)
|
||||
{
|
||||
emit started();
|
||||
|
||||
|
||||
return parent.newChild(i18nc("@info/plain", "Job: %1", description()));
|
||||
}
|
||||
|
||||
|
@ -362,7 +386,7 @@ QIcon Job::statusIcon() const
|
|||
|
||||
if (status() < 0 || static_cast<quint32>(status()) >= sizeof(icons) / sizeof(icons[0]))
|
||||
return QIcon();
|
||||
|
||||
|
||||
return SmallIcon(icons[status()]);
|
||||
}
|
||||
|
||||
|
@ -377,9 +401,9 @@ QString Job::statusText() const
|
|||
};
|
||||
|
||||
Q_ASSERT(status() >= 0 && static_cast<quint32>(status()) < sizeof(s) / sizeof(s[0]));
|
||||
|
||||
|
||||
if (status() < 0 || static_cast<quint32>(status()) >= sizeof(s) / sizeof(s[0]))
|
||||
return QString();
|
||||
|
||||
|
||||
return s[status()];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue