Bug Summary

File:out/../deps/uv/src/unix/fs.c
Warning:line 1033, column 5
Value stored to 'try_sendfile' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name fs.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/maurizio/node-v18.6.0/out -resource-dir /usr/local/lib/clang/16.0.0 -D V8_DEPRECATION_WARNINGS -D V8_IMMINENT_DEPRECATION_WARNINGS -D _GLIBCXX_USE_CXX11_ABI=1 -D NODE_OPENSSL_CONF_NAME=nodejs_conf -D NODE_OPENSSL_HAS_QUIC -D __STDC_FORMAT_MACROS -D OPENSSL_NO_PINSHARED -D OPENSSL_THREADS -D _LARGEFILE_SOURCE -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -I ../deps/uv/include -I ../deps/uv/src -internal-isystem /usr/local/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-unused-parameter -fdebug-compilation-dir=/home/maurizio/node-v18.6.0/out -ferror-limit 19 -fvisibility hidden -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-08-22-142216-507842-1 -x c ../deps/uv/src/unix/fs.c
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/* Caveat emptor: this file deviates from the libuv convention of returning
23 * negated errno codes. Most uv_fs_*() functions map directly to the system
24 * call of the same name. For more complex wrappers, it's easier to just
25 * return -1 with errno set. The dispatcher in uv__fs_work() takes care of
26 * getting the errno to the right place (req->result or as the return value.)
27 */
28
29#include "uv.h"
30#include "internal.h"
31
32#include <errno(*__errno_location ()).h>
33#include <dlfcn.h>
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include <limits.h> /* PATH_MAX */
38
39#include <sys/types.h>
40#include <sys/socket.h>
41#include <sys/stat.h>
42#include <sys/time.h>
43#include <sys/uio.h>
44#include <pthread.h>
45#include <unistd.h>
46#include <fcntl.h>
47#include <poll.h>
48
49#if defined(__DragonFly__) || \
50 defined(__FreeBSD__) || \
51 defined(__FreeBSD_kernel__) || \
52 defined(__OpenBSD__) || \
53 defined(__NetBSD__)
54# define HAVE_PREADV0 1
55#else
56# define HAVE_PREADV0 0
57#endif
58
59#if defined(__linux__1)
60# include "sys/utsname.h"
61#endif
62
63#if defined(__linux__1) || defined(__sun)
64# include <sys/sendfile.h>
65# include <sys/sysmacros.h>
66#endif
67
68#if defined(__APPLE__)
69# include <sys/sysctl.h>
70#elif defined(__linux__1) && !defined(FICLONE(((1U) << (((0 +8)+8)+14)) | (((0x94)) << (0 +8))
| (((9)) << 0) | ((((sizeof(int)))) << ((0 +8)+8
)))
)
71# include <sys/ioctl.h>
72# define FICLONE(((1U) << (((0 +8)+8)+14)) | (((0x94)) << (0 +8))
| (((9)) << 0) | ((((sizeof(int)))) << ((0 +8)+8
)))
_IOW(0x94, 9, int)(((1U) << (((0 +8)+8)+14)) | (((0x94)) << (0 +8))
| (((9)) << 0) | ((((sizeof(int)))) << ((0 +8)+8
)))
73#endif
74
75#if defined(_AIX) && !defined(_AIX71)
76# include <utime.h>
77#endif
78
79#if defined(__APPLE__) || \
80 defined(__DragonFly__) || \
81 defined(__FreeBSD__) || \
82 defined(__FreeBSD_kernel__) || \
83 defined(__OpenBSD__) || \
84 defined(__NetBSD__)
85# include <sys/param.h>
86# include <sys/mount.h>
87#elif defined(__sun) || \
88 defined(__MVS__) || \
89 defined(__NetBSD__) || \
90 defined(__HAIKU__) || \
91 defined(__QNX__)
92# include <sys/statvfs.h>
93#else
94# include <sys/statfs.h>
95#endif
96
97#if defined(_AIX) && _XOPEN_SOURCE700 <= 600
98extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */
99#endif
100
101#define INIT(subtype)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_subtype;
req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
\
102 do { \
103 if (req == NULL((void*)0)) \
104 return UV_EINVAL; \
105 UV_REQ_INIT(req, UV_FS)do { (req)->type = (UV_FS); } while (0); \
106 req->fs_type = UV_FS_ ## subtype; \
107 req->result = 0; \
108 req->ptr = NULL((void*)0); \
109 req->loop = loop; \
110 req->path = NULL((void*)0); \
111 req->new_path = NULL((void*)0); \
112 req->bufs = NULL((void*)0); \
113 req->cb = cb; \
114 } \
115 while (0)
116
117#define PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 117, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
\
118 do { \
119 assert(path != NULL)((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__ (
{ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 119, __extension__ __PRETTY_FUNCTION__
); }))
; \
120 if (cb == NULL((void*)0)) { \
121 req->path = path; \
122 } else { \
123 req->path = uv__strdup(path); \
124 if (req->path == NULL((void*)0)) \
125 return UV_ENOMEM; \
126 } \
127 } \
128 while (0)
129
130#define PATH2do { if (cb == ((void*)0)) { req->path = path; req->new_path
= new_path; } else { size_t path_len; size_t new_path_len; path_len
= strlen(path) + 1; new_path_len = strlen(new_path) + 1; req
->path = uv__malloc(path_len + new_path_len); if (req->
path == ((void*)0)) return UV_ENOMEM; req->new_path = req->
path + path_len; memcpy((void*) req->path, path, path_len)
; memcpy((void*) req->new_path, new_path, new_path_len); }
} while (0)
\
131 do { \
132 if (cb == NULL((void*)0)) { \
133 req->path = path; \
134 req->new_path = new_path; \
135 } else { \
136 size_t path_len; \
137 size_t new_path_len; \
138 path_len = strlen(path) + 1; \
139 new_path_len = strlen(new_path) + 1; \
140 req->path = uv__malloc(path_len + new_path_len); \
141 if (req->path == NULL((void*)0)) \
142 return UV_ENOMEM; \
143 req->new_path = req->path + path_len; \
144 memcpy((void*) req->path, path, path_len); \
145 memcpy((void*) req->new_path, new_path, new_path_len); \
146 } \
147 } \
148 while (0)
149
150#define POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
\
151 do { \
152 if (cb != NULL((void*)0)) { \
153 uv__req_register(loop, req)do { (loop)->active_reqs.count++; } while (0); \
154 uv__work_submit(loop, \
155 &req->work_req, \
156 UV__WORK_FAST_IO, \
157 uv__fs_work, \
158 uv__fs_done); \
159 return 0; \
160 } \
161 else { \
162 uv__fs_work(&req->work_req); \
163 return req->result; \
164 } \
165 } \
166 while (0)
167
168
169static int uv__fs_close(int fd) {
170 int rc;
171
172 rc = uv__close_nocancel(fd);
173 if (rc == -1)
174 if (errno(*__errno_location ()) == EINTR4 || errno(*__errno_location ()) == EINPROGRESS115)
175 rc = 0; /* The close is in progress, not an error. */
176
177 return rc;
178}
179
180
181static ssize_t uv__fs_fsync(uv_fs_t* req) {
182#if defined(__APPLE__)
183 /* Apple's fdatasync and fsync explicitly do NOT flush the drive write cache
184 * to the drive platters. This is in contrast to Linux's fdatasync and fsync
185 * which do, according to recent man pages. F_FULLFSYNC is Apple's equivalent
186 * for flushing buffered data to permanent storage. If F_FULLFSYNC is not
187 * supported by the file system we fall back to F_BARRIERFSYNC or fsync().
188 * This is the same approach taken by sqlite, except sqlite does not issue
189 * an F_BARRIERFSYNC call.
190 */
191 int r;
192
193 r = fcntl(req->file, F_FULLFSYNC);
194 if (r != 0)
195 r = fcntl(req->file, 85 /* F_BARRIERFSYNC */); /* fsync + barrier */
196 if (r != 0)
197 r = fsync(req->file);
198 return r;
199#else
200 return fsync(req->file);
201#endif
202}
203
204
205static ssize_t uv__fs_fdatasync(uv_fs_t* req) {
206#if defined(__linux__1) || defined(__sun) || defined(__NetBSD__)
207 return fdatasync(req->file);
208#elif defined(__APPLE__)
209 /* See the comment in uv__fs_fsync. */
210 return uv__fs_fsync(req);
211#else
212 return fsync(req->file);
213#endif
214}
215
216
217UV_UNUSED(static struct timespec uv__fs_to_timespec(double time))__attribute__((unused)) static struct timespec uv__fs_to_timespec
(double time)
{
218 struct timespec ts;
219 ts.tv_sec = time;
220 ts.tv_nsec = (time - ts.tv_sec) * 1e9;
221
222 /* TODO(bnoordhuis) Remove this. utimesat() has nanosecond resolution but we
223 * stick to microsecond resolution for the sake of consistency with other
224 * platforms. I'm the original author of this compatibility hack but I'm
225 * less convinced it's useful nowadays.
226 */
227 ts.tv_nsec -= ts.tv_nsec % 1000;
228
229 if (ts.tv_nsec < 0) {
230 ts.tv_nsec += 1e9;
231 ts.tv_sec -= 1;
232 }
233 return ts;
234}
235
236UV_UNUSED(static struct timeval uv__fs_to_timeval(double time))__attribute__((unused)) static struct timeval uv__fs_to_timeval
(double time)
{
237 struct timeval tv;
238 tv.tv_sec = time;
239 tv.tv_usec = (time - tv.tv_sec) * 1e6;
240 if (tv.tv_usec < 0) {
241 tv.tv_usec += 1e6;
242 tv.tv_sec -= 1;
243 }
244 return tv;
245}
246
247static ssize_t uv__fs_futime(uv_fs_t* req) {
248#if defined(__linux__1) \
249 || defined(_AIX71) \
250 || defined(__HAIKU__)
251 struct timespec ts[2];
252 ts[0] = uv__fs_to_timespec(req->atime);
253 ts[1] = uv__fs_to_timespec(req->mtime);
254 return futimens(req->file, ts);
255#elif defined(__APPLE__) \
256 || defined(__DragonFly__) \
257 || defined(__FreeBSD__) \
258 || defined(__FreeBSD_kernel__) \
259 || defined(__NetBSD__) \
260 || defined(__OpenBSD__) \
261 || defined(__sun)
262 struct timeval tv[2];
263 tv[0] = uv__fs_to_timeval(req->atime);
264 tv[1] = uv__fs_to_timeval(req->mtime);
265# if defined(__sun)
266 return futimesat(req->file, NULL((void*)0), tv);
267# else
268 return futimes(req->file, tv);
269# endif
270#elif defined(__MVS__)
271 attrib_t atr;
272 memset(&atr, 0, sizeof(atr));
273 atr.att_mtimechg = 1;
274 atr.att_atimechg = 1;
275 atr.att_mtime = req->mtime;
276 atr.att_atime = req->atime;
277 return __fchattr(req->file, &atr, sizeof(atr));
278#else
279 errno(*__errno_location ()) = ENOSYS38;
280 return -1;
281#endif
282}
283
284
285static ssize_t uv__fs_mkdtemp(uv_fs_t* req) {
286 return mkdtemp((char*) req->path) ? 0 : -1;
287}
288
289
290static int (*uv__mkostemp)(char*, int);
291
292
293static void uv__mkostemp_initonce(void) {
294 /* z/os doesn't have RTLD_DEFAULT but that's okay
295 * because it doesn't have mkostemp(O_CLOEXEC) either.
296 */
297#ifdef RTLD_DEFAULT((void *) 0)
298 uv__mkostemp = (int (*)(char*, int)) dlsym(RTLD_DEFAULT((void *) 0), "mkostemp");
299
300 /* We don't care about errors, but we do want to clean them up.
301 * If there has been no error, then dlerror() will just return
302 * NULL.
303 */
304 dlerror();
305#endif /* RTLD_DEFAULT */
306}
307
308
309static int uv__fs_mkstemp(uv_fs_t* req) {
310 static uv_once_t once = UV_ONCE_INIT0;
311 int r;
312#ifdef O_CLOEXEC02000000
313 static int no_cloexec_support;
314#endif
315 static const char pattern[] = "XXXXXX";
316 static const size_t pattern_size = sizeof(pattern) - 1;
317 char* path;
318 size_t path_length;
319
320 path = (char*) req->path;
321 path_length = strlen(path);
322
323 /* EINVAL can be returned for 2 reasons:
324 1. The template's last 6 characters were not XXXXXX
325 2. open() didn't support O_CLOEXEC
326 We want to avoid going to the fallback path in case
327 of 1, so it's manually checked before. */
328 if (path_length < pattern_size ||
329 strcmp(path + path_length - pattern_size, pattern)) {
330 errno(*__errno_location ()) = EINVAL22;
331 r = -1;
332 goto clobber;
333 }
334
335 uv_once(&once, uv__mkostemp_initonce);
336
337#ifdef O_CLOEXEC02000000
338 if (uv__load_relaxed(&no_cloexec_support)(*&no_cloexec_support) == 0 && uv__mkostemp != NULL((void*)0)) {
339 r = uv__mkostemp(path, O_CLOEXEC02000000);
340
341 if (r >= 0)
342 return r;
343
344 /* If mkostemp() returns EINVAL, it means the kernel doesn't
345 support O_CLOEXEC, so we just fallback to mkstemp() below. */
346 if (errno(*__errno_location ()) != EINVAL22)
347 goto clobber;
348
349 /* We set the static variable so that next calls don't even
350 try to use mkostemp. */
351 uv__store_relaxed(&no_cloexec_support, 1)do *&no_cloexec_support = 1; while (0);
352 }
353#endif /* O_CLOEXEC */
354
355 if (req->cb != NULL((void*)0))
356 uv_rwlock_rdlock(&req->loop->cloexec_lock);
357
358 r = mkstemp(path);
359
360 /* In case of failure `uv__cloexec` will leave error in `errno`,
361 * so it is enough to just set `r` to `-1`.
362 */
363 if (r >= 0 && uv__cloexecuv__cloexec_ioctl(r, 1) != 0) {
364 r = uv__close(r);
365 if (r != 0)
366 abort();
367 r = -1;
368 }
369
370 if (req->cb != NULL((void*)0))
371 uv_rwlock_rdunlock(&req->loop->cloexec_lock);
372
373clobber:
374 if (r < 0)
375 path[0] = '\0';
376 return r;
377}
378
379
380static ssize_t uv__fs_open(uv_fs_t* req) {
381#ifdef O_CLOEXEC02000000
382 return open(req->path, req->flags | O_CLOEXEC02000000, req->mode);
383#else /* O_CLOEXEC */
384 int r;
385
386 if (req->cb != NULL((void*)0))
387 uv_rwlock_rdlock(&req->loop->cloexec_lock);
388
389 r = open(req->path, req->flags, req->mode);
390
391 /* In case of failure `uv__cloexec` will leave error in `errno`,
392 * so it is enough to just set `r` to `-1`.
393 */
394 if (r >= 0 && uv__cloexecuv__cloexec_ioctl(r, 1) != 0) {
395 r = uv__close(r);
396 if (r != 0)
397 abort();
398 r = -1;
399 }
400
401 if (req->cb != NULL((void*)0))
402 uv_rwlock_rdunlock(&req->loop->cloexec_lock);
403
404 return r;
405#endif /* O_CLOEXEC */
406}
407
408
409#if !HAVE_PREADV0
410static ssize_t uv__fs_preadv(uv_file fd,
411 uv_buf_t* bufs,
412 unsigned int nbufs,
413 off_t off) {
414 uv_buf_t* buf;
415 uv_buf_t* end;
416 ssize_t result;
417 ssize_t rc;
418 size_t pos;
419
420 assert(nbufs > 0)((void) sizeof ((nbufs > 0) ? 1 : 0), __extension__ ({ if (
nbufs > 0) ; else __assert_fail ("nbufs > 0", "../deps/uv/src/unix/fs.c"
, 420, __extension__ __PRETTY_FUNCTION__); }))
;
421
422 result = 0;
423 pos = 0;
424 buf = bufs + 0;
425 end = bufs + nbufs;
426
427 for (;;) {
428 do
429 rc = pread(fd, buf->base + pos, buf->len - pos, off + result);
430 while (rc == -1 && errno(*__errno_location ()) == EINTR4);
431
432 if (rc == 0)
433 break;
434
435 if (rc == -1 && result == 0)
436 return UV__ERR(errno)(-((*__errno_location ())));
437
438 if (rc == -1)
439 break; /* We read some data so return that, ignore the error. */
440
441 pos += rc;
442 result += rc;
443
444 if (pos < buf->len)
445 continue;
446
447 pos = 0;
448 buf += 1;
449
450 if (buf == end)
451 break;
452 }
453
454 return result;
455}
456#endif
457
458
459static ssize_t uv__fs_read(uv_fs_t* req) {
460#if defined(__linux__1)
461 static int no_preadv;
462#endif
463 unsigned int iovmax;
464 ssize_t result;
465
466 iovmax = uv__getiovmax();
467 if (req->nbufs > iovmax)
468 req->nbufs = iovmax;
469
470 if (req->off < 0) {
471 if (req->nbufs == 1)
472 result = read(req->file, req->bufs[0].base, req->bufs[0].len);
473 else
474 result = readv(req->file, (struct iovec*) req->bufs, req->nbufs);
475 } else {
476 if (req->nbufs == 1) {
477 result = pread(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
478 goto done;
479 }
480
481#if HAVE_PREADV0
482 result = preadv(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
483#else
484# if defined(__linux__1)
485 if (uv__load_relaxed(&no_preadv)(*&no_preadv)) retry:
486# endif
487 {
488 result = uv__fs_preadv(req->file, req->bufs, req->nbufs, req->off);
489 }
490# if defined(__linux__1)
491 else {
492 result = uv__preadv(req->file,
493 (struct iovec*)req->bufs,
494 req->nbufs,
495 req->off);
496 if (result == -1 && errno(*__errno_location ()) == ENOSYS38) {
497 uv__store_relaxed(&no_preadv, 1)do *&no_preadv = 1; while (0);
498 goto retry;
499 }
500 }
501# endif
502#endif
503 }
504
505done:
506 /* Early cleanup of bufs allocation, since we're done with it. */
507 if (req->bufs != req->bufsml)
508 uv__free(req->bufs);
509
510 req->bufs = NULL((void*)0);
511 req->nbufs = 0;
512
513#ifdef __PASE__
514 /* PASE returns EOPNOTSUPP when reading a directory, convert to EISDIR */
515 if (result == -1 && errno(*__errno_location ()) == EOPNOTSUPP95) {
516 struct stat buf;
517 ssize_t rc;
518 rc = fstat(req->file, &buf);
519 if (rc == 0 && S_ISDIR(buf.st_mode)((((buf.st_mode)) & 0170000) == (0040000))) {
520 errno(*__errno_location ()) = EISDIR21;
521 }
522 }
523#endif
524
525 return result;
526}
527
528
529#if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_8)
530#define UV_CONST_DIRENTconst uv__dirent_t uv__dirent_t
531#else
532#define UV_CONST_DIRENTconst uv__dirent_t const uv__dirent_t
533#endif
534
535
536static int uv__fs_scandir_filter(UV_CONST_DIRENTconst uv__dirent_t* dent) {
537 return strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0;
538}
539
540
541static int uv__fs_scandir_sort(UV_CONST_DIRENTconst uv__dirent_t** a, UV_CONST_DIRENTconst uv__dirent_t** b) {
542 return strcmp((*a)->d_name, (*b)->d_name);
543}
544
545
546static ssize_t uv__fs_scandir(uv_fs_t* req) {
547 uv__dirent_t** dents;
548 int n;
549
550 dents = NULL((void*)0);
551 n = scandir(req->path, &dents, uv__fs_scandir_filter, uv__fs_scandir_sort);
552
553 /* NOTE: We will use nbufs as an index field */
554 req->nbufs = 0;
555
556 if (n == 0) {
557 /* OS X still needs to deallocate some memory.
558 * Memory was allocated using the system allocator, so use free() here.
559 */
560 free(dents);
561 dents = NULL((void*)0);
562 } else if (n == -1) {
563 return n;
564 }
565
566 req->ptr = dents;
567
568 return n;
569}
570
571static int uv__fs_opendir(uv_fs_t* req) {
572 uv_dir_t* dir;
573
574 dir = uv__malloc(sizeof(*dir));
575 if (dir == NULL((void*)0))
576 goto error;
577
578 dir->dir = opendir(req->path);
579 if (dir->dir == NULL((void*)0))
580 goto error;
581
582 req->ptr = dir;
583 return 0;
584
585error:
586 uv__free(dir);
587 req->ptr = NULL((void*)0);
588 return -1;
589}
590
591static int uv__fs_readdir(uv_fs_t* req) {
592 uv_dir_t* dir;
593 uv_dirent_t* dirent;
594 struct dirent* res;
595 unsigned int dirent_idx;
596 unsigned int i;
597
598 dir = req->ptr;
599 dirent_idx = 0;
600
601 while (dirent_idx < dir->nentries) {
602 /* readdir() returns NULL on end of directory, as well as on error. errno
603 is used to differentiate between the two conditions. */
604 errno(*__errno_location ()) = 0;
605 res = readdir(dir->dir);
606
607 if (res == NULL((void*)0)) {
608 if (errno(*__errno_location ()) != 0)
609 goto error;
610 break;
611 }
612
613 if (strcmp(res->d_name, ".") == 0 || strcmp(res->d_name, "..") == 0)
614 continue;
615
616 dirent = &dir->dirents[dirent_idx];
617 dirent->name = uv__strdup(res->d_name);
618
619 if (dirent->name == NULL((void*)0))
620 goto error;
621
622 dirent->type = uv__fs_get_dirent_type(res);
623 ++dirent_idx;
624 }
625
626 return dirent_idx;
627
628error:
629 for (i = 0; i < dirent_idx; ++i) {
630 uv__free((char*) dir->dirents[i].name);
631 dir->dirents[i].name = NULL((void*)0);
632 }
633
634 return -1;
635}
636
637static int uv__fs_closedir(uv_fs_t* req) {
638 uv_dir_t* dir;
639
640 dir = req->ptr;
641
642 if (dir->dir != NULL((void*)0)) {
643 closedir(dir->dir);
644 dir->dir = NULL((void*)0);
645 }
646
647 uv__free(req->ptr);
648 req->ptr = NULL((void*)0);
649 return 0;
650}
651
652static int uv__fs_statfs(uv_fs_t* req) {
653 uv_statfs_t* stat_fs;
654#if defined(__sun) || \
655 defined(__MVS__) || \
656 defined(__NetBSD__) || \
657 defined(__HAIKU__) || \
658 defined(__QNX__)
659 struct statvfs buf;
660
661 if (0 != statvfs(req->path, &buf))
662#else
663 struct statfs buf;
664
665 if (0 != statfs(req->path, &buf))
666#endif /* defined(__sun) */
667 return -1;
668
669 stat_fs = uv__malloc(sizeof(*stat_fs));
670 if (stat_fs == NULL((void*)0)) {
671 errno(*__errno_location ()) = ENOMEM12;
672 return -1;
673 }
674
675#if defined(__sun) || \
676 defined(__MVS__) || \
677 defined(__OpenBSD__) || \
678 defined(__NetBSD__) || \
679 defined(__HAIKU__) || \
680 defined(__QNX__)
681 stat_fs->f_type = 0; /* f_type is not supported. */
682#else
683 stat_fs->f_type = buf.f_type;
684#endif
685 stat_fs->f_bsize = buf.f_bsize;
686 stat_fs->f_blocks = buf.f_blocks;
687 stat_fs->f_bfree = buf.f_bfree;
688 stat_fs->f_bavail = buf.f_bavail;
689 stat_fs->f_files = buf.f_files;
690 stat_fs->f_ffree = buf.f_ffree;
691 req->ptr = stat_fs;
692 return 0;
693}
694
695static ssize_t uv__fs_pathmax_size(const char* path) {
696 ssize_t pathmax;
697
698 pathmax = pathconf(path, _PC_PATH_MAX_PC_PATH_MAX);
699
700 if (pathmax == -1)
701 pathmax = UV__PATH_MAX4096;
702
703 return pathmax;
704}
705
706static ssize_t uv__fs_readlink(uv_fs_t* req) {
707 ssize_t maxlen;
708 ssize_t len;
709 char* buf;
710
711#if defined(_POSIX_PATH_MAX256) || defined(PATH_MAX4096)
712 maxlen = uv__fs_pathmax_size(req->path);
713#else
714 /* We may not have a real PATH_MAX. Read size of link. */
715 struct stat st;
716 int ret;
717 ret = lstat(req->path, &st);
718 if (ret != 0)
719 return -1;
720 if (!S_ISLNK(st.st_mode)((((st.st_mode)) & 0170000) == (0120000))) {
721 errno(*__errno_location ()) = EINVAL22;
722 return -1;
723 }
724
725 maxlen = st.st_size;
726
727 /* According to readlink(2) lstat can report st_size == 0
728 for some symlinks, such as those in /proc or /sys. */
729 if (maxlen == 0)
730 maxlen = uv__fs_pathmax_size(req->path);
731#endif
732
733 buf = uv__malloc(maxlen);
734
735 if (buf == NULL((void*)0)) {
736 errno(*__errno_location ()) = ENOMEM12;
737 return -1;
738 }
739
740#if defined(__MVS__)
741 len = os390_readlink(req->path, buf, maxlen);
742#else
743 len = readlink(req->path, buf, maxlen);
744#endif
745
746 if (len == -1) {
747 uv__free(buf);
748 return -1;
749 }
750
751 /* Uncommon case: resize to make room for the trailing nul byte. */
752 if (len == maxlen) {
753 buf = uv__reallocf(buf, len + 1);
754
755 if (buf == NULL((void*)0))
756 return -1;
757 }
758
759 buf[len] = '\0';
760 req->ptr = buf;
761
762 return 0;
763}
764
765static ssize_t uv__fs_realpath(uv_fs_t* req) {
766 char* buf;
767
768#if defined(_POSIX_VERSION200809L) && _POSIX_VERSION200809L >= 200809L
769 buf = realpath(req->path, NULL((void*)0));
770 if (buf == NULL((void*)0))
771 return -1;
772#else
773 ssize_t len;
774
775 len = uv__fs_pathmax_size(req->path);
776 buf = uv__malloc(len + 1);
777
778 if (buf == NULL((void*)0)) {
779 errno(*__errno_location ()) = ENOMEM12;
780 return -1;
781 }
782
783 if (realpath(req->path, buf) == NULL((void*)0)) {
784 uv__free(buf);
785 return -1;
786 }
787#endif
788
789 req->ptr = buf;
790
791 return 0;
792}
793
794static ssize_t uv__fs_sendfile_emul(uv_fs_t* req) {
795 struct pollfd pfd;
796 int use_pread;
797 off_t offset;
798 ssize_t nsent;
799 ssize_t nread;
800 ssize_t nwritten;
801 size_t buflen;
802 size_t len;
803 ssize_t n;
804 int in_fd;
805 int out_fd;
806 char buf[8192];
807
808 len = req->bufsml[0].len;
809 in_fd = req->flags;
810 out_fd = req->file;
811 offset = req->off;
812 use_pread = 1;
813
814 /* Here are the rules regarding errors:
815 *
816 * 1. Read errors are reported only if nsent==0, otherwise we return nsent.
817 * The user needs to know that some data has already been sent, to stop
818 * them from sending it twice.
819 *
820 * 2. Write errors are always reported. Write errors are bad because they
821 * mean data loss: we've read data but now we can't write it out.
822 *
823 * We try to use pread() and fall back to regular read() if the source fd
824 * doesn't support positional reads, for example when it's a pipe fd.
825 *
826 * If we get EAGAIN when writing to the target fd, we poll() on it until
827 * it becomes writable again.
828 *
829 * FIXME: If we get a write error when use_pread==1, it should be safe to
830 * return the number of sent bytes instead of an error because pread()
831 * is, in theory, idempotent. However, special files in /dev or /proc
832 * may support pread() but not necessarily return the same data on
833 * successive reads.
834 *
835 * FIXME: There is no way now to signal that we managed to send *some* data
836 * before a write error.
837 */
838 for (nsent = 0; (size_t) nsent < len; ) {
839 buflen = len - nsent;
840
841 if (buflen > sizeof(buf))
842 buflen = sizeof(buf);
843
844 do
845 if (use_pread)
846 nread = pread(in_fd, buf, buflen, offset);
847 else
848 nread = read(in_fd, buf, buflen);
849 while (nread == -1 && errno(*__errno_location ()) == EINTR4);
850
851 if (nread == 0)
852 goto out;
853
854 if (nread == -1) {
855 if (use_pread && nsent == 0 && (errno(*__errno_location ()) == EIO5 || errno(*__errno_location ()) == ESPIPE29)) {
856 use_pread = 0;
857 continue;
858 }
859
860 if (nsent == 0)
861 nsent = -1;
862
863 goto out;
864 }
865
866 for (nwritten = 0; nwritten < nread; ) {
867 do
868 n = write(out_fd, buf + nwritten, nread - nwritten);
869 while (n == -1 && errno(*__errno_location ()) == EINTR4);
870
871 if (n != -1) {
872 nwritten += n;
873 continue;
874 }
875
876 if (errno(*__errno_location ()) != EAGAIN11 && errno(*__errno_location ()) != EWOULDBLOCK11) {
877 nsent = -1;
878 goto out;
879 }
880
881 pfd.fd = out_fd;
882 pfd.events = POLLOUT0x004;
883 pfd.revents = 0;
884
885 do
886 n = poll(&pfd, 1, -1);
887 while (n == -1 && errno(*__errno_location ()) == EINTR4);
888
889 if (n == -1 || (pfd.revents & ~POLLOUT0x004) != 0) {
890 errno(*__errno_location ()) = EIO5;
891 nsent = -1;
892 goto out;
893 }
894 }
895
896 offset += nread;
897 nsent += nread;
898 }
899
900out:
901 if (nsent != -1)
902 req->off = offset;
903
904 return nsent;
905}
906
907
908#ifdef __linux__1
909static unsigned uv__kernel_version(void) {
910 static unsigned cached_version;
911 struct utsname u;
912 unsigned version;
913 unsigned major;
914 unsigned minor;
915 unsigned patch;
916
917 version = uv__load_relaxed(&cached_version)(*&cached_version);
918 if (version != 0)
919 return version;
920
921 if (-1 == uname(&u))
922 return 0;
923
924 if (3 != sscanf(u.release, "%u.%u.%u", &major, &minor, &patch))
925 return 0;
926
927 version = major * 65536 + minor * 256 + patch;
928 uv__store_relaxed(&cached_version, version)do *&cached_version = version; while (0);
929
930 return version;
931}
932
933
934/* Pre-4.20 kernels have a bug where CephFS uses the RADOS copy-from command
935 * in copy_file_range() when it shouldn't. There is no workaround except to
936 * fall back to a regular copy.
937 */
938static int uv__is_buggy_cephfs(int fd) {
939 struct statfs s;
940
941 if (-1 == fstatfs(fd, &s))
942 return 0;
943
944 if (s.f_type != /* CephFS */ 0xC36400)
945 return 0;
946
947 return uv__kernel_version() < /* 4.20.0 */ 0x041400;
948}
949
950
951static int uv__is_cifs_or_smb(int fd) {
952 struct statfs s;
953
954 if (-1 == fstatfs(fd, &s))
955 return 0;
956
957 switch ((unsigned) s.f_type) {
958 case 0x0000517Bu: /* SMB */
959 case 0xFE534D42u: /* SMB2 */
960 case 0xFF534D42u: /* CIFS */
961 return 1;
962 }
963
964 return 0;
965}
966
967
968static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off,
969 int out_fd, size_t len) {
970 static int no_copy_file_range_support;
971 ssize_t r;
972
973 if (uv__load_relaxed(&no_copy_file_range_support)(*&no_copy_file_range_support)) {
974 errno(*__errno_location ()) = ENOSYS38;
975 return -1;
976 }
977
978 r = uv__fs_copy_file_range(in_fd, off, out_fd, NULL((void*)0), len, 0);
979
980 if (r != -1)
981 return r;
982
983 switch (errno(*__errno_location ())) {
984 case EACCES13:
985 /* Pre-4.20 kernels have a bug where CephFS uses the RADOS
986 * copy-from command when it shouldn't.
987 */
988 if (uv__is_buggy_cephfs(in_fd))
989 errno(*__errno_location ()) = ENOSYS38; /* Use fallback. */
990 break;
991 case ENOSYS38:
992 uv__store_relaxed(&no_copy_file_range_support, 1)do *&no_copy_file_range_support = 1; while (0);
993 break;
994 case EPERM1:
995 /* It's been reported that CIFS spuriously fails.
996 * Consider it a transient error.
997 */
998 if (uv__is_cifs_or_smb(out_fd))
999 errno(*__errno_location ()) = ENOSYS38; /* Use fallback. */
1000 break;
1001 case ENOTSUP95:
1002 case EXDEV18:
1003 /* ENOTSUP - it could work on another file system type.
1004 * EXDEV - it will not work when in_fd and out_fd are not on the same
1005 * mounted filesystem (pre Linux 5.3)
1006 */
1007 errno(*__errno_location ()) = ENOSYS38; /* Use fallback. */
1008 break;
1009 }
1010
1011 return -1;
1012}
1013
1014#endif /* __linux__ */
1015
1016
1017static ssize_t uv__fs_sendfile(uv_fs_t* req) {
1018 int in_fd;
1019 int out_fd;
1020
1021 in_fd = req->flags;
1022 out_fd = req->file;
1023
1024#if defined(__linux__1) || defined(__sun)
1025 {
1026 off_t off;
1027 ssize_t r;
1028 size_t len;
1029 int try_sendfile;
1030
1031 off = req->off;
1032 len = req->bufsml[0].len;
1033 try_sendfile = 1;
Value stored to 'try_sendfile' is never read
1034
1035#ifdef __linux__1
1036 r = uv__fs_try_copy_file_range(in_fd, &off, out_fd, len);
1037 try_sendfile = (r == -1 && errno(*__errno_location ()) == ENOSYS38);
1038#endif
1039
1040 if (try_sendfile)
1041 r = sendfile(out_fd, in_fd, &off, len);
1042
1043 /* sendfile() on SunOS returns EINVAL if the target fd is not a socket but
1044 * it still writes out data. Fortunately, we can detect it by checking if
1045 * the offset has been updated.
1046 */
1047 if (r != -1 || off > req->off) {
1048 r = off - req->off;
1049 req->off = off;
1050 return r;
1051 }
1052
1053 if (errno(*__errno_location ()) == EINVAL22 ||
1054 errno(*__errno_location ()) == EIO5 ||
1055 errno(*__errno_location ()) == ENOTSOCK88 ||
1056 errno(*__errno_location ()) == EXDEV18) {
1057 errno(*__errno_location ()) = 0;
1058 return uv__fs_sendfile_emul(req);
1059 }
1060
1061 return -1;
1062 }
1063#elif defined(__APPLE__) || \
1064 defined(__DragonFly__) || \
1065 defined(__FreeBSD__) || \
1066 defined(__FreeBSD_kernel__)
1067 {
1068 off_t len;
1069 ssize_t r;
1070
1071 /* sendfile() on FreeBSD and Darwin returns EAGAIN if the target fd is in
1072 * non-blocking mode and not all data could be written. If a non-zero
1073 * number of bytes have been sent, we don't consider it an error.
1074 */
1075
1076#if defined(__FreeBSD__) || defined(__DragonFly__)
1077 len = 0;
1078 r = sendfile(in_fd, out_fd, req->off, req->bufsml[0].len, NULL((void*)0), &len, 0);
1079#elif defined(__FreeBSD_kernel__)
1080 len = 0;
1081 r = bsd_sendfile(in_fd,
1082 out_fd,
1083 req->off,
1084 req->bufsml[0].len,
1085 NULL((void*)0),
1086 &len,
1087 0);
1088#else
1089 /* The darwin sendfile takes len as an input for the length to send,
1090 * so make sure to initialize it with the caller's value. */
1091 len = req->bufsml[0].len;
1092 r = sendfile(in_fd, out_fd, req->off, &len, NULL((void*)0), 0);
1093#endif
1094
1095 /*
1096 * The man page for sendfile(2) on DragonFly states that `len` contains
1097 * a meaningful value ONLY in case of EAGAIN and EINTR.
1098 * Nothing is said about it's value in case of other errors, so better
1099 * not depend on the potential wrong assumption that is was not modified
1100 * by the syscall.
1101 */
1102 if (r == 0 || ((errno(*__errno_location ()) == EAGAIN11 || errno(*__errno_location ()) == EINTR4) && len != 0)) {
1103 req->off += len;
1104 return (ssize_t) len;
1105 }
1106
1107 if (errno(*__errno_location ()) == EINVAL22 ||
1108 errno(*__errno_location ()) == EIO5 ||
1109 errno(*__errno_location ()) == ENOTSOCK88 ||
1110 errno(*__errno_location ()) == EXDEV18) {
1111 errno(*__errno_location ()) = 0;
1112 return uv__fs_sendfile_emul(req);
1113 }
1114
1115 return -1;
1116 }
1117#else
1118 /* Squelch compiler warnings. */
1119 (void) &in_fd;
1120 (void) &out_fd;
1121
1122 return uv__fs_sendfile_emul(req);
1123#endif
1124}
1125
1126
1127static ssize_t uv__fs_utime(uv_fs_t* req) {
1128#if defined(__linux__1) \
1129 || defined(_AIX71) \
1130 || defined(__sun) \
1131 || defined(__HAIKU__)
1132 struct timespec ts[2];
1133 ts[0] = uv__fs_to_timespec(req->atime);
1134 ts[1] = uv__fs_to_timespec(req->mtime);
1135 return utimensat(AT_FDCWD-100, req->path, ts, 0);
1136#elif defined(__APPLE__) \
1137 || defined(__DragonFly__) \
1138 || defined(__FreeBSD__) \
1139 || defined(__FreeBSD_kernel__) \
1140 || defined(__NetBSD__) \
1141 || defined(__OpenBSD__)
1142 struct timeval tv[2];
1143 tv[0] = uv__fs_to_timeval(req->atime);
1144 tv[1] = uv__fs_to_timeval(req->mtime);
1145 return utimes(req->path, tv);
1146#elif defined(_AIX) \
1147 && !defined(_AIX71)
1148 struct utimbuf buf;
1149 buf.actime = req->atime;
1150 buf.modtime = req->mtime;
1151 return utime(req->path, &buf);
1152#elif defined(__MVS__)
1153 attrib_t atr;
1154 memset(&atr, 0, sizeof(atr));
1155 atr.att_mtimechg = 1;
1156 atr.att_atimechg = 1;
1157 atr.att_mtime = req->mtime;
1158 atr.att_atime = req->atime;
1159 return __lchattr((char*) req->path, &atr, sizeof(atr));
1160#else
1161 errno(*__errno_location ()) = ENOSYS38;
1162 return -1;
1163#endif
1164}
1165
1166
1167static ssize_t uv__fs_lutime(uv_fs_t* req) {
1168#if defined(__linux__1) || \
1169 defined(_AIX71) || \
1170 defined(__sun) || \
1171 defined(__HAIKU__)
1172 struct timespec ts[2];
1173 ts[0] = uv__fs_to_timespec(req->atime);
1174 ts[1] = uv__fs_to_timespec(req->mtime);
1175 return utimensat(AT_FDCWD-100, req->path, ts, AT_SYMLINK_NOFOLLOW0x100);
1176#elif defined(__APPLE__) || \
1177 defined(__DragonFly__) || \
1178 defined(__FreeBSD__) || \
1179 defined(__FreeBSD_kernel__) || \
1180 defined(__NetBSD__)
1181 struct timeval tv[2];
1182 tv[0] = uv__fs_to_timeval(req->atime);
1183 tv[1] = uv__fs_to_timeval(req->mtime);
1184 return lutimes(req->path, tv);
1185#else
1186 errno(*__errno_location ()) = ENOSYS38;
1187 return -1;
1188#endif
1189}
1190
1191
1192static ssize_t uv__fs_write(uv_fs_t* req) {
1193#if defined(__linux__1)
1194 static int no_pwritev;
1195#endif
1196 ssize_t r;
1197
1198 /* Serialize writes on OS X, concurrent write() and pwrite() calls result in
1199 * data loss. We can't use a per-file descriptor lock, the descriptor may be
1200 * a dup().
1201 */
1202#if defined(__APPLE__)
1203 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER{ { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } };
1204
1205 if (pthread_mutex_lock(&lock))
1206 abort();
1207#endif
1208
1209 if (req->off < 0) {
1210 if (req->nbufs == 1)
1211 r = write(req->file, req->bufs[0].base, req->bufs[0].len);
1212 else
1213 r = writev(req->file, (struct iovec*) req->bufs, req->nbufs);
1214 } else {
1215 if (req->nbufs == 1) {
1216 r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
1217 goto done;
1218 }
1219#if HAVE_PREADV0
1220 r = pwritev(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
1221#else
1222# if defined(__linux__1)
1223 if (no_pwritev) retry:
1224# endif
1225 {
1226 r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
1227 }
1228# if defined(__linux__1)
1229 else {
1230 r = uv__pwritev(req->file,
1231 (struct iovec*) req->bufs,
1232 req->nbufs,
1233 req->off);
1234 if (r == -1 && errno(*__errno_location ()) == ENOSYS38) {
1235 no_pwritev = 1;
1236 goto retry;
1237 }
1238 }
1239# endif
1240#endif
1241 }
1242
1243done:
1244#if defined(__APPLE__)
1245 if (pthread_mutex_unlock(&lock))
1246 abort();
1247#endif
1248
1249 return r;
1250}
1251
1252static ssize_t uv__fs_copyfile(uv_fs_t* req) {
1253 uv_fs_t fs_req;
1254 uv_file srcfd;
1255 uv_file dstfd;
1256 struct stat src_statsbuf;
1257 struct stat dst_statsbuf;
1258 int dst_flags;
1259 int result;
1260 int err;
1261 off_t bytes_to_send;
1262 off_t in_offset;
1263 off_t bytes_written;
1264 size_t bytes_chunk;
1265
1266 dstfd = -1;
1267 err = 0;
1268
1269 /* Open the source file. */
1270 srcfd = uv_fs_open(NULL((void*)0), &fs_req, req->path, O_RDONLY00, 0, NULL((void*)0));
1271 uv_fs_req_cleanup(&fs_req);
1272
1273 if (srcfd < 0)
1274 return srcfd;
1275
1276 /* Get the source file's mode. */
1277 if (fstat(srcfd, &src_statsbuf)) {
1278 err = UV__ERR(errno)(-((*__errno_location ())));
1279 goto out;
1280 }
1281
1282 dst_flags = O_WRONLY01 | O_CREAT0100;
1283
1284 if (req->flags & UV_FS_COPYFILE_EXCL0x0001)
1285 dst_flags |= O_EXCL0200;
1286
1287 /* Open the destination file. */
1288 dstfd = uv_fs_open(NULL((void*)0),
1289 &fs_req,
1290 req->new_path,
1291 dst_flags,
1292 src_statsbuf.st_mode,
1293 NULL((void*)0));
1294 uv_fs_req_cleanup(&fs_req);
1295
1296 if (dstfd < 0) {
1297 err = dstfd;
1298 goto out;
1299 }
1300
1301 /* If the file is not being opened exclusively, verify that the source and
1302 destination are not the same file. If they are the same, bail out early. */
1303 if ((req->flags & UV_FS_COPYFILE_EXCL0x0001) == 0) {
1304 /* Get the destination file's mode. */
1305 if (fstat(dstfd, &dst_statsbuf)) {
1306 err = UV__ERR(errno)(-((*__errno_location ())));
1307 goto out;
1308 }
1309
1310 /* Check if srcfd and dstfd refer to the same file */
1311 if (src_statsbuf.st_dev == dst_statsbuf.st_dev &&
1312 src_statsbuf.st_ino == dst_statsbuf.st_ino) {
1313 goto out;
1314 }
1315
1316 /* Truncate the file in case the destination already existed. */
1317 if (ftruncate(dstfd, 0) != 0) {
1318 err = UV__ERR(errno)(-((*__errno_location ())));
1319 goto out;
1320 }
1321 }
1322
1323 if (fchmod(dstfd, src_statsbuf.st_mode) == -1) {
1324 err = UV__ERR(errno)(-((*__errno_location ())));
1325#ifdef __linux__1
1326 /* fchmod() on CIFS shares always fails with EPERM unless the share is
1327 * mounted with "noperm". As fchmod() is a meaningless operation on such
1328 * shares anyway, detect that condition and squelch the error.
1329 */
1330 if (err != UV_EPERM)
1331 goto out;
1332
1333 if (!uv__is_cifs_or_smb(dstfd))
1334 goto out;
1335
1336 err = 0;
1337#else /* !__linux__ */
1338 goto out;
1339#endif /* !__linux__ */
1340 }
1341
1342#ifdef FICLONE(((1U) << (((0 +8)+8)+14)) | (((0x94)) << (0 +8))
| (((9)) << 0) | ((((sizeof(int)))) << ((0 +8)+8
)))
1343 if (req->flags & UV_FS_COPYFILE_FICLONE0x0002 ||
1344 req->flags & UV_FS_COPYFILE_FICLONE_FORCE0x0004) {
1345 if (ioctl(dstfd, FICLONE(((1U) << (((0 +8)+8)+14)) | (((0x94)) << (0 +8))
| (((9)) << 0) | ((((sizeof(int)))) << ((0 +8)+8
)))
, srcfd) == 0) {
1346 /* ioctl() with FICLONE succeeded. */
1347 goto out;
1348 }
1349 /* If an error occurred and force was set, return the error to the caller;
1350 * fall back to sendfile() when force was not set. */
1351 if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE0x0004) {
1352 err = UV__ERR(errno)(-((*__errno_location ())));
1353 goto out;
1354 }
1355 }
1356#else
1357 if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE0x0004) {
1358 err = UV_ENOSYS;
1359 goto out;
1360 }
1361#endif
1362
1363 bytes_to_send = src_statsbuf.st_size;
1364 in_offset = 0;
1365 while (bytes_to_send != 0) {
1366 bytes_chunk = SSIZE_MAX9223372036854775807L;
1367 if (bytes_to_send < (off_t) bytes_chunk)
1368 bytes_chunk = bytes_to_send;
1369 uv_fs_sendfile(NULL((void*)0), &fs_req, dstfd, srcfd, in_offset, bytes_chunk, NULL((void*)0));
1370 bytes_written = fs_req.result;
1371 uv_fs_req_cleanup(&fs_req);
1372
1373 if (bytes_written < 0) {
1374 err = bytes_written;
1375 break;
1376 }
1377
1378 bytes_to_send -= bytes_written;
1379 in_offset += bytes_written;
1380 }
1381
1382out:
1383 if (err < 0)
1384 result = err;
1385 else
1386 result = 0;
1387
1388 /* Close the source file. */
1389 err = uv__close_nocheckstdio(srcfd);
1390
1391 /* Don't overwrite any existing errors. */
1392 if (err != 0 && result == 0)
1393 result = err;
1394
1395 /* Close the destination file if it is open. */
1396 if (dstfd >= 0) {
1397 err = uv__close_nocheckstdio(dstfd);
1398
1399 /* Don't overwrite any existing errors. */
1400 if (err != 0 && result == 0)
1401 result = err;
1402
1403 /* Remove the destination file if something went wrong. */
1404 if (result != 0) {
1405 uv_fs_unlink(NULL((void*)0), &fs_req, req->new_path, NULL((void*)0));
1406 /* Ignore the unlink return value, as an error already happened. */
1407 uv_fs_req_cleanup(&fs_req);
1408 }
1409 }
1410
1411 if (result == 0)
1412 return 0;
1413
1414 errno(*__errno_location ()) = UV__ERR(result)(-(result));
1415 return -1;
1416}
1417
1418static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
1419 dst->st_dev = src->st_dev;
1420 dst->st_mode = src->st_mode;
1421 dst->st_nlink = src->st_nlink;
1422 dst->st_uid = src->st_uid;
1423 dst->st_gid = src->st_gid;
1424 dst->st_rdev = src->st_rdev;
1425 dst->st_ino = src->st_ino;
1426 dst->st_size = src->st_size;
1427 dst->st_blksize = src->st_blksize;
1428 dst->st_blocks = src->st_blocks;
1429
1430#if defined(__APPLE__)
1431 dst->st_atim.tv_sec = src->st_atimespec.tv_sec;
1432 dst->st_atim.tv_nsec = src->st_atimespec.tv_nsec;
1433 dst->st_mtim.tv_sec = src->st_mtimespec.tv_sec;
1434 dst->st_mtim.tv_nsec = src->st_mtimespec.tv_nsec;
1435 dst->st_ctim.tv_sec = src->st_ctimespec.tv_sec;
1436 dst->st_ctim.tv_nsec = src->st_ctimespec.tv_nsec;
1437 dst->st_birthtim.tv_sec = src->st_birthtimespec.tv_sec;
1438 dst->st_birthtim.tv_nsec = src->st_birthtimespec.tv_nsec;
1439 dst->st_flags = src->st_flags;
1440 dst->st_gen = src->st_gen;
1441#elif defined(__ANDROID__)
1442 dst->st_atim.tv_sec = src->st_atimest_atim.tv_sec;
1443 dst->st_atim.tv_nsec = src->st_atimensec;
1444 dst->st_mtim.tv_sec = src->st_mtimest_mtim.tv_sec;
1445 dst->st_mtim.tv_nsec = src->st_mtimensec;
1446 dst->st_ctim.tv_sec = src->st_ctimest_ctim.tv_sec;
1447 dst->st_ctim.tv_nsec = src->st_ctimensec;
1448 dst->st_birthtim.tv_sec = src->st_ctimest_ctim.tv_sec;
1449 dst->st_birthtim.tv_nsec = src->st_ctimensec;
1450 dst->st_flags = 0;
1451 dst->st_gen = 0;
1452#elif !defined(_AIX) && \
1453 !defined(__MVS__) && ( \
1454 defined(__DragonFly__) || \
1455 defined(__FreeBSD__) || \
1456 defined(__OpenBSD__) || \
1457 defined(__NetBSD__) || \
1458 defined(_GNU_SOURCE1) || \
1459 defined(_BSD_SOURCE) || \
1460 defined(_SVID_SOURCE) || \
1461 defined(_XOPEN_SOURCE700) || \
1462 defined(_DEFAULT_SOURCE1))
1463 dst->st_atim.tv_sec = src->st_atim.tv_sec;
1464 dst->st_atim.tv_nsec = src->st_atim.tv_nsec;
1465 dst->st_mtim.tv_sec = src->st_mtim.tv_sec;
1466 dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec;
1467 dst->st_ctim.tv_sec = src->st_ctim.tv_sec;
1468 dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec;
1469# if defined(__FreeBSD__) || \
1470 defined(__NetBSD__)
1471 dst->st_birthtim.tv_sec = src->st_birthtim.tv_sec;
1472 dst->st_birthtim.tv_nsec = src->st_birthtim.tv_nsec;
1473 dst->st_flags = src->st_flags;
1474 dst->st_gen = src->st_gen;
1475# else
1476 dst->st_birthtim.tv_sec = src->st_ctim.tv_sec;
1477 dst->st_birthtim.tv_nsec = src->st_ctim.tv_nsec;
1478 dst->st_flags = 0;
1479 dst->st_gen = 0;
1480# endif
1481#else
1482 dst->st_atim.tv_sec = src->st_atimest_atim.tv_sec;
1483 dst->st_atim.tv_nsec = 0;
1484 dst->st_mtim.tv_sec = src->st_mtimest_mtim.tv_sec;
1485 dst->st_mtim.tv_nsec = 0;
1486 dst->st_ctim.tv_sec = src->st_ctimest_ctim.tv_sec;
1487 dst->st_ctim.tv_nsec = 0;
1488 dst->st_birthtim.tv_sec = src->st_ctimest_ctim.tv_sec;
1489 dst->st_birthtim.tv_nsec = 0;
1490 dst->st_flags = 0;
1491 dst->st_gen = 0;
1492#endif
1493}
1494
1495
1496static int uv__fs_statx(int fd,
1497 const char* path,
1498 int is_fstat,
1499 int is_lstat,
1500 uv_stat_t* buf) {
1501 STATIC_ASSERT(UV_ENOSYS != -1)void uv__static_assert(int static_assert_failed[1 - 2 * !(UV_ENOSYS
!= -1)])
;
1502#ifdef __linux__1
1503 static int no_statx;
1504 struct uv__statx statxbuf;
1505 int dirfd;
1506 int flags;
1507 int mode;
1508 int rc;
1509
1510 if (uv__load_relaxed(&no_statx)(*&no_statx))
1511 return UV_ENOSYS;
1512
1513 dirfd = AT_FDCWD-100;
1514 flags = 0; /* AT_STATX_SYNC_AS_STAT */
1515 mode = 0xFFF; /* STATX_BASIC_STATS + STATX_BTIME */
1516
1517 if (is_fstat) {
1518 dirfd = fd;
1519 flags |= 0x1000; /* AT_EMPTY_PATH */
1520 }
1521
1522 if (is_lstat)
1523 flags |= AT_SYMLINK_NOFOLLOW0x100;
1524
1525 rc = uv__statx(dirfd, path, flags, mode, &statxbuf);
1526
1527 switch (rc) {
1528 case 0:
1529 break;
1530 case -1:
1531 /* EPERM happens when a seccomp filter rejects the system call.
1532 * Has been observed with libseccomp < 2.3.3 and docker < 18.04.
1533 * EOPNOTSUPP is used on DVS exported filesystems
1534 */
1535 if (errno(*__errno_location ()) != EINVAL22 && errno(*__errno_location ()) != EPERM1 && errno(*__errno_location ()) != ENOSYS38 && errno(*__errno_location ()) != EOPNOTSUPP95)
1536 return -1;
1537 /* Fall through. */
1538 default:
1539 /* Normally on success, zero is returned and On error, -1 is returned.
1540 * Observed on S390 RHEL running in a docker container with statx not
1541 * implemented, rc might return 1 with 0 set as the error code in which
1542 * case we return ENOSYS.
1543 */
1544 uv__store_relaxed(&no_statx, 1)do *&no_statx = 1; while (0);
1545 return UV_ENOSYS;
1546 }
1547
1548 buf->st_dev = makedev(statxbuf.stx_dev_major, statxbuf.stx_dev_minor)gnu_dev_makedev (statxbuf.stx_dev_major, statxbuf.stx_dev_minor
)
;
1549 buf->st_mode = statxbuf.stx_mode;
1550 buf->st_nlink = statxbuf.stx_nlink;
1551 buf->st_uid = statxbuf.stx_uid;
1552 buf->st_gid = statxbuf.stx_gid;
1553 buf->st_rdev = makedev(statxbuf.stx_rdev_major, statxbuf.stx_rdev_minor)gnu_dev_makedev (statxbuf.stx_rdev_major, statxbuf.stx_rdev_minor
)
;
1554 buf->st_ino = statxbuf.stx_ino;
1555 buf->st_size = statxbuf.stx_size;
1556 buf->st_blksize = statxbuf.stx_blksize;
1557 buf->st_blocks = statxbuf.stx_blocks;
1558 buf->st_atim.tv_sec = statxbuf.stx_atime.tv_sec;
1559 buf->st_atim.tv_nsec = statxbuf.stx_atime.tv_nsec;
1560 buf->st_mtim.tv_sec = statxbuf.stx_mtime.tv_sec;
1561 buf->st_mtim.tv_nsec = statxbuf.stx_mtime.tv_nsec;
1562 buf->st_ctim.tv_sec = statxbuf.stx_ctime.tv_sec;
1563 buf->st_ctim.tv_nsec = statxbuf.stx_ctime.tv_nsec;
1564 buf->st_birthtim.tv_sec = statxbuf.stx_btime.tv_sec;
1565 buf->st_birthtim.tv_nsec = statxbuf.stx_btime.tv_nsec;
1566 buf->st_flags = 0;
1567 buf->st_gen = 0;
1568
1569 return 0;
1570#else
1571 return UV_ENOSYS;
1572#endif /* __linux__ */
1573}
1574
1575
1576static int uv__fs_stat(const char *path, uv_stat_t *buf) {
1577 struct stat pbuf;
1578 int ret;
1579
1580 ret = uv__fs_statx(-1, path, /* is_fstat */ 0, /* is_lstat */ 0, buf);
1581 if (ret != UV_ENOSYS)
1582 return ret;
1583
1584 ret = stat(path, &pbuf);
1585 if (ret == 0)
1586 uv__to_stat(&pbuf, buf);
1587
1588 return ret;
1589}
1590
1591
1592static int uv__fs_lstat(const char *path, uv_stat_t *buf) {
1593 struct stat pbuf;
1594 int ret;
1595
1596 ret = uv__fs_statx(-1, path, /* is_fstat */ 0, /* is_lstat */ 1, buf);
1597 if (ret != UV_ENOSYS)
1598 return ret;
1599
1600 ret = lstat(path, &pbuf);
1601 if (ret == 0)
1602 uv__to_stat(&pbuf, buf);
1603
1604 return ret;
1605}
1606
1607
1608static int uv__fs_fstat(int fd, uv_stat_t *buf) {
1609 struct stat pbuf;
1610 int ret;
1611
1612 ret = uv__fs_statx(fd, "", /* is_fstat */ 1, /* is_lstat */ 0, buf);
1613 if (ret != UV_ENOSYS)
1614 return ret;
1615
1616 ret = fstat(fd, &pbuf);
1617 if (ret == 0)
1618 uv__to_stat(&pbuf, buf);
1619
1620 return ret;
1621}
1622
1623static size_t uv__fs_buf_offset(uv_buf_t* bufs, size_t size) {
1624 size_t offset;
1625 /* Figure out which bufs are done */
1626 for (offset = 0; size > 0 && bufs[offset].len <= size; ++offset)
1627 size -= bufs[offset].len;
1628
1629 /* Fix a partial read/write */
1630 if (size > 0) {
1631 bufs[offset].base += size;
1632 bufs[offset].len -= size;
1633 }
1634 return offset;
1635}
1636
1637static ssize_t uv__fs_write_all(uv_fs_t* req) {
1638 unsigned int iovmax;
1639 unsigned int nbufs;
1640 uv_buf_t* bufs;
1641 ssize_t total;
1642 ssize_t result;
1643
1644 iovmax = uv__getiovmax();
1645 nbufs = req->nbufs;
1646 bufs = req->bufs;
1647 total = 0;
1648
1649 while (nbufs > 0) {
1650 req->nbufs = nbufs;
1651 if (req->nbufs > iovmax)
1652 req->nbufs = iovmax;
1653
1654 do
1655 result = uv__fs_write(req);
1656 while (result < 0 && errno(*__errno_location ()) == EINTR4);
1657
1658 if (result <= 0) {
1659 if (total == 0)
1660 total = result;
1661 break;
1662 }
1663
1664 if (req->off >= 0)
1665 req->off += result;
1666
1667 req->nbufs = uv__fs_buf_offset(req->bufs, result);
1668 req->bufs += req->nbufs;
1669 nbufs -= req->nbufs;
1670 total += result;
1671 }
1672
1673 if (bufs != req->bufsml)
1674 uv__free(bufs);
1675
1676 req->bufs = NULL((void*)0);
1677 req->nbufs = 0;
1678
1679 return total;
1680}
1681
1682
1683static void uv__fs_work(struct uv__work* w) {
1684 int retry_on_eintr;
1685 uv_fs_t* req;
1686 ssize_t r;
1687
1688 req = container_of(w, uv_fs_t, work_req)((uv_fs_t *) ((char *) (w) - __builtin_offsetof(uv_fs_t, work_req
)))
;
1689 retry_on_eintr = !(req->fs_type == UV_FS_CLOSE ||
1690 req->fs_type == UV_FS_READ);
1691
1692 do {
1693 errno(*__errno_location ()) = 0;
1694
1695#define X(type, action) \
1696 case UV_FS_ ## type: \
1697 r = action; \
1698 break;
1699
1700 switch (req->fs_type) {
1701 X(ACCESS, access(req->path, req->flags));
1702 X(CHMOD, chmod(req->path, req->mode));
1703 X(CHOWN, chown(req->path, req->uid, req->gid));
1704 X(CLOSE, uv__fs_close(req->file));
1705 X(COPYFILE, uv__fs_copyfile(req));
1706 X(FCHMOD, fchmod(req->file, req->mode));
1707 X(FCHOWN, fchown(req->file, req->uid, req->gid));
1708 X(LCHOWN, lchown(req->path, req->uid, req->gid));
1709 X(FDATASYNC, uv__fs_fdatasync(req));
1710 X(FSTAT, uv__fs_fstat(req->file, &req->statbuf));
1711 X(FSYNC, uv__fs_fsync(req));
1712 X(FTRUNCATE, ftruncate(req->file, req->off));
1713 X(FUTIME, uv__fs_futime(req));
1714 X(LUTIME, uv__fs_lutime(req));
1715 X(LSTAT, uv__fs_lstat(req->path, &req->statbuf));
1716 X(LINK, link(req->path, req->new_path));
1717 X(MKDIR, mkdir(req->path, req->mode));
1718 X(MKDTEMP, uv__fs_mkdtemp(req));
1719 X(MKSTEMP, uv__fs_mkstemp(req));
1720 X(OPEN, uv__fs_open(req));
1721 X(READ, uv__fs_read(req));
1722 X(SCANDIR, uv__fs_scandir(req));
1723 X(OPENDIR, uv__fs_opendir(req));
1724 X(READDIR, uv__fs_readdir(req));
1725 X(CLOSEDIR, uv__fs_closedir(req));
1726 X(READLINK, uv__fs_readlink(req));
1727 X(REALPATH, uv__fs_realpath(req));
1728 X(RENAME, rename(req->path, req->new_path));
1729 X(RMDIR, rmdir(req->path));
1730 X(SENDFILE, uv__fs_sendfile(req));
1731 X(STAT, uv__fs_stat(req->path, &req->statbuf));
1732 X(STATFS, uv__fs_statfs(req));
1733 X(SYMLINK, symlink(req->path, req->new_path));
1734 X(UNLINK, unlink(req->path));
1735 X(UTIME, uv__fs_utime(req));
1736 X(WRITE, uv__fs_write_all(req));
1737 default: abort();
1738 }
1739#undef X
1740 } while (r == -1 && errno(*__errno_location ()) == EINTR4 && retry_on_eintr);
1741
1742 if (r == -1)
1743 req->result = UV__ERR(errno)(-((*__errno_location ())));
1744 else
1745 req->result = r;
1746
1747 if (r == 0 && (req->fs_type == UV_FS_STAT ||
1748 req->fs_type == UV_FS_FSTAT ||
1749 req->fs_type == UV_FS_LSTAT)) {
1750 req->ptr = &req->statbuf;
1751 }
1752}
1753
1754
1755static void uv__fs_done(struct uv__work* w, int status) {
1756 uv_fs_t* req;
1757
1758 req = container_of(w, uv_fs_t, work_req)((uv_fs_t *) ((char *) (w) - __builtin_offsetof(uv_fs_t, work_req
)))
;
1759 uv__req_unregister(req->loop, req)do { ((void) sizeof ((((req->loop)->active_reqs.count >
0)) ? 1 : 0), __extension__ ({ if (((req->loop)->active_reqs
.count > 0)) ; else __assert_fail ("uv__has_active_reqs(req->loop)"
, "../deps/uv/src/unix/fs.c", 1759, __extension__ __PRETTY_FUNCTION__
); })); (req->loop)->active_reqs.count--; } while (0)
;
1760
1761 if (status == UV_ECANCELED) {
1762 assert(req->result == 0)((void) sizeof ((req->result == 0) ? 1 : 0), __extension__
({ if (req->result == 0) ; else __assert_fail ("req->result == 0"
, "../deps/uv/src/unix/fs.c", 1762, __extension__ __PRETTY_FUNCTION__
); }))
;
1763 req->result = UV_ECANCELED;
1764 }
1765
1766 req->cb(req);
1767}
1768
1769
1770int uv_fs_access(uv_loop_t* loop,
1771 uv_fs_t* req,
1772 const char* path,
1773 int flags,
1774 uv_fs_cb cb) {
1775 INIT(ACCESS)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_ACCESS; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1776 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 1776, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
1777 req->flags = flags;
1778 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1779}
1780
1781
1782int uv_fs_chmod(uv_loop_t* loop,
1783 uv_fs_t* req,
1784 const char* path,
1785 int mode,
1786 uv_fs_cb cb) {
1787 INIT(CHMOD)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_CHMOD; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1788 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 1788, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
1789 req->mode = mode;
1790 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1791}
1792
1793
1794int uv_fs_chown(uv_loop_t* loop,
1795 uv_fs_t* req,
1796 const char* path,
1797 uv_uid_t uid,
1798 uv_gid_t gid,
1799 uv_fs_cb cb) {
1800 INIT(CHOWN)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_CHOWN; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1801 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 1801, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
1802 req->uid = uid;
1803 req->gid = gid;
1804 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1805}
1806
1807
1808int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
1809 INIT(CLOSE)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_CLOSE; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1810 req->file = file;
1811 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1812}
1813
1814
1815int uv_fs_fchmod(uv_loop_t* loop,
1816 uv_fs_t* req,
1817 uv_file file,
1818 int mode,
1819 uv_fs_cb cb) {
1820 INIT(FCHMOD)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_FCHMOD; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1821 req->file = file;
1822 req->mode = mode;
1823 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1824}
1825
1826
1827int uv_fs_fchown(uv_loop_t* loop,
1828 uv_fs_t* req,
1829 uv_file file,
1830 uv_uid_t uid,
1831 uv_gid_t gid,
1832 uv_fs_cb cb) {
1833 INIT(FCHOWN)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_FCHOWN; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1834 req->file = file;
1835 req->uid = uid;
1836 req->gid = gid;
1837 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1838}
1839
1840
1841int uv_fs_lchown(uv_loop_t* loop,
1842 uv_fs_t* req,
1843 const char* path,
1844 uv_uid_t uid,
1845 uv_gid_t gid,
1846 uv_fs_cb cb) {
1847 INIT(LCHOWN)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_LCHOWN; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1848 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 1848, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
1849 req->uid = uid;
1850 req->gid = gid;
1851 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1852}
1853
1854
1855int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
1856 INIT(FDATASYNC)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_FDATASYNC
; req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
1857 req->file = file;
1858 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1859}
1860
1861
1862int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
1863 INIT(FSTAT)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_FSTAT; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1864 req->file = file;
1865 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1866}
1867
1868
1869int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
1870 INIT(FSYNC)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_FSYNC; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1871 req->file = file;
1872 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1873}
1874
1875
1876int uv_fs_ftruncate(uv_loop_t* loop,
1877 uv_fs_t* req,
1878 uv_file file,
1879 int64_t off,
1880 uv_fs_cb cb) {
1881 INIT(FTRUNCATE)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_FTRUNCATE
; req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
1882 req->file = file;
1883 req->off = off;
1884 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1885}
1886
1887
1888int uv_fs_futime(uv_loop_t* loop,
1889 uv_fs_t* req,
1890 uv_file file,
1891 double atime,
1892 double mtime,
1893 uv_fs_cb cb) {
1894 INIT(FUTIME)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_FUTIME; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1895 req->file = file;
1896 req->atime = atime;
1897 req->mtime = mtime;
1898 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1899}
1900
1901int uv_fs_lutime(uv_loop_t* loop,
1902 uv_fs_t* req,
1903 const char* path,
1904 double atime,
1905 double mtime,
1906 uv_fs_cb cb) {
1907 INIT(LUTIME)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_LUTIME; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1908 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 1908, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
1909 req->atime = atime;
1910 req->mtime = mtime;
1911 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1912}
1913
1914
1915int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
1916 INIT(LSTAT)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_LSTAT; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1917 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 1917, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
1918 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1919}
1920
1921
1922int uv_fs_link(uv_loop_t* loop,
1923 uv_fs_t* req,
1924 const char* path,
1925 const char* new_path,
1926 uv_fs_cb cb) {
1927 INIT(LINK)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_LINK; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1928 PATH2do { if (cb == ((void*)0)) { req->path = path; req->new_path
= new_path; } else { size_t path_len; size_t new_path_len; path_len
= strlen(path) + 1; new_path_len = strlen(new_path) + 1; req
->path = uv__malloc(path_len + new_path_len); if (req->
path == ((void*)0)) return UV_ENOMEM; req->new_path = req->
path + path_len; memcpy((void*) req->path, path, path_len)
; memcpy((void*) req->new_path, new_path, new_path_len); }
} while (0)
;
1929 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1930}
1931
1932
1933int uv_fs_mkdir(uv_loop_t* loop,
1934 uv_fs_t* req,
1935 const char* path,
1936 int mode,
1937 uv_fs_cb cb) {
1938 INIT(MKDIR)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_MKDIR; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1939 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 1939, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
1940 req->mode = mode;
1941 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1942}
1943
1944
1945int uv_fs_mkdtemp(uv_loop_t* loop,
1946 uv_fs_t* req,
1947 const char* tpl,
1948 uv_fs_cb cb) {
1949 INIT(MKDTEMP)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_MKDTEMP;
req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
1950 req->path = uv__strdup(tpl);
1951 if (req->path == NULL((void*)0))
1952 return UV_ENOMEM;
1953 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1954}
1955
1956
1957int uv_fs_mkstemp(uv_loop_t* loop,
1958 uv_fs_t* req,
1959 const char* tpl,
1960 uv_fs_cb cb) {
1961 INIT(MKSTEMP)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_MKSTEMP;
req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
1962 req->path = uv__strdup(tpl);
1963 if (req->path == NULL((void*)0))
1964 return UV_ENOMEM;
1965 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1966}
1967
1968
1969int uv_fs_open(uv_loop_t* loop,
1970 uv_fs_t* req,
1971 const char* path,
1972 int flags,
1973 int mode,
1974 uv_fs_cb cb) {
1975 INIT(OPEN)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_OPEN; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1976 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 1976, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
1977 req->flags = flags;
1978 req->mode = mode;
1979 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
1980}
1981
1982
1983int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
1984 uv_file file,
1985 const uv_buf_t bufs[],
1986 unsigned int nbufs,
1987 int64_t off,
1988 uv_fs_cb cb) {
1989 INIT(READ)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_READ; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
1990
1991 if (bufs == NULL((void*)0) || nbufs == 0)
1992 return UV_EINVAL;
1993
1994 req->file = file;
1995
1996 req->nbufs = nbufs;
1997 req->bufs = req->bufsml;
1998 if (nbufs > ARRAY_SIZE(req->bufsml)(sizeof(req->bufsml) / sizeof((req->bufsml)[0])))
1999 req->bufs = uv__malloc(nbufs * sizeof(*bufs));
2000
2001 if (req->bufs == NULL((void*)0))
2002 return UV_ENOMEM;
2003
2004 memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
2005
2006 req->off = off;
2007 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2008}
2009
2010
2011int uv_fs_scandir(uv_loop_t* loop,
2012 uv_fs_t* req,
2013 const char* path,
2014 int flags,
2015 uv_fs_cb cb) {
2016 INIT(SCANDIR)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_SCANDIR;
req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
2017 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 2017, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
2018 req->flags = flags;
2019 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2020}
2021
2022int uv_fs_opendir(uv_loop_t* loop,
2023 uv_fs_t* req,
2024 const char* path,
2025 uv_fs_cb cb) {
2026 INIT(OPENDIR)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_OPENDIR;
req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
2027 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 2027, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
2028 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2029}
2030
2031int uv_fs_readdir(uv_loop_t* loop,
2032 uv_fs_t* req,
2033 uv_dir_t* dir,
2034 uv_fs_cb cb) {
2035 INIT(READDIR)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_READDIR;
req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
2036
2037 if (dir == NULL((void*)0) || dir->dir == NULL((void*)0) || dir->dirents == NULL((void*)0))
2038 return UV_EINVAL;
2039
2040 req->ptr = dir;
2041 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2042}
2043
2044int uv_fs_closedir(uv_loop_t* loop,
2045 uv_fs_t* req,
2046 uv_dir_t* dir,
2047 uv_fs_cb cb) {
2048 INIT(CLOSEDIR)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_CLOSEDIR
; req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
2049
2050 if (dir == NULL((void*)0))
2051 return UV_EINVAL;
2052
2053 req->ptr = dir;
2054 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2055}
2056
2057int uv_fs_readlink(uv_loop_t* loop,
2058 uv_fs_t* req,
2059 const char* path,
2060 uv_fs_cb cb) {
2061 INIT(READLINK)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_READLINK
; req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
2062 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 2062, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
2063 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2064}
2065
2066
2067int uv_fs_realpath(uv_loop_t* loop,
2068 uv_fs_t* req,
2069 const char * path,
2070 uv_fs_cb cb) {
2071 INIT(REALPATH)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_REALPATH
; req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
2072 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 2072, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
2073 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2074}
2075
2076
2077int uv_fs_rename(uv_loop_t* loop,
2078 uv_fs_t* req,
2079 const char* path,
2080 const char* new_path,
2081 uv_fs_cb cb) {
2082 INIT(RENAME)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_RENAME; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
2083 PATH2do { if (cb == ((void*)0)) { req->path = path; req->new_path
= new_path; } else { size_t path_len; size_t new_path_len; path_len
= strlen(path) + 1; new_path_len = strlen(new_path) + 1; req
->path = uv__malloc(path_len + new_path_len); if (req->
path == ((void*)0)) return UV_ENOMEM; req->new_path = req->
path + path_len; memcpy((void*) req->path, path, path_len)
; memcpy((void*) req->new_path, new_path, new_path_len); }
} while (0)
;
2084 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2085}
2086
2087
2088int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
2089 INIT(RMDIR)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_RMDIR; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
2090 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 2090, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
2091 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2092}
2093
2094
2095int uv_fs_sendfile(uv_loop_t* loop,
2096 uv_fs_t* req,
2097 uv_file out_fd,
2098 uv_file in_fd,
2099 int64_t off,
2100 size_t len,
2101 uv_fs_cb cb) {
2102 INIT(SENDFILE)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_SENDFILE
; req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
2103 req->flags = in_fd; /* hack */
2104 req->file = out_fd;
2105 req->off = off;
2106 req->bufsml[0].len = len;
2107 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2108}
2109
2110
2111int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
2112 INIT(STAT)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_STAT; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
2113 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 2113, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
2114 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2115}
2116
2117
2118int uv_fs_symlink(uv_loop_t* loop,
2119 uv_fs_t* req,
2120 const char* path,
2121 const char* new_path,
2122 int flags,
2123 uv_fs_cb cb) {
2124 INIT(SYMLINK)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_SYMLINK;
req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
2125 PATH2do { if (cb == ((void*)0)) { req->path = path; req->new_path
= new_path; } else { size_t path_len; size_t new_path_len; path_len
= strlen(path) + 1; new_path_len = strlen(new_path) + 1; req
->path = uv__malloc(path_len + new_path_len); if (req->
path == ((void*)0)) return UV_ENOMEM; req->new_path = req->
path + path_len; memcpy((void*) req->path, path, path_len)
; memcpy((void*) req->new_path, new_path, new_path_len); }
} while (0)
;
2126 req->flags = flags;
2127 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2128}
2129
2130
2131int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
2132 INIT(UNLINK)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_UNLINK; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
2133 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 2133, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
2134 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2135}
2136
2137
2138int uv_fs_utime(uv_loop_t* loop,
2139 uv_fs_t* req,
2140 const char* path,
2141 double atime,
2142 double mtime,
2143 uv_fs_cb cb) {
2144 INIT(UTIME)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_UTIME; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
2145 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 2145, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
2146 req->atime = atime;
2147 req->mtime = mtime;
2148 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2149}
2150
2151
2152int uv_fs_write(uv_loop_t* loop,
2153 uv_fs_t* req,
2154 uv_file file,
2155 const uv_buf_t bufs[],
2156 unsigned int nbufs,
2157 int64_t off,
2158 uv_fs_cb cb) {
2159 INIT(WRITE)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_WRITE; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
2160
2161 if (bufs == NULL((void*)0) || nbufs == 0)
2162 return UV_EINVAL;
2163
2164 req->file = file;
2165
2166 req->nbufs = nbufs;
2167 req->bufs = req->bufsml;
2168 if (nbufs > ARRAY_SIZE(req->bufsml)(sizeof(req->bufsml) / sizeof((req->bufsml)[0])))
2169 req->bufs = uv__malloc(nbufs * sizeof(*bufs));
2170
2171 if (req->bufs == NULL((void*)0))
2172 return UV_ENOMEM;
2173
2174 memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
2175
2176 req->off = off;
2177 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2178}
2179
2180
2181void uv_fs_req_cleanup(uv_fs_t* req) {
2182 if (req == NULL((void*)0))
2183 return;
2184
2185 /* Only necessary for asychronous requests, i.e., requests with a callback.
2186 * Synchronous ones don't copy their arguments and have req->path and
2187 * req->new_path pointing to user-owned memory. UV_FS_MKDTEMP and
2188 * UV_FS_MKSTEMP are the exception to the rule, they always allocate memory.
2189 */
2190 if (req->path != NULL((void*)0) &&
2191 (req->cb != NULL((void*)0) ||
2192 req->fs_type == UV_FS_MKDTEMP || req->fs_type == UV_FS_MKSTEMP))
2193 uv__free((void*) req->path); /* Memory is shared with req->new_path. */
2194
2195 req->path = NULL((void*)0);
2196 req->new_path = NULL((void*)0);
2197
2198 if (req->fs_type == UV_FS_READDIR && req->ptr != NULL((void*)0))
2199 uv__fs_readdir_cleanup(req);
2200
2201 if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL((void*)0))
2202 uv__fs_scandir_cleanup(req);
2203
2204 if (req->bufs != req->bufsml)
2205 uv__free(req->bufs);
2206 req->bufs = NULL((void*)0);
2207
2208 if (req->fs_type != UV_FS_OPENDIR && req->ptr != &req->statbuf)
2209 uv__free(req->ptr);
2210 req->ptr = NULL((void*)0);
2211}
2212
2213
2214int uv_fs_copyfile(uv_loop_t* loop,
2215 uv_fs_t* req,
2216 const char* path,
2217 const char* new_path,
2218 int flags,
2219 uv_fs_cb cb) {
2220 INIT(COPYFILE)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_COPYFILE
; req->result = 0; req->ptr = ((void*)0); req->loop =
loop; req->path = ((void*)0); req->new_path = ((void*)
0); req->bufs = ((void*)0); req->cb = cb; } while (0)
;
2221
2222 if (flags & ~(UV_FS_COPYFILE_EXCL0x0001 |
2223 UV_FS_COPYFILE_FICLONE0x0002 |
2224 UV_FS_COPYFILE_FICLONE_FORCE0x0004)) {
2225 return UV_EINVAL;
2226 }
2227
2228 PATH2do { if (cb == ((void*)0)) { req->path = path; req->new_path
= new_path; } else { size_t path_len; size_t new_path_len; path_len
= strlen(path) + 1; new_path_len = strlen(new_path) + 1; req
->path = uv__malloc(path_len + new_path_len); if (req->
path == ((void*)0)) return UV_ENOMEM; req->new_path = req->
path + path_len; memcpy((void*) req->path, path, path_len)
; memcpy((void*) req->new_path, new_path, new_path_len); }
} while (0)
;
2229 req->flags = flags;
2230 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2231}
2232
2233
2234int uv_fs_statfs(uv_loop_t* loop,
2235 uv_fs_t* req,
2236 const char* path,
2237 uv_fs_cb cb) {
2238 INIT(STATFS)do { if (req == ((void*)0)) return UV_EINVAL; do { (req)->
type = (UV_FS); } while (0); req->fs_type = UV_FS_STATFS; req
->result = 0; req->ptr = ((void*)0); req->loop = loop
; req->path = ((void*)0); req->new_path = ((void*)0); req
->bufs = ((void*)0); req->cb = cb; } while (0)
;
2239 PATHdo { ((void) sizeof ((path != ((void*)0)) ? 1 : 0), __extension__
({ if (path != ((void*)0)) ; else __assert_fail ("path != NULL"
, "../deps/uv/src/unix/fs.c", 2239, __extension__ __PRETTY_FUNCTION__
); })); if (cb == ((void*)0)) { req->path = path; } else {
req->path = uv__strdup(path); if (req->path == ((void*
)0)) return UV_ENOMEM; } } while (0)
;
2240 POSTdo { if (cb != ((void*)0)) { do { (loop)->active_reqs.count
++; } while (0); uv__work_submit(loop, &req->work_req,
UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); return 0; } else
{ uv__fs_work(&req->work_req); return req->result;
} } while (0)
;
2241}
2242
2243int uv_fs_get_system_error(const uv_fs_t* req) {
2244 return -req->result;
2245}