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 EIO_PATH_MIN |
|
|
331 | # define EIO_PATH_MIN 8160 |
|
|
332 | #endif |
|
|
333 | |
|
|
334 | #define EIO_PATH_MAX (PATH_MAX <= EIO_PATH_MIN ? EIO_PATH_MIN : PATH_MAX) |
326 | |
335 | |
327 | /* buffer size for various temporary buffers */ |
336 | /* buffer size for various temporary buffers */ |
328 | #define EIO_BUFSIZE 65536 |
337 | #define EIO_BUFSIZE 65536 |
329 | |
338 | |
330 | #define dBUF \ |
339 | #define dBUF \ |
… | |
… | |
544 | } |
553 | } |
545 | |
554 | |
546 | /*****************************************************************************/ |
555 | /*****************************************************************************/ |
547 | /* work around various missing functions */ |
556 | /* work around various missing functions */ |
548 | |
557 | |
|
|
558 | #if HAVE_POSIX_CLOSE && !__linux |
|
|
559 | # define eio__close(fd) posix_close (fd, 0) |
|
|
560 | #else |
|
|
561 | # define eio__close(fd) close (fd) |
|
|
562 | #endif |
|
|
563 | |
|
|
564 | /* close() without disturbing errno */ |
|
|
565 | static void |
|
|
566 | silent_close (int fd) |
|
|
567 | { |
|
|
568 | int saved_errno = errno; |
|
|
569 | eio__close (fd); |
|
|
570 | errno = saved_errno; |
|
|
571 | } |
|
|
572 | |
549 | #ifndef HAVE_UTIMES |
573 | #ifndef HAVE_UTIMES |
550 | |
574 | |
551 | # undef utimes |
575 | # undef utimes |
552 | # define utimes(path,times) eio__utimes (path, times) |
576 | # define utimes(path,times) eio__utimes (path, times) |
553 | |
577 | |
… | |
… | |
977 | |
1001 | |
978 | errno = ENOENT; |
1002 | errno = ENOENT; |
979 | if (!*rel) |
1003 | if (!*rel) |
980 | return -1; |
1004 | return -1; |
981 | |
1005 | |
982 | res = etp_tmpbuf_get (tmpbuf, PATH_MAX * 3); |
1006 | res = etp_tmpbuf_get (tmpbuf, EIO_PATH_MAX * 3); |
983 | #ifdef _WIN32 |
1007 | #ifdef _WIN32 |
984 | if (_access (rel, 4) != 0) |
1008 | if (_access (rel, 4) != 0) |
985 | return -1; |
1009 | return -1; |
986 | |
1010 | |
987 | symlinks = GetFullPathName (rel, PATH_MAX * 3, res, 0); |
1011 | symlinks = GetFullPathName (rel, EIO_PATH_MAX * 3, res, 0); |
988 | |
1012 | |
989 | errno = ENAMETOOLONG; |
1013 | errno = ENAMETOOLONG; |
990 | if (symlinks >= PATH_MAX * 3) |
1014 | if (symlinks >= EIO_PATH_MAX * 3) |
991 | return -1; |
1015 | return -1; |
992 | |
1016 | |
993 | errno = EIO; |
1017 | errno = EIO; |
994 | if (symlinks <= 0) |
1018 | if (symlinks <= 0) |
995 | return -1; |
1019 | return -1; |
996 | |
1020 | |
997 | return symlinks; |
1021 | return symlinks; |
998 | |
1022 | |
999 | #else |
1023 | #else |
1000 | tmp1 = res + PATH_MAX; |
1024 | tmp1 = res + EIO_PATH_MAX; |
1001 | tmp2 = tmp1 + PATH_MAX; |
1025 | tmp2 = tmp1 + EIO_PATH_MAX; |
1002 | |
1026 | |
1003 | #if 0 /* disabled, the musl way to do things is just too racy */ |
1027 | #if 0 /* disabled, the musl way to do things is just too racy */ |
1004 | #if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) |
1028 | #if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) |
1005 | /* on linux we may be able to ask the kernel */ |
1029 | /* on linux we may be able to ask the kernel */ |
1006 | { |
1030 | { |
1007 | int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME); |
1031 | int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME); |
1008 | |
1032 | |
1009 | if (fd >= 0) |
1033 | if (fd >= 0) |
1010 | { |
1034 | { |
1011 | sprintf (tmp1, "/proc/self/fd/%d", fd); |
1035 | sprintf (tmp1, "/proc/self/fd/%d", fd); |
1012 | req->result = readlink (tmp1, res, PATH_MAX); |
1036 | 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 */ |
1037 | /* here we should probably stat the open file and the disk file, to make sure they still match */ |
1014 | close (fd); |
1038 | eio__close (fd); |
1015 | |
1039 | |
1016 | if (req->result > 0) |
1040 | if (req->result > 0) |
1017 | goto done; |
1041 | goto done; |
1018 | } |
1042 | } |
1019 | else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO) |
1043 | else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO) |
… | |
… | |
1030 | if (wd == EIO_INVALID_WD) |
1054 | if (wd == EIO_INVALID_WD) |
1031 | return -1; |
1055 | return -1; |
1032 | |
1056 | |
1033 | if (wd == EIO_CWD) |
1057 | if (wd == EIO_CWD) |
1034 | { |
1058 | { |
1035 | if (!getcwd (res, PATH_MAX)) |
1059 | if (!getcwd (res, EIO_PATH_MAX)) |
1036 | return -1; |
1060 | return -1; |
1037 | |
1061 | |
1038 | len = strlen (res); |
1062 | len = strlen (res); |
1039 | } |
1063 | } |
1040 | else |
1064 | else |
… | |
… | |
1087 | |
1111 | |
1088 | /* zero-terminate, for readlink */ |
1112 | /* zero-terminate, for readlink */ |
1089 | res [len + 1] = 0; |
1113 | res [len + 1] = 0; |
1090 | |
1114 | |
1091 | /* now check if it's a symlink */ |
1115 | /* now check if it's a symlink */ |
1092 | linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); |
1116 | linklen = readlink (tmpbuf->ptr, tmp1, EIO_PATH_MAX); |
1093 | |
1117 | |
1094 | if (linklen < 0) |
1118 | if (linklen < 0) |
1095 | { |
1119 | { |
1096 | if (errno != EINVAL) |
1120 | if (errno != EINVAL) |
1097 | return -1; |
1121 | return -1; |
… | |
… | |
1103 | { |
1127 | { |
1104 | /* yay, it was a symlink - build new path in tmp2 */ |
1128 | /* yay, it was a symlink - build new path in tmp2 */ |
1105 | int rellen = strlen (rel); |
1129 | int rellen = strlen (rel); |
1106 | |
1130 | |
1107 | errno = ENAMETOOLONG; |
1131 | errno = ENAMETOOLONG; |
1108 | if (linklen + 1 + rellen >= PATH_MAX) |
1132 | if (linklen + 1 + rellen >= EIO_PATH_MAX) /* also catch linklen >= EIO_PATH_MAX */ |
1109 | return -1; |
1133 | return -1; |
1110 | |
1134 | |
1111 | errno = ELOOP; |
1135 | errno = ELOOP; |
1112 | if (!--symlinks) |
1136 | if (!--symlinks) |
1113 | return -1; |
1137 | return -1; |
… | |
… | |
1377 | return; |
1401 | return; |
1378 | |
1402 | |
1379 | dirp = fdopendir (fd); |
1403 | dirp = fdopendir (fd); |
1380 | |
1404 | |
1381 | if (!dirp) |
1405 | if (!dirp) |
1382 | close (fd); |
1406 | silent_close (fd); |
1383 | } |
1407 | } |
1384 | else |
1408 | else |
1385 | dirp = opendir (req->ptr1); |
1409 | dirp = opendir (req->ptr1); |
1386 | #else |
1410 | #else |
1387 | dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); |
1411 | dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); |
… | |
… | |
1666 | eio_wd_close_sync (eio_wd wd) |
1690 | eio_wd_close_sync (eio_wd wd) |
1667 | { |
1691 | { |
1668 | if (wd != EIO_INVALID_WD && wd != EIO_CWD) |
1692 | if (wd != EIO_INVALID_WD && wd != EIO_CWD) |
1669 | { |
1693 | { |
1670 | #if HAVE_AT |
1694 | #if HAVE_AT |
1671 | close (wd->fd); |
1695 | eio__close (wd->fd); |
1672 | #endif |
1696 | #endif |
1673 | free (wd); |
1697 | free (wd); |
1674 | } |
1698 | } |
1675 | } |
1699 | } |
1676 | |
1700 | |
1677 | #if HAVE_AT |
1701 | #if HAVE_AT |
1678 | |
1702 | |
|
|
1703 | static int |
|
|
1704 | eio__renameat2 (int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags) |
|
|
1705 | { |
|
|
1706 | #if HAVE_RENAMEAT2 |
|
|
1707 | return syscall (SYS_renameat2, olddirfd, oldpath, newdirfd, newpath, flags); |
|
|
1708 | #else |
|
|
1709 | if (flags) |
|
|
1710 | return EIO_ENOSYS (); |
|
|
1711 | |
|
|
1712 | return renameat (olddirfd, oldpath, newdirfd, newpath); |
|
|
1713 | #endif |
|
|
1714 | } |
|
|
1715 | |
1679 | /* they forgot these */ |
1716 | /* they forgot these */ |
1680 | |
1717 | |
1681 | static int |
1718 | static int |
1682 | eio__truncateat (int dirfd, const char *path, off_t length) |
1719 | eio__truncateat (int dirfd, const char *path, off_t length) |
1683 | { |
1720 | { |
… | |
… | |
1686 | |
1723 | |
1687 | if (fd < 0) |
1724 | if (fd < 0) |
1688 | return fd; |
1725 | return fd; |
1689 | |
1726 | |
1690 | res = ftruncate (fd, length); |
1727 | res = ftruncate (fd, length); |
1691 | close (fd); |
1728 | silent_close (fd); |
1692 | return res; |
1729 | return res; |
1693 | } |
1730 | } |
1694 | |
1731 | |
1695 | static int |
1732 | static int |
1696 | eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) |
1733 | eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) |
… | |
… | |
1700 | |
1737 | |
1701 | if (fd < 0) |
1738 | if (fd < 0) |
1702 | return fd; |
1739 | return fd; |
1703 | |
1740 | |
1704 | res = fstatvfs (fd, buf); |
1741 | res = fstatvfs (fd, buf); |
1705 | close (fd); |
1742 | silent_close (fd); |
1706 | return res; |
1743 | return res; |
1707 | |
|
|
1708 | } |
1744 | } |
1709 | |
1745 | |
1710 | #endif |
1746 | #endif |
1711 | |
1747 | |
1712 | /*****************************************************************************/ |
1748 | /*****************************************************************************/ |
… | |
… | |
1720 | req->ptr2 = malloc (len); \ |
1756 | req->ptr2 = malloc (len); \ |
1721 | if (!req->ptr2) \ |
1757 | if (!req->ptr2) \ |
1722 | { \ |
1758 | { \ |
1723 | errno = ENOMEM; \ |
1759 | errno = ENOMEM; \ |
1724 | req->result = -1; \ |
1760 | req->result = -1; \ |
1725 | break; \ |
1761 | goto alloc_fail; \ |
1726 | } \ |
1762 | } \ |
1727 | } |
1763 | } |
1728 | |
1764 | |
1729 | /*****************************************************************************/ |
1765 | /*****************************************************************************/ |
|
|
1766 | |
|
|
1767 | static void |
|
|
1768 | eio__slurp (int fd, eio_req *req) |
|
|
1769 | { |
|
|
1770 | req->result = fd; |
|
|
1771 | |
|
|
1772 | if (fd < 0) |
|
|
1773 | return; |
|
|
1774 | |
|
|
1775 | if (req->offs < 0 || !req->size) /* do we need the size? */ |
|
|
1776 | { |
|
|
1777 | off_t size = lseek (fd, 0, SEEK_END); |
|
|
1778 | |
|
|
1779 | if (req->offs < 0) |
|
|
1780 | req->offs += size; |
|
|
1781 | |
|
|
1782 | if (!req->size) |
|
|
1783 | req->size = size - req->offs; |
|
|
1784 | } |
|
|
1785 | |
|
|
1786 | ALLOC (req->size); |
|
|
1787 | req->result = pread (fd, req->ptr2, req->size, req->offs); |
|
|
1788 | |
|
|
1789 | silent_close (fd); |
|
|
1790 | |
|
|
1791 | alloc_fail: |
|
|
1792 | ; |
|
|
1793 | } |
1730 | |
1794 | |
1731 | int ecb_cold |
1795 | int ecb_cold |
1732 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1796 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1733 | { |
1797 | { |
1734 | eio_want_poll_cb = want_poll; |
1798 | eio_want_poll_cb = want_poll; |
… | |
… | |
1816 | : read (req->int1, req->ptr2, req->size); break; |
1880 | : read (req->int1, req->ptr2, req->size); break; |
1817 | case EIO_WRITE: req->result = req->offs >= 0 |
1881 | case EIO_WRITE: req->result = req->offs >= 0 |
1818 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
1882 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
1819 | : write (req->int1, req->ptr2, req->size); break; |
1883 | : write (req->int1, req->ptr2, req->size); break; |
1820 | |
1884 | |
|
|
1885 | case EIO_FCNTL: req->result = fcntl (req->int1, (int) req->int2, req->ptr2); break; |
|
|
1886 | case EIO_IOCTL: req->result = ioctl (req->int1, (unsigned long)req->int2, req->ptr2); break; |
|
|
1887 | |
1821 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
1888 | 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; |
1889 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; |
1823 | |
1890 | |
1824 | #if HAVE_AT |
1891 | #if HAVE_AT |
1825 | |
1892 | |
… | |
… | |
1829 | req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; |
1896 | 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; |
1897 | 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; |
1898 | 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; |
1899 | 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; |
1900 | case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break; |
|
|
1901 | case EIO_SLURP: eio__slurp ( openat (dirfd, req->ptr1, O_RDONLY | O_CLOEXEC), req); break; |
1834 | |
1902 | |
1835 | case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; |
1903 | 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 */ |
1904 | case EIO_RMDIR: /* complications arise because "." cannot be removed, so we might have to expand */ |
1837 | req->result = req->wd && SINGLEDOT (req->ptr1) |
1905 | req->result = req->wd && SINGLEDOT (req->ptr1) |
1838 | ? rmdir (req->wd->str) |
1906 | ? rmdir (req->wd->str) |
1839 | : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; |
1907 | : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; |
1840 | case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; |
1908 | case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; |
|
|
1909 | case EIO_RENAME: req->result = eio__renameat2 ( |
|
|
1910 | dirfd, |
1841 | case EIO_RENAME: /* complications arise because "." cannot be renamed, so we might have to expand */ |
1911 | /* complications arise because "." cannot be renamed, so we might have to expand */ |
1842 | req->result = req->wd && SINGLEDOT (req->ptr1) |
1912 | req->wd && SINGLEDOT (req->ptr1) ? req->wd->str : req->ptr1, |
1843 | ? rename (req->wd->str, req->ptr2) |
1913 | WD2FD ((eio_wd)req->int3), |
1844 | : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; |
1914 | req->ptr2, |
|
|
1915 | req->int2 |
|
|
1916 | ); |
|
|
1917 | break; |
1845 | case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; |
1918 | 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; |
1919 | 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; |
1920 | 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)); |
1921 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
1851 | req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
1922 | req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
|
|
1923 | case EIO_READLINK: ALLOC (EIO_PATH_MAX); |
|
|
1924 | req->result = readlinkat (dirfd, req->ptr1, req->ptr2, EIO_PATH_MAX); |
|
|
1925 | if (req->result == EIO_PATH_MAX) |
|
|
1926 | { |
|
|
1927 | req->result = -1; |
|
|
1928 | errno = ENAMETOOLONG; |
|
|
1929 | } |
|
|
1930 | break; |
1852 | case EIO_UTIME: |
1931 | case EIO_UTIME: |
1853 | case EIO_FUTIME: |
1932 | case EIO_FUTIME: |
1854 | { |
1933 | { |
1855 | struct timespec ts[2]; |
1934 | struct timespec ts[2]; |
1856 | struct timespec *times; |
1935 | struct timespec *times; |
… | |
… | |
1881 | req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
1960 | req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
1882 | case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; |
1961 | 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; |
1962 | case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break; |
1884 | case EIO_TRUNCATE: req->result = truncate (path , req->offs); break; |
1963 | 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; |
1964 | case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break; |
|
|
1965 | case EIO_SLURP: eio__slurp ( open (path , O_RDONLY | O_CLOEXEC), req); break; |
1886 | |
1966 | |
1887 | case EIO_UNLINK: req->result = unlink (path ); break; |
1967 | case EIO_UNLINK: req->result = unlink (path ); break; |
1888 | case EIO_RMDIR: req->result = rmdir (path ); break; |
1968 | case EIO_RMDIR: req->result = rmdir (path ); break; |
1889 | case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; |
1969 | case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; |
1890 | case EIO_RENAME: req->result = rename (path , req->ptr2); break; |
1970 | 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; |
1971 | case EIO_LINK: req->result = link (path , req->ptr2); break; |
1892 | case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; |
1972 | 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; |
1973 | 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)); |
1974 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
1897 | req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; |
1975 | req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; |
|
|
1976 | case EIO_READLINK: ALLOC (EIO_PATH_MAX); |
|
|
1977 | req->result = readlink (path, req->ptr2, EIO_PATH_MAX); |
|
|
1978 | if (req->result == EIO_PATH_MAX) |
|
|
1979 | { |
|
|
1980 | req->result = -1; |
|
|
1981 | errno = ENAMETOOLONG; |
|
|
1982 | } |
|
|
1983 | break; |
1898 | |
1984 | |
1899 | case EIO_UTIME: |
1985 | case EIO_UTIME: |
1900 | case EIO_FUTIME: |
1986 | case EIO_FUTIME: |
1901 | { |
1987 | { |
1902 | struct timeval tv[2]; |
1988 | struct timeval tv[2]; |
… | |
… | |
1937 | |
2023 | |
1938 | case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; |
2024 | 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; |
2025 | 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; |
2026 | case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; |
1941 | |
2027 | |
1942 | case EIO_CLOSE: req->result = close (req->int1); break; |
2028 | case EIO_CLOSE: req->result = eio__close (req->int1); break; |
1943 | case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; |
2029 | case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; |
1944 | case EIO_SYNC: req->result = 0; sync (); break; |
2030 | case EIO_SYNC: req->result = 0; sync (); break; |
1945 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2031 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
1946 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
2032 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
1947 | case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; |
2033 | case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; |
… | |
… | |
1985 | default: |
2071 | default: |
1986 | req->result = EIO_ENOSYS (); |
2072 | req->result = EIO_ENOSYS (); |
1987 | break; |
2073 | break; |
1988 | } |
2074 | } |
1989 | |
2075 | |
|
|
2076 | alloc_fail: |
1990 | req->errorno = errno; |
2077 | req->errorno = errno; |
1991 | } |
2078 | } |
1992 | |
2079 | |
1993 | #ifndef EIO_NO_WRAPPERS |
2080 | #ifndef EIO_NO_WRAPPERS |
1994 | |
2081 | |
… | |
… | |
2083 | } |
2170 | } |
2084 | |
2171 | |
2085 | eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
2172 | eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
2086 | { |
2173 | { |
2087 | REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
2174 | REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
|
|
2175 | } |
|
|
2176 | |
|
|
2177 | eio_req *eio_fcntl (int fd, int cmd, void *arg, int pri, eio_cb cb, void *data) |
|
|
2178 | { |
|
|
2179 | REQ (EIO_IOCTL); req->int1 = fd; req->int2 = cmd; req->ptr2 = arg; SEND; |
|
|
2180 | } |
|
|
2181 | |
|
|
2182 | eio_req *eio_ioctl (int fd, unsigned long request, void *buf, int pri, eio_cb cb, void *data) |
|
|
2183 | { |
|
|
2184 | REQ (EIO_IOCTL); req->int1 = fd; req->int2 = request; req->ptr2 = buf; SEND; |
2088 | } |
2185 | } |
2089 | |
2186 | |
2090 | eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) |
2187 | eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) |
2091 | { |
2188 | { |
2092 | REQ (EIO_FSTAT); req->int1 = fd; SEND; |
2189 | REQ (EIO_FSTAT); req->int1 = fd; SEND; |
… | |
… | |
2237 | eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
2334 | eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
2238 | { |
2335 | { |
2239 | return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); |
2336 | return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); |
2240 | } |
2337 | } |
2241 | |
2338 | |
|
|
2339 | eio_req *eio_slurp (const char *path, void *buf, ssize_t length, off_t offset, int pri, eio_cb cb, void *data) |
|
|
2340 | { |
|
|
2341 | REQ (EIO_SLURP); PATH; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
|
|
2342 | } |
|
|
2343 | |
2242 | eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data) |
2344 | eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data) |
2243 | { |
2345 | { |
2244 | REQ (EIO_CUSTOM); req->feed = execute; SEND; |
2346 | REQ (EIO_CUSTOM); req->feed = execute; SEND; |
2245 | } |
2347 | } |
2246 | |
2348 | |