The fsck tool should call f2fs_finalize_device before exit to close the device
file.

Signed-off-by: Jaegeuk Kim <jaeg...@kernel.org>
---
 fsck/main.c              |  3 +++
 include/f2fs_fs.h        |  1 +
 lib/libf2fs.c            | 12 ++++++++++++
 mkfs/f2fs_format.c       |  2 --
 mkfs/f2fs_format_main.c  |  2 ++
 mkfs/f2fs_format_utils.c | 14 --------------
 mkfs/f2fs_format_utils.h |  1 -
 7 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index 5aa3956..46f5d04 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -203,6 +203,9 @@ int main (int argc, char **argv)
        }
 
        f2fs_do_umount(sbi);
+
+       f2fs_finalize_device(&config);
+
        printf("\nDone.\n");
        return ret;
 }
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 4f44866..53b8cb9 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -659,6 +659,7 @@ extern int f2fs_crc_valid(u_int32_t blk_crc, void *buf, int 
len);
 extern void f2fs_init_configuration(struct f2fs_configuration *);
 extern int f2fs_dev_is_umounted(struct f2fs_configuration *);
 extern int f2fs_get_device_info(struct f2fs_configuration *);
+extern void f2fs_finalize_device(struct f2fs_configuration *);
 
 extern int dev_read(void *, __u64, size_t);
 extern int dev_write(void *, __u64, size_t);
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 6168c5c..8d6c670 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -493,3 +493,15 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
        return 0;
 }
 
+void f2fs_finalize_device(struct f2fs_configuration *c)
+{
+       /*
+        * We should call fsync() to flush out all the dirty pages
+        * in the block device page cache.
+        */
+       if (fsync(c->fd) < 0)
+               MSG(0, "\tError: Could not conduct fsync!!!\n");
+
+       if (close(c->fd) < 0)
+               MSG(0, "\tError: Failed to close device file!!!\n");
+}
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index c7c6971..1568545 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -880,7 +880,5 @@ exit:
        if (err)
                MSG(0, "\tError: Could not format the device!!!\n");
 
-       f2fs_finalize_device();
-
        return err;
 }
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 2b6c195..19c52e4 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -129,6 +129,8 @@ int main(int argc, char *argv[])
        if (f2fs_format_device() < 0)
                return -1;
 
+       f2fs_finalize_device(&config);
+
        MSG(0, "Info: format successful\n");
 
        return 0;
diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c
index f4c3767..5cc2a32 100644
--- a/mkfs/f2fs_format_utils.c
+++ b/mkfs/f2fs_format_utils.c
@@ -15,20 +15,6 @@
 
 #include "f2fs_fs.h"
 
-void f2fs_finalize_device()
-{
-       /*
-        * We should call fsync() to flush out all the dirty pages
-        * in the block device page cache.
-        */
-       if (fsync(config.fd) < 0)
-               MSG(0, "\tError: Could not conduct fsync!!!\n");
-
-       if (close(config.fd) < 0)
-               MSG(0, "\tError: Failed to close device file!!!\n");
-
-}
-
 int f2fs_trim_device()
 {
        unsigned long long range[2];
diff --git a/mkfs/f2fs_format_utils.h b/mkfs/f2fs_format_utils.h
index fb731fc..9eb2cea 100644
--- a/mkfs/f2fs_format_utils.h
+++ b/mkfs/f2fs_format_utils.h
@@ -12,6 +12,5 @@
 
 extern struct f2fs_configuration config;
 
-void f2fs_finalize_device(void);
 int f2fs_trim_device(void);
 int f2fs_format_device(void);
-- 
1.8.5.2 (Apple Git-48)


------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to