[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/10] lib-fs-resize: rewrite ped_file_system_clobber
From: |
Jim Meyering |
Subject: |
[PATCH 05/10] lib-fs-resize: rewrite ped_file_system_clobber |
Date: |
Fri, 3 Feb 2012 22:46:54 +0100 |
From: Jim Meyering <address@hidden>
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
- libparted-fs-resize: HFS/FAT file system resizing library, Jim Meyering, 2012/02/03
- [PATCH 01/10] maint: remove now-unused fat-related functions, Jim Meyering, 2012/02/03
- [PATCH 07/10] lib-fs-resize: use linker script to expose only selected functions, Jim Meyering, 2012/02/03
- [PATCH 03/10] update copyrights in r/, Jim Meyering, 2012/02/03
- [PATCH 04/10] lib-fs-resize: add wrappers for open, close, resize, get_resize_constraint, Jim Meyering, 2012/02/03
- [PATCH 05/10] lib-fs-resize: rewrite ped_file_system_clobber,
Jim Meyering <=
- [PATCH 10/10] doc: mention HFS+/FAT file system resizing in NEWS, Jim Meyering, 2012/02/03
- [PATCH 09/10] tests: test FAT and HFS file system resizing, Jim Meyering, 2012/02/03
- [PATCH 08/10] tests: add FS-resize test driver, Jim Meyering, 2012/02/03
- [PATCH 06/10] maint: remove r/hfs/DOC,HISTORY,TODO; add VERSION for new library, Jim Meyering, 2012/02/03
- [PATCH 02/10] lib-fs-resize: re-add HFS and FAT file-system-related code, Jim Meyering, 2012/02/03
- Re: libparted-fs-resize: HFS/FAT file system resizing library, Curtis Gedak, 2012/02/03
- Re: libparted-fs-resize: HFS/FAT file system resizing library, Curtis Gedak, 2012/02/04