From 6a9a81ddef01a7e209ce6c927f6def8428e06e68 Mon Sep 17 00:00:00 2001 From: Sahilll <150071026+sahilsharda@users.noreply.github.com> Date: Wed, 26 Nov 2025 02:23:05 +0530 Subject: [PATCH] fs-poll: mark fs_req as internal --- src/fs-poll.c | 135 +++-- src/unix/fs.c | 907 +++++++++++++-------------------- src/uv-common.h | 4 + src/win/fs.c | 1270 ++++++++++++++++++----------------------------- 4 files changed, 880 insertions(+), 1436 deletions(-) diff --git a/src/fs-poll.c b/src/fs-poll.c index 1fadafdea..36756aac6 100644 --- a/src/fs-poll.c +++ b/src/fs-poll.c @@ -19,12 +19,12 @@ * IN THE SOFTWARE. */ -#include "uv.h" #include "uv-common.h" +#include "uv.h" #ifdef _WIN32 -#include "win/internal.h" #include "win/handle-inl.h" +#include "win/internal.h" #define uv__make_close_pending(h) uv__want_endgame((h)->loop, (h)) #else #include "unix/internal.h" @@ -35,44 +35,40 @@ #include struct poll_ctx { - uv_fs_poll_t* parent_handle; + uv_fs_poll_t *parent_handle; int busy_polling; unsigned int interval; uint64_t start_time; - uv_loop_t* loop; + uv_loop_t *loop; uv_fs_poll_cb poll_cb; uv_timer_t timer_handle; uv_fs_t fs_req; /* TODO(bnoordhuis) mark fs_req internal */ uv_stat_t statbuf; - struct poll_ctx* previous; /* context from previous start()..stop() period */ - char path[1]; /* variable length */ + struct poll_ctx *previous; /* context from previous start()..stop() period */ + char path[1]; /* variable length */ }; -static int statbuf_eq(const uv_stat_t* a, const uv_stat_t* b); -static void poll_cb(uv_fs_t* req); -static void timer_cb(uv_timer_t* timer); -static void timer_close_cb(uv_handle_t* timer); +static int statbuf_eq(const uv_stat_t *a, const uv_stat_t *b); +static void poll_cb(uv_fs_t *req); +static void timer_cb(uv_timer_t *timer); +static void timer_close_cb(uv_handle_t *timer); static uv_stat_t zero_statbuf; - -int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle) { - uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_POLL); +int uv_fs_poll_init(uv_loop_t *loop, uv_fs_poll_t *handle) { + uv__handle_init(loop, (uv_handle_t *)handle, UV_FS_POLL); handle->poll_ctx = NULL; return 0; } - -int uv_fs_poll_start(uv_fs_poll_t* handle, - uv_fs_poll_cb cb, - const char* path, +int uv_fs_poll_start(uv_fs_poll_t *handle, uv_fs_poll_cb cb, const char *path, unsigned int interval) { - struct poll_ctx* ctx; - uv_loop_t* loop; + struct poll_ctx *ctx; + uv_loop_t *loop; size_t len; int err; - if (uv_is_active((uv_handle_t*)handle)) + if (uv_is_active((uv_handle_t *)handle)) return 0; loop = handle->loop; @@ -112,11 +108,10 @@ error: return err; } +int uv_fs_poll_stop(uv_fs_poll_t *handle) { + struct poll_ctx *ctx; -int uv_fs_poll_stop(uv_fs_poll_t* handle) { - struct poll_ctx* ctx; - - if (!uv_is_active((uv_handle_t*)handle)) + if (!uv_is_active((uv_handle_t *)handle)) return 0; ctx = handle->poll_ctx; @@ -126,23 +121,22 @@ int uv_fs_poll_stop(uv_fs_poll_t* handle) { /* Close the timer if it's active. If it's inactive, there's a stat request * in progress and poll_cb will take care of the cleanup. */ - if (uv_is_active((uv_handle_t*)&ctx->timer_handle)) - uv_close((uv_handle_t*)&ctx->timer_handle, timer_close_cb); + if (uv_is_active((uv_handle_t *)&ctx->timer_handle)) + uv_close((uv_handle_t *)&ctx->timer_handle, timer_close_cb); uv__handle_stop(handle); return 0; } - -int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buffer, size_t* size) { - struct poll_ctx* ctx; +int uv_fs_poll_getpath(uv_fs_poll_t *handle, char *buffer, size_t *size) { + struct poll_ctx *ctx; size_t required_len; if (buffer == NULL || size == NULL || *size == 0) return UV_EINVAL; - if (!uv_is_active((uv_handle_t*)handle)) { + if (!uv_is_active((uv_handle_t *)handle)) { *size = 0; return UV_EINVAL; } @@ -163,17 +157,15 @@ int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buffer, size_t* size) { return 0; } - -void uv__fs_poll_close(uv_fs_poll_t* handle) { +void uv__fs_poll_close(uv_fs_poll_t *handle) { uv_fs_poll_stop(handle); if (handle->poll_ctx == NULL) - uv__make_close_pending((uv_handle_t*)handle); + uv__make_close_pending((uv_handle_t *)handle); } - -static void timer_cb(uv_timer_t* timer) { - struct poll_ctx* ctx; +static void timer_cb(uv_timer_t *timer) { + struct poll_ctx *ctx; ctx = container_of(timer, struct poll_ctx, timer_handle); assert(ctx->parent_handle != NULL); @@ -182,26 +174,27 @@ static void timer_cb(uv_timer_t* timer) { if (uv_fs_stat(ctx->loop, &ctx->fs_req, ctx->path, poll_cb)) abort(); + + /* Mark fs_req as internal and unregister it. */ + ctx->fs_req.reserved[0] = (void *)UV__REQ_INTERNAL; + uv__req_unregister(ctx->loop); } - -static void poll_cb(uv_fs_t* req) { - uv_stat_t* statbuf; - struct poll_ctx* ctx; +static void poll_cb(uv_fs_t *req) { + uv_stat_t *statbuf; + struct poll_ctx *ctx; uint64_t interval; - uv_fs_poll_t* handle; + uv_fs_poll_t *handle; ctx = container_of(req, struct poll_ctx, fs_req); handle = ctx->parent_handle; - if (!uv_is_active((uv_handle_t*)handle) || uv__is_closing(handle)) + if (!uv_is_active((uv_handle_t *)handle) || uv__is_closing(handle)) goto out; if (req->result != 0) { if (ctx->busy_polling != req->result) { - ctx->poll_cb(ctx->parent_handle, - req->result, - &ctx->statbuf, + ctx->poll_cb(ctx->parent_handle, req->result, &ctx->statbuf, &zero_statbuf); ctx->busy_polling = req->result; } @@ -220,8 +213,8 @@ static void poll_cb(uv_fs_t* req) { out: uv_fs_req_cleanup(req); - if (!uv_is_active((uv_handle_t*)handle) || uv__is_closing(handle)) { - uv_close((uv_handle_t*)&ctx->timer_handle, timer_close_cb); + if (!uv_is_active((uv_handle_t *)handle) || uv__is_closing(handle)) { + uv_close((uv_handle_t *)&ctx->timer_handle, timer_close_cb); return; } @@ -233,22 +226,20 @@ out: abort(); } - -static void timer_close_cb(uv_handle_t* timer) { - struct poll_ctx* ctx; - struct poll_ctx* it; - struct poll_ctx* last; - uv_fs_poll_t* handle; +static void timer_close_cb(uv_handle_t *timer) { + struct poll_ctx *ctx; + struct poll_ctx *it; + struct poll_ctx *last; + uv_fs_poll_t *handle; ctx = container_of(timer, struct poll_ctx, timer_handle); handle = ctx->parent_handle; if (ctx == handle->poll_ctx) { handle->poll_ctx = ctx->previous; if (handle->poll_ctx == NULL && uv__is_closing(handle)) - uv__make_close_pending((uv_handle_t*)handle); + uv__make_close_pending((uv_handle_t *)handle); } else { - for (last = handle->poll_ctx, it = last->previous; - it != ctx; + for (last = handle->poll_ctx, it = last->previous; it != ctx; last = it, it = it->previous) { assert(last->previous != NULL); } @@ -257,31 +248,25 @@ static void timer_close_cb(uv_handle_t* timer) { uv__free(ctx); } - -static int statbuf_eq(const uv_stat_t* a, const uv_stat_t* b) { - return a->st_ctim.tv_nsec == b->st_ctim.tv_nsec - && a->st_mtim.tv_nsec == b->st_mtim.tv_nsec - && a->st_birthtim.tv_nsec == b->st_birthtim.tv_nsec - && a->st_ctim.tv_sec == b->st_ctim.tv_sec - && a->st_mtim.tv_sec == b->st_mtim.tv_sec - && a->st_birthtim.tv_sec == b->st_birthtim.tv_sec - && a->st_size == b->st_size - && a->st_mode == b->st_mode - && a->st_uid == b->st_uid - && a->st_gid == b->st_gid - && a->st_ino == b->st_ino - && a->st_dev == b->st_dev - && a->st_flags == b->st_flags - && a->st_gen == b->st_gen; +static int statbuf_eq(const uv_stat_t *a, const uv_stat_t *b) { + return a->st_ctim.tv_nsec == b->st_ctim.tv_nsec && + a->st_mtim.tv_nsec == b->st_mtim.tv_nsec && + a->st_birthtim.tv_nsec == b->st_birthtim.tv_nsec && + a->st_ctim.tv_sec == b->st_ctim.tv_sec && + a->st_mtim.tv_sec == b->st_mtim.tv_sec && + a->st_birthtim.tv_sec == b->st_birthtim.tv_sec && + a->st_size == b->st_size && a->st_mode == b->st_mode && + a->st_uid == b->st_uid && a->st_gid == b->st_gid && + a->st_ino == b->st_ino && a->st_dev == b->st_dev && + a->st_flags == b->st_flags && a->st_gen == b->st_gen; } - #if defined(_WIN32) -#include "win/internal.h" #include "win/handle-inl.h" +#include "win/internal.h" -void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle) { +void uv__fs_poll_endgame(uv_loop_t *loop, uv_fs_poll_t *handle) { assert(handle->flags & UV_HANDLE_CLOSING); assert(!(handle->flags & UV_HANDLE_CLOSED)); uv__handle_close(handle); diff --git a/src/unix/fs.c b/src/unix/fs.c index bd3f59628..6d93a0078 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -26,134 +26,120 @@ * getting the errno to the right place (req->result or as the return value.) */ -#include "uv.h" #include "internal.h" +#include "uv.h" -#include #include +#include +#include /* PATH_MAX */ #include #include #include #include -#include /* PATH_MAX */ -#include +#include +#include #include #include #include +#include #include #include -#include -#include #if defined(__linux__) -# include +#include #endif #if defined(__sun) -# include -# include +#include +#include #endif #if defined(__APPLE__) -# include +#include #elif defined(__linux__) && !defined(FICLONE) -# include -# define FICLONE _IOW(0x94, 9, int) +#include +#define FICLONE _IOW(0x94, 9, int) #endif #if defined(_AIX) && !defined(_AIX71) -# include +#include #endif -#if defined(__APPLE__) || \ - defined(__DragonFly__) || \ - defined(__FreeBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) -# include -# include -#elif defined(__sun) || \ - defined(__MVS__) || \ - defined(__NetBSD__) || \ - defined(__HAIKU__) || \ - defined(__QNX__) -# include +#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \ + defined(__OpenBSD__) || defined(__NetBSD__) +#include +#include +#elif defined(__sun) || defined(__MVS__) || defined(__NetBSD__) || \ + defined(__HAIKU__) || defined(__QNX__) +#include #else -# include +#include #endif #if defined(_AIX) && _XOPEN_SOURCE <= 600 extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */ #endif -#define INIT(subtype) \ - do { \ - if (req == NULL) \ - return UV_EINVAL; \ - UV_REQ_INIT(req, UV_FS); \ - req->fs_type = UV_FS_ ## subtype; \ - req->result = 0; \ - req->ptr = NULL; \ - req->loop = loop; \ - req->path = NULL; \ - req->new_path = NULL; \ - req->bufs = NULL; \ - req->cb = cb; \ - } \ - while (0) +#define INIT(subtype) \ + do { \ + if (req == NULL) \ + return UV_EINVAL; \ + UV_REQ_INIT(req, UV_FS); \ + req->fs_type = UV_FS_##subtype; \ + req->result = 0; \ + req->ptr = NULL; \ + req->loop = loop; \ + req->path = NULL; \ + req->new_path = NULL; \ + req->bufs = NULL; \ + req->cb = cb; \ + req->reserved[0] = NULL; \ + } while (0) -#define PATH \ - do { \ - assert(path != NULL); \ - if (cb == NULL) { \ - req->path = path; \ - } else { \ - req->path = uv__strdup(path); \ - if (req->path == NULL) \ - return UV_ENOMEM; \ - } \ - } \ - while (0) +#define PATH \ + do { \ + assert(path != NULL); \ + if (cb == NULL) { \ + req->path = path; \ + } else { \ + req->path = uv__strdup(path); \ + if (req->path == NULL) \ + return UV_ENOMEM; \ + } \ + } while (0) -#define PATH2 \ - do { \ - if (cb == NULL) { \ - 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 == NULL) \ - 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) - -#define POST \ - do { \ - if (cb != NULL) { \ - uv__req_register(loop); \ - 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) +#define PATH2 \ + do { \ + if (cb == NULL) { \ + 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 == NULL) \ + 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) +#define POST \ + do { \ + if (cb != NULL) { \ + uv__req_register(loop); \ + 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) static int uv__fs_close(int fd) { int rc; @@ -161,13 +147,12 @@ static int uv__fs_close(int fd) { rc = uv__close_nocancel(fd); if (rc == -1) if (errno == EINTR || errno == EINPROGRESS) - rc = 0; /* The close is in progress, not an error. */ + rc = 0; /* The close is in progress, not an error. */ return rc; } - -static ssize_t uv__fs_fsync(uv_fs_t* req) { +static ssize_t uv__fs_fsync(uv_fs_t *req) { #if defined(__APPLE__) /* Apple's fdatasync and fsync explicitly do NOT flush the drive write cache * to the drive platters. This is in contrast to Linux's fdatasync and fsync @@ -181,7 +166,7 @@ static ssize_t uv__fs_fsync(uv_fs_t* req) { r = fcntl(req->file, F_FULLFSYNC); if (r != 0) - r = fcntl(req->file, 85 /* F_BARRIERFSYNC */); /* fsync + barrier */ + r = fcntl(req->file, 85 /* F_BARRIERFSYNC */); /* fsync + barrier */ if (r != 0) r = fsync(req->file); return r; @@ -190,8 +175,7 @@ static ssize_t uv__fs_fsync(uv_fs_t* req) { #endif } - -static ssize_t uv__fs_fdatasync(uv_fs_t* req) { +static ssize_t uv__fs_fdatasync(uv_fs_t *req) { #if defined(__linux__) || defined(__sun) || defined(__NetBSD__) return fdatasync(req->file); #elif defined(__APPLE__) @@ -202,17 +186,10 @@ static ssize_t uv__fs_fdatasync(uv_fs_t* req) { #endif } - -#if defined(__APPLE__) \ - || defined(_AIX71) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) \ - || defined(__HAIKU__) \ - || defined(__NetBSD__) \ - || defined(__OpenBSD__) \ - || defined(__linux__) \ - || defined(__sun) \ - || defined(__QNX__) +#if defined(__APPLE__) || defined(_AIX71) || defined(__DragonFly__) || \ + defined(__FreeBSD__) || defined(__HAIKU__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__linux__) || defined(__sun) || \ + defined(__QNX__) static struct timespec uv__fs_to_timespec(double time) { struct timespec ts; @@ -221,14 +198,14 @@ static struct timespec uv__fs_to_timespec(double time) { if (uv__isnan(time)) return (struct timespec){UTIME_OMIT, UTIME_OMIT}; - ts.tv_sec = time; + ts.tv_sec = time; ts.tv_nsec = (time - ts.tv_sec) * 1e9; - /* TODO(bnoordhuis) Remove this. utimesat() has nanosecond resolution but we - * stick to microsecond resolution for the sake of consistency with other - * platforms. I'm the original author of this compatibility hack but I'm - * less convinced it's useful nowadays. - */ + /* TODO(bnoordhuis) Remove this. utimesat() has nanosecond resolution but we + * stick to microsecond resolution for the sake of consistency with other + * platforms. I'm the original author of this compatibility hack but I'm + * less convinced it's useful nowadays. + */ ts.tv_nsec -= ts.tv_nsec % 1000; if (ts.tv_nsec < 0) { @@ -239,18 +216,11 @@ static struct timespec uv__fs_to_timespec(double time) { } #endif - -static ssize_t uv__fs_futime(uv_fs_t* req) { -#if defined(__APPLE__) \ - || defined(_AIX71) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) \ - || defined(__HAIKU__) \ - || defined(__NetBSD__) \ - || defined(__OpenBSD__) \ - || defined(__linux__) \ - || defined(__sun) \ - || defined(__QNX__) +static ssize_t uv__fs_futime(uv_fs_t *req) { +#if defined(__APPLE__) || defined(_AIX71) || defined(__DragonFly__) || \ + defined(__FreeBSD__) || defined(__HAIKU__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__linux__) || defined(__sun) || \ + defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -269,32 +239,28 @@ static ssize_t uv__fs_futime(uv_fs_t* req) { #endif } - -static ssize_t uv__fs_mkdtemp(uv_fs_t* req) { - return mkdtemp((char*) req->path) ? 0 : -1; +static ssize_t uv__fs_mkdtemp(uv_fs_t *req) { + return mkdtemp((char *)req->path) ? 0 : -1; } - -static int (*uv__mkostemp)(char*, int); - +static int (*uv__mkostemp)(char *, int); static void uv__mkostemp_initonce(void) { /* z/os doesn't have RTLD_DEFAULT but that's okay * because it doesn't have mkostemp(O_CLOEXEC) either. */ #ifdef RTLD_DEFAULT - uv__mkostemp = (int (*)(char*, int)) dlsym(RTLD_DEFAULT, "mkostemp"); + uv__mkostemp = (int (*)(char *, int))dlsym(RTLD_DEFAULT, "mkostemp"); /* We don't care about errors, but we do want to clean them up. * If there has been no error, then dlerror() will just return * NULL. */ dlerror(); -#endif /* RTLD_DEFAULT */ +#endif /* RTLD_DEFAULT */ } - -static int uv__fs_mkstemp(uv_fs_t* req) { +static int uv__fs_mkstemp(uv_fs_t *req) { static uv_once_t once = UV_ONCE_INIT; int r; #ifdef O_CLOEXEC @@ -302,10 +268,10 @@ static int uv__fs_mkstemp(uv_fs_t* req) { #endif static const char pattern[] = "XXXXXX"; static const size_t pattern_size = sizeof(pattern) - 1; - char* path; + char *path; size_t path_length; - path = (char*) req->path; + path = (char *)req->path; path_length = strlen(path); /* EINVAL can be returned for 2 reasons: @@ -339,7 +305,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) { try to use mkostemp. */ atomic_store_explicit(&no_cloexec_support, 1, memory_order_relaxed); } -#endif /* O_CLOEXEC */ +#endif /* O_CLOEXEC */ if (req->cb != NULL) uv_rwlock_rdlock(&req->loop->cloexec_lock); @@ -365,8 +331,7 @@ clobber: return r; } - -static ssize_t uv__fs_open(uv_fs_t* req) { +static ssize_t uv__fs_open(uv_fs_t *req) { #ifdef O_CLOEXEC return open(req->path, req->flags | O_CLOEXEC, req->mode); #else /* O_CLOEXEC */ @@ -391,23 +356,20 @@ static ssize_t uv__fs_open(uv_fs_t* req) { uv_rwlock_rdunlock(&req->loop->cloexec_lock); return r; -#endif /* O_CLOEXEC */ +#endif /* O_CLOEXEC */ } - -static ssize_t uv__preadv_or_pwritev_emul(int fd, - const struct iovec* bufs, - size_t nbufs, - off_t off, +static ssize_t uv__preadv_or_pwritev_emul(int fd, const struct iovec *bufs, + size_t nbufs, off_t off, int is_pread) { ssize_t total; ssize_t r; size_t i; size_t n; - void* p; + void *p; total = 0; - for (i = 0; i < (size_t) nbufs; i++) { + for (i = 0; i < (size_t)nbufs; i++) { p = bufs[i].iov_base; n = bufs[i].iov_len; @@ -427,50 +389,39 @@ static ssize_t uv__preadv_or_pwritev_emul(int fd, off += r; total += r; - if ((size_t) r < n) + if ((size_t)r < n) return total; } return total; } - #ifdef __linux__ typedef int uv__iovcnt; #else typedef size_t uv__iovcnt; #endif - -static ssize_t uv__preadv_emul(int fd, - const struct iovec* bufs, - uv__iovcnt nbufs, - off_t off) { - return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/1); +static ssize_t uv__preadv_emul(int fd, const struct iovec *bufs, + uv__iovcnt nbufs, off_t off) { + return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/ 1); } - -static ssize_t uv__pwritev_emul(int fd, - const struct iovec* bufs, - uv__iovcnt nbufs, - off_t off) { - return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/0); +static ssize_t uv__pwritev_emul(int fd, const struct iovec *bufs, + uv__iovcnt nbufs, off_t off) { + return uv__preadv_or_pwritev_emul(fd, bufs, nbufs, off, /*is_pread*/ 0); } - /* The function pointer cache is an uintptr_t because _Atomic void* * doesn't work on macos/ios/etc... */ -static ssize_t uv__preadv_or_pwritev(int fd, - const struct iovec* bufs, - size_t nbufs, - off_t off, - _Atomic uintptr_t* cache, - int is_pread) { - ssize_t (*f)(int, const struct iovec*, uv__iovcnt, off_t); - void* p; +static ssize_t uv__preadv_or_pwritev(int fd, const struct iovec *bufs, + size_t nbufs, off_t off, + _Atomic uintptr_t *cache, int is_pread) { + ssize_t (*f)(int, const struct iovec *, uv__iovcnt, off_t); + void *p; - p = (void*) atomic_load_explicit(cache, memory_order_relaxed); + p = (void *)atomic_load_explicit(cache, memory_order_relaxed); if (p == NULL) { #ifdef RTLD_DEFAULT /* Try _LARGEFILE_SOURCE version of preadv/pwritev first, @@ -479,38 +430,31 @@ static ssize_t uv__preadv_or_pwritev(int fd, p = dlsym(RTLD_DEFAULT, is_pread ? "preadv64" : "pwritev64"); if (p == NULL) p = dlsym(RTLD_DEFAULT, is_pread ? "preadv" : "pwritev"); - dlerror(); /* Clear errors. */ -#endif /* RTLD_DEFAULT */ + dlerror(); /* Clear errors. */ +#endif /* RTLD_DEFAULT */ if (p == NULL) p = is_pread ? uv__preadv_emul : uv__pwritev_emul; - atomic_store_explicit(cache, (uintptr_t) p, memory_order_relaxed); + atomic_store_explicit(cache, (uintptr_t)p, memory_order_relaxed); } f = p; return f(fd, bufs, nbufs, off); } - -static ssize_t uv__preadv(int fd, - const struct iovec* bufs, - size_t nbufs, +static ssize_t uv__preadv(int fd, const struct iovec *bufs, size_t nbufs, off_t off) { static _Atomic uintptr_t cache; - return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/1); + return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/ 1); } - -static ssize_t uv__pwritev(int fd, - const struct iovec* bufs, - size_t nbufs, +static ssize_t uv__pwritev(int fd, const struct iovec *bufs, size_t nbufs, off_t off) { static _Atomic uintptr_t cache; - return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/0); + return uv__preadv_or_pwritev(fd, bufs, nbufs, off, &cache, /*is_pread*/ 0); } - -static ssize_t uv__fs_read(uv_fs_t* req) { - const struct iovec* bufs; +static ssize_t uv__fs_read(uv_fs_t *req) { + const struct iovec *bufs; unsigned int iovmax; size_t nbufs; ssize_t r; @@ -519,7 +463,7 @@ static ssize_t uv__fs_read(uv_fs_t* req) { fd = req->file; off = req->off; - bufs = (const struct iovec*) req->bufs; + bufs = (const struct iovec *)req->bufs; nbufs = req->nbufs; iovmax = uv__getiovmax(); @@ -562,19 +506,16 @@ static ssize_t uv__fs_read(uv_fs_t* req) { return r; } - -static int uv__fs_scandir_filter(const uv__dirent_t* dent) { +static int uv__fs_scandir_filter(const uv__dirent_t *dent) { return strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0; } - -static int uv__fs_scandir_sort(const uv__dirent_t** a, const uv__dirent_t** b) { +static int uv__fs_scandir_sort(const uv__dirent_t **a, const uv__dirent_t **b) { return strcmp((*a)->d_name, (*b)->d_name); } - -static ssize_t uv__fs_scandir(uv_fs_t* req) { - uv__dirent_t** dents; +static ssize_t uv__fs_scandir(uv_fs_t *req) { + uv__dirent_t **dents; int n; dents = NULL; @@ -598,8 +539,8 @@ static ssize_t uv__fs_scandir(uv_fs_t* req) { return n; } -static int uv__fs_opendir(uv_fs_t* req) { - uv_dir_t* dir; +static int uv__fs_opendir(uv_fs_t *req) { + uv_dir_t *dir; dir = uv__malloc(sizeof(*dir)); if (dir == NULL) @@ -618,10 +559,10 @@ error: return -1; } -static int uv__fs_readdir(uv_fs_t* req) { - uv_dir_t* dir; - uv_dirent_t* dirent; - struct dirent* res; +static int uv__fs_readdir(uv_fs_t *req) { + uv_dir_t *dir; + uv_dirent_t *dirent; + struct dirent *res; unsigned int dirent_idx; unsigned int i; @@ -657,15 +598,15 @@ static int uv__fs_readdir(uv_fs_t* req) { error: for (i = 0; i < dirent_idx; ++i) { - uv__free((char*) dir->dirents[i].name); + uv__free((char *)dir->dirents[i].name); dir->dirents[i].name = NULL; } return -1; } -static int uv__fs_closedir(uv_fs_t* req) { - uv_dir_t* dir; +static int uv__fs_closedir(uv_fs_t *req) { + uv_dir_t *dir; dir = req->ptr; @@ -679,13 +620,10 @@ static int uv__fs_closedir(uv_fs_t* req) { return 0; } -static int uv__fs_statfs(uv_fs_t* req) { - uv_statfs_t* stat_fs; -#if defined(__sun) || \ - defined(__MVS__) || \ - defined(__NetBSD__) || \ - defined(__HAIKU__) || \ - defined(__QNX__) +static int uv__fs_statfs(uv_fs_t *req) { + uv_statfs_t *stat_fs; +#if defined(__sun) || defined(__MVS__) || defined(__NetBSD__) || \ + defined(__HAIKU__) || defined(__QNX__) struct statvfs buf; if (0 != statvfs(req->path, &buf)) @@ -702,13 +640,9 @@ static int uv__fs_statfs(uv_fs_t* req) { return -1; } -#if defined(__sun) || \ - defined(__MVS__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) || \ - defined(__HAIKU__) || \ - defined(__QNX__) - stat_fs->f_type = 0; /* f_type is not supported. */ +#if defined(__sun) || defined(__MVS__) || defined(__OpenBSD__) || \ + defined(__NetBSD__) || defined(__HAIKU__) || defined(__QNX__) + stat_fs->f_type = 0; /* f_type is not supported. */ #else stat_fs->f_type = buf.f_type; #endif @@ -722,7 +656,7 @@ static int uv__fs_statfs(uv_fs_t* req) { return 0; } -static ssize_t uv__fs_pathmax_size(const char* path) { +static ssize_t uv__fs_pathmax_size(const char *path) { ssize_t pathmax; pathmax = pathconf(path, _PC_PATH_MAX); @@ -733,10 +667,10 @@ static ssize_t uv__fs_pathmax_size(const char* path) { return pathmax; } -static ssize_t uv__fs_readlink(uv_fs_t* req) { +static ssize_t uv__fs_readlink(uv_fs_t *req) { ssize_t maxlen; ssize_t len; - char* buf; + char *buf; #if defined(_POSIX_PATH_MAX) || defined(PATH_MAX) maxlen = uv__fs_pathmax_size(req->path); @@ -792,9 +726,9 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) { return 0; } -static ssize_t uv__fs_realpath(uv_fs_t* req) { - char* buf; - char* tmp; +static ssize_t uv__fs_realpath(uv_fs_t *req) { + char *buf; + char *tmp; #if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L tmp = realpath(req->path, NULL); @@ -830,7 +764,7 @@ static ssize_t uv__fs_realpath(uv_fs_t* req) { return 0; } -static ssize_t uv__fs_sendfile_emul(uv_fs_t* req) { +static ssize_t uv__fs_sendfile_emul(uv_fs_t *req) { struct pollfd pfd; int use_pread; off_t offset; @@ -874,7 +808,7 @@ static ssize_t uv__fs_sendfile_emul(uv_fs_t* req) { * FIXME: There is no way now to signal that we managed to send *some* data * before a write error. */ - for (nsent = 0; (size_t) nsent < len; ) { + for (nsent = 0; (size_t)nsent < len;) { buflen = len - nsent; if (buflen > sizeof(buf)) @@ -902,7 +836,7 @@ static ssize_t uv__fs_sendfile_emul(uv_fs_t* req) { goto out; } - for (nwritten = 0; nwritten < nread; ) { + for (nwritten = 0; nwritten < nread;) { do n = write(out_fd, buf + nwritten, nread - nwritten); while (n == -1 && errno == EINTR); @@ -943,7 +877,6 @@ out: return nsent; } - #ifdef __linux__ /* Pre-4.20 kernels have a bug where CephFS uses the RADOS copy-from command * in copy_file_range() when it shouldn't. There is no workaround except to @@ -961,26 +894,24 @@ static int uv__is_buggy_cephfs(int fd) { return uv__kernel_version() < /* 4.20.0 */ 0x041400; } - static int uv__is_cifs_or_smb(int fd) { struct statfs s; if (-1 == fstatfs(fd, &s)) return 0; - switch ((unsigned) s.f_type) { - case 0x0000517Bu: /* SMB */ - case 0xFE534D42u: /* SMB2 */ - case 0xFF534D42u: /* CIFS */ + switch ((unsigned)s.f_type) { + case 0x0000517Bu: /* SMB */ + case 0xFE534D42u: /* SMB2 */ + case 0xFF534D42u: /* CIFS */ return 1; } return 0; } - -static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off, - int out_fd, size_t len) { +static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t *off, int out_fd, + size_t len) { static _Atomic int no_copy_file_range_support; ssize_t r; @@ -1000,7 +931,7 @@ static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off, * copy-from command when it shouldn't. */ if (uv__is_buggy_cephfs(in_fd)) - errno = ENOSYS; /* Use fallback. */ + errno = ENOSYS; /* Use fallback. */ break; case ENOSYS: atomic_store_explicit(&no_copy_file_range_support, 1, memory_order_relaxed); @@ -1010,7 +941,7 @@ static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off, * Consider it a transient error. */ if (uv__is_cifs_or_smb(out_fd)) - errno = ENOSYS; /* Use fallback. */ + errno = ENOSYS; /* Use fallback. */ break; case ENOTSUP: case EXDEV: @@ -1018,17 +949,16 @@ static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off, * EXDEV - it will not work when in_fd and out_fd are not on the same * mounted filesystem (pre Linux 5.3) */ - errno = ENOSYS; /* Use fallback. */ + errno = ENOSYS; /* Use fallback. */ break; } return -1; } -#endif /* __linux__ */ +#endif /* __linux__ */ - -static ssize_t uv__fs_sendfile(uv_fs_t* req) { +static ssize_t uv__fs_sendfile(uv_fs_t *req) { int in_fd; int out_fd; @@ -1064,9 +994,7 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { return r; } - if (errno == EINVAL || - errno == EIO || - errno == ENOTSOCK || + if (errno == EINVAL || errno == EIO || errno == ENOTSOCK || errno == EXDEV) { errno = 0; return uv__fs_sendfile_emul(req); @@ -1075,9 +1003,8 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { return -1; } /* sendfile() on iOS(arm64) will throw SIGSYS signal cause crash. */ -#elif (defined(__APPLE__) && !TARGET_OS_IPHONE) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) +#elif (defined(__APPLE__) && !TARGET_OS_IPHONE) || defined(__DragonFly__) || \ + defined(__FreeBSD__) { off_t len; ssize_t r; @@ -1092,11 +1019,12 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { off_t off; off = req->off; - r = uv__fs_copy_file_range(in_fd, &off, out_fd, NULL, req->bufsml[0].len, 0); + r = uv__fs_copy_file_range(in_fd, &off, out_fd, NULL, req->bufsml[0].len, + 0); if (r >= 0) { - r = off - req->off; - req->off = off; - return r; + r = off - req->off; + req->off = off; + return r; } #endif len = 0; @@ -1108,7 +1036,7 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { r = sendfile(in_fd, out_fd, req->off, &len, NULL, 0); #endif - /* + /* * The man page for sendfile(2) on DragonFly states that `len` contains * a meaningful value ONLY in case of EAGAIN and EINTR. * Nothing is said about it's value in case of other errors, so better @@ -1117,12 +1045,10 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { */ if (r == 0 || ((errno == EAGAIN || errno == EINTR) && len != 0)) { req->off += len; - return (ssize_t) len; + return (ssize_t)len; } - if (errno == EINVAL || - errno == EIO || - errno == ENOTSOCK || + if (errno == EINVAL || errno == EIO || errno == ENOTSOCK || errno == EXDEV) { errno = 0; return uv__fs_sendfile_emul(req); @@ -1132,25 +1058,18 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) { } #else /* Squelch compiler warnings. */ - (void) &in_fd; - (void) &out_fd; + (void)&in_fd; + (void)&out_fd; return uv__fs_sendfile_emul(req); #endif } - -static ssize_t uv__fs_utime(uv_fs_t* req) { -#if defined(__APPLE__) \ - || defined(_AIX71) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) \ - || defined(__HAIKU__) \ - || defined(__NetBSD__) \ - || defined(__OpenBSD__) \ - || defined(__linux__) \ - || defined(__sun) \ - || defined(__QNX__) +static ssize_t uv__fs_utime(uv_fs_t *req) { +#if defined(__APPLE__) || defined(_AIX71) || defined(__DragonFly__) || \ + defined(__FreeBSD__) || defined(__HAIKU__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__linux__) || defined(__sun) || \ + defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -1167,25 +1086,18 @@ static ssize_t uv__fs_utime(uv_fs_t* req) { atr.att_atimechg = 1; atr.att_mtime = req->mtime; atr.att_atime = req->atime; - return __lchattr((char*) req->path, &atr, sizeof(atr)); + return __lchattr((char *)req->path, &atr, sizeof(atr)); #else errno = ENOSYS; return -1; #endif } - -static ssize_t uv__fs_lutime(uv_fs_t* req) { -#if defined(__APPLE__) \ - || defined(_AIX71) \ - || defined(__DragonFly__) \ - || defined(__FreeBSD__) \ - || defined(__HAIKU__) \ - || defined(__NetBSD__) \ - || defined(__OpenBSD__) \ - || defined(__linux__) \ - || defined(__sun) \ - || defined(__QNX__) +static ssize_t uv__fs_lutime(uv_fs_t *req) { +#if defined(__APPLE__) || defined(_AIX71) || defined(__DragonFly__) || \ + defined(__FreeBSD__) || defined(__HAIKU__) || defined(__NetBSD__) || \ + defined(__OpenBSD__) || defined(__linux__) || defined(__sun) || \ + defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -1196,9 +1108,8 @@ static ssize_t uv__fs_lutime(uv_fs_t* req) { #endif } - -static ssize_t uv__fs_write(uv_fs_t* req) { - const struct iovec* bufs; +static ssize_t uv__fs_write(uv_fs_t *req) { + const struct iovec *bufs; size_t nbufs; ssize_t r; off_t off; @@ -1206,7 +1117,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) { fd = req->file; off = req->off; - bufs = (const struct iovec*) req->bufs; + bufs = (const struct iovec *)req->bufs; nbufs = req->nbufs; r = 0; @@ -1225,8 +1136,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) { return r; } - -static ssize_t uv__fs_copyfile(uv_fs_t* req) { +static ssize_t uv__fs_copyfile(uv_fs_t *req) { uv_fs_t fs_req; uv_file srcfd; uv_file dstfd; @@ -1263,12 +1173,8 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { dst_flags |= O_EXCL; /* Open the destination file. */ - dstfd = uv_fs_open(NULL, - &fs_req, - req->new_path, - dst_flags, - src_statsbuf.st_mode, - NULL); + dstfd = uv_fs_open(NULL, &fs_req, req->new_path, dst_flags, + src_statsbuf.st_mode, NULL); uv_fs_req_cleanup(&fs_req); if (dstfd < 0) { @@ -1355,7 +1261,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { err = 0; #else /* !__linux__ */ goto out; -#endif /* !__linux__ */ +#endif /* !__linux__ */ } #ifdef FICLONE @@ -1383,7 +1289,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { in_offset = 0; while (bytes_to_send != 0) { bytes_chunk = SSIZE_MAX; - if (bytes_to_send < (off_t) bytes_chunk) + if (bytes_to_send < (off_t)bytes_chunk) bytes_chunk = bytes_to_send; uv_fs_sendfile(NULL, &fs_req, dstfd, srcfd, in_offset, bytes_chunk, NULL); bytes_written = fs_req.result; @@ -1434,7 +1340,7 @@ out: return -1; } -static void uv__to_stat(struct stat* src, uv_stat_t* dst) { +static void uv__to_stat(struct stat *src, uv_stat_t *dst) { dst->st_dev = src->st_dev; dst->st_mode = src->st_mode; dst->st_nlink = src->st_nlink; @@ -1468,35 +1374,28 @@ static void uv__to_stat(struct stat* src, uv_stat_t* dst) { dst->st_birthtim.tv_nsec = src->st_ctimensec; dst->st_flags = 0; dst->st_gen = 0; -#elif !defined(_AIX) && \ - !defined(__MVS__) && ( \ - defined(__DragonFly__) || \ - defined(__FreeBSD__) || \ - defined(__OpenBSD__) || \ - defined(__NetBSD__) || \ - defined(_GNU_SOURCE) || \ - defined(_BSD_SOURCE) || \ - defined(_SVID_SOURCE) || \ - defined(_XOPEN_SOURCE) || \ - defined(_DEFAULT_SOURCE)) +#elif !defined(_AIX) && !defined(__MVS__) && \ + (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ + defined(__NetBSD__) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \ + defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE) || \ + defined(_DEFAULT_SOURCE)) dst->st_atim.tv_sec = src->st_atim.tv_sec; dst->st_atim.tv_nsec = src->st_atim.tv_nsec; dst->st_mtim.tv_sec = src->st_mtim.tv_sec; dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec; dst->st_ctim.tv_sec = src->st_ctim.tv_sec; dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec; -# if defined(__FreeBSD__) || \ - defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) dst->st_birthtim.tv_sec = src->st_birthtim.tv_sec; dst->st_birthtim.tv_nsec = src->st_birthtim.tv_nsec; dst->st_flags = src->st_flags; dst->st_gen = src->st_gen; -# else +#else dst->st_birthtim.tv_sec = src->st_ctim.tv_sec; dst->st_birthtim.tv_nsec = src->st_ctim.tv_nsec; dst->st_flags = 0; dst->st_gen = 0; -# endif +#endif #else dst->st_atim.tv_sec = src->st_atime; dst->st_atim.tv_nsec = 0; @@ -1511,12 +1410,8 @@ static void uv__to_stat(struct stat* src, uv_stat_t* dst) { #endif } - -static int uv__fs_statx(int fd, - const char* path, - int is_fstat, - int is_lstat, - uv_stat_t* buf) { +static int uv__fs_statx(int fd, const char *path, int is_fstat, int is_lstat, + uv_stat_t *buf) { STATIC_ASSERT(UV_ENOSYS != -1); #ifdef __linux__ static _Atomic int no_statx; @@ -1530,7 +1425,7 @@ static int uv__fs_statx(int fd, return UV_ENOSYS; dirfd = AT_FDCWD; - flags = 0; /* AT_STATX_SYNC_AS_STAT */ + flags = 0; /* AT_STATX_SYNC_AS_STAT */ mode = 0xFFF; /* STATX_BASIC_STATS + STATX_BTIME */ if (is_fstat) { @@ -1551,7 +1446,8 @@ static int uv__fs_statx(int fd, * Has been observed with libseccomp < 2.3.3 and docker < 18.04. * EOPNOTSUPP is used on DVS exported filesystems */ - if (errno != EINVAL && errno != EPERM && errno != ENOSYS && errno != EOPNOTSUPP) + if (errno != EINVAL && errno != EPERM && errno != ENOSYS && + errno != EOPNOTSUPP) return -1; /* Fall through. */ default: @@ -1572,7 +1468,6 @@ static int uv__fs_statx(int fd, #endif /* __linux__ */ } - static int uv__fs_stat(const char *path, uv_stat_t *buf) { struct stat pbuf; int ret; @@ -1588,7 +1483,6 @@ static int uv__fs_stat(const char *path, uv_stat_t *buf) { return ret; } - static int uv__fs_lstat(const char *path, uv_stat_t *buf) { struct stat pbuf; int ret; @@ -1604,7 +1498,6 @@ static int uv__fs_lstat(const char *path, uv_stat_t *buf) { return ret; } - static int uv__fs_fstat(int fd, uv_stat_t *buf) { struct stat pbuf; int ret; @@ -1620,7 +1513,7 @@ static int uv__fs_fstat(int fd, uv_stat_t *buf) { return ret; } -static size_t uv__fs_buf_offset(uv_buf_t* bufs, size_t size) { +static size_t uv__fs_buf_offset(uv_buf_t *bufs, size_t size) { size_t offset; /* Figure out which bufs are done */ for (offset = 0; size > 0 && bufs[offset].len <= size; ++offset) @@ -1634,10 +1527,10 @@ static size_t uv__fs_buf_offset(uv_buf_t* bufs, size_t size) { return offset; } -static ssize_t uv__fs_write_all(uv_fs_t* req) { +static ssize_t uv__fs_write_all(uv_fs_t *req) { unsigned int iovmax; unsigned int nbufs; - uv_buf_t* bufs; + uv_buf_t *bufs; ssize_t total; ssize_t result; @@ -1679,62 +1572,61 @@ static ssize_t uv__fs_write_all(uv_fs_t* req) { return total; } - -static void uv__fs_work(struct uv__work* w) { +static void uv__fs_work(struct uv__work *w) { int retry_on_eintr; - uv_fs_t* req; + uv_fs_t *req; ssize_t r; req = container_of(w, uv_fs_t, work_req); - retry_on_eintr = !(req->fs_type == UV_FS_CLOSE || - req->fs_type == UV_FS_READ); + retry_on_eintr = !(req->fs_type == UV_FS_CLOSE || req->fs_type == UV_FS_READ); do { errno = 0; -#define X(type, action) \ - case UV_FS_ ## type: \ - r = action; \ +#define X(type, action) \ + case UV_FS_##type: \ + r = action; \ break; switch (req->fs_type) { - X(ACCESS, access(req->path, req->flags)); - X(CHMOD, chmod(req->path, req->mode)); - X(CHOWN, chown(req->path, req->uid, req->gid)); - X(CLOSE, uv__fs_close(req->file)); - X(COPYFILE, uv__fs_copyfile(req)); - X(FCHMOD, fchmod(req->file, req->mode)); - X(FCHOWN, fchown(req->file, req->uid, req->gid)); - X(LCHOWN, lchown(req->path, req->uid, req->gid)); - X(FDATASYNC, uv__fs_fdatasync(req)); - X(FSTAT, uv__fs_fstat(req->file, &req->statbuf)); - X(FSYNC, uv__fs_fsync(req)); - X(FTRUNCATE, ftruncate(req->file, req->off)); - X(FUTIME, uv__fs_futime(req)); - X(LUTIME, uv__fs_lutime(req)); - X(LSTAT, uv__fs_lstat(req->path, &req->statbuf)); - X(LINK, link(req->path, req->new_path)); - X(MKDIR, mkdir(req->path, req->mode)); - X(MKDTEMP, uv__fs_mkdtemp(req)); - X(MKSTEMP, uv__fs_mkstemp(req)); - X(OPEN, uv__fs_open(req)); - X(READ, uv__fs_read(req)); - X(SCANDIR, uv__fs_scandir(req)); - X(OPENDIR, uv__fs_opendir(req)); - X(READDIR, uv__fs_readdir(req)); - X(CLOSEDIR, uv__fs_closedir(req)); - X(READLINK, uv__fs_readlink(req)); - X(REALPATH, uv__fs_realpath(req)); - X(RENAME, rename(req->path, req->new_path)); - X(RMDIR, rmdir(req->path)); - X(SENDFILE, uv__fs_sendfile(req)); - X(STAT, uv__fs_stat(req->path, &req->statbuf)); - X(STATFS, uv__fs_statfs(req)); - X(SYMLINK, symlink(req->path, req->new_path)); - X(UNLINK, unlink(req->path)); - X(UTIME, uv__fs_utime(req)); - X(WRITE, uv__fs_write_all(req)); - default: abort(); + X(ACCESS, access(req->path, req->flags)); + X(CHMOD, chmod(req->path, req->mode)); + X(CHOWN, chown(req->path, req->uid, req->gid)); + X(CLOSE, uv__fs_close(req->file)); + X(COPYFILE, uv__fs_copyfile(req)); + X(FCHMOD, fchmod(req->file, req->mode)); + X(FCHOWN, fchown(req->file, req->uid, req->gid)); + X(LCHOWN, lchown(req->path, req->uid, req->gid)); + X(FDATASYNC, uv__fs_fdatasync(req)); + X(FSTAT, uv__fs_fstat(req->file, &req->statbuf)); + X(FSYNC, uv__fs_fsync(req)); + X(FTRUNCATE, ftruncate(req->file, req->off)); + X(FUTIME, uv__fs_futime(req)); + X(LUTIME, uv__fs_lutime(req)); + X(LSTAT, uv__fs_lstat(req->path, &req->statbuf)); + X(LINK, link(req->path, req->new_path)); + X(MKDIR, mkdir(req->path, req->mode)); + X(MKDTEMP, uv__fs_mkdtemp(req)); + X(MKSTEMP, uv__fs_mkstemp(req)); + X(OPEN, uv__fs_open(req)); + X(READ, uv__fs_read(req)); + X(SCANDIR, uv__fs_scandir(req)); + X(OPENDIR, uv__fs_opendir(req)); + X(READDIR, uv__fs_readdir(req)); + X(CLOSEDIR, uv__fs_closedir(req)); + X(READLINK, uv__fs_readlink(req)); + X(REALPATH, uv__fs_realpath(req)); + X(RENAME, rename(req->path, req->new_path)); + X(RMDIR, rmdir(req->path)); + X(SENDFILE, uv__fs_sendfile(req)); + X(STAT, uv__fs_stat(req->path, &req->statbuf)); + X(STATFS, uv__fs_statfs(req)); + X(SYMLINK, symlink(req->path, req->new_path)); + X(UNLINK, unlink(req->path)); + X(UTIME, uv__fs_utime(req)); + X(WRITE, uv__fs_write_all(req)); + default: + abort(); } #undef X } while (r == -1 && errno == EINTR && retry_on_eintr); @@ -1744,19 +1636,19 @@ static void uv__fs_work(struct uv__work* w) { else req->result = r; - if (r == 0 && (req->fs_type == UV_FS_STAT || - req->fs_type == UV_FS_FSTAT || + if (r == 0 && (req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_FSTAT || req->fs_type == UV_FS_LSTAT)) { req->ptr = &req->statbuf; } } - -static void uv__fs_done(struct uv__work* w, int status) { - uv_fs_t* req; +static void uv__fs_done(struct uv__work *w, int status) { + uv_fs_t *req; req = container_of(w, uv_fs_t, work_req); - uv__req_unregister(req->loop); + + if (req->reserved[0] != (void *)UV__REQ_INTERNAL) + uv__req_unregister(req->loop); if (status == UV_ECANCELED) { assert(req->result == 0); @@ -1766,21 +1658,13 @@ static void uv__fs_done(struct uv__work* w, int status) { req->cb(req); } - -void uv__fs_post(uv_loop_t* loop, uv_fs_t* req) { +void uv__fs_post(uv_loop_t *loop, uv_fs_t *req) { uv__req_register(loop); - uv__work_submit(loop, - &req->work_req, - UV__WORK_FAST_IO, - uv__fs_work, + uv__work_submit(loop, &req->work_req, UV__WORK_FAST_IO, uv__fs_work, uv__fs_done); } - -int uv_fs_access(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int flags, +int uv_fs_access(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) { INIT(ACCESS); PATH; @@ -1788,11 +1672,7 @@ int uv_fs_access(uv_loop_t* loop, POST; } - -int uv_fs_chmod(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int mode, +int uv_fs_chmod(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb) { INIT(CHMOD); PATH; @@ -1800,13 +1680,8 @@ int uv_fs_chmod(uv_loop_t* loop, POST; } - -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) { +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) { INIT(CHOWN); PATH; req->uid = uid; @@ -1814,8 +1689,7 @@ int uv_fs_chown(uv_loop_t* loop, POST; } - -int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_close(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) { INIT(CLOSE); req->file = file; if (cb != NULL) @@ -1824,11 +1698,7 @@ int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { POST; } - -int uv_fs_fchmod(uv_loop_t* loop, - uv_fs_t* req, - uv_file file, - int mode, +int uv_fs_fchmod(uv_loop_t *loop, uv_fs_t *req, uv_file file, int mode, uv_fs_cb cb) { INIT(FCHMOD); req->file = file; @@ -1836,13 +1706,8 @@ int uv_fs_fchmod(uv_loop_t* loop, POST; } - -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) { +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) { INIT(FCHOWN); req->file = file; req->uid = uid; @@ -1850,13 +1715,8 @@ int uv_fs_fchown(uv_loop_t* loop, POST; } - -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) { +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) { INIT(LCHOWN); PATH; req->uid = uid; @@ -1864,8 +1724,7 @@ int uv_fs_lchown(uv_loop_t* loop, POST; } - -int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fdatasync(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) { INIT(FDATASYNC); req->file = file; if (cb != NULL) @@ -1874,8 +1733,7 @@ int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { POST; } - -int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fstat(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) { INIT(FSTAT); req->file = file; if (cb != NULL) @@ -1884,8 +1742,7 @@ int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { POST; } - -int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { +int uv_fs_fsync(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) { INIT(FSYNC); req->file = file; if (cb != NULL) @@ -1894,11 +1751,7 @@ int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { POST; } - -int uv_fs_ftruncate(uv_loop_t* loop, - uv_fs_t* req, - uv_file file, - int64_t off, +int uv_fs_ftruncate(uv_loop_t *loop, uv_fs_t *req, uv_file file, int64_t off, uv_fs_cb cb) { INIT(FTRUNCATE); req->file = file; @@ -1909,13 +1762,8 @@ int uv_fs_ftruncate(uv_loop_t* loop, POST; } - -int uv_fs_futime(uv_loop_t* loop, - uv_fs_t* req, - uv_file file, - double atime, - double mtime, - uv_fs_cb cb) { +int uv_fs_futime(uv_loop_t *loop, uv_fs_t *req, uv_file file, double atime, + double mtime, uv_fs_cb cb) { INIT(FUTIME); req->file = file; req->atime = atime; @@ -1923,12 +1771,8 @@ int uv_fs_futime(uv_loop_t* loop, POST; } -int uv_fs_lutime(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - double atime, - double mtime, - uv_fs_cb cb) { +int uv_fs_lutime(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, + double mtime, uv_fs_cb cb) { INIT(LUTIME); PATH; req->atime = atime; @@ -1936,8 +1780,7 @@ int uv_fs_lutime(uv_loop_t* loop, POST; } - -int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_lstat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(LSTAT); PATH; if (cb != NULL) @@ -1946,12 +1789,8 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { POST; } - -int uv_fs_link(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - const char* new_path, - uv_fs_cb cb) { +int uv_fs_link(uv_loop_t *loop, uv_fs_t *req, const char *path, + const char *new_path, uv_fs_cb cb) { INIT(LINK); PATH2; if (cb != NULL) @@ -1960,11 +1799,7 @@ int uv_fs_link(uv_loop_t* loop, POST; } - -int uv_fs_mkdir(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int mode, +int uv_fs_mkdir(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb) { INIT(MKDIR); PATH; @@ -1975,11 +1810,7 @@ int uv_fs_mkdir(uv_loop_t* loop, POST; } - -int uv_fs_mkdtemp(uv_loop_t* loop, - uv_fs_t* req, - const char* tpl, - uv_fs_cb cb) { +int uv_fs_mkdtemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb) { INIT(MKDTEMP); req->path = uv__strdup(tpl); if (req->path == NULL) @@ -1987,11 +1818,7 @@ int uv_fs_mkdtemp(uv_loop_t* loop, POST; } - -int uv_fs_mkstemp(uv_loop_t* loop, - uv_fs_t* req, - const char* tpl, - uv_fs_cb cb) { +int uv_fs_mkstemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb) { INIT(MKSTEMP); req->path = uv__strdup(tpl); if (req->path == NULL) @@ -1999,13 +1826,8 @@ int uv_fs_mkstemp(uv_loop_t* loop, POST; } - -int uv_fs_open(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int flags, - int mode, - uv_fs_cb cb) { +int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, + int mode, uv_fs_cb cb) { INIT(OPEN); PATH; req->flags = flags; @@ -2016,12 +1838,8 @@ int uv_fs_open(uv_loop_t* loop, POST; } - -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 off, +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 off, uv_fs_cb cb) { INIT(READ); @@ -2030,7 +1848,7 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, req->off = off; req->file = file; - req->bufs = (uv_buf_t*) bufs; /* Safe, doesn't mutate |bufs| */ + req->bufs = (uv_buf_t *)bufs; /* Safe, doesn't mutate |bufs| */ req->nbufs = nbufs; if (cb == NULL) @@ -2052,11 +1870,7 @@ post: POST; } - -int uv_fs_scandir(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int flags, +int uv_fs_scandir(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) { INIT(SCANDIR); PATH; @@ -2064,19 +1878,14 @@ int uv_fs_scandir(uv_loop_t* loop, POST; } -int uv_fs_opendir(uv_loop_t* loop, - uv_fs_t* req, - const char* path, +int uv_fs_opendir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(OPENDIR); PATH; POST; } -int uv_fs_readdir(uv_loop_t* loop, - uv_fs_t* req, - uv_dir_t* dir, - uv_fs_cb cb) { +int uv_fs_readdir(uv_loop_t *loop, uv_fs_t *req, uv_dir_t *dir, uv_fs_cb cb) { INIT(READDIR); if (dir == NULL || dir->dir == NULL || dir->dirents == NULL) @@ -2086,10 +1895,7 @@ int uv_fs_readdir(uv_loop_t* loop, POST; } -int uv_fs_closedir(uv_loop_t* loop, - uv_fs_t* req, - uv_dir_t* dir, - uv_fs_cb cb) { +int uv_fs_closedir(uv_loop_t *loop, uv_fs_t *req, uv_dir_t *dir, uv_fs_cb cb) { INIT(CLOSEDIR); if (dir == NULL) @@ -2099,31 +1905,22 @@ int uv_fs_closedir(uv_loop_t* loop, POST; } -int uv_fs_readlink(uv_loop_t* loop, - uv_fs_t* req, - const char* path, +int uv_fs_readlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(READLINK); PATH; POST; } - -int uv_fs_realpath(uv_loop_t* loop, - uv_fs_t* req, - const char * path, - uv_fs_cb cb) { +int uv_fs_realpath(uv_loop_t *loop, uv_fs_t *req, const char *path, + uv_fs_cb cb) { INIT(REALPATH); PATH; POST; } - -int uv_fs_rename(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - const char* new_path, - uv_fs_cb cb) { +int uv_fs_rename(uv_loop_t *loop, uv_fs_t *req, const char *path, + const char *new_path, uv_fs_cb cb) { INIT(RENAME); PATH2; if (cb != NULL) @@ -2132,21 +1929,14 @@ int uv_fs_rename(uv_loop_t* loop, POST; } - -int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(RMDIR); PATH; POST; } - -int uv_fs_sendfile(uv_loop_t* loop, - uv_fs_t* req, - uv_file out_fd, - uv_file in_fd, - int64_t off, - size_t len, - uv_fs_cb cb) { +int uv_fs_sendfile(uv_loop_t *loop, uv_fs_t *req, uv_file out_fd, uv_file in_fd, + int64_t off, size_t len, uv_fs_cb cb) { INIT(SENDFILE); req->flags = in_fd; /* hack */ req->file = out_fd; @@ -2155,8 +1945,7 @@ int uv_fs_sendfile(uv_loop_t* loop, POST; } - -int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_stat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(STAT); PATH; if (cb != NULL) @@ -2165,13 +1954,8 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { POST; } - -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) { +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) { INIT(SYMLINK); PATH2; req->flags = flags; @@ -2181,8 +1965,7 @@ int uv_fs_symlink(uv_loop_t* loop, POST; } - -int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_unlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(UNLINK); PATH; if (cb != NULL) @@ -2191,13 +1974,8 @@ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { POST; } - -int uv_fs_utime(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - double atime, - double mtime, - uv_fs_cb cb) { +int uv_fs_utime(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, + double mtime, uv_fs_cb cb) { INIT(UTIME); PATH; req->atime = atime; @@ -2205,13 +1983,8 @@ int uv_fs_utime(uv_loop_t* loop, POST; } - -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 off, +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 off, uv_fs_cb cb) { INIT(WRITE); @@ -2239,8 +2012,7 @@ int uv_fs_write(uv_loop_t* loop, POST; } - -void uv_fs_req_cleanup(uv_fs_t* req) { +void uv_fs_req_cleanup(uv_fs_t *req) { if (req == NULL) return; @@ -2249,10 +2021,9 @@ void uv_fs_req_cleanup(uv_fs_t* req) { * req->new_path pointing to user-owned memory. UV_FS_MKDTEMP and * UV_FS_MKSTEMP are the exception to the rule, they always allocate memory. */ - if (req->path != NULL && - (req->cb != NULL || - req->fs_type == UV_FS_MKDTEMP || req->fs_type == UV_FS_MKSTEMP)) - uv__free((void*) req->path); /* Memory is shared with req->new_path. */ + if (req->path != NULL && (req->cb != NULL || req->fs_type == UV_FS_MKDTEMP || + req->fs_type == UV_FS_MKSTEMP)) + uv__free((void *)req->path); /* Memory is shared with req->new_path. */ req->path = NULL; req->new_path = NULL; @@ -2272,17 +2043,11 @@ void uv_fs_req_cleanup(uv_fs_t* req) { req->ptr = NULL; } - -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) { +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) { INIT(COPYFILE); - if (flags & ~(UV_FS_COPYFILE_EXCL | - UV_FS_COPYFILE_FICLONE | + if (flags & ~(UV_FS_COPYFILE_EXCL | UV_FS_COPYFILE_FICLONE | UV_FS_COPYFILE_FICLONE_FORCE)) { return UV_EINVAL; } @@ -2292,16 +2057,10 @@ int uv_fs_copyfile(uv_loop_t* loop, POST; } - -int uv_fs_statfs(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - uv_fs_cb cb) { +int uv_fs_statfs(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { INIT(STATFS); PATH; POST; } -int uv_fs_get_system_error(const uv_fs_t* req) { - return -req->result; -} +int uv_fs_get_system_error(const uv_fs_t *req) { return -req->result; } diff --git a/src/uv-common.h b/src/uv-common.h index b9a8e976e..18dddbc84 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -141,6 +141,10 @@ enum { UV_HANDLE_REAP = 0x10000000 }; +enum { + UV__REQ_INTERNAL = 0x8000 +}; + static inline int uv__is_raw_tty_mode(uv_tty_mode_t m) { return m == UV_TTY_MODE_RAW || m == UV_TTY_MODE_RAW_VT; } diff --git a/src/win/fs.c b/src/win/fs.c index cc2e8db94..64fc13abf 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -20,15 +20,15 @@ */ #include -#include #include #include #include #include #include +#include +#include #include #include -#include #include "uv.h" @@ -36,93 +36,84 @@ be included before our "winapi.h", included via "internal.h" below. */ #include +#include "fs-fd-hash-inl.h" +#include "handle-inl.h" #include "internal.h" #include "req-inl.h" -#include "handle-inl.h" -#include "fs-fd-hash-inl.h" - -#define UV_FS_FREE_PATHS 0x0002 -#define UV_FS_FREE_PTR 0x0008 -#define UV_FS_CLEANEDUP 0x0010 +#define UV_FS_FREE_PATHS 0x0002 +#define UV_FS_FREE_PTR 0x0008 +#define UV_FS_CLEANEDUP 0x0010 #ifndef FILE_DISPOSITION_DELETE -#define FILE_DISPOSITION_DELETE 0x0001 -#endif /* FILE_DISPOSITION_DELETE */ +#define FILE_DISPOSITION_DELETE 0x0001 +#endif /* FILE_DISPOSITION_DELETE */ #ifndef FILE_DISPOSITION_POSIX_SEMANTICS -#define FILE_DISPOSITION_POSIX_SEMANTICS 0x0002 -#endif /* FILE_DISPOSITION_POSIX_SEMANTICS */ +#define FILE_DISPOSITION_POSIX_SEMANTICS 0x0002 +#endif /* FILE_DISPOSITION_POSIX_SEMANTICS */ #ifndef FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE -#define FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE 0x0010 -#endif /* FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE */ +#define FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE 0x0010 +#endif /* FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE */ -NTSTATUS uv__RtlUnicodeStringInit( - PUNICODE_STRING DestinationString, - PWSTR SourceString, - size_t SourceStringLen -) { +NTSTATUS uv__RtlUnicodeStringInit(PUNICODE_STRING DestinationString, + PWSTR SourceString, size_t SourceStringLen) { if (SourceStringLen > 0x7FFF) return STATUS_INVALID_PARAMETER; DestinationString->MaximumLength = DestinationString->Length = - SourceStringLen * sizeof(SourceString[0]); + SourceStringLen * sizeof(SourceString[0]); DestinationString->Buffer = SourceString; return STATUS_SUCCESS; } -#define INIT(subtype) \ - do { \ - if (req == NULL) \ - return UV_EINVAL; \ - uv__fs_req_init(loop, req, subtype, cb); \ - } \ - while (0) - -#define POST \ - do { \ - if (cb != NULL) { \ - uv__req_register(loop); \ - 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) - -#define SET_REQ_RESULT(req, result_value) \ - do { \ - req->result = (result_value); \ - assert(req->result != -1); \ +#define INIT(subtype) \ + do { \ + if (req == NULL) \ + return UV_EINVAL; \ + uv__fs_req_init(loop, req, subtype, cb); \ } while (0) -#define SET_REQ_WIN32_ERROR(req, sys_errno) \ - do { \ - req->sys_errno_ = (sys_errno); \ - req->result = uv_translate_sys_error(req->sys_errno_); \ +#define POST \ + do { \ + if (cb != NULL) { \ + uv__req_register(loop); \ + 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) -#define SET_REQ_UV_ERROR(req, uv_errno, sys_errno) \ - do { \ - req->result = (uv_errno); \ - req->sys_errno_ = (sys_errno); \ +#define SET_REQ_RESULT(req, result_value) \ + do { \ + req->result = (result_value); \ + assert(req->result != -1); \ } while (0) -#define VERIFY_FD(fd, req) \ - if (fd == -1) { \ - req->result = UV_EBADF; \ - req->sys_errno_ = ERROR_INVALID_HANDLE; \ - return; \ +#define SET_REQ_WIN32_ERROR(req, sys_errno) \ + do { \ + req->sys_errno_ = (sys_errno); \ + req->result = uv_translate_sys_error(req->sys_errno_); \ + } while (0) + +#define SET_REQ_UV_ERROR(req, uv_errno, sys_errno) \ + do { \ + req->result = (uv_errno); \ + req->sys_errno_ = (sys_errno); \ + } while (0) + +#define VERIFY_FD(fd, req) \ + if (fd == -1) { \ + req->result = UV_EBADF; \ + req->sys_errno_ = ERROR_INVALID_HANDLE; \ + return; \ } #define NSEC_PER_TICK 100 -#define TICKS_PER_SEC ((int64_t) 1e9 / NSEC_PER_TICK) +#define TICKS_PER_SEC ((int64_t)1e9 / NSEC_PER_TICK) static const int64_t WIN_TO_UNIX_TICK_OFFSET = 11644473600 * TICKS_PER_SEC; static void uv__filetime_to_timespec(uv_timespec_t *ts, int64_t filetime) { @@ -135,18 +126,18 @@ static void uv__filetime_to_timespec(uv_timespec_t *ts, int64_t filetime) { } } -#define TIME_T_TO_FILETIME(time, filetime_ptr) \ - do { \ - int64_t bigtime = ((time) * TICKS_PER_SEC + WIN_TO_UNIX_TICK_OFFSET); \ - (filetime_ptr)->dwLowDateTime = (uint64_t) bigtime & 0xFFFFFFFF; \ - (filetime_ptr)->dwHighDateTime = (uint64_t) bigtime >> 32; \ - } while(0) +#define TIME_T_TO_FILETIME(time, filetime_ptr) \ + do { \ + int64_t bigtime = ((time) * TICKS_PER_SEC + WIN_TO_UNIX_TICK_OFFSET); \ + (filetime_ptr)->dwLowDateTime = (uint64_t)bigtime & 0xFFFFFFFF; \ + (filetime_ptr)->dwHighDateTime = (uint64_t)bigtime >> 32; \ + } while (0) #define IS_SLASH(c) ((c) == L'\\' || (c) == L'/') -#define IS_LETTER(c) (((c) >= L'a' && (c) <= L'z') || \ - ((c) >= L'A' && (c) <= L'Z')) +#define IS_LETTER(c) \ + (((c) >= L'a' && (c) <= L'z') || ((c) >= L'A' && (c) <= L'Z')) -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) const WCHAR JUNCTION_PREFIX[] = L"\\??\\"; const WCHAR JUNCTION_PREFIX_LEN = 4; @@ -157,7 +148,8 @@ const WCHAR LONG_PATH_PREFIX_LEN = 4; const WCHAR UNC_PATH_PREFIX[] = L"\\\\?\\UNC\\"; const WCHAR UNC_PATH_PREFIX_LEN = 8; -static int uv__file_symlink_usermode_flag = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE; +static int uv__file_symlink_usermode_flag = + SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE; static DWORD uv__allocation_granularity; @@ -167,12 +159,11 @@ typedef enum { FS__STAT_PATH_TRY_SLOW } fs__stat_path_return_t; -static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf); -static void fs__stat_assign_statbuf(uv_stat_t* statbuf, +static void fs__stat_assign_statbuf_null(uv_stat_t *statbuf); +static void fs__stat_assign_statbuf(uv_stat_t *statbuf, FILE_STAT_BASIC_INFORMATION stat_info, int do_lstat); - void uv__fs_init(void) { SYSTEM_INFO system_info; @@ -182,34 +173,26 @@ void uv__fs_init(void) { uv__fd_hash_init(); } - -static int fs__readlink_handle(HANDLE handle, - char** target_ptr, - size_t* target_len_ptr) { +static int fs__readlink_handle(HANDLE handle, char **target_ptr, + size_t *target_len_ptr) { char buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; - REPARSE_DATA_BUFFER* reparse_data = (REPARSE_DATA_BUFFER*) buffer; - WCHAR* w_target; + REPARSE_DATA_BUFFER *reparse_data = (REPARSE_DATA_BUFFER *)buffer; + WCHAR *w_target; DWORD w_target_len; DWORD bytes; size_t i; size_t len; - if (!DeviceIoControl(handle, - FSCTL_GET_REPARSE_POINT, - NULL, - 0, - buffer, - sizeof buffer, - &bytes, - NULL)) { + if (!DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0, buffer, + sizeof buffer, &bytes, NULL)) { return -1; } if (reparse_data->ReparseTag == IO_REPARSE_TAG_SYMLINK) { /* Real symlink */ w_target = reparse_data->SymbolicLinkReparseBuffer.PathBuffer + - (reparse_data->SymbolicLinkReparseBuffer.SubstituteNameOffset / - sizeof(WCHAR)); + (reparse_data->SymbolicLinkReparseBuffer.SubstituteNameOffset / + sizeof(WCHAR)); w_target_len = reparse_data->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(WCHAR); @@ -219,17 +202,13 @@ static int fs__readlink_handle(HANDLE handle, * path that CreateSymbolicLink will perform on absolute paths. If the path * is win32-namespaced then the user must have explicitly made it so, and * we better just return the unmodified reparse data. */ - if (w_target_len >= 4 && - w_target[0] == L'\\' && - w_target[1] == L'?' && - w_target[2] == L'?' && - w_target[3] == L'\\') { + if (w_target_len >= 4 && w_target[0] == L'\\' && w_target[1] == L'?' && + w_target[2] == L'?' && w_target[3] == L'\\') { /* Starts with \??\ */ if (w_target_len >= 6 && ((w_target[4] >= L'A' && w_target[4] <= L'Z') || (w_target[4] >= L'a' && w_target[4] <= L'z')) && - w_target[5] == L':' && - (w_target_len == 6 || w_target[6] == L'\\')) { + w_target[5] == L':' && (w_target_len == 6 || w_target[6] == L'\\')) { /* \??\:\ */ w_target += 4; w_target_len -= 4; @@ -250,25 +229,21 @@ static int fs__readlink_handle(HANDLE handle, } else if (reparse_data->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { /* Junction. */ w_target = reparse_data->MountPointReparseBuffer.PathBuffer + - (reparse_data->MountPointReparseBuffer.SubstituteNameOffset / - sizeof(WCHAR)); + (reparse_data->MountPointReparseBuffer.SubstituteNameOffset / + sizeof(WCHAR)); w_target_len = reparse_data->MountPointReparseBuffer.SubstituteNameLength / - sizeof(WCHAR); + sizeof(WCHAR); /* Only treat junctions that look like \??\:\ as symlink. Junctions * can also be used as mount points, like \??\Volume{}, but that's * confusing for programs since they wouldn't be able to actually * understand such a path when returned by uv_readlink(). UNC paths are * never valid for junctions so we don't care about them. */ - if (!(w_target_len >= 6 && - w_target[0] == L'\\' && - w_target[1] == L'?' && - w_target[2] == L'?' && - w_target[3] == L'\\' && + if (!(w_target_len >= 6 && w_target[0] == L'\\' && w_target[1] == L'?' && + w_target[2] == L'?' && w_target[3] == L'\\' && ((w_target[4] >= L'A' && w_target[4] <= L'Z') || (w_target[4] >= L'a' && w_target[4] <= L'z')) && - w_target[5] == L':' && - (w_target_len == 6 || w_target[6] == L'\\'))) { + w_target[5] == L':' && (w_target_len == 6 || w_target[6] == L'\\'))) { SetLastError(ERROR_SYMLINK_NOT_SUPPORTED); return -1; } @@ -301,10 +276,9 @@ static int fs__readlink_handle(HANDLE handle, } /* Make sure it is an absolute path. */ if (!(w_target_len >= 3 && - ((w_target[0] >= L'a' && w_target[0] <= L'z') || - (w_target[0] >= L'A' && w_target[0] <= L'Z')) && - w_target[1] == L':' && - w_target[2] == L'\\')) { + ((w_target[0] >= L'a' && w_target[0] <= L'z') || + (w_target[0] >= L'A' && w_target[0] <= L'Z')) && + w_target[1] == L':' && w_target[2] == L'\\')) { SetLastError(ERROR_SYMLINK_NOT_SUPPORTED); return -1; } @@ -319,13 +293,10 @@ static int fs__readlink_handle(HANDLE handle, return uv_utf16_to_wtf8(w_target, w_target_len, target_ptr, target_len_ptr); } - -static int fs__capture_path(uv_fs_t* req, - const char* path, - const char* new_path, - const int copy_path) { - WCHAR* buf; - WCHAR* pos; +static int fs__capture_path(uv_fs_t *req, const char *path, + const char *new_path, const int copy_path) { + WCHAR *buf; + WCHAR *pos; size_t buf_sz = 0; size_t path_len = 0; ssize_t pathw_len = 0; @@ -353,7 +324,6 @@ static int fs__capture_path(uv_fs_t* req, buf_sz += new_pathw_len * sizeof(WCHAR); } - if (buf_sz == 0) { req->file.pathw = NULL; req->fs.info.new_pathw = NULL; @@ -388,7 +358,7 @@ static int fs__capture_path(uv_fs_t* req, if (path != NULL && copy_path) { memcpy(pos, path, path_len); assert(path_len == buf_sz - (pos - buf) * sizeof(WCHAR)); - req->path = (char*) pos; + req->path = (char *)pos; } req->flags |= UV_FS_FREE_PATHS; @@ -396,10 +366,7 @@ static int fs__capture_path(uv_fs_t* req, return 0; } - -static void uv__fs_req_init(uv_loop_t* loop, - uv_fs_t* req, - uv_fs_type fs_type, +static void uv__fs_req_init(uv_loop_t *loop, uv_fs_t *req, uv_fs_type fs_type, const uv_fs_cb cb) { uv__once_init(); UV_REQ_INIT(req, UV_FS); @@ -411,11 +378,11 @@ static void uv__fs_req_init(uv_loop_t* loop, req->ptr = NULL; req->path = NULL; req->cb = cb; + req->reserved[0] = NULL; memset(&req->fs, 0, sizeof(req->fs)); } - -void fs__open(uv_fs_t* req) { +void fs__open(uv_fs_t *req) { DWORD access; DWORD share; DWORD disposition; @@ -516,7 +483,7 @@ void fs__open(uv_fs_t* req) { } } - if (flags & UV_FS_O_TEMPORARY ) { + if (flags & UV_FS_O_TEMPORARY) { attributes |= FILE_FLAG_DELETE_ON_CLOSE | FILE_ATTRIBUTE_TEMPORARY; access |= DELETE; } @@ -583,13 +550,8 @@ void fs__open(uv_fs_t* req) { /* Setting this flag makes it possible to open a directory. */ attributes |= FILE_FLAG_BACKUP_SEMANTICS; - file = CreateFileW(req->file.pathw, - access, - share, - NULL, - disposition, - attributes, - NULL); + file = CreateFileW(req->file.pathw, access, share, NULL, disposition, + attributes, NULL); if (file == INVALID_HANDLE_VALUE) { DWORD error = GetLastError(); if (error == ERROR_FILE_EXISTS && (flags & UV_FS_O_CREAT) && @@ -603,7 +565,7 @@ void fs__open(uv_fs_t* req) { return; } - fd = _open_osfhandle((intptr_t) file, flags); + fd = _open_osfhandle((intptr_t)file, flags); if (fd < 0) { /* The only known failure mode for _open_osfhandle() is EMFILE, in which * case GetLastError() will return zero. However we'll try to handle other @@ -614,16 +576,14 @@ void fs__open(uv_fs_t* req) { else if (GetLastError() != ERROR_SUCCESS) SET_REQ_WIN32_ERROR(req, GetLastError()); else - SET_REQ_WIN32_ERROR(req, (DWORD) UV_UNKNOWN); + SET_REQ_WIN32_ERROR(req, (DWORD)UV_UNKNOWN); CloseHandle(file); return; } if (flags & UV_FS_O_FILEMAP) { FILE_STANDARD_INFO file_info; - if (!GetFileInformationByHandleEx(file, - FileStandardInfo, - &file_info, + if (!GetFileInformationByHandleEx(file, FileStandardInfo, &file_info, sizeof file_info)) { SET_REQ_WIN32_ERROR(req, GetLastError()); CloseHandle(file); @@ -645,13 +605,12 @@ void fs__open(uv_fs_t* req) { fd_info.mapping = INVALID_HANDLE_VALUE; } else { DWORD flProtect = (fd_info.flags & (UV_FS_O_RDONLY | UV_FS_O_WRONLY | - UV_FS_O_RDWR)) == UV_FS_O_RDONLY ? PAGE_READONLY : PAGE_READWRITE; - fd_info.mapping = CreateFileMapping(file, - NULL, - flProtect, - fd_info.size.HighPart, - fd_info.size.LowPart, - NULL); + UV_FS_O_RDWR)) == UV_FS_O_RDONLY + ? PAGE_READONLY + : PAGE_READWRITE; + fd_info.mapping = + CreateFileMapping(file, NULL, flProtect, fd_info.size.HighPart, + fd_info.size.LowPart, NULL); if (fd_info.mapping == NULL) { SET_REQ_WIN32_ERROR(req, GetLastError()); CloseHandle(file); @@ -666,11 +625,11 @@ void fs__open(uv_fs_t* req) { SET_REQ_RESULT(req, fd); return; - einval: +einval: SET_REQ_UV_ERROR(req, UV_EINVAL, ERROR_INVALID_PARAMETER); } -void fs__close(uv_fs_t* req) { +void fs__close(uv_fs_t *req) { int fd = req->file.fd; int result; struct uv__fd_info_s fd_info; @@ -699,9 +658,7 @@ void fs__close(uv_fs_t* req) { } } - -LONG fs__filemap_ex_filter(LONG excode, PEXCEPTION_POINTERS pep, - int* perror) { +LONG fs__filemap_ex_filter(LONG excode, PEXCEPTION_POINTERS pep, int *perror) { if (excode != (LONG)EXCEPTION_IN_PAGE_ERROR) { return EXCEPTION_CONTINUE_SEARCH; } @@ -719,17 +676,16 @@ LONG fs__filemap_ex_filter(LONG excode, PEXCEPTION_POINTERS pep, return EXCEPTION_EXECUTE_HANDLER; } - -void fs__read_filemap(uv_fs_t* req, struct uv__fd_info_s* fd_info) { +void fs__read_filemap(uv_fs_t *req, struct uv__fd_info_s *fd_info) { int fd = req->file.fd; /* VERIFY_FD done in fs__read */ - int rw_flags = fd_info->flags & - (UV_FS_O_RDONLY | UV_FS_O_WRONLY | UV_FS_O_RDWR); + int rw_flags = + fd_info->flags & (UV_FS_O_RDONLY | UV_FS_O_WRONLY | UV_FS_O_RDWR); size_t read_size, done_read; unsigned int index; LARGE_INTEGER pos, end_pos; size_t view_offset; LARGE_INTEGER view_base; - void* view; + void *view; if (rw_flags == UV_FS_O_WRONLY) { SET_REQ_WIN32_ERROR(req, ERROR_INVALID_FLAGS); @@ -756,8 +712,8 @@ void fs__read_filemap(uv_fs_t* req, struct uv__fd_info_s* fd_info) { for (index = 0; index < req->fs.info.nbufs; ++index) { read_size += req->fs.info.bufs[index].len; } - read_size = (size_t) MIN((LONGLONG) read_size, - fd_info->size.QuadPart - pos.QuadPart); + read_size = + (size_t)MIN((LONGLONG)read_size, fd_info->size.QuadPart - pos.QuadPart); if (read_size == 0) { SET_REQ_RESULT(req, 0); return; @@ -767,33 +723,27 @@ void fs__read_filemap(uv_fs_t* req, struct uv__fd_info_s* fd_info) { view_offset = pos.QuadPart % uv__allocation_granularity; view_base.QuadPart = pos.QuadPart - view_offset; - view = MapViewOfFile(fd_info->mapping, - FILE_MAP_READ, - view_base.HighPart, - view_base.LowPart, - view_offset + read_size); + view = MapViewOfFile(fd_info->mapping, FILE_MAP_READ, view_base.HighPart, + view_base.LowPart, view_offset + read_size); if (view == NULL) { SET_REQ_WIN32_ERROR(req, GetLastError()); return; } done_read = 0; - for (index = 0; - index < req->fs.info.nbufs && done_read < read_size; + for (index = 0; index < req->fs.info.nbufs && done_read < read_size; ++index) { - size_t this_read_size = MIN(req->fs.info.bufs[index].len, - read_size - done_read); + size_t this_read_size = + MIN(req->fs.info.bufs[index].len, read_size - done_read); #ifdef _MSC_VER int err = 0; __try { #endif memcpy(req->fs.info.bufs[index].base, - (char*)view + view_offset + done_read, - this_read_size); + (char *)view + view_offset + done_read, this_read_size); #ifdef _MSC_VER - } - __except (fs__filemap_ex_filter(GetExceptionCode(), - GetExceptionInformation(), &err)) { + } __except (fs__filemap_ex_filter(GetExceptionCode(), + GetExceptionInformation(), &err)) { SET_REQ_WIN32_ERROR(req, err); UnmapViewOfFile(view); return; @@ -817,7 +767,7 @@ void fs__read_filemap(uv_fs_t* req, struct uv__fd_info_s* fd_info) { return; } -void fs__read(uv_fs_t* req) { +void fs__read(uv_fs_t *req) { int fd = req->file.fd; int64_t offset = req->fs.info.offset; HANDLE handle; @@ -870,10 +820,8 @@ void fs__read(uv_fs_t* req) { overlapped.OffsetHigh = offset_.HighPart; } - result = ReadFile(handle, - req->fs.info.bufs[index].base, - req->fs.info.bufs[index].len, - &incremental_bytes, + result = ReadFile(handle, req->fs.info.bufs[index].base, + req->fs.info.bufs[index].len, &incremental_bytes, overlapped_ptr); bytes += incremental_bytes; ++index; @@ -898,19 +846,18 @@ void fs__read(uv_fs_t* req) { } } - -void fs__write_filemap(uv_fs_t* req, HANDLE file, - struct uv__fd_info_s* fd_info) { +void fs__write_filemap(uv_fs_t *req, HANDLE file, + struct uv__fd_info_s *fd_info) { int fd = req->file.fd; /* VERIFY_FD done in fs__write */ int force_append = fd_info->flags & UV_FS_O_APPEND; - int rw_flags = fd_info->flags & - (UV_FS_O_RDONLY | UV_FS_O_WRONLY | UV_FS_O_RDWR); + int rw_flags = + fd_info->flags & (UV_FS_O_RDONLY | UV_FS_O_WRONLY | UV_FS_O_RDWR); size_t write_size, done_write; unsigned int index; LARGE_INTEGER pos, end_pos; size_t view_offset; LARGE_INTEGER view_base; - void* view; + void *view; FILETIME ft; if (rw_flags == UV_FS_O_RDONLY) { @@ -948,12 +895,8 @@ void fs__write_filemap(uv_fs_t* req, HANDLE file, CloseHandle(fd_info->mapping); } - fd_info->mapping = CreateFileMapping(file, - NULL, - PAGE_READWRITE, - end_pos.HighPart, - end_pos.LowPart, - NULL); + fd_info->mapping = CreateFileMapping( + file, NULL, PAGE_READWRITE, end_pos.HighPart, end_pos.LowPart, NULL); if (fd_info->mapping == NULL) { SET_REQ_WIN32_ERROR(req, GetLastError()); CloseHandle(file); @@ -970,11 +913,8 @@ void fs__write_filemap(uv_fs_t* req, HANDLE file, view_offset = pos.QuadPart % uv__allocation_granularity; view_base.QuadPart = pos.QuadPart - view_offset; - view = MapViewOfFile(fd_info->mapping, - FILE_MAP_WRITE, - view_base.HighPart, - view_base.LowPart, - view_offset + write_size); + view = MapViewOfFile(fd_info->mapping, FILE_MAP_WRITE, view_base.HighPart, + view_base.LowPart, view_offset + write_size); if (view == NULL) { SET_REQ_WIN32_ERROR(req, GetLastError()); return; @@ -986,13 +926,11 @@ void fs__write_filemap(uv_fs_t* req, HANDLE file, int err = 0; __try { #endif - memcpy((char*)view + view_offset + done_write, - req->fs.info.bufs[index].base, - req->fs.info.bufs[index].len); + memcpy((char *)view + view_offset + done_write, + req->fs.info.bufs[index].base, req->fs.info.bufs[index].len); #ifdef _MSC_VER - } - __except (fs__filemap_ex_filter(GetExceptionCode(), - GetExceptionInformation(), &err)) { + } __except (fs__filemap_ex_filter(GetExceptionCode(), + GetExceptionInformation(), &err)) { SET_REQ_WIN32_ERROR(req, err); UnmapViewOfFile(view); return; @@ -1023,7 +961,7 @@ void fs__write_filemap(uv_fs_t* req, HANDLE file, SET_REQ_RESULT(req, done_write); } -void fs__write(uv_fs_t* req) { +void fs__write(uv_fs_t *req) { int fd = req->file.fd; int64_t offset = req->fs.info.offset; HANDLE handle; @@ -1075,10 +1013,8 @@ void fs__write(uv_fs_t* req) { overlapped.OffsetHigh = offset_.HighPart; } - result = WriteFile(handle, - req->fs.info.bufs[index].base, - req->fs.info.bufs[index].len, - &incremental_bytes, + result = WriteFile(handle, req->fs.info.bufs[index].base, + req->fs.info.bufs[index].len, &incremental_bytes, overlapped_ptr); bytes += incremental_bytes; ++index; @@ -1100,9 +1036,8 @@ void fs__write(uv_fs_t* req) { } } - -static void fs__unlink_rmdir(uv_fs_t* req, BOOL isrmdir) { - const WCHAR* pathw = req->file.pathw; +static void fs__unlink_rmdir(uv_fs_t *req, BOOL isrmdir) { + const WCHAR *pathw = req->file.pathw; HANDLE handle; BY_HANDLE_FILE_INFORMATION info; FILE_DISPOSITION_INFORMATION disposition; @@ -1111,13 +1046,11 @@ static void fs__unlink_rmdir(uv_fs_t* req, BOOL isrmdir) { NTSTATUS status; DWORD error; - handle = CreateFileW(pathw, - FILE_READ_ATTRIBUTES | DELETE, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, - NULL); + handle = CreateFileW( + pathw, FILE_READ_ATTRIBUTES | DELETE, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, + OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, + NULL); if (handle == INVALID_HANDLE_VALUE) { SET_REQ_WIN32_ERROR(req, GetLastError()); @@ -1163,56 +1096,54 @@ static void fs__unlink_rmdir(uv_fs_t* req, BOOL isrmdir) { } /* Try posix delete first */ - disposition_ex.Flags = FILE_DISPOSITION_DELETE | FILE_DISPOSITION_POSIX_SEMANTICS | - FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE; + disposition_ex.Flags = FILE_DISPOSITION_DELETE | + FILE_DISPOSITION_POSIX_SEMANTICS | + FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE; - status = pNtSetInformationFile(handle, - &iosb, - &disposition_ex, + status = pNtSetInformationFile(handle, &iosb, &disposition_ex, sizeof disposition_ex, FileDispositionInformationEx); if (NT_SUCCESS(status)) { SET_REQ_SUCCESS(req); } else { /* If status == STATUS_CANNOT_DELETE here, given we set - * FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE, STATUS_CANNOT_DELETE can only mean - * that there is an existing mapped view to the file, preventing delete. - * STATUS_CANNOT_DELETE maps to UV_EACCES so it's not specifically worth handling */ + * FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE, STATUS_CANNOT_DELETE can only + * mean that there is an existing mapped view to the file, preventing + * delete. STATUS_CANNOT_DELETE maps to UV_EACCES so it's not specifically + * worth handling */ error = pRtlNtStatusToDosError(status); - if (error == ERROR_NOT_SUPPORTED /* filesystem does not support posix deletion */ || - error == ERROR_INVALID_PARAMETER /* pre Windows 10 error */ || + if (error == + ERROR_NOT_SUPPORTED /* filesystem does not support posix deletion */ + || error == ERROR_INVALID_PARAMETER /* pre Windows 10 error */ || error == ERROR_INVALID_FUNCTION /* pre Windows 10 1607 error */) { /* posix delete not supported so try fallback */ if (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { /* Remove read-only attribute */ - FILE_BASIC_INFORMATION basic = { 0 }; + FILE_BASIC_INFORMATION basic = {0}; - /* We opened the handle above without FILE_WRITE_ATTRIBUTES access, which - * is not required in the happy path. On windows, it would probably - * be ok to ask for them anyway, but Wine has a bug that causes such calls - * to fail (https://bugs.winehq.org/show_bug.cgi?id=50771). To work around - * this bug, we re-open the handle here */ + /* We opened the handle above without FILE_WRITE_ATTRIBUTES access, + * which is not required in the happy path. On windows, it would + * probably be ok to ask for them anyway, but Wine has a bug that causes + * such calls to fail (https://bugs.winehq.org/show_bug.cgi?id=50771). + * To work around this bug, we re-open the handle here */ HANDLE write_attributes_handle; - basic.FileAttributes = (info.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY) | - FILE_ATTRIBUTE_ARCHIVE; + basic.FileAttributes = + (info.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY) | + FILE_ATTRIBUTE_ARCHIVE; - write_attributes_handle = ReOpenFile(handle, FILE_WRITE_ATTRIBUTES, - FILE_SHARE_READ | FILE_SHARE_WRITE | - FILE_SHARE_DELETE, - FILE_FLAG_OPEN_REPARSE_POINT | - FILE_FLAG_BACKUP_SEMANTICS); + write_attributes_handle = ReOpenFile( + handle, FILE_WRITE_ATTRIBUTES, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS); if (write_attributes_handle == INVALID_HANDLE_VALUE) { SET_REQ_WIN32_ERROR(req, GetLastError()); CloseHandle(handle); return; } - status = pNtSetInformationFile(write_attributes_handle, - &iosb, - &basic, - sizeof basic, - FileBasicInformation); + status = pNtSetInformationFile(write_attributes_handle, &iosb, &basic, + sizeof basic, FileBasicInformation); CloseHandle(write_attributes_handle); if (!NT_SUCCESS(status)) { SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(status)); @@ -1223,11 +1154,9 @@ static void fs__unlink_rmdir(uv_fs_t* req, BOOL isrmdir) { /* Try to set the delete flag. */ disposition.DeleteFile = TRUE; - status = pNtSetInformationFile(handle, - &iosb, - &disposition, - sizeof disposition, - FileDispositionInformation); + status = + pNtSetInformationFile(handle, &iosb, &disposition, sizeof disposition, + FileDispositionInformation); if (NT_SUCCESS(status)) { SET_REQ_SUCCESS(req); } else { @@ -1241,18 +1170,11 @@ static void fs__unlink_rmdir(uv_fs_t* req, BOOL isrmdir) { CloseHandle(handle); } +static void fs__rmdir(uv_fs_t *req) { fs__unlink_rmdir(req, /*isrmdir*/ 1); } -static void fs__rmdir(uv_fs_t* req) { - fs__unlink_rmdir(req, /*isrmdir*/1); -} +static void fs__unlink(uv_fs_t *req) { fs__unlink_rmdir(req, /*isrmdir*/ 0); } - -static void fs__unlink(uv_fs_t* req) { - fs__unlink_rmdir(req, /*isrmdir*/0); -} - - -void fs__mkdir(uv_fs_t* req) { +void fs__mkdir(uv_fs_t *req) { /* TODO: use req->mode. */ if (CreateDirectoryW(req->file.pathw, NULL)) { SET_REQ_RESULT(req, 0); @@ -1264,21 +1186,21 @@ void fs__mkdir(uv_fs_t* req) { } } -typedef int (*uv__fs_mktemp_func)(uv_fs_t* req); +typedef int (*uv__fs_mktemp_func)(uv_fs_t *req); /* OpenBSD original: lib/libc/stdio/mktemp.c */ -void fs__mktemp(uv_fs_t* req, uv__fs_mktemp_func func) { +void fs__mktemp(uv_fs_t *req, uv__fs_mktemp_func func) { static const WCHAR *tempchars = - L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; static const size_t num_chars = 62; static const size_t num_x = 6; WCHAR *cp, *ep; unsigned int tries, i; size_t len; uint64_t v; - char* path; + char *path; - path = (char*)req->path; + path = (char *)req->path; len = wcslen(req->file.pathw); ep = req->file.pathw + len; if (len < num_x || wcsncmp(ep - num_x, L"XXXXXX", num_x)) { @@ -1314,8 +1236,7 @@ clobber: path[0] = '\0'; } - -static int fs__mkdtemp_func(uv_fs_t* req) { +static int fs__mkdtemp_func(uv_fs_t *req) { DWORD error; if (CreateDirectoryW(req->file.pathw, NULL)) { SET_REQ_RESULT(req, 0); @@ -1330,23 +1251,15 @@ static int fs__mkdtemp_func(uv_fs_t* req) { return 0; } +void fs__mkdtemp(uv_fs_t *req) { fs__mktemp(req, fs__mkdtemp_func); } -void fs__mkdtemp(uv_fs_t* req) { - fs__mktemp(req, fs__mkdtemp_func); -} - - -static int fs__mkstemp_func(uv_fs_t* req) { +static int fs__mkstemp_func(uv_fs_t *req) { HANDLE file; int fd; - file = CreateFileW(req->file.pathw, - GENERIC_READ | GENERIC_WRITE, + file = CreateFileW(req->file.pathw, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); + NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if (file == INVALID_HANDLE_VALUE) { DWORD error; @@ -1362,7 +1275,7 @@ static int fs__mkstemp_func(uv_fs_t* req) { return 0; } - fd = _open_osfhandle((intptr_t) file, 0); + fd = _open_osfhandle((intptr_t)file, 0); if (fd < 0) { /* The only known failure mode for _open_osfhandle() is EMFILE, in which * case GetLastError() will return zero. However we'll try to handle other @@ -1383,18 +1296,14 @@ static int fs__mkstemp_func(uv_fs_t* req) { return 1; } +void fs__mkstemp(uv_fs_t *req) { fs__mktemp(req, fs__mkstemp_func); } -void fs__mkstemp(uv_fs_t* req) { - fs__mktemp(req, fs__mkstemp_func); -} - - -void fs__scandir(uv_fs_t* req) { +void fs__scandir(uv_fs_t *req) { static const size_t dirents_initial_size = 32; HANDLE dir_handle = INVALID_HANDLE_VALUE; - uv__dirent_t** dirents = NULL; + uv__dirent_t **dirents = NULL; size_t dirents_size = 0; size_t dirents_used = 0; @@ -1410,7 +1319,7 @@ void fs__scandir(uv_fs_t* req) { #if _MSC_VER __declspec(align(8)) char buffer[8192]; #else - __attribute__ ((aligned (8))) char buffer[8192]; + __attribute__((aligned(8))) char buffer[8192]; #endif STATIC_ASSERT(sizeof buffer >= @@ -1418,28 +1327,16 @@ void fs__scandir(uv_fs_t* req) { /* Open the directory. */ dir_handle = - CreateFileW(req->file.pathw, - FILE_LIST_DIRECTORY | SYNCHRONIZE, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, - NULL); + CreateFileW(req->file.pathw, FILE_LIST_DIRECTORY | SYNCHRONIZE, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (dir_handle == INVALID_HANDLE_VALUE) goto win32_error; /* Read the first chunk. */ - status = pNtQueryDirectoryFile(dir_handle, - NULL, - NULL, - NULL, - &iosb, - &buffer, - sizeof buffer, - FileDirectoryInformation, - FALSE, - NULL, - TRUE); + status = pNtQueryDirectoryFile(dir_handle, NULL, NULL, NULL, &iosb, &buffer, + sizeof buffer, FileDirectoryInformation, FALSE, + NULL, TRUE); /* If the handle is not a directory, we'll get STATUS_INVALID_PARAMETER. * This should be reported back as UV_ENOTDIR. @@ -1448,20 +1345,20 @@ void fs__scandir(uv_fs_t* req) { goto not_a_directory_error; while (NT_SUCCESS(status)) { - char* position = buffer; + char *position = buffer; size_t next_entry_offset = 0; do { - FILE_DIRECTORY_INFORMATION* info; - uv__dirent_t* dirent; + FILE_DIRECTORY_INFORMATION *info; + uv__dirent_t *dirent; size_t wchar_len; size_t wtf8_len; - char* wtf8; + char *wtf8; /* Obtain a pointer to the current directory entry. */ position += next_entry_offset; - info = (FILE_DIRECTORY_INFORMATION*) position; + info = (FILE_DIRECTORY_INFORMATION *)position; /* Fetch the offset to the next directory entry. */ next_entry_offset = info->NextEntryOffset; @@ -1491,7 +1388,7 @@ void fs__scandir(uv_fs_t* req) { if (dirents_used >= dirents_size) { size_t new_dirents_size = dirents_size == 0 ? dirents_initial_size : dirents_size << 1; - uv__dirent_t** new_dirents = + uv__dirent_t **new_dirents = uv__realloc(dirents, new_dirents_size * sizeof *dirents); if (new_dirents == NULL) @@ -1513,7 +1410,8 @@ void fs__scandir(uv_fs_t* req) { /* Convert file name to UTF-8. */ wtf8 = &dirent->d_name[0]; - if (uv_utf16_to_wtf8(&info->FileName[0], wchar_len, &wtf8, &wtf8_len) != 0) + if (uv_utf16_to_wtf8(&info->FileName[0], wchar_len, &wtf8, &wtf8_len) != + 0) goto out_of_memory_error; /* Fill out the type field. */ @@ -1528,17 +1426,9 @@ void fs__scandir(uv_fs_t* req) { } while (next_entry_offset != 0); /* Read the next chunk. */ - status = pNtQueryDirectoryFile(dir_handle, - NULL, - NULL, - NULL, - &iosb, - &buffer, - sizeof buffer, - FileDirectoryInformation, - FALSE, - NULL, - FALSE); + status = pNtQueryDirectoryFile(dir_handle, NULL, NULL, NULL, &iosb, &buffer, + sizeof buffer, FileDirectoryInformation, + FALSE, NULL, FALSE); /* After the first pNtQueryDirectoryFile call, the function may return * STATUS_SUCCESS even if the buffer was too small to hold at least one @@ -1590,12 +1480,12 @@ cleanup: uv__free(dirents); } -void fs__opendir(uv_fs_t* req) { - WCHAR* pathw; +void fs__opendir(uv_fs_t *req) { + WCHAR *pathw; size_t len; - const WCHAR* fmt; - WCHAR* find_path; - uv_dir_t* dir; + const WCHAR *fmt; + WCHAR *find_path; + uv_dir_t *dir; pathw = req->file.pathw; dir = NULL; @@ -1649,9 +1539,9 @@ error: req->ptr = NULL; } -void fs__readdir(uv_fs_t* req) { - uv_dir_t* dir; - uv_dirent_t* dirents; +void fs__readdir(uv_fs_t *req) { + uv_dir_t *dir; + uv_dirent_t *dirents; uv__dirent_t dent; unsigned int dirent_idx; PWIN32_FIND_DATAW find_data; @@ -1675,15 +1565,14 @@ void fs__readdir(uv_fs_t* req) { /* Skip "." and ".." entries. */ if (find_data->cFileName[0] == L'.' && (find_data->cFileName[1] == L'\0' || - (find_data->cFileName[1] == L'.' && - find_data->cFileName[2] == L'\0'))) { + (find_data->cFileName[1] == L'.' && + find_data->cFileName[2] == L'\0'))) { dir->need_find_call = TRUE; continue; } - r = uv__convert_utf16_to_utf8((const WCHAR*) &find_data->cFileName, - -1, - (char**) &dirents[dirent_idx].name); + r = uv__convert_utf16_to_utf8((const WCHAR *)&find_data->cFileName, -1, + (char **)&dirents[dirent_idx].name); if (r != 0) goto error; @@ -1708,13 +1597,13 @@ void fs__readdir(uv_fs_t* req) { error: SET_REQ_WIN32_ERROR(req, GetLastError()); for (i = 0; i < dirent_idx; ++i) { - uv__free((char*) dirents[i].name); + uv__free((char *)dirents[i].name); dirents[i].name = NULL; } } -void fs__closedir(uv_fs_t* req) { - uv_dir_t* dir; +void fs__closedir(uv_fs_t *req) { + uv_dir_t *dir; dir = req->ptr; FindClose(dir->dir_handle); @@ -1722,8 +1611,7 @@ void fs__closedir(uv_fs_t* req) { SET_REQ_RESULT(req, 0); } -static fs__stat_path_return_t fs__stat_path(WCHAR* path, - uv_stat_t* statbuf, +static fs__stat_path_return_t fs__stat_path(WCHAR *path, uv_stat_t *statbuf, int do_lstat) { FILE_STAT_BASIC_INFORMATION stat_info; @@ -1734,14 +1622,14 @@ static fs__stat_path_return_t fs__stat_path(WCHAR* path, /* Check if the API call fails. */ if (!pGetFileInformationByName(path, FileStatBasicByNameInfo, &stat_info, - sizeof(stat_info))) { - switch(GetLastError()) { - case ERROR_FILE_NOT_FOUND: - case ERROR_PATH_NOT_FOUND: - case ERROR_NOT_READY: - case ERROR_BAD_NET_NAME: - /* These errors aren't worth retrying with the slow path. */ - return FS__STAT_PATH_ERROR; + sizeof(stat_info))) { + switch (GetLastError()) { + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + case ERROR_NOT_READY: + case ERROR_BAD_NET_NAME: + /* These errors aren't worth retrying with the slow path. */ + return FS__STAT_PATH_ERROR; } return FS__STAT_PATH_TRY_SLOW; } @@ -1760,7 +1648,7 @@ static fs__stat_path_return_t fs__stat_path(WCHAR* path, return FS__STAT_PATH_SUCCESS; } -static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, int do_lstat) { +static int fs__stat_handle(HANDLE handle, uv_stat_t *statbuf, int do_lstat) { size_t target_length = 0; FILE_FS_DEVICE_INFORMATION device_info; FILE_ALL_INFORMATION file_info; @@ -1769,9 +1657,7 @@ static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, int do_lstat) { IO_STATUS_BLOCK io_status; FILE_STAT_BASIC_INFORMATION stat_info; - nt_status = pNtQueryVolumeInformationFile(handle, - &io_status, - &device_info, + nt_status = pNtQueryVolumeInformationFile(handle, &io_status, &device_info, sizeof device_info, FileFsDeviceInformation); @@ -1787,11 +1673,8 @@ static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, int do_lstat) { return 0; } - nt_status = pNtQueryInformationFile(handle, - &io_status, - &file_info, - sizeof file_info, - FileAllInformation); + nt_status = pNtQueryInformationFile(handle, &io_status, &file_info, + sizeof file_info, FileAllInformation); /* Buffer overflow (a warning status code) is expected here. */ if (NT_ERROR(nt_status)) { @@ -1799,9 +1682,7 @@ static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, int do_lstat) { return -1; } - nt_status = pNtQueryVolumeInformationFile(handle, - &io_status, - &volume_info, + nt_status = pNtQueryVolumeInformationFile(handle, &io_status, &volume_info, sizeof volume_info, FileFsVolumeInformation); @@ -1831,8 +1712,8 @@ static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, int do_lstat) { stat_info.AllocationSize.QuadPart = file_info.StandardInformation.AllocationSize.QuadPart; - if (do_lstat && - (file_info.BasicInformation.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) { + if (do_lstat && (file_info.BasicInformation.FileAttributes & + FILE_ATTRIBUTE_REPARSE_POINT)) { /* * If reading the link fails, the reparse point is not a symlink and needs * to be treated as a regular file. The higher level lstat function will @@ -1844,14 +1725,14 @@ static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf, int do_lstat) { stat_info.EndOfFile.QuadPart = target_length; } else { stat_info.EndOfFile.QuadPart = - file_info.StandardInformation.EndOfFile.QuadPart; + file_info.StandardInformation.EndOfFile.QuadPart; } fs__stat_assign_statbuf(statbuf, stat_info, do_lstat); return 0; } -static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf) { +static void fs__stat_assign_statbuf_null(uv_stat_t *statbuf) { memset(statbuf, 0, sizeof(uv_stat_t)); statbuf->st_mode = _S_IFCHR; statbuf->st_mode |= (_S_IREAD | _S_IWRITE) | ((_S_IREAD | _S_IWRITE) >> 3) | @@ -1861,7 +1742,7 @@ static void fs__stat_assign_statbuf_null(uv_stat_t* statbuf) { statbuf->st_rdev = FILE_DEVICE_NULL << 16; } -static void fs__stat_assign_statbuf(uv_stat_t* statbuf, +static void fs__stat_assign_statbuf(uv_stat_t *statbuf, FILE_STAT_BASIC_INFORMATION stat_info, int do_lstat) { statbuf->st_dev = stat_info.VolumeSerialNumber.LowPart; @@ -1888,16 +1769,15 @@ static void fs__stat_assign_statbuf(uv_stat_t* statbuf, statbuf->st_mode = 0; /* - * On Windows, FILE_ATTRIBUTE_REPARSE_POINT is a general purpose mechanism - * by which filesystem drivers can intercept and alter file system requests. - * - * The only reparse points we care about are symlinks and mount points, both - * of which are treated as POSIX symlinks. Further, we only care when - * invoked via lstat, which seeks information about the link instead of its - * target. Otherwise, reparse points must be treated as regular files. - */ - if (do_lstat && - (stat_info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) { + * On Windows, FILE_ATTRIBUTE_REPARSE_POINT is a general purpose mechanism + * by which filesystem drivers can intercept and alter file system requests. + * + * The only reparse points we care about are symlinks and mount points, both + * of which are treated as POSIX symlinks. Further, we only care when + * invoked via lstat, which seeks information about the link instead of its + * target. Otherwise, reparse points must be treated as regular files. + */ + if (do_lstat && (stat_info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) { statbuf->st_mode |= S_IFLNK; statbuf->st_size = stat_info.EndOfFile.QuadPart; } @@ -1920,18 +1800,15 @@ static void fs__stat_assign_statbuf(uv_stat_t* statbuf, uv__filetime_to_timespec(&statbuf->st_atim, stat_info.LastAccessTime.QuadPart); - uv__filetime_to_timespec(&statbuf->st_ctim, - stat_info.ChangeTime.QuadPart); - uv__filetime_to_timespec(&statbuf->st_mtim, - stat_info.LastWriteTime.QuadPart); + uv__filetime_to_timespec(&statbuf->st_ctim, stat_info.ChangeTime.QuadPart); + uv__filetime_to_timespec(&statbuf->st_mtim, stat_info.LastWriteTime.QuadPart); uv__filetime_to_timespec(&statbuf->st_birthtim, stat_info.CreationTime.QuadPart); statbuf->st_ino = stat_info.FileId.QuadPart; /* st_blocks contains the on-disk allocation size in 512-byte units. */ - statbuf->st_blocks = - (uint64_t) stat_info.AllocationSize.QuadPart >> 9; + statbuf->st_blocks = (uint64_t)stat_info.AllocationSize.QuadPart >> 9; statbuf->st_nlink = stat_info.NumberOfLinks; @@ -1967,8 +1844,7 @@ static void fs__stat_assign_statbuf(uv_stat_t* statbuf, statbuf->st_gen = 0; } - -static void fs__stat_prepare_path(WCHAR* pathw) { +static void fs__stat_prepare_path(WCHAR *pathw) { size_t len = wcslen(pathw); if (len > 1 && pathw[len - 2] != L':' && @@ -1977,9 +1853,7 @@ static void fs__stat_prepare_path(WCHAR* pathw) { } } -static DWORD fs__stat_directory(WCHAR* path, - uv_stat_t* statbuf, - int do_lstat, +static DWORD fs__stat_directory(WCHAR *path, uv_stat_t *statbuf, int do_lstat, DWORD ret_error) { HANDLE handle = INVALID_HANDLE_VALUE; FILE_STAT_BASIC_INFORMATION stat_info; @@ -1988,8 +1862,8 @@ static DWORD fs__stat_directory(WCHAR* path, FILE_FS_DEVICE_INFORMATION device_info; IO_STATUS_BLOCK io_status; NTSTATUS nt_status; - WCHAR* path_dirpath = NULL; - WCHAR* path_filename = NULL; + WCHAR *path_dirpath = NULL; + WCHAR *path_filename = NULL; UNICODE_STRING FileMask; size_t len; size_t split; @@ -2002,9 +1876,9 @@ static DWORD fs__stat_directory(WCHAR* path, includes_name = 0; while (split > 0 && path[split - 1] != L'\\' && path[split - 1] != L'/' && - path[split - 1] != L':') { + path[split - 1] != L':') { /* check if the path contains a character other than /,\,:,. */ - if (path[split-1] != '.') { + if (path[split - 1] != '.') { includes_name = 1; } split--; @@ -2012,18 +1886,18 @@ static DWORD fs__stat_directory(WCHAR* path, /* If the path is a relative path with a file name or a folder name */ if (split == 0 && includes_name) { path_dirpath = L"."; - /* If there is a slash or a backslash */ + /* If there is a slash or a backslash */ } else if (path[split - 1] == L'\\' || path[split - 1] == L'/') { path_dirpath = path; /* If there is no filename, consider it as a relative folder path */ if (!includes_name) { split = len; - /* Else, split it */ + /* Else, split it */ } else { splitchar = path[split - 1]; path[split - 1] = L'\0'; } - /* e.g. "..", "c:" */ + /* e.g. "..", "c:" */ } else { path_dirpath = path; split = len; @@ -2044,13 +1918,9 @@ static DWORD fs__stat_directory(WCHAR* path, } /* Get directory handle */ - handle = CreateFileW(path_dirpath, - FILE_LIST_DIRECTORY, + handle = CreateFileW(path_dirpath, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, - NULL); + NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (handle == INVALID_HANDLE_VALUE) { ret_error = GetLastError(); @@ -2063,17 +1933,9 @@ static DWORD fs__stat_directory(WCHAR* path, ret_error = pRtlNtStatusToDosError(nt_status); goto cleanup; } - nt_status = pNtQueryDirectoryFile(handle, - NULL, - NULL, - NULL, - &io_status, - &dir_info, - sizeof(dir_info), - FileIdFullDirectoryInformation, - TRUE, - &FileMask, - TRUE); + nt_status = pNtQueryDirectoryFile( + handle, NULL, NULL, NULL, &io_status, &dir_info, sizeof(dir_info), + FileIdFullDirectoryInformation, TRUE, &FileMask, TRUE); /* Buffer overflow (a warning status code) is expected here since there isn't * enough space to store the FileName, and actually indicates success. */ @@ -2111,9 +1973,7 @@ static DWORD fs__stat_directory(WCHAR* path, /* Finish up by getting device info from the directory handle, * since files presumably must live on their device. */ - nt_status = pNtQueryVolumeInformationFile(handle, - &io_status, - &volume_info, + nt_status = pNtQueryVolumeInformationFile(handle, &io_status, &volume_info, sizeof volume_info, FileFsVolumeInformation); @@ -2127,9 +1987,7 @@ static DWORD fs__stat_directory(WCHAR* path, stat_info.VolumeSerialNumber.QuadPart = volume_info.VolumeSerialNumber; } - nt_status = pNtQueryVolumeInformationFile(handle, - &io_status, - &device_info, + nt_status = pNtQueryVolumeInformationFile(handle, &io_status, &device_info, sizeof device_info, FileFsDeviceInformation); @@ -2153,21 +2011,20 @@ cleanup: return ret_error; } -static DWORD fs__stat_impl_from_path(WCHAR* path, - int do_lstat, - uv_stat_t* statbuf) { +static DWORD fs__stat_impl_from_path(WCHAR *path, int do_lstat, + uv_stat_t *statbuf) { HANDLE handle; DWORD flags; DWORD ret; /* If new API exists, try to use it. */ switch (fs__stat_path(path, statbuf, do_lstat)) { - case FS__STAT_PATH_SUCCESS: - return 0; - case FS__STAT_PATH_ERROR: - return GetLastError(); - case FS__STAT_PATH_TRY_SLOW: - break; + case FS__STAT_PATH_SUCCESS: + return 0; + case FS__STAT_PATH_ERROR: + return GetLastError(); + case FS__STAT_PATH_TRY_SLOW: + break; } /* If the new API does not exist, use the old API. */ @@ -2175,13 +2032,9 @@ static DWORD fs__stat_impl_from_path(WCHAR* path, if (do_lstat) flags |= FILE_FLAG_OPEN_REPARSE_POINT; - handle = CreateFileW(path, - FILE_READ_ATTRIBUTES, + handle = CreateFileW(path, FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - OPEN_EXISTING, - flags, - NULL); + NULL, OPEN_EXISTING, flags, NULL); if (handle == INVALID_HANDLE_VALUE) { ret = GetLastError(); @@ -2199,15 +2052,13 @@ static DWORD fs__stat_impl_from_path(WCHAR* path, return ret; } - -static void fs__stat_impl(uv_fs_t* req, int do_lstat) { +static void fs__stat_impl(uv_fs_t *req, int do_lstat) { DWORD error; error = fs__stat_impl_from_path(req->file.pathw, do_lstat, &req->statbuf); if (error != 0) { - if (do_lstat && - (error == ERROR_SYMLINK_NOT_SUPPORTED || - error == ERROR_NOT_A_REPARSE_POINT)) { + if (do_lstat && (error == ERROR_SYMLINK_NOT_SUPPORTED || + error == ERROR_NOT_A_REPARSE_POINT)) { /* We opened a reparse point but it was not a symlink. Try again. */ fs__stat_impl(req, 0); } else { @@ -2222,8 +2073,7 @@ static void fs__stat_impl(uv_fs_t* req, int do_lstat) { SET_REQ_RESULT(req, 0); } - -static int fs__fstat_handle(int fd, HANDLE handle, uv_stat_t* statbuf) { +static int fs__fstat_handle(int fd, HANDLE handle, uv_stat_t *statbuf) { DWORD file_type; /* Each file type is processed differently. */ @@ -2241,8 +2091,10 @@ static int fs__fstat_handle(int fd, HANDLE handle, uv_stat_t* statbuf) { memset(statbuf, 0, sizeof(uv_stat_t)); statbuf->st_mode = file_type == UV_TTY ? _S_IFCHR : _S_IFIFO; statbuf->st_nlink = 1; - statbuf->st_rdev = (file_type == UV_TTY ? FILE_DEVICE_CONSOLE : FILE_DEVICE_NAMED_PIPE) << 16; - statbuf->st_ino = (uintptr_t) handle; + statbuf->st_rdev = + (file_type == UV_TTY ? FILE_DEVICE_CONSOLE : FILE_DEVICE_NAMED_PIPE) + << 16; + statbuf->st_ino = (uintptr_t)handle; return 0; /* If file type is unknown it is an error. */ @@ -2253,20 +2105,17 @@ static int fs__fstat_handle(int fd, HANDLE handle, uv_stat_t* statbuf) { } } - -static void fs__stat(uv_fs_t* req) { +static void fs__stat(uv_fs_t *req) { fs__stat_prepare_path(req->file.pathw); fs__stat_impl(req, 0); } - -static void fs__lstat(uv_fs_t* req) { +static void fs__lstat(uv_fs_t *req) { fs__stat_prepare_path(req->file.pathw); fs__stat_impl(req, 1); } - -static void fs__fstat(uv_fs_t* req) { +static void fs__fstat(uv_fs_t *req) { int fd = req->file.fd; HANDLE handle; @@ -2288,9 +2137,9 @@ static void fs__fstat(uv_fs_t* req) { SET_REQ_RESULT(req, 0); } - -static void fs__rename(uv_fs_t* req) { - if (!MoveFileExW(req->file.pathw, req->fs.info.new_pathw, MOVEFILE_REPLACE_EXISTING)) { +static void fs__rename(uv_fs_t *req) { + if (!MoveFileExW(req->file.pathw, req->fs.info.new_pathw, + MOVEFILE_REPLACE_EXISTING)) { SET_REQ_WIN32_ERROR(req, GetLastError()); return; } @@ -2298,8 +2147,7 @@ static void fs__rename(uv_fs_t* req) { SET_REQ_RESULT(req, 0); } - -static void fs__sync_impl(uv_fs_t* req) { +static void fs__sync_impl(uv_fs_t *req) { int fd = req->file.fd; int result; @@ -2313,21 +2161,14 @@ static void fs__sync_impl(uv_fs_t* req) { } } +static void fs__fsync(uv_fs_t *req) { fs__sync_impl(req); } -static void fs__fsync(uv_fs_t* req) { - fs__sync_impl(req); -} +static void fs__fdatasync(uv_fs_t *req) { fs__sync_impl(req); } - -static void fs__fdatasync(uv_fs_t* req) { - fs__sync_impl(req); -} - - -static void fs__ftruncate(uv_fs_t* req) { +static void fs__ftruncate(uv_fs_t *req) { int fd = req->file.fd; HANDLE handle; - struct uv__fd_info_s fd_info = { 0 }; + struct uv__fd_info_s fd_info = {0}; NTSTATUS status; IO_STATUS_BLOCK io_status; FILE_END_OF_FILE_INFORMATION eof_info; @@ -2349,10 +2190,7 @@ static void fs__ftruncate(uv_fs_t* req) { eof_info.EndOfFile.QuadPart = req->fs.info.offset; - status = pNtSetInformationFile(handle, - &io_status, - &eof_info, - sizeof eof_info, + status = pNtSetInformationFile(handle, &io_status, &eof_info, sizeof eof_info, FileEndOfFileInformation); if (NT_SUCCESS(status)) { @@ -2376,14 +2214,14 @@ static void fs__ftruncate(uv_fs_t* req) { if (fd_info.size.QuadPart == 0) { fd_info.mapping = INVALID_HANDLE_VALUE; } else { - DWORD flProtect = (fd_info.flags & (UV_FS_O_RDONLY | UV_FS_O_WRONLY | - UV_FS_O_RDWR)) == UV_FS_O_RDONLY ? PAGE_READONLY : PAGE_READWRITE; - fd_info.mapping = CreateFileMapping(handle, - NULL, - flProtect, - fd_info.size.HighPart, - fd_info.size.LowPart, - NULL); + DWORD flProtect = + (fd_info.flags & (UV_FS_O_RDONLY | UV_FS_O_WRONLY | UV_FS_O_RDWR)) == + UV_FS_O_RDONLY + ? PAGE_READONLY + : PAGE_READWRITE; + fd_info.mapping = + CreateFileMapping(handle, NULL, flProtect, fd_info.size.HighPart, + fd_info.size.LowPart, NULL); if (fd_info.mapping == NULL) { SET_REQ_WIN32_ERROR(req, GetLastError()); CloseHandle(handle); @@ -2399,8 +2237,7 @@ static void fs__ftruncate(uv_fs_t* req) { } } - -static void fs__copyfile(uv_fs_t* req) { +static void fs__copyfile(uv_fs_t *req) { int flags; int overwrite; uv_stat_t statbuf; @@ -2436,8 +2273,7 @@ static void fs__copyfile(uv_fs_t* req) { } } - -static void fs__sendfile(uv_fs_t* req) { +static void fs__sendfile(uv_fs_t *req) { int fd_in = req->file.fd, fd_out = req->fs.info.fd_out; size_t length = req->fs.info.bufsml[0].len; int64_t offset = req->fs.info.offset; @@ -2445,7 +2281,7 @@ static void fs__sendfile(uv_fs_t* req) { size_t buf_size = length < max_buf_size ? length : max_buf_size; int n, result = 0; int64_t result_offset = 0; - char* buf = (char*) uv__malloc(buf_size); + char *buf = (char *)uv__malloc(buf_size); if (!buf) { uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc"); } @@ -2483,8 +2319,7 @@ static void fs__sendfile(uv_fs_t* req) { SET_REQ_RESULT(req, result); } - -static void fs__access(uv_fs_t* req) { +static void fs__access(uv_fs_t *req) { DWORD attr = GetFileAttributesW(req->file.pathw); if (attr == INVALID_FILE_ATTRIBUTES) { @@ -2499,18 +2334,15 @@ static void fs__access(uv_fs_t* req) { * - or it's a directory. * (Directories cannot be read-only on Windows.) */ - if (!(req->fs.info.mode & W_OK) || - !(attr & FILE_ATTRIBUTE_READONLY) || + if (!(req->fs.info.mode & W_OK) || !(attr & FILE_ATTRIBUTE_READONLY) || (attr & FILE_ATTRIBUTE_DIRECTORY)) { SET_REQ_RESULT(req, 0); } else { SET_REQ_WIN32_ERROR(req, UV_EPERM); } - } - -static void fs__chmod(uv_fs_t* req) { +static void fs__chmod(uv_fs_t *req) { int result = _wchmod(req->file.pathw, req->fs.info.mode); if (result == -1) SET_REQ_WIN32_ERROR(req, _doserrno); @@ -2518,8 +2350,7 @@ static void fs__chmod(uv_fs_t* req) { SET_REQ_RESULT(req, 0); } - -static void fs__fchmod(uv_fs_t* req) { +static void fs__fchmod(uv_fs_t *req) { int fd = req->file.fd; int clear_archive_flag; HANDLE handle; @@ -2535,11 +2366,8 @@ static void fs__fchmod(uv_fs_t* req) { return; } - nt_status = pNtQueryInformationFile(handle, - &io_status, - &file_info, - sizeof file_info, - FileBasicInformation); + nt_status = pNtQueryInformationFile(handle, &io_status, &file_info, + sizeof file_info, FileBasicInformation); if (!NT_SUCCESS(nt_status)) { SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status)); @@ -2548,22 +2376,19 @@ static void fs__fchmod(uv_fs_t* req) { /* Test if the Archive attribute is cleared */ if ((file_info.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == 0) { - /* Set Archive flag, otherwise setting or clearing the read-only - flag will not work */ - file_info.FileAttributes |= FILE_ATTRIBUTE_ARCHIVE; - nt_status = pNtSetInformationFile(handle, - &io_status, - &file_info, - sizeof file_info, - FileBasicInformation); - if (!NT_SUCCESS(nt_status)) { - SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status)); - goto fchmod_cleanup; - } - /* Remember to clear the flag later on */ - clear_archive_flag = 1; + /* Set Archive flag, otherwise setting or clearing the read-only + flag will not work */ + file_info.FileAttributes |= FILE_ATTRIBUTE_ARCHIVE; + nt_status = pNtSetInformationFile(handle, &io_status, &file_info, + sizeof file_info, FileBasicInformation); + if (!NT_SUCCESS(nt_status)) { + SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status)); + goto fchmod_cleanup; + } + /* Remember to clear the flag later on */ + clear_archive_flag = 1; } else { - clear_archive_flag = 0; + clear_archive_flag = 0; } if (req->fs.info.mode & _S_IWRITE) { @@ -2572,11 +2397,8 @@ static void fs__fchmod(uv_fs_t* req) { file_info.FileAttributes |= FILE_ATTRIBUTE_READONLY; } - nt_status = pNtSetInformationFile(handle, - &io_status, - &file_info, - sizeof file_info, - FileBasicInformation); + nt_status = pNtSetInformationFile(handle, &io_status, &file_info, + sizeof file_info, FileBasicInformation); if (!NT_SUCCESS(nt_status)) { SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status)); @@ -2584,19 +2406,16 @@ static void fs__fchmod(uv_fs_t* req) { } if (clear_archive_flag) { - file_info.FileAttributes &= ~FILE_ATTRIBUTE_ARCHIVE; - if (file_info.FileAttributes == 0) { - file_info.FileAttributes = FILE_ATTRIBUTE_NORMAL; - } - nt_status = pNtSetInformationFile(handle, - &io_status, - &file_info, - sizeof file_info, - FileBasicInformation); - if (!NT_SUCCESS(nt_status)) { - SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status)); - goto fchmod_cleanup; - } + file_info.FileAttributes &= ~FILE_ATTRIBUTE_ARCHIVE; + if (file_info.FileAttributes == 0) { + file_info.FileAttributes = FILE_ATTRIBUTE_NORMAL; + } + nt_status = pNtSetInformationFile(handle, &io_status, &file_info, + sizeof file_info, FileBasicInformation); + if (!NT_SUCCESS(nt_status)) { + SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status)); + goto fchmod_cleanup; + } } SET_REQ_SUCCESS(req); @@ -2604,7 +2423,6 @@ fchmod_cleanup: CloseHandle(handle); } - static int fs__utime_handle(HANDLE handle, double atime, double mtime) { FILETIME filetime_as, *filetime_a = &filetime_as; FILETIME filetime_ms, *filetime_m = &filetime_ms; @@ -2633,9 +2451,7 @@ static int fs__utime_handle(HANDLE handle, double atime, double mtime) { return 0; } -static DWORD fs__utime_impl_from_path(WCHAR* path, - double atime, - double mtime, +static DWORD fs__utime_impl_from_path(WCHAR *path, double atime, double mtime, int do_lutime) { HANDLE handle; DWORD flags; @@ -2646,13 +2462,9 @@ static DWORD fs__utime_impl_from_path(WCHAR* path, flags |= FILE_FLAG_OPEN_REPARSE_POINT; } - handle = CreateFileW(path, - FILE_WRITE_ATTRIBUTES, + handle = CreateFileW(path, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, - OPEN_EXISTING, - flags, - NULL); + NULL, OPEN_EXISTING, flags, NULL); if (handle == INVALID_HANDLE_VALUE) return GetLastError(); @@ -2666,18 +2478,15 @@ static DWORD fs__utime_impl_from_path(WCHAR* path, return ret; } -static void fs__utime_impl(uv_fs_t* req, int do_lutime) { +static void fs__utime_impl(uv_fs_t *req, int do_lutime) { DWORD error; - error = fs__utime_impl_from_path(req->file.pathw, - req->fs.time.atime, - req->fs.time.mtime, - do_lutime); + error = fs__utime_impl_from_path(req->file.pathw, req->fs.time.atime, + req->fs.time.mtime, do_lutime); if (error != 0) { - if (do_lutime && - (error == ERROR_SYMLINK_NOT_SUPPORTED || - error == ERROR_NOT_A_REPARSE_POINT)) { + if (do_lutime && (error == ERROR_SYMLINK_NOT_SUPPORTED || + error == ERROR_NOT_A_REPARSE_POINT)) { /* Opened file is a reparse point but not a symlink. Try again. */ fs__utime_impl(req, 0); } else { @@ -2691,12 +2500,9 @@ static void fs__utime_impl(uv_fs_t* req, int do_lutime) { SET_REQ_RESULT(req, 0); } -static void fs__utime(uv_fs_t* req) { - fs__utime_impl(req, /* do_lutime */ 0); -} +static void fs__utime(uv_fs_t *req) { fs__utime_impl(req, /* do_lutime */ 0); } - -static void fs__futime(uv_fs_t* req) { +static void fs__futime(uv_fs_t *req) { int fd = req->file.fd; HANDLE handle; VERIFY_FD(fd, req); @@ -2716,12 +2522,9 @@ static void fs__futime(uv_fs_t* req) { SET_REQ_RESULT(req, 0); } -static void fs__lutime(uv_fs_t* req) { - fs__utime_impl(req, /* do_lutime */ 1); -} +static void fs__lutime(uv_fs_t *req) { fs__utime_impl(req, /* do_lutime */ 1); } - -static void fs__link(uv_fs_t* req) { +static void fs__link(uv_fs_t *req) { DWORD r = CreateHardLinkW(req->fs.info.new_pathw, req->file.pathw, NULL); if (r == 0) SET_REQ_WIN32_ERROR(req, GetLastError()); @@ -2729,9 +2532,8 @@ static void fs__link(uv_fs_t* req) { SET_REQ_RESULT(req, 0); } - -static void fs__create_junction(uv_fs_t* req, const WCHAR* path, - const WCHAR* new_path) { +static void fs__create_junction(uv_fs_t *req, const WCHAR *path, + const WCHAR *new_path) { HANDLE handle = INVALID_HANDLE_VALUE; REPARSE_DATA_BUFFER *buffer = NULL; int created = 0; @@ -2741,7 +2543,7 @@ static void fs__create_junction(uv_fs_t* req, const WCHAR* path, int start, len, i; int add_slash; DWORD bytes; - WCHAR* path_buf; + WCHAR *path_buf; target_len = wcslen(path); is_long_path = wcsncmp(path, LONG_PATH_PREFIX, LONG_PATH_PREFIX_LEN) == 0; @@ -2749,8 +2551,8 @@ static void fs__create_junction(uv_fs_t* req, const WCHAR* path, if (is_long_path) { is_absolute = 1; } else { - is_absolute = target_len >= 3 && IS_LETTER(path[0]) && - path[1] == L':' && IS_SLASH(path[2]); + is_absolute = target_len >= 3 && IS_LETTER(path[0]) && path[1] == L':' && + IS_SLASH(path[2]); } if (!is_absolute) { @@ -2766,20 +2568,20 @@ static void fs__create_junction(uv_fs_t* req, const WCHAR* path, 2 * (target_len + 2) * sizeof(WCHAR); /* Allocate the buffer */ - buffer = (REPARSE_DATA_BUFFER*)uv__malloc(needed_buf_size); + buffer = (REPARSE_DATA_BUFFER *)uv__malloc(needed_buf_size); if (!buffer) { uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc"); } /* Grab a pointer to the part of the buffer where filenames go */ - path_buf = (WCHAR*)&(buffer->MountPointReparseBuffer.PathBuffer); + path_buf = (WCHAR *)&(buffer->MountPointReparseBuffer.PathBuffer); path_buf_len = 0; /* Copy the substitute (internal) target path */ start = path_buf_len; - wcsncpy((WCHAR*)&path_buf[path_buf_len], JUNCTION_PREFIX, - JUNCTION_PREFIX_LEN); + wcsncpy((WCHAR *)&path_buf[path_buf_len], JUNCTION_PREFIX, + JUNCTION_PREFIX_LEN); path_buf_len += JUNCTION_PREFIX_LEN; add_slash = 0; @@ -2837,10 +2639,11 @@ static void fs__create_junction(uv_fs_t* req, const WCHAR* path, buffer->MountPointReparseBuffer.PrintNameLength = len * sizeof(WCHAR); /* Calculate how much buffer space was actually used */ - used_buf_size = FIELD_OFFSET(REPARSE_DATA_BUFFER, MountPointReparseBuffer.PathBuffer) + - path_buf_len * sizeof(WCHAR); + used_buf_size = + FIELD_OFFSET(REPARSE_DATA_BUFFER, MountPointReparseBuffer.PathBuffer) + + path_buf_len * sizeof(WCHAR); used_data_size = used_buf_size - - FIELD_OFFSET(REPARSE_DATA_BUFFER, MountPointReparseBuffer); + FIELD_OFFSET(REPARSE_DATA_BUFFER, MountPointReparseBuffer); /* Put general info in the data buffer */ buffer->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT; @@ -2855,28 +2658,17 @@ static void fs__create_junction(uv_fs_t* req, const WCHAR* path, created = 1; /* Open the directory */ - handle = CreateFileW(new_path, - GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS | - FILE_FLAG_OPEN_REPARSE_POINT, - NULL); + handle = CreateFileW( + new_path, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); if (handle == INVALID_HANDLE_VALUE) { SET_REQ_WIN32_ERROR(req, GetLastError()); goto error; } /* Create the actual reparse point */ - if (!DeviceIoControl(handle, - FSCTL_SET_REPARSE_POINT, - buffer, - used_buf_size, - NULL, - 0, - &bytes, - NULL)) { + if (!DeviceIoControl(handle, FSCTL_SET_REPARSE_POINT, buffer, used_buf_size, + NULL, 0, &bytes, NULL)) { SET_REQ_WIN32_ERROR(req, GetLastError()); goto error; } @@ -2900,10 +2692,9 @@ error: } } - -static void fs__symlink(uv_fs_t* req) { - WCHAR* pathw; - WCHAR* new_pathw; +static void fs__symlink(uv_fs_t *req) { + WCHAR *pathw; + WCHAR *new_pathw; int flags; int err; @@ -2941,17 +2732,12 @@ static void fs__symlink(uv_fs_t* req) { } } - -static void fs__readlink(uv_fs_t* req) { +static void fs__readlink(uv_fs_t *req) { HANDLE handle; - handle = CreateFileW(req->file.pathw, - 0, - 0, - NULL, - OPEN_EXISTING, - FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, - NULL); + handle = CreateFileW( + req->file.pathw, 0, 0, NULL, OPEN_EXISTING, + FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, NULL); if (handle == INVALID_HANDLE_VALUE) { SET_REQ_WIN32_ERROR(req, GetLastError()); @@ -2959,7 +2745,7 @@ static void fs__readlink(uv_fs_t* req) { } assert(req->ptr == NULL); - if (fs__readlink_handle(handle, (char**) &req->ptr, NULL) != 0) { + if (fs__readlink_handle(handle, (char **)&req->ptr, NULL) != 0) { DWORD error = GetLastError(); SET_REQ_WIN32_ERROR(req, error); if (error == ERROR_NOT_A_REPARSE_POINT) @@ -2974,12 +2760,11 @@ static void fs__readlink(uv_fs_t* req) { CloseHandle(handle); } - -static ssize_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) { +static ssize_t fs__realpath_handle(HANDLE handle, char **realpath_ptr) { int r; DWORD w_realpath_len; - WCHAR* w_realpath_ptr = NULL; - WCHAR* w_realpath_buf; + WCHAR *w_realpath_ptr = NULL; + WCHAR *w_realpath_buf; w_realpath_len = GetFinalPathNameByHandleW(handle, NULL, 0, VOLUME_NAME_DOS); if (w_realpath_len == 0) { @@ -2993,23 +2778,20 @@ static ssize_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) { } w_realpath_ptr = w_realpath_buf; - if (GetFinalPathNameByHandleW( - handle, w_realpath_ptr, w_realpath_len, VOLUME_NAME_DOS) == 0) { + if (GetFinalPathNameByHandleW(handle, w_realpath_ptr, w_realpath_len, + VOLUME_NAME_DOS) == 0) { uv__free(w_realpath_buf); SetLastError(ERROR_INVALID_HANDLE); return -1; } /* convert UNC path to long path */ - if (wcsncmp(w_realpath_ptr, - UNC_PATH_PREFIX, - UNC_PATH_PREFIX_LEN) == 0) { + if (wcsncmp(w_realpath_ptr, UNC_PATH_PREFIX, UNC_PATH_PREFIX_LEN) == 0) { w_realpath_ptr += 6; *w_realpath_ptr = L'\\'; w_realpath_len -= 6; - } else if (wcsncmp(w_realpath_ptr, - LONG_PATH_PREFIX, - LONG_PATH_PREFIX_LEN) == 0) { + } else if (wcsncmp(w_realpath_ptr, LONG_PATH_PREFIX, LONG_PATH_PREFIX_LEN) == + 0) { w_realpath_ptr += 4; w_realpath_len -= 4; } else { @@ -3024,23 +2806,19 @@ static ssize_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) { return r; } -static void fs__realpath(uv_fs_t* req) { +static void fs__realpath(uv_fs_t *req) { HANDLE handle; - handle = CreateFileW(req->file.pathw, - 0, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, - NULL); + handle = + CreateFileW(req->file.pathw, 0, 0, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); if (handle == INVALID_HANDLE_VALUE) { SET_REQ_WIN32_ERROR(req, GetLastError()); return; } assert(req->ptr == NULL); - if (fs__realpath_handle(handle, (char**) &req->ptr) == -1) { + if (fs__realpath_handle(handle, (char **)&req->ptr) == -1) { CloseHandle(handle); SET_REQ_WIN32_ERROR(req, GetLastError()); return; @@ -3051,39 +2829,26 @@ static void fs__realpath(uv_fs_t* req) { SET_REQ_RESULT(req, 0); } +static void fs__chown(uv_fs_t *req) { SET_REQ_RESULT(req, 0); } -static void fs__chown(uv_fs_t* req) { - SET_REQ_RESULT(req, 0); -} +static void fs__fchown(uv_fs_t *req) { SET_REQ_RESULT(req, 0); } +static void fs__lchown(uv_fs_t *req) { SET_REQ_RESULT(req, 0); } -static void fs__fchown(uv_fs_t* req) { - SET_REQ_RESULT(req, 0); -} - - -static void fs__lchown(uv_fs_t* req) { - SET_REQ_RESULT(req, 0); -} - - -static void fs__statfs(uv_fs_t* req) { - uv_statfs_t* stat_fs; +static void fs__statfs(uv_fs_t *req) { + uv_statfs_t *stat_fs; DWORD sectors_per_cluster; DWORD bytes_per_sector; DWORD free_clusters; DWORD total_clusters; - WCHAR* pathw; + WCHAR *pathw; pathw = req->file.pathw; retry_get_disk_free_space: - if (0 == GetDiskFreeSpaceW(pathw, - §ors_per_cluster, - &bytes_per_sector, - &free_clusters, - &total_clusters)) { + if (0 == GetDiskFreeSpaceW(pathw, §ors_per_cluster, &bytes_per_sector, + &free_clusters, &total_clusters)) { DWORD err; - WCHAR* fpart; + WCHAR *fpart; size_t len; DWORD ret; BOOL is_second; @@ -3104,11 +2869,8 @@ retry_get_disk_free_space: SET_REQ_UV_ERROR(req, UV_ENOMEM, ERROR_OUTOFMEMORY); return; } -retry_get_full_path_name: - ret = GetFullPathNameW(req->file.pathw, - len, - pathw, - &fpart); + retry_get_full_path_name: + ret = GetFullPathNameW(req->file.pathw, len, pathw, &fpart); if (ret == 0) { uv__free(pathw); SET_REQ_WIN32_ERROR(req, err); @@ -3149,14 +2911,16 @@ retry_get_full_path_name: SET_REQ_RESULT(req, 0); } - -static void uv__fs_work(struct uv__work* w) { - uv_fs_t* req; +static void uv__fs_work(struct uv__work *w) { + uv_fs_t *req; req = container_of(w, uv_fs_t, work_req); assert(req->type == UV_FS); -#define XX(uc, lc) case UV_FS_##uc: fs__##lc(req); break; +#define XX(uc, lc) \ + case UV_FS_##uc: \ + fs__##lc(req); \ + break; switch (req->fs_type) { XX(OPEN, open) XX(CLOSE, close) @@ -3194,14 +2958,13 @@ static void uv__fs_work(struct uv__work* w) { XX(FCHOWN, fchown) XX(LCHOWN, lchown) XX(STATFS, statfs) - default: - assert(!"bad uv_fs_type"); + default: + assert(!"bad uv_fs_type"); } } - -static void uv__fs_done(struct uv__work* w, int status) { - uv_fs_t* req; +static void uv__fs_done(struct uv__work *w, int status) { + uv_fs_t *req; req = container_of(w, uv_fs_t, work_req); uv__req_unregister(req->loop); @@ -3211,11 +2974,13 @@ static void uv__fs_done(struct uv__work* w, int status) { SET_REQ_UV_ERROR(req, UV_ECANCELED, 0); } + if (req->reserved[0] == (void *)UV__REQ_INTERNAL) + uv__req_register(req->loop); + req->cb(req); } - -void uv_fs_req_cleanup(uv_fs_t* req) { +void uv_fs_req_cleanup(uv_fs_t *req) { if (req == NULL) return; @@ -3246,9 +3011,8 @@ void uv_fs_req_cleanup(uv_fs_t* req) { req->flags |= UV_FS_CLEANEDUP; } - -int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, - int mode, uv_fs_cb cb) { +int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, + int mode, uv_fs_cb cb) { int err; INIT(UV_FS_OPEN); @@ -3263,21 +3027,14 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, POST; } - -int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) { +int uv_fs_close(uv_loop_t *loop, uv_fs_t *req, uv_file fd, uv_fs_cb cb) { INIT(UV_FS_CLOSE); req->file.fd = fd; POST; } - -int uv_fs_read(uv_loop_t* loop, - uv_fs_t* req, - uv_file fd, - const uv_buf_t bufs[], - unsigned int nbufs, - int64_t offset, - uv_fs_cb cb) { +int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file fd, const uv_buf_t bufs[], + unsigned int nbufs, int64_t offset, uv_fs_cb cb) { INIT(UV_FS_READ); if (bufs == NULL || nbufs == 0) { @@ -3303,13 +3060,8 @@ int uv_fs_read(uv_loop_t* loop, POST; } - -int uv_fs_write(uv_loop_t* loop, - uv_fs_t* req, - uv_file fd, - const uv_buf_t bufs[], - unsigned int nbufs, - int64_t offset, +int uv_fs_write(uv_loop_t *loop, uv_fs_t *req, uv_file fd, + const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb) { INIT(UV_FS_WRITE); @@ -3336,9 +3088,7 @@ int uv_fs_write(uv_loop_t* loop, POST; } - -int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, - uv_fs_cb cb) { +int uv_fs_unlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { int err; INIT(UV_FS_UNLINK); @@ -3351,9 +3101,8 @@ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, POST; } - -int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, - uv_fs_cb cb) { +int uv_fs_mkdir(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, + uv_fs_cb cb) { int err; INIT(UV_FS_MKDIR); @@ -3367,11 +3116,7 @@ int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, POST; } - -int uv_fs_mkdtemp(uv_loop_t* loop, - uv_fs_t* req, - const char* tpl, - uv_fs_cb cb) { +int uv_fs_mkdtemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb) { int err; INIT(UV_FS_MKDTEMP); @@ -3384,11 +3129,7 @@ int uv_fs_mkdtemp(uv_loop_t* loop, POST; } - -int uv_fs_mkstemp(uv_loop_t* loop, - uv_fs_t* req, - const char* tpl, - uv_fs_cb cb) { +int uv_fs_mkstemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb) { int err; INIT(UV_FS_MKSTEMP); @@ -3401,8 +3142,7 @@ int uv_fs_mkstemp(uv_loop_t* loop, POST; } - -int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { int err; INIT(UV_FS_RMDIR); @@ -3415,9 +3155,8 @@ int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { POST; } - -int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, - uv_fs_cb cb) { +int uv_fs_scandir(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, + uv_fs_cb cb) { int err; INIT(UV_FS_SCANDIR); @@ -3431,9 +3170,7 @@ int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, POST; } -int uv_fs_opendir(uv_loop_t* loop, - uv_fs_t* req, - const char* path, +int uv_fs_opendir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { int err; @@ -3446,14 +3183,10 @@ int uv_fs_opendir(uv_loop_t* loop, POST; } -int uv_fs_readdir(uv_loop_t* loop, - uv_fs_t* req, - uv_dir_t* dir, - uv_fs_cb cb) { +int uv_fs_readdir(uv_loop_t *loop, uv_fs_t *req, uv_dir_t *dir, uv_fs_cb cb) { INIT(UV_FS_READDIR); - if (dir == NULL || - dir->dirents == NULL || + if (dir == NULL || dir->dirents == NULL || dir->dir_handle == INVALID_HANDLE_VALUE) { SET_REQ_UV_ERROR(req, UV_EINVAL, ERROR_INVALID_PARAMETER); return UV_EINVAL; @@ -3463,10 +3196,7 @@ int uv_fs_readdir(uv_loop_t* loop, POST; } -int uv_fs_closedir(uv_loop_t* loop, - uv_fs_t* req, - uv_dir_t* dir, - uv_fs_cb cb) { +int uv_fs_closedir(uv_loop_t *loop, uv_fs_t *req, uv_dir_t *dir, uv_fs_cb cb) { INIT(UV_FS_CLOSEDIR); if (dir == NULL) { SET_REQ_UV_ERROR(req, UV_EINVAL, ERROR_INVALID_PARAMETER); @@ -3476,8 +3206,8 @@ int uv_fs_closedir(uv_loop_t* loop, POST; } -int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path, - const char* new_path, uv_fs_cb cb) { +int uv_fs_link(uv_loop_t *loop, uv_fs_t *req, const char *path, + const char *new_path, uv_fs_cb cb) { int err; INIT(UV_FS_LINK); @@ -3490,9 +3220,8 @@ int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path, POST; } - -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) { +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) { int err; INIT(UV_FS_SYMLINK); @@ -3506,9 +3235,8 @@ int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path, POST; } - -int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, - uv_fs_cb cb) { +int uv_fs_readlink(uv_loop_t *loop, uv_fs_t *req, const char *path, + uv_fs_cb cb) { int err; INIT(UV_FS_READLINK); @@ -3521,9 +3249,8 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, POST; } - -int uv_fs_realpath(uv_loop_t* loop, uv_fs_t* req, const char* path, - uv_fs_cb cb) { +int uv_fs_realpath(uv_loop_t *loop, uv_fs_t *req, const char *path, + uv_fs_cb cb) { int err; INIT(UV_FS_REALPATH); @@ -3542,9 +3269,8 @@ int uv_fs_realpath(uv_loop_t* loop, uv_fs_t* req, const char* path, POST; } - -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) { +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) { int err; INIT(UV_FS_CHOWN); @@ -3557,16 +3283,14 @@ int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_uid_t uid, POST; } - -int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_uid_t uid, - uv_gid_t gid, uv_fs_cb cb) { +int uv_fs_fchown(uv_loop_t *loop, uv_fs_t *req, uv_file fd, uv_uid_t uid, + uv_gid_t gid, uv_fs_cb cb) { INIT(UV_FS_FCHOWN); POST; } - -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) { +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) { int err; INIT(UV_FS_LCHOWN); @@ -3579,8 +3303,7 @@ int uv_fs_lchown(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_uid_t uid, POST; } - -int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_stat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { int err; INIT(UV_FS_STAT); @@ -3593,8 +3316,7 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { POST; } - -int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { +int uv_fs_lstat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { int err; INIT(UV_FS_LSTAT); @@ -3607,16 +3329,14 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { POST; } - -int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) { +int uv_fs_fstat(uv_loop_t *loop, uv_fs_t *req, uv_file fd, uv_fs_cb cb) { INIT(UV_FS_FSTAT); req->file.fd = fd; POST; } - -int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path, - const char* new_path, uv_fs_cb cb) { +int uv_fs_rename(uv_loop_t *loop, uv_fs_t *req, const char *path, + const char *new_path, uv_fs_cb cb) { int err; INIT(UV_FS_RENAME); @@ -3629,42 +3349,33 @@ int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path, POST; } - -int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) { +int uv_fs_fsync(uv_loop_t *loop, uv_fs_t *req, uv_file fd, uv_fs_cb cb) { INIT(UV_FS_FSYNC); req->file.fd = fd; POST; } - -int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) { +int uv_fs_fdatasync(uv_loop_t *loop, uv_fs_t *req, uv_file fd, uv_fs_cb cb) { INIT(UV_FS_FDATASYNC); req->file.fd = fd; POST; } - -int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file fd, - int64_t offset, uv_fs_cb cb) { +int uv_fs_ftruncate(uv_loop_t *loop, uv_fs_t *req, uv_file fd, int64_t offset, + uv_fs_cb cb) { INIT(UV_FS_FTRUNCATE); req->file.fd = fd; req->fs.info.offset = offset; POST; } - -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) { +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) { int err; INIT(UV_FS_COPYFILE); - if (flags & ~(UV_FS_COPYFILE_EXCL | - UV_FS_COPYFILE_FICLONE | + if (flags & ~(UV_FS_COPYFILE_EXCL | UV_FS_COPYFILE_FICLONE | UV_FS_COPYFILE_FICLONE_FORCE)) { SET_REQ_UV_ERROR(req, UV_EINVAL, ERROR_INVALID_PARAMETER); return UV_EINVAL; @@ -3680,9 +3391,8 @@ int uv_fs_copyfile(uv_loop_t* loop, POST; } - -int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file fd_out, - uv_file fd_in, int64_t in_offset, size_t length, uv_fs_cb cb) { +int uv_fs_sendfile(uv_loop_t *loop, uv_fs_t *req, uv_file fd_out, uv_file fd_in, + int64_t in_offset, size_t length, uv_fs_cb cb) { INIT(UV_FS_SENDFILE); req->file.fd = fd_in; req->fs.info.fd_out = fd_out; @@ -3691,11 +3401,7 @@ int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file fd_out, POST; } - -int uv_fs_access(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - int flags, +int uv_fs_access(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) { int err; @@ -3710,9 +3416,8 @@ int uv_fs_access(uv_loop_t* loop, POST; } - -int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, - uv_fs_cb cb) { +int uv_fs_chmod(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, + uv_fs_cb cb) { int err; INIT(UV_FS_CHMOD); @@ -3726,18 +3431,16 @@ int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, POST; } - -int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file fd, int mode, - uv_fs_cb cb) { +int uv_fs_fchmod(uv_loop_t *loop, uv_fs_t *req, uv_file fd, int mode, + uv_fs_cb cb) { INIT(UV_FS_FCHMOD); req->file.fd = fd; req->fs.info.mode = mode; POST; } - -int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, - double mtime, uv_fs_cb cb) { +int uv_fs_utime(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, + double mtime, uv_fs_cb cb) { int err; INIT(UV_FS_UTIME); @@ -3752,9 +3455,8 @@ int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, POST; } - -int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file fd, double atime, - double mtime, uv_fs_cb cb) { +int uv_fs_futime(uv_loop_t *loop, uv_fs_t *req, uv_file fd, double atime, + double mtime, uv_fs_cb cb) { INIT(UV_FS_FUTIME); req->file.fd = fd; req->fs.time.atime = atime; @@ -3762,8 +3464,8 @@ int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file fd, double atime, POST; } -int uv_fs_lutime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, - double mtime, uv_fs_cb cb) { +int uv_fs_lutime(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, + double mtime, uv_fs_cb cb) { int err; INIT(UV_FS_LUTIME); @@ -3778,11 +3480,7 @@ int uv_fs_lutime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, POST; } - -int uv_fs_statfs(uv_loop_t* loop, - uv_fs_t* req, - const char* path, - uv_fs_cb cb) { +int uv_fs_statfs(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { int err; INIT(UV_FS_STATFS); @@ -3795,6 +3493,4 @@ int uv_fs_statfs(uv_loop_t* loop, POST; } -int uv_fs_get_system_error(const uv_fs_t* req) { - return req->sys_errno_; -} +int uv_fs_get_system_error(const uv_fs_t *req) { return req->sys_errno_; }