--- libeio/eio.c 2011/07/26 11:07:08 1.99 +++ libeio/eio.c 2011/09/26 20:19:08 1.106 @@ -45,7 +45,7 @@ #include "ecb.h" #ifdef EIO_STACKSIZE -# define XTHREAD_STACKSIZE EIO_STACKSIZE +# define X_STACKSIZE EIO_STACKSIZE #endif #include "xthread.h" @@ -60,6 +60,12 @@ #include #include +#if _POSIX_VERSION >= 200809L +# define HAVE_AT 1 +#else +# define HAVE_AT 0 +#endif + /* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ /* intptr_t only comes from stdint.h, says idiot openbsd coder */ #if HAVE_STDINT_H @@ -107,7 +113,10 @@ #undef PAGESIZE #define PAGESIZE 4096 /* GetSystemInfo? */ + /* TODO: look at how perl does stat (non-sloppy), unlink (ro-files), utime, link */ + #ifdef EIO_STRUCT_STATI64 + /* look at perl's non-sloppy stat */ #define stat(path,buf) _stati64 (path,buf) #define fstat(fd,buf) _fstati64 (fd,buf) #endif @@ -291,6 +300,28 @@ #define EIO_TICKS ((1000000 + 1023) >> 10) +/*****************************************************************************/ + +struct tmpbuf +{ + void *ptr; + int len; +}; + +static void * +tmpbuf_get (struct tmpbuf *buf, int len) +{ + if (buf->len < len) + { + free (buf->ptr); + buf->ptr = malloc (buf->len = len); + } + + return buf->ptr; +} + +/*****************************************************************************/ + #define ETP_PRI_MIN EIO_PRI_MIN #define ETP_PRI_MAX EIO_PRI_MAX @@ -323,11 +354,11 @@ static unsigned int max_poll_time; /* reslock */ static unsigned int max_poll_reqs; /* reslock */ -static volatile unsigned int nreqs; /* reqlock */ -static volatile unsigned int nready; /* reqlock */ -static volatile unsigned int npending; /* reqlock */ -static volatile unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */ -static volatile unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */ +static unsigned int nreqs; /* reqlock */ +static unsigned int nready; /* reqlock */ +static unsigned int npending; /* reqlock */ +static unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */ +static unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */ static xmutex_t wrklock; static xmutex_t reslock; @@ -345,14 +376,13 @@ typedef struct etp_worker { + struct tmpbuf tmpbuf; + /* locked by wrklock */ struct etp_worker *prev, *next; xthread_t tid; - /* locked by reslock, reqlock or wrklock */ - ETP_REQ *req; /* currently processed request */ - #ifdef ETP_WORKER_COMMON ETP_WORKER_COMMON #endif @@ -373,6 +403,8 @@ static void ecb_cold etp_worker_free (etp_worker *wrk) { + free (wrk->tmpbuf.ptr); + wrk->next->prev = wrk->prev; wrk->prev->next = wrk->next; @@ -560,7 +592,7 @@ static void ecb_cold etp_end_thread (void) { - eio_req *req = calloc (1, sizeof (eio_req)); + eio_req *req = calloc (1, sizeof (eio_req)); /* will be freed by worker */ req->type = -1; req->pri = ETP_PRI_MAX - ETP_PRI_MIN; @@ -1336,10 +1368,26 @@ /*****************************************************************************/ /* requests implemented outside eio_execute, because they are so large */ -static void -eio__realpath (eio_req *req, etp_worker *self) +/* copies some absolute path to tmpbuf */ +static char * +eio__getwd (struct tmpbuf *tmpbuf, eio_wd wd) +{ + if (wd == EIO_CWD) + return getcwd (tmpbuf->ptr, PATH_MAX); + +#if HAVE_AT + abort (); /*TODO*/ +#else + strcpy (tmpbuf->ptr, wd); +#endif + return tmpbuf->ptr; +} + +/* result will always end up in tmpbuf, there is always space for adding a 0-byte */ +static int +eio__realpath (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) { - char *rel = req->ptr1; + const char *rel = path; char *res; char *tmp1, *tmp2; #if SYMLOOP_MAX > 32 @@ -1348,29 +1396,17 @@ int symlinks = 32; #endif - req->result = -1; + /*D*/ /*TODO: wd ignored */ errno = EINVAL; if (!rel) - return; + return -1; errno = ENOENT; if (!*rel) - return; - - if (!req->ptr2) - { - X_LOCK (wrklock); - req->flags |= EIO_FLAG_PTR2_FREE; - X_UNLOCK (wrklock); - req->ptr2 = malloc (PATH_MAX * 3); - - errno = ENOMEM; - if (!req->ptr2) - return; - } + return -1; - res = req->ptr2; + res = tmpbuf_get (tmpbuf, PATH_MAX * 3); tmp1 = res + PATH_MAX; tmp2 = tmp1 + PATH_MAX; @@ -1399,8 +1435,8 @@ if (*rel != '/') { - if (!getcwd (res, PATH_MAX)) - return; + if (!eio__getwd (tmpbuf, wd)) + return -1; if (res [1]) /* only use if not / */ res += strlen (res); @@ -1409,7 +1445,7 @@ while (*rel) { eio_ssize_t len, linklen; - char *beg = rel; + const char *beg = rel; while (*rel && *rel != '/') ++rel; @@ -1431,7 +1467,7 @@ { /* .. - back up one component, if possible */ - while (res != req->ptr2) + while (res != tmpbuf->ptr) if (*--res == '/') break; @@ -1451,12 +1487,12 @@ res [len + 1] = 0; /* now check if it's a symlink */ - linklen = readlink (req->ptr2, tmp1, PATH_MAX); + linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); if (linklen < 0) { if (errno != EINVAL) - return; + return -1; /* it's a normal directory. hopefully */ res += len + 1; @@ -1468,14 +1504,14 @@ errno = ENAMETOOLONG; if (linklen + 1 + rellen >= PATH_MAX) - return; + return -1; errno = ELOOP; if (!--symlinks) - return; + return -1; if (*tmp1 == '/') - res = req->ptr2; /* symlink resolves to an absolute path */ + res = tmpbuf->ptr; /* symlink resolves to an absolute path */ /* we need to be careful, as rel might point into tmp2 already */ memmove (tmp2 + linklen + 1, rel, rellen + 1); @@ -1487,13 +1523,10 @@ } /* special case for the lone root path */ - if (res == req->ptr2) + if (res == tmpbuf->ptr) *res++ = '/'; - req->result = res - (char *)req->ptr2; - -done: - req->ptr2 = realloc (req->ptr2, req->result); /* trade time for space savings */ + return res - (char *)tmpbuf->ptr; } static signed char @@ -1663,7 +1696,7 @@ /* read a full directory */ static void -eio__scandir (eio_req *req, etp_worker *self) +eio__scandir (eio_req *req) { char *name, *names; int namesalloc = 4096 - sizeof (void *) * 4; @@ -1705,33 +1738,36 @@ if (dirp == INVALID_HANDLE_VALUE) { - dirp = 0; - - /* should steal _dosmaperr */ - switch (GetLastError ()) - { - case ERROR_FILE_NOT_FOUND: - req->result = 0; - break; - - case ERROR_INVALID_NAME: - case ERROR_PATH_NOT_FOUND: - case ERROR_NO_MORE_FILES: - errno = ENOENT; - break; - - case ERROR_NOT_ENOUGH_MEMORY: - errno = ENOMEM; - break; + /* should steal _dosmaperr */ + switch (GetLastError ()) + { + case ERROR_FILE_NOT_FOUND: + req->result = 0; + break; + + case ERROR_INVALID_NAME: + case ERROR_PATH_NOT_FOUND: + case ERROR_NO_MORE_FILES: + errno = ENOENT; + break; + + case ERROR_NOT_ENOUGH_MEMORY: + errno = ENOMEM; + break; + + default: + errno = EINVAL; + break; + } - default: - errno = EINVAL; - break; - } + return; } } #else dirp = opendir (req->ptr1); + + if (!dirp) + return; #endif if (req->flags & EIO_FLAG_PTR1_FREE) @@ -1741,193 +1777,327 @@ req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; req->ptr2 = names = malloc (namesalloc); - if (dirp && names && (!flags || dents)) - for (;;) - { - int done; + if (!names || (flags && !dents)) + return; + + for (;;) + { + int done; #ifdef _WIN32 - done = !dirp; + done = !dirp; #else - errno = 0; - entp = readdir (dirp); - done = !entp; + errno = 0; + entp = readdir (dirp); + done = !entp; #endif - if (done) - { + if (done) + { #ifndef _WIN32 - int old_errno = errno; - closedir (dirp); - errno = old_errno; + int old_errno = errno; + closedir (dirp); + errno = old_errno; - if (errno) - break; + if (errno) + break; #endif - /* sort etc. */ - req->int1 = flags; - req->result = dentoffs; - - if (flags & EIO_READDIR_STAT_ORDER) - eio_dent_sort (dents, dentoffs, flags & EIO_READDIR_DIRS_FIRST ? 7 : 0, inode_bits); - else if (flags & EIO_READDIR_DIRS_FIRST) - if (flags & EIO_READDIR_FOUND_UNKNOWN) - eio_dent_sort (dents, dentoffs, 7, inode_bits); /* sort by score and inode */ - else - { - /* in this case, all is known, and we just put dirs first and sort them */ - eio_dirent *oth = dents + dentoffs; - eio_dirent *dir = dents; - - /* now partition dirs to the front, and non-dirs to the back */ - /* by walking from both sides and swapping if necessary */ - while (oth > dir) - { - if (dir->type == EIO_DT_DIR) - ++dir; - else if ((--oth)->type == EIO_DT_DIR) - { - eio_dirent tmp = *dir; *dir = *oth; *oth = tmp; + /* sort etc. */ + req->int1 = flags; + req->result = dentoffs; + + if (flags & EIO_READDIR_STAT_ORDER) + eio_dent_sort (dents, dentoffs, flags & EIO_READDIR_DIRS_FIRST ? 7 : 0, inode_bits); + else if (flags & EIO_READDIR_DIRS_FIRST) + if (flags & EIO_READDIR_FOUND_UNKNOWN) + eio_dent_sort (dents, dentoffs, 7, inode_bits); /* sort by score and inode */ + else + { + /* in this case, all is known, and we just put dirs first and sort them */ + eio_dirent *oth = dents + dentoffs; + eio_dirent *dir = dents; + + /* now partition dirs to the front, and non-dirs to the back */ + /* by walking from both sides and swapping if necessary */ + while (oth > dir) + { + if (dir->type == EIO_DT_DIR) + ++dir; + else if ((--oth)->type == EIO_DT_DIR) + { + eio_dirent tmp = *dir; *dir = *oth; *oth = tmp; - ++dir; - } - } + ++dir; + } + } - /* now sort the dirs only (dirs all have the same score) */ - eio_dent_sort (dents, dir - dents, 0, inode_bits); - } + /* now sort the dirs only (dirs all have the same score) */ + eio_dent_sort (dents, dir - dents, 0, inode_bits); + } - break; - } + break; + } - /* now add the entry to our list(s) */ - name = D_NAME (entp); + /* now add the entry to our list(s) */ + name = D_NAME (entp); - /* skip . and .. entries */ - if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) - { - int len = D_NAMLEN (entp) + 1; + /* skip . and .. entries */ + if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) + { + int len = D_NAMLEN (entp) + 1; - while (ecb_expect_false (namesoffs + len > namesalloc)) - { - namesalloc *= 2; - req->ptr2 = names = realloc (names, namesalloc); + while (ecb_expect_false (namesoffs + len > namesalloc)) + { + namesalloc *= 2; + req->ptr2 = names = realloc (names, namesalloc); - if (!names) - break; - } + if (!names) + break; + } - memcpy (names + namesoffs, name, len); + memcpy (names + namesoffs, name, len); - if (dents) - { - struct eio_dirent *ent; + if (dents) + { + struct eio_dirent *ent; - if (ecb_expect_false (dentoffs == dentalloc)) - { - dentalloc *= 2; - req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent)); + if (ecb_expect_false (dentoffs == dentalloc)) + { + dentalloc *= 2; + req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent)); - if (!dents) - break; - } + if (!dents) + break; + } - ent = dents + dentoffs; + ent = dents + dentoffs; - ent->nameofs = namesoffs; /* rather dirtily we store the offset in the pointer */ - ent->namelen = len - 1; - ent->inode = D_INO (entp); + ent->nameofs = namesoffs; /* rather dirtily we store the offset in the pointer */ + ent->namelen = len - 1; + ent->inode = D_INO (entp); - inode_bits |= ent->inode; + inode_bits |= ent->inode; - switch (D_TYPE (entp)) - { - default: - ent->type = EIO_DT_UNKNOWN; - flags |= EIO_READDIR_FOUND_UNKNOWN; - break; - - #ifdef DT_FIFO - case DT_FIFO: ent->type = EIO_DT_FIFO; break; - #endif - #ifdef DT_CHR - case DT_CHR: ent->type = EIO_DT_CHR; break; - #endif - #ifdef DT_MPC - case DT_MPC: ent->type = EIO_DT_MPC; break; - #endif - #ifdef DT_DIR - case DT_DIR: ent->type = EIO_DT_DIR; break; - #endif - #ifdef DT_NAM - case DT_NAM: ent->type = EIO_DT_NAM; break; - #endif - #ifdef DT_BLK - case DT_BLK: ent->type = EIO_DT_BLK; break; - #endif - #ifdef DT_MPB - case DT_MPB: ent->type = EIO_DT_MPB; break; - #endif - #ifdef DT_REG - case DT_REG: ent->type = EIO_DT_REG; break; - #endif - #ifdef DT_NWK - case DT_NWK: ent->type = EIO_DT_NWK; break; - #endif - #ifdef DT_CMP - case DT_CMP: ent->type = EIO_DT_CMP; break; - #endif - #ifdef DT_LNK - case DT_LNK: ent->type = EIO_DT_LNK; break; - #endif - #ifdef DT_SOCK - case DT_SOCK: ent->type = EIO_DT_SOCK; break; - #endif - #ifdef DT_DOOR - case DT_DOOR: ent->type = EIO_DT_DOOR; break; - #endif - #ifdef DT_WHT - case DT_WHT: ent->type = EIO_DT_WHT; break; - #endif - } + switch (D_TYPE (entp)) + { + default: + ent->type = EIO_DT_UNKNOWN; + flags |= EIO_READDIR_FOUND_UNKNOWN; + break; + + #ifdef DT_FIFO + case DT_FIFO: ent->type = EIO_DT_FIFO; break; + #endif + #ifdef DT_CHR + case DT_CHR: ent->type = EIO_DT_CHR; break; + #endif + #ifdef DT_MPC + case DT_MPC: ent->type = EIO_DT_MPC; break; + #endif + #ifdef DT_DIR + case DT_DIR: ent->type = EIO_DT_DIR; break; + #endif + #ifdef DT_NAM + case DT_NAM: ent->type = EIO_DT_NAM; break; + #endif + #ifdef DT_BLK + case DT_BLK: ent->type = EIO_DT_BLK; break; + #endif + #ifdef DT_MPB + case DT_MPB: ent->type = EIO_DT_MPB; break; + #endif + #ifdef DT_REG + case DT_REG: ent->type = EIO_DT_REG; break; + #endif + #ifdef DT_NWK + case DT_NWK: ent->type = EIO_DT_NWK; break; + #endif + #ifdef DT_CMP + case DT_CMP: ent->type = EIO_DT_CMP; break; + #endif + #ifdef DT_LNK + case DT_LNK: ent->type = EIO_DT_LNK; break; + #endif + #ifdef DT_SOCK + case DT_SOCK: ent->type = EIO_DT_SOCK; break; + #endif + #ifdef DT_DOOR + case DT_DOOR: ent->type = EIO_DT_DOOR; break; + #endif + #ifdef DT_WHT + case DT_WHT: ent->type = EIO_DT_WHT; break; + #endif + } - ent->score = 7; + ent->score = 7; - if (flags & EIO_READDIR_DIRS_FIRST) - { - if (ent->type == EIO_DT_UNKNOWN) - { - if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ - ent->score = 1; - else if (!strchr (name, '.')) /* absense of dots indicate likely dirs */ - ent->score = len <= 2 ? 4 - len : len <= 4 ? 4 : len <= 7 ? 5 : 6; /* shorter == more likely dir, but avoid too many classes */ - } - else if (ent->type == EIO_DT_DIR) - ent->score = 0; - } - } + if (flags & EIO_READDIR_DIRS_FIRST) + { + if (ent->type == EIO_DT_UNKNOWN) + { + if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ + ent->score = 1; + else if (!strchr (name, '.')) /* absense of dots indicate likely dirs */ + ent->score = len <= 2 ? 4 - len : len <= 4 ? 4 : len <= 7 ? 5 : 6; /* shorter == more likely dir, but avoid too many classes */ + } + else if (ent->type == EIO_DT_DIR) + ent->score = 0; + } + } - namesoffs += len; - ++dentoffs; - } + namesoffs += len; + ++dentoffs; + } - if (EIO_CANCELLED (req)) - { - errno = ECANCELED; - break; - } + if (EIO_CANCELLED (req)) + { + errno = ECANCELED; + break; + } #ifdef _WIN32 - if (!FindNextFile (dirp, &entp)) - { - FindClose (dirp); - dirp = 0; - } + if (!FindNextFile (dirp, &entp)) + { + FindClose (dirp); + dirp = 0; + } #endif - } + } +} + +/*****************************************************************************/ +/* working directory stuff */ + +#if HAVE_AT + +#define WD2FD(wd) ((wd) ? ((int)(long)(wd)) - 1 : AT_FDCWD) + +#ifndef O_SEARCH +# define O_SEARCH O_RDONLY +#endif + +eio_wd +eio_wd_open_sync (eio_wd wd, const char *path) +{ + int fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY); + + return fd >= 0 ? (eio_wd)(long)(fd + 1) : EIO_INVALID_WD; +} + +static eio_wd +eio__wd_open_sync (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) +{ + return eio_wd_open_sync (wd, path); +} + +void +eio_wd_close_sync (eio_wd wd) +{ + int fd = WD2FD (wd); + + if (fd >= 0) + close (fd); +} + +static int +eio__truncateat (int dirfd, const char *path, off_t length) +{ + int fd = openat (dirfd, path, O_WRONLY | O_CLOEXEC); + int res; + + if (fd < 0) + return fd; + + res = ftruncate (fd, length); + close (fd); + return res; +} + +static int +eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) +{ + int fd = openat (dirfd, path, O_SEARCH | O_CLOEXEC); + int res; + + if (fd < 0) + return fd; + + res = fstatvfs (fd, buf); + close (fd); + return res; + } +#else + +/* on legacy systems, we represent the working directories simply by their path strings */ + +static const char * +wd_expand (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) +{ + if (!wd || *path == '/') + return path; + + { + int l1 = strlen ((const char *)wd); + int l2 = strlen (path); + + char *res = tmpbuf_get (tmpbuf, l1 + l2 + 2); + + memcpy (res, wd, l1); + res [l1] = '/'; + memcpy (res + l1 + 1, path, l2 + 1); + + return res; + } +} + +static eio_wd +eio__wd_open_sync (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) +{ + if (*path == '/') /* absolute paths ignore wd */ + path = strdup (path); + else if (path [0] == '.' && !path [1]) /* special case '.', as it is common */ + return wd; + else + { + int len = eio__realpath (tmpbuf, wd, path); + + path = EIO_INVALID_WD; + + if (len >= 0) + { + ((char *)tmpbuf->ptr)[len] = 0; + path = strdup (tmpbuf->ptr); + } + } + + if (!path) + path = EIO_INVALID_WD; + + return (eio_wd)path; +} + +eio_wd +eio_wd_open_sync (eio_wd wd, const char *path) +{ + struct tmpbuf tmpbuf = { 0 }; + wd = eio__wd_open_sync (&tmpbuf, wd, path); + free (tmpbuf.ptr); + + return wd; +} + +void +eio_wd_close_sync (eio_wd wd) +{ + if (wd != EIO_INVALID_WD) + free (wd); +} + +#endif + /*****************************************************************************/ #define ALLOC(len) \ @@ -1966,7 +2136,7 @@ for (;;) { - self->req = req = reqq_shift (&req_queue); + req = reqq_shift (&req_queue); if (req) break; @@ -2014,13 +2184,14 @@ if (!reqq_push (&res_queue, req) && want_poll_cb) want_poll_cb (); - self->req = 0; etp_worker_clear (self); X_UNLOCK (reslock); } quit: + free (req); + X_LOCK (wrklock); etp_worker_free (self); X_UNLOCK (wrklock); @@ -2073,6 +2244,12 @@ static void eio_execute (etp_worker *self, eio_req *req) { +#if HAVE_AT + int dirfd; +#else + const char *path; +#endif + if (ecb_expect_false (EIO_CANCELLED (req))) { req->result = -1; @@ -2080,8 +2257,30 @@ return; } + if (ecb_expect_false (req->wd == EIO_INVALID_WD)) + { + req->result = -1; + req->errorno = ENOENT; + return; + } + + if (req->type >= EIO_OPEN) + { + #if HAVE_AT + dirfd = WD2FD (req->wd); + #else + path = wd_expand (&self->tmpbuf, req->wd, req->ptr1); + #endif + } + switch (req->type) { + case EIO_WD_OPEN: req->wd = eio__wd_open_sync (&self->tmpbuf, req->wd, req->ptr1); + req->result = req->wd == EIO_INVALID_WD ? -1 : 0; + break; + case EIO_WD_CLOSE: req->result = 0; + eio_wd_close_sync (req->wd); break; + case EIO_READ: ALLOC (req->size); req->result = req->offs >= 0 ? pread (req->int1, req->ptr2, req->size, req->offs) @@ -2093,41 +2292,120 @@ case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; +#if HAVE_AT + + case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); + req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, 0); break; + case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); + req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; + case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break; + case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break; + case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break; + case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break; + + case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; + case EIO_RMDIR: req->result = unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; + case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; + case EIO_RENAME: req->result = renameat (dirfd, req->ptr1, WD2FD (req->int3), req->ptr2); break; + case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD (req->int3), req->ptr2, 0); break; + case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; + case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; + case EIO_READLINK: ALLOC (PATH_MAX); + req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break; + case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); + req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; + case EIO_UTIME: + case EIO_FUTIME: + { + struct timespec ts[2]; + struct timespec *times; + + if (req->nv1 != -1. || req->nv2 != -1.) + { + ts[0].tv_sec = req->nv1; + ts[0].tv_nsec = (req->nv1 - ts[0].tv_sec) * 1e9; + ts[1].tv_sec = req->nv2; + ts[1].tv_nsec = (req->nv2 - ts[1].tv_sec) * 1e9; + + times = ts; + } + else + times = 0; + + req->result = req->type == EIO_FUTIME + ? futimens (req->int1, times) + : utimensat (dirfd, req->ptr1, times, 0); + } + break; + +#else + case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); - req->result = stat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; + req->result = stat (path , (EIO_STRUCT_STAT *)req->ptr2); break; case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); - req->result = lstat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; + req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; + case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; + case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break; + case EIO_TRUNCATE: req->result = truncate (path , req->offs); break; + case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break; + + case EIO_UNLINK: req->result = unlink (path ); break; + case EIO_RMDIR: req->result = rmdir (path ); break; + case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; + case EIO_RENAME: req->result = rename (path , req->ptr2); break; + case EIO_LINK: req->result = link (path , req->ptr2); break; + case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; + case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; + case EIO_READLINK: ALLOC (PATH_MAX); + req->result = readlink (path, req->ptr2, PATH_MAX); break; + case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); + req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; + + case EIO_UTIME: + case EIO_FUTIME: + { + struct timeval tv[2]; + struct timeval *times; + + if (req->nv1 != -1. || req->nv2 != -1.) + { + tv[0].tv_sec = req->nv1; + tv[0].tv_usec = (req->nv1 - tv[0].tv_sec) * 1e6; + tv[1].tv_sec = req->nv2; + tv[1].tv_usec = (req->nv2 - tv[1].tv_sec) * 1e6; + + times = tv; + } + else + times = 0; + + req->result = req->type == EIO_FUTIME + ? futimes (req->int1, times) + : utimes (req->ptr1, times); + } + break; + +#endif + + case EIO_REALPATH: if (0 <= (req->result = eio__realpath (&self->tmpbuf, req->wd, req->ptr1))) + { + ALLOC (req->result); + memcpy (req->ptr2, self->tmpbuf.ptr, req->result); + } + break; + case EIO_FSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); req->result = fstat (req->int1, (EIO_STRUCT_STAT *)req->ptr2); break; - case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); - req->result = statvfs (req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; case EIO_FSTATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); req->result = fstatvfs (req->int1, (EIO_STRUCT_STATVFS *)req->ptr2); break; - case EIO_CHOWN: req->result = chown (req->ptr1, req->int2, req->int3); break; case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; - case EIO_CHMOD: req->result = chmod (req->ptr1, (mode_t)req->int2); break; case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break; - case EIO_TRUNCATE: req->result = truncate (req->ptr1, req->offs); break; case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; - case EIO_OPEN: req->result = open (req->ptr1, req->int1, (mode_t)req->int2); break; case EIO_CLOSE: req->result = close (req->int1); break; case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; - case EIO_UNLINK: req->result = unlink (req->ptr1); break; - case EIO_RMDIR: req->result = rmdir (req->ptr1); break; - case EIO_MKDIR: req->result = mkdir (req->ptr1, (mode_t)req->int2); break; - case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break; - case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break; - case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; - case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; - - case EIO_REALPATH: eio__realpath (req, self); break; - - case EIO_READLINK: ALLOC (PATH_MAX); - req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; - case EIO_SYNC: req->result = 0; sync (); break; case EIO_FSYNC: req->result = fsync (req->int1); break; case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; @@ -2139,7 +2417,7 @@ case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; - case EIO_READDIR: eio__scandir (req, self); break; + case EIO_READDIR: eio__scandir (req); break; case EIO_BUSY: #ifdef _WIN32 @@ -2156,30 +2434,6 @@ #endif break; - case EIO_UTIME: - case EIO_FUTIME: - { - struct timeval tv[2]; - struct timeval *times; - - if (req->nv1 != -1. || req->nv2 != -1.) - { - tv[0].tv_sec = req->nv1; - tv[0].tv_usec = (req->nv1 - tv[0].tv_sec) * 1000000.; - tv[1].tv_sec = req->nv2; - tv[1].tv_usec = (req->nv2 - tv[1].tv_sec) * 1000000.; - - times = tv; - } - else - times = 0; - - req->result = req->type == EIO_FUTIME - ? futimes (req->int1, times) - : utimes (req->ptr1, times); - } - break; - case EIO_GROUP: abort (); /* handled in eio_request */