diff options
author | Ron Yorston <rmy@pobox.com> | 2021-06-07 16:18:56 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-06-07 16:18:56 +0100 |
commit | cfac1da2aaccaf45a669b0a53c82a32c8231827c (patch) | |
tree | 89a19cd3d661d0234e07b55ce7f7718559cc7ad8 | |
parent | abe872e2a0342357a5608342cb2892e94027b3e7 (diff) | |
download | busybox-w32-cfac1da2aaccaf45a669b0a53c82a32c8231827c.tar.gz busybox-w32-cfac1da2aaccaf45a669b0a53c82a32c8231827c.tar.bz2 busybox-w32-cfac1da2aaccaf45a669b0a53c82a32c8231827c.zip |
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.
-rw-r--r-- | include/mingw.h | 3 | ||||
-rw-r--r-- | win32/mingw.c | 23 |
2 files changed, 25 insertions, 1 deletions
diff --git a/include/mingw.h b/include/mingw.h index 49e792b69..c4849215b 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -471,7 +471,6 @@ NOIMPL(setuid,uid_t gid UNUSED_PARAM); | |||
471 | NOIMPL(seteuid,uid_t gid UNUSED_PARAM); | 471 | NOIMPL(seteuid,uid_t gid UNUSED_PARAM); |
472 | unsigned int sleep(unsigned int seconds); | 472 | unsigned int sleep(unsigned int seconds); |
473 | int symlink(const char *target, const char *linkpath); | 473 | int symlink(const char *target, const char *linkpath); |
474 | static inline void sync(void) { sleep(2); } | ||
475 | long sysconf(int name); | 474 | long sysconf(int name); |
476 | IMPL(getpagesize,int,4096,void); | 475 | IMPL(getpagesize,int,4096,void); |
477 | NOIMPL(ttyname_r,int fd UNUSED_PARAM, char *buf UNUSED_PARAM, int sz UNUSED_PARAM); | 476 | NOIMPL(ttyname_r,int fd UNUSED_PARAM, char *buf UNUSED_PARAM, int sz UNUSED_PARAM); |
@@ -479,6 +478,7 @@ int mingw_unlink(const char *pathname); | |||
479 | pid_t vfork(void); | 478 | pid_t vfork(void); |
480 | int mingw_access(const char *name, int mode); | 479 | int mingw_access(const char *name, int mode); |
481 | int mingw_rmdir(const char *name); | 480 | int mingw_rmdir(const char *name); |
481 | void mingw_sync(void); | ||
482 | int mingw_isatty(int fd); | 482 | int mingw_isatty(int fd); |
483 | 483 | ||
484 | #define dup2 mingw_dup2 | 484 | #define dup2 mingw_dup2 |
@@ -488,6 +488,7 @@ int mingw_isatty(int fd); | |||
488 | #define close mingw_close | 488 | #define close mingw_close |
489 | #define unlink mingw_unlink | 489 | #define unlink mingw_unlink |
490 | #define rmdir mingw_rmdir | 490 | #define rmdir mingw_rmdir |
491 | #define sync mingw_sync | ||
491 | #undef lseek | 492 | #undef lseek |
492 | #define lseek mingw_lseek | 493 | #define lseek mingw_lseek |
493 | 494 | ||
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) | |||
1666 | return rmdir(path); | 1666 | return rmdir(path); |
1667 | } | 1667 | } |
1668 | 1668 | ||
1669 | void mingw_sync(void) | ||
1670 | { | ||
1671 | HANDLE h; | ||
1672 | FILE *mnt; | ||
1673 | struct mntent *entry; | ||
1674 | char name[] = "\\\\.\\C:"; | ||
1675 | |||
1676 | mnt = setmntent(bb_path_mtab_file, "r"); | ||
1677 | if (mnt) { | ||
1678 | while ((entry=getmntent(mnt)) != NULL) { | ||
1679 | name[4] = entry->mnt_dir[0]; | ||
1680 | h = CreateFile(name, GENERIC_READ | GENERIC_WRITE, | ||
1681 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, | ||
1682 | OPEN_EXISTING, 0, NULL); | ||
1683 | if (h != INVALID_HANDLE_VALUE) { | ||
1684 | FlushFileBuffers(h); | ||
1685 | CloseHandle(h); | ||
1686 | } | ||
1687 | } | ||
1688 | endmntent(mnt); | ||
1689 | } | ||
1690 | } | ||
1691 | |||
1669 | #define NUMEXT 5 | 1692 | #define NUMEXT 5 |
1670 | static const char win_suffix[NUMEXT][4] = { "sh", "com", "exe", "bat", "cmd" }; | 1693 | static const char win_suffix[NUMEXT][4] = { "sh", "com", "exe", "bat", "cmd" }; |
1671 | 1694 | ||