… | |
… | |
132 | #define sync() EIO_ENOSYS () |
132 | #define sync() EIO_ENOSYS () |
133 | #define readlink(path,buf,s) EIO_ENOSYS () |
133 | #define readlink(path,buf,s) EIO_ENOSYS () |
134 | #define statvfs(path,buf) EIO_ENOSYS () |
134 | #define statvfs(path,buf) EIO_ENOSYS () |
135 | #define fstatvfs(fd,buf) EIO_ENOSYS () |
135 | #define fstatvfs(fd,buf) EIO_ENOSYS () |
136 | |
136 | |
|
|
137 | #define pread(fd,buf,count,offset) eio__pread (fd, buf, count, offset) |
|
|
138 | #define pwrite(fd,buf,count,offset) eio__pwrite (fd, buf, count, offset) |
|
|
139 | |
|
|
140 | #if __GNUC__ |
|
|
141 | typedef long long eio_off_t; /* signed for compatibility to msvc */ |
|
|
142 | #else |
|
|
143 | typedef __int64 eio_off_t; /* unsigned not supported by msvc */ |
|
|
144 | #endif |
|
|
145 | |
|
|
146 | static eio_ssize_t |
|
|
147 | eio__pread (int fd, void *buf, eio_ssize_t count, eio_off_t offset) |
|
|
148 | { |
|
|
149 | OVERLAPPED o = { 0 }; |
|
|
150 | DWORD got; |
|
|
151 | |
|
|
152 | o.Offset = offset; |
|
|
153 | o.OffsetHigh = offset >> 32; |
|
|
154 | |
|
|
155 | return ReadFile ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd), buf, count, &got, &o) |
|
|
156 | ? got : -1; |
|
|
157 | } |
|
|
158 | |
|
|
159 | static eio_ssize_t |
|
|
160 | eio__pwrite (int fd, void *buf, eio_ssize_t count, eio_off_t offset) |
|
|
161 | { |
|
|
162 | OVERLAPPED o = { 0 }; |
|
|
163 | DWORD got; |
|
|
164 | |
|
|
165 | o.Offset = offset; |
|
|
166 | o.OffsetHigh = offset >> 32; |
|
|
167 | |
|
|
168 | return WriteFile ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd), buf, count, &got, &o) |
|
|
169 | ? got : -1; |
|
|
170 | } |
|
|
171 | |
137 | /* rename() uses MoveFile, which fails to overwrite */ |
172 | /* rename() uses MoveFile, which fails to overwrite */ |
138 | #define rename(old,neu) eio__rename (old, neu) |
173 | #define rename(old,neu) eio__rename (old, neu) |
139 | |
174 | |
140 | static int |
175 | static int |
141 | eio__rename (const char *old, const char *neu) |
176 | eio__rename (const char *old, const char *neu) |
… | |
… | |
379 | static xmutex_t wrklock; |
414 | static xmutex_t wrklock; |
380 | static xmutex_t reslock; |
415 | static xmutex_t reslock; |
381 | static xmutex_t reqlock; |
416 | static xmutex_t reqlock; |
382 | static xcond_t reqwait; |
417 | static xcond_t reqwait; |
383 | |
418 | |
384 | #if !HAVE_PREADWRITE |
|
|
385 | /* |
|
|
386 | * make our pread/pwrite emulation safe against themselves, but not against |
|
|
387 | * normal read/write by using a mutex. slows down execution a lot, |
|
|
388 | * but that's your problem, not mine. |
|
|
389 | */ |
|
|
390 | static xmutex_t preadwritelock; |
|
|
391 | #endif |
|
|
392 | |
|
|
393 | typedef struct etp_worker |
419 | typedef struct etp_worker |
394 | { |
420 | { |
395 | struct tmpbuf tmpbuf; |
421 | struct tmpbuf tmpbuf; |
396 | |
422 | |
397 | /* locked by wrklock */ |
423 | /* locked by wrklock */ |
… | |
… | |
942 | return etp_poll (); |
968 | return etp_poll (); |
943 | } |
969 | } |
944 | |
970 | |
945 | /*****************************************************************************/ |
971 | /*****************************************************************************/ |
946 | /* work around various missing functions */ |
972 | /* work around various missing functions */ |
947 | |
|
|
948 | #if !HAVE_PREADWRITE |
|
|
949 | # undef pread |
|
|
950 | # undef pwrite |
|
|
951 | # define pread eio__pread |
|
|
952 | # define pwrite eio__pwrite |
|
|
953 | |
|
|
954 | static eio_ssize_t |
|
|
955 | eio__pread (int fd, void *buf, size_t count, off_t offset) |
|
|
956 | { |
|
|
957 | eio_ssize_t res; |
|
|
958 | off_t ooffset; |
|
|
959 | |
|
|
960 | X_LOCK (preadwritelock); |
|
|
961 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
962 | lseek (fd, offset, SEEK_SET); |
|
|
963 | res = read (fd, buf, count); |
|
|
964 | lseek (fd, ooffset, SEEK_SET); |
|
|
965 | X_UNLOCK (preadwritelock); |
|
|
966 | |
|
|
967 | return res; |
|
|
968 | } |
|
|
969 | |
|
|
970 | static eio_ssize_t |
|
|
971 | eio__pwrite (int fd, void *buf, size_t count, off_t offset) |
|
|
972 | { |
|
|
973 | eio_ssize_t res; |
|
|
974 | off_t ooffset; |
|
|
975 | |
|
|
976 | X_LOCK (preadwritelock); |
|
|
977 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
978 | lseek (fd, offset, SEEK_SET); |
|
|
979 | res = write (fd, buf, count); |
|
|
980 | lseek (fd, ooffset, SEEK_SET); |
|
|
981 | X_UNLOCK (preadwritelock); |
|
|
982 | |
|
|
983 | return res; |
|
|
984 | } |
|
|
985 | #endif |
|
|
986 | |
973 | |
987 | #ifndef HAVE_UTIMES |
974 | #ifndef HAVE_UTIMES |
988 | |
975 | |
989 | # undef utimes |
976 | # undef utimes |
990 | # define utimes(path,times) eio__utimes (path, times) |
977 | # define utimes(path,times) eio__utimes (path, times) |
… | |
… | |
1931 | #ifdef DT_FIFO |
1918 | #ifdef DT_FIFO |
1932 | case DT_FIFO: ent->type = EIO_DT_FIFO; break; |
1919 | case DT_FIFO: ent->type = EIO_DT_FIFO; break; |
1933 | #endif |
1920 | #endif |
1934 | #ifdef DT_CHR |
1921 | #ifdef DT_CHR |
1935 | case DT_CHR: ent->type = EIO_DT_CHR; break; |
1922 | case DT_CHR: ent->type = EIO_DT_CHR; break; |
1936 | #endif |
1923 | #endif |
1937 | #ifdef DT_MPC |
1924 | #ifdef DT_MPC |
1938 | case DT_MPC: ent->type = EIO_DT_MPC; break; |
1925 | case DT_MPC: ent->type = EIO_DT_MPC; break; |
1939 | #endif |
1926 | #endif |
1940 | #ifdef DT_DIR |
1927 | #ifdef DT_DIR |
1941 | case DT_DIR: ent->type = EIO_DT_DIR; break; |
1928 | case DT_DIR: ent->type = EIO_DT_DIR; break; |
1942 | #endif |
1929 | #endif |
1943 | #ifdef DT_NAM |
1930 | #ifdef DT_NAM |
1944 | case DT_NAM: ent->type = EIO_DT_NAM; break; |
1931 | case DT_NAM: ent->type = EIO_DT_NAM; break; |
1945 | #endif |
1932 | #endif |
1946 | #ifdef DT_BLK |
1933 | #ifdef DT_BLK |
1947 | case DT_BLK: ent->type = EIO_DT_BLK; break; |
1934 | case DT_BLK: ent->type = EIO_DT_BLK; break; |
1948 | #endif |
1935 | #endif |
1949 | #ifdef DT_MPB |
1936 | #ifdef DT_MPB |
1950 | case DT_MPB: ent->type = EIO_DT_MPB; break; |
1937 | case DT_MPB: ent->type = EIO_DT_MPB; break; |
1951 | #endif |
1938 | #endif |
1952 | #ifdef DT_REG |
1939 | #ifdef DT_REG |
1953 | case DT_REG: ent->type = EIO_DT_REG; break; |
1940 | case DT_REG: ent->type = EIO_DT_REG; break; |
1954 | #endif |
1941 | #endif |
1955 | #ifdef DT_NWK |
1942 | #ifdef DT_NWK |
1956 | case DT_NWK: ent->type = EIO_DT_NWK; break; |
1943 | case DT_NWK: ent->type = EIO_DT_NWK; break; |
1957 | #endif |
1944 | #endif |
1958 | #ifdef DT_CMP |
1945 | #ifdef DT_CMP |
1959 | case DT_CMP: ent->type = EIO_DT_CMP; break; |
1946 | case DT_CMP: ent->type = EIO_DT_CMP; break; |
1960 | #endif |
1947 | #endif |
1961 | #ifdef DT_LNK |
1948 | #ifdef DT_LNK |
1962 | case DT_LNK: ent->type = EIO_DT_LNK; break; |
1949 | case DT_LNK: ent->type = EIO_DT_LNK; break; |
1963 | #endif |
1950 | #endif |
1964 | #ifdef DT_SOCK |
1951 | #ifdef DT_SOCK |
1965 | case DT_SOCK: ent->type = EIO_DT_SOCK; break; |
1952 | case DT_SOCK: ent->type = EIO_DT_SOCK; break; |
… | |
… | |
2249 | /*****************************************************************************/ |
2236 | /*****************************************************************************/ |
2250 | |
2237 | |
2251 | int ecb_cold |
2238 | int ecb_cold |
2252 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
2239 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
2253 | { |
2240 | { |
2254 | #if !HAVE_PREADWRITE |
|
|
2255 | X_MUTEX_CREATE (preadwritelock); |
|
|
2256 | #endif |
|
|
2257 | |
|
|
2258 | return etp_init (want_poll, done_poll); |
2241 | return etp_init (want_poll, done_poll); |
2259 | } |
2242 | } |
2260 | |
2243 | |
2261 | ecb_inline void |
2244 | ecb_inline void |
2262 | eio_api_destroy (eio_req *req) |
2245 | eio_api_destroy (eio_req *req) |
2263 | { |
2246 | { |
2264 | free (req); |
2247 | free (req); |
2265 | } |
2248 | } |
2266 | |
2249 | |
2267 | #define REQ(rtype) \ |
2250 | #define REQ(rtype) \ |
2268 | eio_req *req; \ |
2251 | eio_req *req; \ |
2269 | \ |
2252 | \ |
2270 | req = (eio_req *)calloc (1, sizeof *req); \ |
2253 | req = (eio_req *)calloc (1, sizeof *req); \ |
2271 | if (!req) \ |
2254 | if (!req) \ |
2272 | return 0; \ |
2255 | return 0; \ |