From: Jim Meyering <[email protected]>
Before, it would probe for an existing file system type and then,
according to what it found, call the corresponding <FS_TYPE>_clobber
function. Now that we have restored only HFS and FAT FS-writing
support, only those few types have a corresponding _clobber function.
We would obviously fail to clear common types of file systems, and even
if we were to restore all previous _clobber functions, none of those
were able to handle sector sizes larger than 512. Not worth it.
* libparted/fs/r/filesys.c: Include pt-tools.h.
(MIN): Define.
(ped_file_system_clobber): Rewrite not to use hfs*_clobber or
fat_clobber. Instead, simply clear the first three and last two
sectors of the specified "device".
* libparted/fs/Makefile.am (INCLUDES): Add
-I$(top_srcdir)/libparted/labels for new use of a ptt_* function.
---
libparted/fs/Makefile.am | 5 +++-
libparted/fs/r/filesys.c | 47 ++++++++++++++++-----------------------------
2 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/libparted/fs/Makefile.am b/libparted/fs/Makefile.am
index ddc8fd9..b579381 100644
--- a/libparted/fs/Makefile.am
+++ b/libparted/fs/Makefile.am
@@ -102,4 +102,7 @@ libparted_fs_resize_la_SOURCES = \
r/hfs/reloc_plus.c \
r/hfs/reloc_plus.h
-INCLUDES = $(partedincludedir) $(INTLINCS)
+INCLUDES = \
+ -I$(top_srcdir)/libparted/labels \
+ $(partedincludedir) \
+ $(INTLINCS)
diff --git a/libparted/fs/r/filesys.c b/libparted/fs/r/filesys.c
index 6463ab5..7466128 100644
--- a/libparted/fs/r/filesys.c
+++ b/libparted/fs/r/filesys.c
@@ -29,6 +29,7 @@
#include <parted/parted.h>
#include <parted/debug.h>
+#include "pt-tools.h"
#if ENABLE_NLS
# include <libintl.h>
@@ -39,6 +40,10 @@
#define STREQ(a, b) (strcmp (a, b) == 0)
+#ifndef MIN
+# define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
typedef PedFileSystem * (*open_fn_t) (PedGeometry *);
extern PedFileSystem *hfsplus_open (PedGeometry *);
extern PedFileSystem *hfs_open (PedGeometry *);
@@ -215,40 +220,22 @@ error_close_dev:
static int
ped_file_system_clobber (PedGeometry* geom)
{
- PedFileSystemType* fs_type = NULL;
-
- PED_ASSERT (geom != NULL);
-
- if (!ped_device_open (geom->dev))
- goto error;
+ PED_ASSERT (geom != NULL);
- ped_exception_fetch_all ();
- while ((fs_type = ped_file_system_type_get_next (fs_type))) {
- PedGeometry* probed;
+ if (!ped_device_open (geom->dev))
+ return 0;
- if (!fs_type->ops->clobber)
- continue;
+ /* Clear the first three and the last two sectors, albeit fewer
+ when GEOM is too small. */
+ PedSector len = MIN (geom->length, geom->dev->length);
- probed = ped_file_system_probe_specific (fs_type, geom);
- if (!probed) {
- ped_exception_catch ();
- continue;
- }
- ped_geometry_destroy (probed);
+ int ok = (len <= 5
+ ? ptt_geom_clear_sectors (geom, 0, len)
+ : (ptt_geom_clear_sectors (geom, 0, 3)
+ && ptt_geom_clear_sectors (geom, geom->dev->length - 2, 2)));
- if (fs_type->ops->clobber && !fs_type->ops->clobber (geom)) {
- ped_exception_leave_all ();
- goto error_close_dev;
- }
- }
- ped_device_close (geom->dev);
- ped_exception_leave_all ();
- return 1;
-
-error_close_dev:
- ped_device_close (geom->dev);
-error:
- return 0;
+ ped_device_close (geom->dev);
+ return !!ok;
}
/* This function erases all signatures that indicate the presence of
--
1.7.9.112.gb85f2