OSDN Git Service

lib-fs-resize: rewrite ped_file_system_clobber
authorJim Meyering <meyering@redhat.com>
Tue, 20 Dec 2011 09:27:45 +0000 (10:27 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 10 Feb 2012 19:05:49 +0000 (20:05 +0100)
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
libparted/fs/r/filesys.c

index d0e60f5..da85655 100644 (file)
@@ -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)
index 1b3f752..7bffea0 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <parted/parted.h>
 #include <parted/debug.h>
+#include "pt-tools.h"
 
 #if ENABLE_NLS
 #  include <libintl.h>
 
 #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