From cfac1da2aaccaf45a669b0a53c82a32c8231827c Mon Sep 17 00:00:00 2001 From: Ron Yorston <rmy@pobox.com> Date: Mon, 7 Jun 2021 16:18:56 +0100 Subject: win32: partial implementation of sync(2) Provide a partial implementation of sync(2), so sync(1) can actually do something in some circumstances: - Only logical drives are handled. - Flushing buffers requires administrative privileges. If run as a normal user nothing will happen. --- win32/mingw.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'win32/mingw.c') diff --git a/win32/mingw.c b/win32/mingw.c index 3183cd78e..a65a0a6d1 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1666,6 +1666,29 @@ int mingw_rmdir(const char *path) return rmdir(path); } +void mingw_sync(void) +{ + HANDLE h; + FILE *mnt; + struct mntent *entry; + char name[] = "\\\\.\\C:"; + + mnt = setmntent(bb_path_mtab_file, "r"); + if (mnt) { + while ((entry=getmntent(mnt)) != NULL) { + name[4] = entry->mnt_dir[0]; + h = CreateFile(name, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, NULL); + if (h != INVALID_HANDLE_VALUE) { + FlushFileBuffers(h); + CloseHandle(h); + } + } + endmntent(mnt); + } +} + #define NUMEXT 5 static const char win_suffix[NUMEXT][4] = { "sh", "com", "exe", "bat", "cmd" }; -- cgit v1.2.3-55-g6feb