From: Vladimir Serbinenko Date: Wed, 27 Nov 2013 13:13:50 +0000 (+0100) Subject: Introduce grub_util_file_sync and use it instead of fsync(fileno(f)). X-Git-Tag: grub-2.02-beta1~199 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f9541226ccdda1beca805e1bec6c0cbaa485562;p=thirdparty%2Fgrub.git Introduce grub_util_file_sync and use it instead of fsync(fileno(f)). Fixes build for windows. --- diff --git a/ChangeLog b/ChangeLog index d06f3e7ba..b4708df7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-11-27 Vladimir Serbinenko + + Introduce grub_util_file_sync and use it instead of fsync(fileno(f)). + Fixes build for windows. + 2013-11-27 Vladimir Serbinenko * gentpl.py: Don't generate platform-dependent conditionals for diff --git a/grub-core/osdep/aros/hostdisk.c b/grub-core/osdep/aros/hostdisk.c index b15390766..c7efb9608 100644 --- a/grub-core/osdep/aros/hostdisk.c +++ b/grub-core/osdep/aros/hostdisk.c @@ -485,6 +485,15 @@ grub_util_fd_sync (grub_util_fd_t fd) } } +void +grub_util_file_sync (FILE *f) +{ + fflush (f); + if (!allow_fd_syncs) + return; + fsync (fileno (f)); +} + void grub_util_disable_fd_syncs (void) { diff --git a/grub-core/osdep/unix/hostdisk.c b/grub-core/osdep/unix/hostdisk.c index fc88ed4cc..309562af4 100644 --- a/grub-core/osdep/unix/hostdisk.c +++ b/grub-core/osdep/unix/hostdisk.c @@ -200,6 +200,15 @@ grub_util_fd_sync (grub_util_fd_t fd) fsync (fd); } +void +grub_util_file_sync (FILE *f) +{ + fflush (f); + if (!allow_fd_syncs) + return; + fsync (fileno (f)); +} + void grub_util_disable_fd_syncs (void) { diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c index 4748a616f..41ab318c0 100644 --- a/grub-core/osdep/windows/hostdisk.c +++ b/grub-core/osdep/windows/hostdisk.c @@ -584,12 +584,16 @@ grub_util_fopen (const char *path, const char *mode) return ret; } -int fsync (int fno) +void +grub_util_file_sync (FILE *f) { HANDLE hnd; - hnd = (HANDLE) _get_osfhandle (fno); + + fflush (f); + if (!allow_fd_syncs) + return; + hnd = (HANDLE) _get_osfhandle (fileno (f)); FlushFileBuffers (hnd); - return 0; } int diff --git a/include/grub/emu/misc.h b/include/grub/emu/misc.h index c4e579b0b..4f708cf10 100644 --- a/include/grub/emu/misc.h +++ b/include/grub/emu/misc.h @@ -66,4 +66,6 @@ FILE * grub_util_fopen (const char *path, const char *mode); #endif +void grub_util_file_sync (FILE *f); + #endif /* GRUB_EMU_MISC_H */ diff --git a/include/grub/osdep/hostfile_windows.h b/include/grub/osdep/hostfile_windows.h index e928b3f96..36615b2c4 100644 --- a/include/grub/osdep/hostfile_windows.h +++ b/include/grub/osdep/hostfile_windows.h @@ -79,10 +79,4 @@ grub_util_utf8_to_tchar (const char *in); char * grub_util_tchar_to_utf8 (LPCTSTR in); -#ifdef __MINGW32__ - -int fsync (int fno); - -#endif - #endif diff --git a/util/editenv.c b/util/editenv.c index 264531345..f79e405d7 100644 --- a/util/editenv.c +++ b/util/editenv.c @@ -53,7 +53,8 @@ grub_util_create_envblk_file (const char *name) grub_util_error (_("cannot write to `%s': %s"), namenew, strerror (errno)); - fsync (fileno (fp)); + + grub_util_file_sync (fp); free (buf); fclose (fp); diff --git a/util/grub-editenv.c b/util/grub-editenv.c index cffcf9e0d..540495b45 100644 --- a/util/grub-editenv.c +++ b/util/grub-editenv.c @@ -188,7 +188,7 @@ write_envblk (const char *name, grub_envblk_t envblk) grub_util_error (_("cannot write to `%s': %s"), name, strerror (errno)); - fsync (fileno (fp)); + grub_util_file_sync (fp); fclose (fp); } diff --git a/util/grub-install-common.c b/util/grub-install-common.c index fcf994d5b..91b558e1e 100644 --- a/util/grub-install-common.c +++ b/util/grub-install-common.c @@ -491,8 +491,7 @@ grub_install_make_image_wrap (const char *dir, const char *prefix, grub_install_make_image_wrap_file (dir, prefix, fp, outname, memdisk_path, config_path, mkimage_target, note, comp); - fflush (fp); - grub_util_fd_sync (fileno (fp)); + grub_util_file_sync (fp); fclose (fp); } diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c index 33cce36ad..02437417d 100644 --- a/util/grub-mkimage.c +++ b/util/grub-mkimage.c @@ -285,8 +285,7 @@ main (int argc, char *argv[]) arguments.image_target, arguments.note, arguments.comp); - fflush (fp); - fsync (fileno (fp)); + grub_util_file_sync (fp); fclose (fp); if (arguments.dir)