… | |
… | |
71 | #endif |
71 | #endif |
72 | #ifndef ELOOP |
72 | #ifndef ELOOP |
73 | # define ELOOP EDOM |
73 | # define ELOOP EDOM |
74 | #endif |
74 | #endif |
75 | |
75 | |
|
|
76 | #if !defined(ENOTSOCK) && defined(WSAENOTSOCK) |
|
|
77 | # define ENOTSOCK WSAENOTSOCK |
|
|
78 | #endif |
|
|
79 | |
76 | static void eio_destroy (eio_req *req); |
80 | static void eio_destroy (eio_req *req); |
77 | |
81 | |
78 | #ifndef EIO_FINISH |
82 | #ifndef EIO_FINISH |
79 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
83 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
80 | #endif |
84 | #endif |
… | |
… | |
103 | #undef PAGESIZE |
107 | #undef PAGESIZE |
104 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
108 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
105 | |
109 | |
106 | #ifdef EIO_STRUCT_STATI64 |
110 | #ifdef EIO_STRUCT_STATI64 |
107 | #define stat(path,buf) _stati64 (path,buf) |
111 | #define stat(path,buf) _stati64 (path,buf) |
108 | #define fstat(fd,buf) _fstati64 (path,buf) |
112 | #define fstat(fd,buf) _fstati64 (fd,buf) |
109 | #endif |
113 | #endif |
110 | #define lstat(path,buf) stat (path,buf) |
114 | #define lstat(path,buf) stat (path,buf) |
111 | #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) |
115 | #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) |
112 | #define mkdir(path,mode) _mkdir (path) |
116 | #define mkdir(path,mode) _mkdir (path) |
113 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
117 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
… | |
… | |
125 | #define sync() EIO_ENOSYS () |
129 | #define sync() EIO_ENOSYS () |
126 | #define readlink(path,buf,s) EIO_ENOSYS () |
130 | #define readlink(path,buf,s) EIO_ENOSYS () |
127 | #define statvfs(path,buf) EIO_ENOSYS () |
131 | #define statvfs(path,buf) EIO_ENOSYS () |
128 | #define fstatvfs(fd,buf) EIO_ENOSYS () |
132 | #define fstatvfs(fd,buf) EIO_ENOSYS () |
129 | |
133 | |
|
|
134 | /* rename() uses MoveFile, which fails to overwrite */ |
|
|
135 | #define rename(old,neu) eio__rename (old, neu) |
|
|
136 | |
|
|
137 | static int |
|
|
138 | eio__rename (const char *old, const char *neu) |
|
|
139 | { |
|
|
140 | if (MoveFileEx (old, neu, MOVEFILE_REPLACE_EXISTING)) |
|
|
141 | return 0; |
|
|
142 | |
|
|
143 | /* should steal _dosmaperr */ |
|
|
144 | switch (GetLastError ()) |
|
|
145 | { |
|
|
146 | case ERROR_FILE_NOT_FOUND: |
|
|
147 | case ERROR_PATH_NOT_FOUND: |
|
|
148 | case ERROR_INVALID_DRIVE: |
|
|
149 | case ERROR_NO_MORE_FILES: |
|
|
150 | case ERROR_BAD_NETPATH: |
|
|
151 | case ERROR_BAD_NET_NAME: |
|
|
152 | case ERROR_BAD_PATHNAME: |
|
|
153 | case ERROR_FILENAME_EXCED_RANGE: |
|
|
154 | errno = ENOENT; |
|
|
155 | break; |
|
|
156 | |
|
|
157 | default: |
|
|
158 | errno = EACCES; |
|
|
159 | break; |
|
|
160 | } |
|
|
161 | |
|
|
162 | return -1; |
|
|
163 | } |
|
|
164 | |
130 | /* we could even stat and see if it exists */ |
165 | /* we could even stat and see if it exists */ |
131 | static int |
166 | static int |
132 | symlink (const char *old, const char *neu) |
167 | symlink (const char *old, const char *neu) |
133 | { |
168 | { |
134 | #if WINVER >= 0x0600 |
169 | #if WINVER >= 0x0600 |
… | |
… | |
160 | |
195 | |
161 | #include <sys/time.h> |
196 | #include <sys/time.h> |
162 | #include <sys/select.h> |
197 | #include <sys/select.h> |
163 | #include <sys/statvfs.h> |
198 | #include <sys/statvfs.h> |
164 | #include <unistd.h> |
199 | #include <unistd.h> |
165 | #include <utime.h> |
|
|
166 | #include <signal.h> |
200 | #include <signal.h> |
167 | #include <dirent.h> |
201 | #include <dirent.h> |
168 | |
202 | |
169 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
203 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
170 | #include <sys/mman.h> |
204 | #include <sys/mman.h> |
… | |
… | |
192 | |
226 | |
193 | #ifndef EIO_STRUCT_DIRENT |
227 | #ifndef EIO_STRUCT_DIRENT |
194 | #define EIO_STRUCT_DIRENT struct dirent |
228 | #define EIO_STRUCT_DIRENT struct dirent |
195 | #endif |
229 | #endif |
196 | |
230 | |
|
|
231 | #endif |
|
|
232 | |
|
|
233 | #if HAVE_UTIMES |
|
|
234 | # include <utime.h> |
|
|
235 | #endif |
|
|
236 | |
|
|
237 | #if HAVE_SYS_SYSCALL_H |
|
|
238 | # include <sys/syscall.h> |
|
|
239 | #endif |
|
|
240 | |
|
|
241 | #if HAVE_SYS_PRCTL_H |
|
|
242 | # include <sys/prctl.h> |
197 | #endif |
243 | #endif |
198 | |
244 | |
199 | #if HAVE_SENDFILE |
245 | #if HAVE_SENDFILE |
200 | # if __linux |
246 | # if __linux |
201 | # include <sys/sendfile.h> |
247 | # include <sys/sendfile.h> |
… | |
… | |
929 | |
975 | |
930 | #if !HAVE_FDATASYNC |
976 | #if !HAVE_FDATASYNC |
931 | # undef fdatasync |
977 | # undef fdatasync |
932 | # define fdatasync(fd) fsync (fd) |
978 | # define fdatasync(fd) fsync (fd) |
933 | #endif |
979 | #endif |
|
|
980 | |
|
|
981 | static int |
|
|
982 | eio__syncfs (int fd) |
|
|
983 | { |
|
|
984 | int res; |
|
|
985 | |
|
|
986 | #if HAVE_SYS_SYNCFS |
|
|
987 | res = (int)syscall (__NR_syncfs, (int)(fd)); |
|
|
988 | #else |
|
|
989 | res = -1; |
|
|
990 | errno = ENOSYS; |
|
|
991 | #endif |
|
|
992 | |
|
|
993 | if (res < 0 && errno == ENOSYS && fd >= 0) |
|
|
994 | sync (); |
|
|
995 | |
|
|
996 | return res; |
|
|
997 | } |
934 | |
998 | |
935 | /* sync_file_range always needs emulation */ |
999 | /* sync_file_range always needs emulation */ |
936 | static int |
1000 | static int |
937 | eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) |
1001 | eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) |
938 | { |
1002 | { |
… | |
… | |
1641 | |
1705 | |
1642 | if (dirp == INVALID_HANDLE_VALUE) |
1706 | if (dirp == INVALID_HANDLE_VALUE) |
1643 | { |
1707 | { |
1644 | dirp = 0; |
1708 | dirp = 0; |
1645 | |
1709 | |
|
|
1710 | /* should steal _dosmaperr */ |
1646 | switch (GetLastError ()) |
1711 | switch (GetLastError ()) |
1647 | { |
1712 | { |
1648 | case ERROR_FILE_NOT_FOUND: |
1713 | case ERROR_FILE_NOT_FOUND: |
1649 | req->result = 0; |
1714 | req->result = 0; |
1650 | break; |
1715 | break; |
… | |
… | |
1884 | { |
1949 | { |
1885 | ETP_REQ *req; |
1950 | ETP_REQ *req; |
1886 | struct timespec ts; |
1951 | struct timespec ts; |
1887 | etp_worker *self = (etp_worker *)thr_arg; |
1952 | etp_worker *self = (etp_worker *)thr_arg; |
1888 | |
1953 | |
|
|
1954 | #if HAVE_PRCTL_SET_NAME |
|
|
1955 | prctl (PR_SET_NAME, (unsigned long)"eio_thread", 0, 0, 0); |
|
|
1956 | #endif |
|
|
1957 | |
1889 | /* try to distribute timeouts somewhat evenly */ |
1958 | /* try to distribute timeouts somewhat evenly */ |
1890 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
1959 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
1891 | |
1960 | |
1892 | for (;;) |
1961 | for (;;) |
1893 | { |
1962 | { |
… | |
… | |
2060 | req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; |
2129 | req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; |
2061 | |
2130 | |
2062 | case EIO_SYNC: req->result = 0; sync (); break; |
2131 | case EIO_SYNC: req->result = 0; sync (); break; |
2063 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2132 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2064 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
2133 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
|
|
2134 | case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; |
|
|
2135 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
2065 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
2136 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
2066 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
2137 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
2067 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
2138 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
2068 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
2139 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
2069 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
|
|
2070 | case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; |
2140 | case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; |
2071 | |
2141 | |
2072 | case EIO_READDIR: eio__scandir (req, self); break; |
2142 | case EIO_READDIR: eio__scandir (req, self); break; |
2073 | |
2143 | |
2074 | case EIO_BUSY: |
2144 | case EIO_BUSY: |
… | |
… | |
2155 | eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2225 | eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2156 | { |
2226 | { |
2157 | REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2227 | REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2158 | } |
2228 | } |
2159 | |
2229 | |
|
|
2230 | eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
|
|
2231 | { |
|
|
2232 | REQ (EIO_FDATASYNC); req->int1 = fd; SEND; |
|
|
2233 | } |
|
|
2234 | |
|
|
2235 | eio_req *eio_syncfs (int fd, int pri, eio_cb cb, void *data) |
|
|
2236 | { |
|
|
2237 | REQ (EIO_SYNCFS); req->int1 = fd; SEND; |
|
|
2238 | } |
|
|
2239 | |
|
|
2240 | eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
|
|
2241 | { |
|
|
2242 | REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; |
|
|
2243 | } |
|
|
2244 | |
2160 | eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2245 | eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2161 | { |
2246 | { |
2162 | REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2247 | REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2163 | } |
2248 | } |
2164 | |
2249 | |
… | |
… | |
2170 | eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data) |
2255 | eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data) |
2171 | { |
2256 | { |
2172 | REQ (EIO_MLOCKALL); req->int1 = flags; SEND; |
2257 | REQ (EIO_MLOCKALL); req->int1 = flags; SEND; |
2173 | } |
2258 | } |
2174 | |
2259 | |
2175 | eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
|
|
2176 | { |
|
|
2177 | REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; |
|
|
2178 | } |
|
|
2179 | |
|
|
2180 | eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data) |
2260 | eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data) |
2181 | { |
2261 | { |
2182 | REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND; |
2262 | REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND; |
2183 | } |
|
|
2184 | |
|
|
2185 | eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
|
|
2186 | { |
|
|
2187 | REQ (EIO_FDATASYNC); req->int1 = fd; SEND; |
|
|
2188 | } |
2263 | } |
2189 | |
2264 | |
2190 | eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) |
2265 | eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) |
2191 | { |
2266 | { |
2192 | REQ (EIO_CLOSE); req->int1 = fd; SEND; |
2267 | REQ (EIO_CLOSE); req->int1 = fd; SEND; |