… | |
… | |
312 | } |
312 | } |
313 | |
313 | |
314 | return buf->ptr; |
314 | return buf->ptr; |
315 | } |
315 | } |
316 | |
316 | |
|
|
317 | struct tmpbuf; |
|
|
318 | |
|
|
319 | #if _POSIX_VERSION >= 200809L |
|
|
320 | #define HAVE_AT 1 |
|
|
321 | #define WD2FD(wd) ((wd) ? (wd)->fd : AT_FDCWD) |
|
|
322 | #ifndef O_SEARCH |
|
|
323 | #define O_SEARCH O_RDONLY |
|
|
324 | #endif |
|
|
325 | #else |
|
|
326 | #define HAVE_AT 0 |
|
|
327 | static const char *wd_expand (struct tmpbuf *tmpbuf, eio_wd wd, const char *path); |
|
|
328 | #endif |
|
|
329 | |
|
|
330 | struct eio_pwd |
|
|
331 | { |
|
|
332 | #if HAVE_AT |
|
|
333 | int fd; |
|
|
334 | #endif |
|
|
335 | int len; |
|
|
336 | char str[1]; /* actually, a 0-terminated canonical path */ |
|
|
337 | }; |
|
|
338 | |
317 | /*****************************************************************************/ |
339 | /*****************************************************************************/ |
318 | |
340 | |
319 | #define ETP_PRI_MIN EIO_PRI_MIN |
341 | #define ETP_PRI_MIN EIO_PRI_MIN |
320 | #define ETP_PRI_MAX EIO_PRI_MAX |
342 | #define ETP_PRI_MAX EIO_PRI_MAX |
321 | |
343 | |
… | |
… | |
387 | #define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) |
409 | #define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) |
388 | #define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock) |
410 | #define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock) |
389 | |
411 | |
390 | /* worker threads management */ |
412 | /* worker threads management */ |
391 | |
413 | |
392 | static void ecb_cold |
414 | static void |
393 | etp_worker_clear (etp_worker *wrk) |
415 | etp_worker_clear (etp_worker *wrk) |
394 | { |
416 | { |
395 | } |
417 | } |
396 | |
418 | |
397 | static void ecb_cold |
419 | static void ecb_cold |
… | |
… | |
584 | } |
606 | } |
585 | |
607 | |
586 | static void ecb_cold |
608 | static void ecb_cold |
587 | etp_end_thread (void) |
609 | etp_end_thread (void) |
588 | { |
610 | { |
589 | eio_req *req = calloc (1, sizeof (eio_req)); |
611 | eio_req *req = calloc (1, sizeof (eio_req)); /* will be freed by worker */ |
590 | |
612 | |
591 | req->type = -1; |
613 | req->type = -1; |
592 | req->pri = ETP_PRI_MAX - ETP_PRI_MIN; |
614 | req->pri = ETP_PRI_MAX - ETP_PRI_MIN; |
593 | |
615 | |
594 | X_LOCK (reqlock); |
616 | X_LOCK (reqlock); |
… | |
… | |
1360 | } |
1382 | } |
1361 | |
1383 | |
1362 | /*****************************************************************************/ |
1384 | /*****************************************************************************/ |
1363 | /* requests implemented outside eio_execute, because they are so large */ |
1385 | /* requests implemented outside eio_execute, because they are so large */ |
1364 | |
1386 | |
1365 | /* copies some absolute path to tmpbuf */ |
|
|
1366 | static char * |
|
|
1367 | eio__getwd (struct tmpbuf *tmpbuf, eio_wd wd) |
|
|
1368 | { |
|
|
1369 | if (wd == EIO_CWD) |
|
|
1370 | return getcwd (tmpbuf->ptr, PATH_MAX); |
|
|
1371 | |
|
|
1372 | #if HAVE_AT |
|
|
1373 | abort (); /*TODO*/ |
|
|
1374 | #else |
|
|
1375 | strcpy (tmpbuf->ptr, wd); |
|
|
1376 | #endif |
|
|
1377 | return tmpbuf->ptr; |
|
|
1378 | } |
|
|
1379 | |
|
|
1380 | /* result will always end up in tmpbuf, there is always space for adding a 0-byte */ |
1387 | /* result will always end up in tmpbuf, there is always space for adding a 0-byte */ |
1381 | static int |
1388 | static int |
1382 | eio__realpath (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
1389 | eio__realpath (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
1383 | { |
1390 | { |
1384 | const char *rel = path; |
1391 | const char *rel = path; |
… | |
… | |
1388 | int symlinks = SYMLOOP_MAX; |
1395 | int symlinks = SYMLOOP_MAX; |
1389 | #else |
1396 | #else |
1390 | int symlinks = 32; |
1397 | int symlinks = 32; |
1391 | #endif |
1398 | #endif |
1392 | |
1399 | |
1393 | /*D*/ /*TODO: wd ignored */ |
|
|
1394 | |
|
|
1395 | errno = EINVAL; |
1400 | errno = EINVAL; |
1396 | if (!rel) |
1401 | if (!rel) |
1397 | return -1; |
1402 | return -1; |
1398 | |
1403 | |
1399 | errno = ENOENT; |
1404 | errno = ENOENT; |
… | |
… | |
1427 | #endif |
1432 | #endif |
1428 | #endif |
1433 | #endif |
1429 | |
1434 | |
1430 | if (*rel != '/') |
1435 | if (*rel != '/') |
1431 | { |
1436 | { |
1432 | if (!eio__getwd (tmpbuf, wd)) |
1437 | int len; |
|
|
1438 | |
|
|
1439 | errno = ENOENT; |
|
|
1440 | if (wd == EIO_INVALID_WD) |
1433 | return -1; |
1441 | return -1; |
|
|
1442 | |
|
|
1443 | if (wd == EIO_CWD) |
|
|
1444 | { |
|
|
1445 | if (!getcwd (res, PATH_MAX)) |
|
|
1446 | return -1; |
|
|
1447 | |
|
|
1448 | len = strlen (res); |
|
|
1449 | } |
|
|
1450 | else |
|
|
1451 | memcpy (res, wd->str, len = wd->len); |
1434 | |
1452 | |
1435 | if (res [1]) /* only use if not / */ |
1453 | if (res [1]) /* only use if not / */ |
1436 | res += strlen (res); |
1454 | res += len; |
1437 | } |
1455 | } |
1438 | |
1456 | |
1439 | while (*rel) |
1457 | while (*rel) |
1440 | { |
1458 | { |
1441 | eio_ssize_t len, linklen; |
1459 | eio_ssize_t len, linklen; |
… | |
… | |
1469 | } |
1487 | } |
1470 | } |
1488 | } |
1471 | |
1489 | |
1472 | errno = ENAMETOOLONG; |
1490 | errno = ENAMETOOLONG; |
1473 | if (res + 1 + len + 1 >= tmp1) |
1491 | if (res + 1 + len + 1 >= tmp1) |
1474 | return; |
1492 | return -1; |
1475 | |
1493 | |
1476 | /* copy one component */ |
1494 | /* copy one component */ |
1477 | *res = '/'; |
1495 | *res = '/'; |
1478 | memcpy (res + 1, beg, len); |
1496 | memcpy (res + 1, beg, len); |
1479 | |
1497 | |
… | |
… | |
1688 | eio_dent_insertion_sort (dents, size); |
1706 | eio_dent_insertion_sort (dents, size); |
1689 | } |
1707 | } |
1690 | |
1708 | |
1691 | /* read a full directory */ |
1709 | /* read a full directory */ |
1692 | static void |
1710 | static void |
1693 | eio__scandir (eio_req *req) |
1711 | eio__scandir (eio_req *req, etp_worker *self) |
1694 | { |
1712 | { |
1695 | char *name, *names; |
1713 | char *name, *names; |
1696 | int namesalloc = 4096 - sizeof (void *) * 4; |
1714 | int namesalloc = 4096 - sizeof (void *) * 4; |
1697 | int namesoffs = 0; |
1715 | int namesoffs = 0; |
1698 | int flags = req->int1; |
1716 | int flags = req->int1; |
… | |
… | |
1716 | #ifdef _WIN32 |
1734 | #ifdef _WIN32 |
1717 | { |
1735 | { |
1718 | int len = strlen ((const char *)req->ptr1); |
1736 | int len = strlen ((const char *)req->ptr1); |
1719 | char *path = malloc (MAX_PATH); |
1737 | char *path = malloc (MAX_PATH); |
1720 | const char *fmt; |
1738 | const char *fmt; |
|
|
1739 | const char *reqpath = wd_expand (&self->tmpbuf, req->wd, req->ptr1); |
1721 | |
1740 | |
1722 | if (!len) |
1741 | if (!len) |
1723 | fmt = "./*"; |
1742 | fmt = "./*"; |
1724 | else if (((const char *)req->ptr1)[len - 1] == '/' || ((const char *)req->ptr1)[len - 1] == '\\') |
1743 | else if (reqpath[len - 1] == '/' || reqpath[len - 1] == '\\') |
1725 | fmt = "%s*"; |
1744 | fmt = "%s*"; |
1726 | else |
1745 | else |
1727 | fmt = "%s/*"; |
1746 | fmt = "%s/*"; |
1728 | |
1747 | |
1729 | _snprintf (path, MAX_PATH, fmt, (const char *)req->ptr1); |
1748 | _snprintf (path, MAX_PATH, fmt, reqpath); |
1730 | dirp = FindFirstFile (path, &entp); |
1749 | dirp = FindFirstFile (path, &entp); |
1731 | free (path); |
1750 | free (path); |
1732 | |
1751 | |
1733 | if (dirp == INVALID_HANDLE_VALUE) |
1752 | if (dirp == INVALID_HANDLE_VALUE) |
1734 | { |
1753 | { |
… | |
… | |
1756 | |
1775 | |
1757 | return; |
1776 | return; |
1758 | } |
1777 | } |
1759 | } |
1778 | } |
1760 | #else |
1779 | #else |
|
|
1780 | #if HAVE_AT |
|
|
1781 | if (req->wd) |
|
|
1782 | { |
|
|
1783 | int fd = openat (WD2FD (req->wd), req->ptr1, O_CLOEXEC | O_SEARCH | O_DIRECTORY); |
|
|
1784 | |
|
|
1785 | if (fd < 0) |
|
|
1786 | return; |
|
|
1787 | |
|
|
1788 | dirp = fdopendir (fd); |
|
|
1789 | |
|
|
1790 | if (!dirp) |
|
|
1791 | close (fd); |
|
|
1792 | } |
|
|
1793 | else |
1761 | dirp = opendir (req->ptr1); |
1794 | dirp = opendir (req->ptr1); |
|
|
1795 | #else |
|
|
1796 | dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); |
|
|
1797 | #endif |
1762 | |
1798 | |
1763 | if (!dirp) |
1799 | if (!dirp) |
1764 | return; |
1800 | return; |
1765 | #endif |
1801 | #endif |
1766 | |
1802 | |
… | |
… | |
1930 | { |
1966 | { |
1931 | if (ent->type == EIO_DT_UNKNOWN) |
1967 | if (ent->type == EIO_DT_UNKNOWN) |
1932 | { |
1968 | { |
1933 | if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ |
1969 | if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ |
1934 | ent->score = 1; |
1970 | ent->score = 1; |
1935 | else if (!strchr (name, '.')) /* absense of dots indicate likely dirs */ |
1971 | else if (!strchr (name, '.')) /* absence of dots indicate likely dirs */ |
1936 | ent->score = len <= 2 ? 4 - len : len <= 4 ? 4 : len <= 7 ? 5 : 6; /* shorter == more likely dir, but avoid too many classes */ |
1972 | ent->score = len <= 2 ? 4 - len : len <= 4 ? 4 : len <= 7 ? 5 : 6; /* shorter == more likely dir, but avoid too many classes */ |
1937 | } |
1973 | } |
1938 | else if (ent->type == EIO_DT_DIR) |
1974 | else if (ent->type == EIO_DT_DIR) |
1939 | ent->score = 0; |
1975 | ent->score = 0; |
1940 | } |
1976 | } |
… | |
… | |
1960 | } |
1996 | } |
1961 | } |
1997 | } |
1962 | |
1998 | |
1963 | /*****************************************************************************/ |
1999 | /*****************************************************************************/ |
1964 | /* working directory stuff */ |
2000 | /* working directory stuff */ |
|
|
2001 | /* various deficiencies in the posix 2008 api force us to */ |
|
|
2002 | /* keep the absolute path in string form at all times */ |
|
|
2003 | /* fuck yeah. */ |
1965 | |
2004 | |
1966 | #if HAVE_AT |
2005 | #if !HAVE_AT |
1967 | |
2006 | |
1968 | #define WD2FD(wd) (wd ? ((int)wd) - 1 : AT_FDCWD) |
2007 | /* a bit like realpath, but usually faster because it doesn'T have to return */ |
1969 | |
2008 | /* an absolute or canonical path */ |
1970 | eio_wd |
|
|
1971 | eio_wd_open_sync (eio_wd wd, const char *path) |
|
|
1972 | { |
|
|
1973 | int fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY); |
|
|
1974 | |
|
|
1975 | return fd >= 0 ? (eio_wd)(fd + 1) : EIO_INVALID_WD; |
|
|
1976 | } |
|
|
1977 | |
|
|
1978 | void |
|
|
1979 | eio_wd_close_sync (eio_wd wd) |
|
|
1980 | { |
|
|
1981 | int fd = WD2FD (wd); |
|
|
1982 | |
|
|
1983 | if (fd >= 0) |
|
|
1984 | close (fd); |
|
|
1985 | } |
|
|
1986 | |
|
|
1987 | #else |
|
|
1988 | |
|
|
1989 | /* on legacy systems, we represent the working directories simply by their path strings */ |
|
|
1990 | |
|
|
1991 | static const char * |
2009 | static const char * |
1992 | wd_expand (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
2010 | wd_expand (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
1993 | { |
2011 | { |
1994 | if (!wd || *path == '/') |
2012 | if (!wd || *path == '/') |
1995 | return path; |
2013 | return path; |
1996 | |
2014 | |
|
|
2015 | if (path [0] == '.' && !path [1]) |
|
|
2016 | return wd->str; |
|
|
2017 | |
1997 | { |
2018 | { |
1998 | int l1 = strlen ((const char *)wd); |
2019 | int l1 = wd->len; |
1999 | int l2 = strlen (path); |
2020 | int l2 = strlen (path); |
2000 | |
2021 | |
2001 | char *res = tmpbuf_get (tmpbuf, l1 + l2 + 2); |
2022 | char *res = tmpbuf_get (tmpbuf, l1 + l2 + 2); |
2002 | |
2023 | |
2003 | memcpy (res, wd, l1); |
2024 | memcpy (res, wd->str, l1); |
2004 | res [l1] = '/'; |
2025 | res [l1] = '/'; |
2005 | memcpy (res + l1 + 1, path, l2 + 1); |
2026 | memcpy (res + l1 + 1, path, l2 + 1); |
2006 | |
2027 | |
2007 | return res; |
2028 | return res; |
2008 | } |
2029 | } |
2009 | } |
2030 | } |
2010 | |
2031 | |
2011 | eio_wd |
2032 | #endif |
|
|
2033 | |
|
|
2034 | static eio_wd |
2012 | eio__wd_open_sync (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
2035 | eio__wd_open_sync (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
2013 | { |
2036 | { |
2014 | if (*path == '/') /* absolute paths ignore wd */ |
2037 | int fd; |
2015 | path = strdup (path); |
2038 | eio_wd res; |
2016 | else if (path [0] == '.' && !path [1]) /* special case '.', as it is common */ |
|
|
2017 | return wd; |
|
|
2018 | else |
|
|
2019 | { |
|
|
2020 | int len = eio__realpath (tmpbuf, wd, path); |
2039 | int len = eio__realpath (tmpbuf, wd, path); |
2021 | |
2040 | |
2022 | path = EIO_INVALID_WD; |
|
|
2023 | |
|
|
2024 | if (len >= 0) |
2041 | if (len < 0) |
2025 | { |
|
|
2026 | ((char *)tmpbuf->ptr)[len] = 0; |
|
|
2027 | path = strdup (tmpbuf->ptr); |
|
|
2028 | } |
|
|
2029 | } |
|
|
2030 | |
|
|
2031 | if (!path) |
|
|
2032 | path = EIO_INVALID_WD; |
2042 | return EIO_INVALID_WD; |
2033 | |
2043 | |
2034 | return (eio_wd)path; |
2044 | #if HAVE_AT |
|
|
2045 | fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY); |
|
|
2046 | |
|
|
2047 | if (fd < 0) |
|
|
2048 | return EIO_INVALID_WD; |
|
|
2049 | #endif |
|
|
2050 | |
|
|
2051 | res = malloc (sizeof (*res) + len); /* one extra 0-byte */ |
|
|
2052 | |
|
|
2053 | #if HAVE_AT |
|
|
2054 | res->fd = fd; |
|
|
2055 | #endif |
|
|
2056 | |
|
|
2057 | res->len = len; |
|
|
2058 | memcpy (res->str, tmpbuf->ptr, len); |
|
|
2059 | res->str [len] = 0; |
|
|
2060 | |
|
|
2061 | return res; |
2035 | } |
2062 | } |
2036 | |
2063 | |
2037 | eio_wd |
2064 | eio_wd |
2038 | eio_wd_open_sync (eio_wd wd, const char *path) |
2065 | eio_wd_open_sync (eio_wd wd, const char *path) |
2039 | { |
2066 | { |
… | |
… | |
2045 | } |
2072 | } |
2046 | |
2073 | |
2047 | void |
2074 | void |
2048 | eio_wd_close_sync (eio_wd wd) |
2075 | eio_wd_close_sync (eio_wd wd) |
2049 | { |
2076 | { |
2050 | if (wd != EIO_INVALID_WD) |
2077 | if (wd != EIO_INVALID_WD && wd != EIO_CWD) |
|
|
2078 | { |
|
|
2079 | #if HAVE_AT |
|
|
2080 | close (wd->fd); |
|
|
2081 | #endif |
2051 | free (wd); |
2082 | free (wd); |
|
|
2083 | } |
|
|
2084 | } |
|
|
2085 | |
|
|
2086 | #if HAVE_AT |
|
|
2087 | |
|
|
2088 | /* they forgot these */ |
|
|
2089 | |
|
|
2090 | static int |
|
|
2091 | eio__truncateat (int dirfd, const char *path, off_t length) |
|
|
2092 | { |
|
|
2093 | int fd = openat (dirfd, path, O_WRONLY | O_CLOEXEC); |
|
|
2094 | int res; |
|
|
2095 | |
|
|
2096 | if (fd < 0) |
|
|
2097 | return fd; |
|
|
2098 | |
|
|
2099 | res = ftruncate (fd, length); |
|
|
2100 | close (fd); |
|
|
2101 | return res; |
|
|
2102 | } |
|
|
2103 | |
|
|
2104 | static int |
|
|
2105 | eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) |
|
|
2106 | { |
|
|
2107 | int fd = openat (dirfd, path, O_SEARCH | O_CLOEXEC); |
|
|
2108 | int res; |
|
|
2109 | |
|
|
2110 | if (fd < 0) |
|
|
2111 | return fd; |
|
|
2112 | |
|
|
2113 | res = fstatvfs (fd, buf); |
|
|
2114 | close (fd); |
|
|
2115 | return res; |
|
|
2116 | |
2052 | } |
2117 | } |
2053 | |
2118 | |
2054 | #endif |
2119 | #endif |
2055 | |
2120 | |
2056 | /*****************************************************************************/ |
2121 | /*****************************************************************************/ |
… | |
… | |
2068 | req->result = -1; \ |
2133 | req->result = -1; \ |
2069 | break; \ |
2134 | break; \ |
2070 | } \ |
2135 | } \ |
2071 | } |
2136 | } |
2072 | |
2137 | |
|
|
2138 | static void ecb_noinline ecb_cold |
|
|
2139 | etp_proc_init (void) |
|
|
2140 | { |
|
|
2141 | #if HAVE_PRCTL_SET_NAME |
|
|
2142 | /* provide a more sensible "thread name" */ |
|
|
2143 | char name[16 + 1]; |
|
|
2144 | const int namelen = sizeof (name) - 1; |
|
|
2145 | int len; |
|
|
2146 | |
|
|
2147 | prctl (PR_GET_NAME, (unsigned long)name, 0, 0, 0); |
|
|
2148 | name [namelen] = 0; |
|
|
2149 | len = strlen (name); |
|
|
2150 | strcpy (name + (len <= namelen - 4 ? len : namelen - 4), "/eio"); |
|
|
2151 | prctl (PR_SET_NAME, (unsigned long)name, 0, 0, 0); |
|
|
2152 | #endif |
|
|
2153 | } |
|
|
2154 | |
2073 | X_THREAD_PROC (etp_proc) |
2155 | X_THREAD_PROC (etp_proc) |
2074 | { |
2156 | { |
2075 | ETP_REQ *req; |
2157 | ETP_REQ *req; |
2076 | struct timespec ts; |
2158 | struct timespec ts; |
2077 | etp_worker *self = (etp_worker *)thr_arg; |
2159 | etp_worker *self = (etp_worker *)thr_arg; |
2078 | |
2160 | |
2079 | #if HAVE_PRCTL_SET_NAME |
2161 | etp_proc_init (); |
2080 | prctl (PR_SET_NAME, (unsigned long)"eio_thread", 0, 0, 0); |
|
|
2081 | #endif |
|
|
2082 | |
2162 | |
2083 | /* try to distribute timeouts somewhat evenly */ |
2163 | /* try to distribute timeouts somewhat evenly */ |
2084 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
2164 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
2085 | |
2165 | |
2086 | for (;;) |
2166 | for (;;) |
… | |
… | |
2231 | switch (req->type) |
2311 | switch (req->type) |
2232 | { |
2312 | { |
2233 | case EIO_WD_OPEN: req->wd = eio__wd_open_sync (&self->tmpbuf, req->wd, req->ptr1); |
2313 | case EIO_WD_OPEN: req->wd = eio__wd_open_sync (&self->tmpbuf, req->wd, req->ptr1); |
2234 | req->result = req->wd == EIO_INVALID_WD ? -1 : 0; |
2314 | req->result = req->wd == EIO_INVALID_WD ? -1 : 0; |
2235 | break; |
2315 | break; |
2236 | case EIO_WD_CLOSE: eio_wd_close_sync (req->wd); break; |
2316 | case EIO_WD_CLOSE: req->result = 0; |
|
|
2317 | eio_wd_close_sync (req->wd); break; |
2237 | |
2318 | |
2238 | case EIO_READ: ALLOC (req->size); |
2319 | case EIO_READ: ALLOC (req->size); |
2239 | req->result = req->offs >= 0 |
2320 | req->result = req->offs >= 0 |
2240 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
2321 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
2241 | : read (req->int1, req->ptr2, req->size); break; |
2322 | : read (req->int1, req->ptr2, req->size); break; |
… | |
… | |
2245 | |
2326 | |
2246 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
2327 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
2247 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; |
2328 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; |
2248 | |
2329 | |
2249 | #if HAVE_AT |
2330 | #if HAVE_AT |
2250 | case EIO_GETPATH: abort (); |
2331 | |
2251 | case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2332 | case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2252 | req->result = fstatat (dirfd, path, (EIO_STRUCT_STAT *)req->ptr2); break; |
2333 | req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, 0); break; |
2253 | case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2334 | case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2254 | req->result = lstat (dirfd, path, (EIO_STRUCT_STAT *)req->ptr2); break; |
2335 | req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; |
2255 | #if 0/*D*/ |
2336 | case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break; |
|
|
2337 | case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break; |
|
|
2338 | case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break; |
|
|
2339 | case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break; |
|
|
2340 | |
|
|
2341 | case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; |
|
|
2342 | case EIO_RMDIR: req->result = unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; |
|
|
2343 | case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; |
|
|
2344 | case EIO_RENAME: req->result = renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; |
|
|
2345 | case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; |
|
|
2346 | case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; |
|
|
2347 | case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; |
|
|
2348 | case EIO_READLINK: ALLOC (PATH_MAX); |
|
|
2349 | req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break; |
2256 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
2350 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
2257 | req->result = statvfs (dirfd, path, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
2351 | req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
2258 | #endif |
2352 | case EIO_UTIME: |
2259 | case EIO_CHOWN: req->result = chown (dirfd, path, req->int2, req->int3); break; |
2353 | case EIO_FUTIME: |
2260 | case EIO_CHMOD: req->result = chmod (dirfd, path, (mode_t)req->int2); break; |
2354 | { |
2261 | case EIO_TRUNCATE: req->result = truncate (dirfd, path, req->offs); break; |
2355 | struct timespec ts[2]; |
2262 | case EIO_OPEN: req->result = open (dirfd, path, req->int1, (mode_t)req->int2); break; |
2356 | struct timespec *times; |
2263 | |
2357 | |
2264 | case EIO_UNLINK: req->result = unlink (dirfd, path); break; |
2358 | if (req->nv1 != -1. || req->nv2 != -1.) |
2265 | case EIO_RMDIR: req->result = rmdir (dirfd, path); break; |
2359 | { |
2266 | case EIO_MKDIR: req->result = mkdir (dirfd, path, (mode_t)req->int2); break; |
2360 | ts[0].tv_sec = req->nv1; |
2267 | case EIO_RENAME: req->result = rename (dirfd, path, req->ptr2); break; |
2361 | ts[0].tv_nsec = (req->nv1 - ts[0].tv_sec) * 1e9; |
2268 | case EIO_LINK: req->result = link (dirfd, path, req->ptr2); break; |
2362 | ts[1].tv_sec = req->nv2; |
2269 | case EIO_SYMLINK: req->result = symlink (dirfd, path, req->ptr2); break; |
2363 | ts[1].tv_nsec = (req->nv2 - ts[1].tv_sec) * 1e9; |
2270 | case EIO_MKNOD: req->result = mknod (dirfd, path, (mode_t)req->int2, (dev_t)req->offs); break; |
2364 | |
|
|
2365 | times = ts; |
|
|
2366 | } |
|
|
2367 | else |
|
|
2368 | times = 0; |
|
|
2369 | |
|
|
2370 | req->result = req->type == EIO_FUTIME |
|
|
2371 | ? futimens (req->int1, times) |
|
|
2372 | : utimensat (dirfd, req->ptr1, times, 0); |
|
|
2373 | } |
|
|
2374 | break; |
|
|
2375 | |
2271 | #else |
2376 | #else |
|
|
2377 | |
2272 | case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2378 | case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2273 | req->result = stat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
2379 | req->result = stat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
2274 | case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2380 | case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2275 | req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
2381 | req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
2276 | case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; |
2382 | case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; |
… | |
… | |
2283 | case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; |
2389 | case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; |
2284 | case EIO_RENAME: req->result = rename (path , req->ptr2); break; |
2390 | case EIO_RENAME: req->result = rename (path , req->ptr2); break; |
2285 | case EIO_LINK: req->result = link (path , req->ptr2); break; |
2391 | case EIO_LINK: req->result = link (path , req->ptr2); break; |
2286 | case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; |
2392 | case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; |
2287 | case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; |
2393 | case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; |
2288 | |
|
|
2289 | case EIO_READLINK: ALLOC (PATH_MAX); |
2394 | case EIO_READLINK: ALLOC (PATH_MAX); |
2290 | req->result = readlink (path, req->ptr2, PATH_MAX); break; |
2395 | req->result = readlink (path, req->ptr2, PATH_MAX); break; |
|
|
2396 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
|
|
2397 | req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; |
|
|
2398 | |
|
|
2399 | case EIO_UTIME: |
|
|
2400 | case EIO_FUTIME: |
|
|
2401 | { |
|
|
2402 | struct timeval tv[2]; |
|
|
2403 | struct timeval *times; |
|
|
2404 | |
|
|
2405 | if (req->nv1 != -1. || req->nv2 != -1.) |
|
|
2406 | { |
|
|
2407 | tv[0].tv_sec = req->nv1; |
|
|
2408 | tv[0].tv_usec = (req->nv1 - tv[0].tv_sec) * 1e6; |
|
|
2409 | tv[1].tv_sec = req->nv2; |
|
|
2410 | tv[1].tv_usec = (req->nv2 - tv[1].tv_sec) * 1e6; |
|
|
2411 | |
|
|
2412 | times = tv; |
|
|
2413 | } |
|
|
2414 | else |
|
|
2415 | times = 0; |
|
|
2416 | |
|
|
2417 | req->result = req->type == EIO_FUTIME |
|
|
2418 | ? futimes (req->int1, times) |
|
|
2419 | : utimes (req->ptr1, times); |
|
|
2420 | } |
|
|
2421 | break; |
|
|
2422 | |
2291 | #endif |
2423 | #endif |
2292 | |
2424 | |
2293 | case EIO_REALPATH: if (0 <= (req->result = eio__realpath (&self->tmpbuf, req->wd, req->ptr1))) |
2425 | case EIO_REALPATH: if (0 <= (req->result = eio__realpath (&self->tmpbuf, req->wd, req->ptr1))) |
2294 | { |
2426 | { |
2295 | ALLOC (req->result); |
2427 | ALLOC (req->result); |
2296 | memcpy (req->ptr2, self->tmpbuf.ptr, req->result); |
2428 | memcpy (req->ptr2, self->tmpbuf.ptr, req->result); |
2297 | } |
2429 | } |
2298 | break; |
2430 | break; |
2299 | |
|
|
2300 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); /*D*/ |
|
|
2301 | req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; |
|
|
2302 | |
2431 | |
2303 | case EIO_FSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2432 | case EIO_FSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2304 | req->result = fstat (req->int1, (EIO_STRUCT_STAT *)req->ptr2); break; |
2433 | req->result = fstat (req->int1, (EIO_STRUCT_STAT *)req->ptr2); break; |
2305 | |
2434 | |
2306 | case EIO_FSTATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
2435 | case EIO_FSTATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
… | |
… | |
2321 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
2450 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
2322 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
2451 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
2323 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
2452 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
2324 | case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; |
2453 | case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; |
2325 | |
2454 | |
2326 | case EIO_READDIR: eio__scandir (req); break; |
2455 | case EIO_READDIR: eio__scandir (req, self); break; |
2327 | |
2456 | |
2328 | case EIO_BUSY: |
2457 | case EIO_BUSY: |
2329 | #ifdef _WIN32 |
2458 | #ifdef _WIN32 |
2330 | Sleep (req->nv1 * 1e3); |
2459 | Sleep (req->nv1 * 1e3); |
2331 | #else |
2460 | #else |
… | |
… | |
2338 | req->result = select (0, 0, 0, 0, &tv); |
2467 | req->result = select (0, 0, 0, 0, &tv); |
2339 | } |
2468 | } |
2340 | #endif |
2469 | #endif |
2341 | break; |
2470 | break; |
2342 | |
2471 | |
2343 | case EIO_UTIME: |
|
|
2344 | case EIO_FUTIME: |
|
|
2345 | { |
|
|
2346 | struct timeval tv[2]; |
|
|
2347 | struct timeval *times; |
|
|
2348 | |
|
|
2349 | if (req->nv1 != -1. || req->nv2 != -1.) |
|
|
2350 | { |
|
|
2351 | tv[0].tv_sec = req->nv1; |
|
|
2352 | tv[0].tv_usec = (req->nv1 - tv[0].tv_sec) * 1000000.; |
|
|
2353 | tv[1].tv_sec = req->nv2; |
|
|
2354 | tv[1].tv_usec = (req->nv2 - tv[1].tv_sec) * 1000000.; |
|
|
2355 | |
|
|
2356 | times = tv; |
|
|
2357 | } |
|
|
2358 | else |
|
|
2359 | times = 0; |
|
|
2360 | |
|
|
2361 | req->result = req->type == EIO_FUTIME |
|
|
2362 | ? futimes (req->int1, times) |
|
|
2363 | : utimes (req->ptr1, times); |
|
|
2364 | } |
|
|
2365 | break; |
|
|
2366 | |
|
|
2367 | case EIO_GROUP: |
2472 | case EIO_GROUP: |
2368 | abort (); /* handled in eio_request */ |
2473 | abort (); /* handled in eio_request */ |
2369 | |
2474 | |
2370 | case EIO_NOP: |
2475 | case EIO_NOP: |
2371 | req->result = 0; |
2476 | req->result = 0; |
… | |
… | |
2383 | |
2488 | |
2384 | req->errorno = errno; |
2489 | req->errorno = errno; |
2385 | } |
2490 | } |
2386 | |
2491 | |
2387 | #ifndef EIO_NO_WRAPPERS |
2492 | #ifndef EIO_NO_WRAPPERS |
|
|
2493 | |
|
|
2494 | eio_req *eio_wd_open (const char *path, int pri, eio_cb cb, void *data) |
|
|
2495 | { |
|
|
2496 | REQ (EIO_WD_OPEN); PATH; SEND; |
|
|
2497 | } |
|
|
2498 | |
|
|
2499 | eio_req *eio_wd_close (eio_wd wd, int pri, eio_cb cb, void *data) |
|
|
2500 | { |
|
|
2501 | REQ (EIO_WD_CLOSE); req->wd = wd; SEND; |
|
|
2502 | } |
2388 | |
2503 | |
2389 | eio_req *eio_nop (int pri, eio_cb cb, void *data) |
2504 | eio_req *eio_nop (int pri, eio_cb cb, void *data) |
2390 | { |
2505 | { |
2391 | REQ (EIO_NOP); SEND; |
2506 | REQ (EIO_NOP); SEND; |
2392 | } |
2507 | } |