… | |
… | |
43 | |
43 | |
44 | #include "eio.h" |
44 | #include "eio.h" |
45 | #include "ecb.h" |
45 | #include "ecb.h" |
46 | |
46 | |
47 | #ifdef EIO_STACKSIZE |
47 | #ifdef EIO_STACKSIZE |
48 | # define XTHREAD_STACKSIZE EIO_STACKSIZE |
48 | # define X_STACKSIZE EIO_STACKSIZE |
49 | #endif |
49 | #endif |
50 | #include "xthread.h" |
50 | #include "xthread.h" |
51 | |
51 | |
52 | #include <errno.h> |
52 | #include <errno.h> |
53 | #include <stddef.h> |
53 | #include <stddef.h> |
… | |
… | |
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 |
… | |
… | |
101 | #ifdef _WIN32 |
105 | #ifdef _WIN32 |
102 | |
106 | |
103 | #undef PAGESIZE |
107 | #undef PAGESIZE |
104 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
108 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
105 | |
109 | |
|
|
110 | /* TODO: look at how perl does stat (non-sloppy), unlink (ro-files), utime, link */ |
|
|
111 | |
106 | #ifdef EIO_STRUCT_STATI64 |
112 | #ifdef EIO_STRUCT_STATI64 |
|
|
113 | /* look at perl's non-sloppy stat */ |
107 | #define stat(path,buf) _stati64 (path,buf) |
114 | #define stat(path,buf) _stati64 (path,buf) |
108 | #define fstat(fd,buf) _fstati64 (path,buf) |
115 | #define fstat(fd,buf) _fstati64 (fd,buf) |
109 | #endif |
116 | #endif |
110 | #define lstat(path,buf) stat (path,buf) |
117 | #define lstat(path,buf) stat (path,buf) |
111 | #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) |
118 | #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) |
112 | #define mkdir(path,mode) _mkdir (path) |
119 | #define mkdir(path,mode) _mkdir (path) |
113 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
120 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
… | |
… | |
125 | #define sync() EIO_ENOSYS () |
132 | #define sync() EIO_ENOSYS () |
126 | #define readlink(path,buf,s) EIO_ENOSYS () |
133 | #define readlink(path,buf,s) EIO_ENOSYS () |
127 | #define statvfs(path,buf) EIO_ENOSYS () |
134 | #define statvfs(path,buf) EIO_ENOSYS () |
128 | #define fstatvfs(fd,buf) EIO_ENOSYS () |
135 | #define fstatvfs(fd,buf) EIO_ENOSYS () |
129 | |
136 | |
|
|
137 | /* rename() uses MoveFile, which fails to overwrite */ |
|
|
138 | #define rename(old,neu) eio__rename (old, neu) |
|
|
139 | |
|
|
140 | static int |
|
|
141 | eio__rename (const char *old, const char *neu) |
|
|
142 | { |
|
|
143 | if (MoveFileEx (old, neu, MOVEFILE_REPLACE_EXISTING)) |
|
|
144 | return 0; |
|
|
145 | |
|
|
146 | /* should steal _dosmaperr */ |
|
|
147 | switch (GetLastError ()) |
|
|
148 | { |
|
|
149 | case ERROR_FILE_NOT_FOUND: |
|
|
150 | case ERROR_PATH_NOT_FOUND: |
|
|
151 | case ERROR_INVALID_DRIVE: |
|
|
152 | case ERROR_NO_MORE_FILES: |
|
|
153 | case ERROR_BAD_NETPATH: |
|
|
154 | case ERROR_BAD_NET_NAME: |
|
|
155 | case ERROR_BAD_PATHNAME: |
|
|
156 | case ERROR_FILENAME_EXCED_RANGE: |
|
|
157 | errno = ENOENT; |
|
|
158 | break; |
|
|
159 | |
|
|
160 | default: |
|
|
161 | errno = EACCES; |
|
|
162 | break; |
|
|
163 | } |
|
|
164 | |
|
|
165 | return -1; |
|
|
166 | } |
|
|
167 | |
130 | /* we could even stat and see if it exists */ |
168 | /* we could even stat and see if it exists */ |
131 | static int |
169 | static int |
132 | symlink (const char *old, const char *neu) |
170 | symlink (const char *old, const char *neu) |
133 | { |
171 | { |
134 | #if WINVER >= 0x0600 |
172 | #if WINVER >= 0x0600 |
… | |
… | |
160 | |
198 | |
161 | #include <sys/time.h> |
199 | #include <sys/time.h> |
162 | #include <sys/select.h> |
200 | #include <sys/select.h> |
163 | #include <sys/statvfs.h> |
201 | #include <sys/statvfs.h> |
164 | #include <unistd.h> |
202 | #include <unistd.h> |
165 | #include <utime.h> |
|
|
166 | #include <signal.h> |
203 | #include <signal.h> |
167 | #include <dirent.h> |
204 | #include <dirent.h> |
168 | |
205 | |
169 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
206 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
170 | #include <sys/mman.h> |
207 | #include <sys/mman.h> |
… | |
… | |
192 | |
229 | |
193 | #ifndef EIO_STRUCT_DIRENT |
230 | #ifndef EIO_STRUCT_DIRENT |
194 | #define EIO_STRUCT_DIRENT struct dirent |
231 | #define EIO_STRUCT_DIRENT struct dirent |
195 | #endif |
232 | #endif |
196 | |
233 | |
|
|
234 | #endif |
|
|
235 | |
|
|
236 | #if HAVE_UTIMES |
|
|
237 | # include <utime.h> |
|
|
238 | #endif |
|
|
239 | |
|
|
240 | #if HAVE_SYS_SYSCALL_H |
|
|
241 | # include <sys/syscall.h> |
|
|
242 | #endif |
|
|
243 | |
|
|
244 | #if HAVE_SYS_PRCTL_H |
|
|
245 | # include <sys/prctl.h> |
197 | #endif |
246 | #endif |
198 | |
247 | |
199 | #if HAVE_SENDFILE |
248 | #if HAVE_SENDFILE |
200 | # if __linux |
249 | # if __linux |
201 | # include <sys/sendfile.h> |
250 | # include <sys/sendfile.h> |
… | |
… | |
233 | |
282 | |
234 | /* buffer size for various temporary buffers */ |
283 | /* buffer size for various temporary buffers */ |
235 | #define EIO_BUFSIZE 65536 |
284 | #define EIO_BUFSIZE 65536 |
236 | |
285 | |
237 | #define dBUF \ |
286 | #define dBUF \ |
238 | char *eio_buf; \ |
|
|
239 | ETP_WORKER_LOCK (self); \ |
|
|
240 | self->dbuf = eio_buf = malloc (EIO_BUFSIZE); \ |
287 | char *eio_buf = malloc (EIO_BUFSIZE); \ |
241 | ETP_WORKER_UNLOCK (self); \ |
|
|
242 | errno = ENOMEM; \ |
288 | errno = ENOMEM; \ |
243 | if (!eio_buf) \ |
289 | if (!eio_buf) \ |
244 | return -1; |
290 | return -1 |
|
|
291 | |
|
|
292 | #define FUBd \ |
|
|
293 | free (eio_buf) |
245 | |
294 | |
246 | #define EIO_TICKS ((1000000 + 1023) >> 10) |
295 | #define EIO_TICKS ((1000000 + 1023) >> 10) |
|
|
296 | |
|
|
297 | /*****************************************************************************/ |
|
|
298 | |
|
|
299 | struct tmpbuf |
|
|
300 | { |
|
|
301 | void *ptr; |
|
|
302 | int len; |
|
|
303 | }; |
|
|
304 | |
|
|
305 | static void * |
|
|
306 | tmpbuf_get (struct tmpbuf *buf, int len) |
|
|
307 | { |
|
|
308 | if (buf->len < len) |
|
|
309 | { |
|
|
310 | free (buf->ptr); |
|
|
311 | buf->ptr = malloc (buf->len = len); |
|
|
312 | } |
|
|
313 | |
|
|
314 | return buf->ptr; |
|
|
315 | } |
|
|
316 | |
|
|
317 | /*****************************************************************************/ |
247 | |
318 | |
248 | #define ETP_PRI_MIN EIO_PRI_MIN |
319 | #define ETP_PRI_MIN EIO_PRI_MIN |
249 | #define ETP_PRI_MAX EIO_PRI_MAX |
320 | #define ETP_PRI_MAX EIO_PRI_MAX |
250 | |
321 | |
251 | struct etp_worker; |
322 | struct etp_worker; |
… | |
… | |
255 | static int eio_finish (eio_req *req); |
326 | static int eio_finish (eio_req *req); |
256 | #define ETP_FINISH(req) eio_finish (req) |
327 | #define ETP_FINISH(req) eio_finish (req) |
257 | static void eio_execute (struct etp_worker *self, eio_req *req); |
328 | static void eio_execute (struct etp_worker *self, eio_req *req); |
258 | #define ETP_EXECUTE(wrk,req) eio_execute (wrk,req) |
329 | #define ETP_EXECUTE(wrk,req) eio_execute (wrk,req) |
259 | |
330 | |
260 | #define ETP_WORKER_CLEAR(req) \ |
|
|
261 | if (wrk->dbuf) \ |
|
|
262 | { \ |
|
|
263 | free (wrk->dbuf); \ |
|
|
264 | wrk->dbuf = 0; \ |
|
|
265 | } |
|
|
266 | |
|
|
267 | #define ETP_WORKER_COMMON \ |
|
|
268 | void *dbuf; |
|
|
269 | |
|
|
270 | /*****************************************************************************/ |
331 | /*****************************************************************************/ |
271 | |
332 | |
272 | #define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) |
333 | #define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) |
273 | |
334 | |
274 | /* calculate time difference in ~1/EIO_TICKS of a second */ |
335 | /* calculate time difference in ~1/EIO_TICKS of a second */ |
… | |
… | |
285 | static void (*done_poll_cb) (void); |
346 | static void (*done_poll_cb) (void); |
286 | |
347 | |
287 | static unsigned int max_poll_time; /* reslock */ |
348 | static unsigned int max_poll_time; /* reslock */ |
288 | static unsigned int max_poll_reqs; /* reslock */ |
349 | static unsigned int max_poll_reqs; /* reslock */ |
289 | |
350 | |
290 | static volatile unsigned int nreqs; /* reqlock */ |
351 | static unsigned int nreqs; /* reqlock */ |
291 | static volatile unsigned int nready; /* reqlock */ |
352 | static unsigned int nready; /* reqlock */ |
292 | static volatile unsigned int npending; /* reqlock */ |
353 | static unsigned int npending; /* reqlock */ |
293 | static volatile unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */ |
354 | static unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */ |
294 | static volatile unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */ |
355 | static unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */ |
295 | |
356 | |
296 | static xmutex_t wrklock; |
357 | static xmutex_t wrklock; |
297 | static xmutex_t reslock; |
358 | static xmutex_t reslock; |
298 | static xmutex_t reqlock; |
359 | static xmutex_t reqlock; |
299 | static xcond_t reqwait; |
360 | static xcond_t reqwait; |
… | |
… | |
307 | static xmutex_t preadwritelock; |
368 | static xmutex_t preadwritelock; |
308 | #endif |
369 | #endif |
309 | |
370 | |
310 | typedef struct etp_worker |
371 | typedef struct etp_worker |
311 | { |
372 | { |
|
|
373 | struct tmpbuf tmpbuf; |
|
|
374 | |
312 | /* locked by wrklock */ |
375 | /* locked by wrklock */ |
313 | struct etp_worker *prev, *next; |
376 | struct etp_worker *prev, *next; |
314 | |
377 | |
315 | xthread_t tid; |
378 | xthread_t tid; |
316 | |
379 | |
317 | /* locked by reslock, reqlock or wrklock */ |
380 | #ifdef ETP_WORKER_COMMON |
318 | ETP_REQ *req; /* currently processed request */ |
|
|
319 | |
|
|
320 | ETP_WORKER_COMMON |
381 | ETP_WORKER_COMMON |
|
|
382 | #endif |
321 | } etp_worker; |
383 | } etp_worker; |
322 | |
384 | |
323 | static etp_worker wrk_first; /* NOT etp */ |
385 | static etp_worker wrk_first; /* NOT etp */ |
324 | |
386 | |
325 | #define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) |
387 | #define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) |
… | |
… | |
328 | /* worker threads management */ |
390 | /* worker threads management */ |
329 | |
391 | |
330 | static void ecb_cold |
392 | static void ecb_cold |
331 | etp_worker_clear (etp_worker *wrk) |
393 | etp_worker_clear (etp_worker *wrk) |
332 | { |
394 | { |
333 | ETP_WORKER_CLEAR (wrk); |
|
|
334 | } |
395 | } |
335 | |
396 | |
336 | static void ecb_cold |
397 | static void ecb_cold |
337 | etp_worker_free (etp_worker *wrk) |
398 | etp_worker_free (etp_worker *wrk) |
338 | { |
399 | { |
|
|
400 | free (wrk->tmpbuf.ptr); |
|
|
401 | |
339 | wrk->next->prev = wrk->prev; |
402 | wrk->next->prev = wrk->prev; |
340 | wrk->prev->next = wrk->next; |
403 | wrk->prev->next = wrk->next; |
341 | |
404 | |
342 | free (wrk); |
405 | free (wrk); |
343 | } |
406 | } |
… | |
… | |
521 | } |
584 | } |
522 | |
585 | |
523 | static void ecb_cold |
586 | static void ecb_cold |
524 | etp_end_thread (void) |
587 | etp_end_thread (void) |
525 | { |
588 | { |
526 | eio_req *req = calloc (1, sizeof (eio_req)); |
589 | eio_req *req = calloc (1, sizeof (eio_req)); /* will be freed by worker */ |
527 | |
590 | |
528 | req->type = -1; |
591 | req->type = -1; |
529 | req->pri = ETP_PRI_MAX - ETP_PRI_MIN; |
592 | req->pri = ETP_PRI_MAX - ETP_PRI_MIN; |
530 | |
593 | |
531 | X_LOCK (reqlock); |
594 | X_LOCK (reqlock); |
… | |
… | |
939 | #if !HAVE_FDATASYNC |
1002 | #if !HAVE_FDATASYNC |
940 | # undef fdatasync |
1003 | # undef fdatasync |
941 | # define fdatasync(fd) fsync (fd) |
1004 | # define fdatasync(fd) fsync (fd) |
942 | #endif |
1005 | #endif |
943 | |
1006 | |
|
|
1007 | static int |
|
|
1008 | eio__syncfs (int fd) |
|
|
1009 | { |
|
|
1010 | int res; |
|
|
1011 | |
|
|
1012 | #if HAVE_SYS_SYNCFS |
|
|
1013 | res = (int)syscall (__NR_syncfs, (int)(fd)); |
|
|
1014 | #else |
|
|
1015 | res = -1; |
|
|
1016 | errno = ENOSYS; |
|
|
1017 | #endif |
|
|
1018 | |
|
|
1019 | if (res < 0 && errno == ENOSYS && fd >= 0) |
|
|
1020 | sync (); |
|
|
1021 | |
|
|
1022 | return res; |
|
|
1023 | } |
|
|
1024 | |
944 | /* sync_file_range always needs emulation */ |
1025 | /* sync_file_range always needs emulation */ |
945 | static int |
1026 | static int |
946 | eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) |
1027 | eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) |
947 | { |
1028 | { |
948 | #if HAVE_SYNC_FILE_RANGE |
1029 | #if HAVE_SYNC_FILE_RANGE |
… | |
… | |
997 | pread (fd, eio_buf, len, offset); |
1078 | pread (fd, eio_buf, len, offset); |
998 | offset += len; |
1079 | offset += len; |
999 | todo -= len; |
1080 | todo -= len; |
1000 | } |
1081 | } |
1001 | |
1082 | |
|
|
1083 | FUBd; |
|
|
1084 | |
1002 | errno = 0; |
1085 | errno = 0; |
1003 | return count; |
1086 | return count; |
1004 | } |
1087 | } |
1005 | |
1088 | |
1006 | #endif |
1089 | #endif |
1007 | |
1090 | |
1008 | /* sendfile always needs emulation */ |
1091 | /* sendfile always needs emulation */ |
1009 | static eio_ssize_t |
1092 | static eio_ssize_t |
1010 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) |
1093 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count) |
1011 | { |
1094 | { |
1012 | eio_ssize_t written = 0; |
1095 | eio_ssize_t written = 0; |
1013 | eio_ssize_t res; |
1096 | eio_ssize_t res; |
1014 | |
1097 | |
1015 | if (!count) |
1098 | if (!count) |
… | |
… | |
1151 | |
1234 | |
1152 | offset += cnt; |
1235 | offset += cnt; |
1153 | res += cnt; |
1236 | res += cnt; |
1154 | count -= cnt; |
1237 | count -= cnt; |
1155 | } |
1238 | } |
|
|
1239 | |
|
|
1240 | FUBd; |
1156 | } |
1241 | } |
1157 | |
1242 | |
1158 | return res; |
1243 | return res; |
1159 | } |
1244 | } |
1160 | |
1245 | |
… | |
… | |
1275 | } |
1360 | } |
1276 | |
1361 | |
1277 | /*****************************************************************************/ |
1362 | /*****************************************************************************/ |
1278 | /* requests implemented outside eio_execute, because they are so large */ |
1363 | /* requests implemented outside eio_execute, because they are so large */ |
1279 | |
1364 | |
|
|
1365 | /* copies some absolute path to tmpbuf */ |
|
|
1366 | static char * |
|
|
1367 | eio__getwd (struct tmpbuf *tmpbuf, eio_wd wd) |
|
|
1368 | { |
|
|
1369 | if (wd == EIO_CWD) |
|
|
1370 | return getcwd (tmpbuf->ptr, PATH_MAX); |
|
|
1371 | |
|
|
1372 | #if HAVE_AT |
|
|
1373 | abort (); /*TODO*/ |
|
|
1374 | #else |
|
|
1375 | strcpy (tmpbuf->ptr, wd); |
|
|
1376 | #endif |
|
|
1377 | return tmpbuf->ptr; |
|
|
1378 | } |
|
|
1379 | |
|
|
1380 | /* result will always end up in tmpbuf, there is always space for adding a 0-byte */ |
1280 | static void |
1381 | static int |
1281 | eio__realpath (eio_req *req, etp_worker *self) |
1382 | eio__realpath (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
1282 | { |
1383 | { |
1283 | char *rel = req->ptr1; |
1384 | const char *rel = path; |
1284 | char *res; |
1385 | char *res; |
1285 | char *tmp1, *tmp2; |
1386 | char *tmp1, *tmp2; |
1286 | #if SYMLOOP_MAX > 32 |
1387 | #if SYMLOOP_MAX > 32 |
1287 | int symlinks = SYMLOOP_MAX; |
1388 | int symlinks = SYMLOOP_MAX; |
1288 | #else |
1389 | #else |
1289 | int symlinks = 32; |
1390 | int symlinks = 32; |
1290 | #endif |
1391 | #endif |
1291 | |
1392 | |
1292 | req->result = -1; |
1393 | /*D*/ /*TODO: wd ignored */ |
1293 | |
1394 | |
1294 | errno = EINVAL; |
1395 | errno = EINVAL; |
1295 | if (!rel) |
1396 | if (!rel) |
1296 | return; |
1397 | return -1; |
1297 | |
1398 | |
1298 | errno = ENOENT; |
1399 | errno = ENOENT; |
1299 | if (!*rel) |
1400 | if (!*rel) |
1300 | return; |
1401 | return -1; |
1301 | |
1402 | |
1302 | if (!req->ptr2) |
1403 | res = tmpbuf_get (tmpbuf, PATH_MAX * 3); |
1303 | { |
|
|
1304 | X_LOCK (wrklock); |
|
|
1305 | req->flags |= EIO_FLAG_PTR2_FREE; |
|
|
1306 | X_UNLOCK (wrklock); |
|
|
1307 | req->ptr2 = malloc (PATH_MAX * 3); |
|
|
1308 | |
|
|
1309 | errno = ENOMEM; |
|
|
1310 | if (!req->ptr2) |
|
|
1311 | return; |
|
|
1312 | } |
|
|
1313 | |
|
|
1314 | res = req->ptr2; |
|
|
1315 | tmp1 = res + PATH_MAX; |
1404 | tmp1 = res + PATH_MAX; |
1316 | tmp2 = tmp1 + PATH_MAX; |
1405 | tmp2 = tmp1 + PATH_MAX; |
1317 | |
1406 | |
1318 | #if 0 /* disabled, the musl way to do things is just too racy */ |
1407 | #if 0 /* disabled, the musl way to do things is just too racy */ |
1319 | #if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) |
1408 | #if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) |
… | |
… | |
1338 | #endif |
1427 | #endif |
1339 | #endif |
1428 | #endif |
1340 | |
1429 | |
1341 | if (*rel != '/') |
1430 | if (*rel != '/') |
1342 | { |
1431 | { |
1343 | if (!getcwd (res, PATH_MAX)) |
1432 | if (!eio__getwd (tmpbuf, wd)) |
1344 | return; |
1433 | return -1; |
1345 | |
1434 | |
1346 | if (res [1]) /* only use if not / */ |
1435 | if (res [1]) /* only use if not / */ |
1347 | res += strlen (res); |
1436 | res += strlen (res); |
1348 | } |
1437 | } |
1349 | |
1438 | |
1350 | while (*rel) |
1439 | while (*rel) |
1351 | { |
1440 | { |
1352 | eio_ssize_t len, linklen; |
1441 | eio_ssize_t len, linklen; |
1353 | char *beg = rel; |
1442 | const char *beg = rel; |
1354 | |
1443 | |
1355 | while (*rel && *rel != '/') |
1444 | while (*rel && *rel != '/') |
1356 | ++rel; |
1445 | ++rel; |
1357 | |
1446 | |
1358 | len = rel - beg; |
1447 | len = rel - beg; |
… | |
… | |
1370 | |
1459 | |
1371 | if (beg [1] == '.' && len == 2) |
1460 | if (beg [1] == '.' && len == 2) |
1372 | { |
1461 | { |
1373 | /* .. - back up one component, if possible */ |
1462 | /* .. - back up one component, if possible */ |
1374 | |
1463 | |
1375 | while (res != req->ptr2) |
1464 | while (res != tmpbuf->ptr) |
1376 | if (*--res == '/') |
1465 | if (*--res == '/') |
1377 | break; |
1466 | break; |
1378 | |
1467 | |
1379 | continue; |
1468 | continue; |
1380 | } |
1469 | } |
… | |
… | |
1390 | |
1479 | |
1391 | /* zero-terminate, for readlink */ |
1480 | /* zero-terminate, for readlink */ |
1392 | res [len + 1] = 0; |
1481 | res [len + 1] = 0; |
1393 | |
1482 | |
1394 | /* now check if it's a symlink */ |
1483 | /* now check if it's a symlink */ |
1395 | linklen = readlink (req->ptr2, tmp1, PATH_MAX); |
1484 | linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); |
1396 | |
1485 | |
1397 | if (linklen < 0) |
1486 | if (linklen < 0) |
1398 | { |
1487 | { |
1399 | if (errno != EINVAL) |
1488 | if (errno != EINVAL) |
1400 | return; |
1489 | return -1; |
1401 | |
1490 | |
1402 | /* it's a normal directory. hopefully */ |
1491 | /* it's a normal directory. hopefully */ |
1403 | res += len + 1; |
1492 | res += len + 1; |
1404 | } |
1493 | } |
1405 | else |
1494 | else |
… | |
… | |
1407 | /* yay, it was a symlink - build new path in tmp2 */ |
1496 | /* yay, it was a symlink - build new path in tmp2 */ |
1408 | int rellen = strlen (rel); |
1497 | int rellen = strlen (rel); |
1409 | |
1498 | |
1410 | errno = ENAMETOOLONG; |
1499 | errno = ENAMETOOLONG; |
1411 | if (linklen + 1 + rellen >= PATH_MAX) |
1500 | if (linklen + 1 + rellen >= PATH_MAX) |
1412 | return; |
1501 | return -1; |
1413 | |
1502 | |
1414 | errno = ELOOP; |
1503 | errno = ELOOP; |
1415 | if (!--symlinks) |
1504 | if (!--symlinks) |
1416 | return; |
1505 | return -1; |
1417 | |
1506 | |
1418 | if (*tmp1 == '/') |
1507 | if (*tmp1 == '/') |
1419 | res = req->ptr2; /* symlink resolves to an absolute path */ |
1508 | res = tmpbuf->ptr; /* symlink resolves to an absolute path */ |
1420 | |
1509 | |
1421 | /* we need to be careful, as rel might point into tmp2 already */ |
1510 | /* we need to be careful, as rel might point into tmp2 already */ |
1422 | memmove (tmp2 + linklen + 1, rel, rellen + 1); |
1511 | memmove (tmp2 + linklen + 1, rel, rellen + 1); |
1423 | tmp2 [linklen] = '/'; |
1512 | tmp2 [linklen] = '/'; |
1424 | memcpy (tmp2, tmp1, linklen); |
1513 | memcpy (tmp2, tmp1, linklen); |
… | |
… | |
1426 | rel = tmp2; |
1515 | rel = tmp2; |
1427 | } |
1516 | } |
1428 | } |
1517 | } |
1429 | |
1518 | |
1430 | /* special case for the lone root path */ |
1519 | /* special case for the lone root path */ |
1431 | if (res == req->ptr2) |
1520 | if (res == tmpbuf->ptr) |
1432 | *res++ = '/'; |
1521 | *res++ = '/'; |
1433 | |
1522 | |
1434 | req->result = res - (char *)req->ptr2; |
1523 | return res - (char *)tmpbuf->ptr; |
1435 | |
|
|
1436 | done: |
|
|
1437 | req->ptr2 = realloc (req->ptr2, req->result); /* trade time for space savings */ |
|
|
1438 | } |
1524 | } |
1439 | |
1525 | |
1440 | static signed char |
1526 | static signed char |
1441 | eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) |
1527 | eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) |
1442 | { |
1528 | { |
… | |
… | |
1602 | eio_dent_insertion_sort (dents, size); |
1688 | eio_dent_insertion_sort (dents, size); |
1603 | } |
1689 | } |
1604 | |
1690 | |
1605 | /* read a full directory */ |
1691 | /* read a full directory */ |
1606 | static void |
1692 | static void |
1607 | eio__scandir (eio_req *req, etp_worker *self) |
1693 | eio__scandir (eio_req *req) |
1608 | { |
1694 | { |
1609 | char *name, *names; |
1695 | char *name, *names; |
1610 | int namesalloc = 4096 - sizeof (void *) * 4; |
1696 | int namesalloc = 4096 - sizeof (void *) * 4; |
1611 | int namesoffs = 0; |
1697 | int namesoffs = 0; |
1612 | int flags = req->int1; |
1698 | int flags = req->int1; |
… | |
… | |
1644 | dirp = FindFirstFile (path, &entp); |
1730 | dirp = FindFirstFile (path, &entp); |
1645 | free (path); |
1731 | free (path); |
1646 | |
1732 | |
1647 | if (dirp == INVALID_HANDLE_VALUE) |
1733 | if (dirp == INVALID_HANDLE_VALUE) |
1648 | { |
1734 | { |
1649 | dirp = 0; |
1735 | /* should steal _dosmaperr */ |
1650 | |
|
|
1651 | switch (GetLastError ()) |
1736 | switch (GetLastError ()) |
1652 | { |
1737 | { |
1653 | case ERROR_FILE_NOT_FOUND: |
1738 | case ERROR_FILE_NOT_FOUND: |
1654 | req->result = 0; |
1739 | req->result = 0; |
1655 | break; |
1740 | break; |
1656 | |
1741 | |
1657 | case ERROR_INVALID_NAME: |
1742 | case ERROR_INVALID_NAME: |
1658 | case ERROR_PATH_NOT_FOUND: |
1743 | case ERROR_PATH_NOT_FOUND: |
1659 | case ERROR_NO_MORE_FILES: |
1744 | case ERROR_NO_MORE_FILES: |
1660 | errno = ENOENT; |
1745 | errno = ENOENT; |
1661 | break; |
1746 | break; |
1662 | |
1747 | |
1663 | case ERROR_NOT_ENOUGH_MEMORY: |
1748 | case ERROR_NOT_ENOUGH_MEMORY: |
1664 | errno = ENOMEM; |
1749 | errno = ENOMEM; |
1665 | break; |
1750 | break; |
1666 | |
1751 | |
1667 | default: |
1752 | default: |
1668 | errno = EINVAL; |
1753 | errno = EINVAL; |
1669 | break; |
1754 | break; |
1670 | } |
1755 | } |
|
|
1756 | |
|
|
1757 | return; |
1671 | } |
1758 | } |
1672 | } |
1759 | } |
1673 | #else |
1760 | #else |
1674 | dirp = opendir (req->ptr1); |
1761 | dirp = opendir (req->ptr1); |
|
|
1762 | |
|
|
1763 | if (!dirp) |
|
|
1764 | return; |
1675 | #endif |
1765 | #endif |
1676 | |
1766 | |
1677 | if (req->flags & EIO_FLAG_PTR1_FREE) |
1767 | if (req->flags & EIO_FLAG_PTR1_FREE) |
1678 | free (req->ptr1); |
1768 | free (req->ptr1); |
1679 | |
1769 | |
1680 | req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; |
1770 | req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; |
1681 | req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; |
1771 | req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; |
1682 | req->ptr2 = names = malloc (namesalloc); |
1772 | req->ptr2 = names = malloc (namesalloc); |
1683 | |
1773 | |
1684 | if (dirp && names && (!flags || dents)) |
1774 | if (!names || (flags && !dents)) |
|
|
1775 | return; |
|
|
1776 | |
1685 | for (;;) |
1777 | for (;;) |
1686 | { |
1778 | { |
1687 | int done; |
1779 | int done; |
1688 | |
1780 | |
1689 | #ifdef _WIN32 |
1781 | #ifdef _WIN32 |
1690 | done = !dirp; |
1782 | done = !dirp; |
1691 | #else |
1783 | #else |
1692 | errno = 0; |
1784 | errno = 0; |
1693 | entp = readdir (dirp); |
1785 | entp = readdir (dirp); |
1694 | done = !entp; |
1786 | done = !entp; |
1695 | #endif |
1787 | #endif |
1696 | |
1788 | |
1697 | if (done) |
1789 | if (done) |
1698 | { |
1790 | { |
1699 | #ifndef _WIN32 |
1791 | #ifndef _WIN32 |
1700 | int old_errno = errno; |
1792 | int old_errno = errno; |
1701 | closedir (dirp); |
1793 | closedir (dirp); |
1702 | errno = old_errno; |
1794 | errno = old_errno; |
1703 | |
1795 | |
1704 | if (errno) |
1796 | if (errno) |
1705 | break; |
1797 | break; |
1706 | #endif |
1798 | #endif |
1707 | |
1799 | |
1708 | /* sort etc. */ |
1800 | /* sort etc. */ |
1709 | req->int1 = flags; |
1801 | req->int1 = flags; |
1710 | req->result = dentoffs; |
1802 | req->result = dentoffs; |
1711 | |
1803 | |
1712 | if (flags & EIO_READDIR_STAT_ORDER) |
1804 | if (flags & EIO_READDIR_STAT_ORDER) |
1713 | eio_dent_sort (dents, dentoffs, flags & EIO_READDIR_DIRS_FIRST ? 7 : 0, inode_bits); |
1805 | eio_dent_sort (dents, dentoffs, flags & EIO_READDIR_DIRS_FIRST ? 7 : 0, inode_bits); |
1714 | else if (flags & EIO_READDIR_DIRS_FIRST) |
1806 | else if (flags & EIO_READDIR_DIRS_FIRST) |
1715 | if (flags & EIO_READDIR_FOUND_UNKNOWN) |
1807 | if (flags & EIO_READDIR_FOUND_UNKNOWN) |
1716 | eio_dent_sort (dents, dentoffs, 7, inode_bits); /* sort by score and inode */ |
1808 | eio_dent_sort (dents, dentoffs, 7, inode_bits); /* sort by score and inode */ |
1717 | else |
1809 | else |
|
|
1810 | { |
|
|
1811 | /* in this case, all is known, and we just put dirs first and sort them */ |
|
|
1812 | eio_dirent *oth = dents + dentoffs; |
|
|
1813 | eio_dirent *dir = dents; |
|
|
1814 | |
|
|
1815 | /* now partition dirs to the front, and non-dirs to the back */ |
|
|
1816 | /* by walking from both sides and swapping if necessary */ |
|
|
1817 | while (oth > dir) |
|
|
1818 | { |
|
|
1819 | if (dir->type == EIO_DT_DIR) |
|
|
1820 | ++dir; |
|
|
1821 | else if ((--oth)->type == EIO_DT_DIR) |
|
|
1822 | { |
|
|
1823 | eio_dirent tmp = *dir; *dir = *oth; *oth = tmp; |
|
|
1824 | |
|
|
1825 | ++dir; |
|
|
1826 | } |
|
|
1827 | } |
|
|
1828 | |
|
|
1829 | /* now sort the dirs only (dirs all have the same score) */ |
|
|
1830 | eio_dent_sort (dents, dir - dents, 0, inode_bits); |
|
|
1831 | } |
|
|
1832 | |
|
|
1833 | break; |
|
|
1834 | } |
|
|
1835 | |
|
|
1836 | /* now add the entry to our list(s) */ |
|
|
1837 | name = D_NAME (entp); |
|
|
1838 | |
|
|
1839 | /* skip . and .. entries */ |
|
|
1840 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
|
|
1841 | { |
|
|
1842 | int len = D_NAMLEN (entp) + 1; |
|
|
1843 | |
|
|
1844 | while (ecb_expect_false (namesoffs + len > namesalloc)) |
|
|
1845 | { |
|
|
1846 | namesalloc *= 2; |
|
|
1847 | req->ptr2 = names = realloc (names, namesalloc); |
|
|
1848 | |
|
|
1849 | if (!names) |
|
|
1850 | break; |
|
|
1851 | } |
|
|
1852 | |
|
|
1853 | memcpy (names + namesoffs, name, len); |
|
|
1854 | |
|
|
1855 | if (dents) |
|
|
1856 | { |
|
|
1857 | struct eio_dirent *ent; |
|
|
1858 | |
|
|
1859 | if (ecb_expect_false (dentoffs == dentalloc)) |
1718 | { |
1860 | { |
1719 | /* in this case, all is known, and we just put dirs first and sort them */ |
1861 | dentalloc *= 2; |
|
|
1862 | req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent)); |
|
|
1863 | |
|
|
1864 | if (!dents) |
|
|
1865 | break; |
|
|
1866 | } |
|
|
1867 | |
1720 | eio_dirent *oth = dents + dentoffs; |
1868 | ent = dents + dentoffs; |
1721 | eio_dirent *dir = dents; |
|
|
1722 | |
1869 | |
1723 | /* now partition dirs to the front, and non-dirs to the back */ |
1870 | ent->nameofs = namesoffs; /* rather dirtily we store the offset in the pointer */ |
1724 | /* by walking from both sides and swapping if necessary */ |
1871 | ent->namelen = len - 1; |
1725 | while (oth > dir) |
1872 | ent->inode = D_INO (entp); |
|
|
1873 | |
|
|
1874 | inode_bits |= ent->inode; |
|
|
1875 | |
|
|
1876 | switch (D_TYPE (entp)) |
|
|
1877 | { |
|
|
1878 | default: |
|
|
1879 | ent->type = EIO_DT_UNKNOWN; |
|
|
1880 | flags |= EIO_READDIR_FOUND_UNKNOWN; |
|
|
1881 | break; |
|
|
1882 | |
|
|
1883 | #ifdef DT_FIFO |
|
|
1884 | case DT_FIFO: ent->type = EIO_DT_FIFO; break; |
|
|
1885 | #endif |
|
|
1886 | #ifdef DT_CHR |
|
|
1887 | case DT_CHR: ent->type = EIO_DT_CHR; break; |
|
|
1888 | #endif |
|
|
1889 | #ifdef DT_MPC |
|
|
1890 | case DT_MPC: ent->type = EIO_DT_MPC; break; |
|
|
1891 | #endif |
|
|
1892 | #ifdef DT_DIR |
|
|
1893 | case DT_DIR: ent->type = EIO_DT_DIR; break; |
|
|
1894 | #endif |
|
|
1895 | #ifdef DT_NAM |
|
|
1896 | case DT_NAM: ent->type = EIO_DT_NAM; break; |
|
|
1897 | #endif |
|
|
1898 | #ifdef DT_BLK |
|
|
1899 | case DT_BLK: ent->type = EIO_DT_BLK; break; |
|
|
1900 | #endif |
|
|
1901 | #ifdef DT_MPB |
|
|
1902 | case DT_MPB: ent->type = EIO_DT_MPB; break; |
|
|
1903 | #endif |
|
|
1904 | #ifdef DT_REG |
|
|
1905 | case DT_REG: ent->type = EIO_DT_REG; break; |
|
|
1906 | #endif |
|
|
1907 | #ifdef DT_NWK |
|
|
1908 | case DT_NWK: ent->type = EIO_DT_NWK; break; |
|
|
1909 | #endif |
|
|
1910 | #ifdef DT_CMP |
|
|
1911 | case DT_CMP: ent->type = EIO_DT_CMP; break; |
|
|
1912 | #endif |
|
|
1913 | #ifdef DT_LNK |
|
|
1914 | case DT_LNK: ent->type = EIO_DT_LNK; break; |
|
|
1915 | #endif |
|
|
1916 | #ifdef DT_SOCK |
|
|
1917 | case DT_SOCK: ent->type = EIO_DT_SOCK; break; |
|
|
1918 | #endif |
|
|
1919 | #ifdef DT_DOOR |
|
|
1920 | case DT_DOOR: ent->type = EIO_DT_DOOR; break; |
|
|
1921 | #endif |
|
|
1922 | #ifdef DT_WHT |
|
|
1923 | case DT_WHT: ent->type = EIO_DT_WHT; break; |
|
|
1924 | #endif |
|
|
1925 | } |
|
|
1926 | |
|
|
1927 | ent->score = 7; |
|
|
1928 | |
|
|
1929 | if (flags & EIO_READDIR_DIRS_FIRST) |
|
|
1930 | { |
|
|
1931 | if (ent->type == EIO_DT_UNKNOWN) |
1726 | { |
1932 | { |
1727 | if (dir->type == EIO_DT_DIR) |
1933 | if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ |
1728 | ++dir; |
1934 | ent->score = 1; |
1729 | else if ((--oth)->type == EIO_DT_DIR) |
1935 | else if (!strchr (name, '.')) /* absense of dots indicate likely dirs */ |
1730 | { |
1936 | ent->score = len <= 2 ? 4 - len : len <= 4 ? 4 : len <= 7 ? 5 : 6; /* shorter == more likely dir, but avoid too many classes */ |
1731 | eio_dirent tmp = *dir; *dir = *oth; *oth = tmp; |
|
|
1732 | |
|
|
1733 | ++dir; |
|
|
1734 | } |
|
|
1735 | } |
1937 | } |
1736 | |
1938 | else if (ent->type == EIO_DT_DIR) |
1737 | /* now sort the dirs only (dirs all have the same score) */ |
1939 | ent->score = 0; |
1738 | eio_dent_sort (dents, dir - dents, 0, inode_bits); |
|
|
1739 | } |
1940 | } |
1740 | |
|
|
1741 | break; |
|
|
1742 | } |
|
|
1743 | |
|
|
1744 | /* now add the entry to our list(s) */ |
|
|
1745 | name = D_NAME (entp); |
|
|
1746 | |
|
|
1747 | /* skip . and .. entries */ |
|
|
1748 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
|
|
1749 | { |
|
|
1750 | int len = D_NAMLEN (entp) + 1; |
|
|
1751 | |
|
|
1752 | while (ecb_expect_false (namesoffs + len > namesalloc)) |
|
|
1753 | { |
|
|
1754 | namesalloc *= 2; |
|
|
1755 | req->ptr2 = names = realloc (names, namesalloc); |
|
|
1756 | |
|
|
1757 | if (!names) |
|
|
1758 | break; |
|
|
1759 | } |
1941 | } |
1760 | |
1942 | |
1761 | memcpy (names + namesoffs, name, len); |
|
|
1762 | |
|
|
1763 | if (dents) |
|
|
1764 | { |
|
|
1765 | struct eio_dirent *ent; |
|
|
1766 | |
|
|
1767 | if (ecb_expect_false (dentoffs == dentalloc)) |
|
|
1768 | { |
|
|
1769 | dentalloc *= 2; |
|
|
1770 | req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent)); |
|
|
1771 | |
|
|
1772 | if (!dents) |
|
|
1773 | break; |
|
|
1774 | } |
|
|
1775 | |
|
|
1776 | ent = dents + dentoffs; |
|
|
1777 | |
|
|
1778 | ent->nameofs = namesoffs; /* rather dirtily we store the offset in the pointer */ |
|
|
1779 | ent->namelen = len - 1; |
|
|
1780 | ent->inode = D_INO (entp); |
|
|
1781 | |
|
|
1782 | inode_bits |= ent->inode; |
|
|
1783 | |
|
|
1784 | switch (D_TYPE (entp)) |
|
|
1785 | { |
|
|
1786 | default: |
|
|
1787 | ent->type = EIO_DT_UNKNOWN; |
|
|
1788 | flags |= EIO_READDIR_FOUND_UNKNOWN; |
|
|
1789 | break; |
|
|
1790 | |
|
|
1791 | #ifdef DT_FIFO |
|
|
1792 | case DT_FIFO: ent->type = EIO_DT_FIFO; break; |
|
|
1793 | #endif |
|
|
1794 | #ifdef DT_CHR |
|
|
1795 | case DT_CHR: ent->type = EIO_DT_CHR; break; |
|
|
1796 | #endif |
|
|
1797 | #ifdef DT_MPC |
|
|
1798 | case DT_MPC: ent->type = EIO_DT_MPC; break; |
|
|
1799 | #endif |
|
|
1800 | #ifdef DT_DIR |
|
|
1801 | case DT_DIR: ent->type = EIO_DT_DIR; break; |
|
|
1802 | #endif |
|
|
1803 | #ifdef DT_NAM |
|
|
1804 | case DT_NAM: ent->type = EIO_DT_NAM; break; |
|
|
1805 | #endif |
|
|
1806 | #ifdef DT_BLK |
|
|
1807 | case DT_BLK: ent->type = EIO_DT_BLK; break; |
|
|
1808 | #endif |
|
|
1809 | #ifdef DT_MPB |
|
|
1810 | case DT_MPB: ent->type = EIO_DT_MPB; break; |
|
|
1811 | #endif |
|
|
1812 | #ifdef DT_REG |
|
|
1813 | case DT_REG: ent->type = EIO_DT_REG; break; |
|
|
1814 | #endif |
|
|
1815 | #ifdef DT_NWK |
|
|
1816 | case DT_NWK: ent->type = EIO_DT_NWK; break; |
|
|
1817 | #endif |
|
|
1818 | #ifdef DT_CMP |
|
|
1819 | case DT_CMP: ent->type = EIO_DT_CMP; break; |
|
|
1820 | #endif |
|
|
1821 | #ifdef DT_LNK |
|
|
1822 | case DT_LNK: ent->type = EIO_DT_LNK; break; |
|
|
1823 | #endif |
|
|
1824 | #ifdef DT_SOCK |
|
|
1825 | case DT_SOCK: ent->type = EIO_DT_SOCK; break; |
|
|
1826 | #endif |
|
|
1827 | #ifdef DT_DOOR |
|
|
1828 | case DT_DOOR: ent->type = EIO_DT_DOOR; break; |
|
|
1829 | #endif |
|
|
1830 | #ifdef DT_WHT |
|
|
1831 | case DT_WHT: ent->type = EIO_DT_WHT; break; |
|
|
1832 | #endif |
|
|
1833 | } |
|
|
1834 | |
|
|
1835 | ent->score = 7; |
|
|
1836 | |
|
|
1837 | if (flags & EIO_READDIR_DIRS_FIRST) |
|
|
1838 | { |
|
|
1839 | if (ent->type == EIO_DT_UNKNOWN) |
|
|
1840 | { |
|
|
1841 | if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ |
|
|
1842 | ent->score = 1; |
|
|
1843 | else if (!strchr (name, '.')) /* absense of dots indicate likely dirs */ |
|
|
1844 | ent->score = len <= 2 ? 4 - len : len <= 4 ? 4 : len <= 7 ? 5 : 6; /* shorter == more likely dir, but avoid too many classes */ |
|
|
1845 | } |
|
|
1846 | else if (ent->type == EIO_DT_DIR) |
|
|
1847 | ent->score = 0; |
|
|
1848 | } |
|
|
1849 | } |
|
|
1850 | |
|
|
1851 | namesoffs += len; |
1943 | namesoffs += len; |
1852 | ++dentoffs; |
1944 | ++dentoffs; |
1853 | } |
1945 | } |
1854 | |
1946 | |
1855 | if (EIO_CANCELLED (req)) |
1947 | if (EIO_CANCELLED (req)) |
1856 | { |
1948 | { |
1857 | errno = ECANCELED; |
1949 | errno = ECANCELED; |
1858 | break; |
1950 | break; |
1859 | } |
1951 | } |
1860 | |
1952 | |
1861 | #ifdef _WIN32 |
1953 | #ifdef _WIN32 |
1862 | if (!FindNextFile (dirp, &entp)) |
1954 | if (!FindNextFile (dirp, &entp)) |
1863 | { |
1955 | { |
1864 | FindClose (dirp); |
1956 | FindClose (dirp); |
1865 | dirp = 0; |
1957 | dirp = 0; |
1866 | } |
1958 | } |
1867 | #endif |
1959 | #endif |
|
|
1960 | } |
|
|
1961 | } |
|
|
1962 | |
|
|
1963 | /*****************************************************************************/ |
|
|
1964 | /* working directory stuff */ |
|
|
1965 | |
|
|
1966 | #if HAVE_AT |
|
|
1967 | |
|
|
1968 | #define WD2FD(wd) ((wd) ? ((int)(long)(wd)) - 1 : AT_FDCWD) |
|
|
1969 | |
|
|
1970 | #ifndef O_SEARCH |
|
|
1971 | # define O_SEARCH O_RDONLY |
|
|
1972 | #endif |
|
|
1973 | |
|
|
1974 | eio_wd |
|
|
1975 | eio_wd_open_sync (eio_wd wd, const char *path) |
|
|
1976 | { |
|
|
1977 | int fd = openat (WD2FD (wd), path, O_CLOEXEC | O_SEARCH | O_DIRECTORY); |
|
|
1978 | |
|
|
1979 | return fd >= 0 ? (eio_wd)(long)(fd + 1) : EIO_INVALID_WD; |
|
|
1980 | } |
|
|
1981 | |
|
|
1982 | static eio_wd |
|
|
1983 | eio__wd_open_sync (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
|
|
1984 | { |
|
|
1985 | return eio_wd_open_sync (wd, path); |
|
|
1986 | } |
|
|
1987 | |
|
|
1988 | void |
|
|
1989 | eio_wd_close_sync (eio_wd wd) |
|
|
1990 | { |
|
|
1991 | int fd = WD2FD (wd); |
|
|
1992 | |
|
|
1993 | if (fd >= 0) |
|
|
1994 | close (fd); |
|
|
1995 | } |
|
|
1996 | |
|
|
1997 | static int |
|
|
1998 | eio__truncateat (int dirfd, const char *path, off_t length) |
|
|
1999 | { |
|
|
2000 | int fd = openat (dirfd, path, O_WRONLY | O_CLOEXEC); |
|
|
2001 | int res; |
|
|
2002 | |
|
|
2003 | if (fd < 0) |
|
|
2004 | return fd; |
|
|
2005 | |
|
|
2006 | res = ftruncate (fd, length); |
|
|
2007 | close (fd); |
|
|
2008 | return res; |
|
|
2009 | } |
|
|
2010 | |
|
|
2011 | static int |
|
|
2012 | eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) |
|
|
2013 | { |
|
|
2014 | int fd = openat (dirfd, path, O_SEARCH | O_CLOEXEC); |
|
|
2015 | int res; |
|
|
2016 | |
|
|
2017 | if (fd < 0) |
|
|
2018 | return fd; |
|
|
2019 | |
|
|
2020 | res = fstatvfs (fd, buf); |
|
|
2021 | close (fd); |
|
|
2022 | return res; |
|
|
2023 | |
|
|
2024 | } |
|
|
2025 | |
|
|
2026 | #else |
|
|
2027 | |
|
|
2028 | /* on legacy systems, we represent the working directories simply by their path strings */ |
|
|
2029 | |
|
|
2030 | static const char * |
|
|
2031 | wd_expand (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
|
|
2032 | { |
|
|
2033 | if (!wd || *path == '/') |
|
|
2034 | return path; |
|
|
2035 | |
|
|
2036 | { |
|
|
2037 | int l1 = strlen ((const char *)wd); |
|
|
2038 | int l2 = strlen (path); |
|
|
2039 | |
|
|
2040 | char *res = tmpbuf_get (tmpbuf, l1 + l2 + 2); |
|
|
2041 | |
|
|
2042 | memcpy (res, wd, l1); |
|
|
2043 | res [l1] = '/'; |
|
|
2044 | memcpy (res + l1 + 1, path, l2 + 1); |
|
|
2045 | |
|
|
2046 | return res; |
|
|
2047 | } |
|
|
2048 | } |
|
|
2049 | |
|
|
2050 | static eio_wd |
|
|
2051 | eio__wd_open_sync (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
|
|
2052 | { |
|
|
2053 | if (*path == '/') /* absolute paths ignore wd */ |
|
|
2054 | path = strdup (path); |
|
|
2055 | else if (path [0] == '.' && !path [1]) /* special case '.', as it is common */ |
|
|
2056 | return wd; |
|
|
2057 | else |
|
|
2058 | { |
|
|
2059 | int len = eio__realpath (tmpbuf, wd, path); |
|
|
2060 | |
|
|
2061 | path = EIO_INVALID_WD; |
|
|
2062 | |
|
|
2063 | if (len >= 0) |
|
|
2064 | { |
|
|
2065 | ((char *)tmpbuf->ptr)[len] = 0; |
|
|
2066 | path = strdup (tmpbuf->ptr); |
1868 | } |
2067 | } |
|
|
2068 | } |
|
|
2069 | |
|
|
2070 | if (!path) |
|
|
2071 | path = EIO_INVALID_WD; |
|
|
2072 | |
|
|
2073 | return (eio_wd)path; |
1869 | } |
2074 | } |
|
|
2075 | |
|
|
2076 | eio_wd |
|
|
2077 | eio_wd_open_sync (eio_wd wd, const char *path) |
|
|
2078 | { |
|
|
2079 | struct tmpbuf tmpbuf = { 0 }; |
|
|
2080 | wd = eio__wd_open_sync (&tmpbuf, wd, path); |
|
|
2081 | free (tmpbuf.ptr); |
|
|
2082 | |
|
|
2083 | return wd; |
|
|
2084 | } |
|
|
2085 | |
|
|
2086 | void |
|
|
2087 | eio_wd_close_sync (eio_wd wd) |
|
|
2088 | { |
|
|
2089 | if (wd != EIO_INVALID_WD) |
|
|
2090 | free (wd); |
|
|
2091 | } |
|
|
2092 | |
|
|
2093 | #endif |
1870 | |
2094 | |
1871 | /*****************************************************************************/ |
2095 | /*****************************************************************************/ |
1872 | |
2096 | |
1873 | #define ALLOC(len) \ |
2097 | #define ALLOC(len) \ |
1874 | if (!req->ptr2) \ |
2098 | if (!req->ptr2) \ |
… | |
… | |
1889 | { |
2113 | { |
1890 | ETP_REQ *req; |
2114 | ETP_REQ *req; |
1891 | struct timespec ts; |
2115 | struct timespec ts; |
1892 | etp_worker *self = (etp_worker *)thr_arg; |
2116 | etp_worker *self = (etp_worker *)thr_arg; |
1893 | |
2117 | |
|
|
2118 | #if HAVE_PRCTL_SET_NAME |
|
|
2119 | prctl (PR_SET_NAME, (unsigned long)"eio_thread", 0, 0, 0); |
|
|
2120 | #endif |
|
|
2121 | |
1894 | /* try to distribute timeouts somewhat evenly */ |
2122 | /* try to distribute timeouts somewhat evenly */ |
1895 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
2123 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
1896 | |
2124 | |
1897 | for (;;) |
2125 | for (;;) |
1898 | { |
2126 | { |
… | |
… | |
1900 | |
2128 | |
1901 | X_LOCK (reqlock); |
2129 | X_LOCK (reqlock); |
1902 | |
2130 | |
1903 | for (;;) |
2131 | for (;;) |
1904 | { |
2132 | { |
1905 | self->req = req = reqq_shift (&req_queue); |
2133 | req = reqq_shift (&req_queue); |
1906 | |
2134 | |
1907 | if (req) |
2135 | if (req) |
1908 | break; |
2136 | break; |
1909 | |
2137 | |
1910 | if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */ |
2138 | if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */ |
… | |
… | |
1948 | ++npending; |
2176 | ++npending; |
1949 | |
2177 | |
1950 | if (!reqq_push (&res_queue, req) && want_poll_cb) |
2178 | if (!reqq_push (&res_queue, req) && want_poll_cb) |
1951 | want_poll_cb (); |
2179 | want_poll_cb (); |
1952 | |
2180 | |
1953 | self->req = 0; |
|
|
1954 | etp_worker_clear (self); |
2181 | etp_worker_clear (self); |
1955 | |
2182 | |
1956 | X_UNLOCK (reslock); |
2183 | X_UNLOCK (reslock); |
1957 | } |
2184 | } |
1958 | |
2185 | |
1959 | quit: |
2186 | quit: |
|
|
2187 | free (req); |
|
|
2188 | |
1960 | X_LOCK (wrklock); |
2189 | X_LOCK (wrklock); |
1961 | etp_worker_free (self); |
2190 | etp_worker_free (self); |
1962 | X_UNLOCK (wrklock); |
2191 | X_UNLOCK (wrklock); |
1963 | |
2192 | |
1964 | return 0; |
2193 | return 0; |
… | |
… | |
2007 | } |
2236 | } |
2008 | |
2237 | |
2009 | static void |
2238 | static void |
2010 | eio_execute (etp_worker *self, eio_req *req) |
2239 | eio_execute (etp_worker *self, eio_req *req) |
2011 | { |
2240 | { |
|
|
2241 | #if HAVE_AT |
|
|
2242 | int dirfd; |
|
|
2243 | #else |
|
|
2244 | const char *path; |
|
|
2245 | #endif |
|
|
2246 | |
2012 | if (ecb_expect_false (EIO_CANCELLED (req))) |
2247 | if (ecb_expect_false (EIO_CANCELLED (req))) |
2013 | { |
2248 | { |
2014 | req->result = -1; |
2249 | req->result = -1; |
2015 | req->errorno = ECANCELED; |
2250 | req->errorno = ECANCELED; |
2016 | return; |
2251 | return; |
2017 | } |
2252 | } |
2018 | |
2253 | |
|
|
2254 | if (ecb_expect_false (req->wd == EIO_INVALID_WD)) |
|
|
2255 | { |
|
|
2256 | req->result = -1; |
|
|
2257 | req->errorno = ENOENT; |
|
|
2258 | return; |
|
|
2259 | } |
|
|
2260 | |
|
|
2261 | if (req->type >= EIO_OPEN) |
|
|
2262 | { |
|
|
2263 | #if HAVE_AT |
|
|
2264 | dirfd = WD2FD (req->wd); |
|
|
2265 | #else |
|
|
2266 | path = wd_expand (&self->tmpbuf, req->wd, req->ptr1); |
|
|
2267 | #endif |
|
|
2268 | } |
|
|
2269 | |
2019 | switch (req->type) |
2270 | switch (req->type) |
2020 | { |
2271 | { |
|
|
2272 | case EIO_WD_OPEN: req->wd = eio__wd_open_sync (&self->tmpbuf, req->wd, req->ptr1); |
|
|
2273 | req->result = req->wd == EIO_INVALID_WD ? -1 : 0; |
|
|
2274 | break; |
|
|
2275 | case EIO_WD_CLOSE: eio_wd_close_sync (req->wd); break; |
|
|
2276 | |
2021 | case EIO_READ: ALLOC (req->size); |
2277 | case EIO_READ: ALLOC (req->size); |
2022 | req->result = req->offs >= 0 |
2278 | req->result = req->offs >= 0 |
2023 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
2279 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
2024 | : read (req->int1, req->ptr2, req->size); break; |
2280 | : read (req->int1, req->ptr2, req->size); break; |
2025 | case EIO_WRITE: req->result = req->offs >= 0 |
2281 | case EIO_WRITE: req->result = req->offs >= 0 |
2026 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
2282 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
2027 | : write (req->int1, req->ptr2, req->size); break; |
2283 | : write (req->int1, req->ptr2, req->size); break; |
2028 | |
2284 | |
2029 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
2285 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
2030 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size, self); break; |
2286 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; |
2031 | |
2287 | |
|
|
2288 | #if HAVE_AT |
2032 | case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2289 | case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2033 | req->result = stat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; |
2290 | req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, 0); break; |
2034 | case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2291 | case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
|
|
2292 | req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; |
|
|
2293 | case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break; |
|
|
2294 | case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break; |
|
|
2295 | case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break; |
|
|
2296 | case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break; |
|
|
2297 | |
|
|
2298 | case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; |
|
|
2299 | case EIO_RMDIR: req->result = unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; |
|
|
2300 | case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; |
|
|
2301 | case EIO_RENAME: req->result = renameat (dirfd, req->ptr1, WD2FD (req->int3), req->ptr2); break; |
|
|
2302 | case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD (req->int3), req->ptr2, 0); break; |
|
|
2303 | case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; |
|
|
2304 | case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; |
|
|
2305 | case EIO_READLINK: ALLOC (PATH_MAX); |
|
|
2306 | req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break; |
|
|
2307 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
|
|
2308 | req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
|
|
2309 | #else |
|
|
2310 | case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
|
|
2311 | req->result = stat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
|
|
2312 | case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2035 | req->result = lstat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; |
2313 | req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
|
|
2314 | case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; |
|
|
2315 | case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break; |
|
|
2316 | case EIO_TRUNCATE: req->result = truncate (path , req->offs); break; |
|
|
2317 | case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break; |
|
|
2318 | |
|
|
2319 | case EIO_UNLINK: req->result = unlink (path ); break; |
|
|
2320 | case EIO_RMDIR: req->result = rmdir (path ); break; |
|
|
2321 | case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; |
|
|
2322 | case EIO_RENAME: req->result = rename (path , req->ptr2); break; |
|
|
2323 | case EIO_LINK: req->result = link (path , req->ptr2); break; |
|
|
2324 | case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; |
|
|
2325 | case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; |
|
|
2326 | case EIO_READLINK: ALLOC (PATH_MAX); |
|
|
2327 | req->result = readlink (path, req->ptr2, PATH_MAX); break; |
|
|
2328 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
|
|
2329 | req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; |
|
|
2330 | #endif |
|
|
2331 | |
|
|
2332 | case EIO_REALPATH: if (0 <= (req->result = eio__realpath (&self->tmpbuf, req->wd, req->ptr1))) |
|
|
2333 | { |
|
|
2334 | ALLOC (req->result); |
|
|
2335 | memcpy (req->ptr2, self->tmpbuf.ptr, req->result); |
|
|
2336 | } |
|
|
2337 | break; |
|
|
2338 | |
2036 | case EIO_FSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2339 | case EIO_FSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); |
2037 | req->result = fstat (req->int1, (EIO_STRUCT_STAT *)req->ptr2); break; |
2340 | req->result = fstat (req->int1, (EIO_STRUCT_STAT *)req->ptr2); break; |
2038 | |
2341 | |
2039 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
|
|
2040 | req->result = statvfs (req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
|
|
2041 | case EIO_FSTATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
2342 | case EIO_FSTATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
2042 | req->result = fstatvfs (req->int1, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
2343 | req->result = fstatvfs (req->int1, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
2043 | |
2344 | |
2044 | case EIO_CHOWN: req->result = chown (req->ptr1, req->int2, req->int3); break; |
|
|
2045 | case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; |
2345 | case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; |
2046 | case EIO_CHMOD: req->result = chmod (req->ptr1, (mode_t)req->int2); break; |
|
|
2047 | case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break; |
2346 | case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break; |
2048 | case EIO_TRUNCATE: req->result = truncate (req->ptr1, req->offs); break; |
|
|
2049 | case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; |
2347 | case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; |
2050 | |
2348 | |
2051 | case EIO_OPEN: req->result = open (req->ptr1, req->int1, (mode_t)req->int2); break; |
|
|
2052 | case EIO_CLOSE: req->result = close (req->int1); break; |
2349 | case EIO_CLOSE: req->result = close (req->int1); break; |
2053 | case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; |
2350 | case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; |
2054 | case EIO_UNLINK: req->result = unlink (req->ptr1); break; |
|
|
2055 | case EIO_RMDIR: req->result = rmdir (req->ptr1); break; |
|
|
2056 | case EIO_MKDIR: req->result = mkdir (req->ptr1, (mode_t)req->int2); break; |
|
|
2057 | case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break; |
|
|
2058 | case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break; |
|
|
2059 | case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; |
|
|
2060 | case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; |
|
|
2061 | |
|
|
2062 | case EIO_REALPATH: eio__realpath (req, self); break; |
|
|
2063 | |
|
|
2064 | case EIO_READLINK: ALLOC (PATH_MAX); |
|
|
2065 | req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; |
|
|
2066 | |
|
|
2067 | case EIO_SYNC: req->result = 0; sync (); break; |
2351 | case EIO_SYNC: req->result = 0; sync (); break; |
2068 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2352 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2069 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
2353 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
|
|
2354 | case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; |
|
|
2355 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
2070 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
2356 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
2071 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
2357 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
2072 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
2358 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
2073 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
2359 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
2074 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
|
|
2075 | case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; |
2360 | case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; |
2076 | |
2361 | |
2077 | case EIO_READDIR: eio__scandir (req, self); break; |
2362 | case EIO_READDIR: eio__scandir (req); break; |
2078 | |
2363 | |
2079 | case EIO_BUSY: |
2364 | case EIO_BUSY: |
2080 | #ifdef _WIN32 |
2365 | #ifdef _WIN32 |
2081 | Sleep (req->nv1 * 1e3); |
2366 | Sleep (req->nv1 * 1e3); |
2082 | #else |
2367 | #else |
… | |
… | |
2160 | eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2445 | eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2161 | { |
2446 | { |
2162 | REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2447 | REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2163 | } |
2448 | } |
2164 | |
2449 | |
|
|
2450 | eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
|
|
2451 | { |
|
|
2452 | REQ (EIO_FDATASYNC); req->int1 = fd; SEND; |
|
|
2453 | } |
|
|
2454 | |
|
|
2455 | eio_req *eio_syncfs (int fd, int pri, eio_cb cb, void *data) |
|
|
2456 | { |
|
|
2457 | REQ (EIO_SYNCFS); req->int1 = fd; SEND; |
|
|
2458 | } |
|
|
2459 | |
|
|
2460 | eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
|
|
2461 | { |
|
|
2462 | REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; |
|
|
2463 | } |
|
|
2464 | |
2165 | eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2465 | eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) |
2166 | { |
2466 | { |
2167 | REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2467 | REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; |
2168 | } |
2468 | } |
2169 | |
2469 | |
… | |
… | |
2175 | eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data) |
2475 | eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data) |
2176 | { |
2476 | { |
2177 | REQ (EIO_MLOCKALL); req->int1 = flags; SEND; |
2477 | REQ (EIO_MLOCKALL); req->int1 = flags; SEND; |
2178 | } |
2478 | } |
2179 | |
2479 | |
2180 | eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) |
|
|
2181 | { |
|
|
2182 | REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; |
|
|
2183 | } |
|
|
2184 | |
|
|
2185 | eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data) |
2480 | eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data) |
2186 | { |
2481 | { |
2187 | REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND; |
2482 | REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND; |
2188 | } |
|
|
2189 | |
|
|
2190 | eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) |
|
|
2191 | { |
|
|
2192 | REQ (EIO_FDATASYNC); req->int1 = fd; SEND; |
|
|
2193 | } |
2483 | } |
2194 | |
2484 | |
2195 | eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) |
2485 | eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) |
2196 | { |
2486 | { |
2197 | REQ (EIO_CLOSE); req->int1 = fd; SEND; |
2487 | REQ (EIO_CLOSE); req->int1 = fd; SEND; |
… | |
… | |
2425 | /* misc garbage */ |
2715 | /* misc garbage */ |
2426 | |
2716 | |
2427 | eio_ssize_t |
2717 | eio_ssize_t |
2428 | eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) |
2718 | eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) |
2429 | { |
2719 | { |
2430 | etp_worker wrk; |
|
|
2431 | eio_ssize_t ret; |
|
|
2432 | |
|
|
2433 | wrk.dbuf = 0; |
|
|
2434 | |
|
|
2435 | ret = eio__sendfile (ofd, ifd, offset, count, &wrk); |
2720 | return eio__sendfile (ofd, ifd, offset, count); |
2436 | |
|
|
2437 | if (wrk.dbuf) |
|
|
2438 | free (wrk.dbuf); |
|
|
2439 | |
|
|
2440 | return ret; |
|
|
2441 | } |
2721 | } |
2442 | |
2722 | |