From 6a2b4c5c09eb3ac74b4d89a981d53f3ea125a94e Mon Sep 17 00:00:00 2001 From: Volker Lanz Date: Sun, 28 Aug 2011 13:25:16 +0000 Subject: [PATCH] Make KDE Partition Manager build and work with libparted 3.x. This mostly means anything that libparted used to do regarding file systems (mainly resizing fat16 and fat32) is now no longer possible. BUG:278569 svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1249901 --- cmake/modules/FindLIBPARTED.cmake | 18 +++++++++++-- src/fs/fat16.cpp | 8 +++--- src/fs/hfs.cpp | 6 +---- src/fs/hfsplus.cpp | 7 ++---- src/plugins/libparted/CMakeLists.txt | 4 +++ src/plugins/libparted/libpartedbackend.cpp | 12 ++++++++- .../libparted/libpartedpartitiontable.cpp | 25 ++++++++++++++++--- 7 files changed, 59 insertions(+), 21 deletions(-) diff --git a/cmake/modules/FindLIBPARTED.cmake b/cmake/modules/FindLIBPARTED.cmake index 7a7c1f6..61fcc09 100644 --- a/cmake/modules/FindLIBPARTED.cmake +++ b/cmake/modules/FindLIBPARTED.cmake @@ -1,4 +1,4 @@ -# Copyright (C) 2008,2010 by Volker Lanz +# Copyright (C) 2008,2010,2011 by Volker Lanz # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -21,6 +21,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +INCLUDE(CheckCSourceCompiles) + if (LIBPARTED_INCLUDE_DIR AND LIBPARTED_LIBRARY) # Already in cache, be silent set(LIBPARTED_FIND_QUIETLY TRUE) @@ -36,4 +38,16 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBPARTED DEFAULT_MSG LIBPARTED_LIBRARY LIBPAR SET(LIBPARTED_LIBS ${LIBPARTED_LIBRARY}) -MARK_AS_ADVANCED(LIBPARTED_LIBRARY LIBPARTED_INCLUDE_DIR) +# KDE adds -ansi to the C make flags, parted headers use GNU extensions, so +# undo that +unset(CMAKE_C_FLAGS) + +set(CMAKE_REQUIRED_INCLUDES ${LIBPARTED_INCLUDE_DIR}) +set(CMAKE_REQUIRED_LIBRARIES ${LIBPARTED_LIBS}) + +CHECK_C_SOURCE_COMPILES(" +#include +int main() { ped_file_system_clobber(0); } +" LIBPARTED_FILESYSTEM_SUPPORT) + +MARK_AS_ADVANCED(LIBPARTED_LIBRARY LIBPARTED_INCLUDE_DIR LIBPARTED_FILESYSTEM_SUPPORT) diff --git a/src/fs/fat16.cpp b/src/fs/fat16.cpp index 13c366b..3ceec89 100644 --- a/src/fs/fat16.cpp +++ b/src/fs/fat16.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008,2009 by Volker Lanz * + * Copyright (C) 2008,2009,2011 by Volker Lanz * * * * 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 * @@ -60,8 +60,6 @@ namespace FS m_GetUsed = m_Check = findExternal("fsck.msdos", QStringList(), 2) ? cmdSupportFileSystem : cmdSupportNone; m_GetLabel = cmdSupportCore; m_SetLabel = cmdSupportFileSystem; - m_Grow = cmdSupportNone; - m_Shrink = cmdSupportNone; m_Move = cmdSupportCore; m_Copy = cmdSupportCore; m_Backup = cmdSupportCore; @@ -78,8 +76,8 @@ namespace FS m_Create != cmdSupportNone && m_Check != cmdSupportNone && m_UpdateUUID != cmdSupportNone && - m_Grow != cmdSupportNone && - m_Shrink != cmdSupportNone && +// m_Grow != cmdSupportNone && +// m_Shrink != cmdSupportNone && m_Copy != cmdSupportNone && m_Move != cmdSupportNone && m_Backup != cmdSupportNone && diff --git a/src/fs/hfs.cpp b/src/fs/hfs.cpp index f7771c8..d9b76b9 100644 --- a/src/fs/hfs.cpp +++ b/src/fs/hfs.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Volker Lanz * + * Copyright (C) 2008,2011 by Volker Lanz * * * * 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 * @@ -46,10 +46,6 @@ namespace FS m_GetLabel = cmdSupportCore; m_Create = findExternal("hformat") ? cmdSupportFileSystem : cmdSupportNone; m_Check = findExternal("hfsck") ? cmdSupportFileSystem : cmdSupportNone; - - m_GetUsed = cmdSupportCore; - m_Shrink = cmdSupportNone; - m_Move = m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Backup = cmdSupportCore; } diff --git a/src/fs/hfsplus.cpp b/src/fs/hfsplus.cpp index 860dc0f..7789658 100644 --- a/src/fs/hfsplus.cpp +++ b/src/fs/hfsplus.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Volker Lanz * + * Copyright (C) 2008,2011 by Volker Lanz * * * * 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 * @@ -41,9 +41,6 @@ namespace FS void hfsplus::init() { m_Check = findExternal("hpfsck") ? cmdSupportFileSystem : cmdSupportNone; - - m_GetUsed = cmdSupportCore; - m_Shrink = cmdSupportNone; m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_Backup = cmdSupportCore; @@ -52,7 +49,7 @@ namespace FS bool hfsplus::supportToolFound() const { return - m_GetUsed != cmdSupportNone && +// m_GetUsed != cmdSupportNone && // m_GetLabel != cmdSupportNone && // m_SetLabel != cmdSupportNone && // m_Create != cmdSupportNone && diff --git a/src/plugins/libparted/CMakeLists.txt b/src/plugins/libparted/CMakeLists.txt index 0e59510..e1544c4 100644 --- a/src/plugins/libparted/CMakeLists.txt +++ b/src/plugins/libparted/CMakeLists.txt @@ -17,6 +17,10 @@ find_package(LIBPARTED REQUIRED) +if (LIBPARTED_FILESYSTEM_SUPPORT) + add_definitions(-DLIBPARTED_FILESYSTEM_SUPPORT) +endif (LIBPARTED_FILESYSTEM_SUPPORT) + include_directories(${LIBPARTED_INCLUDE_DIR}) file (GLOB pmlibpartedbackendplugin_SRCS *.cpp) diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index 34634bd..ddcf45b 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008,2009,2010 by Volker Lanz * + * Copyright (C) 2008,2009,2010,2011 by Volker Lanz * * * * 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 * @@ -191,6 +191,7 @@ static quint64 lastUsableSector(const Device& d) @param p the Partition the FileSystem is on @return the number of sectors used */ +#if defined LIBPARTED_FILESYSTEM_SUPPORT static qint64 readSectorsUsedLibParted(PedDisk* pedDisk, const Partition& p) { Q_ASSERT(pedDisk); @@ -217,6 +218,7 @@ static qint64 readSectorsUsedLibParted(PedDisk* pedDisk, const Partition& p) return rval; } +#endif /** Reads the sectors used in a FileSystem and stores the result in the Partition's FileSystem object. @param pedDisk pointer to pedDisk where the Partition and its FileSystem are @@ -233,8 +235,12 @@ static void readSectorsUsed(PedDisk* pedDisk, const Device& d, Partition& p, con p.fileSystem().setSectorsUsed(freeSpaceInfo.used() / d.logicalSectorSize()); else if (p.fileSystem().supportGetUsed() == FileSystem::cmdSupportFileSystem) p.fileSystem().setSectorsUsed(p.fileSystem().readUsedCapacity(p.deviceNode()) / d.logicalSectorSize()); +#if defined LIBPARTED_FILESYSTEM_SUPPORT else if (p.fileSystem().supportGetUsed() == FileSystem::cmdSupportCore) p.fileSystem().setSectorsUsed(readSectorsUsedLibParted(pedDisk, p)); +#else + Q_UNUSED(pedDisk); +#endif } static PartitionTable::Flags activeFlags(PedPartition* p) @@ -283,10 +289,14 @@ LibPartedBackend::LibPartedBackend(QObject*, const QList&) : void LibPartedBackend::initFSSupport() { +#if defined LIBPARTED_FILESYSTEM_SUPPORT FS::fat16::m_Shrink = FileSystem::cmdSupportBackend; FS::fat16::m_Grow = FileSystem::cmdSupportBackend; FS::hfs::m_Shrink = FileSystem::cmdSupportBackend; FS::hfsplus::m_Shrink = FileSystem::cmdSupportBackend; + FS::hfs::m_GetUsed = FileSystem::cmdSupportBackend; + FS::hfsplus::m_GetUsed = FileSystem::cmdSupportBackend; +#endif } /** Scans a Device for Partitions. diff --git a/src/plugins/libparted/libpartedpartitiontable.cpp b/src/plugins/libparted/libpartedpartitiontable.cpp index f433da9..59a6f73 100644 --- a/src/plugins/libparted/libpartedpartitiontable.cpp +++ b/src/plugins/libparted/libpartedpartitiontable.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Volker Lanz geom)) @@ -285,19 +285,33 @@ bool LibPartedPartitionTable::clobberFileSystem(Report& report, const Partition& } else report.line() << i18nc("@info/plain", "Could not delete file system on partition %1: Failed to get partition.", partition.deviceNode()); +#else + // One would assume we'd need to implement clobbering ourselves here, now that libparted does not + // support it anymore. + // Strangely enough, creating a partition with a valid file system, then deleting it without any + // removing of file system signatues, then creating a new unfortmatted partition in its place with + // the exact same geometry does NOT result in the old file system being magically restored. So + // it appears to be ok to just skip clobbering altogether. + Q_UNUSED(report); + Q_UNUSED(partition); + rval = true; +#endif return rval; } +#if defined LIBPARTED_FILESYSTEM_SUPPORT static void pedTimerHandler(PedTimer* pedTimer, void*) { CoreBackendManager::self()->backend()->emitProgress(pedTimer->frac * 100); } +#endif bool LibPartedPartitionTable::resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) { bool rval = false; +#if defined LIBPARTED_FILESYSTEM_SUPPORT if (PedGeometry* originalGeometry = ped_geometry_new(pedDevice(), partition.fileSystem().firstSector(), partition.fileSystem().length())) { if (PedFileSystem* pedFileSystem = ped_file_system_open(originalGeometry)) @@ -321,7 +335,12 @@ bool LibPartedPartitionTable::resizeFileSystem(Report& report, const Partition& } else report.line() << i18nc("@info/plain", "Could not read geometry for partition %1 while trying to resize the file system.", partition.deviceNode()); - +#else + Q_UNUSED(report); + Q_UNUSED(partition); + Q_UNUSED(newLength); +#endif + return rval; }