external/parted
Révision | f5308e408980443b20cb35696b09e1f6e6e60966 (tree) |
---|---|
l'heure | 2012-02-11 04:05:49 |
Auteur | Jim Meyering <meyering@redh...> |
Commiter | Jim Meyering |
lib-fs-resize: rewrite ped_file_system_clobber
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.
@@ -102,4 +102,7 @@ libparted_fs_resize_la_SOURCES = \ | ||
102 | 102 | r/hfs/reloc_plus.c \ |
103 | 103 | r/hfs/reloc_plus.h |
104 | 104 | |
105 | -INCLUDES = $(partedincludedir) $(INTLINCS) | |
105 | +INCLUDES = \ | |
106 | + -I$(top_srcdir)/libparted/labels \ | |
107 | + $(partedincludedir) \ | |
108 | + $(INTLINCS) |
@@ -29,6 +29,7 @@ | ||
29 | 29 | |
30 | 30 | #include <parted/parted.h> |
31 | 31 | #include <parted/debug.h> |
32 | +#include "pt-tools.h" | |
32 | 33 | |
33 | 34 | #if ENABLE_NLS |
34 | 35 | # include <libintl.h> |
@@ -39,6 +40,10 @@ | ||
39 | 40 | |
40 | 41 | #define STREQ(a, b) (strcmp (a, b) == 0) |
41 | 42 | |
43 | +#ifndef MIN | |
44 | +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) | |
45 | +#endif | |
46 | + | |
42 | 47 | typedef PedFileSystem * (*open_fn_t) (PedGeometry *); |
43 | 48 | extern PedFileSystem *hfsplus_open (PedGeometry *); |
44 | 49 | extern PedFileSystem *hfs_open (PedGeometry *); |
@@ -215,40 +220,22 @@ error_close_dev: | ||
215 | 220 | static int |
216 | 221 | ped_file_system_clobber (PedGeometry* geom) |
217 | 222 | { |
218 | - PedFileSystemType* fs_type = NULL; | |
219 | - | |
220 | - PED_ASSERT (geom != NULL); | |
221 | - | |
222 | - if (!ped_device_open (geom->dev)) | |
223 | - goto error; | |
223 | + PED_ASSERT (geom != NULL); | |
224 | 224 | |
225 | - ped_exception_fetch_all (); | |
226 | - while ((fs_type = ped_file_system_type_get_next (fs_type))) { | |
227 | - PedGeometry* probed; | |
225 | + if (!ped_device_open (geom->dev)) | |
226 | + return 0; | |
228 | 227 | |
229 | - if (!fs_type->ops->clobber) | |
230 | - continue; | |
228 | + /* Clear the first three and the last two sectors, albeit fewer | |
229 | + when GEOM is too small. */ | |
230 | + PedSector len = MIN (geom->length, geom->dev->length); | |
231 | 231 | |
232 | - probed = ped_file_system_probe_specific (fs_type, geom); | |
233 | - if (!probed) { | |
234 | - ped_exception_catch (); | |
235 | - continue; | |
236 | - } | |
237 | - ped_geometry_destroy (probed); | |
232 | + int ok = (len <= 5 | |
233 | + ? ptt_geom_clear_sectors (geom, 0, len) | |
234 | + : (ptt_geom_clear_sectors (geom, 0, 3) | |
235 | + && ptt_geom_clear_sectors (geom, geom->dev->length - 2, 2))); | |
238 | 236 | |
239 | - if (fs_type->ops->clobber && !fs_type->ops->clobber (geom)) { | |
240 | - ped_exception_leave_all (); | |
241 | - goto error_close_dev; | |
242 | - } | |
243 | - } | |
244 | - ped_device_close (geom->dev); | |
245 | - ped_exception_leave_all (); | |
246 | - return 1; | |
247 | - | |
248 | -error_close_dev: | |
249 | - ped_device_close (geom->dev); | |
250 | -error: | |
251 | - return 0; | |
237 | + ped_device_close (geom->dev); | |
238 | + return !!ok; | |
252 | 239 | } |
253 | 240 | |
254 | 241 | /* This function erases all signatures that indicate the presence of |