Whamcloud - gitweb
libext2fs: call numeric_progress functions through a operations struct
authorTheodore Ts'o <tytso@mit.edu>
Mon, 30 Jul 2012 21:16:51 +0000 (17:16 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 30 Jul 2012 21:19:19 +0000 (17:19 -0400)
Instead of calling ext2fs_numeric_progress_*() directly from closefs.c
and alloc_tables.c, call it via a operations structure which is only
initialized by the one program (mke2fs) which needs it.

This reduces the number of C library symbols needed by boot loader
systems such as yaboot.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/alloc_tables.c
lib/ext2fs/closefs.c
lib/ext2fs/ext2fs.h
lib/ext2fs/ext2fsP.h
lib/ext2fs/progress.c
misc/mke2fs.c

index 9f3d4e0..5e6e556 100644 (file)
@@ -230,16 +230,19 @@ errcode_t ext2fs_allocate_tables(ext2_filsys fs)
        dgrp_t          i;
        struct ext2fs_numeric_progress_struct progress;
 
-       ext2fs_numeric_progress_init(fs, &progress, NULL,
-                                    fs->group_desc_count);
+       if (fs->progress_ops && fs->progress_ops->init)
+               (fs->progress_ops->init)(fs, &progress, NULL,
+                                        fs->group_desc_count);
 
        for (i = 0; i < fs->group_desc_count; i++) {
-               ext2fs_numeric_progress_update(fs, &progress, i);
+               if (fs->progress_ops && fs->progress_ops->update)
+                       (fs->progress_ops->update)(fs, &progress, i);
                retval = ext2fs_allocate_group_table(fs, i, fs->block_map);
                if (retval)
                        return retval;
        }
-       ext2fs_numeric_progress_close(fs, &progress, NULL);
+       if (fs->progress_ops && fs->progress_ops->close)
+               (fs->progress_ops->close)(fs, &progress, NULL);
        return 0;
 }
 
index 973c2a2..bb7f8b3 100644 (file)
@@ -340,14 +340,16 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags)
        else
                old_desc_blocks = fs->desc_blocks;
 
-       ext2fs_numeric_progress_init(fs, &progress, NULL,
-                                    fs->group_desc_count);
+       if (fs->progress_ops && fs->progress_ops->init)
+               (fs->progress_ops->init)(fs, &progress, NULL,
+                                        fs->group_desc_count);
 
 
        for (i = 0; i < fs->group_desc_count; i++) {
                blk64_t super_blk, old_desc_blk, new_desc_blk;
 
-               ext2fs_numeric_progress_update(fs, &progress, i);
+               if (fs->progress_ops && fs->progress_ops->update)
+                       (fs->progress_ops->update)(fs, &progress, i);
                ext2fs_super_and_bgd_loc2(fs, i, &super_blk, &old_desc_blk,
                                         &new_desc_blk, 0);
 
@@ -376,7 +378,8 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags)
                }
        }
 
-       ext2fs_numeric_progress_close(fs, &progress, NULL);
+       if (fs->progress_ops && fs->progress_ops->close)
+               (fs->progress_ops->close)(fs, &progress, NULL);
 
        /*
         * If the write_bitmaps() function is present, call it to
index 62282b1..5746b4f 100644 (file)
@@ -267,6 +267,9 @@ struct struct_ext2_filsys {
         * Time at which e2fsck last updated the MMP block.
         */
        long mmp_last_written;
+
+       /* progress operation functions */
+       struct ext2fs_progress_ops *progress_ops;
 };
 
 #if EXT2_FLAT_INCLUDES
index 729d5c5..bdfb85e 100644 (file)
@@ -95,6 +95,23 @@ struct ext2fs_numeric_progress_struct {
        int             skip_progress;
 };
 
+/*
+ * progress callback functions
+ */
+struct ext2fs_progress_ops {
+       void (*init)(ext2_filsys fs,
+                    struct ext2fs_numeric_progress_struct * progress,
+                    const char *label, __u64 max);
+       void (*update)(ext2_filsys fs,
+                      struct ext2fs_numeric_progress_struct * progress,
+                      __u64 val);
+       void (*close)(ext2_filsys fs,
+                     struct ext2fs_numeric_progress_struct * progress,
+                     const char *message);
+};
+
+extern struct ext2fs_progress_ops ext2fs_numeric_progress_ops;
+
 extern void ext2fs_numeric_progress_init(ext2_filsys fs,
                                         struct ext2fs_numeric_progress_struct * progress,
                                         const char *label, __u64 max);
index 37d1509..432816b 100644 (file)
 
 static char spaces[80], backspaces[80];
 
+struct ext2fs_progress_ops ext2fs_numeric_progress_ops = {
+       .init           = ext2fs_numeric_progress_init,
+       .update         = ext2fs_numeric_progress_update,
+       .close          = ext2fs_numeric_progress_close,
+};
+
 static int int_log10(unsigned int arg)
 {
        int     l;
index 7ec8cc2..01b2111 100644 (file)
@@ -2277,6 +2277,7 @@ int main (int argc, char *argv[])
                com_err(device_name, retval, _("while setting up superblock"));
                exit(1);
        }
+       fs->progress_ops = &ext2fs_numeric_progress_ops;
 
        /* Can't undo discard ... */
        if (!noaction && discard && (io_ptr != undo_io_manager)) {