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

Comparing libeio/eio.c (file contents):
Revision 1.141 by root, Tue Feb 23 19:47:44 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 *
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>
206 /* we could even stat and see if it exists */ 201 /* we could even stat and see if it exists */
207 static int 202 static int
208 symlink (const char *old, const char *neu) 203 symlink (const char *old, const char *neu)
209 { 204 {
210 #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)
211 if (CreateSymbolicLink (neu, old, 1)) 213 if (CreateSymbolicLink (neu, old, flags))
212 return 0; 214 return 0;
213
214 if (CreateSymbolicLink (neu, old, 0))
215 return 0;
216 #endif 215 #endif
217 216
218 return EIO_ERRNO (ENOENT, -1); 217 return EIO_ERRNO (ENOENT, -1);
219 } 218 }
220 219
232 #define D_NAME(entp) entp.cFileName 231 #define D_NAME(entp) entp.cFileName
233 #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)
234 233
235#else 234#else
236 235
236 #include <sys/ioctl.h>
237 #include <sys/time.h> 237 #include <sys/time.h>
238 #include <sys/select.h> 238 #include <sys/select.h>
239 #include <unistd.h> 239 #include <unistd.h>
240 #include <signal.h> 240 #include <signal.h>
241 #include <dirent.h> 241 #include <dirent.h>
283# include <utime.h> 283# include <utime.h>
284#endif 284#endif
285 285
286#if HAVE_SYS_SYSCALL_H 286#if HAVE_SYS_SYSCALL_H
287# include <sys/syscall.h> 287# include <sys/syscall.h>
288#endif
289
290#if HAVE_SYS_PRCTL_H
291# include <sys/prctl.h>
292#endif 288#endif
293 289
294#if HAVE_SENDFILE 290#if HAVE_SENDFILE
295# if __linux 291# if __linux
296# include <sys/sendfile.h> 292# include <sys/sendfile.h>
304# else 300# else
305# error sendfile support requested but not available 301# error sendfile support requested but not available
306# endif 302# endif
307#endif 303#endif
308 304
305#if HAVE_RENAMEAT2
306# include <sys/syscall.h>
307# include <linux/fs.h>
308#endif
309
309#ifndef D_TYPE 310#ifndef D_TYPE
310# define D_TYPE(de) 0 311# define D_TYPE(de) 0
311#endif 312#endif
312#ifndef D_INO 313#ifndef D_INO
313# define D_INO(de) 0 314# define D_INO(de) 0
321# define NAME_MAX 4096 322# define NAME_MAX 4096
322#endif 323#endif
323 324
324/* used for readlink etc. */ 325/* used for readlink etc. */
325#ifndef PATH_MAX 326#ifndef PATH_MAX
326# define PATH_MAX 4096 327# define PATH_MAX 0
327#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)
328 339
329/* buffer size for various temporary buffers */ 340/* buffer size for various temporary buffers */
330#define EIO_BUFSIZE 65536 341#define EIO_BUFSIZE 65536
331 342
332#define dBUF \ 343#define dBUF \
546} 557}
547 558
548/*****************************************************************************/ 559/*****************************************************************************/
549/* work around various missing functions */ 560/* work around various missing functions */
550 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
551#ifndef HAVE_UTIMES 577#ifndef HAVE_UTIMES
552 578
553# undef utimes 579# undef utimes
554# define utimes(path,times) eio__utimes (path, times) 580# define utimes(path,times) eio__utimes (path, times)
555 581
933 intptr_t end = addr + len; 959 intptr_t end = addr + len;
934 intptr_t page = eio_pagesize (); 960 intptr_t page = eio_pagesize ();
935 961
936 if (addr < end) 962 if (addr < end)
937 if (flags & EIO_MT_MODIFY) /* modify */ 963 if (flags & EIO_MT_MODIFY) /* modify */
938 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));
939 else 965 else
940 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));
941 } 967 }
942 968
943 return 0; 969 return 0;
944} 970}
945 971
979 1005
980 errno = ENOENT; 1006 errno = ENOENT;
981 if (!*rel) 1007 if (!*rel)
982 return -1; 1008 return -1;
983 1009
984 res = etp_tmpbuf_get (tmpbuf, PATH_MAX * 3); 1010 res = etp_tmpbuf_get (tmpbuf, EIO_PATH_MAX * 3);
985#ifdef _WIN32 1011#ifdef _WIN32
986 if (_access (rel, 4) != 0) 1012 if (_access (rel, 4) != 0)
987 return -1; 1013 return -1;
988 1014
989 symlinks = GetFullPathName (rel, PATH_MAX * 3, res, 0); 1015 symlinks = GetFullPathName (rel, EIO_PATH_MAX * 3, res, 0);
990 1016
991 errno = ENAMETOOLONG; 1017 errno = ENAMETOOLONG;
992 if (symlinks >= PATH_MAX * 3) 1018 if (symlinks >= EIO_PATH_MAX * 3)
993 return -1; 1019 return -1;
994 1020
995 errno = EIO; 1021 errno = EIO;
996 if (symlinks <= 0) 1022 if (symlinks <= 0)
997 return -1; 1023 return -1;
998 1024
999 return symlinks; 1025 return symlinks;
1000 1026
1001#else 1027#else
1002 tmp1 = res + PATH_MAX; 1028 tmp1 = res + EIO_PATH_MAX;
1003 tmp2 = tmp1 + PATH_MAX; 1029 tmp2 = tmp1 + EIO_PATH_MAX;
1004 1030
1005#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 */
1006#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) 1032#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME)
1007 /* on linux we may be able to ask the kernel */ 1033 /* on linux we may be able to ask the kernel */
1008 { 1034 {
1009 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);
1010 1036
1011 if (fd >= 0) 1037 if (fd >= 0)
1012 { 1038 {
1013 sprintf (tmp1, "/proc/self/fd/%d", fd); 1039 sprintf (tmp1, "/proc/self/fd/%d", fd);
1014 req->result = readlink (tmp1, res, PATH_MAX); 1040 req->result = readlink (tmp1, res, EIO_PATH_MAX);
1015 /* 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 */
1016 close (fd); 1042 eio__close (fd);
1017 1043
1018 if (req->result > 0) 1044 if (req->result > 0)
1019 goto done; 1045 goto done;
1020 } 1046 }
1021 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)
1032 if (wd == EIO_INVALID_WD) 1058 if (wd == EIO_INVALID_WD)
1033 return -1; 1059 return -1;
1034 1060
1035 if (wd == EIO_CWD) 1061 if (wd == EIO_CWD)
1036 { 1062 {
1037 if (!getcwd (res, PATH_MAX)) 1063 if (!getcwd (res, EIO_PATH_MAX))
1038 return -1; 1064 return -1;
1039 1065
1040 len = strlen (res); 1066 len = strlen (res);
1041 } 1067 }
1042 else 1068 else
1089 1115
1090 /* zero-terminate, for readlink */ 1116 /* zero-terminate, for readlink */
1091 res [len + 1] = 0; 1117 res [len + 1] = 0;
1092 1118
1093 /* now check if it's a symlink */ 1119 /* now check if it's a symlink */
1094 linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); 1120 linklen = readlink (tmpbuf->ptr, tmp1, EIO_PATH_MAX);
1095 1121
1096 if (linklen < 0) 1122 if (linklen < 0)
1097 { 1123 {
1098 if (errno != EINVAL) 1124 if (errno != EINVAL)
1099 return -1; 1125 return -1;
1105 { 1131 {
1106 /* yay, it was a symlink - build new path in tmp2 */ 1132 /* yay, it was a symlink - build new path in tmp2 */
1107 int rellen = strlen (rel); 1133 int rellen = strlen (rel);
1108 1134
1109 errno = ENAMETOOLONG; 1135 errno = ENAMETOOLONG;
1110 if (linklen + 1 + rellen >= PATH_MAX) 1136 if (linklen + 1 + rellen >= EIO_PATH_MAX) /* also catch linklen >= EIO_PATH_MAX */
1111 return -1; 1137 return -1;
1112 1138
1113 errno = ELOOP; 1139 errno = ELOOP;
1114 if (!--symlinks) 1140 if (!--symlinks)
1115 return -1; 1141 return -1;
1379 return; 1405 return;
1380 1406
1381 dirp = fdopendir (fd); 1407 dirp = fdopendir (fd);
1382 1408
1383 if (!dirp) 1409 if (!dirp)
1384 close (fd); 1410 silent_close (fd);
1385 } 1411 }
1386 else 1412 else
1387 dirp = opendir (req->ptr1); 1413 dirp = opendir (req->ptr1);
1388 #else 1414 #else
1389 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); 1415 dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1));
1668eio_wd_close_sync (eio_wd wd) 1694eio_wd_close_sync (eio_wd wd)
1669{ 1695{
1670 if (wd != EIO_INVALID_WD && wd != EIO_CWD) 1696 if (wd != EIO_INVALID_WD && wd != EIO_CWD)
1671 { 1697 {
1672 #if HAVE_AT 1698 #if HAVE_AT
1673 close (wd->fd); 1699 eio__close (wd->fd);
1674 #endif 1700 #endif
1675 free (wd); 1701 free (wd);
1676 } 1702 }
1677} 1703}
1678 1704
1679#if HAVE_AT 1705#if HAVE_AT
1680 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
1681/* they forgot these */ 1720/* they forgot these */
1682 1721
1683static int 1722static int
1684eio__truncateat (int dirfd, const char *path, off_t length) 1723eio__truncateat (int dirfd, const char *path, off_t length)
1685{ 1724{
1688 1727
1689 if (fd < 0) 1728 if (fd < 0)
1690 return fd; 1729 return fd;
1691 1730
1692 res = ftruncate (fd, length); 1731 res = ftruncate (fd, length);
1693 close (fd); 1732 silent_close (fd);
1694 return res; 1733 return res;
1695} 1734}
1696 1735
1697static int 1736static int
1698eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) 1737eio__statvfsat (int dirfd, const char *path, struct statvfs *buf)
1702 1741
1703 if (fd < 0) 1742 if (fd < 0)
1704 return fd; 1743 return fd;
1705 1744
1706 res = fstatvfs (fd, buf); 1745 res = fstatvfs (fd, buf);
1707 close (fd); 1746 silent_close (fd);
1708 return res; 1747 return res;
1709
1710} 1748}
1711 1749
1712#endif 1750#endif
1713 1751
1714/*****************************************************************************/ 1752/*****************************************************************************/
1722 req->ptr2 = malloc (len); \ 1760 req->ptr2 = malloc (len); \
1723 if (!req->ptr2) \ 1761 if (!req->ptr2) \
1724 { \ 1762 { \
1725 errno = ENOMEM; \ 1763 errno = ENOMEM; \
1726 req->result = -1; \ 1764 req->result = -1; \
1727 break; \ 1765 goto alloc_fail; \
1728 } \ 1766 } \
1729 } 1767 }
1730 1768
1731/*****************************************************************************/ 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}
1732 1798
1733int ecb_cold 1799int ecb_cold
1734eio_init (void (*want_poll)(void), void (*done_poll)(void)) 1800eio_init (void (*want_poll)(void), void (*done_poll)(void))
1735{ 1801{
1736 eio_want_poll_cb = want_poll; 1802 eio_want_poll_cb = want_poll;
1834 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;
1835 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;
1836 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;
1837 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;
1838 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;
1839 1906
1840 case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; 1907 case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break;
1841 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 */
1842 req->result = req->wd && SINGLEDOT (req->ptr1) 1909 req->result = req->wd && SINGLEDOT (req->ptr1)
1843 ? rmdir (req->wd->str) 1910 ? rmdir (req->wd->str)
1844 : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; 1911 : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break;
1845 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,
1846 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 */
1847 req->result = req->wd && SINGLEDOT (req->ptr1) 1916 req->wd && SINGLEDOT (req->ptr1) ? req->wd->str : req->ptr1,
1848 ? rename (req->wd->str, req->ptr2) 1917 WD2FD ((eio_wd)req->int3),
1849 : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; 1918 req->ptr2,
1919 req->int2
1920 );
1921 break;
1850 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;
1851 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;
1852 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;
1853 case EIO_READLINK: ALLOC (PATH_MAX);
1854 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break;
1855 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1925 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1856 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;
1857 case EIO_UTIME: 1935 case EIO_UTIME:
1858 case EIO_FUTIME: 1936 case EIO_FUTIME:
1859 { 1937 {
1860 struct timespec ts[2]; 1938 struct timespec ts[2];
1861 struct timespec *times; 1939 struct timespec *times;
1886 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; 1964 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break;
1887 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;
1888 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;
1889 case EIO_TRUNCATE: req->result = truncate (path , req->offs); break; 1967 case EIO_TRUNCATE: req->result = truncate (path , req->offs); break;
1890 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;
1891 1970
1892 case EIO_UNLINK: req->result = unlink (path ); break; 1971 case EIO_UNLINK: req->result = unlink (path ); break;
1893 case EIO_RMDIR: req->result = rmdir (path ); break; 1972 case EIO_RMDIR: req->result = rmdir (path ); break;
1894 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;
1895 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;
1896 case EIO_LINK: req->result = link (path , req->ptr2); break; 1975 case EIO_LINK: req->result = link (path , req->ptr2); break;
1897 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; 1976 case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break;
1898 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;
1899 case EIO_READLINK: ALLOC (PATH_MAX);
1900 req->result = readlink (path, req->ptr2, PATH_MAX); break;
1901 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 1978 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
1902 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;
1903 1988
1904 case EIO_UTIME: 1989 case EIO_UTIME:
1905 case EIO_FUTIME: 1990 case EIO_FUTIME:
1906 { 1991 {
1907 struct timeval tv[2]; 1992 struct timeval tv[2];
1942 2027
1943 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;
1944 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;
1945 case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; 2030 case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break;
1946 2031
1947 case EIO_CLOSE: req->result = close (req->int1); break; 2032 case EIO_CLOSE: req->result = eio__close (req->int1); break;
1948 case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; 2033 case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break;
1949 case EIO_SYNC: req->result = 0; sync (); break; 2034 case EIO_SYNC: req->result = 0; sync (); break;
1950 case EIO_FSYNC: req->result = fsync (req->int1); break; 2035 case EIO_FSYNC: req->result = fsync (req->int1); break;
1951 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; 2036 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break;
1952 case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; 2037 case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break;
1990 default: 2075 default:
1991 req->result = EIO_ENOSYS (); 2076 req->result = EIO_ENOSYS ();
1992 break; 2077 break;
1993 } 2078 }
1994 2079
2080alloc_fail:
1995 req->errorno = errno; 2081 req->errorno = errno;
1996} 2082}
1997 2083
1998#ifndef EIO_NO_WRAPPERS 2084#ifndef EIO_NO_WRAPPERS
1999 2085
2252eio_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)
2253{ 2339{
2254 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); 2340 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data);
2255} 2341}
2256 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
2257eio_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)
2258{ 2349{
2259 REQ (EIO_CUSTOM); req->feed = execute; SEND; 2350 REQ (EIO_CUSTOM); req->feed = execute; SEND;
2260} 2351}
2261 2352

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines