Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bd
diff options
context:
space:
mode:
authorMartin Hoffmann <m.hoffmann@microist.com>2022-02-13 22:07:17 +0300
committerChristopher Haster <chaster@utexas.edu>2022-04-11 05:55:00 +0300
commit1e038c81fcd38ae0fe889adf332321bb17e7d859 (patch)
tree80d340f291cd6b3f201d5ffc2e1e67171543203c /bd
parent9c7e232086f865cff0bb96fe753deb66431d91fd (diff)
Fixes to use lfs_filebd on windows platforms
There are two issues, when using the file-based block device emulation on Windows Platforms: 1. There is no fsync implementation available. This needs to be mapped to a Windows-specific FlushFileBuffers system call. 2. The block device file needs to be opened as binary file (O_BINARY) The corresponding flag is not required for Linux.
Diffstat (limited to 'bd')
-rw-r--r--bd/lfs_filebd.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/bd/lfs_filebd.c b/bd/lfs_filebd.c
index 248a67f..f6c816d 100644
--- a/bd/lfs_filebd.c
+++ b/bd/lfs_filebd.c
@@ -10,6 +10,10 @@
#include <unistd.h>
#include <errno.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path,
const struct lfs_filebd_config *bdcfg) {
LFS_FILEBD_TRACE("lfs_filebd_createcfg(%p {.context=%p, "
@@ -27,7 +31,12 @@ int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path,
bd->cfg = bdcfg;
// open file
+ #ifdef _WIN32
+ bd->fd = open(path, O_RDWR | O_CREAT | O_BINARY, 0666);
+ #else
bd->fd = open(path, O_RDWR | O_CREAT, 0666);
+ #endif
+
if (bd->fd < 0) {
int err = -errno;
LFS_FILEBD_TRACE("lfs_filebd_createcfg -> %d", err);
@@ -193,7 +202,11 @@ int lfs_filebd_sync(const struct lfs_config *cfg) {
LFS_FILEBD_TRACE("lfs_filebd_sync(%p)", (void*)cfg);
// file sync
lfs_filebd_t *bd = cfg->context;
+ #ifdef _WIN32
+ int err = FlushFileBuffers((HANDLE) _get_osfhandle(fd)) ? 0 : -1;
+ #else
int err = fsync(bd->fd);
+ #endif
if (err) {
err = -errno;
LFS_FILEBD_TRACE("lfs_filebd_sync -> %d", 0);