src: define O_SYNC, O_DSYNC and O_DIRECT on Windows

Signed-off-by: Kirill Saied <sayed.kirill@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64707
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Kirill Saied authored and GitHub committed 2026-08-20 11:05:05 +00:00
1 parent fd5b13557f
commit 6d60352305
3 files changed
+33 -4

No files matched your search

+5 -3
View File
@@ -8789,12 +8789,14 @@ The following constants are meant for use with `fs.open()`.
<tr>
<td><code>O_SYNC</code></td>
<td>Flag indicating that the file is opened for synchronized I/O with write
operations waiting for file integrity.</td>
operations waiting for file integrity. On Windows, this maps to
<code>FILE_FLAG_WRITE_THROUGH</code>.</td>
</tr>
<tr>
<td><code>O_DSYNC</code></td>
<td>Flag indicating that the file is opened for synchronized I/O with write
operations waiting for data integrity.</td>
operations waiting for data integrity. On Windows, this maps to
<code>FILE_FLAG_WRITE_THROUGH</code>.</td>
</tr>
<tr>
<td><code>O_SYMLINK</code></td>
@@ -8804,7 +8806,7 @@ The following constants are meant for use with `fs.open()`.
<tr>
<td><code>O_DIRECT</code></td>
<td>When set, an attempt will be made to minimize caching effects of file
I/O.</td>
I/O. On Windows, this maps to <code>FILE_FLAG_NO_BUFFERING</code>.</td>
</tr>
<tr>
<td><code>O_NONBLOCK</code></td>
+18
View File
@@ -1170,10 +1170,22 @@ void DefineFsConstants(Local<Object> target) {
#ifdef O_SYNC
NODE_DEFINE_CONSTANT(target, O_SYNC);
#elif UV_FS_O_SYNC != 0
// Windows lacks the POSIX O_SYNC macro, but libuv maps UV_FS_O_SYNC to
// FILE_FLAG_WRITE_THROUGH, so expose it under the portable name.
#define O_SYNC UV_FS_O_SYNC
NODE_DEFINE_CONSTANT(target, O_SYNC);
#undef O_SYNC
#endif
#ifdef O_DSYNC
NODE_DEFINE_CONSTANT(target, O_DSYNC);
#elif UV_FS_O_DSYNC != 0
// Windows lacks the POSIX O_DSYNC macro, but libuv maps UV_FS_O_DSYNC to
// FILE_FLAG_WRITE_THROUGH, so expose it under the portable name.
#define O_DSYNC UV_FS_O_DSYNC
NODE_DEFINE_CONSTANT(target, O_DSYNC);
#undef O_DSYNC
#endif
@@ -1183,6 +1195,12 @@ void DefineFsConstants(Local<Object> target) {
#ifdef O_DIRECT
NODE_DEFINE_CONSTANT(target, O_DIRECT);
#elif UV_FS_O_DIRECT != 0
// Windows lacks the POSIX O_DIRECT macro, but libuv maps UV_FS_O_DIRECT to
// FILE_FLAG_NO_BUFFERING, so expose it under the portable name.
#define O_DIRECT UV_FS_O_DIRECT
NODE_DEFINE_CONSTANT(target, O_DIRECT);
#undef O_DIRECT
#endif
#ifdef O_NONBLOCK
+10 -1
View File
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
@@ -7,6 +7,15 @@ const assert = require('assert');
assert.notStrictEqual(fs.constants.S_IRUSR, undefined);
assert.notStrictEqual(fs.constants.S_IWUSR, undefined);
// O_SYNC, O_DSYNC and O_DIRECT have no POSIX macro on Windows, but libuv
// honors them via FILE_FLAG_WRITE_THROUGH / FILE_FLAG_NO_BUFFERING, so they
// are exposed under their portable names with libuv's flag values.
if (common.isWindows) {
assert.strictEqual(fs.constants.O_SYNC, 0x08000000);
assert.strictEqual(fs.constants.O_DSYNC, 0x04000000);
assert.strictEqual(fs.constants.O_DIRECT, 0x02000000);
}
// Check null prototype.
assert.strictEqual(Object.getPrototypeOf(fs.constants), null);