Rizin
unix-like reverse engineering framework and cli tools
fs.c File Reference
#include "uv.h"
#include "internal.h"
#include <errno.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include <sys/statfs.h>

Go to the source code of this file.

Macros

#define HAVE_PREADV   0
 
#define INIT(subtype)
 
#define PATH
 
#define PATH2
 
#define POST
 
#define UV_CONST_DIRENT   const uv__dirent_t
 
#define X(type, action)
 

Functions

static int uv__fs_close (int fd)
 
static ssize_t uv__fs_fsync (uv_fs_t *req)
 
static ssize_t uv__fs_fdatasync (uv_fs_t *req)
 
 UV_UNUSED (static struct timespec uv__fs_to_timespec(double time))
 
 UV_UNUSED (static struct timeval uv__fs_to_timeval(double time))
 
static ssize_t uv__fs_futime (uv_fs_t *req)
 
static ssize_t uv__fs_mkdtemp (uv_fs_t *req)
 
static void uv__mkostemp_initonce (void)
 
static int uv__fs_mkstemp (uv_fs_t *req)
 
static ssize_t uv__fs_open (uv_fs_t *req)
 
static ssize_t uv__fs_preadv (uv_file fd, uv_buf_t *bufs, unsigned int nbufs, off_t off)
 
static ssize_t uv__fs_read (uv_fs_t *req)
 
static int uv__fs_scandir_filter (UV_CONST_DIRENT *dent)
 
static int uv__fs_scandir_sort (UV_CONST_DIRENT **a, UV_CONST_DIRENT **b)
 
static ssize_t uv__fs_scandir (uv_fs_t *req)
 
static int uv__fs_opendir (uv_fs_t *req)
 
static int uv__fs_readdir (uv_fs_t *req)
 
static int uv__fs_closedir (uv_fs_t *req)
 
static int uv__fs_statfs (uv_fs_t *req)
 
static ssize_t uv__fs_pathmax_size (const char *path)
 
static ssize_t uv__fs_readlink (uv_fs_t *req)
 
static ssize_t uv__fs_realpath (uv_fs_t *req)
 
static ssize_t uv__fs_sendfile_emul (uv_fs_t *req)
 
static ssize_t uv__fs_sendfile (uv_fs_t *req)
 
static ssize_t uv__fs_utime (uv_fs_t *req)
 
static ssize_t uv__fs_lutime (uv_fs_t *req)
 
static ssize_t uv__fs_write (uv_fs_t *req)
 
static ssize_t uv__fs_copyfile (uv_fs_t *req)
 
static void uv__to_stat (struct stat *src, uv_stat_t *dst)
 
static int uv__fs_statx (int fd, const char *path, int is_fstat, int is_lstat, uv_stat_t *buf)
 
static int uv__fs_stat (const char *path, uv_stat_t *buf)
 
static int uv__fs_lstat (const char *path, uv_stat_t *buf)
 
static int uv__fs_fstat (int fd, uv_stat_t *buf)
 
static size_t uv__fs_buf_offset (uv_buf_t *bufs, size_t size)
 
static ssize_t uv__fs_write_all (uv_fs_t *req)
 
static void uv__fs_work (struct uv__work *w)
 
static void uv__fs_done (struct uv__work *w, int status)
 
int uv_fs_access (uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, 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 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_close (uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
 
int uv_fs_fchmod (uv_loop_t *loop, uv_fs_t *req, uv_file file, int mode, 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)
 
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_fdatasync (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)
 
int uv_fs_fsync (uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
 
int uv_fs_ftruncate (uv_loop_t *loop, uv_fs_t *req, uv_file file, int64_t off, 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)
 
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_lstat (uv_loop_t *loop, uv_fs_t *req, const char *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 uv_fs_mkdir (uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb)
 
int uv_fs_mkdtemp (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 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_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)
 
int uv_fs_scandir (uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb)
 
int uv_fs_opendir (uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
 
int uv_fs_readdir (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)
 
int uv_fs_readlink (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 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_rmdir (uv_loop_t *loop, uv_fs_t *req, const char *path, 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)
 
int uv_fs_stat (uv_loop_t *loop, uv_fs_t *req, const char *path, 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 uv_fs_unlink (uv_loop_t *loop, uv_fs_t *req, const char *path, 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 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)
 
void uv_fs_req_cleanup (uv_fs_t *req)
 
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_statfs (uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
 
int uv_fs_get_system_error (const uv_fs_t *req)
 

Variables

static int(* uv__mkostemp )(char *, int)
 

Macro Definition Documentation

◆ HAVE_PREADV

#define HAVE_PREADV   0

Definition at line 56 of file fs.c.

◆ INIT

#define INIT (   subtype)
Value:
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 NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
uv_loop_t * loop
Definition: main.c:7
static const char * cb[]
Definition: z80_tab.h:176

Definition at line 96 of file fs.c.

◆ PATH

#define PATH
Value:
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)
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
char * uv__strdup(const char *s)
Definition: uv-common.c:55

Definition at line 112 of file fs.c.

◆ PATH2

#define PATH2
Value:
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)
void * uv__malloc(size_t size)
Definition: uv-common.c:75

Definition at line 125 of file fs.c.

◆ POST

#define POST
Value:
do { \
if (cb != NULL) { \
uv__req_register(loop, req); \
uv__work_submit(loop, \
&req->work_req, \
return 0; \
} \
else { \
uv__fs_work(&req->work_req); \
return req->result; \
} \
} \
while (0)
static void uv__fs_done(struct uv__work *w, int status)
Definition: fs.c:1644
static void uv__fs_work(struct uv__work *w)
Definition: fs.c:1572
@ UV__WORK_FAST_IO
Definition: uv-common.h:193

Definition at line 145 of file fs.c.

◆ UV_CONST_DIRENT

#define UV_CONST_DIRENT   const uv__dirent_t

Definition at line 514 of file fs.c.

◆ X

#define X (   type,
  action 
)
Value:
case UV_FS_ ## type: \
r = action; \
break;
int type
Definition: mipsasm.c:17

Function Documentation

◆ uv__fs_buf_offset()

static size_t uv__fs_buf_offset ( uv_buf_t bufs,
size_t  size 
)
static

Definition at line 1512 of file fs.c.

1512  {
1513  size_t offset;
1514  /* Figure out which bufs are done */
1515  for (offset = 0; size > 0 && bufs[offset].len <= size; ++offset)
1516  size -= bufs[offset].len;
1517 
1518  /* Fix a partial read/write */
1519  if (size > 0) {
1520  bufs[offset].base += size;
1521  bufs[offset].len -= size;
1522  }
1523  return offset;
1524 }
size_t len
Definition: 6502dis.c:15
voidpf void uLong size
Definition: ioapi.h:138
voidpf uLong offset
Definition: ioapi.h:144
static char bufs[4][128]
Buffers for uint64_to_str() and uint64_to_nicestr()
Definition: util.c:18

References bufs, and len.

Referenced by uv__fs_write_all().

◆ uv__fs_close()

static int uv__fs_close ( int  fd)
static

Definition at line 164 of file fs.c.

164  {
165  int rc;
166 
167  rc = uv__close_nocancel(fd);
168  if (rc == -1)
169  if (errno == EINTR || errno == EINPROGRESS)
170  rc = 0; /* The close is in progress, not an error. */
171 
172  return rc;
173 }
#define EINTR
Definition: sftypes.h:114
#define EINPROGRESS
Definition: sftypes.h:175
int uv__close_nocancel(int fd)
Definition: core.c:530
static const z80_opcode fd[]
Definition: z80_tab.h:997

References EINPROGRESS, EINTR, fd, and uv__close_nocancel().

Referenced by uv__fs_work().

◆ uv__fs_closedir()

static int uv__fs_closedir ( uv_fs_t req)
static

Definition at line 619 of file fs.c.

619  {
620  uv_dir_t* dir;
621 
622  dir = req->ptr;
623 
624  if (dir->dir != NULL) {
625  closedir(dir->dir);
626  dir->dir = NULL;
627  }
628 
629  uv__free(req->ptr);
630  req->ptr = NULL;
631  return 0;
632 }
Definition: uv.h:1298
void uv__free(void *ptr)
Definition: uv-common.c:81

References NULL, req, and uv__free().

Referenced by uv__fs_work().

◆ uv__fs_copyfile()

static ssize_t uv__fs_copyfile ( uv_fs_t req)
static

Definition at line 1136 of file fs.c.

1136  {
1137  uv_fs_t fs_req;
1138  uv_file srcfd;
1139  uv_file dstfd;
1140  struct stat src_statsbuf;
1141  struct stat dst_statsbuf;
1142  int dst_flags;
1143  int result;
1144  int err;
1145  off_t bytes_to_send;
1146  off_t in_offset;
1147  off_t bytes_written;
1148  size_t bytes_chunk;
1149 
1150  dstfd = -1;
1151  err = 0;
1152 
1153  /* Open the source file. */
1154  srcfd = uv_fs_open(NULL, &fs_req, req->path, O_RDONLY, 0, NULL);
1155  uv_fs_req_cleanup(&fs_req);
1156 
1157  if (srcfd < 0)
1158  return srcfd;
1159 
1160  /* Get the source file's mode. */
1161  if (fstat(srcfd, &src_statsbuf)) {
1162  err = UV__ERR(errno);
1163  goto out;
1164  }
1165 
1166  dst_flags = O_WRONLY | O_CREAT;
1167 
1168  if (req->flags & UV_FS_COPYFILE_EXCL)
1169  dst_flags |= O_EXCL;
1170 
1171  /* Open the destination file. */
1172  dstfd = uv_fs_open(NULL,
1173  &fs_req,
1174  req->new_path,
1175  dst_flags,
1176  src_statsbuf.st_mode,
1177  NULL);
1178  uv_fs_req_cleanup(&fs_req);
1179 
1180  if (dstfd < 0) {
1181  err = dstfd;
1182  goto out;
1183  }
1184 
1185  /* If the file is not being opened exclusively, verify that the source and
1186  destination are not the same file. If they are the same, bail out early. */
1187  if ((req->flags & UV_FS_COPYFILE_EXCL) == 0) {
1188  /* Get the destination file's mode. */
1189  if (fstat(dstfd, &dst_statsbuf)) {
1190  err = UV__ERR(errno);
1191  goto out;
1192  }
1193 
1194  /* Check if srcfd and dstfd refer to the same file */
1195  if (src_statsbuf.st_dev == dst_statsbuf.st_dev &&
1196  src_statsbuf.st_ino == dst_statsbuf.st_ino) {
1197  goto out;
1198  }
1199 
1200  /* Truncate the file in case the destination already existed. */
1201  if (ftruncate(dstfd, 0) != 0) {
1202  err = UV__ERR(errno);
1203  goto out;
1204  }
1205  }
1206 
1207  if (fchmod(dstfd, src_statsbuf.st_mode) == -1) {
1208  err = UV__ERR(errno);
1209 #ifdef __linux__
1210  if (err != UV_EPERM)
1211  goto out;
1212 
1213  {
1214  struct statfs s;
1215 
1216  /* fchmod() on CIFS shares always fails with EPERM unless the share is
1217  * mounted with "noperm". As fchmod() is a meaningless operation on such
1218  * shares anyway, detect that condition and squelch the error.
1219  */
1220  if (fstatfs(dstfd, &s) == -1)
1221  goto out;
1222 
1223  if (s.f_type != /* CIFS */ 0xFF534D42u)
1224  goto out;
1225  }
1226 
1227  err = 0;
1228 #else /* !__linux__ */
1229  goto out;
1230 #endif /* !__linux__ */
1231  }
1232 
1233 #ifdef FICLONE
1234  if (req->flags & UV_FS_COPYFILE_FICLONE ||
1235  req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
1236  if (ioctl(dstfd, FICLONE, srcfd) == 0) {
1237  /* ioctl() with FICLONE succeeded. */
1238  goto out;
1239  }
1240  /* If an error occurred and force was set, return the error to the caller;
1241  * fall back to sendfile() when force was not set. */
1242  if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
1243  err = UV__ERR(errno);
1244  goto out;
1245  }
1246  }
1247 #else
1248  if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
1249  err = UV_ENOSYS;
1250  goto out;
1251  }
1252 #endif
1253 
1254  bytes_to_send = src_statsbuf.st_size;
1255  in_offset = 0;
1256  while (bytes_to_send != 0) {
1257  bytes_chunk = SSIZE_MAX;
1258  if (bytes_to_send < (off_t) bytes_chunk)
1259  bytes_chunk = bytes_to_send;
1260  uv_fs_sendfile(NULL, &fs_req, dstfd, srcfd, in_offset, bytes_chunk, NULL);
1261  bytes_written = fs_req.result;
1262  uv_fs_req_cleanup(&fs_req);
1263 
1264  if (bytes_written < 0) {
1265  err = bytes_written;
1266  break;
1267  }
1268 
1269  bytes_to_send -= bytes_written;
1270  in_offset += bytes_written;
1271  }
1272 
1273 out:
1274  if (err < 0)
1275  result = err;
1276  else
1277  result = 0;
1278 
1279  /* Close the source file. */
1280  err = uv__close_nocheckstdio(srcfd);
1281 
1282  /* Don't overwrite any existing errors. */
1283  if (err != 0 && result == 0)
1284  result = err;
1285 
1286  /* Close the destination file if it is open. */
1287  if (dstfd >= 0) {
1288  err = uv__close_nocheckstdio(dstfd);
1289 
1290  /* Don't overwrite any existing errors. */
1291  if (err != 0 && result == 0)
1292  result = err;
1293 
1294  /* Remove the destination file if something went wrong. */
1295  if (result != 0) {
1296  uv_fs_unlink(NULL, &fs_req, req->new_path, NULL);
1297  /* Ignore the unlink return value, as an error already happened. */
1298  uv_fs_req_cleanup(&fs_req);
1299  }
1300  }
1301 
1302  if (result == 0)
1303  return 0;
1304 
1305  errno = UV__ERR(result);
1306  return -1;
1307 }
static bool err
Definition: armass.c:435
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence ftruncate
Definition: sflib.h:113
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count fchmod
Definition: sflib.h:84
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void static flags fstatfs
Definition: sflib.h:137
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset fstat
Definition: sflib.h:107
static static sync static getppid static getegid const char static filename ioctl
Definition: sflib.h:62
#define UV__ERR(x)
Definition: errno.h:29
static RzSocket * s
Definition: rtr.c:28
#define O_WRONLY
Definition: sftypes.h:487
#define O_CREAT
Definition: sftypes.h:489
#define O_RDONLY
Definition: sftypes.h:486
#define O_EXCL
Definition: sftypes.h:490
int off_t
Definition: sftypes.h:41
Definition: sftypes.h:80
Definition: sftypes.h:74
Definition: uv.h:1306
ssize_t result
Definition: uv.h:1311
int uv__close_nocheckstdio(int fd)
Definition: core.c:550
int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb)
Definition: fs.c:1858
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)
Definition: fs.c:1984
int uv_fs_unlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
Definition: fs.c:2020
void uv_fs_req_cleanup(uv_fs_t *req)
Definition: fs.c:2070
int uv_file
Definition: unix.h:128
#define UV_FS_COPYFILE_FICLONE_FORCE
Definition: uv.h:1370
#define UV_FS_COPYFILE_EXCL
Definition: uv.h:1358
#define UV_FS_COPYFILE_FICLONE
Definition: uv.h:1364
#define SSIZE_MAX
Definition: win.h:28

References err, fchmod, fstat, fstatfs, ftruncate, ioctl, NULL, O_CREAT, O_EXCL, O_RDONLY, O_WRONLY, out, req, uv_fs_s::result, s, SSIZE_MAX, uv__close_nocheckstdio(), UV__ERR, UV_FS_COPYFILE_EXCL, UV_FS_COPYFILE_FICLONE, UV_FS_COPYFILE_FICLONE_FORCE, uv_fs_open(), uv_fs_req_cleanup(), uv_fs_sendfile(), and uv_fs_unlink().

Referenced by uv__fs_work().

◆ uv__fs_done()

static void uv__fs_done ( struct uv__work w,
int  status 
)
static

Definition at line 1644 of file fs.c.

1644  {
1645  uv_fs_t* req;
1646 
1647  req = container_of(w, uv_fs_t, work_req);
1648  uv__req_unregister(req->loop, req);
1649 
1650  if (status == UV_ECANCELED) {
1651  assert(req->result == 0);
1652  req->result = UV_ECANCELED;
1653  }
1654 
1655  req->cb(req);
1656 }
#define w
Definition: crypto_rc6.c:13
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
assert(limit<=UINT32_MAX/2)
#define container_of(ptr, type, member)
Definition: rz_types.h:650
#define uv__req_unregister(loop, req)
Definition: uv-common.h:230

References assert(), container_of, req, status, uv__req_unregister, and w.

◆ uv__fs_fdatasync()

static ssize_t uv__fs_fdatasync ( uv_fs_t req)
static

Definition at line 200 of file fs.c.

200  {
201 #if defined(__linux__) || defined(__sun) || defined(__NetBSD__)
202  return fdatasync(req->file);
203 #elif defined(__APPLE__)
204  /* See the comment in uv__fs_fsync. */
205  return uv__fs_fsync(req);
206 #else
207  return fsync(req->file);
208 #endif
209 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg fsync
Definition: sflib.h:79
static const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage struct sysinfo static info unsigned static __unused struct utsname static buf const char static size const char static name static pid unsigned static persona static fsgid const void static flags const struct iovec static count fdatasync
Definition: sflib.h:177
static ssize_t uv__fs_fsync(uv_fs_t *req)
Definition: fs.c:176

References fdatasync, fsync, req, and uv__fs_fsync().

Referenced by uv__fs_work().

◆ uv__fs_fstat()

static int uv__fs_fstat ( int  fd,
uv_stat_t buf 
)
static

Definition at line 1497 of file fs.c.

1497  {
1498  struct stat pbuf;
1499  int ret;
1500 
1501  ret = uv__fs_statx(fd, "", /* is_fstat */ 1, /* is_lstat */ 0, buf);
1502  if (ret != UV_ENOSYS)
1503  return ret;
1504 
1505  ret = fstat(fd, &pbuf);
1506  if (ret == 0)
1507  uv__to_stat(&pbuf, buf);
1508 
1509  return ret;
1510 }
voidpf void * buf
Definition: ioapi.h:138
static void uv__to_stat(struct stat *src, uv_stat_t *dst)
Definition: fs.c:1309
static int uv__fs_statx(int fd, const char *path, int is_fstat, int is_lstat, uv_stat_t *buf)
Definition: fs.c:1386

References fd, fstat, uv__fs_statx(), and uv__to_stat().

Referenced by uv__fs_work().

◆ uv__fs_fsync()

static ssize_t uv__fs_fsync ( uv_fs_t req)
static

Definition at line 176 of file fs.c.

176  {
177 #if defined(__APPLE__)
178  /* Apple's fdatasync and fsync explicitly do NOT flush the drive write cache
179  * to the drive platters. This is in contrast to Linux's fdatasync and fsync
180  * which do, according to recent man pages. F_FULLFSYNC is Apple's equivalent
181  * for flushing buffered data to permanent storage. If F_FULLFSYNC is not
182  * supported by the file system we fall back to F_BARRIERFSYNC or fsync().
183  * This is the same approach taken by sqlite, except sqlite does not issue
184  * an F_BARRIERFSYNC call.
185  */
186  int r;
187 
188  r = fcntl(req->file, F_FULLFSYNC);
189  if (r != 0)
190  r = fcntl(req->file, 85 /* F_BARRIERFSYNC */); /* fsync + barrier */
191  if (r != 0)
192  r = fsync(req->file);
193  return r;
194 #else
195  return fsync(req->file);
196 #endif
197 }
#define r
Definition: crypto_rc6.c:12
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags fcntl
Definition: sflib.h:79

References fcntl, fsync, r, and req.

Referenced by uv__fs_fdatasync(), and uv__fs_work().

◆ uv__fs_futime()

static ssize_t uv__fs_futime ( uv_fs_t req)
static

Definition at line 226 of file fs.c.

226  {
227 #if defined(__linux__) \
228  || defined(_AIX71) \
229  || defined(__HAIKU__)
230  /* utimesat() has nanosecond resolution but we stick to microseconds
231  * for the sake of consistency with other platforms.
232  */
233  struct timespec ts[2];
234  ts[0] = uv__fs_to_timespec(req->atime);
235  ts[1] = uv__fs_to_timespec(req->mtime);
236  return futimens(req->file, ts);
237 #elif defined(__APPLE__) \
238  || defined(__DragonFly__) \
239  || defined(__FreeBSD__) \
240  || defined(__FreeBSD_kernel__) \
241  || defined(__NetBSD__) \
242  || defined(__OpenBSD__) \
243  || defined(__sun)
244  struct timeval tv[2];
245  tv[0] = uv__fs_to_timeval(req->atime);
246  tv[1] = uv__fs_to_timeval(req->mtime);
247 # if defined(__sun)
248  return futimesat(req->file, NULL, tv);
249 # else
250  return futimes(req->file, tv);
251 # endif
252 #elif defined(__MVS__)
253  attrib_t atr;
254  memset(&atr, 0, sizeof(atr));
255  atr.att_mtimechg = 1;
256  atr.att_atimechg = 1;
257  atr.att_mtime = req->mtime;
258  atr.att_atime = req->atime;
259  return __fchattr(req->file, &atr, sizeof(atr));
260 #else
261  errno = ENOSYS;
262  return -1;
263 #endif
264 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval tv
Definition: sflib.h:79
return memset(p, 0, total)

References memset(), NULL, req, and tv.

Referenced by uv__fs_work().

◆ uv__fs_lstat()

static int uv__fs_lstat ( const char *  path,
uv_stat_t buf 
)
static

Definition at line 1481 of file fs.c.

1481  {
1482  struct stat pbuf;
1483  int ret;
1484 
1485  ret = uv__fs_statx(-1, path, /* is_fstat */ 0, /* is_lstat */ 1, buf);
1486  if (ret != UV_ENOSYS)
1487  return ret;
1488 
1489  ret = lstat(path, &pbuf);
1490  if (ret == 0)
1491  uv__to_stat(&pbuf, buf);
1492 
1493  return ret;
1494 }

References path, uv__fs_statx(), and uv__to_stat().

Referenced by uv__fs_work().

◆ uv__fs_lutime()

static ssize_t uv__fs_lutime ( uv_fs_t req)
static

Definition at line 1051 of file fs.c.

1051  {
1052 #if defined(__linux__) || \
1053  defined(_AIX71) || \
1054  defined(__sun) || \
1055  defined(__HAIKU__)
1056  struct timespec ts[2];
1057  ts[0] = uv__fs_to_timespec(req->atime);
1058  ts[1] = uv__fs_to_timespec(req->mtime);
1059  return utimensat(AT_FDCWD, req->path, ts, AT_SYMLINK_NOFOLLOW);
1060 #elif defined(__APPLE__) || \
1061  defined(__DragonFly__) || \
1062  defined(__FreeBSD__) || \
1063  defined(__FreeBSD_kernel__) || \
1064  defined(__NetBSD__)
1065  struct timeval tv[2];
1066  tv[0] = uv__fs_to_timeval(req->atime);
1067  tv[1] = uv__fs_to_timeval(req->mtime);
1068  return lutimes(req->path, tv);
1069 #else
1070  errno = ENOSYS;
1071  return -1;
1072 #endif
1073 }

References req, and tv.

Referenced by uv__fs_work().

◆ uv__fs_mkdtemp()

static ssize_t uv__fs_mkdtemp ( uv_fs_t req)
static

Definition at line 267 of file fs.c.

267  {
268  return mkdtemp((char*) req->path) ? 0 : -1;
269 }
char * mkdtemp(char *path)

References mkdtemp(), and req.

Referenced by uv__fs_work().

◆ uv__fs_mkstemp()

static int uv__fs_mkstemp ( uv_fs_t req)
static

Definition at line 291 of file fs.c.

291  {
292  static uv_once_t once = UV_ONCE_INIT;
293  int r;
294 #ifdef O_CLOEXEC
295  static int no_cloexec_support;
296 #endif
297  static const char pattern[] = "XXXXXX";
298  static const size_t pattern_size = sizeof(pattern) - 1;
299  char* path;
300  size_t path_length;
301 
302  path = (char*) req->path;
303  path_length = strlen(path);
304 
305  /* EINVAL can be returned for 2 reasons:
306  1. The template's last 6 characters were not XXXXXX
307  2. open() didn't support O_CLOEXEC
308  We want to avoid going to the fallback path in case
309  of 1, so it's manually checked before. */
310  if (path_length < pattern_size ||
311  strcmp(path + path_length - pattern_size, pattern)) {
312  errno = EINVAL;
313  r = -1;
314  goto clobber;
315  }
316 
318 
319 #ifdef O_CLOEXEC
320  if (uv__load_relaxed(&no_cloexec_support) == 0 && uv__mkostemp != NULL) {
322 
323  if (r >= 0)
324  return r;
325 
326  /* If mkostemp() returns EINVAL, it means the kernel doesn't
327  support O_CLOEXEC, so we just fallback to mkstemp() below. */
328  if (errno != EINVAL)
329  goto clobber;
330 
331  /* We set the static variable so that next calls don't even
332  try to use mkostemp. */
333  uv__store_relaxed(&no_cloexec_support, 1);
334  }
335 #endif /* O_CLOEXEC */
336 
337  if (req->cb != NULL)
338  uv_rwlock_rdlock(&req->loop->cloexec_lock);
339 
340  r = mkstemp(path);
341 
342  /* In case of failure `uv__cloexec` will leave error in `errno`,
343  * so it is enough to just set `r` to `-1`.
344  */
345  if (r >= 0 && uv__cloexec(r, 1) != 0) {
346  r = uv__close(r);
347  if (r != 0)
348  abort();
349  r = -1;
350  }
351 
352  if (req->cb != NULL)
353  uv_rwlock_rdunlock(&req->loop->cloexec_lock);
354 
355 clobber:
356  if (r < 0)
357  path[0] = '\0';
358  return r;
359 }
#define O_CLOEXEC
Definition: compat.h:80
#define EINVAL
Definition: sftypes.h:132
int uv__close(int fd)
Definition: core.c:569
#define uv__cloexec
Definition: internal.h:169
static uv_once_t once
Definition: threadpool.c:32
static int(* uv__mkostemp)(char *, int)
Definition: fs.c:272
static void uv__mkostemp_initonce(void)
Definition: fs.c:275
pthread_once_t uv_once_t
Definition: unix.h:135
#define UV_ONCE_INIT
Definition: unix.h:133
#define uv__load_relaxed(p)
Definition: uv-common.h:67
#define uv__store_relaxed(p, v)
Definition: uv-common.h:68
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419
UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t *rwlock)
Definition: thread.c:367
UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t *rwlock)
Definition: thread.c:387

References EINVAL, NULL, O_CLOEXEC, once, path, r, req, uv__cloexec, uv__close(), uv__load_relaxed, uv__mkostemp, uv__mkostemp_initonce(), uv__store_relaxed, uv_once(), UV_ONCE_INIT, uv_rwlock_rdlock(), and uv_rwlock_rdunlock().

Referenced by uv__fs_work().

◆ uv__fs_open()

static ssize_t uv__fs_open ( uv_fs_t req)
static

Definition at line 362 of file fs.c.

362  {
363 #ifdef O_CLOEXEC
364  return open(req->path, req->flags | O_CLOEXEC, req->mode);
365 #else /* O_CLOEXEC */
366  int r;
367 
368  if (req->cb != NULL)
369  uv_rwlock_rdlock(&req->loop->cloexec_lock);
370 
371  r = open(req->path, req->flags, req->mode);
372 
373  /* In case of failure `uv__cloexec` will leave error in `errno`,
374  * so it is enough to just set `r` to `-1`.
375  */
376  if (r >= 0 && uv__cloexec(r, 1) != 0) {
377  r = uv__close(r);
378  if (r != 0)
379  abort();
380  r = -1;
381  }
382 
383  if (req->cb != NULL)
384  uv_rwlock_rdunlock(&req->loop->cloexec_lock);
385 
386  return r;
387 #endif /* O_CLOEXEC */
388 }

References NULL, O_CLOEXEC, r, req, uv__cloexec, uv__close(), uv_rwlock_rdlock(), and uv_rwlock_rdunlock().

Referenced by uv__fs_work().

◆ uv__fs_opendir()

static int uv__fs_opendir ( uv_fs_t req)
static

Definition at line 553 of file fs.c.

553  {
554  uv_dir_t* dir;
555 
556  dir = uv__malloc(sizeof(*dir));
557  if (dir == NULL)
558  goto error;
559 
560  dir->dir = opendir(req->path);
561  if (dir->dir == NULL)
562  goto error;
563 
564  req->ptr = dir;
565  return 0;
566 
567 error:
568  uv__free(dir);
569  req->ptr = NULL;
570  return -1;
571 }
void error(const char *msg)
Definition: untgz.c:593

References error(), NULL, req, uv__free(), and uv__malloc().

Referenced by uv__fs_work().

◆ uv__fs_pathmax_size()

static ssize_t uv__fs_pathmax_size ( const char *  path)
static

Definition at line 677 of file fs.c.

677  {
678  ssize_t pathmax;
679 
680  pathmax = pathconf(path, _PC_PATH_MAX);
681 
682  if (pathmax == -1)
683  pathmax = UV__PATH_MAX;
684 
685  return pathmax;
686 }
int ssize_t
Definition: sftypes.h:39
#define UV__PATH_MAX
Definition: internal.h:68

References path, and UV__PATH_MAX.

Referenced by uv__fs_readlink(), and uv__fs_realpath().

◆ uv__fs_preadv()

static ssize_t uv__fs_preadv ( uv_file  fd,
uv_buf_t bufs,
unsigned int  nbufs,
off_t  off 
)
static

Definition at line 392 of file fs.c.

395  {
396  uv_buf_t* buf;
397  uv_buf_t* end;
398  ssize_t result;
399  ssize_t rc;
400  size_t pos;
401 
402  assert(nbufs > 0);
403 
404  result = 0;
405  pos = 0;
406  buf = bufs + 0;
407  end = bufs + nbufs;
408 
409  for (;;) {
410  do
411  rc = pread(fd, buf->base + pos, buf->len - pos, off + result);
412  while (rc == -1 && errno == EINTR);
413 
414  if (rc == 0)
415  break;
416 
417  if (rc == -1 && result == 0)
418  return UV__ERR(errno);
419 
420  if (rc == -1)
421  break; /* We read some data so return that, ignore the error. */
422 
423  pos += rc;
424  result += rc;
425 
426  if (pos < buf->len)
427  continue;
428 
429  pos = 0;
430  buf += 1;
431 
432  if (buf == end)
433  break;
434  }
435 
436  return result;
437 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname pread
Definition: sflib.h:98
int off
Definition: pal.c:13
Definition: unix.h:123
int pos
Definition: main.c:11

References assert(), bufs, EINTR, test_evm::end, fd, len, off, pos, pread, and UV__ERR.

Referenced by uv__fs_read().

◆ uv__fs_read()

static ssize_t uv__fs_read ( uv_fs_t req)
static

Definition at line 441 of file fs.c.

441  {
442 #if defined(__linux__)
443  static int no_preadv;
444 #endif
445  unsigned int iovmax;
446  ssize_t result;
447 
448  iovmax = uv__getiovmax();
449  if (req->nbufs > iovmax)
450  req->nbufs = iovmax;
451 
452  if (req->off < 0) {
453  if (req->nbufs == 1)
454  result = read(req->file, req->bufs[0].base, req->bufs[0].len);
455  else
456  result = readv(req->file, (struct iovec*) req->bufs, req->nbufs);
457  } else {
458  if (req->nbufs == 1) {
459  result = pread(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
460  goto done;
461  }
462 
463 #if HAVE_PREADV
464  result = preadv(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
465 #else
466 # if defined(__linux__)
467  if (uv__load_relaxed(&no_preadv)) retry:
468 # endif
469  {
470  result = uv__fs_preadv(req->file, req->bufs, req->nbufs, req->off);
471  }
472 # if defined(__linux__)
473  else {
474  result = uv__preadv(req->file,
475  (struct iovec*)req->bufs,
476  req->nbufs,
477  req->off);
478  if (result == -1 && errno == ENOSYS) {
479  uv__store_relaxed(&no_preadv, 1);
480  goto retry;
481  }
482  }
483 # endif
484 #endif
485  }
486 
487 done:
488  /* Early cleanup of bufs allocation, since we're done with it. */
489  if (req->bufs != req->bufsml)
490  uv__free(req->bufs);
491 
492  req->bufs = NULL;
493  req->nbufs = 0;
494 
495 #ifdef __PASE__
496  /* PASE returns EOPNOTSUPP when reading a directory, convert to EISDIR */
497  if (result == -1 && errno == EOPNOTSUPP) {
498  struct stat buf;
499  ssize_t rc;
500  rc = fstat(req->file, &buf);
501  if (rc == 0 && S_ISDIR(buf.st_mode)) {
502  errno = EISDIR;
503  }
504  }
505 #endif
506 
507  return result;
508 }
#define S_ISDIR(mode)
Definition: compat.h:187
struct tab * done
Definition: enough.c:233
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count readv
Definition: sflib.h:166
ssize_t uv__preadv(int fd, const struct iovec *iov, int iovcnt, int64_t offset)
#define EOPNOTSUPP
Definition: sftypes.h:155
#define EISDIR
Definition: sftypes.h:131
Definition: sftypes.h:73
int uv__getiovmax(void)
Definition: core.c:215
static ssize_t uv__fs_preadv(uv_file fd, uv_buf_t *bufs, unsigned int nbufs, off_t off)
Definition: fs.c:392
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References done, EISDIR, EOPNOTSUPP, fstat, NULL, pread, read(), readv, req, S_ISDIR, uv__free(), uv__fs_preadv(), uv__getiovmax(), uv__load_relaxed, uv__preadv(), and uv__store_relaxed.

Referenced by uv__fs_work().

◆ uv__fs_readdir()

static int uv__fs_readdir ( uv_fs_t req)
static

Definition at line 573 of file fs.c.

573  {
574  uv_dir_t* dir;
576  struct dirent* res;
577  unsigned int dirent_idx;
578  unsigned int i;
579 
580  dir = req->ptr;
581  dirent_idx = 0;
582 
583  while (dirent_idx < dir->nentries) {
584  /* readdir() returns NULL on end of directory, as well as on error. errno
585  is used to differentiate between the two conditions. */
586  errno = 0;
587  res = readdir(dir->dir);
588 
589  if (res == NULL) {
590  if (errno != 0)
591  goto error;
592  break;
593  }
594 
595  if (strcmp(res->d_name, ".") == 0 || strcmp(res->d_name, "..") == 0)
596  continue;
597 
598  dirent = &dir->dirents[dirent_idx];
599  dirent->name = uv__strdup(res->d_name);
600 
601  if (dirent->name == NULL)
602  goto error;
603 
604  dirent->type = uv__fs_get_dirent_type(res);
605  ++dirent_idx;
606  }
607 
608  return dirent_idx;
609 
610 error:
611  for (i = 0; i < dirent_idx; ++i) {
612  uv__free((char*) dir->dirents[i].name);
613  dir->dirents[i].name = NULL;
614  }
615 
616  return -1;
617 }
lzma_index ** i
Definition: index.h:629
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path static newfd static getpgrp static euid const sigset_t static mask const char static len const gid_t static list const char const char static newpath const char static library readdir
Definition: sflib.h:120
Definition: sftypes.h:48
char d_name[256]
Definition: sftypes.h:52
uv_dirent_t * dirents
Definition: uv.h:1299
const char * name
Definition: uv.h:1151
uv_dirent_type_t uv__fs_get_dirent_type(uv__dirent_t *dent)
Definition: uv-common.c:688

References dirent::d_name, uv_dir_s::dirents, error(), i, uv_dirent_s::name, NULL, readdir, req, uv__free(), uv__fs_get_dirent_type(), and uv__strdup().

Referenced by uv__fs_work().

◆ uv__fs_readlink()

static ssize_t uv__fs_readlink ( uv_fs_t req)
static

Definition at line 688 of file fs.c.

688  {
689  ssize_t maxlen;
690  ssize_t len;
691  char* buf;
692 
693 #if defined(_POSIX_PATH_MAX) || defined(PATH_MAX)
694  maxlen = uv__fs_pathmax_size(req->path);
695 #else
696  /* We may not have a real PATH_MAX. Read size of link. */
697  struct stat st;
698  int ret;
699  ret = lstat(req->path, &st);
700  if (ret != 0)
701  return -1;
702  if (!S_ISLNK(st.st_mode)) {
703  errno = EINVAL;
704  return -1;
705  }
706 
707  maxlen = st.st_size;
708 
709  /* According to readlink(2) lstat can report st_size == 0
710  for some symlinks, such as those in /proc or /sys. */
711  if (maxlen == 0)
712  maxlen = uv__fs_pathmax_size(req->path);
713 #endif
714 
715  buf = uv__malloc(maxlen);
716 
717  if (buf == NULL) {
718  errno = ENOMEM;
719  return -1;
720  }
721 
722 #if defined(__MVS__)
723  len = os390_readlink(req->path, buf, maxlen);
724 #else
725  len = readlink(req->path, buf, maxlen);
726 #endif
727 
728  if (len == -1) {
729  uv__free(buf);
730  return -1;
731  }
732 
733  /* Uncommon case: resize to make room for the trailing nul byte. */
734  if (len == maxlen) {
735  buf = uv__reallocf(buf, len + 1);
736 
737  if (buf == NULL)
738  return -1;
739  }
740 
741  buf[len] = '\0';
742  req->ptr = buf;
743 
744  return 0;
745 }
static static sync static getppid static getegid const char static filename char static len readlink
Definition: sflib.h:65
ssize_t os390_readlink(const char *path, char *buf, size_t len)
#define ENOMEM
Definition: sftypes.h:122
ut64 maxlen
Definition: core.c:76
static ssize_t uv__fs_pathmax_size(const char *path)
Definition: fs.c:677
void * uv__reallocf(void *ptr, size_t size)
Definition: uv-common.c:103

References EINVAL, ENOMEM, len, maxlen, NULL, os390_readlink(), readlink, req, uv__free(), uv__fs_pathmax_size(), uv__malloc(), and uv__reallocf().

Referenced by uv__fs_work().

◆ uv__fs_realpath()

static ssize_t uv__fs_realpath ( uv_fs_t req)
static

Definition at line 747 of file fs.c.

747  {
748  char* buf;
749 
750 #if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L
751  buf = realpath(req->path, NULL);
752  if (buf == NULL)
753  return -1;
754 #else
755  ssize_t len;
756 
757  len = uv__fs_pathmax_size(req->path);
758  buf = uv__malloc(len + 1);
759 
760  if (buf == NULL) {
761  errno = ENOMEM;
762  return -1;
763  }
764 
765  if (realpath(req->path, buf) == NULL) {
766  uv__free(buf);
767  return -1;
768  }
769 #endif
770 
771  req->ptr = buf;
772 
773  return 0;
774 }

References ENOMEM, len, NULL, req, uv__free(), uv__fs_pathmax_size(), and uv__malloc().

Referenced by uv__fs_work().

◆ uv__fs_scandir()

static ssize_t uv__fs_scandir ( uv_fs_t req)
static

Definition at line 528 of file fs.c.

528  {
529  uv__dirent_t** dents;
530  int n;
531 
532  dents = NULL;
534 
535  /* NOTE: We will use nbufs as an index field */
536  req->nbufs = 0;
537 
538  if (n == 0) {
539  /* OS X still needs to deallocate some memory.
540  * Memory was allocated using the system allocator, so use free() here.
541  */
542  free(dents);
543  dents = NULL;
544  } else if (n == -1) {
545  return n;
546  }
547 
548  req->ptr = dents;
549 
550  return n;
551 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
int n
Definition: mipsasm.c:19
int scandir(const char *maindir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const struct dirent **, const struct dirent **))
static int uv__fs_scandir_sort(UV_CONST_DIRENT **a, UV_CONST_DIRENT **b)
Definition: fs.c:523
static int uv__fs_scandir_filter(UV_CONST_DIRENT *dent)
Definition: fs.c:518

References free(), n, NULL, req, scandir(), uv__fs_scandir_filter(), and uv__fs_scandir_sort().

Referenced by uv__fs_work().

◆ uv__fs_scandir_filter()

static int uv__fs_scandir_filter ( UV_CONST_DIRENT dent)
static

Definition at line 518 of file fs.c.

518  {
519  return strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0;
520 }

Referenced by uv__fs_scandir().

◆ uv__fs_scandir_sort()

static int uv__fs_scandir_sort ( UV_CONST_DIRENT **  a,
UV_CONST_DIRENT **  b 
)
static

Definition at line 523 of file fs.c.

523  {
524  return strcmp((*a)->d_name, (*b)->d_name);
525 }

Referenced by uv__fs_scandir().

◆ uv__fs_sendfile()

static ssize_t uv__fs_sendfile ( uv_fs_t req)
static

Definition at line 890 of file fs.c.

890  {
891  int in_fd;
892  int out_fd;
893 
894  in_fd = req->flags;
895  out_fd = req->file;
896 
897 #if defined(__linux__) || defined(__sun)
898  {
899  off_t off;
900  ssize_t r;
901 
902  off = req->off;
903 
904 #ifdef __linux__
905  {
906  static int copy_file_range_support = 1;
907 
908  if (copy_file_range_support) {
909  r = uv__fs_copy_file_range(in_fd, NULL, out_fd, &off, req->bufsml[0].len, 0);
910 
911  if (r == -1 && errno == ENOSYS) {
912  errno = 0;
913  copy_file_range_support = 0;
914  } else {
915  goto ok;
916  }
917  }
918  }
919 #endif
920 
921  r = sendfile(out_fd, in_fd, &off, req->bufsml[0].len);
922 
923 ok:
924  /* sendfile() on SunOS returns EINVAL if the target fd is not a socket but
925  * it still writes out data. Fortunately, we can detect it by checking if
926  * the offset has been updated.
927  */
928  if (r != -1 || off > req->off) {
929  r = off - req->off;
930  req->off = off;
931  return r;
932  }
933 
934  if (errno == EINVAL ||
935  errno == EIO ||
936  errno == ENOTSOCK ||
937  errno == EXDEV) {
938  errno = 0;
939  return uv__fs_sendfile_emul(req);
940  }
941 
942  return -1;
943  }
944 #elif defined(__APPLE__) || \
945  defined(__DragonFly__) || \
946  defined(__FreeBSD__) || \
947  defined(__FreeBSD_kernel__)
948  {
949  off_t len;
950  ssize_t r;
951 
952  /* sendfile() on FreeBSD and Darwin returns EAGAIN if the target fd is in
953  * non-blocking mode and not all data could be written. If a non-zero
954  * number of bytes have been sent, we don't consider it an error.
955  */
956 
957 #if defined(__FreeBSD__) || defined(__DragonFly__)
958  len = 0;
959  r = sendfile(in_fd, out_fd, req->off, req->bufsml[0].len, NULL, &len, 0);
960 #elif defined(__FreeBSD_kernel__)
961  len = 0;
962  r = bsd_sendfile(in_fd,
963  out_fd,
964  req->off,
965  req->bufsml[0].len,
966  NULL,
967  &len,
968  0);
969 #else
970  /* The darwin sendfile takes len as an input for the length to send,
971  * so make sure to initialize it with the caller's value. */
972  len = req->bufsml[0].len;
973  r = sendfile(in_fd, out_fd, req->off, &len, NULL, 0);
974 #endif
975 
976  /*
977  * The man page for sendfile(2) on DragonFly states that `len` contains
978  * a meaningful value ONLY in case of EAGAIN and EINTR.
979  * Nothing is said about it's value in case of other errors, so better
980  * not depend on the potential wrong assumption that is was not modified
981  * by the syscall.
982  */
983  if (r == 0 || ((errno == EAGAIN || errno == EINTR) && len != 0)) {
984  req->off += len;
985  return (ssize_t) len;
986  }
987 
988  if (errno == EINVAL ||
989  errno == EIO ||
990  errno == ENOTSOCK ||
991  errno == EXDEV) {
992  errno = 0;
993  return uv__fs_sendfile_emul(req);
994  }
995 
996  return -1;
997  }
998 #else
999  /* Squelch compiler warnings. */
1000  (void) &in_fd;
1001  (void) &out_fd;
1002 
1003  return uv__fs_sendfile_emul(req);
1004 #endif
1005 }
ssize_t uv__fs_copy_file_range(int fd_in, ssize_t *off_in, int fd_out, ssize_t *off_out, size_t len, unsigned int flags)
@ ok
Definition: lz4.c:1706
#define EXDEV
Definition: sftypes.h:128
#define EIO
Definition: sftypes.h:115
#define ENOTSOCK
Definition: sftypes.h:148
#define EAGAIN
Definition: sftypes.h:121
static ssize_t uv__fs_sendfile_emul(uv_fs_t *req)
Definition: fs.c:776

References EAGAIN, EINTR, EINVAL, EIO, ENOTSOCK, EXDEV, len, NULL, off, ok, r, req, uv__fs_copy_file_range(), and uv__fs_sendfile_emul().

Referenced by uv__fs_work().

◆ uv__fs_sendfile_emul()

static ssize_t uv__fs_sendfile_emul ( uv_fs_t req)
static

Definition at line 776 of file fs.c.

776  {
777  struct pollfd pfd;
778  int use_pread;
779  off_t offset;
780  ssize_t nsent;
781  ssize_t nread;
782  ssize_t nwritten;
783  size_t buflen;
784  size_t len;
785  ssize_t n;
786  int in_fd;
787  int out_fd;
788  char buf[8192];
789 
790  len = req->bufsml[0].len;
791  in_fd = req->flags;
792  out_fd = req->file;
793  offset = req->off;
794  use_pread = 1;
795 
796  /* Here are the rules regarding errors:
797  *
798  * 1. Read errors are reported only if nsent==0, otherwise we return nsent.
799  * The user needs to know that some data has already been sent, to stop
800  * them from sending it twice.
801  *
802  * 2. Write errors are always reported. Write errors are bad because they
803  * mean data loss: we've read data but now we can't write it out.
804  *
805  * We try to use pread() and fall back to regular read() if the source fd
806  * doesn't support positional reads, for example when it's a pipe fd.
807  *
808  * If we get EAGAIN when writing to the target fd, we poll() on it until
809  * it becomes writable again.
810  *
811  * FIXME: If we get a write error when use_pread==1, it should be safe to
812  * return the number of sent bytes instead of an error because pread()
813  * is, in theory, idempotent. However, special files in /dev or /proc
814  * may support pread() but not necessarily return the same data on
815  * successive reads.
816  *
817  * FIXME: There is no way now to signal that we managed to send *some* data
818  * before a write error.
819  */
820  for (nsent = 0; (size_t) nsent < len; ) {
821  buflen = len - nsent;
822 
823  if (buflen > sizeof(buf))
824  buflen = sizeof(buf);
825 
826  do
827  if (use_pread)
828  nread = pread(in_fd, buf, buflen, offset);
829  else
830  nread = read(in_fd, buf, buflen);
831  while (nread == -1 && errno == EINTR);
832 
833  if (nread == 0)
834  goto out;
835 
836  if (nread == -1) {
837  if (use_pread && nsent == 0 && (errno == EIO || errno == ESPIPE)) {
838  use_pread = 0;
839  continue;
840  }
841 
842  if (nsent == 0)
843  nsent = -1;
844 
845  goto out;
846  }
847 
848  for (nwritten = 0; nwritten < nread; ) {
849  do
850  n = write(out_fd, buf + nwritten, nread - nwritten);
851  while (n == -1 && errno == EINTR);
852 
853  if (n != -1) {
854  nwritten += n;
855  continue;
856  }
857 
858  if (errno != EAGAIN && errno != EWOULDBLOCK) {
859  nsent = -1;
860  goto out;
861  }
862 
863  pfd.fd = out_fd;
864  pfd.events = POLLOUT;
865  pfd.revents = 0;
866 
867  do
868  n = poll(&pfd, 1, -1);
869  while (n == -1 && errno == EINTR);
870 
871  if (n == -1 || (pfd.revents & ~POLLOUT) != 0) {
872  errno = EIO;
873  nsent = -1;
874  goto out;
875  }
876  }
877 
878  offset += nread;
879  nsent += nread;
880  }
881 
882 out:
883  if (nsent != -1)
884  req->off = offset;
885 
886  return nsent;
887 }
static static fork write
Definition: sflib.h:33
static const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage struct sysinfo static info unsigned static __unused struct utsname static buf const char static size const char static name static pid unsigned static persona static fsgid const void static flags const struct iovec static count static fd const void static len static munlockall struct sched_param static p static sched_yield static policy const struct timespec struct timespec static rem uid_t uid_t uid_t static suid poll
Definition: sflib.h:196
#define ESPIPE
Definition: sftypes.h:139
int size_t
Definition: sftypes.h:40
Definition: sftypes.h:75
ut64 buflen
Definition: core.c:76

References buflen, EAGAIN, EINTR, EIO, ESPIPE, len, n, out, poll, pread, read(), req, and write.

Referenced by uv__fs_sendfile().

◆ uv__fs_stat()

static int uv__fs_stat ( const char *  path,
uv_stat_t buf 
)
static

Definition at line 1465 of file fs.c.

1465  {
1466  struct stat pbuf;
1467  int ret;
1468 
1469  ret = uv__fs_statx(-1, path, /* is_fstat */ 0, /* is_lstat */ 0, buf);
1470  if (ret != UV_ENOSYS)
1471  return ret;
1472 
1473  ret = stat(path, &pbuf);
1474  if (ret == 0)
1475  uv__to_stat(&pbuf, buf);
1476 
1477  return ret;
1478 }
static stat
Definition: sflib.h:131

References path, stat, uv__fs_statx(), and uv__to_stat().

Referenced by uv__fs_work().

◆ uv__fs_statfs()

static int uv__fs_statfs ( uv_fs_t req)
static

Definition at line 634 of file fs.c.

634  {
635  uv_statfs_t* stat_fs;
636 #if defined(__sun) || \
637  defined(__MVS__) || \
638  defined(__NetBSD__) || \
639  defined(__HAIKU__) || \
640  defined(__QNX__)
641  struct statvfs buf;
642 
643  if (0 != statvfs(req->path, &buf))
644 #else
645  struct statfs buf;
646 
647  if (0 != statfs(req->path, &buf))
648 #endif /* defined(__sun) */
649  return -1;
650 
651  stat_fs = uv__malloc(sizeof(*stat_fs));
652  if (stat_fs == NULL) {
653  errno = ENOMEM;
654  return -1;
655  }
656 
657 #if defined(__sun) || \
658  defined(__MVS__) || \
659  defined(__OpenBSD__) || \
660  defined(__NetBSD__) || \
661  defined(__HAIKU__) || \
662  defined(__QNX__)
663  stat_fs->f_type = 0; /* f_type is not supported. */
664 #else
665  stat_fs->f_type = buf.f_type;
666 #endif
667  stat_fs->f_bsize = buf.f_bsize;
668  stat_fs->f_blocks = buf.f_blocks;
669  stat_fs->f_bfree = buf.f_bfree;
670  stat_fs->f_bavail = buf.f_bavail;
671  stat_fs->f_files = buf.f_files;
672  stat_fs->f_ffree = buf.f_ffree;
673  req->ptr = stat_fs;
674  return 0;
675 }
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who statfs
Definition: sflib.h:124
uint64_t f_files
Definition: uv.h:1134
uint64_t f_type
Definition: uv.h:1129
uint64_t f_bsize
Definition: uv.h:1130
uint64_t f_bfree
Definition: uv.h:1132
uint64_t f_ffree
Definition: uv.h:1135
uint64_t f_bavail
Definition: uv.h:1133
uint64_t f_blocks
Definition: uv.h:1131

References ENOMEM, uv_statfs_s::f_bavail, uv_statfs_s::f_bfree, uv_statfs_s::f_blocks, uv_statfs_s::f_bsize, uv_statfs_s::f_ffree, uv_statfs_s::f_files, uv_statfs_s::f_type, NULL, req, statfs, and uv__malloc().

Referenced by uv__fs_work().

◆ uv__fs_statx()

static int uv__fs_statx ( int  fd,
const char *  path,
int  is_fstat,
int  is_lstat,
uv_stat_t buf 
)
static

Definition at line 1386 of file fs.c.

1390  {
1391  STATIC_ASSERT(UV_ENOSYS != -1);
1392 #ifdef __linux__
1393  static int no_statx;
1394  struct uv__statx statxbuf;
1395  int dirfd;
1396  int flags;
1397  int mode;
1398  int rc;
1399 
1400  if (uv__load_relaxed(&no_statx))
1401  return UV_ENOSYS;
1402 
1403  dirfd = AT_FDCWD;
1404  flags = 0; /* AT_STATX_SYNC_AS_STAT */
1405  mode = 0xFFF; /* STATX_BASIC_STATS + STATX_BTIME */
1406 
1407  if (is_fstat) {
1408  dirfd = fd;
1409  flags |= 0x1000; /* AT_EMPTY_PATH */
1410  }
1411 
1412  if (is_lstat)
1413  flags |= AT_SYMLINK_NOFOLLOW;
1414 
1415  rc = uv__statx(dirfd, path, flags, mode, &statxbuf);
1416 
1417  switch (rc) {
1418  case 0:
1419  break;
1420  case -1:
1421  /* EPERM happens when a seccomp filter rejects the system call.
1422  * Has been observed with libseccomp < 2.3.3 and docker < 18.04.
1423  */
1424  if (errno != EINVAL && errno != EPERM && errno != ENOSYS)
1425  return -1;
1426  /* Fall through. */
1427  default:
1428  /* Normally on success, zero is returned and On error, -1 is returned.
1429  * Observed on S390 RHEL running in a docker container with statx not
1430  * implemented, rc might return 1 with 0 set as the error code in which
1431  * case we return ENOSYS.
1432  */
1433  uv__store_relaxed(&no_statx, 1);
1434  return UV_ENOSYS;
1435  }
1436 
1437  buf->st_dev = 256 * statxbuf.stx_dev_major + statxbuf.stx_dev_minor;
1438  buf->st_mode = statxbuf.stx_mode;
1439  buf->st_nlink = statxbuf.stx_nlink;
1440  buf->st_uid = statxbuf.stx_uid;
1441  buf->st_gid = statxbuf.stx_gid;
1442  buf->st_rdev = statxbuf.stx_rdev_major;
1443  buf->st_ino = statxbuf.stx_ino;
1444  buf->st_size = statxbuf.stx_size;
1445  buf->st_blksize = statxbuf.stx_blksize;
1446  buf->st_blocks = statxbuf.stx_blocks;
1447  buf->st_atim.tv_sec = statxbuf.stx_atime.tv_sec;
1448  buf->st_atim.tv_nsec = statxbuf.stx_atime.tv_nsec;
1449  buf->st_mtim.tv_sec = statxbuf.stx_mtime.tv_sec;
1450  buf->st_mtim.tv_nsec = statxbuf.stx_mtime.tv_nsec;
1451  buf->st_ctim.tv_sec = statxbuf.stx_ctime.tv_sec;
1452  buf->st_ctim.tv_nsec = statxbuf.stx_ctime.tv_nsec;
1453  buf->st_birthtim.tv_sec = statxbuf.stx_btime.tv_sec;
1454  buf->st_birthtim.tv_nsec = statxbuf.stx_btime.tv_nsec;
1455  buf->st_flags = 0;
1456  buf->st_gen = 0;
1457 
1458  return 0;
1459 #else
1460  return UV_ENOSYS;
1461 #endif /* __linux__ */
1462 }
const char int mode
Definition: ioapi.h:137
int uv__statx(int dirfd, const char *path, int flags, unsigned int mask, struct uv__statx *statxbuf)
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
#define EPERM
Definition: sftypes.h:111
#define STATIC_ASSERT(expr)
Definition: uv-common.h:60

References EINVAL, EPERM, fd, flags, path, STATIC_ASSERT, uv__statx::stx_atime, uv__statx::stx_blksize, uv__statx::stx_blocks, uv__statx::stx_btime, uv__statx::stx_ctime, uv__statx::stx_dev_major, uv__statx::stx_dev_minor, uv__statx::stx_gid, uv__statx::stx_ino, uv__statx::stx_mode, uv__statx::stx_mtime, uv__statx::stx_nlink, uv__statx::stx_rdev_major, uv__statx::stx_size, uv__statx::stx_uid, uv__statx_timestamp::tv_nsec, uv__statx_timestamp::tv_sec, uv__load_relaxed, uv__statx(), and uv__store_relaxed.

Referenced by uv__fs_fstat(), uv__fs_lstat(), and uv__fs_stat().

◆ uv__fs_utime()

static ssize_t uv__fs_utime ( uv_fs_t req)
static

Definition at line 1008 of file fs.c.

1008  {
1009 #if defined(__linux__) \
1010  || defined(_AIX71) \
1011  || defined(__sun) \
1012  || defined(__HAIKU__)
1013  /* utimesat() has nanosecond resolution but we stick to microseconds
1014  * for the sake of consistency with other platforms.
1015  */
1016  struct timespec ts[2];
1017  ts[0] = uv__fs_to_timespec(req->atime);
1018  ts[1] = uv__fs_to_timespec(req->mtime);
1019  return utimensat(AT_FDCWD, req->path, ts, 0);
1020 #elif defined(__APPLE__) \
1021  || defined(__DragonFly__) \
1022  || defined(__FreeBSD__) \
1023  || defined(__FreeBSD_kernel__) \
1024  || defined(__NetBSD__) \
1025  || defined(__OpenBSD__)
1026  struct timeval tv[2];
1027  tv[0] = uv__fs_to_timeval(req->atime);
1028  tv[1] = uv__fs_to_timeval(req->mtime);
1029  return utimes(req->path, tv);
1030 #elif defined(_AIX) \
1031  && !defined(_AIX71)
1032  struct utimbuf buf;
1033  buf.actime = req->atime;
1034  buf.modtime = req->mtime;
1035  return utime(req->path, &buf);
1036 #elif defined(__MVS__)
1037  attrib_t atr;
1038  memset(&atr, 0, sizeof(atr));
1039  atr.att_mtimechg = 1;
1040  atr.att_atimechg = 1;
1041  atr.att_mtime = req->mtime;
1042  atr.att_atime = req->atime;
1043  return __lchattr((char*) req->path, &atr, sizeof(atr));
1044 #else
1045  errno = ENOSYS;
1046  return -1;
1047 #endif
1048 }
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds utime
Definition: sflib.h:57

References memset(), req, tv, and utime.

Referenced by uv__fs_work().

◆ uv__fs_work()

static void uv__fs_work ( struct uv__work w)
static

Definition at line 1572 of file fs.c.

1572  {
1573  int retry_on_eintr;
1574  uv_fs_t* req;
1575  ssize_t r;
1576 
1577  req = container_of(w, uv_fs_t, work_req);
1578  retry_on_eintr = !(req->fs_type == UV_FS_CLOSE ||
1579  req->fs_type == UV_FS_READ);
1580 
1581  do {
1582  errno = 0;
1583 
1584 #define X(type, action) \
1585  case UV_FS_ ## type: \
1586  r = action; \
1587  break;
1588 
1589  switch (req->fs_type) {
1590  X(ACCESS, access(req->path, req->flags));
1591  X(CHMOD, chmod(req->path, req->mode));
1592  X(CHOWN, chown(req->path, req->uid, req->gid));
1593  X(CLOSE, uv__fs_close(req->file));
1594  X(COPYFILE, uv__fs_copyfile(req));
1595  X(FCHMOD, fchmod(req->file, req->mode));
1596  X(FCHOWN, fchown(req->file, req->uid, req->gid));
1597  X(LCHOWN, lchown(req->path, req->uid, req->gid));
1598  X(FDATASYNC, uv__fs_fdatasync(req));
1599  X(FSTAT, uv__fs_fstat(req->file, &req->statbuf));
1600  X(FSYNC, uv__fs_fsync(req));
1601  X(FTRUNCATE, ftruncate(req->file, req->off));
1602  X(FUTIME, uv__fs_futime(req));
1603  X(LUTIME, uv__fs_lutime(req));
1604  X(LSTAT, uv__fs_lstat(req->path, &req->statbuf));
1605  X(LINK, link(req->path, req->new_path));
1606  X(MKDIR, mkdir(req->path, req->mode));
1607  X(MKDTEMP, uv__fs_mkdtemp(req));
1608  X(MKSTEMP, uv__fs_mkstemp(req));
1609  X(OPEN, uv__fs_open(req));
1610  X(READ, uv__fs_read(req));
1611  X(SCANDIR, uv__fs_scandir(req));
1612  X(OPENDIR, uv__fs_opendir(req));
1613  X(READDIR, uv__fs_readdir(req));
1614  X(CLOSEDIR, uv__fs_closedir(req));
1615  X(READLINK, uv__fs_readlink(req));
1616  X(REALPATH, uv__fs_realpath(req));
1617  X(RENAME, rename(req->path, req->new_path));
1618  X(RMDIR, rmdir(req->path));
1619  X(SENDFILE, uv__fs_sendfile(req));
1620  X(STAT, uv__fs_stat(req->path, &req->statbuf));
1621  X(STATFS, uv__fs_statfs(req));
1622  X(SYMLINK, symlink(req->path, req->new_path));
1623  X(UNLINK, unlink(req->path));
1624  X(UTIME, uv__fs_utime(req));
1625  X(WRITE, uv__fs_write_all(req));
1626  default: abort();
1627  }
1628 #undef X
1629  } while (r == -1 && errno == EINTR && retry_on_eintr);
1630 
1631  if (r == -1)
1632  req->result = UV__ERR(errno);
1633  else
1634  req->result = r;
1635 
1636  if (r == 0 && (req->fs_type == UV_FS_STAT ||
1637  req->fs_type == UV_FS_FSTAT ||
1638  req->fs_type == UV_FS_LSTAT)) {
1639  req->ptr = &req->statbuf;
1640  }
1641 }
#define READ(x, i)
Definition: bflt.c:22
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen rmdir
Definition: sflib.h:90
static static fork const void static count static fd const char const char static newpath const char static path chmod
Definition: sflib.h:35
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem lchown
Definition: sflib.h:133
static static fork const void static count static fd link
Definition: sflib.h:33
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig mkdir
Definition: sflib.h:66
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause access
Definition: sflib.h:64
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path static newfd static getpgrp static euid const sigset_t static mask const char static len const gid_t static list symlink
Definition: sflib.h:114
static static fork const void static count static fd const char static mode unlink
Definition: sflib.h:41
static const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage struct sysinfo static info unsigned static __unused struct utsname static buf const char static size const char static name static pid unsigned static persona static fsgid const void static flags const struct iovec static count static fd const void static len static munlockall struct sched_param static p static sched_yield static policy const struct timespec struct timespec static rem uid_t uid_t uid_t static suid struct pollfd unsigned static timeout chown
Definition: sflib.h:210
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync rename
Definition: sflib.h:69
#define X(type, action)
static int uv__fs_statfs(uv_fs_t *req)
Definition: fs.c:634
static ssize_t uv__fs_utime(uv_fs_t *req)
Definition: fs.c:1008
static ssize_t uv__fs_futime(uv_fs_t *req)
Definition: fs.c:226
static int uv__fs_close(int fd)
Definition: fs.c:164
static int uv__fs_readdir(uv_fs_t *req)
Definition: fs.c:573
static ssize_t uv__fs_mkdtemp(uv_fs_t *req)
Definition: fs.c:267
static ssize_t uv__fs_open(uv_fs_t *req)
Definition: fs.c:362
static ssize_t uv__fs_readlink(uv_fs_t *req)
Definition: fs.c:688
static ssize_t uv__fs_fdatasync(uv_fs_t *req)
Definition: fs.c:200
static ssize_t uv__fs_realpath(uv_fs_t *req)
Definition: fs.c:747
static ssize_t uv__fs_scandir(uv_fs_t *req)
Definition: fs.c:528
static int uv__fs_opendir(uv_fs_t *req)
Definition: fs.c:553
static int uv__fs_mkstemp(uv_fs_t *req)
Definition: fs.c:291
static int uv__fs_closedir(uv_fs_t *req)
Definition: fs.c:619
static int uv__fs_fstat(int fd, uv_stat_t *buf)
Definition: fs.c:1497
static ssize_t uv__fs_read(uv_fs_t *req)
Definition: fs.c:441
static ssize_t uv__fs_sendfile(uv_fs_t *req)
Definition: fs.c:890
static int uv__fs_lstat(const char *path, uv_stat_t *buf)
Definition: fs.c:1481
static ssize_t uv__fs_write_all(uv_fs_t *req)
Definition: fs.c:1526
static ssize_t uv__fs_lutime(uv_fs_t *req)
Definition: fs.c:1051
static ssize_t uv__fs_copyfile(uv_fs_t *req)
Definition: fs.c:1136
static int uv__fs_stat(const char *path, uv_stat_t *buf)
Definition: fs.c:1465
@ UV_FS_STAT
Definition: uv.h:1265
@ UV_FS_CLOSE
Definition: uv.h:1261
@ UV_FS_READ
Definition: uv.h:1262
@ UV_FS_FSTAT
Definition: uv.h:1267
@ UV_FS_LSTAT
Definition: uv.h:1266

References access, chmod, chown, container_of, EINTR, fchmod, ftruncate, lchown, link, mkdir, r, READ, rename, req, rmdir, symlink, unlink, UV__ERR, uv__fs_close(), uv__fs_closedir(), uv__fs_copyfile(), uv__fs_fdatasync(), uv__fs_fstat(), uv__fs_fsync(), uv__fs_futime(), uv__fs_lstat(), uv__fs_lutime(), uv__fs_mkdtemp(), uv__fs_mkstemp(), uv__fs_open(), uv__fs_opendir(), uv__fs_read(), uv__fs_readdir(), uv__fs_readlink(), uv__fs_realpath(), uv__fs_scandir(), uv__fs_sendfile(), uv__fs_stat(), uv__fs_statfs(), uv__fs_utime(), uv__fs_write_all(), UV_FS_CLOSE, UV_FS_FSTAT, UV_FS_LSTAT, UV_FS_READ, UV_FS_STAT, w, and X.

◆ uv__fs_write()

static ssize_t uv__fs_write ( uv_fs_t req)
static

Definition at line 1076 of file fs.c.

1076  {
1077 #if defined(__linux__)
1078  static int no_pwritev;
1079 #endif
1080  ssize_t r;
1081 
1082  /* Serialize writes on OS X, concurrent write() and pwrite() calls result in
1083  * data loss. We can't use a per-file descriptor lock, the descriptor may be
1084  * a dup().
1085  */
1086 #if defined(__APPLE__)
1087  static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
1088 
1089  if (pthread_mutex_lock(&lock))
1090  abort();
1091 #endif
1092 
1093  if (req->off < 0) {
1094  if (req->nbufs == 1)
1095  r = write(req->file, req->bufs[0].base, req->bufs[0].len);
1096  else
1097  r = writev(req->file, (struct iovec*) req->bufs, req->nbufs);
1098  } else {
1099  if (req->nbufs == 1) {
1100  r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
1101  goto done;
1102  }
1103 #if HAVE_PREADV
1104  r = pwritev(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
1105 #else
1106 # if defined(__linux__)
1107  if (no_pwritev) retry:
1108 # endif
1109  {
1110  r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
1111  }
1112 # if defined(__linux__)
1113  else {
1114  r = uv__pwritev(req->file,
1115  (struct iovec*) req->bufs,
1116  req->nbufs,
1117  req->off);
1118  if (r == -1 && errno == ENOSYS) {
1119  no_pwritev = 1;
1120  goto retry;
1121  }
1122  }
1123 # endif
1124 #endif
1125  }
1126 
1127 done:
1128 #if defined(__APPLE__)
1129  if (pthread_mutex_unlock(&lock))
1130  abort();
1131 #endif
1132 
1133  return r;
1134 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz writev
Definition: sflib.h:82
ssize_t uv__pwritev(int fd, const struct iovec *iov, int iovcnt, int64_t offset)
static void lock(volatile int *lk)
Definition: malloc.c:61

References done, lock(), r, req, uv__pwritev(), write, and writev.

Referenced by uv__fs_write_all().

◆ uv__fs_write_all()

static ssize_t uv__fs_write_all ( uv_fs_t req)
static

Definition at line 1526 of file fs.c.

1526  {
1527  unsigned int iovmax;
1528  unsigned int nbufs;
1529  uv_buf_t* bufs;
1530  ssize_t total;
1531  ssize_t result;
1532 
1533  iovmax = uv__getiovmax();
1534  nbufs = req->nbufs;
1535  bufs = req->bufs;
1536  total = 0;
1537 
1538  while (nbufs > 0) {
1539  req->nbufs = nbufs;
1540  if (req->nbufs > iovmax)
1541  req->nbufs = iovmax;
1542 
1543  do
1544  result = uv__fs_write(req);
1545  while (result < 0 && errno == EINTR);
1546 
1547  if (result <= 0) {
1548  if (total == 0)
1549  total = result;
1550  break;
1551  }
1552 
1553  if (req->off >= 0)
1554  req->off += result;
1555 
1556  req->nbufs = uv__fs_buf_offset(req->bufs, result);
1557  req->bufs += req->nbufs;
1558  nbufs -= req->nbufs;
1559  total += result;
1560  }
1561 
1562  if (bufs != req->bufsml)
1563  uv__free(bufs);
1564 
1565  req->bufs = NULL;
1566  req->nbufs = 0;
1567 
1568  return total;
1569 }
static size_t uv__fs_buf_offset(uv_buf_t *bufs, size_t size)
Definition: fs.c:1512
static ssize_t uv__fs_write(uv_fs_t *req)
Definition: fs.c:1076

References bufs, EINTR, NULL, req, uv__free(), uv__fs_buf_offset(), uv__fs_write(), and uv__getiovmax().

Referenced by uv__fs_work().

◆ uv__mkostemp_initonce()

static void uv__mkostemp_initonce ( void  )
static

Definition at line 275 of file fs.c.

275  {
276  /* z/os doesn't have RTLD_DEFAULT but that's okay
277  * because it doesn't have mkostemp(O_CLOEXEC) either.
278  */
279 #ifdef RTLD_DEFAULT
280  uv__mkostemp = (int (*)(char*, int)) dlsym(RTLD_DEFAULT, "mkostemp");
281 
282  /* We don't care about errors, but we do want to clean them up.
283  * If there has been no error, then dlerror() will just return
284  * NULL.
285  */
286  dlerror();
287 #endif /* RTLD_DEFAULT */
288 }
static int
Definition: sfsocketcall.h:114

References int, and uv__mkostemp.

Referenced by uv__fs_mkstemp().

◆ uv__to_stat()

static void uv__to_stat ( struct stat src,
uv_stat_t dst 
)
static

Definition at line 1309 of file fs.c.

1309  {
1310  dst->st_dev = src->st_dev;
1311  dst->st_mode = src->st_mode;
1312  dst->st_nlink = src->st_nlink;
1313  dst->st_uid = src->st_uid;
1314  dst->st_gid = src->st_gid;
1315  dst->st_rdev = src->st_rdev;
1316  dst->st_ino = src->st_ino;
1317  dst->st_size = src->st_size;
1318  dst->st_blksize = src->st_blksize;
1319  dst->st_blocks = src->st_blocks;
1320 
1321 #if defined(__APPLE__)
1322  dst->st_atim.tv_sec = src->st_atimespec.tv_sec;
1323  dst->st_atim.tv_nsec = src->st_atimespec.tv_nsec;
1324  dst->st_mtim.tv_sec = src->st_mtimespec.tv_sec;
1325  dst->st_mtim.tv_nsec = src->st_mtimespec.tv_nsec;
1326  dst->st_ctim.tv_sec = src->st_ctimespec.tv_sec;
1327  dst->st_ctim.tv_nsec = src->st_ctimespec.tv_nsec;
1328  dst->st_birthtim.tv_sec = src->st_birthtimespec.tv_sec;
1329  dst->st_birthtim.tv_nsec = src->st_birthtimespec.tv_nsec;
1330  dst->st_flags = src->st_flags;
1331  dst->st_gen = src->st_gen;
1332 #elif defined(__ANDROID__)
1333  dst->st_atim.tv_sec = src->st_atime;
1334  dst->st_atim.tv_nsec = src->st_atimensec;
1335  dst->st_mtim.tv_sec = src->st_mtime;
1336  dst->st_mtim.tv_nsec = src->st_mtimensec;
1337  dst->st_ctim.tv_sec = src->st_ctime;
1338  dst->st_ctim.tv_nsec = src->st_ctimensec;
1339  dst->st_birthtim.tv_sec = src->st_ctime;
1340  dst->st_birthtim.tv_nsec = src->st_ctimensec;
1341  dst->st_flags = 0;
1342  dst->st_gen = 0;
1343 #elif !defined(_AIX) && ( \
1344  defined(__DragonFly__) || \
1345  defined(__FreeBSD__) || \
1346  defined(__OpenBSD__) || \
1347  defined(__NetBSD__) || \
1348  defined(_GNU_SOURCE) || \
1349  defined(_BSD_SOURCE) || \
1350  defined(_SVID_SOURCE) || \
1351  defined(_XOPEN_SOURCE) || \
1352  defined(_DEFAULT_SOURCE))
1353  dst->st_atim.tv_sec = src->st_atim.tv_sec;
1354  dst->st_atim.tv_nsec = src->st_atim.tv_nsec;
1355  dst->st_mtim.tv_sec = src->st_mtim.tv_sec;
1356  dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec;
1357  dst->st_ctim.tv_sec = src->st_ctim.tv_sec;
1358  dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec;
1359 # if defined(__FreeBSD__) || \
1360  defined(__NetBSD__)
1361  dst->st_birthtim.tv_sec = src->st_birthtim.tv_sec;
1362  dst->st_birthtim.tv_nsec = src->st_birthtim.tv_nsec;
1363  dst->st_flags = src->st_flags;
1364  dst->st_gen = src->st_gen;
1365 # else
1366  dst->st_birthtim.tv_sec = src->st_ctim.tv_sec;
1367  dst->st_birthtim.tv_nsec = src->st_ctim.tv_nsec;
1368  dst->st_flags = 0;
1369  dst->st_gen = 0;
1370 # endif
1371 #else
1372  dst->st_atim.tv_sec = src->st_atime;
1373  dst->st_atim.tv_nsec = 0;
1374  dst->st_mtim.tv_sec = src->st_mtime;
1375  dst->st_mtim.tv_nsec = 0;
1376  dst->st_ctim.tv_sec = src->st_ctime;
1377  dst->st_ctim.tv_nsec = 0;
1378  dst->st_birthtim.tv_sec = src->st_ctime;
1379  dst->st_birthtim.tv_nsec = 0;
1380  dst->st_flags = 0;
1381  dst->st_gen = 0;
1382 #endif
1383 }
lzma_index * src
Definition: index.h:567
char * dst
Definition: lz4.h:724

References dst, and src.

Referenced by uv__fs_fstat(), uv__fs_lstat(), and uv__fs_stat().

◆ uv_fs_access()

int uv_fs_access ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
int  flags,
uv_fs_cb  cb 
)

Definition at line 1659 of file fs.c.

1663  {
1664  INIT(ACCESS);
1665  PATH;
1666  req->flags = flags;
1667  POST;
1668 }
#define POST
Definition: fs.c:145
#define PATH
Definition: fs.c:112
#define INIT(subtype)
Definition: fs.c:96

◆ uv_fs_chmod()

int uv_fs_chmod ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
int  mode,
uv_fs_cb  cb 
)

Definition at line 1671 of file fs.c.

1675  {
1676  INIT(CHMOD);
1677  PATH;
1678  req->mode = mode;
1679  POST;
1680 }

◆ uv_fs_chown()

int uv_fs_chown ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_uid_t  uid,
uv_gid_t  gid,
uv_fs_cb  cb 
)

Definition at line 1683 of file fs.c.

1688  {
1689  INIT(CHOWN);
1690  PATH;
1691  req->uid = uid;
1692  req->gid = gid;
1693  POST;
1694 }

◆ uv_fs_close()

int uv_fs_close ( uv_loop_t loop,
uv_fs_t req,
uv_file  file,
uv_fs_cb  cb 
)

Definition at line 1697 of file fs.c.

1697  {
1698  INIT(CLOSE);
1699  req->file = file;
1700  POST;
1701 }
static int file
Definition: z80asm.c:58

◆ uv_fs_closedir()

int uv_fs_closedir ( uv_loop_t loop,
uv_fs_t req,
uv_dir_t dir,
uv_fs_cb  cb 
)

Definition at line 1933 of file fs.c.

1936  {
1937  INIT(CLOSEDIR);
1938 
1939  if (dir == NULL)
1940  return UV_EINVAL;
1941 
1942  req->ptr = dir;
1943  POST;
1944 }

◆ uv_fs_copyfile()

int uv_fs_copyfile ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
const char *  new_path,
int  flags,
uv_fs_cb  cb 
)

Definition at line 2103 of file fs.c.

2108  {
2109  INIT(COPYFILE);
2110 
2111  if (flags & ~(UV_FS_COPYFILE_EXCL |
2114  return UV_EINVAL;
2115  }
2116 
2117  PATH2;
2118  req->flags = flags;
2119  POST;
2120 }
#define PATH2
Definition: fs.c:125

◆ uv_fs_fchmod()

int uv_fs_fchmod ( uv_loop_t loop,
uv_fs_t req,
uv_file  file,
int  mode,
uv_fs_cb  cb 
)

Definition at line 1704 of file fs.c.

1708  {
1709  INIT(FCHMOD);
1710  req->file = file;
1711  req->mode = mode;
1712  POST;
1713 }

◆ uv_fs_fchown()

int uv_fs_fchown ( uv_loop_t loop,
uv_fs_t req,
uv_file  file,
uv_uid_t  uid,
uv_gid_t  gid,
uv_fs_cb  cb 
)

Definition at line 1716 of file fs.c.

1721  {
1722  INIT(FCHOWN);
1723  req->file = file;
1724  req->uid = uid;
1725  req->gid = gid;
1726  POST;
1727 }

◆ uv_fs_fdatasync()

int uv_fs_fdatasync ( uv_loop_t loop,
uv_fs_t req,
uv_file  file,
uv_fs_cb  cb 
)

Definition at line 1744 of file fs.c.

1744  {
1745  INIT(FDATASYNC);
1746  req->file = file;
1747  POST;
1748 }

◆ uv_fs_fstat()

int uv_fs_fstat ( uv_loop_t loop,
uv_fs_t req,
uv_file  file,
uv_fs_cb  cb 
)

Definition at line 1751 of file fs.c.

1751  {
1752  INIT(FSTAT);
1753  req->file = file;
1754  POST;
1755 }

◆ uv_fs_fsync()

int uv_fs_fsync ( uv_loop_t loop,
uv_fs_t req,
uv_file  file,
uv_fs_cb  cb 
)

Definition at line 1758 of file fs.c.

1758  {
1759  INIT(FSYNC);
1760  req->file = file;
1761  POST;
1762 }

◆ uv_fs_ftruncate()

int uv_fs_ftruncate ( uv_loop_t loop,
uv_fs_t req,
uv_file  file,
int64_t  off,
uv_fs_cb  cb 
)

Definition at line 1765 of file fs.c.

1769  {
1770  INIT(FTRUNCATE);
1771  req->file = file;
1772  req->off = off;
1773  POST;
1774 }

◆ uv_fs_futime()

int uv_fs_futime ( uv_loop_t loop,
uv_fs_t req,
uv_file  file,
double  atime,
double  mtime,
uv_fs_cb  cb 
)

Definition at line 1777 of file fs.c.

1782  {
1783  INIT(FUTIME);
1784  req->file = file;
1785  req->atime = atime;
1786  req->mtime = mtime;
1787  POST;
1788 }

◆ uv_fs_get_system_error()

int uv_fs_get_system_error ( const uv_fs_t req)

Definition at line 2132 of file fs.c.

2132  {
2133  return -req->result;
2134 }

◆ uv_fs_lchown()

int uv_fs_lchown ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_uid_t  uid,
uv_gid_t  gid,
uv_fs_cb  cb 
)

Definition at line 1730 of file fs.c.

1735  {
1736  INIT(LCHOWN);
1737  PATH;
1738  req->uid = uid;
1739  req->gid = gid;
1740  POST;
1741 }

◆ uv_fs_link()

int uv_fs_link ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
const char *  new_path,
uv_fs_cb  cb 
)

Definition at line 1811 of file fs.c.

1815  {
1816  INIT(LINK);
1817  PATH2;
1818  POST;
1819 }

◆ uv_fs_lstat()

int uv_fs_lstat ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_fs_cb  cb 
)

Definition at line 1804 of file fs.c.

1804  {
1805  INIT(LSTAT);
1806  PATH;
1807  POST;
1808 }

◆ uv_fs_lutime()

int uv_fs_lutime ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
double  atime,
double  mtime,
uv_fs_cb  cb 
)

Definition at line 1790 of file fs.c.

1795  {
1796  INIT(LUTIME);
1797  PATH;
1798  req->atime = atime;
1799  req->mtime = mtime;
1800  POST;
1801 }

◆ uv_fs_mkdir()

int uv_fs_mkdir ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
int  mode,
uv_fs_cb  cb 
)

Definition at line 1822 of file fs.c.

1826  {
1827  INIT(MKDIR);
1828  PATH;
1829  req->mode = mode;
1830  POST;
1831 }

◆ uv_fs_mkdtemp()

int uv_fs_mkdtemp ( uv_loop_t loop,
uv_fs_t req,
const char *  tpl,
uv_fs_cb  cb 
)

Definition at line 1834 of file fs.c.

1837  {
1838  INIT(MKDTEMP);
1839  req->path = uv__strdup(tpl);
1840  if (req->path == NULL)
1841  return UV_ENOMEM;
1842  POST;
1843 }

◆ uv_fs_mkstemp()

int uv_fs_mkstemp ( uv_loop_t loop,
uv_fs_t req,
const char *  tpl,
uv_fs_cb  cb 
)

Definition at line 1846 of file fs.c.

1849  {
1850  INIT(MKSTEMP);
1851  req->path = uv__strdup(tpl);
1852  if (req->path == NULL)
1853  return UV_ENOMEM;
1854  POST;
1855 }

◆ uv_fs_open()

int uv_fs_open ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
int  flags,
int  mode,
uv_fs_cb  cb 
)

Definition at line 1858 of file fs.c.

1863  {
1864  INIT(OPEN);
1865  PATH;
1866  req->flags = flags;
1867  req->mode = mode;
1868  POST;
1869 }

Referenced by uv__fs_copyfile().

◆ uv_fs_opendir()

int uv_fs_opendir ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_fs_cb  cb 
)

Definition at line 1911 of file fs.c.

1914  {
1915  INIT(OPENDIR);
1916  PATH;
1917  POST;
1918 }

◆ uv_fs_read()

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 
)

Definition at line 1872 of file fs.c.

1877  {
1878  INIT(READ);
1879 
1880  if (bufs == NULL || nbufs == 0)
1881  return UV_EINVAL;
1882 
1883  req->file = file;
1884 
1885  req->nbufs = nbufs;
1886  req->bufs = req->bufsml;
1887  if (nbufs > ARRAY_SIZE(req->bufsml))
1888  req->bufs = uv__malloc(nbufs * sizeof(*bufs));
1889 
1890  if (req->bufs == NULL)
1891  return UV_ENOMEM;
1892 
1893  memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
1894 
1895  req->off = off;
1896  POST;
1897 }
#define ARRAY_SIZE(a)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))

◆ uv_fs_readdir()

int uv_fs_readdir ( uv_loop_t loop,
uv_fs_t req,
uv_dir_t dir,
uv_fs_cb  cb 
)

Definition at line 1920 of file fs.c.

1923  {
1924  INIT(READDIR);
1925 
1926  if (dir == NULL || dir->dir == NULL || dir->dirents == NULL)
1927  return UV_EINVAL;
1928 
1929  req->ptr = dir;
1930  POST;
1931 }

◆ uv_fs_readlink()

int uv_fs_readlink ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_fs_cb  cb 
)

Definition at line 1946 of file fs.c.

1949  {
1950  INIT(READLINK);
1951  PATH;
1952  POST;
1953 }

◆ uv_fs_realpath()

int uv_fs_realpath ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_fs_cb  cb 
)

Definition at line 1956 of file fs.c.

1959  {
1960  INIT(REALPATH);
1961  PATH;
1962  POST;
1963 }

◆ uv_fs_rename()

int uv_fs_rename ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
const char *  new_path,
uv_fs_cb  cb 
)

Definition at line 1966 of file fs.c.

1970  {
1971  INIT(RENAME);
1972  PATH2;
1973  POST;
1974 }

◆ uv_fs_req_cleanup()

void uv_fs_req_cleanup ( uv_fs_t req)

Definition at line 2070 of file fs.c.

2070  {
2071  if (req == NULL)
2072  return;
2073 
2074  /* Only necessary for asychronous requests, i.e., requests with a callback.
2075  * Synchronous ones don't copy their arguments and have req->path and
2076  * req->new_path pointing to user-owned memory. UV_FS_MKDTEMP and
2077  * UV_FS_MKSTEMP are the exception to the rule, they always allocate memory.
2078  */
2079  if (req->path != NULL &&
2080  (req->cb != NULL ||
2081  req->fs_type == UV_FS_MKDTEMP || req->fs_type == UV_FS_MKSTEMP))
2082  uv__free((void*) req->path); /* Memory is shared with req->new_path. */
2083 
2084  req->path = NULL;
2085  req->new_path = NULL;
2086 
2087  if (req->fs_type == UV_FS_READDIR && req->ptr != NULL)
2089 
2090  if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL)
2092 
2093  if (req->bufs != req->bufsml)
2094  uv__free(req->bufs);
2095  req->bufs = NULL;
2096 
2097  if (req->fs_type != UV_FS_OPENDIR && req->ptr != &req->statbuf)
2098  uv__free(req->ptr);
2099  req->ptr = NULL;
2100 }
void uv__fs_scandir_cleanup(uv_fs_t *req)
Definition: uv-common.c:635
void uv__fs_readdir_cleanup(uv_fs_t *req)
Definition: uv-common.c:724
@ UV_FS_SCANDIR
Definition: uv.h:1281
@ UV_FS_READDIR
Definition: uv.h:1291
@ UV_FS_OPENDIR
Definition: uv.h:1290
@ UV_FS_MKSTEMP
Definition: uv.h:1294
@ UV_FS_MKDTEMP
Definition: uv.h:1279

Referenced by uv__fs_copyfile().

◆ uv_fs_rmdir()

int uv_fs_rmdir ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_fs_cb  cb 
)

Definition at line 1977 of file fs.c.

1977  {
1978  INIT(RMDIR);
1979  PATH;
1980  POST;
1981 }

◆ uv_fs_scandir()

int uv_fs_scandir ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
int  flags,
uv_fs_cb  cb 
)

Definition at line 1900 of file fs.c.

1904  {
1905  INIT(SCANDIR);
1906  PATH;
1907  req->flags = flags;
1908  POST;
1909 }

◆ uv_fs_sendfile()

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 
)

Definition at line 1984 of file fs.c.

1990  {
1991  INIT(SENDFILE);
1992  req->flags = in_fd; /* hack */
1993  req->file = out_fd;
1994  req->off = off;
1995  req->bufsml[0].len = len;
1996  POST;
1997 }

Referenced by uv__fs_copyfile().

◆ uv_fs_stat()

int uv_fs_stat ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_fs_cb  cb 
)

Definition at line 2000 of file fs.c.

2000  {
2001  INIT(STAT);
2002  PATH;
2003  POST;
2004 }

◆ uv_fs_statfs()

int uv_fs_statfs ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_fs_cb  cb 
)

Definition at line 2123 of file fs.c.

2126  {
2127  INIT(STATFS);
2128  PATH;
2129  POST;
2130 }

◆ uv_fs_symlink()

int uv_fs_symlink ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
const char *  new_path,
int  flags,
uv_fs_cb  cb 
)

Definition at line 2007 of file fs.c.

2012  {
2013  INIT(SYMLINK);
2014  PATH2;
2015  req->flags = flags;
2016  POST;
2017 }

◆ uv_fs_unlink()

int uv_fs_unlink ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
uv_fs_cb  cb 
)

Definition at line 2020 of file fs.c.

2020  {
2021  INIT(UNLINK);
2022  PATH;
2023  POST;
2024 }

Referenced by uv__fs_copyfile().

◆ uv_fs_utime()

int uv_fs_utime ( uv_loop_t loop,
uv_fs_t req,
const char *  path,
double  atime,
double  mtime,
uv_fs_cb  cb 
)

Definition at line 2027 of file fs.c.

2032  {
2033  INIT(UTIME);
2034  PATH;
2035  req->atime = atime;
2036  req->mtime = mtime;
2037  POST;
2038 }

◆ uv_fs_write()

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 
)

Definition at line 2041 of file fs.c.

2047  {
2048  INIT(WRITE);
2049 
2050  if (bufs == NULL || nbufs == 0)
2051  return UV_EINVAL;
2052 
2053  req->file = file;
2054 
2055  req->nbufs = nbufs;
2056  req->bufs = req->bufsml;
2057  if (nbufs > ARRAY_SIZE(req->bufsml))
2058  req->bufs = uv__malloc(nbufs * sizeof(*bufs));
2059 
2060  if (req->bufs == NULL)
2061  return UV_ENOMEM;
2062 
2063  memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
2064 
2065  req->off = off;
2066  POST;
2067 }

◆ UV_UNUSED() [1/2]

UV_UNUSED ( static struct timespec   uv__fs_to_timespecdouble time)

Definition at line 212 of file fs.c.

212  {
213  struct timespec ts;
214  ts.tv_sec = time;
215  ts.tv_nsec = (uint64_t)(time * 1000000) % 1000000 * 1000;
216  return ts;
217 }
static static fork const void static count static fd const char const char static newpath char char char static envp time
Definition: sflib.h:42
unsigned long uint64_t
Definition: sftypes.h:28
time_t tv_sec
Definition: sftypes.h:89

References time, timespec::tv_nsec, and timespec::tv_sec.

◆ UV_UNUSED() [2/2]

UV_UNUSED ( static struct timeval   uv__fs_to_timevaldouble time)

Definition at line 219 of file fs.c.

219  {
220  struct timeval tv;
221  tv.tv_sec = time;
222  tv.tv_usec = (uint64_t)(time * 1000000) % 1000000;
223  return tv;
224 }

References time, and tv.

Variable Documentation

◆ uv__mkostemp

int(* uv__mkostemp) (char *, int) ( char *  ,
int   
)
static

Definition at line 272 of file fs.c.

Referenced by uv__fs_mkstemp(), and uv__mkostemp_initonce().