Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8706,12 +8706,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>
Expand All @@ -8721,7 +8723,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>
Expand Down
18 changes: 18 additions & 0 deletions src/node_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1165,10 +1165,22 @@ NODE_DEFINE_CONSTANT(target, UV_FS_O_FILEMAP);

#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


Expand All @@ -1178,6 +1190,12 @@ NODE_DEFINE_CONSTANT(target, UV_FS_O_FILEMAP);

#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
Expand Down
11 changes: 10 additions & 1 deletion test/parallel/test-fs-constants.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
'use strict';
require('../common');
const common = require('../common');
const fs = require('fs');
const assert = require('assert');

// Check if the two constants accepted by chmod() on Windows are defined.
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);

Expand Down
Loading