libf2fs, fsck, mkfs: call f2fs_finalize_device before exit
PATCH 1/1 libf2fs, fsck, mkfs: call f2fs_finalize_device before exit
The fsck tool should call f2fs_finalize_device before exit to close the device file.
--- 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(-)
fsck/main.c +3 -0
@@ -203,6 +203,9 @@ int main (int argc, char **argv) }f2fs_do_umount (sbi); + +f2fs_finalize_device (&config); +printf ("\nDone.\n" );return ret; }
include/f2fs_fs.h +1 -0
@@ -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 );
lib/libf2fs.c +12 -0
@@ -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" ); +}
mkfs/f2fs_format.c +0 -2
@@ -880,7 +880,5 @@ exit:if (err)MSG (0 ,"\tError: Could not format the device!!!\n" ); -f2fs_finalize_device (); -return err; }
mkfs/f2fs_format_main.c +2 -0
@@ -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 ;
mkfs/f2fs_format_utils.c +0 -14
@@ -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 ];
mkfs/f2fs_format_utils.h +0 -1
@@ -12,6 +12,5 @@extern struct f2fs_configuration config; -void f2fs_finalize_device (void );int f2fs_trim_device (void );int f2fs_format_device (void );
Signature · 9 lines
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
Quoted 10 lines · Jaegeuk Kim
lib/libf2fs.c +2
-0@@ -493,3 +493,15 @@ int f2fs_get_device_info(struct f2fs_configuration *c)return 0 ; } +void f2fs_finalize_device (struct f2fs_configuration *c) +{
lib/libf2fs.c int f2fs_get_device_info(struct f2fs_configuration *c) · line 507
Quoted 10 lines
lib/libf2fs.c +10
-0+/* +* 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" ); +}
This might be better in lib/libf2fs_io.c.
It should stay outside of libf2fs otherwise it prevents building code that works on something else that an fd which supports fsync/close/... Currently libf2fs is device agnostic: I'm able to use it against Android's libsparse by linking against a lib that provides stubs for everything in f2fs_format_utils.c and lib/libf2fs_io.c.
------------------------------------------------------------------------------
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