test-fs.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include "uv.h"
23 #include "task.h"
24 
25 #include <errno.h>
26 #include <string.h> /* memset */
27 #include <fcntl.h>
28 #include <sys/stat.h>
29 #include <limits.h> /* INT_MAX, PATH_MAX, IOV_MAX */
30 
31 /* FIXME we shouldn't need to branch in this file */
32 #if defined(__unix__) || defined(__POSIX__) || \
33  defined(__APPLE__) || defined(__sun) || \
34  defined(_AIX) || defined(__MVS__) || \
35  defined(__HAIKU__)
36 #include <unistd.h> /* unlink, rmdir, etc. */
37 #else
38 # include <winioctl.h>
39 # include <direct.h>
40 # include <io.h>
41 # ifndef ERROR_SYMLINK_NOT_SUPPORTED
42 # define ERROR_SYMLINK_NOT_SUPPORTED 1464
43 # endif
44 # define unlink _unlink
45 # define rmdir _rmdir
46 # define open _open
47 # define write _write
48 # define close _close
49 # ifndef stat
50 # define stat _stati64
51 # endif
52 # ifndef lseek
53 # define lseek _lseek
54 # endif
55 #endif
56 
57 #define TOO_LONG_NAME_LENGTH 65536
58 #define PATHMAX 4096
59 
60 typedef struct {
61  const char* path;
62  double atime;
63  double mtime;
65 
66 
67 static int dummy_cb_count;
68 static int close_cb_count;
69 static int create_cb_count;
70 static int open_cb_count;
71 static int read_cb_count;
72 static int write_cb_count;
73 static int unlink_cb_count;
74 static int mkdir_cb_count;
75 static int mkdtemp_cb_count;
76 static int mkstemp_cb_count;
77 static int rmdir_cb_count;
78 static int scandir_cb_count;
79 static int stat_cb_count;
80 static int rename_cb_count;
81 static int fsync_cb_count;
82 static int fdatasync_cb_count;
83 static int ftruncate_cb_count;
84 static int sendfile_cb_count;
85 static int fstat_cb_count;
86 static int access_cb_count;
87 static int chmod_cb_count;
88 static int fchmod_cb_count;
89 static int chown_cb_count;
90 static int fchown_cb_count;
91 static int lchown_cb_count;
92 static int link_cb_count;
93 static int symlink_cb_count;
94 static int readlink_cb_count;
95 static int realpath_cb_count;
96 static int utime_cb_count;
97 static int futime_cb_count;
98 static int lutime_cb_count;
99 static int statfs_cb_count;
100 
101 static uv_loop_t* loop;
102 
125 
126 static char buf[32];
127 static char buf2[32];
128 static char test_buf[] = "test-buffer\n";
129 static char test_buf2[] = "second-buffer\n";
130 static uv_buf_t iov;
131 
132 #ifdef _WIN32
133 int uv_test_getiovmax(void) {
134  return INT32_MAX; /* Emulated by libuv, so no real limit. */
135 }
136 #else
137 int uv_test_getiovmax(void) {
138 #if defined(IOV_MAX)
139  return IOV_MAX;
140 #elif defined(_SC_IOV_MAX)
141  static int iovmax = -1;
142  if (iovmax == -1) {
143  iovmax = sysconf(_SC_IOV_MAX);
144  /* On some embedded devices (arm-linux-uclibc based ip camera),
145  * sysconf(_SC_IOV_MAX) can not get the correct value. The return
146  * value is -1 and the errno is EINPROGRESS. Degrade the value to 1.
147  */
148  if (iovmax == -1) iovmax = 1;
149  }
150  return iovmax;
151 #else
152  return 1024;
153 #endif
154 }
155 #endif
156 
157 #ifdef _WIN32
158 /*
159  * This tag and guid have no special meaning, and don't conflict with
160  * reserved ids.
161 */
162 static unsigned REPARSE_TAG = 0x9913;
163 static GUID REPARSE_GUID = {
164  0x1bf6205f, 0x46ae, 0x4527,
165  { 0xb1, 0x0c, 0xc5, 0x09, 0xb7, 0x55, 0x22, 0x80 }};
166 #endif
167 
168 static void check_permission(const char* filename, unsigned int mode) {
169  int r;
170  uv_fs_t req;
171  uv_stat_t* s;
172 
173  r = uv_fs_stat(NULL, &req, filename, NULL);
174  ASSERT(r == 0);
175  ASSERT(req.result == 0);
176 
177  s = &req.statbuf;
178 #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MSYS__)
179  /*
180  * On Windows, chmod can only modify S_IWUSR (_S_IWRITE) bit,
181  * so only testing for the specified flags.
182  */
183  ASSERT((s->st_mode & 0777) & mode);
184 #else
185  ASSERT((s->st_mode & 0777) == mode);
186 #endif
187 
189 }
190 
191 
192 static void dummy_cb(uv_fs_t* req) {
193  (void) req;
194  dummy_cb_count++;
195 }
196 
197 
198 static void link_cb(uv_fs_t* req) {
199  ASSERT(req->fs_type == UV_FS_LINK);
200  ASSERT(req->result == 0);
201  link_cb_count++;
203 }
204 
205 
206 static void symlink_cb(uv_fs_t* req) {
207  ASSERT(req->fs_type == UV_FS_SYMLINK);
208  ASSERT(req->result == 0);
211 }
212 
213 static void readlink_cb(uv_fs_t* req) {
214  ASSERT(req->fs_type == UV_FS_READLINK);
215  ASSERT(req->result == 0);
216  ASSERT(strcmp(req->ptr, "test_file_symlink2") == 0);
219 }
220 
221 
222 static void realpath_cb(uv_fs_t* req) {
223  char test_file_abs_buf[PATHMAX];
224  size_t test_file_abs_size = sizeof(test_file_abs_buf);
225  ASSERT(req->fs_type == UV_FS_REALPATH);
226 #ifdef _WIN32
227  /*
228  * Windows XP and Server 2003 don't support GetFinalPathNameByHandleW()
229  */
230  if (req->result == UV_ENOSYS) {
233  return;
234  }
235 #endif
236  ASSERT(req->result == 0);
237 
238  uv_cwd(test_file_abs_buf, &test_file_abs_size);
239 #ifdef _WIN32
240  strcat(test_file_abs_buf, "\\test_file");
241  ASSERT(stricmp(req->ptr, test_file_abs_buf) == 0);
242 #else
243  strcat(test_file_abs_buf, "/test_file");
244  ASSERT(strcmp(req->ptr, test_file_abs_buf) == 0);
245 #endif
248 }
249 
250 
251 static void access_cb(uv_fs_t* req) {
252  ASSERT(req->fs_type == UV_FS_ACCESS);
253  access_cb_count++;
255 }
256 
257 
258 static void fchmod_cb(uv_fs_t* req) {
259  ASSERT(req->fs_type == UV_FS_FCHMOD);
260  ASSERT(req->result == 0);
261  fchmod_cb_count++;
263  check_permission("test_file", *(int*)req->data);
264 }
265 
266 
267 static void chmod_cb(uv_fs_t* req) {
268  ASSERT(req->fs_type == UV_FS_CHMOD);
269  ASSERT(req->result == 0);
270  chmod_cb_count++;
272  check_permission("test_file", *(int*)req->data);
273 }
274 
275 
276 static void fchown_cb(uv_fs_t* req) {
277  ASSERT(req->fs_type == UV_FS_FCHOWN);
278  ASSERT(req->result == 0);
279  fchown_cb_count++;
281 }
282 
283 
284 static void chown_cb(uv_fs_t* req) {
285  ASSERT(req->fs_type == UV_FS_CHOWN);
286  ASSERT(req->result == 0);
287  chown_cb_count++;
289 }
290 
291 static void lchown_cb(uv_fs_t* req) {
292  ASSERT(req->fs_type == UV_FS_LCHOWN);
293  ASSERT(req->result == 0);
294  lchown_cb_count++;
296 }
297 
298 static void chown_root_cb(uv_fs_t* req) {
299  ASSERT(req->fs_type == UV_FS_CHOWN);
300 #if defined(_WIN32) || defined(__MSYS__)
301  /* On windows, chown is a no-op and always succeeds. */
302  ASSERT(req->result == 0);
303 #else
304  /* On unix, chown'ing the root directory is not allowed -
305  * unless you're root, of course.
306  */
307  if (geteuid() == 0)
308  ASSERT(req->result == 0);
309  else
310 # if defined(__CYGWIN__)
311  /* On Cygwin, uid 0 is invalid (no root). */
312  ASSERT(req->result == UV_EINVAL);
313 # elif defined(__PASE__)
314  /* On IBMi PASE, there is no root user. uid 0 is user qsecofr.
315  * User may grant qsecofr's privileges, including changing
316  * the file's ownership to uid 0.
317  */
318  ASSERT(req->result == 0);
319 # else
320  ASSERT(req->result == UV_EPERM);
321 # endif
322 #endif
323  chown_cb_count++;
325 }
326 
327 static void unlink_cb(uv_fs_t* req) {
328  ASSERT(req == &unlink_req);
329  ASSERT(req->fs_type == UV_FS_UNLINK);
330  ASSERT(req->result == 0);
331  unlink_cb_count++;
333 }
334 
335 static void fstat_cb(uv_fs_t* req) {
336  uv_stat_t* s = req->ptr;
337  ASSERT(req->fs_type == UV_FS_FSTAT);
338  ASSERT(req->result == 0);
339  ASSERT(s->st_size == sizeof(test_buf));
341  fstat_cb_count++;
342 }
343 
344 
345 static void statfs_cb(uv_fs_t* req) {
347 
348  ASSERT(req->fs_type == UV_FS_STATFS);
349  ASSERT(req->result == 0);
350  ASSERT(req->ptr != NULL);
351  stats = req->ptr;
352 
353 #if defined(_WIN32) || defined(__sun) || defined(_AIX) || defined(__MVS__) || \
354  defined(__OpenBSD__) || defined(__NetBSD__)
355  ASSERT(stats->f_type == 0);
356 #else
357  ASSERT(stats->f_type > 0);
358 #endif
359 
360  ASSERT(stats->f_bsize > 0);
361  ASSERT(stats->f_blocks > 0);
362  ASSERT(stats->f_bfree <= stats->f_blocks);
363  ASSERT(stats->f_bavail <= stats->f_bfree);
364 
365 #ifdef _WIN32
366  ASSERT(stats->f_files == 0);
367  ASSERT(stats->f_ffree == 0);
368 #else
369  /* There is no assertion for stats->f_files that makes sense, so ignore it. */
370  ASSERT(stats->f_ffree <= stats->f_files);
371 #endif
373  ASSERT(req->ptr == NULL);
374  statfs_cb_count++;
375 }
376 
377 
378 static void close_cb(uv_fs_t* req) {
379  int r;
380  ASSERT(req == &close_req);
381  ASSERT(req->fs_type == UV_FS_CLOSE);
382  ASSERT(req->result == 0);
383  close_cb_count++;
385  if (close_cb_count == 3) {
386  r = uv_fs_unlink(loop, &unlink_req, "test_file2", unlink_cb);
387  ASSERT(r == 0);
388  }
389 }
390 
391 
392 static void ftruncate_cb(uv_fs_t* req) {
393  int r;
394  ASSERT(req == &ftruncate_req);
395  ASSERT(req->fs_type == UV_FS_FTRUNCATE);
396  ASSERT(req->result == 0);
400  ASSERT(r == 0);
401 }
402 
403 static void fail_cb(uv_fs_t* req) {
404  FATAL("fail_cb should not have been called");
405 }
406 
407 static void read_cb(uv_fs_t* req) {
408  int r;
409  ASSERT(req == &read_req);
410  ASSERT(req->fs_type == UV_FS_READ);
411  ASSERT(req->result >= 0); /* FIXME(bnoordhuis) Check if requested size? */
412  read_cb_count++;
414  if (read_cb_count == 1) {
415  ASSERT(strcmp(buf, test_buf) == 0);
417  ftruncate_cb);
418  } else {
419  ASSERT(strcmp(buf, "test-bu") == 0);
421  }
422  ASSERT(r == 0);
423 }
424 
425 
426 static void open_cb(uv_fs_t* req) {
427  int r;
428  ASSERT(req == &open_req1);
429  ASSERT(req->fs_type == UV_FS_OPEN);
430  if (req->result < 0) {
431  fprintf(stderr, "async open error: %d\n", (int) req->result);
432  ASSERT(0);
433  }
434  open_cb_count++;
435  ASSERT(req->path);
436  ASSERT(memcmp(req->path, "test_file2\0", 11) == 0);
438  memset(buf, 0, sizeof(buf));
439  iov = uv_buf_init(buf, sizeof(buf));
440  r = uv_fs_read(loop, &read_req, open_req1.result, &iov, 1, -1,
441  read_cb);
442  ASSERT(r == 0);
443 }
444 
445 
446 static void open_cb_simple(uv_fs_t* req) {
447  ASSERT(req->fs_type == UV_FS_OPEN);
448  if (req->result < 0) {
449  fprintf(stderr, "async open error: %d\n", (int) req->result);
450  ASSERT(0);
451  }
452  open_cb_count++;
453  ASSERT(req->path);
455 }
456 
457 
458 static void fsync_cb(uv_fs_t* req) {
459  int r;
460  ASSERT(req == &fsync_req);
461  ASSERT(req->fs_type == UV_FS_FSYNC);
462  ASSERT(req->result == 0);
463  fsync_cb_count++;
466  ASSERT(r == 0);
467 }
468 
469 
470 static void fdatasync_cb(uv_fs_t* req) {
471  int r;
472  ASSERT(req == &fdatasync_req);
473  ASSERT(req->fs_type == UV_FS_FDATASYNC);
474  ASSERT(req->result == 0);
478  ASSERT(r == 0);
479 }
480 
481 
482 static void write_cb(uv_fs_t* req) {
483  int r;
484  ASSERT(req == &write_req);
485  ASSERT(req->fs_type == UV_FS_WRITE);
486  ASSERT(req->result >= 0); /* FIXME(bnoordhuis) Check if requested size? */
487  write_cb_count++;
490  ASSERT(r == 0);
491 }
492 
493 
494 static void create_cb(uv_fs_t* req) {
495  int r;
496  ASSERT(req == &open_req1);
497  ASSERT(req->fs_type == UV_FS_OPEN);
498  ASSERT(req->result >= 0);
499  create_cb_count++;
501  iov = uv_buf_init(test_buf, sizeof(test_buf));
502  r = uv_fs_write(loop, &write_req, req->result, &iov, 1, -1, write_cb);
503  ASSERT(r == 0);
504 }
505 
506 
507 static void rename_cb(uv_fs_t* req) {
508  ASSERT(req == &rename_req);
509  ASSERT(req->fs_type == UV_FS_RENAME);
510  ASSERT(req->result == 0);
511  rename_cb_count++;
513 }
514 
515 
516 static void mkdir_cb(uv_fs_t* req) {
517  ASSERT(req == &mkdir_req);
518  ASSERT(req->fs_type == UV_FS_MKDIR);
519  ASSERT(req->result == 0);
520  mkdir_cb_count++;
521  ASSERT(req->path);
522  ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
524 }
525 
526 
528  int r;
529 
530  ASSERT(req->fs_type == UV_FS_MKDTEMP);
531  ASSERT(req->result == 0);
532  ASSERT(req->path);
533  ASSERT(strlen(req->path) == 15);
534  ASSERT(memcmp(req->path, "test_dir_", 9) == 0);
535  ASSERT(memcmp(req->path + 9, "XXXXXX", 6) != 0);
536  check_permission(req->path, 0700);
537 
538  /* Check if req->path is actually a directory */
539  r = uv_fs_stat(NULL, &stat_req, req->path, NULL);
540  ASSERT(r == 0);
541  ASSERT(((uv_stat_t*)stat_req.ptr)->st_mode & S_IFDIR);
543 }
544 
545 
546 static void mkdtemp_cb(uv_fs_t* req) {
547  ASSERT(req == &mkdtemp_req1);
550 }
551 
552 
554  int r;
555 
556  ASSERT(req->fs_type == UV_FS_MKSTEMP);
557  ASSERT(req->result >= 0);
558  ASSERT(req->path);
559  ASSERT(strlen(req->path) == 16);
560  ASSERT(memcmp(req->path, "test_file_", 10) == 0);
561  ASSERT(memcmp(req->path + 10, "XXXXXX", 6) != 0);
562  check_permission(req->path, 0600);
563 
564  /* Check if req->path is actually a file */
565  r = uv_fs_stat(NULL, &stat_req, req->path, NULL);
566  ASSERT(r == 0);
567  ASSERT(stat_req.statbuf.st_mode & S_IFREG);
569 }
570 
571 
572 static void mkstemp_cb(uv_fs_t* req) {
573  ASSERT(req == &mkstemp_req1);
576 }
577 
578 
579 static void rmdir_cb(uv_fs_t* req) {
580  ASSERT(req == &rmdir_req);
581  ASSERT(req->fs_type == UV_FS_RMDIR);
582  ASSERT(req->result == 0);
583  rmdir_cb_count++;
584  ASSERT(req->path);
585  ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
587 }
588 
589 
590 static void assert_is_file_type(uv_dirent_t dent) {
591 #ifdef HAVE_DIRENT_TYPES
592  /*
593  * For Apple and Windows, we know getdents is expected to work but for other
594  * environments, the filesystem dictates whether or not getdents supports
595  * returning the file type.
596  *
597  * See:
598  * http://man7.org/linux/man-pages/man2/getdents.2.html
599  * https://github.com/libuv/libuv/issues/501
600  */
601  #if defined(__APPLE__) || defined(_WIN32)
602  ASSERT(dent.type == UV_DIRENT_FILE);
603  #else
604  ASSERT(dent.type == UV_DIRENT_FILE || dent.type == UV_DIRENT_UNKNOWN);
605  #endif
606 #else
607  ASSERT(dent.type == UV_DIRENT_UNKNOWN);
608 #endif
609 }
610 
611 
612 static void scandir_cb(uv_fs_t* req) {
613  uv_dirent_t dent;
614  ASSERT(req == &scandir_req);
615  ASSERT(req->fs_type == UV_FS_SCANDIR);
616  ASSERT(req->result == 2);
617  ASSERT(req->ptr);
618 
619  while (UV_EOF != uv_fs_scandir_next(req, &dent)) {
620  ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0);
621  assert_is_file_type(dent);
622  }
624  ASSERT(req->path);
625  ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
627  ASSERT(!req->ptr);
628 }
629 
630 
631 static void empty_scandir_cb(uv_fs_t* req) {
632  uv_dirent_t dent;
633 
634  ASSERT(req == &scandir_req);
635  ASSERT(req->fs_type == UV_FS_SCANDIR);
636  ASSERT(req->result == 0);
637  ASSERT(req->ptr == NULL);
638  ASSERT(UV_EOF == uv_fs_scandir_next(req, &dent));
641 }
642 
644  uv_dirent_t dent;
645 
646  ASSERT(req == &scandir_req);
647  ASSERT(req->fs_type == UV_FS_SCANDIR);
648  ASSERT(req->result == UV_ENOENT);
649  ASSERT(req->ptr == NULL);
650  ASSERT(UV_ENOENT == uv_fs_scandir_next(req, &dent));
653 }
654 
655 
656 static void file_scandir_cb(uv_fs_t* req) {
657  ASSERT(req == &scandir_req);
658  ASSERT(req->fs_type == UV_FS_SCANDIR);
659  ASSERT(req->result == UV_ENOTDIR);
660  ASSERT(req->ptr == NULL);
663 }
664 
665 
666 static void stat_cb(uv_fs_t* req) {
667  ASSERT(req == &stat_req);
668  ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT);
669  ASSERT(req->result == 0);
670  ASSERT(req->ptr);
671  stat_cb_count++;
673  ASSERT(!req->ptr);
674 }
675 
676 
677 static void sendfile_cb(uv_fs_t* req) {
678  ASSERT(req == &sendfile_req);
679  ASSERT(req->fs_type == UV_FS_SENDFILE);
680  ASSERT(req->result == 65546);
683 }
684 
685 
687  ASSERT(req == &sendfile_req);
688  ASSERT(req->fs_type == UV_FS_SENDFILE);
689  ASSERT(req->result == 0);
692 }
693 
694 
695 static void open_noent_cb(uv_fs_t* req) {
696  ASSERT(req->fs_type == UV_FS_OPEN);
697  ASSERT(req->result == UV_ENOENT);
698  open_cb_count++;
700 }
701 
703  ASSERT(req->fs_type == UV_FS_OPEN);
704  ASSERT(req->result == UV_ENAMETOOLONG);
705  open_cb_count++;
707 }
708 
709 static void open_loop_cb(uv_fs_t* req) {
710  ASSERT(req->fs_type == UV_FS_OPEN);
711  ASSERT(req->result == UV_ELOOP);
712  open_cb_count++;
714 }
715 
716 
717 TEST_IMPL(fs_file_noent) {
718  uv_fs_t req;
719  int r;
720 
721  loop = uv_default_loop();
722 
723  r = uv_fs_open(NULL, &req, "does_not_exist", O_RDONLY, 0, NULL);
724  ASSERT(r == UV_ENOENT);
725  ASSERT(req.result == UV_ENOENT);
727 
728  r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, open_noent_cb);
729  ASSERT(r == 0);
730 
731  ASSERT(open_cb_count == 0);
733  ASSERT(open_cb_count == 1);
734 
735  /* TODO add EACCES test */
736 
738  return 0;
739 }
740 
741 TEST_IMPL(fs_file_nametoolong) {
742  uv_fs_t req;
743  int r;
744  char name[TOO_LONG_NAME_LENGTH + 1];
745 
746  loop = uv_default_loop();
747 
750 
751  r = uv_fs_open(NULL, &req, name, O_RDONLY, 0, NULL);
752  ASSERT(r == UV_ENAMETOOLONG);
753  ASSERT(req.result == UV_ENAMETOOLONG);
755 
756  r = uv_fs_open(loop, &req, name, O_RDONLY, 0, open_nametoolong_cb);
757  ASSERT(r == 0);
758 
759  ASSERT(open_cb_count == 0);
761  ASSERT(open_cb_count == 1);
762 
764  return 0;
765 }
766 
767 TEST_IMPL(fs_file_loop) {
768  uv_fs_t req;
769  int r;
770 
771  loop = uv_default_loop();
772 
773  unlink("test_symlink");
774  r = uv_fs_symlink(NULL, &req, "test_symlink", "test_symlink", 0, NULL);
775 #ifdef _WIN32
776  /*
777  * Windows XP and Server 2003 don't support symlinks; we'll get UV_ENOTSUP.
778  * Starting with vista they are supported, but only when elevated, otherwise
779  * we'll see UV_EPERM.
780  */
781  if (r == UV_ENOTSUP || r == UV_EPERM)
782  return 0;
783 #elif defined(__MSYS__)
784  /* MSYS2's approximation of symlinks with copies does not work for broken
785  links. */
786  if (r == UV_ENOENT)
787  return 0;
788 #endif
789  ASSERT(r == 0);
791 
792  r = uv_fs_open(NULL, &req, "test_symlink", O_RDONLY, 0, NULL);
793  ASSERT(r == UV_ELOOP);
794  ASSERT(req.result == UV_ELOOP);
796 
797  r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, open_loop_cb);
798  ASSERT(r == 0);
799 
800  ASSERT(open_cb_count == 0);
802  ASSERT(open_cb_count == 1);
803 
804  unlink("test_symlink");
805 
807  return 0;
808 }
809 
810 static void check_utime(const char* path,
811  double atime,
812  double mtime,
813  int test_lutime) {
814  uv_stat_t* s;
815  uv_fs_t req;
816  int r;
817 
818  if (test_lutime)
819  r = uv_fs_lstat(loop, &req, path, NULL);
820  else
821  r = uv_fs_stat(loop, &req, path, NULL);
822 
823  ASSERT(r == 0);
824 
825  ASSERT(req.result == 0);
826  s = &req.statbuf;
827 
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);
830 
832 }
833 
834 
835 static void utime_cb(uv_fs_t* req) {
836  utime_check_t* c;
837 
838  ASSERT(req == &utime_req);
839  ASSERT(req->result == 0);
840  ASSERT(req->fs_type == UV_FS_UTIME);
841 
842  c = req->data;
843  check_utime(c->path, c->atime, c->mtime, /* test_lutime */ 0);
844 
846  utime_cb_count++;
847 }
848 
849 
850 static void futime_cb(uv_fs_t* req) {
851  utime_check_t* c;
852 
853  ASSERT(req == &futime_req);
854  ASSERT(req->result == 0);
855  ASSERT(req->fs_type == UV_FS_FUTIME);
856 
857  c = req->data;
858  check_utime(c->path, c->atime, c->mtime, /* test_lutime */ 0);
859 
861  futime_cb_count++;
862 }
863 
864 
865 static void lutime_cb(uv_fs_t* req) {
866  utime_check_t* c;
867 
868  ASSERT(req->result == 0);
869  ASSERT(req->fs_type == UV_FS_LUTIME);
870 
871  c = req->data;
872  check_utime(c->path, c->atime, c->mtime, /* test_lutime */ 1);
873 
875  lutime_cb_count++;
876 }
877 
878 
879 TEST_IMPL(fs_file_async) {
880  int r;
881 
882  /* Setup. */
883  unlink("test_file");
884  unlink("test_file2");
885 
886  loop = uv_default_loop();
887 
888  r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
889  S_IRUSR | S_IWUSR, create_cb);
890  ASSERT(r == 0);
892 
893  ASSERT(create_cb_count == 1);
894  ASSERT(write_cb_count == 1);
895  ASSERT(fsync_cb_count == 1);
897  ASSERT(close_cb_count == 1);
898 
899  r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", rename_cb);
900  ASSERT(r == 0);
901 
903  ASSERT(create_cb_count == 1);
904  ASSERT(write_cb_count == 1);
905  ASSERT(close_cb_count == 1);
906  ASSERT(rename_cb_count == 1);
907 
908  r = uv_fs_open(loop, &open_req1, "test_file2", O_RDWR, 0, open_cb);
909  ASSERT(r == 0);
910 
912  ASSERT(open_cb_count == 1);
913  ASSERT(read_cb_count == 1);
914  ASSERT(close_cb_count == 2);
915  ASSERT(rename_cb_count == 1);
916  ASSERT(create_cb_count == 1);
917  ASSERT(write_cb_count == 1);
919 
920  r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, open_cb);
921  ASSERT(r == 0);
922 
924  ASSERT(open_cb_count == 2);
925  ASSERT(read_cb_count == 2);
926  ASSERT(close_cb_count == 3);
927  ASSERT(rename_cb_count == 1);
928  ASSERT(unlink_cb_count == 1);
929  ASSERT(create_cb_count == 1);
930  ASSERT(write_cb_count == 1);
932 
933  /* Cleanup. */
934  unlink("test_file");
935  unlink("test_file2");
936 
938  return 0;
939 }
940 
941 
942 static void fs_file_sync(int add_flags) {
943  int r;
944 
945  /* Setup. */
946  unlink("test_file");
947  unlink("test_file2");
948 
949  loop = uv_default_loop();
950 
951  r = uv_fs_open(loop, &open_req1, "test_file",
952  O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
953  ASSERT(r >= 0);
954  ASSERT(open_req1.result >= 0);
956 
957  iov = uv_buf_init(test_buf, sizeof(test_buf));
958  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, -1, NULL);
959  ASSERT(r >= 0);
960  ASSERT(write_req.result >= 0);
962 
963  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
964  ASSERT(r == 0);
965  ASSERT(close_req.result == 0);
967 
968  r = uv_fs_open(NULL, &open_req1, "test_file", O_RDWR | add_flags, 0, NULL);
969  ASSERT(r >= 0);
970  ASSERT(open_req1.result >= 0);
972 
973  iov = uv_buf_init(buf, sizeof(buf));
974  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
975  ASSERT(r >= 0);
976  ASSERT(read_req.result >= 0);
977  ASSERT(strcmp(buf, test_buf) == 0);
979 
980  r = uv_fs_ftruncate(NULL, &ftruncate_req, open_req1.result, 7, NULL);
981  ASSERT(r == 0);
984 
985  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
986  ASSERT(r == 0);
987  ASSERT(close_req.result == 0);
989 
990  r = uv_fs_rename(NULL, &rename_req, "test_file", "test_file2", NULL);
991  ASSERT(r == 0);
992  ASSERT(rename_req.result == 0);
994 
995  r = uv_fs_open(NULL, &open_req1, "test_file2", O_RDONLY | add_flags, 0,
996  NULL);
997  ASSERT(r >= 0);
998  ASSERT(open_req1.result >= 0);
1000 
1001  memset(buf, 0, sizeof(buf));
1002  iov = uv_buf_init(buf, sizeof(buf));
1003  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
1004  ASSERT(r >= 0);
1005  ASSERT(read_req.result >= 0);
1006  ASSERT(strcmp(buf, "test-bu") == 0);
1008 
1009  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
1010  ASSERT(r == 0);
1011  ASSERT(close_req.result == 0);
1013 
1014  r = uv_fs_unlink(NULL, &unlink_req, "test_file2", NULL);
1015  ASSERT(r == 0);
1016  ASSERT(unlink_req.result == 0);
1018 
1019  /* Cleanup */
1020  unlink("test_file");
1021  unlink("test_file2");
1022 }
1024  fs_file_sync(0);
1026 
1028  return 0;
1029 }
1030 
1031 
1032 static void fs_file_write_null_buffer(int add_flags) {
1033  int r;
1034 
1035  /* Setup. */
1036  unlink("test_file");
1037 
1038  loop = uv_default_loop();
1039 
1040  r = uv_fs_open(NULL, &open_req1, "test_file",
1041  O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
1042  ASSERT(r >= 0);
1043  ASSERT(open_req1.result >= 0);
1045 
1046  iov = uv_buf_init(NULL, 0);
1047  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, -1, NULL);
1048  ASSERT(r == 0);
1049  ASSERT(write_req.result == 0);
1051 
1052  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
1053  ASSERT(r == 0);
1054  ASSERT(close_req.result == 0);
1056 
1057  unlink("test_file");
1058 }
1062 
1064  return 0;
1065 }
1066 
1067 
1068 TEST_IMPL(fs_async_dir) {
1069  int r;
1070  uv_dirent_t dent;
1071 
1072  /* Setup */
1073  unlink("test_dir/file1");
1074  unlink("test_dir/file2");
1075  rmdir("test_dir");
1076 
1077  loop = uv_default_loop();
1078 
1079  r = uv_fs_mkdir(loop, &mkdir_req, "test_dir", 0755, mkdir_cb);
1080  ASSERT(r == 0);
1081 
1083  ASSERT(mkdir_cb_count == 1);
1084 
1085  /* Create 2 files synchronously. */
1086  r = uv_fs_open(NULL, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT,
1087  S_IWUSR | S_IRUSR, NULL);
1088  ASSERT(r >= 0);
1090  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
1091  ASSERT(r == 0);
1093 
1094  r = uv_fs_open(NULL, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT,
1095  S_IWUSR | S_IRUSR, NULL);
1096  ASSERT(r >= 0);
1098  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
1099  ASSERT(r == 0);
1101 
1102  r = uv_fs_scandir(loop, &scandir_req, "test_dir", 0, scandir_cb);
1103  ASSERT(r == 0);
1104 
1106  ASSERT(scandir_cb_count == 1);
1107 
1108  /* sync uv_fs_scandir */
1109  r = uv_fs_scandir(NULL, &scandir_req, "test_dir", 0, NULL);
1110  ASSERT(r == 2);
1111  ASSERT(scandir_req.result == 2);
1113  while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) {
1114  ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0);
1115  assert_is_file_type(dent);
1116  }
1119 
1120  r = uv_fs_stat(loop, &stat_req, "test_dir", stat_cb);
1121  ASSERT(r == 0);
1123 
1124  r = uv_fs_stat(loop, &stat_req, "test_dir/", stat_cb);
1125  ASSERT(r == 0);
1127 
1128  r = uv_fs_lstat(loop, &stat_req, "test_dir", stat_cb);
1129  ASSERT(r == 0);
1131 
1132  r = uv_fs_lstat(loop, &stat_req, "test_dir/", stat_cb);
1133  ASSERT(r == 0);
1135 
1136  ASSERT(stat_cb_count == 4);
1137 
1138  r = uv_fs_unlink(loop, &unlink_req, "test_dir/file1", unlink_cb);
1139  ASSERT(r == 0);
1141  ASSERT(unlink_cb_count == 1);
1142 
1143  r = uv_fs_unlink(loop, &unlink_req, "test_dir/file2", unlink_cb);
1144  ASSERT(r == 0);
1146  ASSERT(unlink_cb_count == 2);
1147 
1148  r = uv_fs_rmdir(loop, &rmdir_req, "test_dir", rmdir_cb);
1149  ASSERT(r == 0);
1151  ASSERT(rmdir_cb_count == 1);
1152 
1153  /* Cleanup */
1154  unlink("test_dir/file1");
1155  unlink("test_dir/file2");
1156  rmdir("test_dir");
1157 
1159  return 0;
1160 }
1161 
1162 
1163 static int test_sendfile(void (*setup)(int), uv_fs_cb cb, off_t expected_size) {
1164  int f, r;
1165  struct stat s1, s2;
1166 
1167  loop = uv_default_loop();
1168 
1169  /* Setup. */
1170  unlink("test_file");
1171  unlink("test_file2");
1172 
1173  f = open("test_file", O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR);
1174  ASSERT(f != -1);
1175 
1176  if (setup != NULL)
1177  setup(f);
1178 
1179  r = close(f);
1180  ASSERT(r == 0);
1181 
1182  /* Test starts here. */
1183  r = uv_fs_open(NULL, &open_req1, "test_file", O_RDWR, 0, NULL);
1184  ASSERT(r >= 0);
1185  ASSERT(open_req1.result >= 0);
1187 
1188  r = uv_fs_open(NULL, &open_req2, "test_file2", O_WRONLY | O_CREAT,
1189  S_IWUSR | S_IRUSR, NULL);
1190  ASSERT(r >= 0);
1191  ASSERT(open_req2.result >= 0);
1193 
1195  0, 131072, cb);
1196  ASSERT(r == 0);
1198 
1199  ASSERT(sendfile_cb_count == 1);
1200 
1201  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
1202  ASSERT(r == 0);
1204  r = uv_fs_close(NULL, &close_req, open_req2.result, NULL);
1205  ASSERT(r == 0);
1207 
1208  ASSERT(0 == stat("test_file", &s1));
1209  ASSERT(0 == stat("test_file2", &s2));
1210  ASSERT(s1.st_size == s2.st_size);
1211  ASSERT(s2.st_size == expected_size);
1212 
1213  /* Cleanup. */
1214  unlink("test_file");
1215  unlink("test_file2");
1216 
1218  return 0;
1219 }
1220 
1221 
1222 static void sendfile_setup(int f) {
1223  ASSERT(6 == write(f, "begin\n", 6));
1224  ASSERT(65542 == lseek(f, 65536, SEEK_CUR));
1225  ASSERT(4 == write(f, "end\n", 4));
1226 }
1227 
1228 
1229 TEST_IMPL(fs_async_sendfile) {
1230  return test_sendfile(sendfile_setup, sendfile_cb, 65546);
1231 }
1232 
1233 
1234 TEST_IMPL(fs_async_sendfile_nodata) {
1235  return test_sendfile(NULL, sendfile_nodata_cb, 0);
1236 }
1237 
1238 
1239 TEST_IMPL(fs_mkdtemp) {
1240  int r;
1241  const char* path_template = "test_dir_XXXXXX";
1242 
1243  loop = uv_default_loop();
1244 
1245  r = uv_fs_mkdtemp(loop, &mkdtemp_req1, path_template, mkdtemp_cb);
1246  ASSERT(r == 0);
1247 
1249  ASSERT(mkdtemp_cb_count == 1);
1250 
1251  /* sync mkdtemp */
1252  r = uv_fs_mkdtemp(NULL, &mkdtemp_req2, path_template, NULL);
1253  ASSERT(r == 0);
1255 
1256  /* mkdtemp return different values on subsequent calls */
1257  ASSERT(strcmp(mkdtemp_req1.path, mkdtemp_req2.path) != 0);
1258 
1259  /* Cleanup */
1264 
1266  return 0;
1267 }
1268 
1269 
1270 TEST_IMPL(fs_mkstemp) {
1271  int r;
1272  int fd;
1273  const char path_template[] = "test_file_XXXXXX";
1274  uv_fs_t req;
1275 
1276  loop = uv_default_loop();
1277 
1278  r = uv_fs_mkstemp(loop, &mkstemp_req1, path_template, mkstemp_cb);
1279  ASSERT(r == 0);
1280 
1282  ASSERT(mkstemp_cb_count == 1);
1283 
1284  /* sync mkstemp */
1285  r = uv_fs_mkstemp(NULL, &mkstemp_req2, path_template, NULL);
1286  ASSERT(r >= 0);
1288 
1289  /* mkstemp return different values on subsequent calls */
1290  ASSERT(strcmp(mkstemp_req1.path, mkstemp_req2.path) != 0);
1291 
1292  /* invalid template returns EINVAL */
1293  ASSERT(uv_fs_mkstemp(NULL, &mkstemp_req3, "test_file", NULL) == UV_EINVAL);
1294 
1295  /* We can write to the opened file */
1296  iov = uv_buf_init(test_buf, sizeof(test_buf));
1297  r = uv_fs_write(NULL, &req, mkstemp_req1.result, &iov, 1, -1, NULL);
1298  ASSERT(r == sizeof(test_buf));
1299  ASSERT(req.result == sizeof(test_buf));
1301 
1302  /* Cleanup */
1303  uv_fs_close(NULL, &req, mkstemp_req1.result, NULL);
1305  uv_fs_close(NULL, &req, mkstemp_req2.result, NULL);
1307 
1308  fd = uv_fs_open(NULL, &req, mkstemp_req1.path , O_RDONLY, 0, NULL);
1309  ASSERT(fd >= 0);
1311 
1312  memset(buf, 0, sizeof(buf));
1313  iov = uv_buf_init(buf, sizeof(buf));
1314  r = uv_fs_read(NULL, &req, fd, &iov, 1, -1, NULL);
1315  ASSERT(r >= 0);
1316  ASSERT(req.result >= 0);
1317  ASSERT(strcmp(buf, test_buf) == 0);
1319 
1320  uv_fs_close(NULL, &req, fd, NULL);
1322 
1327 
1329  return 0;
1330 }
1331 
1332 
1333 TEST_IMPL(fs_fstat) {
1334  int r;
1335  uv_fs_t req;
1336  uv_file file;
1337  uv_stat_t* s;
1338 #ifndef _WIN32
1339  struct stat t;
1340 #endif
1341 
1342  /* Setup. */
1343  unlink("test_file");
1344 
1345  loop = uv_default_loop();
1346 
1347  r = uv_fs_open(NULL, &req, "test_file", O_RDWR | O_CREAT,
1348  S_IWUSR | S_IRUSR, NULL);
1349  ASSERT(r >= 0);
1350  ASSERT(req.result >= 0);
1351  file = req.result;
1353 
1354 #ifndef _WIN32
1355  ASSERT(0 == fstat(file, &t));
1356  ASSERT(0 == uv_fs_fstat(NULL, &req, file, NULL));
1357  ASSERT(req.result == 0);
1358  s = req.ptr;
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__)
1363  /* If statx() is supported, the birth time should be equal to the change time
1364  * because we just created the file. On older kernels, it's set to zero.
1365  */
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);
1370 # endif
1371 #endif
1372 
1373  iov = uv_buf_init(test_buf, sizeof(test_buf));
1374  r = uv_fs_write(NULL, &req, file, &iov, 1, -1, NULL);
1375  ASSERT(r == sizeof(test_buf));
1376  ASSERT(req.result == sizeof(test_buf));
1378 
1379  memset(&req.statbuf, 0xaa, sizeof(req.statbuf));
1380  r = uv_fs_fstat(NULL, &req, file, NULL);
1381  ASSERT(r == 0);
1382  ASSERT(req.result == 0);
1383  s = req.ptr;
1384  ASSERT(s->st_size == sizeof(test_buf));
1385 
1386 #ifndef _WIN32
1387  r = fstat(file, &t);
1388  ASSERT(r == 0);
1389 
1390  ASSERT(s->st_dev == (uint64_t) t.st_dev);
1391  ASSERT(s->st_mode == (uint64_t) t.st_mode);
1392  ASSERT(s->st_nlink == (uint64_t) t.st_nlink);
1393  ASSERT(s->st_uid == (uint64_t) t.st_uid);
1394  ASSERT(s->st_gid == (uint64_t) t.st_gid);
1395  ASSERT(s->st_rdev == (uint64_t) t.st_rdev);
1396  ASSERT(s->st_ino == (uint64_t) t.st_ino);
1397  ASSERT(s->st_size == (uint64_t) t.st_size);
1398  ASSERT(s->st_blksize == (uint64_t) t.st_blksize);
1399  ASSERT(s->st_blocks == (uint64_t) t.st_blocks);
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);
1407 #elif defined(_AIX)
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__) || \
1438  defined(__NetBSD__)
1439  ASSERT(s->st_birthtim.tv_sec == t.st_birthtim.tv_sec);
1440  ASSERT(s->st_birthtim.tv_nsec == t.st_birthtim.tv_nsec);
1441 # endif
1442 #else
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);
1449 #endif
1450 #endif
1451 
1452 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
1453  ASSERT(s->st_flags == t.st_flags);
1454  ASSERT(s->st_gen == t.st_gen);
1455 #else
1456  ASSERT(s->st_flags == 0);
1457  ASSERT(s->st_gen == 0);
1458 #endif
1459 
1461 
1462  /* Now do the uv_fs_fstat call asynchronously */
1463  r = uv_fs_fstat(loop, &req, file, fstat_cb);
1464  ASSERT(r == 0);
1466  ASSERT(fstat_cb_count == 1);
1467 
1468 
1469  r = uv_fs_close(NULL, &req, file, NULL);
1470  ASSERT(r == 0);
1471  ASSERT(req.result == 0);
1473 
1474  /*
1475  * Run the loop just to check we don't have make any extraneous uv_ref()
1476  * calls. This should drop out immediately.
1477  */
1479 
1480  /* Cleanup. */
1481  unlink("test_file");
1482 
1484  return 0;
1485 }
1486 
1487 
1488 TEST_IMPL(fs_access) {
1489  int r;
1490  uv_fs_t req;
1491  uv_file file;
1492 
1493  /* Setup. */
1494  unlink("test_file");
1495  rmdir("test_dir");
1496 
1497  loop = uv_default_loop();
1498 
1499  /* File should not exist */
1500  r = uv_fs_access(NULL, &req, "test_file", F_OK, NULL);
1501  ASSERT(r < 0);
1502  ASSERT(req.result < 0);
1504 
1505  /* File should not exist */
1506  r = uv_fs_access(loop, &req, "test_file", F_OK, access_cb);
1507  ASSERT(r == 0);
1509  ASSERT(access_cb_count == 1);
1510  access_cb_count = 0; /* reset for the next test */
1511 
1512  /* Create file */
1513  r = uv_fs_open(NULL, &req, "test_file", O_RDWR | O_CREAT,
1514  S_IWUSR | S_IRUSR, NULL);
1515  ASSERT(r >= 0);
1516  ASSERT(req.result >= 0);
1517  file = req.result;
1519 
1520  /* File should exist */
1521  r = uv_fs_access(NULL, &req, "test_file", F_OK, NULL);
1522  ASSERT(r == 0);
1523  ASSERT(req.result == 0);
1525 
1526  /* File should exist */
1527  r = uv_fs_access(loop, &req, "test_file", F_OK, access_cb);
1528  ASSERT(r == 0);
1530  ASSERT(access_cb_count == 1);
1531  access_cb_count = 0; /* reset for the next test */
1532 
1533  /* Close file */
1534  r = uv_fs_close(NULL, &req, file, NULL);
1535  ASSERT(r == 0);
1536  ASSERT(req.result == 0);
1538 
1539  /* Directory access */
1540  r = uv_fs_mkdir(NULL, &req, "test_dir", 0777, NULL);
1541  ASSERT(r == 0);
1543 
1544  r = uv_fs_access(NULL, &req, "test_dir", W_OK, NULL);
1545  ASSERT(r == 0);
1546  ASSERT(req.result == 0);
1548 
1549  /*
1550  * Run the loop just to check we don't have make any extraneous uv_ref()
1551  * calls. This should drop out immediately.
1552  */
1554 
1555  /* Cleanup. */
1556  unlink("test_file");
1557  rmdir("test_dir");
1558 
1560  return 0;
1561 }
1562 
1563 
1564 TEST_IMPL(fs_chmod) {
1565  int r;
1566  uv_fs_t req;
1567  uv_file file;
1568 
1569  /* Setup. */
1570  unlink("test_file");
1571 
1572  loop = uv_default_loop();
1573 
1574  r = uv_fs_open(NULL, &req, "test_file", O_RDWR | O_CREAT,
1575  S_IWUSR | S_IRUSR, NULL);
1576  ASSERT(r >= 0);
1577  ASSERT(req.result >= 0);
1578  file = req.result;
1580 
1581  iov = uv_buf_init(test_buf, sizeof(test_buf));
1582  r = uv_fs_write(NULL, &req, file, &iov, 1, -1, NULL);
1583  ASSERT(r == sizeof(test_buf));
1584  ASSERT(req.result == sizeof(test_buf));
1586 
1587 #ifndef _WIN32
1588  /* Make the file write-only */
1589  r = uv_fs_chmod(NULL, &req, "test_file", 0200, NULL);
1590  ASSERT(r == 0);
1591  ASSERT(req.result == 0);
1593 
1594  check_permission("test_file", 0200);
1595 #endif
1596 
1597  /* Make the file read-only */
1598  r = uv_fs_chmod(NULL, &req, "test_file", 0400, NULL);
1599  ASSERT(r == 0);
1600  ASSERT(req.result == 0);
1602 
1603  check_permission("test_file", 0400);
1604 
1605  /* Make the file read+write with sync uv_fs_fchmod */
1606  r = uv_fs_fchmod(NULL, &req, file, 0600, NULL);
1607  ASSERT(r == 0);
1608  ASSERT(req.result == 0);
1610 
1611  check_permission("test_file", 0600);
1612 
1613 #ifndef _WIN32
1614  /* async chmod */
1615  {
1616  static int mode = 0200;
1617  req.data = &mode;
1618  }
1619  r = uv_fs_chmod(loop, &req, "test_file", 0200, chmod_cb);
1620  ASSERT(r == 0);
1622  ASSERT(chmod_cb_count == 1);
1623  chmod_cb_count = 0; /* reset for the next test */
1624 #endif
1625 
1626  /* async chmod */
1627  {
1628  static int mode = 0400;
1629  req.data = &mode;
1630  }
1631  r = uv_fs_chmod(loop, &req, "test_file", 0400, chmod_cb);
1632  ASSERT(r == 0);
1634  ASSERT(chmod_cb_count == 1);
1635 
1636  /* async fchmod */
1637  {
1638  static int mode = 0600;
1639  req.data = &mode;
1640  }
1641  r = uv_fs_fchmod(loop, &req, file, 0600, fchmod_cb);
1642  ASSERT(r == 0);
1644  ASSERT(fchmod_cb_count == 1);
1645 
1646  uv_fs_close(loop, &req, file, NULL);
1647 
1648  /*
1649  * Run the loop just to check we don't have make any extraneous uv_ref()
1650  * calls. This should drop out immediately.
1651  */
1653 
1654  /* Cleanup. */
1655  unlink("test_file");
1656 
1658  return 0;
1659 }
1660 
1661 
1662 TEST_IMPL(fs_unlink_readonly) {
1663  int r;
1664  uv_fs_t req;
1665  uv_file file;
1666 
1667  /* Setup. */
1668  unlink("test_file");
1669 
1670  loop = uv_default_loop();
1671 
1672  r = uv_fs_open(NULL,
1673  &req,
1674  "test_file",
1675  O_RDWR | O_CREAT,
1676  S_IWUSR | S_IRUSR,
1677  NULL);
1678  ASSERT(r >= 0);
1679  ASSERT(req.result >= 0);
1680  file = req.result;
1682 
1683  iov = uv_buf_init(test_buf, sizeof(test_buf));
1684  r = uv_fs_write(NULL, &req, file, &iov, 1, -1, NULL);
1685  ASSERT(r == sizeof(test_buf));
1686  ASSERT(req.result == sizeof(test_buf));
1688 
1689  uv_fs_close(loop, &req, file, NULL);
1690 
1691  /* Make the file read-only */
1692  r = uv_fs_chmod(NULL, &req, "test_file", 0400, NULL);
1693  ASSERT(r == 0);
1694  ASSERT(req.result == 0);
1696 
1697  check_permission("test_file", 0400);
1698 
1699  /* Try to unlink the file */
1700  r = uv_fs_unlink(NULL, &req, "test_file", NULL);
1701  ASSERT(r == 0);
1702  ASSERT(req.result == 0);
1704 
1705  /*
1706  * Run the loop just to check we don't have make any extraneous uv_ref()
1707  * calls. This should drop out immediately.
1708  */
1710 
1711  /* Cleanup. */
1712  uv_fs_chmod(NULL, &req, "test_file", 0600, NULL);
1714  unlink("test_file");
1715 
1717  return 0;
1718 }
1719 
1720 #ifdef _WIN32
1721 TEST_IMPL(fs_unlink_archive_readonly) {
1722  int r;
1723  uv_fs_t req;
1724  uv_file file;
1725 
1726  /* Setup. */
1727  unlink("test_file");
1728 
1729  loop = uv_default_loop();
1730 
1731  r = uv_fs_open(NULL,
1732  &req,
1733  "test_file",
1734  O_RDWR | O_CREAT,
1735  S_IWUSR | S_IRUSR,
1736  NULL);
1737  ASSERT(r >= 0);
1738  ASSERT(req.result >= 0);
1739  file = req.result;
1741 
1742  iov = uv_buf_init(test_buf, sizeof(test_buf));
1743  r = uv_fs_write(NULL, &req, file, &iov, 1, -1, NULL);
1744  ASSERT(r == sizeof(test_buf));
1745  ASSERT(req.result == sizeof(test_buf));
1747 
1748  uv_fs_close(loop, &req, file, NULL);
1749 
1750  /* Make the file read-only and clear archive flag */
1751  r = SetFileAttributes("test_file", FILE_ATTRIBUTE_READONLY);
1752  ASSERT(r != 0);
1754 
1755  check_permission("test_file", 0400);
1756 
1757  /* Try to unlink the file */
1758  r = uv_fs_unlink(NULL, &req, "test_file", NULL);
1759  ASSERT(r == 0);
1760  ASSERT(req.result == 0);
1762 
1763  /*
1764  * Run the loop just to check we don't have make any extraneous uv_ref()
1765  * calls. This should drop out immediately.
1766  */
1768 
1769  /* Cleanup. */
1770  uv_fs_chmod(NULL, &req, "test_file", 0600, NULL);
1772  unlink("test_file");
1773 
1775  return 0;
1776 }
1777 #endif
1778 
1779 TEST_IMPL(fs_chown) {
1780  int r;
1781  uv_fs_t req;
1782  uv_file file;
1783 
1784  /* Setup. */
1785  unlink("test_file");
1786  unlink("test_file_link");
1787 
1788  loop = uv_default_loop();
1789 
1790  r = uv_fs_open(NULL, &req, "test_file", O_RDWR | O_CREAT,
1791  S_IWUSR | S_IRUSR, NULL);
1792  ASSERT(r >= 0);
1793  ASSERT(req.result >= 0);
1794  file = req.result;
1796 
1797  /* sync chown */
1798  r = uv_fs_chown(NULL, &req, "test_file", -1, -1, NULL);
1799  ASSERT(r == 0);
1800  ASSERT(req.result == 0);
1802 
1803  /* sync fchown */
1804  r = uv_fs_fchown(NULL, &req, file, -1, -1, NULL);
1805  ASSERT(r == 0);
1806  ASSERT(req.result == 0);
1808 
1809  /* async chown */
1810  r = uv_fs_chown(loop, &req, "test_file", -1, -1, chown_cb);
1811  ASSERT(r == 0);
1813  ASSERT(chown_cb_count == 1);
1814 
1815 #ifndef __MVS__
1816  /* chown to root (fail) */
1817  chown_cb_count = 0;
1818  r = uv_fs_chown(loop, &req, "test_file", 0, 0, chown_root_cb);
1819  ASSERT(r == 0);
1821  ASSERT(chown_cb_count == 1);
1822 #endif
1823 
1824  /* async fchown */
1825  r = uv_fs_fchown(loop, &req, file, -1, -1, fchown_cb);
1826  ASSERT(r == 0);
1828  ASSERT(fchown_cb_count == 1);
1829 
1830 #ifndef __HAIKU__
1831  /* Haiku doesn't support hardlink */
1832  /* sync link */
1833  r = uv_fs_link(NULL, &req, "test_file", "test_file_link", NULL);
1834  ASSERT(r == 0);
1835  ASSERT(req.result == 0);
1837 
1838  /* sync lchown */
1839  r = uv_fs_lchown(NULL, &req, "test_file_link", -1, -1, NULL);
1840  ASSERT(r == 0);
1841  ASSERT(req.result == 0);
1843 
1844  /* async lchown */
1845  r = uv_fs_lchown(loop, &req, "test_file_link", -1, -1, lchown_cb);
1846  ASSERT(r == 0);
1848  ASSERT(lchown_cb_count == 1);
1849 #endif
1850 
1851  /* Close file */
1852  r = uv_fs_close(NULL, &req, file, NULL);
1853  ASSERT(r == 0);
1854  ASSERT(req.result == 0);
1856 
1857  /*
1858  * Run the loop just to check we don't have make any extraneous uv_ref()
1859  * calls. This should drop out immediately.
1860  */
1862 
1863  /* Cleanup. */
1864  unlink("test_file");
1865  unlink("test_file_link");
1866 
1868  return 0;
1869 }
1870 
1871 
1872 TEST_IMPL(fs_link) {
1873  int r;
1874  uv_fs_t req;
1875  uv_file file;
1876  uv_file link;
1877 
1878  /* Setup. */
1879  unlink("test_file");
1880  unlink("test_file_link");
1881  unlink("test_file_link2");
1882 
1883  loop = uv_default_loop();
1884 
1885  r = uv_fs_open(NULL, &req, "test_file", O_RDWR | O_CREAT,
1886  S_IWUSR | S_IRUSR, NULL);
1887  ASSERT(r >= 0);
1888  ASSERT(req.result >= 0);
1889  file = req.result;
1891 
1892  iov = uv_buf_init(test_buf, sizeof(test_buf));
1893  r = uv_fs_write(NULL, &req, file, &iov, 1, -1, NULL);
1894  ASSERT(r == sizeof(test_buf));
1895  ASSERT(req.result == sizeof(test_buf));
1897 
1898  uv_fs_close(loop, &req, file, NULL);
1899 
1900  /* sync link */
1901  r = uv_fs_link(NULL, &req, "test_file", "test_file_link", NULL);
1902  ASSERT(r == 0);
1903  ASSERT(req.result == 0);
1905 
1906  r = uv_fs_open(NULL, &req, "test_file_link", O_RDWR, 0, NULL);
1907  ASSERT(r >= 0);
1908  ASSERT(req.result >= 0);
1909  link = req.result;
1911 
1912  memset(buf, 0, sizeof(buf));
1913  iov = uv_buf_init(buf, sizeof(buf));
1914  r = uv_fs_read(NULL, &req, link, &iov, 1, 0, NULL);
1915  ASSERT(r >= 0);
1916  ASSERT(req.result >= 0);
1917  ASSERT(strcmp(buf, test_buf) == 0);
1918 
1919  close(link);
1920 
1921  /* async link */
1922  r = uv_fs_link(loop, &req, "test_file", "test_file_link2", link_cb);
1923  ASSERT(r == 0);
1925  ASSERT(link_cb_count == 1);
1926 
1927  r = uv_fs_open(NULL, &req, "test_file_link2", O_RDWR, 0, NULL);
1928  ASSERT(r >= 0);
1929  ASSERT(req.result >= 0);
1930  link = req.result;
1932 
1933  memset(buf, 0, sizeof(buf));
1934  iov = uv_buf_init(buf, sizeof(buf));
1935  r = uv_fs_read(NULL, &req, link, &iov, 1, 0, NULL);
1936  ASSERT(r >= 0);
1937  ASSERT(req.result >= 0);
1938  ASSERT(strcmp(buf, test_buf) == 0);
1939 
1940  uv_fs_close(loop, &req, link, NULL);
1941 
1942  /*
1943  * Run the loop just to check we don't have make any extraneous uv_ref()
1944  * calls. This should drop out immediately.
1945  */
1947 
1948  /* Cleanup. */
1949  unlink("test_file");
1950  unlink("test_file_link");
1951  unlink("test_file_link2");
1952 
1954  return 0;
1955 }
1956 
1957 
1958 TEST_IMPL(fs_readlink) {
1959  uv_fs_t req;
1960 
1961  loop = uv_default_loop();
1962  ASSERT(0 == uv_fs_readlink(loop, &req, "no_such_file", dummy_cb));
1963  ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
1964  ASSERT(dummy_cb_count == 1);
1965  ASSERT(req.ptr == NULL);
1966  ASSERT(req.result == UV_ENOENT);
1968 
1969  ASSERT(UV_ENOENT == uv_fs_readlink(NULL, &req, "no_such_file", NULL));
1970  ASSERT(req.ptr == NULL);
1971  ASSERT(req.result == UV_ENOENT);
1973 
1975  return 0;
1976 }
1977 
1978 
1979 TEST_IMPL(fs_realpath) {
1980  uv_fs_t req;
1981 
1982  loop = uv_default_loop();
1983  ASSERT(0 == uv_fs_realpath(loop, &req, "no_such_file", dummy_cb));
1984  ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
1985  ASSERT(dummy_cb_count == 1);
1986  ASSERT(req.ptr == NULL);
1987 #ifdef _WIN32
1988  /*
1989  * Windows XP and Server 2003 don't support GetFinalPathNameByHandleW()
1990  */
1991  if (req.result == UV_ENOSYS) {
1993  RETURN_SKIP("realpath is not supported on Windows XP");
1994  }
1995 #endif
1996  ASSERT(req.result == UV_ENOENT);
1998 
1999  ASSERT(UV_ENOENT == uv_fs_realpath(NULL, &req, "no_such_file", NULL));
2000  ASSERT(req.ptr == NULL);
2001  ASSERT(req.result == UV_ENOENT);
2003 
2005  return 0;
2006 }
2007 
2008 
2009 TEST_IMPL(fs_symlink) {
2010  int r;
2011  uv_fs_t req;
2012  uv_file file;
2013  uv_file link;
2014  char test_file_abs_buf[PATHMAX];
2015  size_t test_file_abs_size;
2016 
2017  /* Setup. */
2018  unlink("test_file");
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);
2024 #ifdef _WIN32
2025  uv_cwd(test_file_abs_buf, &test_file_abs_size);
2026  strcat(test_file_abs_buf, "\\test_file");
2027 #else
2028  uv_cwd(test_file_abs_buf, &test_file_abs_size);
2029  strcat(test_file_abs_buf, "/test_file");
2030 #endif
2031 
2032  loop = uv_default_loop();
2033 
2034  r = uv_fs_open(NULL, &req, "test_file", O_RDWR | O_CREAT,
2035  S_IWUSR | S_IRUSR, NULL);
2036  ASSERT(r >= 0);
2037  ASSERT(req.result >= 0);
2038  file = req.result;
2040 
2041  iov = uv_buf_init(test_buf, sizeof(test_buf));
2042  r = uv_fs_write(NULL, &req, file, &iov, 1, -1, NULL);
2043  ASSERT(r == sizeof(test_buf));
2044  ASSERT(req.result == sizeof(test_buf));
2046 
2047  uv_fs_close(loop, &req, file, NULL);
2048 
2049  /* sync symlink */
2050  r = uv_fs_symlink(NULL, &req, "test_file", "test_file_symlink", 0, NULL);
2051 #ifdef _WIN32
2052  if (r < 0) {
2053  if (r == UV_ENOTSUP) {
2054  /*
2055  * Windows doesn't support symlinks on older versions.
2056  * We just pass the test and bail out early if we get ENOTSUP.
2057  */
2058  return 0;
2059  } else if (r == UV_EPERM) {
2060  /*
2061  * Creating a symlink is only allowed when running elevated.
2062  * We pass the test and bail out early if we get UV_EPERM.
2063  */
2064  return 0;
2065  }
2066  }
2067 #endif
2068  ASSERT(r == 0);
2069  ASSERT(req.result == 0);
2071 
2072  r = uv_fs_open(NULL, &req, "test_file_symlink", O_RDWR, 0, NULL);
2073  ASSERT(r >= 0);
2074  ASSERT(req.result >= 0);
2075  link = req.result;
2077 
2078  memset(buf, 0, sizeof(buf));
2079  iov = uv_buf_init(buf, sizeof(buf));
2080  r = uv_fs_read(NULL, &req, link, &iov, 1, 0, NULL);
2081  ASSERT(r >= 0);
2082  ASSERT(req.result >= 0);
2083  ASSERT(strcmp(buf, test_buf) == 0);
2084 
2085  uv_fs_close(loop, &req, link, NULL);
2086 
2087  r = uv_fs_symlink(NULL,
2088  &req,
2089  "test_file_symlink",
2090  "test_file_symlink_symlink",
2091  0,
2092  NULL);
2093  ASSERT(r == 0);
2095 
2096 #if defined(__MSYS__)
2097  RETURN_SKIP("symlink reading is not supported on MSYS2");
2098 #endif
2099 
2100  r = uv_fs_readlink(NULL, &req, "test_file_symlink_symlink", NULL);
2101  ASSERT(r == 0);
2102  ASSERT(strcmp(req.ptr, "test_file_symlink") == 0);
2104 
2105  r = uv_fs_realpath(NULL, &req, "test_file_symlink_symlink", NULL);
2106 #ifdef _WIN32
2107  /*
2108  * Windows XP and Server 2003 don't support GetFinalPathNameByHandleW()
2109  */
2110  if (r == UV_ENOSYS) {
2112  RETURN_SKIP("realpath is not supported on Windows XP");
2113  }
2114 #endif
2115  ASSERT(r == 0);
2116 #ifdef _WIN32
2117  ASSERT(stricmp(req.ptr, test_file_abs_buf) == 0);
2118 #else
2119  ASSERT(strcmp(req.ptr, test_file_abs_buf) == 0);
2120 #endif
2122 
2123  /* async link */
2124  r = uv_fs_symlink(loop,
2125  &req,
2126  "test_file",
2127  "test_file_symlink2",
2128  0,
2129  symlink_cb);
2130  ASSERT(r == 0);
2132  ASSERT(symlink_cb_count == 1);
2133 
2134  r = uv_fs_open(NULL, &req, "test_file_symlink2", O_RDWR, 0, NULL);
2135  ASSERT(r >= 0);
2136  ASSERT(req.result >= 0);
2137  link = req.result;
2139 
2140  memset(buf, 0, sizeof(buf));
2141  iov = uv_buf_init(buf, sizeof(buf));
2142  r = uv_fs_read(NULL, &req, link, &iov, 1, 0, NULL);
2143  ASSERT(r >= 0);
2144  ASSERT(req.result >= 0);
2145  ASSERT(strcmp(buf, test_buf) == 0);
2146 
2147  uv_fs_close(loop, &req, link, NULL);
2148 
2149  r = uv_fs_symlink(NULL,
2150  &req,
2151  "test_file_symlink2",
2152  "test_file_symlink2_symlink",
2153  0,
2154  NULL);
2155  ASSERT(r == 0);
2157 
2158  r = uv_fs_readlink(loop, &req, "test_file_symlink2_symlink", readlink_cb);
2159  ASSERT(r == 0);
2161  ASSERT(readlink_cb_count == 1);
2162 
2163  r = uv_fs_realpath(loop, &req, "test_file", realpath_cb);
2164 #ifdef _WIN32
2165  /*
2166  * Windows XP and Server 2003 don't support GetFinalPathNameByHandleW()
2167  */
2168  if (r == UV_ENOSYS) {
2170  RETURN_SKIP("realpath is not supported on Windows XP");
2171  }
2172 #endif
2173  ASSERT(r == 0);
2175  ASSERT(realpath_cb_count == 1);
2176 
2177  /*
2178  * Run the loop just to check we don't have make any extraneous uv_ref()
2179  * calls. This should drop out immediately.
2180  */
2182 
2183  /* Cleanup. */
2184  unlink("test_file");
2185  unlink("test_file_symlink");
2186  unlink("test_file_symlink_symlink");
2187  unlink("test_file_symlink2");
2188  unlink("test_file_symlink2_symlink");
2189 
2191  return 0;
2192 }
2193 
2194 
2196  uv_fs_t req;
2197  int r;
2198  char* test_dir;
2199  uv_dirent_t dent;
2200  static char test_dir_abs_buf[PATHMAX];
2201  size_t test_dir_abs_size;
2202 
2203  /* set-up */
2204  unlink("test_dir/file1");
2205  unlink("test_dir/file2");
2206  rmdir("test_dir");
2207  rmdir("test_dir_symlink");
2208  test_dir_abs_size = sizeof(test_dir_abs_buf);
2209 
2210  loop = uv_default_loop();
2211 
2212  uv_fs_mkdir(NULL, &req, "test_dir", 0777, NULL);
2214 
2215 #ifdef _WIN32
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;
2222 #else
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";
2227 #endif
2228 
2229  r = uv_fs_symlink(NULL, &req, test_dir, "test_dir_symlink", type, NULL);
2230  if (type == UV_FS_SYMLINK_DIR && (r == UV_ENOTSUP || r == UV_EPERM)) {
2232  RETURN_SKIP("this version of Windows doesn't support unprivileged "
2233  "creation of directory symlinks");
2234  }
2235  fprintf(stderr, "r == %i\n", r);
2236  ASSERT(r == 0);
2237  ASSERT(req.result == 0);
2239 
2240  r = uv_fs_stat(NULL, &req, "test_dir_symlink", NULL);
2241  ASSERT(r == 0);
2242  ASSERT(((uv_stat_t*)req.ptr)->st_mode & S_IFDIR);
2244 
2245  r = uv_fs_lstat(NULL, &req, "test_dir_symlink", NULL);
2246  ASSERT(r == 0);
2247 #if defined(__MSYS__)
2248  RETURN_SKIP("symlink reading is not supported on MSYS2");
2249 #endif
2250  ASSERT(((uv_stat_t*)req.ptr)->st_mode & S_IFLNK);
2251 #ifdef _WIN32
2252  ASSERT(((uv_stat_t*)req.ptr)->st_size == strlen(test_dir + 4));
2253 #else
2254 # ifdef __PASE__
2255  /* On IBMi PASE, st_size returns the length of the symlink itself. */
2256  ASSERT(((uv_stat_t*)req.ptr)->st_size == strlen("test_dir_symlink"));
2257 # else
2258  ASSERT(((uv_stat_t*)req.ptr)->st_size == strlen(test_dir));
2259 # endif
2260 #endif
2262 
2263  r = uv_fs_readlink(NULL, &req, "test_dir_symlink", NULL);
2264  ASSERT(r == 0);
2265 #ifdef _WIN32
2266  ASSERT(strcmp(req.ptr, test_dir + 4) == 0);
2267 #else
2268  ASSERT(strcmp(req.ptr, test_dir) == 0);
2269 #endif
2271 
2272  r = uv_fs_realpath(NULL, &req, "test_dir_symlink", NULL);
2273 #ifdef _WIN32
2274  /*
2275  * Windows XP and Server 2003 don't support GetFinalPathNameByHandleW()
2276  */
2277  if (r == UV_ENOSYS) {
2279  RETURN_SKIP("realpath is not supported on Windows XP");
2280  }
2281 #endif
2282  ASSERT(r == 0);
2283 #ifdef _WIN32
2284  ASSERT(strlen(req.ptr) == test_dir_abs_size - 5);
2285  ASSERT(strnicmp(req.ptr, test_dir + 4, test_dir_abs_size - 5) == 0);
2286 #else
2287  ASSERT(strcmp(req.ptr, test_dir_abs_buf) == 0);
2288 #endif
2290 
2291  r = uv_fs_open(NULL, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT,
2292  S_IWUSR | S_IRUSR, NULL);
2293  ASSERT(r >= 0);
2295  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
2296  ASSERT(r == 0);
2298 
2299  r = uv_fs_open(NULL, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT,
2300  S_IWUSR | S_IRUSR, NULL);
2301  ASSERT(r >= 0);
2303  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
2304  ASSERT(r == 0);
2306 
2307  r = uv_fs_scandir(NULL, &scandir_req, "test_dir_symlink", 0, NULL);
2308  ASSERT(r == 2);
2309  ASSERT(scandir_req.result == 2);
2311  while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) {
2312  ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0);
2313  assert_is_file_type(dent);
2314  }
2317 
2318  /* unlink will remove the directory symlink */
2319  r = uv_fs_unlink(NULL, &req, "test_dir_symlink", NULL);
2320  ASSERT(r == 0);
2322 
2323  r = uv_fs_scandir(NULL, &scandir_req, "test_dir_symlink", 0, NULL);
2324  ASSERT(r == UV_ENOENT);
2326 
2327  r = uv_fs_scandir(NULL, &scandir_req, "test_dir", 0, NULL);
2328  ASSERT(r == 2);
2329  ASSERT(scandir_req.result == 2);
2331  while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) {
2332  ASSERT(strcmp(dent.name, "file1") == 0 || strcmp(dent.name, "file2") == 0);
2333  assert_is_file_type(dent);
2334  }
2337 
2338  /* clean-up */
2339  unlink("test_dir/file1");
2340  unlink("test_dir/file2");
2341  rmdir("test_dir");
2342  rmdir("test_dir_symlink");
2343 
2345  return 0;
2346 }
2347 
2348 TEST_IMPL(fs_symlink_dir) {
2350 }
2351 
2352 TEST_IMPL(fs_symlink_junction) {
2354 }
2355 
2356 #ifdef _WIN32
2357 TEST_IMPL(fs_non_symlink_reparse_point) {
2358  uv_fs_t req;
2359  int r;
2360  HANDLE file_handle;
2361  REPARSE_GUID_DATA_BUFFER reparse_buffer;
2362  DWORD bytes_returned;
2363  uv_dirent_t dent;
2364 
2365  /* set-up */
2366  unlink("test_dir/test_file");
2367  rmdir("test_dir");
2368 
2369  loop = uv_default_loop();
2370 
2371  uv_fs_mkdir(NULL, &req, "test_dir", 0777, NULL);
2373 
2374  file_handle = CreateFile("test_dir/test_file",
2375  GENERIC_WRITE | FILE_WRITE_ATTRIBUTES,
2376  0,
2377  NULL,
2378  CREATE_ALWAYS,
2379  FILE_FLAG_OPEN_REPARSE_POINT |
2380  FILE_FLAG_BACKUP_SEMANTICS,
2381  NULL);
2382  ASSERT(file_handle != INVALID_HANDLE_VALUE);
2383 
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;
2388 
2389  r = DeviceIoControl(file_handle,
2391  &reparse_buffer,
2392  REPARSE_GUID_DATA_BUFFER_HEADER_SIZE,
2393  NULL,
2394  0,
2395  &bytes_returned,
2396  NULL);
2397  ASSERT(r != 0);
2398 
2399  CloseHandle(file_handle);
2400 
2401  r = uv_fs_readlink(NULL, &req, "test_dir/test_file", NULL);
2402  ASSERT(r == UV_EINVAL && GetLastError() == ERROR_SYMLINK_NOT_SUPPORTED);
2404 
2405 /*
2406  Placeholder tests for exercising the behavior fixed in issue #995.
2407  To run, update the path with the IP address of a Mac with the hard drive
2408  shared via SMB as "Macintosh HD".
2409 
2410  r = uv_fs_stat(NULL, &req, "\\\<mac_ip>\\Macintosh HD\\.DS_Store", NULL);
2411  ASSERT(r == 0);
2412  uv_fs_req_cleanup(&req);
2413 
2414  r = uv_fs_lstat(NULL, &req, "\\\<mac_ip>\\Macintosh HD\\.DS_Store", NULL);
2415  ASSERT(r == 0);
2416  uv_fs_req_cleanup(&req);
2417 */
2418 
2419 /*
2420  uv_fs_stat and uv_fs_lstat can only work on non-symlink reparse
2421  points when a minifilter driver is registered which intercepts
2422  associated filesystem requests. Installing a driver is beyond
2423  the scope of this test.
2424 
2425  r = uv_fs_stat(NULL, &req, "test_dir/test_file", NULL);
2426  ASSERT(r == 0);
2427  uv_fs_req_cleanup(&req);
2428 
2429  r = uv_fs_lstat(NULL, &req, "test_dir/test_file", NULL);
2430  ASSERT(r == 0);
2431  uv_fs_req_cleanup(&req);
2432 */
2433 
2434  r = uv_fs_scandir(NULL, &scandir_req, "test_dir", 0, NULL);
2435  ASSERT(r == 1);
2436  ASSERT(scandir_req.result == 1);
2438  while (UV_EOF != uv_fs_scandir_next(&scandir_req, &dent)) {
2439  ASSERT(strcmp(dent.name, "test_file") == 0);
2440  /* uv_fs_scandir incorrectly identifies non-symlink reparse points
2441  as links because it doesn't open the file and verify the reparse
2442  point tag. The PowerShell Get-ChildItem command shares this
2443  behavior, so it's reasonable to leave it as is. */
2444  ASSERT(dent.type == UV_DIRENT_LINK);
2445  }
2448 
2449  /* clean-up */
2450  unlink("test_dir/test_file");
2451  rmdir("test_dir");
2452 
2454  return 0;
2455 }
2456 #endif
2457 
2458 
2459 TEST_IMPL(fs_utime) {
2460  utime_check_t checkme;
2461  const char* path = "test_file";
2462  double atime;
2463  double mtime;
2464  uv_fs_t req;
2465  int r;
2466 
2467  /* Setup. */
2468  loop = uv_default_loop();
2469  unlink(path);
2470  r = uv_fs_open(NULL, &req, path, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR, NULL);
2471  ASSERT(r >= 0);
2472  ASSERT(req.result >= 0);
2474  uv_fs_close(loop, &req, r, NULL);
2475 
2476  atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
2477 
2478  /*
2479  * Test sub-second timestamps only on Windows (assuming NTFS). Some other
2480  * platforms support sub-second timestamps, but that support is filesystem-
2481  * dependent. Notably OS X (HFS Plus) does NOT support sub-second timestamps.
2482  */
2483 #ifdef _WIN32
2484  mtime += 0.444; /* 1982-09-10 11:22:33.444 */
2485 #endif
2486 
2487  r = uv_fs_utime(NULL, &req, path, atime, mtime, NULL);
2488  ASSERT(r == 0);
2489  ASSERT(req.result == 0);
2491 
2492  r = uv_fs_stat(NULL, &req, path, NULL);
2493  ASSERT(r == 0);
2494  ASSERT(req.result == 0);
2495  check_utime(path, atime, mtime, /* test_lutime */ 0);
2497 
2498  atime = mtime = 1291404900; /* 2010-12-03 20:35:00 - mees <3 */
2499  checkme.path = path;
2500  checkme.atime = atime;
2501  checkme.mtime = mtime;
2502 
2503  /* async utime */
2504  utime_req.data = &checkme;
2505  r = uv_fs_utime(loop, &utime_req, path, atime, mtime, utime_cb);
2506  ASSERT(r == 0);
2508  ASSERT(utime_cb_count == 1);
2509 
2510  /* Cleanup. */
2511  unlink(path);
2512 
2514  return 0;
2515 }
2516 
2517 
2518 #ifdef _WIN32
2519 TEST_IMPL(fs_stat_root) {
2520  int r;
2521 
2522  r = uv_fs_stat(NULL, &stat_req, "\\", NULL);
2523  ASSERT(r == 0);
2524 
2525  r = uv_fs_stat(NULL, &stat_req, "..\\..\\..\\..\\..\\..\\..", NULL);
2526  ASSERT(r == 0);
2527 
2528  r = uv_fs_stat(NULL, &stat_req, "..", NULL);
2529  ASSERT(r == 0);
2530 
2531  r = uv_fs_stat(NULL, &stat_req, "..\\", NULL);
2532  ASSERT(r == 0);
2533 
2534  /* stats the current directory on c: */
2535  r = uv_fs_stat(NULL, &stat_req, "c:", NULL);
2536  ASSERT(r == 0);
2537 
2538  r = uv_fs_stat(NULL, &stat_req, "c:\\", NULL);
2539  ASSERT(r == 0);
2540 
2541  r = uv_fs_stat(NULL, &stat_req, "\\\\?\\C:\\", NULL);
2542  ASSERT(r == 0);
2543 
2545  return 0;
2546 }
2547 #endif
2548 
2549 
2550 TEST_IMPL(fs_futime) {
2551  utime_check_t checkme;
2552  const char* path = "test_file";
2553  double atime;
2554  double mtime;
2555  uv_file file;
2556  uv_fs_t req;
2557  int r;
2558 #if defined(_AIX) && !defined(_AIX71)
2559  RETURN_SKIP("futime is not implemented for AIX versions below 7.1");
2560 #endif
2561 
2562  /* Setup. */
2563  loop = uv_default_loop();
2564  unlink(path);
2565  r = uv_fs_open(NULL, &req, path, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR, NULL);
2566  ASSERT(r >= 0);
2567  ASSERT(req.result >= 0);
2569  uv_fs_close(loop, &req, r, NULL);
2570 
2571  atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
2572 
2573  /*
2574  * Test sub-second timestamps only on Windows (assuming NTFS). Some other
2575  * platforms support sub-second timestamps, but that support is filesystem-
2576  * dependent. Notably OS X (HFS Plus) does NOT support sub-second timestamps.
2577  */
2578 #ifdef _WIN32
2579  mtime += 0.444; /* 1982-09-10 11:22:33.444 */
2580 #endif
2581 
2582  r = uv_fs_open(NULL, &req, path, O_RDWR, 0, NULL);
2583  ASSERT(r >= 0);
2584  ASSERT(req.result >= 0);
2585  file = req.result; /* FIXME probably not how it's supposed to be used */
2587 
2588  r = uv_fs_futime(NULL, &req, file, atime, mtime, NULL);
2589 #if defined(__CYGWIN__) || defined(__MSYS__)
2590  ASSERT(r == UV_ENOSYS);
2591  RETURN_SKIP("futime not supported on Cygwin");
2592 #else
2593  ASSERT(r == 0);
2594  ASSERT(req.result == 0);
2595 #endif
2597 
2598  r = uv_fs_stat(NULL, &req, path, NULL);
2599  ASSERT(r == 0);
2600  ASSERT(req.result == 0);
2601  check_utime(path, atime, mtime, /* test_lutime */ 0);
2603 
2604  atime = mtime = 1291404900; /* 2010-12-03 20:35:00 - mees <3 */
2605 
2606  checkme.atime = atime;
2607  checkme.mtime = mtime;
2608  checkme.path = path;
2609 
2610  /* async futime */
2611  futime_req.data = &checkme;
2612  r = uv_fs_futime(loop, &futime_req, file, atime, mtime, futime_cb);
2613  ASSERT(r == 0);
2615  ASSERT(futime_cb_count == 1);
2616 
2617  /* Cleanup. */
2618  unlink(path);
2619 
2621  return 0;
2622 }
2623 
2624 
2625 TEST_IMPL(fs_lutime) {
2626  utime_check_t checkme;
2627  const char* path = "test_file";
2628  const char* symlink_path = "test_file_symlink";
2629  double atime;
2630  double mtime;
2631  uv_fs_t req;
2632  int r, s;
2633 
2634 
2635  /* Setup */
2636  loop = uv_default_loop();
2637  unlink(path);
2638  r = uv_fs_open(NULL, &req, path, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR, NULL);
2639  ASSERT(r >= 0);
2640  ASSERT(req.result >= 0);
2642  uv_fs_close(loop, &req, r, NULL);
2643 
2644  unlink(symlink_path);
2645  s = uv_fs_symlink(NULL, &req, path, symlink_path, 0, NULL);
2646 #ifdef _WIN32
2647  if (s == UV_EPERM) {
2648  /*
2649  * Creating a symlink before Windows 10 Creators Update was only allowed
2650  * when running elevated console (with admin rights)
2651  */
2652  RETURN_SKIP(
2653  "Symlink creation requires elevated console (with admin rights)");
2654  }
2655 #endif
2656  ASSERT(s == 0);
2657  ASSERT(req.result == 0);
2659 
2660  /* Test the synchronous version. */
2661  atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
2662 
2663 #ifdef _WIN32
2664  mtime += 0.444; /* 1982-09-10 11:22:33.444 */
2665 #endif
2666 
2667  checkme.atime = atime;
2668  checkme.mtime = mtime;
2669  checkme.path = symlink_path;
2670  req.data = &checkme;
2671 
2672  r = uv_fs_lutime(NULL, &req, symlink_path, atime, mtime, NULL);
2673 #if (defined(_AIX) && !defined(_AIX71)) || \
2674  defined(__MVS__)
2675  ASSERT(r == UV_ENOSYS);
2676  RETURN_SKIP("lutime is not implemented for z/OS and AIX versions below 7.1");
2677 #endif
2678  ASSERT(r == 0);
2679  lutime_cb(&req);
2680  ASSERT(lutime_cb_count == 1);
2681 
2682  /* Test the asynchronous version. */
2683  atime = mtime = 1291404900; /* 2010-12-03 20:35:00 */
2684 
2685  checkme.atime = atime;
2686  checkme.mtime = mtime;
2687  checkme.path = symlink_path;
2688 
2689  r = uv_fs_lutime(loop, &req, symlink_path, atime, mtime, lutime_cb);
2690  ASSERT(r == 0);
2692  ASSERT(lutime_cb_count == 2);
2693 
2694  /* Cleanup. */
2695  unlink(path);
2696  unlink(symlink_path);
2697 
2699  return 0;
2700 }
2701 
2702 
2703 TEST_IMPL(fs_stat_missing_path) {
2704  uv_fs_t req;
2705  int r;
2706 
2707  loop = uv_default_loop();
2708 
2709  r = uv_fs_stat(NULL, &req, "non_existent_file", NULL);
2710  ASSERT(r == UV_ENOENT);
2711  ASSERT(req.result == UV_ENOENT);
2713 
2715  return 0;
2716 }
2717 
2718 
2719 TEST_IMPL(fs_scandir_empty_dir) {
2720  const char* path;
2721  uv_fs_t req;
2722  uv_dirent_t dent;
2723  int r;
2724 
2725  path = "./empty_dir/";
2726  loop = uv_default_loop();
2727 
2728  uv_fs_mkdir(NULL, &req, path, 0777, NULL);
2730 
2731  /* Fill the req to ensure that required fields are cleaned up */
2732  memset(&req, 0xdb, sizeof(req));
2733 
2734  r = uv_fs_scandir(NULL, &req, path, 0, NULL);
2735  ASSERT(r == 0);
2736  ASSERT(req.result == 0);
2737  ASSERT(req.ptr == NULL);
2738  ASSERT(UV_EOF == uv_fs_scandir_next(&req, &dent));
2740 
2742  ASSERT(r == 0);
2743 
2744  ASSERT(scandir_cb_count == 0);
2746  ASSERT(scandir_cb_count == 1);
2747 
2748  uv_fs_rmdir(NULL, &req, path, NULL);
2750 
2752  return 0;
2753 }
2754 
2755 
2756 TEST_IMPL(fs_scandir_non_existent_dir) {
2757  const char* path;
2758  uv_fs_t req;
2759  uv_dirent_t dent;
2760  int r;
2761 
2762  path = "./non_existent_dir/";
2763  loop = uv_default_loop();
2764 
2765  uv_fs_rmdir(NULL, &req, path, NULL);
2767 
2768  /* Fill the req to ensure that required fields are cleaned up */
2769  memset(&req, 0xdb, sizeof(req));
2770 
2771  r = uv_fs_scandir(NULL, &req, path, 0, NULL);
2772  ASSERT(r == UV_ENOENT);
2773  ASSERT(req.result == UV_ENOENT);
2774  ASSERT(req.ptr == NULL);
2775  ASSERT(UV_ENOENT == uv_fs_scandir_next(&req, &dent));
2777 
2779  ASSERT(r == 0);
2780 
2781  ASSERT(scandir_cb_count == 0);
2783  ASSERT(scandir_cb_count == 1);
2784 
2786  return 0;
2787 }
2788 
2789 TEST_IMPL(fs_scandir_file) {
2790  const char* path;
2791  int r;
2792 
2793  path = "test/fixtures/empty_file";
2794  loop = uv_default_loop();
2795 
2796  r = uv_fs_scandir(NULL, &scandir_req, path, 0, NULL);
2797  ASSERT(r == UV_ENOTDIR);
2799 
2801  ASSERT(r == 0);
2802 
2803  ASSERT(scandir_cb_count == 0);
2805  ASSERT(scandir_cb_count == 1);
2806 
2808  return 0;
2809 }
2810 
2811 
2812 TEST_IMPL(fs_open_dir) {
2813  const char* path;
2814  uv_fs_t req;
2815  int r, file;
2816 
2817  path = ".";
2818  loop = uv_default_loop();
2819 
2820  r = uv_fs_open(NULL, &req, path, O_RDONLY, 0, NULL);
2821  ASSERT(r >= 0);
2822  ASSERT(req.result >= 0);
2823  ASSERT(req.ptr == NULL);
2824  file = r;
2826 
2827  r = uv_fs_close(NULL, &req, file, NULL);
2828  ASSERT(r == 0);
2829 
2830  r = uv_fs_open(loop, &req, path, O_RDONLY, 0, open_cb_simple);
2831  ASSERT(r == 0);
2832 
2833  ASSERT(open_cb_count == 0);
2835  ASSERT(open_cb_count == 1);
2836 
2838  return 0;
2839 }
2840 
2841 
2842 static void fs_file_open_append(int add_flags) {
2843  int r;
2844 
2845  /* Setup. */
2846  unlink("test_file");
2847 
2848  loop = uv_default_loop();
2849 
2850  r = uv_fs_open(NULL, &open_req1, "test_file",
2851  O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
2852  ASSERT(r >= 0);
2853  ASSERT(open_req1.result >= 0);
2855 
2856  iov = uv_buf_init(test_buf, sizeof(test_buf));
2857  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, -1, NULL);
2858  ASSERT(r >= 0);
2859  ASSERT(write_req.result >= 0);
2861 
2862  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
2863  ASSERT(r == 0);
2864  ASSERT(close_req.result == 0);
2866 
2867  r = uv_fs_open(NULL, &open_req1, "test_file",
2868  O_RDWR | O_APPEND | add_flags, 0, NULL);
2869  ASSERT(r >= 0);
2870  ASSERT(open_req1.result >= 0);
2872 
2873  iov = uv_buf_init(test_buf, sizeof(test_buf));
2874  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, -1, NULL);
2875  ASSERT(r >= 0);
2876  ASSERT(write_req.result >= 0);
2878 
2879  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
2880  ASSERT(r == 0);
2881  ASSERT(close_req.result == 0);
2883 
2884  r = uv_fs_open(NULL, &open_req1, "test_file", O_RDONLY | add_flags,
2885  S_IRUSR, NULL);
2886  ASSERT(r >= 0);
2887  ASSERT(open_req1.result >= 0);
2889 
2890  iov = uv_buf_init(buf, sizeof(buf));
2891  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
2892  printf("read = %d\n", r);
2893  ASSERT(r == 26);
2894  ASSERT(read_req.result == 26);
2895  ASSERT(memcmp(buf,
2896  "test-buffer\n\0test-buffer\n\0",
2897  sizeof("test-buffer\n\0test-buffer\n\0") - 1) == 0);
2899 
2900  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
2901  ASSERT(r == 0);
2902  ASSERT(close_req.result == 0);
2904 
2905  /* Cleanup */
2906  unlink("test_file");
2907 }
2911 
2913  return 0;
2914 }
2915 
2916 
2917 TEST_IMPL(fs_rename_to_existing_file) {
2918  int r;
2919 
2920  /* Setup. */
2921  unlink("test_file");
2922  unlink("test_file2");
2923 
2924  loop = uv_default_loop();
2925 
2926  r = uv_fs_open(NULL, &open_req1, "test_file", O_WRONLY | O_CREAT,
2927  S_IWUSR | S_IRUSR, NULL);
2928  ASSERT(r >= 0);
2929  ASSERT(open_req1.result >= 0);
2931 
2932  iov = uv_buf_init(test_buf, sizeof(test_buf));
2933  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, -1, NULL);
2934  ASSERT(r >= 0);
2935  ASSERT(write_req.result >= 0);
2937 
2938  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
2939  ASSERT(r == 0);
2940  ASSERT(close_req.result == 0);
2942 
2943  r = uv_fs_open(NULL, &open_req1, "test_file2", O_WRONLY | O_CREAT,
2944  S_IWUSR | S_IRUSR, NULL);
2945  ASSERT(r >= 0);
2946  ASSERT(open_req1.result >= 0);
2948 
2949  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
2950  ASSERT(r == 0);
2951  ASSERT(close_req.result == 0);
2953 
2954  r = uv_fs_rename(NULL, &rename_req, "test_file", "test_file2", NULL);
2955  ASSERT(r == 0);
2956  ASSERT(rename_req.result == 0);
2958 
2959  r = uv_fs_open(NULL, &open_req1, "test_file2", O_RDONLY, 0, NULL);
2960  ASSERT(r >= 0);
2961  ASSERT(open_req1.result >= 0);
2963 
2964  memset(buf, 0, sizeof(buf));
2965  iov = uv_buf_init(buf, sizeof(buf));
2966  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
2967  ASSERT(r >= 0);
2968  ASSERT(read_req.result >= 0);
2969  ASSERT(strcmp(buf, test_buf) == 0);
2971 
2972  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
2973  ASSERT(r == 0);
2974  ASSERT(close_req.result == 0);
2976 
2977  /* Cleanup */
2978  unlink("test_file");
2979  unlink("test_file2");
2980 
2982  return 0;
2983 }
2984 
2985 
2986 static void fs_read_bufs(int add_flags) {
2987  char scratch[768];
2988  uv_buf_t bufs[4];
2989 
2990  ASSERT(0 <= uv_fs_open(NULL, &open_req1,
2991  "test/fixtures/lorem_ipsum.txt",
2992  O_RDONLY | add_flags, 0, NULL));
2993  ASSERT(open_req1.result >= 0);
2995 
2996  ASSERT(UV_EINVAL == uv_fs_read(NULL, &read_req, open_req1.result,
2997  NULL, 0, 0, NULL));
2998  ASSERT(UV_EINVAL == uv_fs_read(NULL, &read_req, open_req1.result,
2999  NULL, 1, 0, NULL));
3000  ASSERT(UV_EINVAL == uv_fs_read(NULL, &read_req, open_req1.result,
3001  bufs, 0, 0, NULL));
3002 
3003  bufs[0] = uv_buf_init(scratch + 0, 256);
3004  bufs[1] = uv_buf_init(scratch + 256, 256);
3005  bufs[2] = uv_buf_init(scratch + 512, 128);
3006  bufs[3] = uv_buf_init(scratch + 640, 128);
3007 
3008  ASSERT(446 == uv_fs_read(NULL,
3009  &read_req,
3010  open_req1.result,
3011  bufs + 0,
3012  2, /* 2x 256 bytes. */
3013  0, /* Positional read. */
3014  NULL));
3015  ASSERT(read_req.result == 446);
3017 
3018  ASSERT(190 == uv_fs_read(NULL,
3019  &read_req,
3020  open_req1.result,
3021  bufs + 2,
3022  2, /* 2x 128 bytes. */
3023  256, /* Positional read. */
3024  NULL));
3025  ASSERT(read_req.result == /* 446 - 256 */ 190);
3027 
3028  ASSERT(0 == memcmp(bufs[1].base + 0, bufs[2].base, 128));
3029  ASSERT(0 == memcmp(bufs[1].base + 128, bufs[3].base, 190 - 128));
3030 
3031  ASSERT(0 == uv_fs_close(NULL, &close_req, open_req1.result, NULL));
3032  ASSERT(close_req.result == 0);
3034 }
3036  fs_read_bufs(0);
3038 
3040  return 0;
3041 }
3042 
3043 
3044 static void fs_read_file_eof(int add_flags) {
3045 #if defined(__CYGWIN__) || defined(__MSYS__)
3046  RETURN_SKIP("Cygwin pread at EOF may (incorrectly) return data!");
3047 #endif
3048  int r;
3049 
3050  /* Setup. */
3051  unlink("test_file");
3052 
3053  loop = uv_default_loop();
3054 
3055  r = uv_fs_open(NULL, &open_req1, "test_file",
3056  O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
3057  ASSERT(r >= 0);
3058  ASSERT(open_req1.result >= 0);
3060 
3061  iov = uv_buf_init(test_buf, sizeof(test_buf));
3062  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, -1, NULL);
3063  ASSERT(r >= 0);
3064  ASSERT(write_req.result >= 0);
3066 
3067  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3068  ASSERT(r == 0);
3069  ASSERT(close_req.result == 0);
3071 
3072  r = uv_fs_open(NULL, &open_req1, "test_file", O_RDONLY | add_flags, 0,
3073  NULL);
3074  ASSERT(r >= 0);
3075  ASSERT(open_req1.result >= 0);
3077 
3078  memset(buf, 0, sizeof(buf));
3079  iov = uv_buf_init(buf, sizeof(buf));
3080  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
3081  ASSERT(r >= 0);
3082  ASSERT(read_req.result >= 0);
3083  ASSERT(strcmp(buf, test_buf) == 0);
3085 
3086  iov = uv_buf_init(buf, sizeof(buf));
3087  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1,
3088  read_req.result, NULL);
3089  ASSERT(r == 0);
3090  ASSERT(read_req.result == 0);
3092 
3093  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3094  ASSERT(r == 0);
3095  ASSERT(close_req.result == 0);
3097 
3098  /* Cleanup */
3099  unlink("test_file");
3100 }
3102  fs_read_file_eof(0);
3104 
3106  return 0;
3107 }
3108 
3109 
3110 static void fs_write_multiple_bufs(int add_flags) {
3111  uv_buf_t iovs[2];
3112  int r;
3113 
3114  /* Setup. */
3115  unlink("test_file");
3116 
3117  loop = uv_default_loop();
3118 
3119  r = uv_fs_open(NULL, &open_req1, "test_file",
3120  O_WRONLY | O_CREAT | add_flags, S_IWUSR | S_IRUSR, NULL);
3121  ASSERT(r >= 0);
3122  ASSERT(open_req1.result >= 0);
3124 
3125  iovs[0] = uv_buf_init(test_buf, sizeof(test_buf));
3126  iovs[1] = uv_buf_init(test_buf2, sizeof(test_buf2));
3127  r = uv_fs_write(NULL, &write_req, open_req1.result, iovs, 2, 0, NULL);
3128  ASSERT(r >= 0);
3129  ASSERT(write_req.result >= 0);
3131 
3132  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3133  ASSERT(r == 0);
3134  ASSERT(close_req.result == 0);
3136 
3137  r = uv_fs_open(NULL, &open_req1, "test_file", O_RDONLY | add_flags, 0,
3138  NULL);
3139  ASSERT(r >= 0);
3140  ASSERT(open_req1.result >= 0);
3142 
3143  memset(buf, 0, sizeof(buf));
3144  memset(buf2, 0, sizeof(buf2));
3145  /* Read the strings back to separate buffers. */
3146  iovs[0] = uv_buf_init(buf, sizeof(test_buf));
3147  iovs[1] = uv_buf_init(buf2, sizeof(test_buf2));
3148  ASSERT(lseek(open_req1.result, 0, SEEK_CUR) == 0);
3149  r = uv_fs_read(NULL, &read_req, open_req1.result, iovs, 2, -1, NULL);
3150  ASSERT(r >= 0);
3151  ASSERT(read_req.result == sizeof(test_buf) + sizeof(test_buf2));
3152  ASSERT(strcmp(buf, test_buf) == 0);
3153  ASSERT(strcmp(buf2, test_buf2) == 0);
3155 
3156  iov = uv_buf_init(buf, sizeof(buf));
3157  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
3158  ASSERT(r == 0);
3159  ASSERT(read_req.result == 0);
3161 
3162  /* Read the strings back to separate buffers. */
3163  iovs[0] = uv_buf_init(buf, sizeof(test_buf));
3164  iovs[1] = uv_buf_init(buf2, sizeof(test_buf2));
3165  r = uv_fs_read(NULL, &read_req, open_req1.result, iovs, 2, 0, NULL);
3166  ASSERT(r >= 0);
3167  if (read_req.result == sizeof(test_buf)) {
3168  /* Infer that preadv is not available. */
3170  r = uv_fs_read(NULL, &read_req, open_req1.result, &iovs[1], 1, read_req.result, NULL);
3171  ASSERT(r >= 0);
3172  ASSERT(read_req.result == sizeof(test_buf2));
3173  } else {
3174  ASSERT(read_req.result == sizeof(test_buf) + sizeof(test_buf2));
3175  }
3176  ASSERT(strcmp(buf, test_buf) == 0);
3177  ASSERT(strcmp(buf2, test_buf2) == 0);
3179 
3180  iov = uv_buf_init(buf, sizeof(buf));
3181  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1,
3182  sizeof(test_buf) + sizeof(test_buf2), NULL);
3183  ASSERT(r == 0);
3184  ASSERT(read_req.result == 0);
3186 
3187  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3188  ASSERT(r == 0);
3189  ASSERT(close_req.result == 0);
3191 
3192  /* Cleanup */
3193  unlink("test_file");
3194 }
3198 
3200  return 0;
3201 }
3202 
3203 
3204 static void fs_write_alotof_bufs(int add_flags) {
3205  size_t iovcount;
3206  size_t iovmax;
3207  uv_buf_t* iovs;
3208  char* buffer;
3209  size_t index;
3210  int r;
3211 
3212  iovcount = 54321;
3213 
3214  /* Setup. */
3215  unlink("test_file");
3216 
3217  loop = uv_default_loop();
3218 
3219  iovs = malloc(sizeof(*iovs) * iovcount);
3220  ASSERT(iovs != NULL);
3221  iovmax = uv_test_getiovmax();
3222 
3223  r = uv_fs_open(NULL,
3224  &open_req1,
3225  "test_file",
3226  O_RDWR | O_CREAT | add_flags,
3227  S_IWUSR | S_IRUSR,
3228  NULL);
3229  ASSERT(r >= 0);
3230  ASSERT(open_req1.result >= 0);
3232 
3233  for (index = 0; index < iovcount; ++index)
3234  iovs[index] = uv_buf_init(test_buf, sizeof(test_buf));
3235 
3236  r = uv_fs_write(NULL,
3237  &write_req,
3238  open_req1.result,
3239  iovs,
3240  iovcount,
3241  -1,
3242  NULL);
3243  ASSERT(r >= 0);
3244  ASSERT((size_t)write_req.result == sizeof(test_buf) * iovcount);
3246 
3247  /* Read the strings back to separate buffers. */
3248  buffer = malloc(sizeof(test_buf) * iovcount);
3249  ASSERT(buffer != NULL);
3250 
3251  for (index = 0; index < iovcount; ++index)
3252  iovs[index] = uv_buf_init(buffer + index * sizeof(test_buf),
3253  sizeof(test_buf));
3254 
3255  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3256  ASSERT(r == 0);
3257  ASSERT(close_req.result == 0);
3259 
3260  r = uv_fs_open(NULL, &open_req1, "test_file", O_RDONLY | add_flags, 0,
3261  NULL);
3262  ASSERT(r >= 0);
3263  ASSERT(open_req1.result >= 0);
3265 
3266  r = uv_fs_read(NULL, &read_req, open_req1.result, iovs, iovcount, -1, NULL);
3267  if (iovcount > iovmax)
3268  iovcount = iovmax;
3269  ASSERT(r >= 0);
3270  ASSERT((size_t)read_req.result == sizeof(test_buf) * iovcount);
3271 
3272  for (index = 0; index < iovcount; ++index)
3273  ASSERT(strncmp(buffer + index * sizeof(test_buf),
3274  test_buf,
3275  sizeof(test_buf)) == 0);
3276 
3278  free(buffer);
3279 
3280  ASSERT(lseek(open_req1.result, write_req.result, SEEK_SET) == write_req.result);
3281  iov = uv_buf_init(buf, sizeof(buf));
3282  r = uv_fs_read(NULL,
3283  &read_req,
3284  open_req1.result,
3285  &iov,
3286  1,
3287  -1,
3288  NULL);
3289  ASSERT(r == 0);
3290  ASSERT(read_req.result == 0);
3292 
3293  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3294  ASSERT(r == 0);
3295  ASSERT(close_req.result == 0);
3297 
3298  /* Cleanup */
3299  unlink("test_file");
3300  free(iovs);
3301 }
3305 
3307  return 0;
3308 }
3309 
3310 
3311 static void fs_write_alotof_bufs_with_offset(int add_flags) {
3312  size_t iovcount;
3313  size_t iovmax;
3314  uv_buf_t* iovs;
3315  char* buffer;
3316  size_t index;
3317  int r;
3318  int64_t offset;
3319  char* filler;
3320  int filler_len;
3321 
3322  filler = "0123456789";
3323  filler_len = strlen(filler);
3324  iovcount = 54321;
3325 
3326  /* Setup. */
3327  unlink("test_file");
3328 
3329  loop = uv_default_loop();
3330 
3331  iovs = malloc(sizeof(*iovs) * iovcount);
3332  ASSERT(iovs != NULL);
3333  iovmax = uv_test_getiovmax();
3334 
3335  r = uv_fs_open(NULL,
3336  &open_req1,
3337  "test_file",
3338  O_RDWR | O_CREAT | add_flags,
3339  S_IWUSR | S_IRUSR,
3340  NULL);
3341  ASSERT(r >= 0);
3342  ASSERT(open_req1.result >= 0);
3344 
3345  iov = uv_buf_init(filler, filler_len);
3346  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, -1, NULL);
3347  ASSERT(r == filler_len);
3348  ASSERT(write_req.result == filler_len);
3350  offset = (int64_t)r;
3351 
3352  for (index = 0; index < iovcount; ++index)
3353  iovs[index] = uv_buf_init(test_buf, sizeof(test_buf));
3354 
3355  r = uv_fs_write(NULL,
3356  &write_req,
3357  open_req1.result,
3358  iovs,
3359  iovcount,
3360  offset,
3361  NULL);
3362  ASSERT(r >= 0);
3363  ASSERT((size_t)write_req.result == sizeof(test_buf) * iovcount);
3365 
3366  /* Read the strings back to separate buffers. */
3367  buffer = malloc(sizeof(test_buf) * iovcount);
3368  ASSERT(buffer != NULL);
3369 
3370  for (index = 0; index < iovcount; ++index)
3371  iovs[index] = uv_buf_init(buffer + index * sizeof(test_buf),
3372  sizeof(test_buf));
3373 
3374  r = uv_fs_read(NULL, &read_req, open_req1.result,
3375  iovs, iovcount, offset, NULL);
3376  ASSERT(r >= 0);
3377  if (r == sizeof(test_buf))
3378  iovcount = 1; /* Infer that preadv is not available. */
3379  else if (iovcount > iovmax)
3380  iovcount = iovmax;
3381  ASSERT((size_t)read_req.result == sizeof(test_buf) * iovcount);
3382 
3383  for (index = 0; index < iovcount; ++index)
3384  ASSERT(strncmp(buffer + index * sizeof(test_buf),
3385  test_buf,
3386  sizeof(test_buf)) == 0);
3387 
3389  free(buffer);
3390 
3391  r = uv_fs_stat(NULL, &stat_req, "test_file", NULL);
3392  ASSERT(r == 0);
3393  ASSERT((int64_t)((uv_stat_t*)stat_req.ptr)->st_size ==
3394  offset + (int64_t)write_req.result);
3396 
3397  iov = uv_buf_init(buf, sizeof(buf));
3398  r = uv_fs_read(NULL,
3399  &read_req,
3400  open_req1.result,
3401  &iov,
3402  1,
3403  offset + write_req.result,
3404  NULL);
3405  ASSERT(r == 0);
3406  ASSERT(read_req.result == 0);
3408 
3409  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3410  ASSERT(r == 0);
3411  ASSERT(close_req.result == 0);
3413 
3414  /* Cleanup */
3415  unlink("test_file");
3416  free(iovs);
3417 }
3421 
3423  return 0;
3424 }
3425 
3426 TEST_IMPL(fs_read_dir) {
3427  int r;
3428  char buf[2];
3429  loop = uv_default_loop();
3430 
3431  /* Setup */
3432  rmdir("test_dir");
3433  r = uv_fs_mkdir(loop, &mkdir_req, "test_dir", 0755, mkdir_cb);
3434  ASSERT(r == 0);
3436  ASSERT(mkdir_cb_count == 1);
3437  /* Setup Done Here */
3438 
3439  /* Get a file descriptor for the directory */
3440  r = uv_fs_open(loop,
3441  &open_req1,
3442  "test_dir",
3444  S_IWUSR | S_IRUSR,
3445  NULL);
3446  ASSERT(r >= 0);
3448 
3449  /* Try to read data from the directory */
3450  iov = uv_buf_init(buf, sizeof(buf));
3451  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, 0, NULL);
3452 #if defined(__FreeBSD__) || \
3453  defined(__OpenBSD__) || \
3454  defined(__NetBSD__) || \
3455  defined(__DragonFly__) || \
3456  defined(_AIX) || \
3457  defined(__sun) || \
3458  defined(__MVS__)
3459  /*
3460  * As of now, these operating systems support reading from a directory,
3461  * that too depends on the filesystem this temporary test directory is
3462  * created on. That is why this assertion is a bit lenient.
3463  */
3464  ASSERT((r >= 0) || (r == UV_EISDIR));
3465 #else
3466  ASSERT(r == UV_EISDIR);
3467 #endif
3469 
3470  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3471  ASSERT(r == 0);
3473 
3474  /* Cleanup */
3475  rmdir("test_dir");
3476 
3478  return 0;
3479 }
3480 
3481 #ifdef _WIN32
3482 
3483 TEST_IMPL(fs_partial_read) {
3484  RETURN_SKIP("Test not implemented on Windows.");
3485 }
3486 
3487 TEST_IMPL(fs_partial_write) {
3488  RETURN_SKIP("Test not implemented on Windows.");
3489 }
3490 
3491 #else /* !_WIN32 */
3492 
3493 struct thread_ctx {
3494  pthread_t pid;
3495  int fd;
3496  char* data;
3497  int size;
3499  int doread;
3500 };
3501 
3502 static void thread_main(void* arg) {
3503  const struct thread_ctx* ctx;
3504  int size;
3505  char* data;
3506 
3507  ctx = (struct thread_ctx*)arg;
3508  size = ctx->size;
3509  data = ctx->data;
3510 
3511  while (size > 0) {
3512  ssize_t result;
3513  int nbytes;
3514  nbytes = size < ctx->interval ? size : ctx->interval;
3515  if (ctx->doread) {
3516  result = write(ctx->fd, data, nbytes);
3517  /* Should not see EINTR (or other errors) */
3518  ASSERT(result == nbytes);
3519  } else {
3520  result = read(ctx->fd, data, nbytes);
3521  /* Should not see EINTR (or other errors),
3522  * but might get a partial read if we are faster than the writer
3523  */
3524  ASSERT(result > 0 && result <= nbytes);
3525  }
3526 
3527  pthread_kill(ctx->pid, SIGUSR1);
3528  size -= result;
3529  data += result;
3530  }
3531 }
3532 
3533 static void sig_func(uv_signal_t* handle, int signum) {
3535 }
3536 
3537 static size_t uv_test_fs_buf_offset(uv_buf_t* bufs, size_t size) {
3538  size_t offset;
3539  /* Figure out which bufs are done */
3540  for (offset = 0; size > 0 && bufs[offset].len <= size; ++offset)
3541  size -= bufs[offset].len;
3542 
3543  /* Fix a partial read/write */
3544  if (size > 0) {
3545  bufs[offset].base += size;
3546  bufs[offset].len -= size;
3547  }
3548  return offset;
3549 }
3550 
3551 static void test_fs_partial(int doread) {
3552  struct thread_ctx ctx;
3555  int pipe_fds[2];
3556  size_t iovcount;
3557  uv_buf_t* iovs;
3558  char* buffer;
3559  size_t index;
3560 
3561  iovcount = 54321;
3562 
3563  iovs = malloc(sizeof(*iovs) * iovcount);
3564  ASSERT(iovs != NULL);
3565 
3566  ctx.pid = pthread_self();
3567  ctx.doread = doread;
3568  ctx.interval = 1000;
3569  ctx.size = sizeof(test_buf) * iovcount;
3570  ctx.data = malloc(ctx.size);
3571  ASSERT(ctx.data != NULL);
3572  buffer = malloc(ctx.size);
3573  ASSERT(buffer != NULL);
3574 
3575  for (index = 0; index < iovcount; ++index)
3576  iovs[index] = uv_buf_init(buffer + index * sizeof(test_buf), sizeof(test_buf));
3577 
3578  loop = uv_default_loop();
3579 
3580  ASSERT(0 == uv_signal_init(loop, &signal));
3581  ASSERT(0 == uv_signal_start(&signal, sig_func, SIGUSR1));
3582 
3583  ASSERT(0 == pipe(pipe_fds));
3584 
3585  ctx.fd = pipe_fds[doread];
3587 
3588  if (doread) {
3589  uv_buf_t* read_iovs;
3590  int nread;
3591  read_iovs = iovs;
3592  nread = 0;
3593  while (nread < ctx.size) {
3594  int result;
3595  result = uv_fs_read(loop, &read_req, pipe_fds[0], read_iovs, iovcount, -1, NULL);
3596  if (result > 0) {
3597  size_t read_iovcount;
3598  read_iovcount = uv_test_fs_buf_offset(read_iovs, result);
3599  read_iovs += read_iovcount;
3600  iovcount -= read_iovcount;
3601  nread += result;
3602  } else {
3603  ASSERT(result == UV_EINTR);
3604  }
3606  }
3607  } else {
3608  int result;
3609  result = uv_fs_write(loop, &write_req, pipe_fds[1], iovs, iovcount, -1, NULL);
3610  ASSERT(write_req.result == result);
3611  ASSERT(result == ctx.size);
3613  }
3614 
3615  ASSERT(0 == memcmp(buffer, ctx.data, ctx.size));
3616 
3617  ASSERT(0 == uv_thread_join(&thread));
3618  ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
3619 
3620  ASSERT(0 == close(pipe_fds[1]));
3621  uv_close((uv_handle_t*) &signal, NULL);
3622 
3623  { /* Make sure we read everything that we wrote. */
3624  int result;
3625  result = uv_fs_read(loop, &read_req, pipe_fds[0], iovs, 1, -1, NULL);
3626  ASSERT(result == 0);
3628  }
3629  ASSERT(0 == close(pipe_fds[0]));
3630 
3631  free(iovs);
3632  free(buffer);
3633  free(ctx.data);
3634 
3636 }
3637 
3638 TEST_IMPL(fs_partial_read) {
3639  test_fs_partial(1);
3640  return 0;
3641 }
3642 
3643 TEST_IMPL(fs_partial_write) {
3644  test_fs_partial(0);
3645  return 0;
3646 }
3647 
3648 #endif/* _WIN32 */
3649 
3650 TEST_IMPL(fs_read_write_null_arguments) {
3651  int r;
3652 
3653  r = uv_fs_read(NULL, &read_req, 0, NULL, 0, -1, NULL);
3654  ASSERT(r == UV_EINVAL);
3656 
3657  r = uv_fs_write(NULL, &write_req, 0, NULL, 0, -1, NULL);
3658  /* Validate some memory management on failed input validation before sending
3659  fs work to the thread pool. */
3660  ASSERT(r == UV_EINVAL);
3661  ASSERT(write_req.path == NULL);
3662  ASSERT(write_req.ptr == NULL);
3663 #ifdef _WIN32
3664  ASSERT(write_req.file.pathw == NULL);
3665  ASSERT(write_req.fs.info.new_pathw == NULL);
3666  ASSERT(write_req.fs.info.bufs == NULL);
3667 #else
3668  ASSERT(write_req.new_path == NULL);
3669  ASSERT(write_req.bufs == NULL);
3670 #endif
3672 
3673  iov = uv_buf_init(NULL, 0);
3674  r = uv_fs_read(NULL, &read_req, 0, &iov, 0, -1, NULL);
3675  ASSERT(r == UV_EINVAL);
3677 
3678  iov = uv_buf_init(NULL, 0);
3679  r = uv_fs_write(NULL, &write_req, 0, &iov, 0, -1, NULL);
3680  ASSERT(r == UV_EINVAL);
3682 
3683  /* If the arguments are invalid, the loop should not be kept open */
3684  loop = uv_default_loop();
3685 
3686  r = uv_fs_read(loop, &read_req, 0, NULL, 0, -1, fail_cb);
3687  ASSERT(r == UV_EINVAL);
3690 
3691  r = uv_fs_write(loop, &write_req, 0, NULL, 0, -1, fail_cb);
3692  ASSERT(r == UV_EINVAL);
3695 
3696  iov = uv_buf_init(NULL, 0);
3697  r = uv_fs_read(loop, &read_req, 0, &iov, 0, -1, fail_cb);
3698  ASSERT(r == UV_EINVAL);
3701 
3702  iov = uv_buf_init(NULL, 0);
3703  r = uv_fs_write(loop, &write_req, 0, &iov, 0, -1, fail_cb);
3704  ASSERT(r == UV_EINVAL);
3707 
3708  return 0;
3709 }
3710 
3711 
3712 TEST_IMPL(get_osfhandle_valid_handle) {
3713  int r;
3714  uv_os_fd_t fd;
3715 
3716  /* Setup. */
3717  unlink("test_file");
3718 
3719  loop = uv_default_loop();
3720 
3721  r = uv_fs_open(NULL,
3722  &open_req1,
3723  "test_file",
3724  O_RDWR | O_CREAT,
3725  S_IWUSR | S_IRUSR,
3726  NULL);
3727  ASSERT(r >= 0);
3728  ASSERT(open_req1.result >= 0);
3730 
3732 #ifdef _WIN32
3734 #else
3735  ASSERT(fd >= 0);
3736 #endif
3737 
3738  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3739  ASSERT(r == 0);
3740  ASSERT(close_req.result == 0);
3742 
3743  /* Cleanup. */
3744  unlink("test_file");
3745 
3747  return 0;
3748 }
3749 
3750 TEST_IMPL(open_osfhandle_valid_handle) {
3751  int r;
3753  int fd;
3754 
3755  /* Setup. */
3756  unlink("test_file");
3757 
3758  loop = uv_default_loop();
3759 
3760  r = uv_fs_open(NULL,
3761  &open_req1,
3762  "test_file",
3763  O_RDWR | O_CREAT,
3764  S_IWUSR | S_IRUSR,
3765  NULL);
3766  ASSERT(r >= 0);
3767  ASSERT(open_req1.result >= 0);
3769 
3771 #ifdef _WIN32
3773 #else
3774  ASSERT(handle >= 0);
3775 #endif
3776 
3778 #ifdef _WIN32
3779  ASSERT(fd > 0);
3780 #else
3781  ASSERT(fd == open_req1.result);
3782 #endif
3783 
3784  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3785  ASSERT(r == 0);
3786  ASSERT(close_req.result == 0);
3788 
3789  /* Cleanup. */
3790  unlink("test_file");
3791 
3793  return 0;
3794 }
3795 
3796 TEST_IMPL(fs_file_pos_after_op_with_offset) {
3797  int r;
3798 
3799  /* Setup. */
3800  unlink("test_file");
3801  loop = uv_default_loop();
3802 
3803  r = uv_fs_open(loop,
3804  &open_req1,
3805  "test_file",
3806  O_RDWR | O_CREAT,
3807  S_IWUSR | S_IRUSR,
3808  NULL);
3809  ASSERT(r > 0);
3811 
3812  iov = uv_buf_init(test_buf, sizeof(test_buf));
3813  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, 0, NULL);
3814  ASSERT(r == sizeof(test_buf));
3815  ASSERT(lseek(open_req1.result, 0, SEEK_CUR) == 0);
3817 
3818  iov = uv_buf_init(buf, sizeof(buf));
3819  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, 0, NULL);
3820  ASSERT(r == sizeof(test_buf));
3821  ASSERT(strcmp(buf, test_buf) == 0);
3822  ASSERT(lseek(open_req1.result, 0, SEEK_CUR) == 0);
3824 
3825  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3826  ASSERT(r == 0);
3828 
3829  /* Cleanup */
3830  unlink("test_file");
3831 
3833  return 0;
3834 }
3835 
3836 #ifdef _WIN32
3837 static void fs_file_pos_common() {
3838  int r;
3839 
3840  iov = uv_buf_init("abc", 3);
3841  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, -1, NULL);
3842  ASSERT(r == 3);
3844 
3845  /* Read with offset should not change the position */
3846  iov = uv_buf_init(buf, 1);
3847  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, 1, NULL);
3848  ASSERT(r == 1);
3849  ASSERT(buf[0] == 'b');
3851 
3852  iov = uv_buf_init(buf, sizeof(buf));
3853  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
3854  ASSERT(r == 0);
3856 
3857  /* Write without offset should change the position */
3858  iov = uv_buf_init("d", 1);
3859  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, -1, NULL);
3860  ASSERT(r == 1);
3862 
3863  iov = uv_buf_init(buf, sizeof(buf));
3864  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
3865  ASSERT(r == 0);
3867 }
3868 
3869 static void fs_file_pos_close_check(const char *contents, int size) {
3870  int r;
3871 
3872  /* Close */
3873  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3874  ASSERT(r == 0);
3876 
3877  /* Confirm file contents */
3878  r = uv_fs_open(NULL, &open_req1, "test_file", O_RDONLY, 0, NULL);
3879  ASSERT(r >= 0);
3880  ASSERT(open_req1.result >= 0);
3882 
3883  iov = uv_buf_init(buf, sizeof(buf));
3884  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
3885  ASSERT(r == size);
3886  ASSERT(strncmp(buf, contents, size) == 0);
3888 
3889  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
3890  ASSERT(r == 0);
3892 
3893  /* Cleanup */
3894  unlink("test_file");
3895 }
3896 
3897 static void fs_file_pos_write(int add_flags) {
3898  int r;
3899 
3900  /* Setup. */
3901  unlink("test_file");
3902 
3903  r = uv_fs_open(NULL,
3904  &open_req1,
3905  "test_file",
3906  O_TRUNC | O_CREAT | O_RDWR | add_flags,
3907  S_IWUSR | S_IRUSR,
3908  NULL);
3909  ASSERT(r > 0);
3911 
3912  fs_file_pos_common();
3913 
3914  /* Write with offset should not change the position */
3915  iov = uv_buf_init("e", 1);
3916  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, 1, NULL);
3917  ASSERT(r == 1);
3919 
3920  iov = uv_buf_init(buf, sizeof(buf));
3921  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
3922  ASSERT(r == 0);
3924 
3925  fs_file_pos_close_check("aecd", 4);
3926 }
3927 TEST_IMPL(fs_file_pos_write) {
3928  fs_file_pos_write(0);
3929  fs_file_pos_write(UV_FS_O_FILEMAP);
3930 
3932  return 0;
3933 }
3934 
3935 static void fs_file_pos_append(int add_flags) {
3936  int r;
3937 
3938  /* Setup. */
3939  unlink("test_file");
3940 
3941  r = uv_fs_open(NULL,
3942  &open_req1,
3943  "test_file",
3944  O_APPEND | O_CREAT | O_RDWR | add_flags,
3945  S_IWUSR | S_IRUSR,
3946  NULL);
3947  ASSERT(r > 0);
3949 
3950  fs_file_pos_common();
3951 
3952  /* Write with offset appends (ignoring offset)
3953  * but does not change the position */
3954  iov = uv_buf_init("e", 1);
3955  r = uv_fs_write(NULL, &write_req, open_req1.result, &iov, 1, 1, NULL);
3956  ASSERT(r == 1);
3958 
3959  iov = uv_buf_init(buf, sizeof(buf));
3960  r = uv_fs_read(NULL, &read_req, open_req1.result, &iov, 1, -1, NULL);
3961  ASSERT(r == 1);
3962  ASSERT(buf[0] == 'e');
3964 
3965  fs_file_pos_close_check("abcde", 5);
3966 }
3967 TEST_IMPL(fs_file_pos_append) {
3968  fs_file_pos_append(0);
3969  fs_file_pos_append(UV_FS_O_FILEMAP);
3970 
3972  return 0;
3973 }
3974 #endif
3975 
3976 TEST_IMPL(fs_null_req) {
3977  /* Verify that all fs functions return UV_EINVAL when the request is NULL. */
3978  int r;
3979 
3980  r = uv_fs_open(NULL, NULL, NULL, 0, 0, NULL);
3981  ASSERT(r == UV_EINVAL);
3982 
3983  r = uv_fs_close(NULL, NULL, 0, NULL);
3984  ASSERT(r == UV_EINVAL);
3985 
3986  r = uv_fs_read(NULL, NULL, 0, NULL, 0, -1, NULL);
3987  ASSERT(r == UV_EINVAL);
3988 
3989  r = uv_fs_write(NULL, NULL, 0, NULL, 0, -1, NULL);
3990  ASSERT(r == UV_EINVAL);
3991 
3992  r = uv_fs_unlink(NULL, NULL, NULL, NULL);
3993  ASSERT(r == UV_EINVAL);
3994 
3995  r = uv_fs_mkdir(NULL, NULL, NULL, 0, NULL);
3996  ASSERT(r == UV_EINVAL);
3997 
3998  r = uv_fs_mkdtemp(NULL, NULL, NULL, NULL);
3999  ASSERT(r == UV_EINVAL);
4000 
4001  r = uv_fs_mkstemp(NULL, NULL, NULL, NULL);
4002  ASSERT(r == UV_EINVAL);
4003 
4004  r = uv_fs_rmdir(NULL, NULL, NULL, NULL);
4005  ASSERT(r == UV_EINVAL);
4006 
4007  r = uv_fs_scandir(NULL, NULL, NULL, 0, NULL);
4008  ASSERT(r == UV_EINVAL);
4009 
4010  r = uv_fs_link(NULL, NULL, NULL, NULL, NULL);
4011  ASSERT(r == UV_EINVAL);
4012 
4013  r = uv_fs_symlink(NULL, NULL, NULL, NULL, 0, NULL);
4014  ASSERT(r == UV_EINVAL);
4015 
4016  r = uv_fs_readlink(NULL, NULL, NULL, NULL);
4017  ASSERT(r == UV_EINVAL);
4018 
4019  r = uv_fs_realpath(NULL, NULL, NULL, NULL);
4020  ASSERT(r == UV_EINVAL);
4021 
4022  r = uv_fs_chown(NULL, NULL, NULL, 0, 0, NULL);
4023  ASSERT(r == UV_EINVAL);
4024 
4025  r = uv_fs_fchown(NULL, NULL, 0, 0, 0, NULL);
4026  ASSERT(r == UV_EINVAL);
4027 
4028  r = uv_fs_stat(NULL, NULL, NULL, NULL);
4029  ASSERT(r == UV_EINVAL);
4030 
4031  r = uv_fs_lstat(NULL, NULL, NULL, NULL);
4032  ASSERT(r == UV_EINVAL);
4033 
4034  r = uv_fs_fstat(NULL, NULL, 0, NULL);
4035  ASSERT(r == UV_EINVAL);
4036 
4037  r = uv_fs_rename(NULL, NULL, NULL, NULL, NULL);
4038  ASSERT(r == UV_EINVAL);
4039 
4040  r = uv_fs_fsync(NULL, NULL, 0, NULL);
4041  ASSERT(r == UV_EINVAL);
4042 
4043  r = uv_fs_fdatasync(NULL, NULL, 0, NULL);
4044  ASSERT(r == UV_EINVAL);
4045 
4046  r = uv_fs_ftruncate(NULL, NULL, 0, 0, NULL);
4047  ASSERT(r == UV_EINVAL);
4048 
4049  r = uv_fs_copyfile(NULL, NULL, NULL, NULL, 0, NULL);
4050  ASSERT(r == UV_EINVAL);
4051 
4052  r = uv_fs_sendfile(NULL, NULL, 0, 0, 0, 0, NULL);
4053  ASSERT(r == UV_EINVAL);
4054 
4055  r = uv_fs_access(NULL, NULL, NULL, 0, NULL);
4056  ASSERT(r == UV_EINVAL);
4057 
4058  r = uv_fs_chmod(NULL, NULL, NULL, 0, NULL);
4059  ASSERT(r == UV_EINVAL);
4060 
4061  r = uv_fs_fchmod(NULL, NULL, 0, 0, NULL);
4062  ASSERT(r == UV_EINVAL);
4063 
4064  r = uv_fs_utime(NULL, NULL, NULL, 0.0, 0.0, NULL);
4065  ASSERT(r == UV_EINVAL);
4066 
4067  r = uv_fs_futime(NULL, NULL, 0, 0.0, 0.0, NULL);
4068  ASSERT(r == UV_EINVAL);
4069 
4070  r = uv_fs_statfs(NULL, NULL, NULL, NULL);
4071  ASSERT(r == UV_EINVAL);
4072 
4073  /* This should be a no-op. */
4074  uv_fs_req_cleanup(NULL);
4075 
4076  return 0;
4077 }
4078 
4079 #ifdef _WIN32
4080 TEST_IMPL(fs_exclusive_sharing_mode) {
4081  int r;
4082 
4083  /* Setup. */
4084  unlink("test_file");
4085 
4086  ASSERT(UV_FS_O_EXLOCK > 0);
4087 
4088  r = uv_fs_open(NULL,
4089  &open_req1,
4090  "test_file",
4091  O_RDWR | O_CREAT | UV_FS_O_EXLOCK,
4092  S_IWUSR | S_IRUSR,
4093  NULL);
4094  ASSERT(r >= 0);
4095  ASSERT(open_req1.result >= 0);
4097 
4098  r = uv_fs_open(NULL,
4099  &open_req2,
4100  "test_file",
4101  O_RDONLY | UV_FS_O_EXLOCK,
4102  S_IWUSR | S_IRUSR,
4103  NULL);
4104  ASSERT(r < 0);
4105  ASSERT(open_req2.result < 0);
4107 
4108  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
4109  ASSERT(r == 0);
4110  ASSERT(close_req.result == 0);
4112 
4113  r = uv_fs_open(NULL,
4114  &open_req2,
4115  "test_file",
4116  O_RDONLY | UV_FS_O_EXLOCK,
4117  S_IWUSR | S_IRUSR,
4118  NULL);
4119  ASSERT(r >= 0);
4120  ASSERT(open_req2.result >= 0);
4122 
4123  r = uv_fs_close(NULL, &close_req, open_req2.result, NULL);
4124  ASSERT(r == 0);
4125  ASSERT(close_req.result == 0);
4127 
4128  /* Cleanup */
4129  unlink("test_file");
4130 
4132  return 0;
4133 }
4134 #endif
4135 
4136 #ifdef _WIN32
4137 TEST_IMPL(fs_file_flag_no_buffering) {
4138  int r;
4139 
4140  /* Setup. */
4141  unlink("test_file");
4142 
4143  ASSERT(UV_FS_O_APPEND > 0);
4144  ASSERT(UV_FS_O_CREAT > 0);
4145  ASSERT(UV_FS_O_DIRECT > 0);
4146  ASSERT(UV_FS_O_RDWR > 0);
4147 
4148  /* FILE_APPEND_DATA must be excluded from FILE_GENERIC_WRITE: */
4149  r = uv_fs_open(NULL,
4150  &open_req1,
4151  "test_file",
4153  S_IWUSR | S_IRUSR,
4154  NULL);
4155  ASSERT(r >= 0);
4156  ASSERT(open_req1.result >= 0);
4158 
4159  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
4160  ASSERT(r == 0);
4161  ASSERT(close_req.result == 0);
4163 
4164  /* FILE_APPEND_DATA and FILE_FLAG_NO_BUFFERING are mutually exclusive: */
4165  r = uv_fs_open(NULL,
4166  &open_req2,
4167  "test_file",
4169  S_IWUSR | S_IRUSR,
4170  NULL);
4171  ASSERT(r == UV_EINVAL);
4172  ASSERT(open_req2.result == UV_EINVAL);
4174 
4175  /* Cleanup */
4176  unlink("test_file");
4177 
4179  return 0;
4180 }
4181 #endif
4182 
4183 #ifdef _WIN32
4184 int call_icacls(const char* command, ...) {
4185  char icacls_command[1024];
4186  va_list args;
4187 
4188  va_start(args, command);
4189  vsnprintf(icacls_command, ARRAYSIZE(icacls_command), command, args);
4190  va_end(args);
4191  return system(icacls_command);
4192 }
4193 
4194 TEST_IMPL(fs_open_readonly_acl) {
4195  uv_passwd_t pwd;
4196  uv_fs_t req;
4197  int r;
4198 
4199  /*
4200  Based on Node.js test from
4201  https://github.com/nodejs/node/commit/3ba81e34e86a5c32658e218cb6e65b13e8326bc5
4202 
4203  If anything goes wrong, you can delte the test_fle_icacls with:
4204 
4205  icacls test_file_icacls /remove "%USERNAME%" /inheritance:e
4206  attrib -r test_file_icacls
4207  del test_file_icacls
4208  */
4209 
4210  /* Setup - clear the ACL and remove the file */
4211  loop = uv_default_loop();
4212  r = uv_os_get_passwd(&pwd);
4213  ASSERT(r == 0);
4214  call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e",
4215  pwd.username);
4216  uv_fs_chmod(loop, &req, "test_file_icacls", S_IWUSR, NULL);
4217  unlink("test_file_icacls");
4218 
4219  /* Create the file */
4220  r = uv_fs_open(loop,
4221  &open_req1,
4222  "test_file_icacls",
4223  O_RDONLY | O_CREAT,
4224  S_IRUSR,
4225  NULL);
4226  ASSERT(r >= 0);
4227  ASSERT(open_req1.result >= 0);
4229  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
4230  ASSERT(r == 0);
4231  ASSERT(close_req.result == 0);
4233 
4234  /* Set up ACL */
4235  r = call_icacls("icacls test_file_icacls /inheritance:r /remove \"%s\"",
4236  pwd.username);
4237  if (r != 0) {
4238  goto acl_cleanup;
4239  }
4240  r = call_icacls("icacls test_file_icacls /grant \"%s\":RX", pwd.username);
4241  if (r != 0) {
4242  goto acl_cleanup;
4243  }
4244 
4245  /* Try opening the file */
4246  r = uv_fs_open(NULL, &open_req1, "test_file_icacls", O_RDONLY, 0, NULL);
4247  if (r < 0) {
4248  goto acl_cleanup;
4249  }
4251  r = uv_fs_close(NULL, &close_req, open_req1.result, NULL);
4252  if (r != 0) {
4253  goto acl_cleanup;
4254  }
4256 
4257  acl_cleanup:
4258  /* Cleanup */
4259  call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e",
4260  pwd.username);
4261  unlink("test_file_icacls");
4262  uv_os_free_passwd(&pwd);
4263  ASSERT(r == 0);
4265  return 0;
4266 }
4267 #endif
4268 
4269 #ifdef _WIN32
4270 TEST_IMPL(fs_fchmod_archive_readonly) {
4271  uv_fs_t req;
4272  uv_file file;
4273  int r;
4274  /* Test clearing read-only flag from files with Archive flag cleared */
4275 
4276  /* Setup*/
4277  unlink("test_file");
4278  r = uv_fs_open(NULL,
4279  &req,
4280  "test_file",
4281  O_WRONLY | O_CREAT,
4282  S_IWUSR | S_IRUSR,
4283  NULL);
4284  ASSERT(r >= 0);
4285  ASSERT(req.result >= 0);
4286  file = req.result;
4288  r = uv_fs_close(NULL, &req, file, NULL);
4289  ASSERT(r == 0);
4291  /* Make the file read-only and clear archive flag */
4292  r = SetFileAttributes("test_file", FILE_ATTRIBUTE_READONLY);
4293  ASSERT(r != 0);
4294  check_permission("test_file", 0400);
4295  /* Try fchmod */
4296  r = uv_fs_open(NULL, &req, "test_file", O_RDONLY, 0, NULL);
4297  ASSERT(r >= 0);
4298  ASSERT(req.result >= 0);
4299  file = req.result;
4301  r = uv_fs_fchmod(NULL, &req, file, S_IWUSR, NULL);
4302  ASSERT(r == 0);
4303  ASSERT(req.result == 0);
4305  r = uv_fs_close(NULL, &req, file, NULL);
4306  ASSERT(r == 0);
4308  check_permission("test_file", S_IWUSR);
4309 
4310  /* Restore Archive flag for rest of the tests */
4311  r = SetFileAttributes("test_file", FILE_ATTRIBUTE_ARCHIVE);
4312  ASSERT(r != 0);
4313 
4314  return 0;
4315 }
4316 
4317 TEST_IMPL(fs_invalid_mkdir_name) {
4318  uv_loop_t* loop;
4319  uv_fs_t req;
4320  int r;
4321 
4322  loop = uv_default_loop();
4323  r = uv_fs_mkdir(loop, &req, "invalid>", 0, NULL);
4324  ASSERT(r == UV_EINVAL);
4325 
4326  return 0;
4327 }
4328 #endif
4329 
4330 TEST_IMPL(fs_statfs) {
4331  uv_fs_t req;
4332  int r;
4333 
4334  loop = uv_default_loop();
4335 
4336  /* Test the synchronous version. */
4337  r = uv_fs_statfs(NULL, &req, ".", NULL);
4338  ASSERT(r == 0);
4339  statfs_cb(&req);
4340  ASSERT(statfs_cb_count == 1);
4341 
4342  /* Test the asynchronous version. */
4343  r = uv_fs_statfs(loop, &req, ".", statfs_cb);
4344  ASSERT(r == 0);
4346  ASSERT(statfs_cb_count == 2);
4347 
4348  return 0;
4349 }
UV_FS_FCHOWN
@ UV_FS_FCHOWN
Definition: uv.h:1274
read_cb_count
static int read_cb_count
Definition: test-fs.c:71
uv_os_free_passwd
UV_EXTERN void uv_os_free_passwd(uv_passwd_t *pwd)
Definition: unix/core.c:1223
rename_cb_count
static int rename_cb_count
Definition: test-fs.c:80
UV_DIRENT_LINK
@ UV_DIRENT_LINK
Definition: uv.h:1132
setup
Definition: setup.py:1
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
uv_fs_access
UV_EXTERN int uv_fs_access(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb)
Definition: unix/fs.c:1613
uv_fs_rmdir
UV_EXTERN int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
Definition: unix/fs.c:1931
uv_fs_s::statbuf
uv_stat_t statbuf
Definition: uv.h:1302
open_cb_simple
static void open_cb_simple(uv_fs_t *req)
Definition: test-fs.c:446
file_scandir_cb
static void file_scandir_cb(uv_fs_t *req)
Definition: test-fs.c:656
UV_FS_UTIME
@ UV_FS_UTIME
Definition: uv.h:1257
utime_check_t::path
const char * path
Definition: test-fs.c:61
filename
const char * filename
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
futime_cb_count
static int futime_cb_count
Definition: test-fs.c:97
vsnprintf
int __cdecl vsnprintf(char *buffer, size_t count, const char *format, va_list argptr)
Definition: libc.cpp:135
empty_scandir_cb
static void empty_scandir_cb(uv_fs_t *req)
Definition: test-fs.c:631
UV_FS_CLOSE
@ UV_FS_CLOSE
Definition: uv.h:1249
dummy_cb_count
static int dummy_cb_count
Definition: test-fs.c:67
read_req
static uv_fs_t read_req
Definition: test-fs.c:105
unlink_req
static uv_fs_t unlink_req
Definition: test-fs.c:107
fsync_cb
static void fsync_cb(uv_fs_t *req)
Definition: test-fs.c:458
UV_FS_READ
@ UV_FS_READ
Definition: uv.h:1250
uv_fs_open
UV_EXTERN int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb)
Definition: unix/fs.c:1812
task.h
ctx
Definition: benchmark-async.c:30
uv_passwd_s
Definition: uv.h:1099
uv_fs_symlink
UV_EXTERN int uv_fs_symlink(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, uv_fs_cb cb)
Definition: unix/fs.c:1961
rmdir
#define rmdir
Definition: test-fs.c:45
fs_write_alotof_bufs_with_offset
static void fs_write_alotof_bufs_with_offset(int add_flags)
Definition: test-fs.c:3311
test_buf
static char test_buf[]
Definition: test-fs.c:128
uv_fs_copyfile
UV_EXTERN int uv_fs_copyfile(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, uv_fs_cb cb)
Definition: unix/fs.c:2057
memset
return memset(p, 0, total)
create_cb_count
static int create_cb_count
Definition: test-fs.c:69
file
const grpc_generator::File * file
Definition: python_private_generator.h:38
utime_req
static uv_fs_t utime_req
Definition: test-fs.c:123
test_symlink_dir_impl
int test_symlink_dir_impl(int type)
Definition: test-fs.c:2195
futime_req
static uv_fs_t futime_req
Definition: test-fs.c:124
futime_cb
static void futime_cb(uv_fs_t *req)
Definition: test-fs.c:850
sig_func
static void sig_func(uv_signal_t *handle, int signum)
Definition: test-fs.c:3533
UV_FS_MKDTEMP
@ UV_FS_MKDTEMP
Definition: uv.h:1267
UV_DIRENT_FILE
@ UV_DIRENT_FILE
Definition: uv.h:1130
utime_check_t::atime
double atime
Definition: test-fs.c:62
write
#define write
Definition: test-fs.c:47
SEEK_CUR
#define SEEK_CUR
Definition: bloaty/third_party/zlib/contrib/minizip/zip.c:80
uv_passwd_s::username
char * username
Definition: uv.h:1100
rmdir_cb
static void rmdir_cb(uv_fs_t *req)
Definition: test-fs.c:579
thread_ctx::interval
int interval
Definition: test-fs.c:3498
uv_fs_stat
UV_EXTERN int uv_fs_stat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
Definition: unix/fs.c:1954
mkdtemp_cb_count
static int mkdtemp_cb_count
Definition: test-fs.c:75
readlink_cb_count
static int readlink_cb_count
Definition: test-fs.c:94
uv_signal_init
UV_EXTERN int uv_signal_init(uv_loop_t *loop, uv_signal_t *handle)
Definition: unix/signal.c:317
string.h
uv_os_get_passwd
UV_EXTERN int uv_os_get_passwd(uv_passwd_t *pwd)
Definition: unix/core.c:1239
uv_fs_sendfile
UV_EXTERN int uv_fs_sendfile(uv_loop_t *loop, uv_fs_t *req, uv_file out_fd, uv_file in_fd, int64_t in_offset, size_t length, uv_fs_cb cb)
Definition: unix/fs.c:1938
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
UV_FS_MKSTEMP
@ UV_FS_MKSTEMP
Definition: uv.h:1282
chmod_cb_count
static int chmod_cb_count
Definition: test-fs.c:87
stat_cb_count
static int stat_cb_count
Definition: test-fs.c:79
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
mkstemp_cb
static void mkstemp_cb(uv_fs_t *req)
Definition: test-fs.c:572
link_cb_count
static int link_cb_count
Definition: test-fs.c:92
UV_FS_O_FILEMAP
#define UV_FS_O_FILEMAP
Definition: unix.h:499
scandir_cb
static void scandir_cb(uv_fs_t *req)
Definition: test-fs.c:612
uv_fs_lutime
UV_EXTERN int uv_fs_lutime(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, double mtime, uv_fs_cb cb)
Definition: unix/fs.c:1744
uv_fs_readlink
UV_EXTERN int uv_fs_readlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
Definition: unix/fs.c:1900
fchown_cb
static void fchown_cb(uv_fs_t *req)
Definition: test-fs.c:276
UV_FS_FSYNC
@ UV_FS_FSYNC
Definition: uv.h:1262
dummy_cb
static void dummy_cb(uv_fs_t *req)
Definition: test-fs.c:192
ASSERT
#define ASSERT(expr)
Definition: task.h:102
fchown_cb_count
static int fchown_cb_count
Definition: test-fs.c:90
UV_FS_LCHOWN
@ UV_FS_LCHOWN
Definition: uv.h:1277
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
stat_cb
static void stat_cb(uv_fs_t *req)
Definition: test-fs.c:666
UV_FS_O_EXLOCK
#define UV_FS_O_EXLOCK
Definition: unix.h:445
UV_FS_O_RDONLY
#define UV_FS_O_RDONLY
Definition: unix.h:470
thread_main
static void thread_main(void *arg)
Definition: test-fs.c:3502
uv_fs_s::path
const char * path
Definition: uv.h:1301
fdatasync_req
static uv_fs_t fdatasync_req
Definition: test-fs.c:120
mode
const char int mode
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
ctx
static struct test_ctx ctx
Definition: test-ipc-send-recv.c:65
utime_cb
static void utime_cb(uv_fs_t *req)
Definition: test-fs.c:835
setup.name
name
Definition: setup.py:542
uv_fs_cb
void(* uv_fs_cb)(uv_fs_t *req)
Definition: uv.h:325
uv_thread_join
UV_EXTERN int uv_thread_join(uv_thread_t *tid)
Definition: libuv/src/unix/thread.c:271
write_req
Definition: benchmark-tcp-write-batch.c:31
lchown_cb_count
static int lchown_cb_count
Definition: test-fs.c:91
check_documentation.path
path
Definition: check_documentation.py:57
UV_FS_O_CREAT
#define UV_FS_O_CREAT
Definition: unix.h:406
rmdir_req
static uv_fs_t rmdir_req
Definition: test-fs.c:115
open_noent_cb
static void open_noent_cb(uv_fs_t *req)
Definition: test-fs.c:695
fstat_cb_count
static int fstat_cb_count
Definition: test-fs.c:85
UV_FS_FTRUNCATE
@ UV_FS_FTRUNCATE
Definition: uv.h:1256
chmod_cb
static void chmod_cb(uv_fs_t *req)
Definition: test-fs.c:267
fs_write_multiple_bufs
static void fs_write_multiple_bufs(int add_flags)
Definition: test-fs.c:3110
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
UV_FS_READLINK
@ UV_FS_READLINK
Definition: uv.h:1272
UV_FS_UNLINK
@ UV_FS_UNLINK
Definition: uv.h:1264
utime_check_t::mtime
double mtime
Definition: test-fs.c:63
mkdir_cb
static void mkdir_cb(uv_fs_t *req)
Definition: test-fs.c:516
uv_fs_s::result
ssize_t result
Definition: uv.h:1299
uv_fs_s
Definition: uv.h:1294
close_cb
static void close_cb(uv_fs_t *req)
Definition: test-fs.c:378
uv_fs_mkdir
UV_EXTERN int uv_fs_mkdir(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb)
Definition: unix/fs.c:1776
mkstemp_req3
static uv_fs_t mkstemp_req3
Definition: test-fs.c:114
non_existent_scandir_cb
static void non_existent_scandir_cb(uv_fs_t *req)
Definition: test-fs.c:643
sendfile_req
static uv_fs_t sendfile_req
Definition: test-fs.c:122
UV_FS_FUTIME
@ UV_FS_FUTIME
Definition: uv.h:1258
uv_fs_futime
UV_EXTERN int uv_fs_futime(uv_loop_t *loop, uv_fs_t *req, uv_file file, double atime, double mtime, uv_fs_cb cb)
Definition: unix/fs.c:1731
S_IFLNK
#define S_IFLNK
Definition: win.h:68
python_utils.port_server.stderr
stderr
Definition: port_server.py:51
uv_close
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: unix/core.c:112
assert_is_file_type
static void assert_is_file_type(uv_dirent_t dent)
Definition: test-fs.c:590
UV_FS_O_RDWR
#define UV_FS_O_RDWR
Definition: unix.h:475
rename_cb
static void rename_cb(uv_fs_t *req)
Definition: test-fs.c:507
uv_fs_statfs
UV_EXTERN int uv_fs_statfs(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
Definition: unix/fs.c:2077
fail_cb
static void fail_cb(uv_fs_t *req)
Definition: test-fs.c:403
uv_fs_unlink
UV_EXTERN int uv_fs_unlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
Definition: unix/fs.c:1974
chown_cb
static void chown_cb(uv_fs_t *req)
Definition: test-fs.c:284
UV_FS_O_DIRECTORY
#define UV_FS_O_DIRECTORY
Definition: unix.h:430
UV_FS_O_APPEND
#define UV_FS_O_APPEND
Definition: unix.h:401
ftruncate_cb
static void ftruncate_cb(uv_fs_t *req)
Definition: test-fs.c:392
UV_FS_STAT
@ UV_FS_STAT
Definition: uv.h:1253
rmdir_cb_count
static int rmdir_cb_count
Definition: test-fs.c:77
uv_test_fs_buf_offset
static size_t uv_test_fs_buf_offset(uv_buf_t *bufs, size_t size)
Definition: test-fs.c:3537
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:733
symlink_cb
static void symlink_cb(uv_fs_t *req)
Definition: test-fs.c:206
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
uv_fs_mkstemp
UV_EXTERN int uv_fs_mkstemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb)
Definition: unix/fs.c:1800
UV_FS_CHMOD
@ UV_FS_CHMOD
Definition: uv.h:1260
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
ssize_t
intptr_t ssize_t
Definition: win.h:27
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
unlink_cb
static void unlink_cb(uv_fs_t *req)
Definition: test-fs.c:327
fdatasync_cb
static void fdatasync_cb(uv_fs_t *req)
Definition: test-fs.c:470
read_cb
static void read_cb(uv_fs_t *req)
Definition: test-fs.c:407
open_cb_count
static int open_cb_count
Definition: test-fs.c:70
uv_fs_mkdtemp
UV_EXTERN int uv_fs_mkdtemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb)
Definition: unix/fs.c:1788
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
write_cb
static void write_cb(uv_fs_t *req)
Definition: test-fs.c:482
signal
static void signal(notification *n)
Definition: alts_tsi_handshaker_test.cc:107
PATHMAX
#define PATHMAX
Definition: test-fs.c:58
req
static uv_connect_t req
Definition: test-connection-fail.c:30
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
chown_root_cb
static void chown_root_cb(uv_fs_t *req)
Definition: test-fs.c:298
ERROR_SYMLINK_NOT_SUPPORTED
#define ERROR_SYMLINK_NOT_SUPPORTED
Definition: test-fs.c:42
chown_cb_count
static int chown_cb_count
Definition: test-fs.c:89
open_req2
static uv_fs_t open_req2
Definition: test-fs.c:104
uv_stat_t::st_mode
uint64_t st_mode
Definition: uv.h:348
unlink
#define unlink
Definition: test-fs.c:44
test_fs_partial
static void test_fs_partial(int doread)
Definition: test-fs.c:3551
gen_stats_data.stats
list stats
Definition: gen_stats_data.py:58
sendfile_nodata_cb
static void sendfile_nodata_cb(uv_fs_t *req)
Definition: test-fs.c:686
uv_cwd
UV_EXTERN int uv_cwd(char *buffer, size_t *size)
Definition: unix/core.c:696
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
pipe_fds
int pipe_fds[2]
Definition: test-eintr-handling.c:42
uv_dirent_s::name
const char * name
Definition: uv.h:1140
test_buf2
static char test_buf2[]
Definition: test-fs.c:129
uv_fs_fsync
UV_EXTERN int uv_fs_fsync(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
Definition: unix/fs.c:1712
close_req
static uv_fs_t close_req
Definition: test-fs.c:108
mkstemp_cb_count
static int mkstemp_cb_count
Definition: test-fs.c:76
arg
Definition: cmdline.cc:40
symlink_cb_count
static int symlink_cb_count
Definition: test-fs.c:93
uv_fs_fchmod
UV_EXTERN int uv_fs_fchmod(uv_loop_t *loop, uv_fs_t *req, uv_file file, int mode, uv_fs_cb cb)
Definition: unix/fs.c:1658
uv_dirent_s::type
uv_dirent_type_t type
Definition: uv.h:1141
close
#define close
Definition: test-fs.c:48
UV_FS_SYMLINK_DIR
#define UV_FS_SYMLINK_DIR
Definition: uv.h:1476
UV_FS_LINK
@ UV_FS_LINK
Definition: uv.h:1270
write_req
static uv_fs_t write_req
Definition: test-fs.c:106
fs_file_write_null_buffer
static void fs_file_write_null_buffer(int add_flags)
Definition: test-fs.c:1032
uv_fs_fdatasync
UV_EXTERN int uv_fs_fdatasync(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
Definition: unix/fs.c:1698
gen_synthetic_protos.base
base
Definition: gen_synthetic_protos.py:31
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
uv_thread_create
UV_EXTERN int uv_thread_create(uv_thread_t *tid, uv_thread_cb entry, void *arg)
Definition: libuv/src/unix/thread.c:209
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
check_utime
static void check_utime(const char *path, double atime, double mtime, int test_lutime)
Definition: test-fs.c:810
stat_req
static uv_fs_t stat_req
Definition: test-fs.c:117
uv_file
int uv_file
Definition: unix.h:126
create_cb
static void create_cb(uv_fs_t *req)
Definition: test-fs.c:494
statfs_cb
static void statfs_cb(uv_fs_t *req)
Definition: test-fs.c:345
UV_FS_SYMLINK_JUNCTION
#define UV_FS_SYMLINK_JUNCTION
Definition: uv.h:1482
uv_signal_stop
UV_EXTERN int uv_signal_stop(uv_signal_t *handle)
Definition: unix/signal.c:511
fs_file_sync
static void fs_file_sync(int add_flags)
Definition: test-fs.c:942
uv_fs_close
UV_EXTERN int uv_fs_close(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
Definition: unix/fs.c:1651
lutime_cb
static void lutime_cb(uv_fs_t *req)
Definition: test-fs.c:865
uv_get_osfhandle
UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd)
Definition: unix/core.c:1384
fs_file_open_append
static void fs_file_open_append(int add_flags)
Definition: test-fs.c:2842
fchmod_cb_count
static int fchmod_cb_count
Definition: test-fs.c:88
access_cb_count
static int access_cb_count
Definition: test-fs.c:86
UV_FS_LSTAT
@ UV_FS_LSTAT
Definition: uv.h:1254
uv_fs_scandir
UV_EXTERN int uv_fs_scandir(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb)
Definition: unix/fs.c:1854
uv_buf_t::base
char * base
Definition: unix.h:122
fdatasync_cb_count
static int fdatasync_cb_count
Definition: test-fs.c:82
uv_fs_utime
UV_EXTERN int uv_fs_utime(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, double mtime, uv_fs_cb cb)
Definition: unix/fs.c:1981
fs_write_alotof_bufs
static void fs_write_alotof_bufs(int add_flags)
Definition: test-fs.c:3204
iov
static uv_buf_t iov
Definition: test-fs.c:130
thread_ctx
Definition: libuv/src/win/thread.c:90
uv_fs_chmod
UV_EXTERN int uv_fs_chmod(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb)
Definition: unix/fs.c:1625
uv_fs_read
UV_EXTERN int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Definition: unix/fs.c:1826
bufs
static uv_buf_t bufs[5]
Definition: benchmark-udp-pummel.c:51
uv.h
close_cb_count
static int close_cb_count
Definition: test-fs.c:68
realpath_cb_count
static int realpath_cb_count
Definition: test-fs.c:95
MAKE_VALGRIND_HAPPY
#define MAKE_VALGRIND_HAPPY()
Definition: task.h:229
uv_statfs_s
Definition: uv.h:1117
uv_dirent_s
Definition: uv.h:1139
link_cb
static void link_cb(uv_fs_t *req)
Definition: test-fs.c:198
FATAL
#define FATAL(msg)
Definition: task.h:88
readlink_cb
static void readlink_cb(uv_fs_t *req)
Definition: test-fs.c:213
fchmod_cb
static void fchmod_cb(uv_fs_t *req)
Definition: test-fs.c:258
uv_fs_ftruncate
UV_EXTERN int uv_fs_ftruncate(uv_loop_t *loop, uv_fs_t *req, uv_file file, int64_t offset, uv_fs_cb cb)
Definition: unix/fs.c:1719
UV_FS_FCHMOD
@ UV_FS_FCHMOD
Definition: uv.h:1261
loop
static uv_loop_t * loop
Definition: test-fs.c:101
uv_fs_fchown
UV_EXTERN int uv_fs_fchown(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_uid_t uid, uv_gid_t gid, uv_fs_cb cb)
Definition: unix/fs.c:1670
uv_signal_s
Definition: uv.h:1561
contents
string_view contents
Definition: elf.cc:597
uv_buf_t
Definition: unix.h:121
mkdir_req
static uv_fs_t mkdir_req
Definition: test-fs.c:109
UV_FS_ACCESS
@ UV_FS_ACCESS
Definition: uv.h:1259
read
int read(izstream &zs, T *x, Items items)
Definition: bloaty/third_party/zlib/contrib/iostream2/zstream.h:115
UV_FS_WRITE
@ UV_FS_WRITE
Definition: uv.h:1251
fsync_cb_count
static int fsync_cb_count
Definition: test-fs.c:81
scratch
static char scratch[256]
Definition: test-random.c:27
uv_stat_t
Definition: uv.h:346
lseek
#define lseek
Definition: test-fs.c:53
uv_os_fd_t
int uv_os_fd_t
Definition: unix.h:128
fsync_req
static uv_fs_t fsync_req
Definition: test-fs.c:119
lchown_cb
static void lchown_cb(uv_fs_t *req)
Definition: test-fs.c:291
UV_FS_LUTIME
@ UV_FS_LUTIME
Definition: uv.h:1283
mkdtemp_cb
static void mkdtemp_cb(uv_fs_t *req)
Definition: test-fs.c:546
thread_ctx::doread
int doread
Definition: test-fs.c:3499
UV_FS_CHOWN
@ UV_FS_CHOWN
Definition: uv.h:1273
statfs_cb_count
static int statfs_cb_count
Definition: test-fs.c:99
uv_fs_write
UV_EXTERN int uv_fs_write(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Definition: unix/fs.c:1995
FSCTL_SET_REPARSE_POINT
#define FSCTL_SET_REPARSE_POINT
Definition: winapi.h:4497
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
F_OK
#define F_OK
Definition: win.h:655
utime_cb_count
static int utime_cb_count
Definition: test-fs.c:96
mkdtemp_req2
static uv_fs_t mkdtemp_req2
Definition: test-fs.c:111
fix_build_deps.r
r
Definition: fix_build_deps.py:491
open_cb
static void open_cb(uv_fs_t *req)
Definition: test-fs.c:426
uv_fs_link
UV_EXTERN int uv_fs_link(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, uv_fs_cb cb)
Definition: unix/fs.c:1765
rename_req
static uv_fs_t rename_req
Definition: test-fs.c:118
W_OK
#define W_OK
Definition: win.h:661
ftruncate_req
static uv_fs_t ftruncate_req
Definition: test-fs.c:121
uv_fs_chown
UV_EXTERN int uv_fs_chown(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_uid_t uid, uv_gid_t gid, uv_fs_cb cb)
Definition: unix/fs.c:1637
INVALID_HANDLE_VALUE
#define INVALID_HANDLE_VALUE
Definition: bloaty/third_party/zlib/contrib/minizip/iowin32.c:21
UV_FS_SENDFILE
@ UV_FS_SENDFILE
Definition: uv.h:1252
thread_ctx::data
char * data
Definition: test-fs.c:3496
UV_FS_FDATASYNC
@ UV_FS_FDATASYNC
Definition: uv.h:1263
uv_fs_rename
UV_EXTERN int uv_fs_rename(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, uv_fs_cb cb)
Definition: unix/fs.c:1920
uv_buf_init
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157
sendfile_cb
static void sendfile_cb(uv_fs_t *req)
Definition: test-fs.c:677
buf2
static char buf2[32]
Definition: test-fs.c:127
uv_buf_t::len
size_t len
Definition: unix.h:123
UV_FS_OPEN
@ UV_FS_OPEN
Definition: uv.h:1248
uv_fs_realpath
UV_EXTERN int uv_fs_realpath(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
Definition: unix/fs.c:1910
check_mkdtemp_result
static void check_mkdtemp_result(uv_fs_t *req)
Definition: test-fs.c:527
UV_FS_SCANDIR
@ UV_FS_SCANDIR
Definition: uv.h:1269
UV_FS_RMDIR
@ UV_FS_RMDIR
Definition: uv.h:1265
uv_fs_req_cleanup
UV_EXTERN void uv_fs_req_cleanup(uv_fs_t *req)
Definition: unix/fs.c:2024
open_loop_cb
static void open_loop_cb(uv_fs_t *req)
Definition: test-fs.c:709
thread_ctx::fd
int fd
Definition: test-eintr-handling.c:46
fstat_cb
static void fstat_cb(uv_fs_t *req)
Definition: test-fs.c:335
UV_FS_SYMLINK
@ UV_FS_SYMLINK
Definition: uv.h:1271
thread_ctx::size
int size
Definition: test-fs.c:3497
RETURN_SKIP
#define RETURN_SKIP(explanation)
Definition: task.h:262
mkstemp_req2
static uv_fs_t mkstemp_req2
Definition: test-fs.c:113
open
#define open
Definition: test-fs.c:46
UV_FS_O_DIRECT
#define UV_FS_O_DIRECT
Definition: unix.h:424
check_mkstemp_result
static void check_mkstemp_result(uv_fs_t *req)
Definition: test-fs.c:553
thread_ctx::pid
pthread_t pid
Definition: test-fs.c:3494
stat
#define stat
Definition: test-fs.c:50
scandir_cb_count
static int scandir_cb_count
Definition: test-fs.c:78
TEST_IMPL
TEST_IMPL(fs_file_noent)
Definition: test-fs.c:717
handle
static csh handle
Definition: test_arm_regression.c:16
uv_open_osfhandle
UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd)
Definition: unix/core.c:1388
UV_FS_MKDIR
@ UV_FS_MKDIR
Definition: uv.h:1266
access_cb
static void access_cb(uv_fs_t *req)
Definition: test-fs.c:251
uv_handle_s
Definition: uv.h:441
fs_read_file_eof
static void fs_read_file_eof(int add_flags)
Definition: test-fs.c:3044
scandir_req
static uv_fs_t scandir_req
Definition: test-fs.c:116
uv_thread_t
pthread_t uv_thread_t
Definition: unix.h:134
sendfile_setup
static void sendfile_setup(int f)
Definition: test-fs.c:1222
uv_loop_s
Definition: uv.h:1767
utime_check_t
Definition: test-fs.c:60
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
uv_fs_s::ptr
void * ptr
Definition: uv.h:1300
run_microbenchmark.link
def link(txt, tgt)
Definition: run_microbenchmark.py:67
open_nametoolong_cb
static void open_nametoolong_cb(uv_fs_t *req)
Definition: test-fs.c:702
lutime_cb_count
static int lutime_cb_count
Definition: test-fs.c:98
sendfile_cb_count
static int sendfile_cb_count
Definition: test-fs.c:84
mkstemp_req1
static uv_fs_t mkstemp_req1
Definition: test-fs.c:112
UV_FS_STATFS
@ UV_FS_STATFS
Definition: uv.h:1281
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
check_permission
static void check_permission(const char *filename, unsigned int mode)
Definition: test-fs.c:168
uv_fs_lchown
UV_EXTERN int uv_fs_lchown(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_uid_t uid, uv_gid_t gid, uv_fs_cb cb)
Definition: unix/fs.c:1684
ftruncate_cb_count
static int ftruncate_cb_count
Definition: test-fs.c:83
INT32_MAX
#define INT32_MAX
Definition: stdint-msvc2008.h:137
uv_fs_lstat
UV_EXTERN int uv_fs_lstat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
Definition: unix/fs.c:1758
unlink_cb_count
static int unlink_cb_count
Definition: test-fs.c:73
realpath_cb
static void realpath_cb(uv_fs_t *req)
Definition: test-fs.c:222
TOO_LONG_NAME_LENGTH
#define TOO_LONG_NAME_LENGTH
Definition: test-fs.c:57
UV_FS_FSTAT
@ UV_FS_FSTAT
Definition: uv.h:1255
write_cb_count
static int write_cb_count
Definition: test-fs.c:72
SEEK_SET
#define SEEK_SET
Definition: bloaty/third_party/zlib/contrib/minizip/zip.c:88
test_sendfile
static int test_sendfile(void(*setup)(int), uv_fs_cb cb, off_t expected_size)
Definition: test-fs.c:1163
uv_fs_scandir_next
UV_EXTERN int uv_fs_scandir_next(uv_fs_t *req, uv_dirent_t *ent)
Definition: uv-common.c:621
thread
static uv_thread_t thread
Definition: test-async-null-cb.c:29
UV_DIRENT_UNKNOWN
@ UV_DIRENT_UNKNOWN
Definition: uv.h:1129
uv_fs_fstat
UV_EXTERN int uv_fs_fstat(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
Definition: unix/fs.c:1705
errno.h
grpc::testing::setup
static void setup()
Definition: bm_cq_multiple_threads.cc:117
cb
OPENSSL_EXPORT pem_password_cb * cb
Definition: pem.h:351
command
const char * command
Definition: grpc_tool.cc:247
open_req1
static uv_fs_t open_req1
Definition: test-fs.c:103
UV_FS_REALPATH
@ UV_FS_REALPATH
Definition: uv.h:1275
mkdtemp_req1
static uv_fs_t mkdtemp_req1
Definition: test-fs.c:110
offset
voidpf uLong offset
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:142
fs_read_bufs
static void fs_read_bufs(int add_flags)
Definition: test-fs.c:2986
uv_signal_start
UV_EXTERN int uv_signal_start(uv_signal_t *handle, uv_signal_cb signal_cb, int signum)
Definition: unix/signal.c:338
uv_test_getiovmax
int uv_test_getiovmax(void)
Definition: test-fs.c:137
UV_FS_RENAME
@ UV_FS_RENAME
Definition: uv.h:1268
mkdir_cb_count
static int mkdir_cb_count
Definition: test-fs.c:74


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:26