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

Comparing libeio/eio.c (file contents):
Revision 1.142 by root, Sun May 1 17:15:45 2016 UTC vs.
Revision 1.150 by root, Fri Jun 15 02:57:36 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 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 *
201 /* we could even stat and see if it exists */ 201 /* we could even stat and see if it exists */
202 static int 202 static int
203 symlink (const char *old, const char *neu) 203 symlink (const char *old, const char *neu)
204 { 204 {
205 #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)
206 if (CreateSymbolicLink (neu, old, 1)) 213 if (CreateSymbolicLink (neu, old, flags))
207 return 0; 214 return 0;
208
209 if (CreateSymbolicLink (neu, old, 0))
210 return 0;
211 #endif 215 #endif
212 216
213 return EIO_ERRNO (ENOENT, -1); 217 return EIO_ERRNO (ENOENT, -1);
214 } 218 }
215 219
227 #define D_NAME(entp) entp.cFileName 231 #define D_NAME(entp) entp.cFileName
228 #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)
229 233
230#else 234#else
231 235
236 #include <sys/ioctl.h>
232 #include <sys/time.h> 237 #include <sys/time.h>
233 #include <sys/select.h> 238 #include <sys/select.h>
234 #include <unistd.h> 239 #include <unistd.h>
235 #include <signal.h> 240 #include <signal.h>
236 #include <dirent.h> 241 #include <dirent.h>
295# else 300# else
296# error sendfile support requested but not available 301# error sendfile support requested but not available
297# endif 302# endif
298#endif 303#endif
299 304
305#if HAVE_RENAMEAT2
306# include <sys/syscall.h>
307# include <linux/fs.h>
308#endif
309
300#ifndef D_TYPE 310#ifndef D_TYPE
301# define D_TYPE(de) 0 311# define D_TYPE(de) 0
302#endif 312#endif
303#ifndef D_INO 313#ifndef D_INO
304# define D_INO(de) 0 314# define D_INO(de) 0
312# define NAME_MAX 4096 322# define NAME_MAX 4096
313#endif 323#endif
314 324
315/* used for readlink etc. */ 325/* used for readlink etc. */
316#ifndef PATH_MAX 326#ifndef PATH_MAX
317# define PATH_MAX 4096 327# define PATH_MAX 0
318#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)
319 339
320/* buffer size for various temporary buffers */ 340/* buffer size for various temporary buffers */
321#define EIO_BUFSIZE 65536 341#define EIO_BUFSIZE 65536
322 342
323#define dBUF \ 343#define dBUF \
537} 557}
538 558
539/*****************************************************************************/ 559/*****************************************************************************/
540/* work around various missing functions */ 560/* work around various missing functions */
541 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
542#ifndef HAVE_UTIMES 577#ifndef HAVE_UTIMES
543 578
544# undef utimes 579# undef utimes
545# define utimes(path,times) eio__utimes (path, times) 580# define utimes(path,times) eio__utimes (path, times)
546 581
924 intptr_t end = addr + len; 959 intptr_t end = addr + len;
925 intptr_t page = eio_pagesize (); 960 intptr_t page = eio_pagesize ();
926 961
927 if (addr < end) 962 if (addr < end)
928 if (flags & EIO_MT_MODIFY) /* modify */ 963 if (flags & EIO_MT_MODIFY) /* modify */
929 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));
930 else 965 else
931 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));
932 } 967 }
933 968
934 return 0; 969 return 0;
935} 970}
936 971
970 1005
971 errno = ENOENT; 1006 errno = ENOENT;
972 if (!*rel) 1007 if (!*rel)
973 return -1; 1008 return -1;
974 1009
975 res = etp_tmpbuf_get (tmpbuf, PATH_MAX * 3); 1010 res = etp_tmpbuf_get (tmpbuf, EIO_PATH_MAX * 3);
976#ifdef _WIN32 1011#ifdef _WIN32
977 if (_access (rel, 4) != 0) 1012 if (_access (rel, 4) != 0)
978 return -1; 1013 return -1;
979 1014
980 symlinks = GetFullPathName (rel, PATH_MAX * 3, res, 0); 1015 symlinks = GetFullPathName (rel, EIO_PATH_MAX * 3, res, 0);
981 1016
982 errno = ENAMETOOLONG; 1017 errno = ENAMETOOLONG;
983 if (symlinks >= PATH_MAX * 3) 1018 if (symlinks >= EIO_PATH_MAX * 3)
984 return -1; 1019 return -1;
985 1020
986 errno = EIO; 1021 errno = EIO;
987 if (symlinks <= 0) 1022 if (symlinks <= 0)
988 return -1; 1023 return -1;
989 1024
990 return symlinks; 1025 return symlinks;
991 1026
992#else 1027#else
993 tmp1 = res + PATH_MAX; 1028 tmp1 = res + EIO_PATH_MAX;
994 tmp2 = tmp1 + PATH_MAX; 1029 tmp2 = tmp1 + EIO_PATH_MAX;
995 1030
996#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 */
997#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) 1032#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME)
998 /* on linux we may be able to ask the kernel */ 1033 /* on linux we may be able to ask the kernel */
999 { 1034 {
1000 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);
1001 1036
1002 if (fd >= 0) 1037 if (fd >= 0)
1003 { 1038 {
1004 sprintf (tmp1, "/proc/self/fd/%d", fd); 1039 sprintf (tmp1, "/proc/self/fd/%d", fd);
1005 req->result = readlink (tmp1, res, PATH_MAX); 1040 req->result = readlink (tmp1, res, EIO_PATH_MAX);
1006 /* 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 */
1007 close (fd); 1042 eio__close (fd);
1008 1043
1009 if (req->result > 0) 1044 if (req->result > 0)
1010 goto done; 1045 goto done;
1011 } 1046 }
1012 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)
1023 if (wd == EIO_INVALID_WD) 1058 if (wd == EIO_INVALID_WD)
1024 return -1; 1059 return -1;
1025 1060
1026 if (wd == EIO_CWD) 1061 if (wd == EIO_CWD)
1027 { 1062 {
1028 if (!getcwd (res, PATH_MAX)) 1063 if (!getcwd (res, EIO_PATH_MAX))
1029 return -1; 1064 return -1;
1030 1065
1031 len = strlen (res); 1066 len = strlen (res);
1032 } 1067 }
1033 else 1068 else
1080 1115
1081 /* zero-terminate, for readlink */ 1116 /* zero-terminate, for readlink */
1082 res [len + 1] = 0; 1117 res [len + 1] = 0;
1083 1118
1084 /* now check if it's a symlink */ 1119 /* now check if it's a symlink */
1085 linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); 1120 linklen = readlink (tmpbuf->ptr, tmp1, EIO_PATH_MAX);
1086 1121
1087 if (linklen < 0) 1122 if (linklen < 0)
1088 { 1123 {
1089 if (errno != EINVAL) 1124 if (errno != EINVAL)
1090 return -1; 1125 return -1;
1096 { 1131 {
1097 /* yay, it was a symlink - build new path in tmp2 */ 1132 /* yay, it was a symlink - build new path in tmp2 */
1098 int rellen = strlen (rel); 1133 int rellen = strlen (rel);
1099 1134
1100 errno = ENAMETOOLONG; 1135 errno = ENAMETOOLONG;
1101 if (linklen + 1 + rellen >= PATH_MAX) 1136 if (linklen + 1 + rellen >= EIO_PATH_MAX) /* also catch linklen >= EIO_PATH_MAX */
1102 return -1; 1137 return -1;
1103 1138
1104 errno = ELOOP; 1139 errno = ELOOP;
1105 if (!--symlinks) 1140 if (!--symlinks)
1106 return -1; 1141 return -1;
1370 return; 1405 return;
1371 1406
1372 dirp = fdopendir (fd); 1407 dirp = fdopendir (fd);
1373 1408
1374 if (!dirp) 1409 if (!dirp)
1375 close (fd); 1410 silent_close (fd);
1376 } 1411 }
1377 else 1412 else
1378 dirp = opendir (req->ptr1); 1413 dirp = opendir (req->ptr1);
1379 #else 1414 #else
1380 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); 1415 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1));
1659eio_wd_close_sync (eio_wd wd) 1694eio_wd_close_sync (eio_wd wd)
1660{ 1695{
1661 if (wd != EIO_INVALID_WD && wd != EIO_CWD) 1696 if (wd != EIO_INVALID_WD && wd != EIO_CWD)
1662 { 1697 {
1663 #if HAVE_AT 1698 #if HAVE_AT
1664 close (wd->fd); 1699 eio__close (wd->fd);
1665 #endif 1700 #endif
1666 free (wd); 1701 free (wd);
1667 } 1702 }
1668} 1703}
1669 1704
1670#if HAVE_AT 1705#if HAVE_AT
1671 1706
1707static int
1708eio__renameat2 (int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags)
1709{
1710#if HAVE_RENAMEAT2
1711 return syscall (SYS_renameat2, olddirfd, oldpath, newdirfd, newpath, flags);
1712#else
1713 if (flags)
1714 return EIO_ENOSYS ();
1715
1716 return renameat (olddirfd, oldpath, newdirfd, newpath);
1717#endif
1718}
1719
1672/* they forgot these */ 1720/* they forgot these */
1673 1721
1674static int 1722static int
1675eio__truncateat (int dirfd, const char *path, off_t length) 1723eio__truncateat (int dirfd, const char *path, off_t length)
1676{ 1724{
1679 1727
1680 if (fd < 0) 1728 if (fd < 0)
1681 return fd; 1729 return fd;
1682 1730
1683 res = ftruncate (fd, length); 1731 res = ftruncate (fd, length);
1684 close (fd); 1732 silent_close (fd);
1685 return res; 1733 return res;
1686} 1734}
1687 1735
1688static int 1736static int
1689eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) 1737eio__statvfsat (int dirfd, const char *path, struct statvfs *buf)
1693 1741
1694 if (fd < 0) 1742 if (fd < 0)
1695 return fd; 1743 return fd;
1696 1744
1697 res = fstatvfs (fd, buf); 1745 res = fstatvfs (fd, buf);
1698 close (fd); 1746 silent_close (fd);
1699 return res; 1747 return res;
1700
1701} 1748}
1702 1749
1703#endif 1750#endif
1704 1751
1705/*****************************************************************************/ 1752/*****************************************************************************/
1713 req->ptr2 = malloc (len); \ 1760 req->ptr2 = malloc (len); \
1714 if (!req->ptr2) \ 1761 if (!req->ptr2) \
1715 { \ 1762 { \
1716 errno = ENOMEM; \ 1763 errno = ENOMEM; \
1717 req->result = -1; \ 1764 req->result = -1; \
1718 break; \ 1765 goto alloc_fail; \
1719 } \ 1766 } \
1720 } 1767 }
1721 1768
1722/*****************************************************************************/ 1769/*****************************************************************************/
1770
1771static void
1772eio__slurp (int fd, eio_req *req)
1773{
1774 req->result = fd;
1775
1776 if (fd < 0)
1777 return;
1778
1779 if (req->offs < 0 || !req->size) /* do we need the size? */
1780 {
1781 off_t size = lseek (fd, 0, SEEK_END);
1782
1783 if (req->offs < 0)
1784 req->offs += size;
1785
1786 if (!req->size)
1787 req->size = size - req->offs;
1788 }
1789
1790 ALLOC (req->size);
1791 req->result = pread (fd, req->ptr2, req->size, req->offs);
1792
1793 silent_close (fd);
1794
1795alloc_fail:
1796 ;
1797}
1723 1798
1724int ecb_cold 1799int ecb_cold
1725eio_init (void (*want_poll)(void), void (*done_poll)(void)) 1800eio_init (void (*want_poll)(void), void (*done_poll)(void))
1726{ 1801{
1727 eio_want_poll_cb = want_poll; 1802 eio_want_poll_cb = want_poll;
1825 req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; 1900 req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break;
1826 case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break; 1901 case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break;
1827 case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break; 1902 case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break;
1828 case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break; 1903 case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break;
1829 case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break; 1904 case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break;
1905 case EIO_SLURP: eio__slurp ( openat (dirfd, req->ptr1, O_RDONLY | O_CLOEXEC), req); break;
1830 1906
1831 case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; 1907 case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break;
1832 case EIO_RMDIR: /* complications arise because "." cannot be removed, so we might have to expand */ 1908 case EIO_RMDIR: /* complications arise because "." cannot be removed, so we might have to expand */
1833 req->result = req->wd && SINGLEDOT (req->ptr1) 1909 req->result = req->wd && SINGLEDOT (req->ptr1)
1834 ? rmdir (req->wd->str) 1910 ? rmdir (req->wd->str)
1835 : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; 1911 : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break;
1836 case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; 1912 case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break;
1913 case EIO_RENAME: req->result = eio__renameat2 (
1914 dirfd,
1837 case EIO_RENAME: /* complications arise because "." cannot be renamed, so we might have to expand */ 1915 /* complications arise because "." cannot be renamed, so we might have to expand */
1838 req->result = req->wd && SINGLEDOT (req->ptr1) 1916 req->wd && SINGLEDOT (req->ptr1) ? req->wd->str : req->ptr1,
1839 ? rename (req->wd->str, req->ptr2) 1917 WD2FD ((eio_wd)req->int3),
1840 : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; 1918 req->ptr2,
1919 req->int2
1920 );
1921 break;
1841 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; 1922 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break;
1842 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; 1923 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break;
1843 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; 1924 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break;
1844 case EIO_READLINK: ALLOC (PATH_MAX);
1845 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break;
1846 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1925 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1847 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; 1926 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break;
1927 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1928 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, EIO_PATH_MAX);
1929 if (req->result == EIO_PATH_MAX)
1930 {
1931 req->result = -1;
1932 errno = ENAMETOOLONG;
1933 }
1934 break;
1848 case EIO_UTIME: 1935 case EIO_UTIME:
1849 case EIO_FUTIME: 1936 case EIO_FUTIME:
1850 { 1937 {
1851 struct timespec ts[2]; 1938 struct timespec ts[2];
1852 struct timespec *times; 1939 struct timespec *times;
1877 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; 1964 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break;
1878 case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; 1965 case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break;
1879 case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break; 1966 case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break;
1880 case EIO_TRUNCATE: req->result = truncate (path , req->offs); break; 1967 case EIO_TRUNCATE: req->result = truncate (path , req->offs); break;
1881 case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break; 1968 case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break;
1969 case EIO_SLURP: eio__slurp ( open (path , O_RDONLY | O_CLOEXEC), req); break;
1882 1970
1883 case EIO_UNLINK: req->result = unlink (path ); break; 1971 case EIO_UNLINK: req->result = unlink (path ); break;
1884 case EIO_RMDIR: req->result = rmdir (path ); break; 1972 case EIO_RMDIR: req->result = rmdir (path ); break;
1885 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; 1973 case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break;
1886 case EIO_RENAME: req->result = rename (path , req->ptr2); break; 1974 case EIO_RENAME: req->result = req->int2 ? EIO_ENOSYS () : rename (path, req->ptr2); break;
1887 case EIO_LINK: req->result = link (path , req->ptr2); break; 1975 case EIO_LINK: req->result = link (path , req->ptr2); break;
1888 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; 1976 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break;
1889 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; 1977 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break;
1890 case EIO_READLINK: ALLOC (PATH_MAX);
1891 req->result = readlink (path, req->ptr2, PATH_MAX); break;
1892 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1978 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1893 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; 1979 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break;
1980 case EIO_READLINK: ALLOC (EIO_PATH_MAX);
1981 req->result = readlink (path, req->ptr2, EIO_PATH_MAX);
1982 if (req->result == EIO_PATH_MAX)
1983 {
1984 req->result = -1;
1985 errno = ENAMETOOLONG;
1986 }
1987 break;
1894 1988
1895 case EIO_UTIME: 1989 case EIO_UTIME:
1896 case EIO_FUTIME: 1990 case EIO_FUTIME:
1897 { 1991 {
1898 struct timeval tv[2]; 1992 struct timeval tv[2];
1933 2027
1934 case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; 2028 case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break;
1935 case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break; 2029 case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break;
1936 case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; 2030 case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break;
1937 2031
1938 case EIO_CLOSE: req->result = close (req->int1); break; 2032 case EIO_CLOSE: req->result = eio__close (req->int1); break;
1939 case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; 2033 case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break;
1940 case EIO_SYNC: req->result = 0; sync (); break; 2034 case EIO_SYNC: req->result = 0; sync (); break;
1941 case EIO_FSYNC: req->result = fsync (req->int1); break; 2035 case EIO_FSYNC: req->result = fsync (req->int1); break;
1942 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; 2036 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break;
1943 case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; 2037 case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break;
1981 default: 2075 default:
1982 req->result = EIO_ENOSYS (); 2076 req->result = EIO_ENOSYS ();
1983 break; 2077 break;
1984 } 2078 }
1985 2079
2080alloc_fail:
1986 req->errorno = errno; 2081 req->errorno = errno;
1987} 2082}
1988 2083
1989#ifndef EIO_NO_WRAPPERS 2084#ifndef EIO_NO_WRAPPERS
1990 2085
2243eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) 2338eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data)
2244{ 2339{
2245 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); 2340 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data);
2246} 2341}
2247 2342
2343eio_req *eio_slurp (const char *path, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data)
2344{
2345 REQ (EIO_SLURP); PATH; req->offs = offset; req->size = length; req->ptr2 = buf; SEND;
2346}
2347
2248eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data) 2348eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data)
2249{ 2349{
2250 REQ (EIO_CUSTOM); req->feed = execute; SEND; 2350 REQ (EIO_CUSTOM); req->feed = execute; SEND;
2251} 2351}
2252 2352

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines