bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 12/17] linux_swap: remove all-but-probe FS-related code


From: Jim Meyering
Subject: [PATCH 12/17] linux_swap: remove all-but-probe FS-related code
Date: Fri, 27 May 2011 17:15:31 +0200

From: Jim Meyering <address@hidden>

---
 libparted/fs/linux_swap/linux_swap.c |  276 +---------------------------------
 1 files changed, 1 insertions(+), 275 deletions(-)

diff --git a/libparted/fs/linux_swap/linux_swap.c 
b/libparted/fs/linux_swap/linux_swap.c
index 571433f..070f51b 100644
--- a/libparted/fs/linux_swap/linux_swap.c
+++ b/libparted/fs/linux_swap/linux_swap.c
@@ -130,47 +130,6 @@ error:
        return NULL;
 }

-#ifndef DISCOVER_ONLY
-static int
-_generic_swap_clobber (PedGeometry* geom, int kind)
-{
-       PedFileSystem*          fs;
-       char                    buf[512];
-
-        switch (kind) {
-        /* Check for old style swap partitions. */
-                case 0:
-                        fs = _swap_v0_open(geom);
-                        break;
-        /* Check for new style swap partitions. */
-                case 1:
-                        fs = _swap_v1_open(geom);
-                        break;
-        /* Check for swap partitions containing swsusp data. */
-                case -1:
-                        fs = _swap_swsusp_open(geom);
-                        break;
-        /* Not reached */
-                default:
-                        goto error;
-        }
-
-       if (!fs)
-               return 1;
-
-       memset (buf, 0, 512);
-       if (!ped_geometry_write (geom, buf, getpagesize() / 512 - 1, 1))
-               goto error_close_fs;
-
-       swap_close (fs);
-       return 1;
-
-error_close_fs:
-       swap_close (fs);
-error:
-       return 0;
-}
-#endif /* !DISCOVER_ONLY */

 static int
 swap_init (PedFileSystem* fs, int fresh)
@@ -199,6 +158,7 @@ swap_init (PedFileSystem* fs, int fresh)
                                           0, fs_info->page_sectors);
 }

+
 static PedFileSystem*
 swap_alloc (PedGeometry* geom)
 {
@@ -387,225 +347,6 @@ swap_close (PedFileSystem* fs)
        return 1;
 }

-#ifndef DISCOVER_ONLY
-static int
-swap_new_find_bad_page (PedFileSystem* fs, unsigned int page)
-{
-       SwapSpecific*   fs_info = SWAP_SPECIFIC (fs);
-       unsigned int    i;
-
-       for (i=0; i < fs_info->header->new.nr_badpages; i++) {
-               if (fs_info->header->new.badpages [i] == page)
-                       return i;
-       }
-
-       return 0;
-}
-
-static int
-swap_new_remove_bad_page (PedFileSystem* fs, unsigned int page)
-{
-       SwapSpecific*   fs_info = SWAP_SPECIFIC (fs);
-       unsigned int    pos;
-
-       pos = swap_new_find_bad_page (fs, page);
-       if (!pos)
-               return 0;
-
-       for (; pos < fs_info->header->new.nr_badpages; pos++) {
-               fs_info->header->new.badpages [pos - 1]
-                       = fs_info->header->new.badpages [pos];
-       }
-
-       return 1;
-}
-
-static int
-swap_mark_page (PedFileSystem* fs, unsigned int page, int ok)
-{
-       SwapSpecific*   fs_info = SWAP_SPECIFIC (fs);
-       char*           ptr;
-       unsigned int    mask;
-
-       if (fs_info->version == 0) {
-               ptr = &fs_info->header->old.page_map [page/8];
-               mask = 1 << (page%8);
-               *ptr = (*ptr & ~mask) + ok * mask;
-       } else {
-               if (ok) {
-                       if (swap_new_remove_bad_page (fs, page))
-                               fs_info->header->new.nr_badpages--;
-               } else {
-                       if (swap_new_find_bad_page (fs, page))
-                               return 1;
-
-                       if (fs_info->header->new.nr_badpages
-                                       > fs_info->max_bad_pages) {
-                               ped_exception_throw (PED_EXCEPTION_ERROR,
-                                       PED_EXCEPTION_CANCEL,
-                                       _("Too many bad pages."));
-                               return 0;
-                       }
-
-                       fs_info->header->new.badpages
-                               [fs_info->header->new.nr_badpages] = page;
-                       fs_info->header->new.nr_badpages++;
-               }
-       }
-
-       return 1;
-}
-
-static void
-swap_clear_pages (PedFileSystem* fs)
-{
-       SwapSpecific*   fs_info = SWAP_SPECIFIC (fs);
-       unsigned int    i;
-
-       for (i = 1; i < fs_info->page_count; i++) {
-               swap_mark_page (fs, i, 1);
-       }
-
-       if (fs_info->version == 0) {
-               for (; i < 1024; i++) {
-                       swap_mark_page (fs, i, 0);
-               }
-       }
-}
-
-static int
-swap_check_pages (PedFileSystem* fs, PedTimer* timer)
-{
-       SwapSpecific*   fs_info = SWAP_SPECIFIC (fs);
-       PedSector       result;
-       int             first_page = 1;
-       int             stop_page = 0;
-       int             last_page = fs_info->page_count - 1;
-       PedTimer*       nested_timer;
-
-       ped_timer_reset (timer);
-       ped_timer_set_state_name (timer, _("checking for bad blocks"));
-
-       swap_clear_pages (fs);
-       while (first_page <= last_page) {
-               nested_timer = ped_timer_new_nested (
-                                 timer,
-                                 1.0 * (last_page - first_page) / last_page);
-               result = ped_geometry_check (
-                               fs->geom,
-                               fs_info->buffer,
-                               fs_info->buffer_size / 512,
-                               first_page * fs_info->page_sectors,
-                               fs_info->page_sectors,
-                               (last_page - first_page + 1)
-                                       * fs_info->page_sectors,
-                               nested_timer);
-               ped_timer_destroy_nested (nested_timer);
-               if (!result)
-                       return 1;
-               stop_page = result / fs_info->page_sectors;
-               if (!swap_mark_page (fs, stop_page, 0))
-                       return 0;
-               first_page = stop_page + 1;
-       }
-       return 1;
-}
-
-static int
-swap_write (PedFileSystem* fs)
-{
-       SwapSpecific*   fs_info = SWAP_SPECIFIC (fs);
-       char*           sig = ((char*) fs_info->header) + getpagesize() - 10;
-
-       if (fs_info->version == 0) {
-               memcpy (sig, "SWAP-SPACE", 10);
-       } else {
-               fs_info->header->new.version = 1;
-               fs_info->header->new.last_page = fs_info->page_count - 1;
-               fs_info->header->new.nr_badpages = 0;
-               memcpy (sig, "SWAPSPACE2", 10);
-       }
-
-       return ped_geometry_write (fs->geom, fs_info->header, 0,
-                                  fs_info->page_sectors);
-}
-
-static PedFileSystem*
-swap_create (PedGeometry* geom, PedTimer* timer)
-{
-       PedFileSystem*          fs;
-
-       fs = swap_alloc (geom);
-       if (!fs)
-               goto error;
-       swap_init (fs, 1);
-       if (!swap_write (fs))
-               goto error_free_fs;
-       return fs;
-
-error_free_fs:
-       swap_free (fs);
-error:
-       return NULL;
-}
-
-static int
-swap_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
-{
-       PedGeometry*    old_geom = fs->geom;
-
-       fs->geom = ped_geometry_duplicate (geom);
-       swap_init (fs, old_geom->start != geom->start);
-       if (!swap_write (fs))
-               goto error;
-       ped_geometry_destroy (old_geom);
-       return 1;
-
-error:
-       ped_geometry_destroy (fs->geom);
-       fs->geom = old_geom;
-       return 0;
-}
-
-static PedFileSystem*
-swap_copy (const PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
-{
-       return ped_file_system_create (geom, &_swap_v1_type, timer);
-}
-
-static int
-swap_check (PedFileSystem* fs, PedTimer* timer)
-{
-       return swap_check_pages (fs, timer)
-               && swap_write (fs);
-}
-
-static PedConstraint*
-swap_get_create_constraint (const PedDevice* dev)
-{
-       PedGeometry     full_dev;
-
-       if (!ped_geometry_init (&full_dev, dev, 0, dev->length - 1))
-               return NULL;
-
-       return ped_constraint_new (ped_alignment_any, ped_alignment_any,
-                                  &full_dev, &full_dev,
-                                  getpagesize() / 512, dev->length);
-}
-
-static PedConstraint*
-swap_get_resize_constraint (const PedFileSystem* fs)
-{
-       return swap_get_create_constraint (fs->geom->dev);
-}
-
-static PedConstraint*
-swap_get_copy_constraint (const PedFileSystem* fs, const PedDevice* dev)
-{
-       return swap_get_create_constraint (dev);
-}
-#endif /* !DISCOVER_ONLY */
-
 static PedGeometry*
 _swap_v0_probe (PedGeometry* geom) {
         return _generic_swap_probe (geom, 0);
@@ -621,21 +362,6 @@ _swap_swsusp_probe (PedGeometry* geom) {
         return _generic_swap_probe (geom, -1);
 }

-static int
-_swap_v0_clobber (PedGeometry* geom) {
-        return _generic_swap_clobber (geom, 0);
-}
-
-static int
-_swap_v1_clobber (PedGeometry* geom) {
-        return _generic_swap_clobber (geom, 1);
-}
-
-static int
-_swap_swsusp_clobber (PedGeometry* geom) {
-        return _generic_swap_clobber (geom, -1);
-}
-
 static PedFileSystemOps _swap_v0_ops = {
        probe:          _swap_v0_probe,
 };
-- 
1.7.5.2.660.g9f46c




reply via email to

[Prev in Thread] Current Thread [Next in Thread]