32 #if defined(__unix__) || defined(__POSIX__) || \
33 defined(__APPLE__) || defined(__sun) || \
34 defined(_AIX) || defined(__MVS__) || \
38 # include <winioctl.h>
41 # ifndef ERROR_SYMLINK_NOT_SUPPORTED
42 # define ERROR_SYMLINK_NOT_SUPPORTED 1464
44 # define unlink _unlink
50 # define stat _stati64
57 #define TOO_LONG_NAME_LENGTH 65536
140 #elif defined(_SC_IOV_MAX)
141 static int iovmax = -1;
143 iovmax = sysconf(_SC_IOV_MAX);
148 if (iovmax == -1) iovmax = 1;
162 static unsigned REPARSE_TAG = 0x9913;
163 static GUID REPARSE_GUID = {
164 0x1bf6205f, 0x46ae, 0x4527,
165 { 0xb1, 0x0c, 0xc5, 0x09, 0xb7, 0x55, 0x22, 0x80 }};
178 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MSYS__)
216 ASSERT(strcmp(
req->ptr,
"test_file_symlink2") == 0);
223 char test_file_abs_buf[
PATHMAX];
224 size_t test_file_abs_size =
sizeof(test_file_abs_buf);
230 if (
req->result == UV_ENOSYS) {
238 uv_cwd(test_file_abs_buf, &test_file_abs_size);
240 strcat(test_file_abs_buf,
"\\test_file");
241 ASSERT(stricmp(
req->ptr, test_file_abs_buf) == 0);
243 strcat(test_file_abs_buf,
"/test_file");
244 ASSERT(strcmp(
req->ptr, test_file_abs_buf) == 0);
300 #if defined(_WIN32) || defined(__MSYS__)
310 # if defined(__CYGWIN__)
313 # elif defined(__PASE__)
353 #if defined(_WIN32) || defined(__sun) || defined(_AIX) || defined(__MVS__) || \
354 defined(__OpenBSD__) || defined(__NetBSD__)
404 FATAL(
"fail_cb should not have been called");
430 if (
req->result < 0) {
431 fprintf(
stderr,
"async open error: %d\n", (
int)
req->result);
436 ASSERT(memcmp(
req->path,
"test_file2\0", 11) == 0);
448 if (
req->result < 0) {
449 fprintf(
stderr,
"async open error: %d\n", (
int)
req->result);
522 ASSERT(memcmp(
req->path,
"test_dir\0", 9) == 0);
534 ASSERT(memcmp(
req->path,
"test_dir_", 9) == 0);
535 ASSERT(memcmp(
req->path + 9,
"XXXXXX", 6) != 0);
560 ASSERT(memcmp(
req->path,
"test_file_", 10) == 0);
561 ASSERT(memcmp(
req->path + 10,
"XXXXXX", 6) != 0);
585 ASSERT(memcmp(
req->path,
"test_dir\0", 9) == 0);
591 #ifdef HAVE_DIRENT_TYPES
601 #if defined(__APPLE__) || defined(_WIN32)
620 ASSERT(strcmp(dent.
name,
"file1") == 0 || strcmp(dent.
name,
"file2") == 0);
625 ASSERT(memcmp(
req->path,
"test_dir\0", 9) == 0);
781 if (
r == UV_ENOTSUP ||
r == UV_EPERM)
783 #elif defined(__MSYS__)
828 ASSERT(s->st_atim.tv_sec + (s->st_atim.tv_nsec / 1000000000.0) == atime);
829 ASSERT(s->st_mtim.tv_sec + (s->st_mtim.tv_nsec / 1000000000.0) == mtime);
952 O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
1041 O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
1073 unlink(
"test_dir/file1");
1074 unlink(
"test_dir/file2");
1087 S_IWUSR | S_IRUSR, NULL);
1095 S_IWUSR | S_IRUSR, NULL);
1114 ASSERT(strcmp(dent.
name,
"file1") == 0 || strcmp(dent.
name,
"file2") == 0);
1154 unlink(
"test_dir/file1");
1155 unlink(
"test_dir/file2");
1173 f =
open(
"test_file", O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR);
1189 S_IWUSR | S_IRUSR, NULL);
1210 ASSERT(s1.st_size == s2.st_size);
1211 ASSERT(s2.st_size == expected_size);
1241 const char* path_template =
"test_dir_XXXXXX";
1273 const char path_template[] =
"test_file_XXXXXX";
1348 S_IWUSR | S_IRUSR, NULL);
1359 # if defined(__APPLE__)
1360 ASSERT(s->st_birthtim.tv_sec == t.st_birthtimespec.tv_sec);
1361 ASSERT(s->st_birthtim.tv_nsec == t.st_birthtimespec.tv_nsec);
1362 # elif defined(__linux__)
1366 ASSERT(s->st_birthtim.tv_sec == 0 ||
1367 s->st_birthtim.tv_sec == t.st_ctim.tv_sec);
1368 ASSERT(s->st_birthtim.tv_nsec == 0 ||
1369 s->st_birthtim.tv_nsec == t.st_ctim.tv_nsec);
1387 r = fstat(
file, &t);
1400 #if defined(__APPLE__)
1401 ASSERT(s->st_atim.tv_sec == t.st_atimespec.tv_sec);
1402 ASSERT(s->st_atim.tv_nsec == t.st_atimespec.tv_nsec);
1403 ASSERT(s->st_mtim.tv_sec == t.st_mtimespec.tv_sec);
1404 ASSERT(s->st_mtim.tv_nsec == t.st_mtimespec.tv_nsec);
1405 ASSERT(s->st_ctim.tv_sec == t.st_ctimespec.tv_sec);
1406 ASSERT(s->st_ctim.tv_nsec == t.st_ctimespec.tv_nsec);
1408 ASSERT(s->st_atim.tv_sec == t.st_atime);
1409 ASSERT(s->st_atim.tv_nsec == 0);
1410 ASSERT(s->st_mtim.tv_sec == t.st_mtime);
1411 ASSERT(s->st_mtim.tv_nsec == 0);
1412 ASSERT(s->st_ctim.tv_sec == t.st_ctime);
1413 ASSERT(s->st_ctim.tv_nsec == 0);
1414 #elif defined(__ANDROID__)
1415 ASSERT(s->st_atim.tv_sec == t.st_atime);
1416 ASSERT(s->st_atim.tv_nsec == t.st_atimensec);
1417 ASSERT(s->st_mtim.tv_sec == t.st_mtime);
1418 ASSERT(s->st_mtim.tv_nsec == t.st_mtimensec);
1419 ASSERT(s->st_ctim.tv_sec == t.st_ctime);
1420 ASSERT(s->st_ctim.tv_nsec == t.st_ctimensec);
1421 #elif defined(__sun) || \
1422 defined(__DragonFly__) || \
1423 defined(__FreeBSD__) || \
1424 defined(__OpenBSD__) || \
1425 defined(__NetBSD__) || \
1426 defined(_GNU_SOURCE) || \
1427 defined(_BSD_SOURCE) || \
1428 defined(_SVID_SOURCE) || \
1429 defined(_XOPEN_SOURCE) || \
1430 defined(_DEFAULT_SOURCE)
1431 ASSERT(s->st_atim.tv_sec == t.st_atim.tv_sec);
1432 ASSERT(s->st_atim.tv_nsec == t.st_atim.tv_nsec);
1433 ASSERT(s->st_mtim.tv_sec == t.st_mtim.tv_sec);
1434 ASSERT(s->st_mtim.tv_nsec == t.st_mtim.tv_nsec);
1435 ASSERT(s->st_ctim.tv_sec == t.st_ctim.tv_sec);
1436 ASSERT(s->st_ctim.tv_nsec == t.st_ctim.tv_nsec);
1437 # if defined(__FreeBSD__) || \
1439 ASSERT(s->st_birthtim.tv_sec == t.st_birthtim.tv_sec);
1440 ASSERT(s->st_birthtim.tv_nsec == t.st_birthtim.tv_nsec);
1443 ASSERT(s->st_atim.tv_sec == t.st_atime);
1444 ASSERT(s->st_atim.tv_nsec == 0);
1445 ASSERT(s->st_mtim.tv_sec == t.st_mtime);
1446 ASSERT(s->st_mtim.tv_nsec == 0);
1447 ASSERT(s->st_ctim.tv_sec == t.st_ctime);
1448 ASSERT(s->st_ctim.tv_nsec == 0);
1452 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
1453 ASSERT(s->st_flags == t.st_flags);
1454 ASSERT(s->st_gen == t.st_gen);
1456 ASSERT(s->st_flags == 0);
1514 S_IWUSR | S_IRUSR, NULL);
1575 S_IWUSR | S_IRUSR, NULL);
1616 static int mode = 0200;
1628 static int mode = 0400;
1638 static int mode = 0600;
1751 r = SetFileAttributes(
"test_file", FILE_ATTRIBUTE_READONLY);
1786 unlink(
"test_file_link");
1791 S_IWUSR | S_IRUSR, NULL);
1865 unlink(
"test_file_link");
1880 unlink(
"test_file_link");
1881 unlink(
"test_file_link2");
1886 S_IWUSR | S_IRUSR, NULL);
1950 unlink(
"test_file_link");
1951 unlink(
"test_file_link2");
1991 if (
req.result == UV_ENOSYS) {
1993 RETURN_SKIP(
"realpath is not supported on Windows XP");
2014 char test_file_abs_buf[
PATHMAX];
2015 size_t test_file_abs_size;
2019 unlink(
"test_file_symlink");
2020 unlink(
"test_file_symlink2");
2021 unlink(
"test_file_symlink_symlink");
2022 unlink(
"test_file_symlink2_symlink");
2023 test_file_abs_size =
sizeof(test_file_abs_buf);
2025 uv_cwd(test_file_abs_buf, &test_file_abs_size);
2026 strcat(test_file_abs_buf,
"\\test_file");
2028 uv_cwd(test_file_abs_buf, &test_file_abs_size);
2029 strcat(test_file_abs_buf,
"/test_file");
2035 S_IWUSR | S_IRUSR, NULL);
2053 if (
r == UV_ENOTSUP) {
2059 }
else if (
r == UV_EPERM) {
2072 r =
uv_fs_open(NULL, &
req,
"test_file_symlink", O_RDWR, 0, NULL);
2089 "test_file_symlink",
2090 "test_file_symlink_symlink",
2096 #if defined(__MSYS__)
2097 RETURN_SKIP(
"symlink reading is not supported on MSYS2");
2102 ASSERT(strcmp(
req.ptr,
"test_file_symlink") == 0);
2110 if (
r == UV_ENOSYS) {
2112 RETURN_SKIP(
"realpath is not supported on Windows XP");
2117 ASSERT(stricmp(
req.ptr, test_file_abs_buf) == 0);
2119 ASSERT(strcmp(
req.ptr, test_file_abs_buf) == 0);
2127 "test_file_symlink2",
2134 r =
uv_fs_open(NULL, &
req,
"test_file_symlink2", O_RDWR, 0, NULL);
2151 "test_file_symlink2",
2152 "test_file_symlink2_symlink",
2168 if (
r == UV_ENOSYS) {
2170 RETURN_SKIP(
"realpath is not supported on Windows XP");
2185 unlink(
"test_file_symlink");
2186 unlink(
"test_file_symlink_symlink");
2187 unlink(
"test_file_symlink2");
2188 unlink(
"test_file_symlink2_symlink");
2200 static char test_dir_abs_buf[
PATHMAX];
2201 size_t test_dir_abs_size;
2204 unlink(
"test_dir/file1");
2205 unlink(
"test_dir/file2");
2207 rmdir(
"test_dir_symlink");
2208 test_dir_abs_size =
sizeof(test_dir_abs_buf);
2216 strcpy(test_dir_abs_buf,
"\\\\?\\");
2217 uv_cwd(test_dir_abs_buf + 4, &test_dir_abs_size);
2218 test_dir_abs_size += 4;
2219 strcat(test_dir_abs_buf,
"\\test_dir\\");
2220 test_dir_abs_size += strlen(
"\\test_dir\\");
2221 test_dir = test_dir_abs_buf;
2223 uv_cwd(test_dir_abs_buf, &test_dir_abs_size);
2224 strcat(test_dir_abs_buf,
"/test_dir");
2225 test_dir_abs_size += strlen(
"/test_dir");
2226 test_dir =
"test_dir";
2232 RETURN_SKIP(
"this version of Windows doesn't support unprivileged "
2233 "creation of directory symlinks");
2235 fprintf(
stderr,
"r == %i\n",
r);
2247 #if defined(__MSYS__)
2248 RETURN_SKIP(
"symlink reading is not supported on MSYS2");
2266 ASSERT(strcmp(
req.ptr, test_dir + 4) == 0);
2277 if (
r == UV_ENOSYS) {
2279 RETURN_SKIP(
"realpath is not supported on Windows XP");
2284 ASSERT(strlen(
req.ptr) == test_dir_abs_size - 5);
2285 ASSERT(strnicmp(
req.ptr, test_dir + 4, test_dir_abs_size - 5) == 0);
2287 ASSERT(strcmp(
req.ptr, test_dir_abs_buf) == 0);
2292 S_IWUSR | S_IRUSR, NULL);
2300 S_IWUSR | S_IRUSR, NULL);
2312 ASSERT(strcmp(dent.
name,
"file1") == 0 || strcmp(dent.
name,
"file2") == 0);
2332 ASSERT(strcmp(dent.
name,
"file1") == 0 || strcmp(dent.
name,
"file2") == 0);
2339 unlink(
"test_dir/file1");
2340 unlink(
"test_dir/file2");
2342 rmdir(
"test_dir_symlink");
2357 TEST_IMPL(fs_non_symlink_reparse_point) {
2361 REPARSE_GUID_DATA_BUFFER reparse_buffer;
2362 DWORD bytes_returned;
2366 unlink(
"test_dir/test_file");
2374 file_handle = CreateFile(
"test_dir/test_file",
2375 GENERIC_WRITE | FILE_WRITE_ATTRIBUTES,
2379 FILE_FLAG_OPEN_REPARSE_POINT |
2380 FILE_FLAG_BACKUP_SEMANTICS,
2384 memset(&reparse_buffer, 0, REPARSE_GUID_DATA_BUFFER_HEADER_SIZE);
2385 reparse_buffer.ReparseTag = REPARSE_TAG;
2386 reparse_buffer.ReparseDataLength = 0;
2387 reparse_buffer.ReparseGuid = REPARSE_GUID;
2389 r = DeviceIoControl(file_handle,
2392 REPARSE_GUID_DATA_BUFFER_HEADER_SIZE,
2399 CloseHandle(file_handle);
2450 unlink(
"test_dir/test_file");
2461 const char*
path =
"test_file";
2476 atime = mtime = 400497753;
2498 atime = mtime = 1291404900;
2500 checkme.
atime = atime;
2501 checkme.
mtime = mtime;
2552 const char*
path =
"test_file";
2558 #if defined(_AIX) && !defined(_AIX71)
2559 RETURN_SKIP(
"futime is not implemented for AIX versions below 7.1");
2571 atime = mtime = 400497753;
2589 #if defined(__CYGWIN__) || defined(__MSYS__)
2604 atime = mtime = 1291404900;
2606 checkme.
atime = atime;
2607 checkme.
mtime = mtime;
2627 const char*
path =
"test_file";
2628 const char* symlink_path =
"test_file_symlink";
2647 if (s == UV_EPERM) {
2653 "Symlink creation requires elevated console (with admin rights)");
2661 atime = mtime = 400497753;
2667 checkme.
atime = atime;
2668 checkme.
mtime = mtime;
2669 checkme.
path = symlink_path;
2670 req.data = &checkme;
2673 #if (defined(_AIX) && !defined(_AIX71)) || \
2676 RETURN_SKIP(
"lutime is not implemented for z/OS and AIX versions below 7.1");
2683 atime = mtime = 1291404900;
2685 checkme.
atime = atime;
2686 checkme.
mtime = mtime;
2687 checkme.
path = symlink_path;
2725 path =
"./empty_dir/";
2762 path =
"./non_existent_dir/";
2793 path =
"test/fixtures/empty_file";
2851 O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
2868 O_RDWR | O_APPEND | add_flags, 0, NULL);
2896 "test-buffer\n\0test-buffer\n\0",
2897 sizeof(
"test-buffer\n\0test-buffer\n\0") - 1) == 0);
2927 S_IWUSR | S_IRUSR, NULL);
2944 S_IWUSR | S_IRUSR, NULL);
2991 "test/fixtures/lorem_ipsum.txt",
2992 O_RDONLY | add_flags, 0, NULL));
3045 #if defined(__CYGWIN__) || defined(__MSYS__)
3046 RETURN_SKIP(
"Cygwin pread at EOF may (incorrectly) return data!");
3056 O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
3120 O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
3219 iovs = malloc(
sizeof(*iovs) * iovcount);
3226 O_RDWR | O_CREAT | add_flags,
3267 if (iovcount > iovmax)
3322 filler =
"0123456789";
3323 filler_len = strlen(filler);
3331 iovs = malloc(
sizeof(*iovs) * iovcount);
3338 O_RDWR | O_CREAT | add_flags,
3375 iovs, iovcount,
offset, NULL);
3379 else if (iovcount > iovmax)
3452 #if defined(__FreeBSD__) || \
3453 defined(__OpenBSD__) || \
3454 defined(__NetBSD__) || \
3455 defined(__DragonFly__) || \
3464 ASSERT((
r >= 0) || (
r == UV_EISDIR));
3527 pthread_kill(
ctx->pid, SIGUSR1);
3563 iovs = malloc(
sizeof(*iovs) * iovcount);
3566 ctx.pid = pthread_self();
3568 ctx.interval = 1000;
3570 ctx.data = malloc(
ctx.size);
3593 while (nread <
ctx.size) {
3597 size_t read_iovcount;
3599 read_iovs += read_iovcount;
3600 iovcount -= read_iovcount;
3837 static void fs_file_pos_common() {
3869 static void fs_file_pos_close_check(
const char *
contents,
int size) {
3897 static void fs_file_pos_write(
int add_flags) {
3906 O_TRUNC | O_CREAT | O_RDWR | add_flags,
3912 fs_file_pos_common();
3925 fs_file_pos_close_check(
"aecd", 4);
3928 fs_file_pos_write(0);
3935 static void fs_file_pos_append(
int add_flags) {
3944 O_APPEND | O_CREAT | O_RDWR | add_flags,
3950 fs_file_pos_common();
3965 fs_file_pos_close_check(
"abcde", 5);
3968 fs_file_pos_append(0);
4184 int call_icacls(
const char*
command, ...) {
4185 char icacls_command[1024];
4191 return system(icacls_command);
4214 call_icacls(
"icacls test_file_icacls /remove \"%s\" /inheritance:e",
4217 unlink(
"test_file_icacls");
4235 r = call_icacls(
"icacls test_file_icacls /inheritance:r /remove \"%s\"",
4240 r = call_icacls(
"icacls test_file_icacls /grant \"%s\":RX", pwd.
username);
4259 call_icacls(
"icacls test_file_icacls /remove \"%s\" /inheritance:e",
4261 unlink(
"test_file_icacls");
4292 r = SetFileAttributes(
"test_file", FILE_ATTRIBUTE_READONLY);
4311 r = SetFileAttributes(
"test_file", FILE_ATTRIBUTE_ARCHIVE);