aboutsummaryrefslogtreecommitdiff
path: root/src/win/fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/win/fs.c')
-rw-r--r--src/win/fs.c97
1 files changed, 62 insertions, 35 deletions
diff --git a/src/win/fs.c b/src/win/fs.c
index fb1a5844..cc2e8db9 100644
--- a/src/win/fs.c
+++ b/src/win/fs.c
@@ -167,9 +167,10 @@ typedef enum {
FS__STAT_PATH_TRY_SLOW
} fs__stat_path_return_t;
-INLINE static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf);
-INLINE static void fs__stat_assign_statbuf(uv_stat_t* statbuf,
- FILE_STAT_BASIC_INFORMATION stat_info, int do_lstat);
+static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf);
+static void fs__stat_assign_statbuf(uv_stat_t* statbuf,
+ FILE_STAT_BASIC_INFORMATION stat_info,
+ int do_lstat);
void uv__fs_init(void) {
@@ -182,9 +183,9 @@ void uv__fs_init(void) {
}
-INLINE static int fs__readlink_handle(HANDLE handle,
- char** target_ptr,
- size_t* target_len_ptr) {
+static int fs__readlink_handle(HANDLE handle,
+ char** target_ptr,
+ size_t* target_len_ptr) {
char buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
REPARSE_DATA_BUFFER* reparse_data = (REPARSE_DATA_BUFFER*) buffer;
WCHAR* w_target;
@@ -319,8 +320,10 @@ INLINE static int fs__readlink_handle(HANDLE handle,
}
-INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
- const char* new_path, const int copy_path) {
+static int fs__capture_path(uv_fs_t* req,
+ const char* path,
+ const char* new_path,
+ const int copy_path) {
WCHAR* buf;
WCHAR* pos;
size_t buf_sz = 0;
@@ -394,8 +397,10 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
}
-INLINE static void uv__fs_req_init(uv_loop_t* loop, uv_fs_t* req,
- uv_fs_type fs_type, const uv_fs_cb cb) {
+static void uv__fs_req_init(uv_loop_t* loop,
+ uv_fs_t* req,
+ uv_fs_type fs_type,
+ const uv_fs_cb cb) {
uv__once_init();
UV_REQ_INIT(req, UV_FS);
req->loop = loop;
@@ -1107,7 +1112,7 @@ static void fs__unlink_rmdir(uv_fs_t* req, BOOL isrmdir) {
DWORD error;
handle = CreateFileW(pathw,
- FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | DELETE,
+ FILE_READ_ATTRIBUTES | DELETE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
@@ -1182,14 +1187,33 @@ static void fs__unlink_rmdir(uv_fs_t* req, BOOL isrmdir) {
/* Remove read-only attribute */
FILE_BASIC_INFORMATION basic = { 0 };
+ /* We opened the handle above without FILE_WRITE_ATTRIBUTES access, which
+ * is not required in the happy path. On windows, it would probably
+ * be ok to ask for them anyway, but Wine has a bug that causes such calls
+ * to fail (https://bugs.winehq.org/show_bug.cgi?id=50771). To work around
+ * this bug, we re-open the handle here */
+ HANDLE write_attributes_handle;
+
basic.FileAttributes = (info.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY) |
FILE_ATTRIBUTE_ARCHIVE;
- status = pNtSetInformationFile(handle,
+ write_attributes_handle = ReOpenFile(handle, FILE_WRITE_ATTRIBUTES,
+ FILE_SHARE_READ | FILE_SHARE_WRITE |
+ FILE_SHARE_DELETE,
+ FILE_FLAG_OPEN_REPARSE_POINT |
+ FILE_FLAG_BACKUP_SEMANTICS);
+ if (write_attributes_handle == INVALID_HANDLE_VALUE) {
+ SET_REQ_WIN32_ERROR(req, GetLastError());
+ CloseHandle(handle);
+ return;
+ }
+
+ status = pNtSetInformationFile(write_attributes_handle,
&iosb,
&basic,
sizeof basic,
FileBasicInformation);
+ CloseHandle(write_attributes_handle);
if (!NT_SUCCESS(status)) {
SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(status));
CloseHandle(handle);
@@ -1264,7 +1288,7 @@ void fs__mktemp(uv_fs_t* req, uv__fs_mktemp_func func) {
tries = TMP_MAX;
do {
- if (uv__random_rtlgenrandom((void *)&v, sizeof(v)) < 0) {
+ if (uv__random_winrandom(&v, sizeof(v)) < 0) {
SET_REQ_UV_ERROR(req, UV_EIO, ERROR_IO_DEVICE);
goto clobber;
}
@@ -1698,8 +1722,9 @@ void fs__closedir(uv_fs_t* req) {
SET_REQ_RESULT(req, 0);
}
-INLINE static fs__stat_path_return_t fs__stat_path(WCHAR* path,
- uv_stat_t* statbuf, int do_lstat) {
+static fs__stat_path_return_t fs__stat_path(WCHAR* path,
+ uv_stat_t* statbuf,
+ int do_lstat) {
FILE_STAT_BASIC_INFORMATION stat_info;
/* Check if the new fast API is available. */
@@ -1735,8 +1760,7 @@ INLINE static fs__stat_path_return_t fs__stat_path(WCHAR* path,
return FS__STAT_PATH_SUCCESS;
}
-INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf,
- int do_lstat) {
+static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, int do_lstat) {
size_t target_length = 0;
FILE_FS_DEVICE_INFORMATION device_info;
FILE_ALL_INFORMATION file_info;
@@ -1827,7 +1851,7 @@ INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf,
return 0;
}
-INLINE static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf) {
+static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf) {
memset(statbuf, 0, sizeof(uv_stat_t));
statbuf->st_mode = _S_IFCHR;
statbuf->st_mode |= (_S_IREAD | _S_IWRITE) | ((_S_IREAD | _S_IWRITE) >> 3) |
@@ -1837,8 +1861,9 @@ INLINE static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf) {
statbuf->st_rdev = FILE_DEVICE_NULL << 16;
}
-INLINE static void fs__stat_assign_statbuf(uv_stat_t* statbuf,
- FILE_STAT_BASIC_INFORMATION stat_info, int do_lstat) {
+static void fs__stat_assign_statbuf(uv_stat_t* statbuf,
+ FILE_STAT_BASIC_INFORMATION stat_info,
+ int do_lstat) {
statbuf->st_dev = stat_info.VolumeSerialNumber.LowPart;
/* Todo: st_mode should probably always be 0666 for everyone. We might also
@@ -1943,7 +1968,7 @@ INLINE static void fs__stat_assign_statbuf(uv_stat_t* statbuf,
}
-INLINE static void fs__stat_prepare_path(WCHAR* pathw) {
+static void fs__stat_prepare_path(WCHAR* pathw) {
size_t len = wcslen(pathw);
if (len > 1 && pathw[len - 2] != L':' &&
@@ -1952,8 +1977,10 @@ INLINE static void fs__stat_prepare_path(WCHAR* pathw) {
}
}
-INLINE static DWORD fs__stat_directory(WCHAR* path, uv_stat_t* statbuf,
- int do_lstat, DWORD ret_error) {
+static DWORD fs__stat_directory(WCHAR* path,
+ uv_stat_t* statbuf,
+ int do_lstat,
+ DWORD ret_error) {
HANDLE handle = INVALID_HANDLE_VALUE;
FILE_STAT_BASIC_INFORMATION stat_info;
FILE_ID_FULL_DIR_INFORMATION dir_info;
@@ -2126,9 +2153,9 @@ cleanup:
return ret_error;
}
-INLINE static DWORD fs__stat_impl_from_path(WCHAR* path,
- int do_lstat,
- uv_stat_t* statbuf) {
+static DWORD fs__stat_impl_from_path(WCHAR* path,
+ int do_lstat,
+ uv_stat_t* statbuf) {
HANDLE handle;
DWORD flags;
DWORD ret;
@@ -2173,7 +2200,7 @@ INLINE static DWORD fs__stat_impl_from_path(WCHAR* path,
}
-INLINE static void fs__stat_impl(uv_fs_t* req, int do_lstat) {
+static void fs__stat_impl(uv_fs_t* req, int do_lstat) {
DWORD error;
error = fs__stat_impl_from_path(req->file.pathw, do_lstat, &req->statbuf);
@@ -2196,7 +2223,7 @@ INLINE static void fs__stat_impl(uv_fs_t* req, int do_lstat) {
}
-INLINE static int fs__fstat_handle(int fd, HANDLE handle, uv_stat_t* statbuf) {
+static int fs__fstat_handle(int fd, HANDLE handle, uv_stat_t* statbuf) {
DWORD file_type;
/* Each file type is processed differently. */
@@ -2272,7 +2299,7 @@ static void fs__rename(uv_fs_t* req) {
}
-INLINE static void fs__sync_impl(uv_fs_t* req) {
+static void fs__sync_impl(uv_fs_t* req) {
int fd = req->file.fd;
int result;
@@ -2578,7 +2605,7 @@ fchmod_cleanup:
}
-INLINE static int fs__utime_handle(HANDLE handle, double atime, double mtime) {
+static int fs__utime_handle(HANDLE handle, double atime, double mtime) {
FILETIME filetime_as, *filetime_a = &filetime_as;
FILETIME filetime_ms, *filetime_m = &filetime_ms;
FILETIME now;
@@ -2606,10 +2633,10 @@ INLINE static int fs__utime_handle(HANDLE handle, double atime, double mtime) {
return 0;
}
-INLINE static DWORD fs__utime_impl_from_path(WCHAR* path,
- double atime,
- double mtime,
- int do_lutime) {
+static DWORD fs__utime_impl_from_path(WCHAR* path,
+ double atime,
+ double mtime,
+ int do_lutime) {
HANDLE handle;
DWORD flags;
DWORD ret;
@@ -2639,7 +2666,7 @@ INLINE static DWORD fs__utime_impl_from_path(WCHAR* path,
return ret;
}
-INLINE static void fs__utime_impl(uv_fs_t* req, int do_lutime) {
+static void fs__utime_impl(uv_fs_t* req, int do_lutime) {
DWORD error;
error = fs__utime_impl_from_path(req->file.pathw,