ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/eio.c
(Generate patch)

Comparing libeio/eio.c (file contents):
Revision 1.143 by root, Sat Dec 3 16:33:46 2016 UTC vs.
Revision 1.155 by root, Fri Aug 17 17:31:43 2018 UTC

1/* 1/*
2 * libeio implementation 2 * libeio implementation
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2016 Marc Alexander Lehmann <libeio@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2016,2017,2018 Marc Alexander Lehmann <libeio@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
231 #define D_NAME(entp) entp.cFileName 231 #define D_NAME(entp) entp.cFileName
232 #define D_TYPE(entp) (entp.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? DT_DIR : DT_REG) 232 #define D_TYPE(entp) (entp.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? DT_DIR : DT_REG)
233 233
234#else 234#else
235 235
236 #include <sys/ioctl.h>
236 #include <sys/time.h> 237 #include <sys/time.h>
237 #include <sys/select.h> 238 #include <sys/select.h>
238 #include <unistd.h> 239 #include <unistd.h>
239 #include <signal.h> 240 #include <signal.h>
240 #include <dirent.h> 241 #include <dirent.h>
299# else 300# else
300# error sendfile support requested but not available 301# error sendfile support requested but not available
301# endif 302# endif
302#endif 303#endif
303 304
305#if HAVE_RENAMEAT2
306# include <sys/syscall.h>
307# include <linux/fs.h>
308#endif
309
304#ifndef D_TYPE 310#ifndef D_TYPE
305# define D_TYPE(de) 0 311# define D_TYPE(de) 0
306#endif 312#endif
307#ifndef D_INO 313#ifndef D_INO
308# define D_INO(de) 0 314# define D_INO(de) 0
316# define NAME_MAX 4096 322# define NAME_MAX 4096
317#endif 323#endif
318 324
319/* used for readlink etc. */ 325/* used for readlink etc. */
320#ifndef PATH_MAX 326#ifndef PATH_MAX
321# define PATH_MAX 4096 327# define PATH_MAX 0
322#endif 328#endif
329
330#ifndef O_CLOEXEC
331 #define O_CLOEXEC 0
332#endif
333
334#ifndef O_NONBLOCK
335 #define O_NONBLOCK 0
336#endif
337
338#ifndef O_SEARCH
339 #define O_SEARCH O_RDONLY
340#endif
341
342#ifndef O_DIRECTORY
343 #define O_DIRECTORY 0
344#endif
345
346#ifndef EIO_PATH_MIN
347# define EIO_PATH_MIN 8160
348#endif
349
350#define EIO_PATH_MAX (PATH_MAX <= EIO_PATH_MIN ? EIO_PATH_MIN : PATH_MAX)
323 351
324/* buffer size for various temporary buffers */ 352/* buffer size for various temporary buffers */
325#define EIO_BUFSIZE 65536 353#define EIO_BUFSIZE 65536
326 354
327#define dBUF \ 355#define dBUF \
338struct etp_tmpbuf; 366struct etp_tmpbuf;
339 367
340#if _POSIX_VERSION >= 200809L 368#if _POSIX_VERSION >= 200809L
341 #define HAVE_AT 1 369 #define HAVE_AT 1
342 #define WD2FD(wd) ((wd) ? (wd)->fd : AT_FDCWD) 370 #define WD2FD(wd) ((wd) ? (wd)->fd : AT_FDCWD)
343 #ifndef O_SEARCH
344 #define O_SEARCH O_RDONLY
345 #endif
346#else 371#else
347 #define HAVE_AT 0 372 #define HAVE_AT 0
348 static const char *wd_expand (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path); 373 static const char *wd_expand (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path);
349#endif 374#endif
350 375
540 return etp_poll (EIO_POOL); 565 return etp_poll (EIO_POOL);
541} 566}
542 567
543/*****************************************************************************/ 568/*****************************************************************************/
544/* work around various missing functions */ 569/* work around various missing functions */
570
571#if HAVE_POSIX_CLOSE && !__linux
572# define eio__close(fd) posix_close (fd, 0)
573#else
574# define eio__close(fd) close (fd)
575#endif
576
577/* close() without disturbing errno */
578static void
579silent_close (int fd)
580{
581 int saved_errno = errno;
582 eio__close (fd);
583 errno = saved_errno;
584}
545 585
546#ifndef HAVE_UTIMES 586#ifndef HAVE_UTIMES
547 587
548# undef utimes 588# undef utimes
549# define utimes(path,times) eio__utimes (path, times) 589# define utimes(path,times) eio__utimes (path, times)
928 intptr_t end = addr + len; 968 intptr_t end = addr + len;
929 intptr_t page = eio_pagesize (); 969 intptr_t page = eio_pagesize ();
930 970
931 if (addr < end) 971 if (addr < end)
932 if (flags & EIO_MT_MODIFY) /* modify */ 972 if (flags & EIO_MT_MODIFY) /* modify */
933 do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req)); 973 do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < end && !EIO_CANCELLED (req));
934 else 974 else
935 do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req)); 975 do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < end && !EIO_CANCELLED (req));
936 } 976 }
937 977
938 return 0; 978 return 0;
939} 979}
940 980
974 1014
975 errno = ENOENT; 1015 errno = ENOENT;
976 if (!*rel) 1016 if (!*rel)
977 return -1; 1017 return -1;
978 1018
979 res = etp_tmpbuf_get (tmpbuf, PATH_MAX * 3); 1019 res = etp_tmpbuf_get (tmpbuf, EIO_PATH_MAX * 3);
980#ifdef _WIN32 1020#ifdef _WIN32
981 if (_access (rel, 4) != 0) 1021 if (_access (rel, 4) != 0)
982 return -1; 1022 return -1;
983 1023
984 symlinks = GetFullPathName (rel, PATH_MAX * 3, res, 0); 1024 symlinks = GetFullPathName (rel, EIO_PATH_MAX * 3, res, 0);
985 1025
986 errno = ENAMETOOLONG; 1026 errno = ENAMETOOLONG;
987 if (symlinks >= PATH_MAX * 3) 1027 if (symlinks >= EIO_PATH_MAX * 3)
988 return -1; 1028 return -1;
989 1029
990 errno = EIO; 1030 errno = EIO;
991 if (symlinks <= 0) 1031 if (symlinks <= 0)
992 return -1; 1032 return -1;
993 1033
994 return symlinks; 1034 return symlinks;
995 1035
996#else 1036#else
997 tmp1 = res + PATH_MAX; 1037 tmp1 = res + EIO_PATH_MAX;
998 tmp2 = tmp1 + PATH_MAX; 1038 tmp2 = tmp1 + EIO_PATH_MAX;
999 1039
1000#if 0 /* disabled, the musl way to do things is just too racy */ 1040#if 0 /* disabled, the musl way to do things is just too racy */
1001#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) 1041#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME)
1002 /* on linux we may be able to ask the kernel */ 1042 /* on linux we may be able to ask the kernel */
1003 { 1043 {
1004 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME); 1044 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME);
1005 1045
1006 if (fd >= 0) 1046 if (fd >= 0)
1007 { 1047 {
1008 sprintf (tmp1, "/proc/self/fd/%d", fd); 1048 sprintf (tmp1, "/proc/self/fd/%d", fd);
1009 req->result = readlink (tmp1, res, PATH_MAX); 1049 req->result = readlink (tmp1, res, EIO_PATH_MAX);
1010 /* here we should probably stat the open file and the disk file, to make sure they still match */ 1050 /* here we should probably stat the open file and the disk file, to make sure they still match */
1011 close (fd); 1051 eio__close (fd);
1012 1052
1013 if (req->result > 0) 1053 if (req->result > 0)
1014 goto done; 1054 goto done;
1015 } 1055 }
1016 else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO) 1056 else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO)
1027 if (wd == EIO_INVALID_WD) 1067 if (wd == EIO_INVALID_WD)
1028 return -1; 1068 return -1;
1029 1069
1030 if (wd == EIO_CWD) 1070 if (wd == EIO_CWD)
1031 { 1071 {
1032 if (!getcwd (res, PATH_MAX)) 1072 if (!getcwd (res, EIO_PATH_MAX))
1033 return -1; 1073 return -1;
1034 1074
1035 len = strlen (res); 1075 len = strlen (res);
1036 } 1076 }
1037 else 1077 else
1084 1124
1085 /* zero-terminate, for readlink */ 1125 /* zero-terminate, for readlink */
1086 res [len + 1] = 0; 1126 res [len + 1] = 0;
1087 1127
1088 /* now check if it's a symlink */ 1128 /* now check if it's a symlink */
1089 linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); 1129 linklen = readlink (tmpbuf->ptr, tmp1, EIO_PATH_MAX);
1090 1130
1091 if (linklen < 0) 1131 if (linklen < 0)
1092 { 1132 {
1093 if (errno != EINVAL) 1133 if (errno != EINVAL)
1094 return -1; 1134 return -1;
1100 { 1140 {
1101 /* yay, it was a symlink - build new path in tmp2 */ 1141 /* yay, it was a symlink - build new path in tmp2 */
1102 int rellen = strlen (rel); 1142 int rellen = strlen (rel);
1103 1143
1104 errno = ENAMETOOLONG; 1144 errno = ENAMETOOLONG;
1105 if (linklen + 1 + rellen >= PATH_MAX) 1145 if (linklen + 1 + rellen >= EIO_PATH_MAX) /* also catch linklen >= EIO_PATH_MAX */
1106 return -1; 1146 return -1;
1107 1147
1108 errno = ELOOP; 1148 errno = ELOOP;
1109 if (!--symlinks) 1149 if (!--symlinks)
1110 return -1; 1150 return -1;
1364 return; 1404 return;
1365 } 1405 }
1366 } 1406 }
1367#else 1407#else
1368 #if HAVE_AT 1408 #if HAVE_AT
1369 if (req->wd)
1370 { 1409 {
1371 int fd = openat (WD2FD (req->wd), req->ptr1, O_CLOEXEC | O_SEARCH | O_DIRECTORY); 1410 int fd = openat (WD2FD (req->wd), req->ptr1, O_CLOEXEC | O_SEARCH | O_DIRECTORY | O_NONBLOCK);
1372 1411
1373 if (fd < 0) 1412 if (fd < 0)
1413 return;
1414
1415 dirp = fdopendir (fd);
1416
1417 if (!dirp)
1418 {
1419 silent_close (fd);
1374 return; 1420 return;
1375
1376 dirp = fdopendir (fd);
1377
1378 if (!dirp)
1379 close (fd);
1380 } 1421 }
1381 else 1422 }
1382 dirp = opendir (req->ptr1);
1383 #else 1423 #else
1384 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); 1424 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1));
1425
1426 if (!dirp)
1427 return;
1385 #endif 1428 #endif
1386
1387 if (!dirp)
1388 return;
1389#endif 1429#endif
1390 1430
1391 if (req->flags & EIO_FLAG_PTR1_FREE) 1431 if (req->flags & EIO_FLAG_PTR1_FREE)
1392 free (req->ptr1); 1432 free (req->ptr1);
1393 1433
1628 1668
1629 if (len < 0) 1669 if (len < 0)
1630 return EIO_INVALID_WD; 1670 return EIO_INVALID_WD;
1631 1671
1632#if HAVE_AT 1672#if HAVE_AT
1633 fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY); 1673 fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY | O_NONBLOCK);
1634 1674
1635 if (fd < 0) 1675 if (fd < 0)
1636 return EIO_INVALID_WD; 1676 return EIO_INVALID_WD;
1637#endif 1677#endif
1638 1678
1650} 1690}
1651 1691
1652eio_wd 1692eio_wd
1653eio_wd_open_sync (eio_wd wd, const char *path) 1693eio_wd_open_sync (eio_wd wd, const char *path)
1654{ 1694{
1655 struct etp_tmpbuf tmpbuf = { }; 1695 struct etp_tmpbuf tmpbuf = { 0 };
1656 wd = eio__wd_open_sync (&tmpbuf, wd, path); 1696 wd = eio__wd_open_sync (&tmpbuf, wd, path);
1657 free (tmpbuf.ptr); 1697 free (tmpbuf.ptr);
1658 1698
1659 return wd; 1699 return wd;
1660} 1700}
1663eio_wd_close_sync (eio_wd wd) 1703eio_wd_close_sync (eio_wd wd)
1664{ 1704{
1665 if (wd != EIO_INVALID_WD && wd != EIO_CWD) 1705 if (wd != EIO_INVALID_WD && wd != EIO_CWD)
1666 { 1706 {
1667 #if HAVE_AT 1707 #if HAVE_AT
1668 close (wd->fd); 1708 eio__close (wd->fd);
1669 #endif 1709 #endif
1670 free (wd); 1710 free (wd);
1671 } 1711 }
1672} 1712}
1673 1713
1674#if HAVE_AT 1714#if HAVE_AT
1675 1715
1716static int
1717eio__renameat2 (int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags)
1718{
1719#if HAVE_RENAMEAT2
1720 return syscall (SYS_renameat2, olddirfd, oldpath, newdirfd, newpath, flags);
1721#else
1722 if (flags)
1723 return EIO_ENOSYS ();
1724
1725 return renameat (olddirfd, oldpath, newdirfd, newpath);
1726#endif
1727}
1728
1676/* they forgot these */ 1729/* they forgot these */
1677 1730
1678static int 1731static int
1679eio__truncateat (int dirfd, const char *path, off_t length) 1732eio__truncateat (int dirfd, const char *path, off_t length)
1680{ 1733{
1681 int fd = openat (dirfd, path, O_WRONLY | O_CLOEXEC); 1734 int fd = openat (dirfd, path, O_WRONLY | O_CLOEXEC | O_NONBLOCK);
1682 int res; 1735 int res;
1683 1736
1684 if (fd < 0) 1737 if (fd < 0)
1685 return fd; 1738 return fd;
1686 1739
1687 res = ftruncate (fd, length); 1740 res = ftruncate (fd, length);
1688 close (fd); 1741 silent_close (fd);
1689 return res; 1742 return res;
1690} 1743}
1691 1744
1692static int 1745static int
1693eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) 1746eio__statvfsat (int dirfd, const char *path, struct statvfs *buf)
1694{ 1747{
1695 int fd = openat (dirfd, path, O_SEARCH | O_CLOEXEC); 1748 int fd = openat (dirfd, path, O_SEARCH | O_CLOEXEC | O_NONBLOCK);
1696 int res; 1749 int res;
1697 1750
1698 if (fd < 0) 1751 if (fd < 0)
1699 return fd; 1752 return fd;
1700 1753
1701 res = fstatvfs (fd, buf); 1754 res = fstatvfs (fd, buf);
1702 close (fd); 1755 silent_close (fd);
1703 return res; 1756 return res;
1704
1705} 1757}
1706 1758
1707#endif 1759#endif
1708 1760
1709/*****************************************************************************/ 1761/*****************************************************************************/
1717 req->ptr2 = malloc (len); \ 1769 req->ptr2 = malloc (len); \
1718 if (!req->ptr2) \ 1770 if (!req->ptr2) \
1719 { \ 1771 { \
1720 errno = ENOMEM; \ 1772 errno = ENOMEM; \
1721 req->result = -1; \ 1773 req->result = -1; \
1722 break; \ 1774 goto alloc_fail; \
1723 } \ 1775 } \
1724 } 1776 }
1725 1777
1726/*****************************************************************************/ 1778/*****************************************************************************/
1779
1780static void
1781eio__slurp (int fd, eio_req *req)
1782{
1783 req->result = fd;
1784
1785 if (fd < 0)
1786 return;
1787
1788 if (req->offs < 0 || !req->size) /* do we need the size? */
1789 {
1790 off_t size = lseek (fd, 0, SEEK_END);
1791
1792 if (req->offs < 0)
1793 req->offs += size;
1794
1795 if (!req->size)
1796 req->size = size - req->offs;
1797 }
1798
1799 ALLOC (req->size);
1800 req->result = pread (fd, req->ptr2, req->size, req->offs);
1801
1802 silent_close (fd);
1803
1804alloc_fail:
1805 ;
1806}
1727 1807
1728int ecb_cold 1808int ecb_cold
1729eio_init (void (*want_poll)(void), void (*done_poll)(void)) 1809eio_init (void (*want_poll)(void), void (*done_poll)(void))
1730{ 1810{
1731 eio_want_poll_cb = want_poll; 1811 eio_want_poll_cb = want_poll;
1829 req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; 1909 req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break;
1830 case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break; 1910 case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break;
1831 case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break; 1911 case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break;
1832 case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break; 1912 case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break;
1833 case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break; 1913 case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break;
1914 case EIO_SLURP: eio__slurp ( openat (dirfd, req->ptr1, O_RDONLY | O_CLOEXEC), req); break;
1834 1915
1835 case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; 1916 case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break;
1836 case EIO_RMDIR: /* complications arise because "." cannot be removed, so we might have to expand */ 1917 case EIO_RMDIR: /* complications arise because "." cannot be removed, so we might have to expand */
1837 req->result = req->wd && SINGLEDOT (req->ptr1) 1918 req->result = req->wd && SINGLEDOT (req->ptr1)
1838 ? rmdir (req->wd->str) 1919 ? rmdir (req->wd->str)
1839 : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; 1920 : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break;
1840 case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; 1921 case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break;
1922 case EIO_RENAME: req->result = eio__renameat2 (
1923 dirfd,
1841 case EIO_RENAME: /* complications arise because "." cannot be renamed, so we might have to expand */ 1924 /* complications arise because "." cannot be renamed, so we might have to expand */
1842 req->result = req->wd && SINGLEDOT (req->ptr1) 1925 req->wd && SINGLEDOT (req->ptr1) ? req->wd->str : req->ptr1,
1843 ? rename (req->wd->str, req->ptr2) 1926 WD2FD ((eio_wd)req->int3),
1844 : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; 1927 req->ptr2,
1928 req->int2
1929 );
1930 break;
1845 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; 1931 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break;
1846 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; 1932 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break;
1847 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; 1933 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break;
1848 case EIO_READLINK: ALLOC (PATH_MAX);
1849 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break;
1850 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1934 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1851 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; 1935 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break;
1936 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1937 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, EIO_PATH_MAX);
1938 if (req->result == EIO_PATH_MAX)
1939 {
1940 req->result = -1;
1941 errno = ENAMETOOLONG;
1942 }
1943 break;
1852 case EIO_UTIME: 1944 case EIO_UTIME:
1853 case EIO_FUTIME: 1945 case EIO_FUTIME:
1854 { 1946 {
1855 struct timespec ts[2]; 1947 struct timespec ts[2];
1856 struct timespec *times; 1948 struct timespec *times;
1881 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; 1973 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break;
1882 case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; 1974 case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break;
1883 case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break; 1975 case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break;
1884 case EIO_TRUNCATE: req->result = truncate (path , req->offs); break; 1976 case EIO_TRUNCATE: req->result = truncate (path , req->offs); break;
1885 case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break; 1977 case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break;
1978 case EIO_SLURP: eio__slurp ( open (path , O_RDONLY | O_CLOEXEC), req); break;
1886 1979
1887 case EIO_UNLINK: req->result = unlink (path ); break; 1980 case EIO_UNLINK: req->result = unlink (path ); break;
1888 case EIO_RMDIR: req->result = rmdir (path ); break; 1981 case EIO_RMDIR: req->result = rmdir (path ); break;
1889 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; 1982 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break;
1890 case EIO_RENAME: req->result = rename (path , req->ptr2); break; 1983 case EIO_RENAME: req->result = req->int2 ? EIO_ENOSYS () : rename (path, req->ptr2); break;
1891 case EIO_LINK: req->result = link (path , req->ptr2); break; 1984 case EIO_LINK: req->result = link (path , req->ptr2); break;
1892 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; 1985 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break;
1893 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; 1986 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break;
1894 case EIO_READLINK: ALLOC (PATH_MAX);
1895 req->result = readlink (path, req->ptr2, PATH_MAX); break;
1896 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1987 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1897 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; 1988 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break;
1989 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1990 req->result = readlink (path, req->ptr2, EIO_PATH_MAX);
1991 if (req->result == EIO_PATH_MAX)
1992 {
1993 req->result = -1;
1994 errno = ENAMETOOLONG;
1995 }
1996 break;
1898 1997
1899 case EIO_UTIME: 1998 case EIO_UTIME:
1900 case EIO_FUTIME: 1999 case EIO_FUTIME:
1901 { 2000 {
1902 struct timeval tv[2]; 2001 struct timeval tv[2];
1937 2036
1938 case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; 2037 case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break;
1939 case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break; 2038 case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break;
1940 case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; 2039 case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break;
1941 2040
1942 case EIO_CLOSE: req->result = close (req->int1); break; 2041 case EIO_CLOSE: req->result = eio__close (req->int1); break;
1943 case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; 2042 case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break;
1944 case EIO_SYNC: req->result = 0; sync (); break; 2043 case EIO_SYNC: req->result = 0; sync (); break;
1945 case EIO_FSYNC: req->result = fsync (req->int1); break; 2044 case EIO_FSYNC: req->result = fsync (req->int1); break;
1946 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; 2045 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break;
1947 case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; 2046 case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break;
1985 default: 2084 default:
1986 req->result = EIO_ENOSYS (); 2085 req->result = EIO_ENOSYS ();
1987 break; 2086 break;
1988 } 2087 }
1989 2088
2089alloc_fail:
1990 req->errorno = errno; 2090 req->errorno = errno;
1991} 2091}
1992 2092
1993#ifndef EIO_NO_WRAPPERS 2093#ifndef EIO_NO_WRAPPERS
1994 2094
2247eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) 2347eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data)
2248{ 2348{
2249 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); 2349 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data);
2250} 2350}
2251 2351
2352eio_req *eio_slurp (const char *path, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data)
2353{
2354 REQ (EIO_SLURP); PATH; req->offs = offset; req->size = length; req->ptr2 = buf; SEND;
2355}
2356
2252eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data) 2357eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data)
2253{ 2358{
2254 REQ (EIO_CUSTOM); req->feed = execute; SEND; 2359 REQ (EIO_CUSTOM); req->feed = execute; SEND;
2255} 2360}
2256 2361

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines