… | |
… | |
54 | #include <stdlib.h> |
54 | #include <stdlib.h> |
55 | #include <string.h> |
55 | #include <string.h> |
56 | #include <errno.h> |
56 | #include <errno.h> |
57 | #include <sys/types.h> |
57 | #include <sys/types.h> |
58 | #include <sys/stat.h> |
58 | #include <sys/stat.h> |
59 | #include <sys/statvfs.h> |
|
|
60 | #include <limits.h> |
59 | #include <limits.h> |
61 | #include <fcntl.h> |
60 | #include <fcntl.h> |
62 | #include <assert.h> |
61 | #include <assert.h> |
63 | |
62 | |
64 | /* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ |
63 | /* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ |
65 | /* intptr_t only comes form stdint.h, says idiot openbsd coder */ |
64 | /* intptr_t only comes from stdint.h, says idiot openbsd coder */ |
66 | #if HAVE_STDINT_H |
65 | #if HAVE_STDINT_H |
67 | # include <stdint.h> |
66 | # include <stdint.h> |
68 | #endif |
67 | #endif |
69 | |
68 | |
|
|
69 | #ifndef ECANCELED |
|
|
70 | # define ECANCELED EDOM |
|
|
71 | #endif |
|
|
72 | |
|
|
73 | static void eio_destroy (eio_req *req); |
|
|
74 | |
70 | #ifndef EIO_FINISH |
75 | #ifndef EIO_FINISH |
71 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
76 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
72 | #endif |
77 | #endif |
73 | |
78 | |
74 | #ifndef EIO_DESTROY |
79 | #ifndef EIO_DESTROY |
… | |
… | |
77 | |
82 | |
78 | #ifndef EIO_FEED |
83 | #ifndef EIO_FEED |
79 | # define EIO_FEED(req) do { if ((req)->feed ) (req)->feed (req); } while (0) |
84 | # define EIO_FEED(req) do { if ((req)->feed ) (req)->feed (req); } while (0) |
80 | #endif |
85 | #endif |
81 | |
86 | |
|
|
87 | #ifndef EIO_FD_TO_WIN32_HANDLE |
|
|
88 | # define EIO_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd) |
|
|
89 | #endif |
|
|
90 | #ifndef EIO_WIN32_HANDLE_TO_FD |
|
|
91 | # define EIO_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (handle, 0) |
|
|
92 | #endif |
|
|
93 | |
|
|
94 | #define EIO_ERRNO(errval,retval) ((errno = errval), retval) |
|
|
95 | |
|
|
96 | #define EIO_ENOSYS() EIO_ERRNO (ENOSYS, -1) |
|
|
97 | |
82 | #ifdef _WIN32 |
98 | #ifdef _WIN32 |
83 | |
99 | |
84 | /*doh*/ |
100 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
|
|
101 | |
|
|
102 | #ifdef EIO_STRUCT_STATI64 |
|
|
103 | #define stat(path,buf) _stati64 (path,buf) |
|
|
104 | #define fstat(fd,buf) _fstati64 (path,buf) |
|
|
105 | #endif |
|
|
106 | #define lstat(path,buf) stat (path,buf) |
|
|
107 | #define fsync(fd) (FlushFileBuffers (EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) |
|
|
108 | #define mkdir(path,mode) _mkdir (path) |
|
|
109 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
|
|
110 | |
|
|
111 | #define chown(path,uid,gid) EIO_ENOSYS () |
|
|
112 | #define fchown(fd,uid,gid) EIO_ENOSYS () |
|
|
113 | #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */ |
|
|
114 | #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */ |
|
|
115 | #define mknod(path,mode,dev) EIO_ENOSYS () |
|
|
116 | #define sync() EIO_ENOSYS () |
|
|
117 | |
|
|
118 | /* we could even stat and see if it exists */ |
|
|
119 | static int |
|
|
120 | symlink (const char *old, const char *neu) |
|
|
121 | { |
|
|
122 | if (CreateSymbolicLink (neu, old, 1)) |
|
|
123 | return 0; |
|
|
124 | |
|
|
125 | if (CreateSymbolicLink (neu, old, 0)) |
|
|
126 | return 0; |
|
|
127 | |
|
|
128 | return EIO_ERRNO (ENOENT, -1); |
|
|
129 | } |
|
|
130 | |
85 | #else |
131 | #else |
86 | |
132 | |
87 | # include <sys/time.h> |
133 | #include <sys/time.h> |
88 | # include <sys/select.h> |
134 | #include <sys/select.h> |
|
|
135 | #include <sys/statvfs.h> |
89 | # include <unistd.h> |
136 | #include <unistd.h> |
90 | # include <utime.h> |
137 | #include <utime.h> |
91 | # include <signal.h> |
138 | #include <signal.h> |
92 | # include <dirent.h> |
139 | #include <dirent.h> |
93 | |
140 | |
94 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
141 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
95 | # include <sys/mman.h> |
142 | #include <sys/mman.h> |
96 | #endif |
143 | #endif |
97 | |
144 | |
98 | /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ |
145 | /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ |
99 | # if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ |
146 | #if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ |
100 | # define _DIRENT_HAVE_D_TYPE /* sigh */ |
147 | #define _DIRENT_HAVE_D_TYPE /* sigh */ |
101 | # define D_INO(de) (de)->d_fileno |
148 | #define D_INO(de) (de)->d_fileno |
102 | # define D_NAMLEN(de) (de)->d_namlen |
149 | #define D_NAMLEN(de) (de)->d_namlen |
103 | # elif __linux || defined d_ino || _XOPEN_SOURCE >= 600 |
150 | #elif __linux || defined d_ino || _XOPEN_SOURCE >= 600 |
104 | # define D_INO(de) (de)->d_ino |
151 | #define D_INO(de) (de)->d_ino |
105 | # endif |
152 | #endif |
106 | |
153 | |
107 | #ifdef _D_EXACT_NAMLEN |
154 | #ifdef _D_EXACT_NAMLEN |
108 | # undef D_NAMLEN |
155 | #undef D_NAMLEN |
109 | # define D_NAMLEN(de) _D_EXACT_NAMLEN (de) |
156 | #define D_NAMLEN(de) _D_EXACT_NAMLEN (de) |
110 | #endif |
157 | #endif |
111 | |
158 | |
112 | # ifdef _DIRENT_HAVE_D_TYPE |
159 | #ifdef _DIRENT_HAVE_D_TYPE |
113 | # define D_TYPE(de) (de)->d_type |
160 | #define D_TYPE(de) (de)->d_type |
114 | # endif |
161 | #endif |
115 | |
162 | |
116 | # ifndef EIO_STRUCT_DIRENT |
163 | #ifndef EIO_STRUCT_DIRENT |
117 | # define EIO_STRUCT_DIRENT struct dirent |
164 | #define EIO_STRUCT_DIRENT struct dirent |
118 | # endif |
165 | #endif |
119 | |
166 | |
120 | #endif |
167 | #endif |
121 | |
168 | |
122 | #if HAVE_SENDFILE |
169 | #if HAVE_SENDFILE |
123 | # if __linux |
170 | # if __linux |
… | |
… | |
200 | /*****************************************************************************/ |
247 | /*****************************************************************************/ |
201 | |
248 | |
202 | #define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) |
249 | #define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) |
203 | |
250 | |
204 | /* calculate time difference in ~1/EIO_TICKS of a second */ |
251 | /* calculate time difference in ~1/EIO_TICKS of a second */ |
205 | ECB_INLINE int |
252 | ecb_inline int |
206 | tvdiff (struct timeval *tv1, struct timeval *tv2) |
253 | tvdiff (struct timeval *tv1, struct timeval *tv2) |
207 | { |
254 | { |
208 | return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS |
255 | return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS |
209 | + ((tv2->tv_usec - tv1->tv_usec) >> 10); |
256 | + ((tv2->tv_usec - tv1->tv_usec) >> 10); |
210 | } |
257 | } |
… | |
… | |
375 | } |
422 | } |
376 | |
423 | |
377 | static void ecb_cold |
424 | static void ecb_cold |
378 | etp_thread_init (void) |
425 | etp_thread_init (void) |
379 | { |
426 | { |
|
|
427 | #if !HAVE_PREADWRITE |
|
|
428 | X_MUTEX_CREATE (preadwritelock); |
|
|
429 | #endif |
380 | X_MUTEX_CREATE (wrklock); |
430 | X_MUTEX_CREATE (wrklock); |
381 | X_MUTEX_CREATE (reslock); |
431 | X_MUTEX_CREATE (reslock); |
382 | X_MUTEX_CREATE (reqlock); |
432 | X_MUTEX_CREATE (reqlock); |
383 | X_COND_CREATE (reqwait); |
433 | X_COND_CREATE (reqwait); |
384 | } |
434 | } |
385 | |
435 | |
386 | static void ecb_cold |
436 | static void ecb_cold |
387 | etp_atfork_prepare (void) |
437 | etp_atfork_prepare (void) |
388 | { |
438 | { |
389 | X_LOCK (wrklock); |
|
|
390 | X_LOCK (reqlock); |
|
|
391 | X_LOCK (reslock); |
|
|
392 | #if !HAVE_PREADWRITE |
|
|
393 | X_LOCK (preadwritelock); |
|
|
394 | #endif |
|
|
395 | } |
439 | } |
396 | |
440 | |
397 | static void ecb_cold |
441 | static void ecb_cold |
398 | etp_atfork_parent (void) |
442 | etp_atfork_parent (void) |
399 | { |
443 | { |
400 | #if !HAVE_PREADWRITE |
|
|
401 | X_UNLOCK (preadwritelock); |
|
|
402 | #endif |
|
|
403 | X_UNLOCK (reslock); |
|
|
404 | X_UNLOCK (reqlock); |
|
|
405 | X_UNLOCK (wrklock); |
|
|
406 | } |
444 | } |
407 | |
445 | |
408 | static void ecb_cold |
446 | static void ecb_cold |
409 | etp_atfork_child (void) |
447 | etp_atfork_child (void) |
410 | { |
448 | { |
… | |
… | |
583 | } |
621 | } |
584 | |
622 | |
585 | static void |
623 | static void |
586 | etp_cancel (ETP_REQ *req) |
624 | etp_cancel (ETP_REQ *req) |
587 | { |
625 | { |
588 | X_LOCK (wrklock); |
626 | req->cancelled = 1; |
589 | req->flags |= EIO_FLAG_CANCELLED; |
|
|
590 | X_UNLOCK (wrklock); |
|
|
591 | |
627 | |
592 | eio_grp_cancel (req); |
628 | eio_grp_cancel (req); |
593 | } |
629 | } |
594 | |
630 | |
595 | static void |
631 | static void |
… | |
… | |
711 | return eio_finish (grp); |
747 | return eio_finish (grp); |
712 | else |
748 | else |
713 | return 0; |
749 | return 0; |
714 | } |
750 | } |
715 | |
751 | |
716 | void |
752 | static void |
717 | eio_destroy (eio_req *req) |
753 | eio_destroy (eio_req *req) |
718 | { |
754 | { |
719 | if ((req)->flags & EIO_FLAG_PTR1_FREE) free (req->ptr1); |
755 | if ((req)->flags & EIO_FLAG_PTR1_FREE) free (req->ptr1); |
720 | if ((req)->flags & EIO_FLAG_PTR2_FREE) free (req->ptr2); |
756 | if ((req)->flags & EIO_FLAG_PTR2_FREE) free (req->ptr2); |
721 | |
757 | |
… | |
… | |
739 | if (grp->grp_first == req) |
775 | if (grp->grp_first == req) |
740 | grp->grp_first = req->grp_next; |
776 | grp->grp_first = req->grp_next; |
741 | |
777 | |
742 | res2 = grp_dec (grp); |
778 | res2 = grp_dec (grp); |
743 | |
779 | |
744 | if (!res && res2) |
780 | if (!res) |
745 | res = res2; |
781 | res = res2; |
746 | } |
782 | } |
747 | |
783 | |
748 | eio_destroy (req); |
784 | eio_destroy (req); |
749 | |
785 | |
… | |
… | |
841 | # undef pread |
877 | # undef pread |
842 | # undef pwrite |
878 | # undef pwrite |
843 | # define pread eio__pread |
879 | # define pread eio__pread |
844 | # define pwrite eio__pwrite |
880 | # define pwrite eio__pwrite |
845 | |
881 | |
846 | static ssize_t |
882 | static eio_ssize_t |
847 | eio__pread (int fd, void *buf, size_t count, off_t offset) |
883 | eio__pread (int fd, void *buf, size_t count, off_t offset) |
848 | { |
884 | { |
849 | ssize_t res; |
885 | eio_ssize_t res; |
850 | off_t ooffset; |
886 | off_t ooffset; |
851 | |
887 | |
852 | X_LOCK (preadwritelock); |
888 | X_LOCK (preadwritelock); |
853 | ooffset = lseek (fd, 0, SEEK_CUR); |
889 | ooffset = lseek (fd, 0, SEEK_CUR); |
854 | lseek (fd, offset, SEEK_SET); |
890 | lseek (fd, offset, SEEK_SET); |
… | |
… | |
857 | X_UNLOCK (preadwritelock); |
893 | X_UNLOCK (preadwritelock); |
858 | |
894 | |
859 | return res; |
895 | return res; |
860 | } |
896 | } |
861 | |
897 | |
862 | static ssize_t |
898 | static eio_ssize_t |
863 | eio__pwrite (int fd, void *buf, size_t count, off_t offset) |
899 | eio__pwrite (int fd, void *buf, size_t count, off_t offset) |
864 | { |
900 | { |
865 | ssize_t res; |
901 | eio_ssize_t res; |
866 | off_t ooffset; |
902 | off_t ooffset; |
867 | |
903 | |
868 | X_LOCK (preadwritelock); |
904 | X_LOCK (preadwritelock); |
869 | ooffset = lseek (fd, 0, SEEK_CUR); |
905 | ooffset = lseek (fd, 0, SEEK_CUR); |
870 | lseek (fd, offset, SEEK_SET); |
906 | lseek (fd, offset, SEEK_SET); |
… | |
… | |
944 | /* even though we could play tricks with the flags, it's better to always |
980 | /* even though we could play tricks with the flags, it's better to always |
945 | * call fdatasync, as that matches the expectation of its users best */ |
981 | * call fdatasync, as that matches the expectation of its users best */ |
946 | return fdatasync (fd); |
982 | return fdatasync (fd); |
947 | } |
983 | } |
948 | |
984 | |
|
|
985 | static int |
|
|
986 | eio__fallocate (int fd, int mode, off_t offset, size_t len) |
|
|
987 | { |
|
|
988 | #if HAVE_FALLOCATE |
|
|
989 | return fallocate (fd, mode, offset, len); |
|
|
990 | #else |
|
|
991 | errno = ENOSYS; |
|
|
992 | return -1; |
|
|
993 | #endif |
|
|
994 | } |
|
|
995 | |
949 | #if !HAVE_READAHEAD |
996 | #if !HAVE_READAHEAD |
950 | # undef readahead |
997 | # undef readahead |
951 | # define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) |
998 | # define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) |
952 | |
999 | |
953 | static ssize_t |
1000 | static eio_ssize_t |
954 | eio__readahead (int fd, off_t offset, size_t count, etp_worker *self) |
1001 | eio__readahead (int fd, off_t offset, size_t count, etp_worker *self) |
955 | { |
1002 | { |
956 | size_t todo = count; |
1003 | size_t todo = count; |
957 | dBUF; |
1004 | dBUF; |
958 | |
1005 | |
… | |
… | |
970 | } |
1017 | } |
971 | |
1018 | |
972 | #endif |
1019 | #endif |
973 | |
1020 | |
974 | /* sendfile always needs emulation */ |
1021 | /* sendfile always needs emulation */ |
975 | static ssize_t |
1022 | static eio_ssize_t |
976 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) |
1023 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) |
977 | { |
1024 | { |
978 | ssize_t written = 0; |
1025 | eio_ssize_t written = 0; |
979 | ssize_t res; |
1026 | eio_ssize_t res; |
980 | |
1027 | |
981 | if (!count) |
1028 | if (!count) |
982 | return 0; |
1029 | return 0; |
983 | |
1030 | |
984 | for (;;) |
1031 | for (;;) |
985 | { |
1032 | { |
|
|
1033 | #ifdef __APPLE__ |
|
|
1034 | # undef HAVE_SENDFILE /* broken, as everything on os x */ |
|
|
1035 | #endif |
986 | #if HAVE_SENDFILE |
1036 | #if HAVE_SENDFILE |
987 | # if __linux |
1037 | # if __linux |
988 | off_t soffset = offset; |
1038 | off_t soffset = offset; |
989 | res = sendfile (ofd, ifd, &soffset, count); |
1039 | res = sendfile (ofd, ifd, &soffset, count); |
990 | |
1040 | |
… | |
… | |
1033 | if (res < 0 && sbytes) |
1083 | if (res < 0 && sbytes) |
1034 | res = sbytes; |
1084 | res = sbytes; |
1035 | |
1085 | |
1036 | # endif |
1086 | # endif |
1037 | |
1087 | |
1038 | #elif defined (_WIN32) |
1088 | #elif defined (_WIN32) && 0 |
1039 | /* does not work, just for documentation of what would need to be done */ |
1089 | /* does not work, just for documentation of what would need to be done */ |
1040 | /* actually, cannot be done like this, as TransmitFile changes the file offset, */ |
1090 | /* actually, cannot be done like this, as TransmitFile changes the file offset, */ |
1041 | /* libeio guarantees that the file offset does not change, and windows */ |
1091 | /* libeio guarantees that the file offset does not change, and windows */ |
1042 | /* has no way to get an independent handle to the same file description */ |
1092 | /* has no way to get an independent handle to the same file description */ |
1043 | HANDLE h = TO_SOCKET (ifd); |
1093 | HANDLE h = TO_SOCKET (ifd); |
… | |
… | |
1090 | |
1140 | |
1091 | res = 0; |
1141 | res = 0; |
1092 | |
1142 | |
1093 | while (count) |
1143 | while (count) |
1094 | { |
1144 | { |
1095 | ssize_t cnt; |
1145 | eio_ssize_t cnt; |
1096 | |
1146 | |
1097 | cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset); |
1147 | cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset); |
1098 | |
1148 | |
1099 | if (cnt <= 0) |
1149 | if (cnt <= 0) |
1100 | { |
1150 | { |
… | |
… | |
1115 | count -= cnt; |
1165 | count -= cnt; |
1116 | } |
1166 | } |
1117 | } |
1167 | } |
1118 | |
1168 | |
1119 | return res; |
1169 | return res; |
|
|
1170 | } |
|
|
1171 | |
|
|
1172 | #ifdef PAGESIZE |
|
|
1173 | # define eio_pagesize() PAGESIZE |
|
|
1174 | #else |
|
|
1175 | static intptr_t |
|
|
1176 | eio_pagesize (void) |
|
|
1177 | { |
|
|
1178 | static intptr_t page; |
|
|
1179 | |
|
|
1180 | if (!page) |
|
|
1181 | page = sysconf (_SC_PAGESIZE); |
|
|
1182 | |
|
|
1183 | return page; |
|
|
1184 | } |
|
|
1185 | #endif |
|
|
1186 | |
|
|
1187 | static void |
|
|
1188 | eio_page_align (void **addr, size_t *length) |
|
|
1189 | { |
|
|
1190 | intptr_t mask = eio_pagesize () - 1; |
|
|
1191 | |
|
|
1192 | /* round down addr */ |
|
|
1193 | intptr_t adj = mask & (intptr_t)*addr; |
|
|
1194 | |
|
|
1195 | *addr = (void *)((intptr_t)*addr - adj); |
|
|
1196 | *length += adj; |
|
|
1197 | |
|
|
1198 | /* round up length */ |
|
|
1199 | *length = (*length + mask) & ~mask; |
|
|
1200 | } |
|
|
1201 | |
|
|
1202 | #if !_POSIX_MEMLOCK |
|
|
1203 | # define eio__mlockall(a) EIO_ENOSYS () |
|
|
1204 | #else |
|
|
1205 | |
|
|
1206 | static int |
|
|
1207 | eio__mlockall (int flags) |
|
|
1208 | { |
|
|
1209 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
|
|
1210 | extern int mallopt (int, int); |
|
|
1211 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1212 | #endif |
|
|
1213 | |
|
|
1214 | if (EIO_MCL_CURRENT != MCL_CURRENT |
|
|
1215 | || EIO_MCL_FUTURE != MCL_FUTURE) |
|
|
1216 | { |
|
|
1217 | flags = 0 |
|
|
1218 | | (flags & EIO_MCL_CURRENT ? MCL_CURRENT : 0) |
|
|
1219 | | (flags & EIO_MCL_FUTURE ? MCL_FUTURE : 0); |
|
|
1220 | } |
|
|
1221 | |
|
|
1222 | return mlockall (flags); |
|
|
1223 | } |
|
|
1224 | #endif |
|
|
1225 | |
|
|
1226 | #if !_POSIX_MEMLOCK_RANGE |
|
|
1227 | # define eio__mlock(a,b) EIO_ENOSYS () |
|
|
1228 | #else |
|
|
1229 | |
|
|
1230 | static int |
|
|
1231 | eio__mlock (void *addr, size_t length) |
|
|
1232 | { |
|
|
1233 | eio_page_align (&addr, &length); |
|
|
1234 | |
|
|
1235 | return mlock (addr, length); |
|
|
1236 | } |
|
|
1237 | |
|
|
1238 | #endif |
|
|
1239 | |
|
|
1240 | #if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) |
|
|
1241 | # define eio__msync(a,b,c) EIO_ENOSYS () |
|
|
1242 | #else |
|
|
1243 | |
|
|
1244 | static int |
|
|
1245 | eio__msync (void *mem, size_t len, int flags) |
|
|
1246 | { |
|
|
1247 | eio_page_align (&mem, &len); |
|
|
1248 | |
|
|
1249 | if (EIO_MS_ASYNC != MS_SYNC |
|
|
1250 | || EIO_MS_INVALIDATE != MS_INVALIDATE |
|
|
1251 | || EIO_MS_SYNC != MS_SYNC) |
|
|
1252 | { |
|
|
1253 | flags = 0 |
|
|
1254 | | (flags & EIO_MS_ASYNC ? MS_ASYNC : 0) |
|
|
1255 | | (flags & EIO_MS_INVALIDATE ? MS_INVALIDATE : 0) |
|
|
1256 | | (flags & EIO_MS_SYNC ? MS_SYNC : 0); |
|
|
1257 | } |
|
|
1258 | |
|
|
1259 | return msync (mem, len, flags); |
|
|
1260 | } |
|
|
1261 | |
|
|
1262 | #endif |
|
|
1263 | |
|
|
1264 | static int |
|
|
1265 | eio__mtouch (eio_req *req) |
|
|
1266 | { |
|
|
1267 | void *mem = req->ptr2; |
|
|
1268 | size_t len = req->size; |
|
|
1269 | int flags = req->int1; |
|
|
1270 | |
|
|
1271 | eio_page_align (&mem, &len); |
|
|
1272 | |
|
|
1273 | { |
|
|
1274 | intptr_t addr = (intptr_t)mem; |
|
|
1275 | intptr_t end = addr + len; |
|
|
1276 | intptr_t page = eio_pagesize (); |
|
|
1277 | |
|
|
1278 | if (addr < end) |
|
|
1279 | if (flags & EIO_MT_MODIFY) /* modify */ |
|
|
1280 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
|
|
1281 | else |
|
|
1282 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
|
|
1283 | } |
|
|
1284 | |
|
|
1285 | return 0; |
|
|
1286 | } |
|
|
1287 | |
|
|
1288 | /*****************************************************************************/ |
|
|
1289 | /* requests implemented outside eio_execute, because they are so large */ |
|
|
1290 | |
|
|
1291 | static void |
|
|
1292 | eio__realpath (eio_req *req, etp_worker *self) |
|
|
1293 | { |
|
|
1294 | char *rel = req->ptr1; |
|
|
1295 | char *res; |
|
|
1296 | char *tmp1, *tmp2; |
|
|
1297 | #if SYMLOOP_MAX > 32 |
|
|
1298 | int symlinks = SYMLOOP_MAX; |
|
|
1299 | #else |
|
|
1300 | int symlinks = 32; |
|
|
1301 | #endif |
|
|
1302 | |
|
|
1303 | req->result = -1; |
|
|
1304 | |
|
|
1305 | errno = EINVAL; |
|
|
1306 | if (!rel) |
|
|
1307 | return; |
|
|
1308 | |
|
|
1309 | errno = ENOENT; |
|
|
1310 | if (!*rel) |
|
|
1311 | return; |
|
|
1312 | |
|
|
1313 | if (!req->ptr2) |
|
|
1314 | { |
|
|
1315 | X_LOCK (wrklock); |
|
|
1316 | req->flags |= EIO_FLAG_PTR2_FREE; |
|
|
1317 | X_UNLOCK (wrklock); |
|
|
1318 | req->ptr2 = malloc (PATH_MAX * 3); |
|
|
1319 | |
|
|
1320 | errno = ENOMEM; |
|
|
1321 | if (!req->ptr2) |
|
|
1322 | return; |
|
|
1323 | } |
|
|
1324 | |
|
|
1325 | res = req->ptr2; |
|
|
1326 | tmp1 = res + PATH_MAX; |
|
|
1327 | tmp2 = tmp1 + PATH_MAX; |
|
|
1328 | |
|
|
1329 | #if 0 /* disabled, the musl way to do things is just too racy */ |
|
|
1330 | #if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) |
|
|
1331 | /* on linux we may be able to ask the kernel */ |
|
|
1332 | { |
|
|
1333 | int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME); |
|
|
1334 | |
|
|
1335 | if (fd >= 0) |
|
|
1336 | { |
|
|
1337 | sprintf (tmp1, "/proc/self/fd/%d", fd); |
|
|
1338 | req->result = readlink (tmp1, res, PATH_MAX); |
|
|
1339 | close (fd); |
|
|
1340 | |
|
|
1341 | /* here we should probably stat the open file and the disk file, to make sure they still match */ |
|
|
1342 | |
|
|
1343 | if (req->result > 0) |
|
|
1344 | goto done; |
|
|
1345 | } |
|
|
1346 | else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO) |
|
|
1347 | return; |
|
|
1348 | } |
|
|
1349 | #endif |
|
|
1350 | #endif |
|
|
1351 | |
|
|
1352 | if (*rel != '/') |
|
|
1353 | { |
|
|
1354 | if (!getcwd (res, PATH_MAX)) |
|
|
1355 | return; |
|
|
1356 | |
|
|
1357 | if (res [1]) /* only use if not / */ |
|
|
1358 | res += strlen (res); |
|
|
1359 | } |
|
|
1360 | |
|
|
1361 | while (*rel) |
|
|
1362 | { |
|
|
1363 | eio_ssize_t len, linklen; |
|
|
1364 | char *beg = rel; |
|
|
1365 | |
|
|
1366 | while (*rel && *rel != '/') |
|
|
1367 | ++rel; |
|
|
1368 | |
|
|
1369 | len = rel - beg; |
|
|
1370 | |
|
|
1371 | if (!len) /* skip slashes */ |
|
|
1372 | { |
|
|
1373 | ++rel; |
|
|
1374 | continue; |
|
|
1375 | } |
|
|
1376 | |
|
|
1377 | if (beg [0] == '.') |
|
|
1378 | { |
|
|
1379 | if (len == 1) |
|
|
1380 | continue; /* . - nop */ |
|
|
1381 | |
|
|
1382 | if (beg [1] == '.' && len == 2) |
|
|
1383 | { |
|
|
1384 | /* .. - back up one component, if possible */ |
|
|
1385 | |
|
|
1386 | while (res != req->ptr2) |
|
|
1387 | if (*--res == '/') |
|
|
1388 | break; |
|
|
1389 | |
|
|
1390 | continue; |
|
|
1391 | } |
|
|
1392 | } |
|
|
1393 | |
|
|
1394 | errno = ENAMETOOLONG; |
|
|
1395 | if (res + 1 + len + 1 >= tmp1) |
|
|
1396 | return; |
|
|
1397 | |
|
|
1398 | /* copy one component */ |
|
|
1399 | *res = '/'; |
|
|
1400 | memcpy (res + 1, beg, len); |
|
|
1401 | |
|
|
1402 | /* zero-terminate, for readlink */ |
|
|
1403 | res [len + 1] = 0; |
|
|
1404 | |
|
|
1405 | /* now check if it's a symlink */ |
|
|
1406 | linklen = readlink (req->ptr2, tmp1, PATH_MAX); |
|
|
1407 | |
|
|
1408 | if (linklen < 0) |
|
|
1409 | { |
|
|
1410 | if (errno != EINVAL) |
|
|
1411 | return; |
|
|
1412 | |
|
|
1413 | /* it's a normal directory. hopefully */ |
|
|
1414 | res += len + 1; |
|
|
1415 | } |
|
|
1416 | else |
|
|
1417 | { |
|
|
1418 | /* yay, it was a symlink - build new path in tmp2 */ |
|
|
1419 | int rellen = strlen (rel); |
|
|
1420 | |
|
|
1421 | errno = ENAMETOOLONG; |
|
|
1422 | if (linklen + 1 + rellen >= PATH_MAX) |
|
|
1423 | return; |
|
|
1424 | |
|
|
1425 | errno = ELOOP; |
|
|
1426 | if (!--symlinks) |
|
|
1427 | return; |
|
|
1428 | |
|
|
1429 | if (*tmp1 == '/') |
|
|
1430 | res = req->ptr2; /* symlink resolves to an absolute path */ |
|
|
1431 | |
|
|
1432 | /* we need to be careful, as rel might point into tmp2 already */ |
|
|
1433 | memmove (tmp2 + linklen + 1, rel, rellen + 1); |
|
|
1434 | tmp2 [linklen] = '/'; |
|
|
1435 | memcpy (tmp2, tmp1, linklen); |
|
|
1436 | |
|
|
1437 | rel = tmp2; |
|
|
1438 | } |
|
|
1439 | } |
|
|
1440 | |
|
|
1441 | /* special case for the lone root path */ |
|
|
1442 | if (res == req->ptr2) |
|
|
1443 | *res++ = '/'; |
|
|
1444 | |
|
|
1445 | req->result = res - (char *)req->ptr2; |
|
|
1446 | |
|
|
1447 | done: |
|
|
1448 | req->ptr2 = realloc (req->ptr2, req->result); /* trade time for space savings */ |
1120 | } |
1449 | } |
1121 | |
1450 | |
1122 | static signed char |
1451 | static signed char |
1123 | eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) |
1452 | eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) |
1124 | { |
1453 | { |
… | |
… | |
1305 | flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER); |
1634 | flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER); |
1306 | |
1635 | |
1307 | X_LOCK (wrklock); |
1636 | X_LOCK (wrklock); |
1308 | /* the corresponding closedir is in ETP_WORKER_CLEAR */ |
1637 | /* the corresponding closedir is in ETP_WORKER_CLEAR */ |
1309 | self->dirp = dirp = opendir (req->ptr1); |
1638 | self->dirp = dirp = opendir (req->ptr1); |
|
|
1639 | |
|
|
1640 | if (req->flags & EIO_FLAG_PTR1_FREE) |
|
|
1641 | free (req->ptr1); |
1310 | |
1642 | |
1311 | req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; |
1643 | req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; |
1312 | req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; |
1644 | req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; |
1313 | req->ptr2 = names = malloc (namesalloc); |
1645 | req->ptr2 = names = malloc (namesalloc); |
1314 | X_UNLOCK (wrklock); |
1646 | X_UNLOCK (wrklock); |
… | |
… | |
1481 | break; |
1813 | break; |
1482 | } |
1814 | } |
1483 | } |
1815 | } |
1484 | } |
1816 | } |
1485 | |
1817 | |
1486 | #ifdef PAGESIZE |
|
|
1487 | # define eio_pagesize() PAGESIZE |
|
|
1488 | #else |
|
|
1489 | static intptr_t |
|
|
1490 | eio_pagesize (void) |
|
|
1491 | { |
|
|
1492 | static intptr_t page; |
|
|
1493 | |
|
|
1494 | if (!page) |
|
|
1495 | page = sysconf (_SC_PAGESIZE); |
|
|
1496 | |
|
|
1497 | return page; |
|
|
1498 | } |
|
|
1499 | #endif |
|
|
1500 | |
|
|
1501 | static void |
|
|
1502 | eio_page_align (void **addr, size_t *length) |
|
|
1503 | { |
|
|
1504 | intptr_t mask = eio_pagesize () - 1; |
|
|
1505 | |
|
|
1506 | /* round down addr */ |
|
|
1507 | intptr_t adj = mask & (intptr_t)*addr; |
|
|
1508 | |
|
|
1509 | *addr = (void *)((intptr_t)*addr - adj); |
|
|
1510 | *length += adj; |
|
|
1511 | |
|
|
1512 | /* round up length */ |
|
|
1513 | *length = (*length + mask) & ~mask; |
|
|
1514 | } |
|
|
1515 | |
|
|
1516 | #if !_POSIX_MEMLOCK |
|
|
1517 | # define eio__mlockall(a) ((errno = ENOSYS), -1) |
|
|
1518 | #else |
|
|
1519 | |
|
|
1520 | static int |
|
|
1521 | eio__mlockall (int flags) |
|
|
1522 | { |
|
|
1523 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
|
|
1524 | extern int mallopt (int, int); |
|
|
1525 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1526 | #endif |
|
|
1527 | |
|
|
1528 | if (EIO_MCL_CURRENT != MCL_CURRENT |
|
|
1529 | || EIO_MCL_FUTURE != MCL_FUTURE) |
|
|
1530 | { |
|
|
1531 | flags = 0 |
|
|
1532 | | (flags & EIO_MCL_CURRENT ? MCL_CURRENT : 0) |
|
|
1533 | | (flags & EIO_MCL_FUTURE ? MCL_FUTURE : 0); |
|
|
1534 | } |
|
|
1535 | |
|
|
1536 | return mlockall (flags); |
|
|
1537 | } |
|
|
1538 | #endif |
|
|
1539 | |
|
|
1540 | #if !_POSIX_MEMLOCK_RANGE |
|
|
1541 | # define eio__mlock(a,b) ((errno = ENOSYS), -1) |
|
|
1542 | #else |
|
|
1543 | |
|
|
1544 | static int |
|
|
1545 | eio__mlock (void *addr, size_t length) |
|
|
1546 | { |
|
|
1547 | eio_page_align (&addr, &length); |
|
|
1548 | |
|
|
1549 | return mlock (addr, length); |
|
|
1550 | } |
|
|
1551 | |
|
|
1552 | #endif |
|
|
1553 | |
|
|
1554 | #if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) |
|
|
1555 | # define eio__msync(a,b,c) ((errno = ENOSYS), -1) |
|
|
1556 | #else |
|
|
1557 | |
|
|
1558 | static int |
|
|
1559 | eio__msync (void *mem, size_t len, int flags) |
|
|
1560 | { |
|
|
1561 | eio_page_align (&mem, &len); |
|
|
1562 | |
|
|
1563 | if (EIO_MS_ASYNC != MS_SYNC |
|
|
1564 | || EIO_MS_INVALIDATE != MS_INVALIDATE |
|
|
1565 | || EIO_MS_SYNC != MS_SYNC) |
|
|
1566 | { |
|
|
1567 | flags = 0 |
|
|
1568 | | (flags & EIO_MS_ASYNC ? MS_ASYNC : 0) |
|
|
1569 | | (flags & EIO_MS_INVALIDATE ? MS_INVALIDATE : 0) |
|
|
1570 | | (flags & EIO_MS_SYNC ? MS_SYNC : 0); |
|
|
1571 | } |
|
|
1572 | |
|
|
1573 | return msync (mem, len, flags); |
|
|
1574 | } |
|
|
1575 | |
|
|
1576 | #endif |
|
|
1577 | |
|
|
1578 | static int |
|
|
1579 | eio__mtouch (eio_req *req) |
|
|
1580 | { |
|
|
1581 | void *mem = req->ptr2; |
|
|
1582 | size_t len = req->size; |
|
|
1583 | int flags = req->int1; |
|
|
1584 | |
|
|
1585 | eio_page_align (&mem, &len); |
|
|
1586 | |
|
|
1587 | { |
|
|
1588 | intptr_t addr = (intptr_t)mem; |
|
|
1589 | intptr_t end = addr + len; |
|
|
1590 | intptr_t page = eio_pagesize (); |
|
|
1591 | |
|
|
1592 | if (addr < end) |
|
|
1593 | if (flags & EIO_MT_MODIFY) /* modify */ |
|
|
1594 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
|
|
1595 | else |
|
|
1596 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
|
|
1597 | } |
|
|
1598 | |
|
|
1599 | return 0; |
|
|
1600 | } |
|
|
1601 | |
|
|
1602 | /*****************************************************************************/ |
1818 | /*****************************************************************************/ |
1603 | |
1819 | |
1604 | #define ALLOC(len) \ |
1820 | #define ALLOC(len) \ |
1605 | if (!req->ptr2) \ |
1821 | if (!req->ptr2) \ |
1606 | { \ |
1822 | { \ |
… | |
… | |
1619 | X_THREAD_PROC (etp_proc) |
1835 | X_THREAD_PROC (etp_proc) |
1620 | { |
1836 | { |
1621 | ETP_REQ *req; |
1837 | ETP_REQ *req; |
1622 | struct timespec ts; |
1838 | struct timespec ts; |
1623 | etp_worker *self = (etp_worker *)thr_arg; |
1839 | etp_worker *self = (etp_worker *)thr_arg; |
|
|
1840 | int timeout; |
1624 | |
1841 | |
1625 | /* try to distribute timeouts somewhat randomly */ |
1842 | /* try to distribute timeouts somewhat evenly */ |
1626 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
1843 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
1627 | |
1844 | |
1628 | for (;;) |
1845 | for (;;) |
1629 | { |
1846 | { |
|
|
1847 | ts.tv_sec = 0; |
|
|
1848 | |
1630 | X_LOCK (reqlock); |
1849 | X_LOCK (reqlock); |
1631 | |
1850 | |
1632 | for (;;) |
1851 | for (;;) |
1633 | { |
1852 | { |
1634 | self->req = req = reqq_shift (&req_queue); |
1853 | self->req = req = reqq_shift (&req_queue); |
1635 | |
1854 | |
1636 | if (req) |
1855 | if (req) |
1637 | break; |
1856 | break; |
1638 | |
1857 | |
|
|
1858 | if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */ |
|
|
1859 | { |
|
|
1860 | X_UNLOCK (reqlock); |
|
|
1861 | X_LOCK (wrklock); |
|
|
1862 | --started; |
|
|
1863 | X_UNLOCK (wrklock); |
|
|
1864 | goto quit; |
|
|
1865 | } |
|
|
1866 | |
1639 | ++idle; |
1867 | ++idle; |
1640 | |
1868 | |
1641 | ts.tv_sec = time (0) + idle_timeout; |
1869 | if (idle <= max_idle) |
1642 | if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT) |
1870 | /* we are allowed to idle, so do so without any timeout */ |
|
|
1871 | X_COND_WAIT (reqwait, reqlock); |
|
|
1872 | else |
1643 | { |
1873 | { |
1644 | if (idle > max_idle) |
1874 | /* initialise timeout once */ |
1645 | { |
1875 | if (!ts.tv_sec) |
1646 | --idle; |
1876 | ts.tv_sec = time (0) + idle_timeout; |
1647 | X_UNLOCK (reqlock); |
|
|
1648 | X_LOCK (wrklock); |
|
|
1649 | --started; |
|
|
1650 | X_UNLOCK (wrklock); |
|
|
1651 | goto quit; |
|
|
1652 | } |
|
|
1653 | |
1877 | |
1654 | /* we are allowed to idle, so do so without any timeout */ |
|
|
1655 | X_COND_WAIT (reqwait, reqlock); |
1878 | if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT) |
|
|
1879 | ts.tv_sec = 1; /* assuming this is not a value computed above.,.. */ |
1656 | } |
1880 | } |
1657 | |
1881 | |
1658 | --idle; |
1882 | --idle; |
1659 | } |
1883 | } |
1660 | |
1884 | |
… | |
… | |
1663 | X_UNLOCK (reqlock); |
1887 | X_UNLOCK (reqlock); |
1664 | |
1888 | |
1665 | if (req->type < 0) |
1889 | if (req->type < 0) |
1666 | goto quit; |
1890 | goto quit; |
1667 | |
1891 | |
1668 | if (!EIO_CANCELLED (req)) |
|
|
1669 | ETP_EXECUTE (self, req); |
1892 | ETP_EXECUTE (self, req); |
1670 | |
1893 | |
1671 | X_LOCK (reslock); |
1894 | X_LOCK (reslock); |
1672 | |
1895 | |
1673 | ++npending; |
1896 | ++npending; |
1674 | |
1897 | |
… | |
… | |
1695 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1918 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1696 | { |
1919 | { |
1697 | return etp_init (want_poll, done_poll); |
1920 | return etp_init (want_poll, done_poll); |
1698 | } |
1921 | } |
1699 | |
1922 | |
1700 | ECB_INLINE void |
1923 | ecb_inline void |
1701 | eio_api_destroy (eio_req *req) |
1924 | eio_api_destroy (eio_req *req) |
1702 | { |
1925 | { |
1703 | free (req); |
1926 | free (req); |
1704 | } |
1927 | } |
1705 | |
1928 | |
… | |
… | |
1728 | } |
1951 | } |
1729 | |
1952 | |
1730 | static void |
1953 | static void |
1731 | eio_execute (etp_worker *self, eio_req *req) |
1954 | eio_execute (etp_worker *self, eio_req *req) |
1732 | { |
1955 | { |
|
|
1956 | if (ecb_expect_false (EIO_CANCELLED (req))) |
|
|
1957 | { |
|
|
1958 | req->result = -1; |
|
|
1959 | req->errorno = ECANCELED; |
|
|
1960 | return; |
|
|
1961 | } |
|
|
1962 | |
1733 | switch (req->type) |
1963 | switch (req->type) |
1734 | { |
1964 | { |
1735 | case EIO_READ: ALLOC (req->size); |
1965 | case EIO_READ: ALLOC (req->size); |
1736 | req->result = req->offs >= 0 |
1966 | req->result = req->offs >= 0 |
1737 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
1967 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
… | |
… | |
1771 | case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break; |
2001 | case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break; |
1772 | case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break; |
2002 | case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break; |
1773 | case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; |
2003 | case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; |
1774 | case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; |
2004 | case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; |
1775 | |
2005 | |
|
|
2006 | case EIO_REALPATH: eio__realpath (req, self); break; |
|
|
2007 | |
1776 | case EIO_READLINK: ALLOC (PATH_MAX); |
2008 | case EIO_READLINK: ALLOC (PATH_MAX); |
1777 | req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; |
2009 | req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; |
1778 | |
2010 | |
1779 | case EIO_SYNC: req->result = 0; sync (); break; |
2011 | case EIO_SYNC: req->result = 0; sync (); break; |
1780 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2012 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
… | |
… | |
1782 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
2014 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
1783 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
2015 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
1784 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
2016 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
1785 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
2017 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
1786 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
2018 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
|
|
2019 | case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; |
1787 | |
2020 | |
1788 | case EIO_READDIR: eio__scandir (req, self); break; |
2021 | case EIO_READDIR: eio__scandir (req, self); break; |
1789 | |
2022 | |
1790 | case EIO_BUSY: |
2023 | case EIO_BUSY: |
1791 | #ifdef _WIN32 |
2024 | #ifdef _WIN32 |
… | |
… | |
1891 | eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
2124 | eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
1892 | { |
2125 | { |
1893 | REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; |
2126 | REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; |
1894 | } |
2127 | } |
1895 | |
2128 | |
|
|
2129 | eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data) |
|
|
2130 | { |
|
|
2131 | REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND; |
|
|
2132 | } |
|
|
2133 | |
1896 | eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
2134 | eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
1897 | { |
2135 | { |
1898 | REQ (EIO_FDATASYNC); req->int1 = fd; SEND; |
2136 | REQ (EIO_FDATASYNC); req->int1 = fd; SEND; |
1899 | } |
2137 | } |
1900 | |
2138 | |
… | |
… | |
1941 | eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) |
2179 | eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) |
1942 | { |
2180 | { |
1943 | REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; |
2181 | REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; |
1944 | } |
2182 | } |
1945 | |
2183 | |
1946 | eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
2184 | eio_req *eio_fchown (int fd, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data) |
1947 | { |
2185 | { |
1948 | REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; |
2186 | REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; |
1949 | } |
2187 | } |
1950 | |
2188 | |
1951 | eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) |
2189 | eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) |
… | |
… | |
1971 | eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) |
2209 | eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) |
1972 | { |
2210 | { |
1973 | REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; |
2211 | REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; |
1974 | } |
2212 | } |
1975 | |
2213 | |
1976 | eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
2214 | eio_req *eio_chown (const char *path, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data) |
1977 | { |
2215 | { |
1978 | REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; |
2216 | REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; |
1979 | } |
2217 | } |
1980 | |
2218 | |
1981 | eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
2219 | eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
… | |
… | |
1995 | } |
2233 | } |
1996 | |
2234 | |
1997 | eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data) |
2235 | eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data) |
1998 | { |
2236 | { |
1999 | return eio__1path (EIO_READLINK, path, pri, cb, data); |
2237 | return eio__1path (EIO_READLINK, path, pri, cb, data); |
|
|
2238 | } |
|
|
2239 | |
|
|
2240 | eio_req *eio_realpath (const char *path, int pri, eio_cb cb, void *data) |
|
|
2241 | { |
|
|
2242 | return eio__1path (EIO_REALPATH, path, pri, cb, data); |
2000 | } |
2243 | } |
2001 | |
2244 | |
2002 | eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data) |
2245 | eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data) |
2003 | { |
2246 | { |
2004 | return eio__1path (EIO_STAT, path, pri, cb, data); |
2247 | return eio__1path (EIO_STAT, path, pri, cb, data); |
… | |
… | |
2123 | } |
2366 | } |
2124 | |
2367 | |
2125 | /*****************************************************************************/ |
2368 | /*****************************************************************************/ |
2126 | /* misc garbage */ |
2369 | /* misc garbage */ |
2127 | |
2370 | |
2128 | ssize_t |
2371 | eio_ssize_t |
2129 | eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) |
2372 | eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) |
2130 | { |
2373 | { |
2131 | etp_worker wrk; |
2374 | etp_worker wrk; |
2132 | ssize_t ret; |
2375 | eio_ssize_t ret; |
2133 | |
2376 | |
2134 | wrk.dbuf = 0; |
2377 | wrk.dbuf = 0; |
2135 | |
2378 | |
2136 | ret = eio__sendfile (ofd, ifd, offset, count, &wrk); |
2379 | ret = eio__sendfile (ofd, ifd, offset, count, &wrk); |
2137 | |
2380 | |