ext/libuv/src/unix/fs.c in libuv-4.0.1 vs ext/libuv/src/unix/fs.c in libuv-4.0.2
- old
+ new
@@ -60,27 +60,25 @@
# include <sys/sendfile.h>
#endif
#if defined(__APPLE__)
# include <copyfile.h>
-#elif defined(__linux__) && !defined(FICLONE)
-# include <sys/ioctl.h>
-# define FICLONE _IOW(0x94, 9, int)
#endif
#define INIT(subtype) \
do { \
if (req == NULL) \
- return UV_EINVAL; \
- UV_REQ_INIT(req, UV_FS); \
+ return -EINVAL; \
+ req->type = UV_FS; \
+ if (cb != NULL) \
+ uv__req_init(loop, 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 PATH \
@@ -88,12 +86,14 @@
assert(path != NULL); \
if (cb == NULL) { \
req->path = path; \
} else { \
req->path = uv__strdup(path); \
- if (req->path == NULL) \
- return UV_ENOMEM; \
+ if (req->path == NULL) { \
+ uv__req_unregister(loop, req); \
+ return -ENOMEM; \
+ } \
} \
} \
while (0)
#define PATH2 \
@@ -105,23 +105,24 @@
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; \
+ if (req->path == NULL) { \
+ uv__req_unregister(loop, req); \
+ return -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, req); \
uv__work_submit(loop, &req->work_req, uv__fs_work, uv__fs_done); \
return 0; \
} \
else { \
uv__fs_work(&req->work_req); \
@@ -791,23 +792,10 @@
flags = COPYFILE_ALL;
if (req->flags & UV_FS_COPYFILE_EXCL)
flags |= COPYFILE_EXCL;
-#ifdef COPYFILE_CLONE
- if (req->flags & UV_FS_COPYFILE_FICLONE)
- flags |= COPYFILE_CLONE;
-#endif
-
- if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
-#ifdef COPYFILE_CLONE_FORCE
- flags |= COPYFILE_CLONE_FORCE;
-#else
- return UV_ENOSYS;
-#endif
- }
-
return copyfile(req->path, req->new_path, NULL, flags);
#else
uv_fs_t fs_req;
uv_file srcfd;
uv_file dstfd;
@@ -828,11 +816,11 @@
if (srcfd < 0)
return srcfd;
/* Get the source file's mode. */
if (fstat(srcfd, &statsbuf)) {
- err = UV__ERR(errno);
+ err = -errno;
goto out;
}
dst_flags = O_WRONLY | O_CREAT | O_TRUNC;
@@ -852,37 +840,14 @@
err = dstfd;
goto out;
}
if (fchmod(dstfd, statsbuf.st_mode) == -1) {
- err = UV__ERR(errno);
+ err = -errno;
goto out;
}
-#ifdef FICLONE
- if (req->flags & UV_FS_COPYFILE_FICLONE ||
- req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
- if (ioctl(dstfd, FICLONE, srcfd) == -1) {
- /* If an error occurred that the sendfile fallback also won't handle, or
- this is a force clone then exit. Otherwise, fall through to try using
- sendfile(). */
- if ((errno != ENOTTY && errno != EOPNOTSUPP && errno != EXDEV) ||
- req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
- err = -errno;
- goto out;
- }
- } else {
- goto out;
- }
- }
-#else
- if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
- err = UV_ENOSYS;
- goto out;
- }
-#endif
-
bytes_to_send = statsbuf.st_size;
in_offset = 0;
while (bytes_to_send != 0) {
err = uv_fs_sendfile(NULL,
&fs_req,
@@ -1140,11 +1105,11 @@
}
#undef X
} while (r == -1 && errno == EINTR && retry_on_eintr);
if (r == -1)
- req->result = UV__ERR(errno);
+ req->result = -errno;
else
req->result = r;
if (r == 0 && (req->fs_type == UV_FS_STAT ||
req->fs_type == UV_FS_FSTAT ||
@@ -1158,13 +1123,13 @@
uv_fs_t* req;
req = container_of(w, uv_fs_t, work_req);
uv__req_unregister(req->loop, req);
- if (status == UV_ECANCELED) {
+ if (status == -ECANCELED) {
assert(req->result == 0);
- req->result = UV_ECANCELED;
+ req->result = -ECANCELED;
}
req->cb(req);
}
@@ -1321,12 +1286,15 @@
uv_fs_t* req,
const char* tpl,
uv_fs_cb cb) {
INIT(MKDTEMP);
req->path = uv__strdup(tpl);
- if (req->path == NULL)
- return UV_ENOMEM;
+ if (req->path == NULL) {
+ if (cb != NULL)
+ uv__req_unregister(loop, req);
+ return -ENOMEM;
+ }
POST;
}
int uv_fs_open(uv_loop_t* loop,
@@ -1350,21 +1318,24 @@
int64_t off,
uv_fs_cb cb) {
INIT(READ);
if (bufs == NULL || nbufs == 0)
- return UV_EINVAL;
+ return -EINVAL;
req->file = file;
req->nbufs = nbufs;
req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml))
req->bufs = uv__malloc(nbufs * sizeof(*bufs));
- if (req->bufs == NULL)
- return UV_ENOMEM;
+ if (req->bufs == NULL) {
+ if (cb != NULL)
+ uv__req_unregister(loop, req);
+ return -ENOMEM;
+ }
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
req->off = off;
POST;
@@ -1486,21 +1457,24 @@
int64_t off,
uv_fs_cb cb) {
INIT(WRITE);
if (bufs == NULL || nbufs == 0)
- return UV_EINVAL;
+ return -EINVAL;
req->file = file;
req->nbufs = nbufs;
req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml))
req->bufs = uv__malloc(nbufs * sizeof(*bufs));
- if (req->bufs == NULL)
- return UV_ENOMEM;
+ if (req->bufs == NULL) {
+ if (cb != NULL)
+ uv__req_unregister(loop, req);
+ return -ENOMEM;
+ }
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
req->off = off;
POST;
@@ -1523,14 +1497,10 @@
req->new_path = NULL;
if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL)
uv__fs_scandir_cleanup(req);
- if (req->bufs != req->bufsml)
- uv__free(req->bufs);
- req->bufs = NULL;
-
if (req->ptr != &req->statbuf)
uv__free(req->ptr);
req->ptr = NULL;
}
@@ -1541,14 +1511,11 @@
const char* new_path,
int flags,
uv_fs_cb cb) {
INIT(COPYFILE);
- if (flags & ~(UV_FS_COPYFILE_EXCL |
- UV_FS_COPYFILE_FICLONE |
- UV_FS_COPYFILE_FICLONE_FORCE)) {
- return UV_EINVAL;
- }
+ if (flags & ~UV_FS_COPYFILE_EXCL)
+ return -EINVAL;
PATH2;
req->flags = flags;
POST;
}