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

Comparing libeio/eio.c (file contents):
Revision 1.139 by root, Thu Jun 25 18:14:19 2015 UTC vs.
Revision 1.152 by root, Fri Aug 17 17:16:22 2018 UTC

1/* 1/*
2 * libeio implementation 2 * libeio implementation
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libeio@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2016,2017 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 *
42#endif 42#endif
43 43
44#include "eio.h" 44#include "eio.h"
45#include "ecb.h" 45#include "ecb.h"
46 46
47#ifdef EIO_STACKSIZE
48# define X_STACKSIZE EIO_STACKSIZE
49#endif
50#include "xthread.h"
51
52#include <errno.h> 47#include <errno.h>
53#include <stddef.h> 48#include <stddef.h>
54#include <stdlib.h> 49#include <stdlib.h>
55#include <string.h> 50#include <string.h>
56#include <errno.h> 51#include <errno.h>
122 #define chmod(path,mode) _chmod (path, mode) 117 #define chmod(path,mode) _chmod (path, mode)
123 #define dup(fd) _dup (fd) 118 #define dup(fd) _dup (fd)
124 #define dup2(fd1,fd2) _dup2 (fd1, fd2) 119 #define dup2(fd1,fd2) _dup2 (fd1, fd2)
125 #define pipe(fds) _pipe (fds, 4096, O_BINARY) 120 #define pipe(fds) _pipe (fds, 4096, O_BINARY)
126 121
122 #define fcntl(fd,cmd,arg) EIO_ENOSYS ()
123 #define ioctl(fd,cmd,arg) EIO_ENOSYS ()
127 #define fchmod(fd,mode) EIO_ENOSYS () 124 #define fchmod(fd,mode) EIO_ENOSYS ()
128 #define chown(path,uid,gid) EIO_ENOSYS () 125 #define chown(path,uid,gid) EIO_ENOSYS ()
129 #define fchown(fd,uid,gid) EIO_ENOSYS () 126 #define fchown(fd,uid,gid) EIO_ENOSYS ()
130 #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */ 127 #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */
131 #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */ 128 #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */
204 /* we could even stat and see if it exists */ 201 /* we could even stat and see if it exists */
205 static int 202 static int
206 symlink (const char *old, const char *neu) 203 symlink (const char *old, const char *neu)
207 { 204 {
208 #if WINVER >= 0x0600 205 #if WINVER >= 0x0600
206 int flags;
207
208 /* This tries out all combinations of SYMBOLIC_LINK_FLAG_DIRECTORY
209 * and SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE,
210 * with directory first.
211 */
212 for (flags = 3; flags >= 0; --flags)
209 if (CreateSymbolicLink (neu, old, 1)) 213 if (CreateSymbolicLink (neu, old, flags))
210 return 0; 214 return 0;
211
212 if (CreateSymbolicLink (neu, old, 0))
213 return 0;
214 #endif 215 #endif
215 216
216 return EIO_ERRNO (ENOENT, -1); 217 return EIO_ERRNO (ENOENT, -1);
217 } 218 }
218 219
230 #define D_NAME(entp) entp.cFileName 231 #define D_NAME(entp) entp.cFileName
231 #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)
232 233
233#else 234#else
234 235
236 #include <sys/ioctl.h>
235 #include <sys/time.h> 237 #include <sys/time.h>
236 #include <sys/select.h> 238 #include <sys/select.h>
237 #include <unistd.h> 239 #include <unistd.h>
238 #include <signal.h> 240 #include <signal.h>
239 #include <dirent.h> 241 #include <dirent.h>
281# include <utime.h> 283# include <utime.h>
282#endif 284#endif
283 285
284#if HAVE_SYS_SYSCALL_H 286#if HAVE_SYS_SYSCALL_H
285# include <sys/syscall.h> 287# include <sys/syscall.h>
286#endif
287
288#if HAVE_SYS_PRCTL_H
289# include <sys/prctl.h>
290#endif 288#endif
291 289
292#if HAVE_SENDFILE 290#if HAVE_SENDFILE
293# if __linux 291# if __linux
294# include <sys/sendfile.h> 292# include <sys/sendfile.h>
302# else 300# else
303# error sendfile support requested but not available 301# error sendfile support requested but not available
304# endif 302# endif
305#endif 303#endif
306 304
305#if HAVE_RENAMEAT2
306# include <sys/syscall.h>
307# include <linux/fs.h>
308#endif
309
307#ifndef D_TYPE 310#ifndef D_TYPE
308# define D_TYPE(de) 0 311# define D_TYPE(de) 0
309#endif 312#endif
310#ifndef D_INO 313#ifndef D_INO
311# define D_INO(de) 0 314# define D_INO(de) 0
319# define NAME_MAX 4096 322# define NAME_MAX 4096
320#endif 323#endif
321 324
322/* used for readlink etc. */ 325/* used for readlink etc. */
323#ifndef PATH_MAX 326#ifndef PATH_MAX
324# define PATH_MAX 4096 327# define PATH_MAX 0
325#endif 328#endif
329
330#ifndef O_CLOEXEC
331 #define O_CLOEXEC 0
332#endif
333
334#ifndef EIO_PATH_MIN
335# define EIO_PATH_MIN 8160
336#endif
337
338#define EIO_PATH_MAX (PATH_MAX <= EIO_PATH_MIN ? EIO_PATH_MIN : PATH_MAX)
326 339
327/* buffer size for various temporary buffers */ 340/* buffer size for various temporary buffers */
328#define EIO_BUFSIZE 65536 341#define EIO_BUFSIZE 65536
329 342
330#define dBUF \ 343#define dBUF \
544} 557}
545 558
546/*****************************************************************************/ 559/*****************************************************************************/
547/* work around various missing functions */ 560/* work around various missing functions */
548 561
562#if HAVE_POSIX_CLOSE && !__linux
563# define eio__close(fd) posix_close (fd, 0)
564#else
565# define eio__close(fd) close (fd)
566#endif
567
568/* close() without disturbing errno */
569static void
570silent_close (int fd)
571{
572 int saved_errno = errno;
573 eio__close (fd);
574 errno = saved_errno;
575}
576
549#ifndef HAVE_UTIMES 577#ifndef HAVE_UTIMES
550 578
551# undef utimes 579# undef utimes
552# define utimes(path,times) eio__utimes (path, times) 580# define utimes(path,times) eio__utimes (path, times)
553 581
931 intptr_t end = addr + len; 959 intptr_t end = addr + len;
932 intptr_t page = eio_pagesize (); 960 intptr_t page = eio_pagesize ();
933 961
934 if (addr < end) 962 if (addr < end)
935 if (flags & EIO_MT_MODIFY) /* modify */ 963 if (flags & EIO_MT_MODIFY) /* modify */
936 do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req)); 964 do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < end && !EIO_CANCELLED (req));
937 else 965 else
938 do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req)); 966 do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < end && !EIO_CANCELLED (req));
939 } 967 }
940 968
941 return 0; 969 return 0;
942} 970}
943 971
977 1005
978 errno = ENOENT; 1006 errno = ENOENT;
979 if (!*rel) 1007 if (!*rel)
980 return -1; 1008 return -1;
981 1009
982 res = etp_tmpbuf_get (tmpbuf, PATH_MAX * 3); 1010 res = etp_tmpbuf_get (tmpbuf, EIO_PATH_MAX * 3);
983#ifdef _WIN32 1011#ifdef _WIN32
984 if (_access (rel, 4) != 0) 1012 if (_access (rel, 4) != 0)
985 return -1; 1013 return -1;
986 1014
987 symlinks = GetFullPathName (rel, PATH_MAX * 3, res, 0); 1015 symlinks = GetFullPathName (rel, EIO_PATH_MAX * 3, res, 0);
988 1016
989 errno = ENAMETOOLONG; 1017 errno = ENAMETOOLONG;
990 if (symlinks >= PATH_MAX * 3) 1018 if (symlinks >= EIO_PATH_MAX * 3)
991 return -1; 1019 return -1;
992 1020
993 errno = EIO; 1021 errno = EIO;
994 if (symlinks <= 0) 1022 if (symlinks <= 0)
995 return -1; 1023 return -1;
996 1024
997 return symlinks; 1025 return symlinks;
998 1026
999#else 1027#else
1000 tmp1 = res + PATH_MAX; 1028 tmp1 = res + EIO_PATH_MAX;
1001 tmp2 = tmp1 + PATH_MAX; 1029 tmp2 = tmp1 + EIO_PATH_MAX;
1002 1030
1003#if 0 /* disabled, the musl way to do things is just too racy */ 1031#if 0 /* disabled, the musl way to do things is just too racy */
1004#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) 1032#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME)
1005 /* on linux we may be able to ask the kernel */ 1033 /* on linux we may be able to ask the kernel */
1006 { 1034 {
1007 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME); 1035 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME);
1008 1036
1009 if (fd >= 0) 1037 if (fd >= 0)
1010 { 1038 {
1011 sprintf (tmp1, "/proc/self/fd/%d", fd); 1039 sprintf (tmp1, "/proc/self/fd/%d", fd);
1012 req->result = readlink (tmp1, res, PATH_MAX); 1040 req->result = readlink (tmp1, res, EIO_PATH_MAX);
1013 /* here we should probably stat the open file and the disk file, to make sure they still match */ 1041 /* here we should probably stat the open file and the disk file, to make sure they still match */
1014 close (fd); 1042 eio__close (fd);
1015 1043
1016 if (req->result > 0) 1044 if (req->result > 0)
1017 goto done; 1045 goto done;
1018 } 1046 }
1019 else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO) 1047 else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO)
1030 if (wd == EIO_INVALID_WD) 1058 if (wd == EIO_INVALID_WD)
1031 return -1; 1059 return -1;
1032 1060
1033 if (wd == EIO_CWD) 1061 if (wd == EIO_CWD)
1034 { 1062 {
1035 if (!getcwd (res, PATH_MAX)) 1063 if (!getcwd (res, EIO_PATH_MAX))
1036 return -1; 1064 return -1;
1037 1065
1038 len = strlen (res); 1066 len = strlen (res);
1039 } 1067 }
1040 else 1068 else
1087 1115
1088 /* zero-terminate, for readlink */ 1116 /* zero-terminate, for readlink */
1089 res [len + 1] = 0; 1117 res [len + 1] = 0;
1090 1118
1091 /* now check if it's a symlink */ 1119 /* now check if it's a symlink */
1092 linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); 1120 linklen = readlink (tmpbuf->ptr, tmp1, EIO_PATH_MAX);
1093 1121
1094 if (linklen < 0) 1122 if (linklen < 0)
1095 { 1123 {
1096 if (errno != EINVAL) 1124 if (errno != EINVAL)
1097 return -1; 1125 return -1;
1103 { 1131 {
1104 /* yay, it was a symlink - build new path in tmp2 */ 1132 /* yay, it was a symlink - build new path in tmp2 */
1105 int rellen = strlen (rel); 1133 int rellen = strlen (rel);
1106 1134
1107 errno = ENAMETOOLONG; 1135 errno = ENAMETOOLONG;
1108 if (linklen + 1 + rellen >= PATH_MAX) 1136 if (linklen + 1 + rellen >= EIO_PATH_MAX) /* also catch linklen >= EIO_PATH_MAX */
1109 return -1; 1137 return -1;
1110 1138
1111 errno = ELOOP; 1139 errno = ELOOP;
1112 if (!--symlinks) 1140 if (!--symlinks)
1113 return -1; 1141 return -1;
1367 return; 1395 return;
1368 } 1396 }
1369 } 1397 }
1370#else 1398#else
1371 #if HAVE_AT 1399 #if HAVE_AT
1372 if (req->wd)
1373 { 1400 {
1374 int fd = openat (WD2FD (req->wd), req->ptr1, O_CLOEXEC | O_SEARCH | O_DIRECTORY); 1401 int fd = openat (WD2FD (req->wd), req->ptr1, O_CLOEXEC | O_SEARCH | O_DIRECTORY);
1375 1402
1376 if (fd < 0) 1403 if (fd < 0)
1377 return; 1404 return;
1378 1405
1379 dirp = fdopendir (fd); 1406 dirp = fdopendir (fd);
1380 1407
1381 if (!dirp) 1408 if (!dirp)
1382 close (fd); 1409 silent_close (fd);
1383 } 1410 }
1384 else
1385 dirp = opendir (req->ptr1);
1386 #else 1411 #else
1387 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); 1412 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1));
1388 #endif 1413 #endif
1389 1414
1390 if (!dirp) 1415 if (!dirp)
1653} 1678}
1654 1679
1655eio_wd 1680eio_wd
1656eio_wd_open_sync (eio_wd wd, const char *path) 1681eio_wd_open_sync (eio_wd wd, const char *path)
1657{ 1682{
1658 struct etp_tmpbuf tmpbuf = { }; 1683 struct etp_tmpbuf tmpbuf = { 0 };
1659 wd = eio__wd_open_sync (&tmpbuf, wd, path); 1684 wd = eio__wd_open_sync (&tmpbuf, wd, path);
1660 free (tmpbuf.ptr); 1685 free (tmpbuf.ptr);
1661 1686
1662 return wd; 1687 return wd;
1663} 1688}
1666eio_wd_close_sync (eio_wd wd) 1691eio_wd_close_sync (eio_wd wd)
1667{ 1692{
1668 if (wd != EIO_INVALID_WD && wd != EIO_CWD) 1693 if (wd != EIO_INVALID_WD && wd != EIO_CWD)
1669 { 1694 {
1670 #if HAVE_AT 1695 #if HAVE_AT
1671 close (wd->fd); 1696 eio__close (wd->fd);
1672 #endif 1697 #endif
1673 free (wd); 1698 free (wd);
1674 } 1699 }
1675} 1700}
1676 1701
1677#if HAVE_AT 1702#if HAVE_AT
1678 1703
1704static int
1705eio__renameat2 (int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags)
1706{
1707#if HAVE_RENAMEAT2
1708 return syscall (SYS_renameat2, olddirfd, oldpath, newdirfd, newpath, flags);
1709#else
1710 if (flags)
1711 return EIO_ENOSYS ();
1712
1713 return renameat (olddirfd, oldpath, newdirfd, newpath);
1714#endif
1715}
1716
1679/* they forgot these */ 1717/* they forgot these */
1680 1718
1681static int 1719static int
1682eio__truncateat (int dirfd, const char *path, off_t length) 1720eio__truncateat (int dirfd, const char *path, off_t length)
1683{ 1721{
1686 1724
1687 if (fd < 0) 1725 if (fd < 0)
1688 return fd; 1726 return fd;
1689 1727
1690 res = ftruncate (fd, length); 1728 res = ftruncate (fd, length);
1691 close (fd); 1729 silent_close (fd);
1692 return res; 1730 return res;
1693} 1731}
1694 1732
1695static int 1733static int
1696eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) 1734eio__statvfsat (int dirfd, const char *path, struct statvfs *buf)
1700 1738
1701 if (fd < 0) 1739 if (fd < 0)
1702 return fd; 1740 return fd;
1703 1741
1704 res = fstatvfs (fd, buf); 1742 res = fstatvfs (fd, buf);
1705 close (fd); 1743 silent_close (fd);
1706 return res; 1744 return res;
1707
1708} 1745}
1709 1746
1710#endif 1747#endif
1711 1748
1712/*****************************************************************************/ 1749/*****************************************************************************/
1720 req->ptr2 = malloc (len); \ 1757 req->ptr2 = malloc (len); \
1721 if (!req->ptr2) \ 1758 if (!req->ptr2) \
1722 { \ 1759 { \
1723 errno = ENOMEM; \ 1760 errno = ENOMEM; \
1724 req->result = -1; \ 1761 req->result = -1; \
1725 break; \ 1762 goto alloc_fail; \
1726 } \ 1763 } \
1727 } 1764 }
1728 1765
1729/*****************************************************************************/ 1766/*****************************************************************************/
1767
1768static void
1769eio__slurp (int fd, eio_req *req)
1770{
1771 req->result = fd;
1772
1773 if (fd < 0)
1774 return;
1775
1776 if (req->offs < 0 || !req->size) /* do we need the size? */
1777 {
1778 off_t size = lseek (fd, 0, SEEK_END);
1779
1780 if (req->offs < 0)
1781 req->offs += size;
1782
1783 if (!req->size)
1784 req->size = size - req->offs;
1785 }
1786
1787 ALLOC (req->size);
1788 req->result = pread (fd, req->ptr2, req->size, req->offs);
1789
1790 silent_close (fd);
1791
1792alloc_fail:
1793 ;
1794}
1730 1795
1731int ecb_cold 1796int ecb_cold
1732eio_init (void (*want_poll)(void), void (*done_poll)(void)) 1797eio_init (void (*want_poll)(void), void (*done_poll)(void))
1733{ 1798{
1734 eio_want_poll_cb = want_poll; 1799 eio_want_poll_cb = want_poll;
1816 : read (req->int1, req->ptr2, req->size); break; 1881 : read (req->int1, req->ptr2, req->size); break;
1817 case EIO_WRITE: req->result = req->offs >= 0 1882 case EIO_WRITE: req->result = req->offs >= 0
1818 ? pwrite (req->int1, req->ptr2, req->size, req->offs) 1883 ? pwrite (req->int1, req->ptr2, req->size, req->offs)
1819 : write (req->int1, req->ptr2, req->size); break; 1884 : write (req->int1, req->ptr2, req->size); break;
1820 1885
1886 case EIO_FCNTL: req->result = fcntl (req->int1, (int) req->int2, req->ptr2); break;
1887 case EIO_IOCTL: req->result = ioctl (req->int1, (unsigned long)req->int2, req->ptr2); break;
1888
1821 case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; 1889 case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break;
1822 case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; 1890 case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break;
1823 1891
1824#if HAVE_AT 1892#if HAVE_AT
1825 1893
1829 req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; 1897 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; 1898 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; 1899 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; 1900 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; 1901 case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break;
1902 case EIO_SLURP: eio__slurp ( openat (dirfd, req->ptr1, O_RDONLY | O_CLOEXEC), req); break;
1834 1903
1835 case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; 1904 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 */ 1905 case EIO_RMDIR: /* complications arise because "." cannot be removed, so we might have to expand */
1837 req->result = req->wd && SINGLEDOT (req->ptr1) 1906 req->result = req->wd && SINGLEDOT (req->ptr1)
1838 ? rmdir (req->wd->str) 1907 ? rmdir (req->wd->str)
1839 : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; 1908 : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break;
1840 case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; 1909 case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break;
1910 case EIO_RENAME: req->result = eio__renameat2 (
1911 dirfd,
1841 case EIO_RENAME: /* complications arise because "." cannot be renamed, so we might have to expand */ 1912 /* complications arise because "." cannot be renamed, so we might have to expand */
1842 req->result = req->wd && SINGLEDOT (req->ptr1) 1913 req->wd && SINGLEDOT (req->ptr1) ? req->wd->str : req->ptr1,
1843 ? rename (req->wd->str, req->ptr2) 1914 WD2FD ((eio_wd)req->int3),
1844 : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; 1915 req->ptr2,
1916 req->int2
1917 );
1918 break;
1845 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; 1919 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; 1920 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; 1921 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)); 1922 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1851 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; 1923 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break;
1924 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1925 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, EIO_PATH_MAX);
1926 if (req->result == EIO_PATH_MAX)
1927 {
1928 req->result = -1;
1929 errno = ENAMETOOLONG;
1930 }
1931 break;
1852 case EIO_UTIME: 1932 case EIO_UTIME:
1853 case EIO_FUTIME: 1933 case EIO_FUTIME:
1854 { 1934 {
1855 struct timespec ts[2]; 1935 struct timespec ts[2];
1856 struct timespec *times; 1936 struct timespec *times;
1881 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; 1961 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break;
1882 case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; 1962 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; 1963 case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break;
1884 case EIO_TRUNCATE: req->result = truncate (path , req->offs); break; 1964 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; 1965 case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break;
1966 case EIO_SLURP: eio__slurp ( open (path , O_RDONLY | O_CLOEXEC), req); break;
1886 1967
1887 case EIO_UNLINK: req->result = unlink (path ); break; 1968 case EIO_UNLINK: req->result = unlink (path ); break;
1888 case EIO_RMDIR: req->result = rmdir (path ); break; 1969 case EIO_RMDIR: req->result = rmdir (path ); break;
1889 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; 1970 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break;
1890 case EIO_RENAME: req->result = rename (path , req->ptr2); break; 1971 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; 1972 case EIO_LINK: req->result = link (path , req->ptr2); break;
1892 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; 1973 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; 1974 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)); 1975 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1897 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; 1976 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break;
1977 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1978 req->result = readlink (path, req->ptr2, EIO_PATH_MAX);
1979 if (req->result == EIO_PATH_MAX)
1980 {
1981 req->result = -1;
1982 errno = ENAMETOOLONG;
1983 }
1984 break;
1898 1985
1899 case EIO_UTIME: 1986 case EIO_UTIME:
1900 case EIO_FUTIME: 1987 case EIO_FUTIME:
1901 { 1988 {
1902 struct timeval tv[2]; 1989 struct timeval tv[2];
1937 2024
1938 case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; 2025 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; 2026 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; 2027 case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break;
1941 2028
1942 case EIO_CLOSE: req->result = close (req->int1); break; 2029 case EIO_CLOSE: req->result = eio__close (req->int1); break;
1943 case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; 2030 case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break;
1944 case EIO_SYNC: req->result = 0; sync (); break; 2031 case EIO_SYNC: req->result = 0; sync (); break;
1945 case EIO_FSYNC: req->result = fsync (req->int1); break; 2032 case EIO_FSYNC: req->result = fsync (req->int1); break;
1946 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; 2033 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break;
1947 case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; 2034 case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break;
1985 default: 2072 default:
1986 req->result = EIO_ENOSYS (); 2073 req->result = EIO_ENOSYS ();
1987 break; 2074 break;
1988 } 2075 }
1989 2076
2077alloc_fail:
1990 req->errorno = errno; 2078 req->errorno = errno;
1991} 2079}
1992 2080
1993#ifndef EIO_NO_WRAPPERS 2081#ifndef EIO_NO_WRAPPERS
1994 2082
2083} 2171}
2084 2172
2085eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) 2173eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data)
2086{ 2174{
2087 REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; 2175 REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND;
2176}
2177
2178eio_req *eio_fcntl (int fd, int cmd, void *arg, int pri, eio_cb cb, void *data)
2179{
2180 REQ (EIO_IOCTL); req->int1 = fd; req->int2 = cmd; req->ptr2 = arg; SEND;
2181}
2182
2183eio_req *eio_ioctl (int fd, unsigned long request, void *buf, int pri, eio_cb cb, void *data)
2184{
2185 REQ (EIO_IOCTL); req->int1 = fd; req->int2 = request; req->ptr2 = buf; SEND;
2088} 2186}
2089 2187
2090eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) 2188eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data)
2091{ 2189{
2092 REQ (EIO_FSTAT); req->int1 = fd; SEND; 2190 REQ (EIO_FSTAT); req->int1 = fd; SEND;
2237eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) 2335eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data)
2238{ 2336{
2239 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); 2337 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data);
2240} 2338}
2241 2339
2340eio_req *eio_slurp (const char *path, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data)
2341{
2342 REQ (EIO_SLURP); PATH; req->offs = offset; req->size = length; req->ptr2 = buf; SEND;
2343}
2344
2242eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data) 2345eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data)
2243{ 2346{
2244 REQ (EIO_CUSTOM); req->feed = execute; SEND; 2347 REQ (EIO_CUSTOM); req->feed = execute; SEND;
2245} 2348}
2246 2349

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines