1 | /* |
1 | /* |
2 | * libeio implementation |
2 | * libeio implementation |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libeio@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2016,2017 Marc Alexander Lehmann <libeio@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * tion, are permitted provided that the following conditions are met: |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * |
9 | * |
… | |
… | |
42 | #endif |
42 | #endif |
43 | |
43 | |
44 | #include "eio.h" |
44 | #include "eio.h" |
45 | #include "ecb.h" |
45 | #include "ecb.h" |
46 | |
46 | |
47 | #ifdef EIO_STACKSIZE |
|
|
48 | # define X_STACKSIZE EIO_STACKSIZE |
|
|
49 | #endif |
|
|
50 | #include "xthread.h" |
|
|
51 | |
|
|
52 | #include <errno.h> |
47 | #include <errno.h> |
53 | #include <stddef.h> |
48 | #include <stddef.h> |
54 | #include <stdlib.h> |
49 | #include <stdlib.h> |
55 | #include <string.h> |
50 | #include <string.h> |
56 | #include <errno.h> |
51 | #include <errno.h> |
… | |
… | |
120 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
115 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
121 | |
116 | |
122 | #define chmod(path,mode) _chmod (path, mode) |
117 | #define chmod(path,mode) _chmod (path, mode) |
123 | #define dup(fd) _dup (fd) |
118 | #define dup(fd) _dup (fd) |
124 | #define dup2(fd1,fd2) _dup2 (fd1, fd2) |
119 | #define dup2(fd1,fd2) _dup2 (fd1, fd2) |
|
|
120 | #define pipe(fds) _pipe (fds, 4096, O_BINARY) |
125 | |
121 | |
|
|
122 | #define fcntl(fd,cmd,arg) EIO_ENOSYS () |
|
|
123 | #define ioctl(fd,cmd,arg) EIO_ENOSYS () |
126 | #define fchmod(fd,mode) EIO_ENOSYS () |
124 | #define fchmod(fd,mode) EIO_ENOSYS () |
127 | #define chown(path,uid,gid) EIO_ENOSYS () |
125 | #define chown(path,uid,gid) EIO_ENOSYS () |
128 | #define fchown(fd,uid,gid) EIO_ENOSYS () |
126 | #define fchown(fd,uid,gid) EIO_ENOSYS () |
129 | #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */ |
127 | #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */ |
130 | #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */ |
128 | #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */ |
… | |
… | |
203 | /* we could even stat and see if it exists */ |
201 | /* we could even stat and see if it exists */ |
204 | static int |
202 | static int |
205 | symlink (const char *old, const char *neu) |
203 | symlink (const char *old, const char *neu) |
206 | { |
204 | { |
207 | #if WINVER >= 0x0600 |
205 | #if WINVER >= 0x0600 |
|
|
206 | int flags; |
|
|
207 | |
|
|
208 | /* This tries out all combinations of SYMBOLIC_LINK_FLAG_DIRECTORY |
|
|
209 | * and SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE, |
|
|
210 | * with directory first. |
|
|
211 | */ |
|
|
212 | for (flags = 3; flags >= 0; --flags) |
208 | if (CreateSymbolicLink (neu, old, 1)) |
213 | if (CreateSymbolicLink (neu, old, flags)) |
209 | return 0; |
214 | return 0; |
210 | |
|
|
211 | if (CreateSymbolicLink (neu, old, 0)) |
|
|
212 | return 0; |
|
|
213 | #endif |
215 | #endif |
214 | |
216 | |
215 | return EIO_ERRNO (ENOENT, -1); |
217 | return EIO_ERRNO (ENOENT, -1); |
216 | } |
218 | } |
217 | |
219 | |
… | |
… | |
229 | #define D_NAME(entp) entp.cFileName |
231 | #define D_NAME(entp) entp.cFileName |
230 | #define D_TYPE(entp) (entp.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? DT_DIR : DT_REG) |
232 | #define D_TYPE(entp) (entp.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? DT_DIR : DT_REG) |
231 | |
233 | |
232 | #else |
234 | #else |
233 | |
235 | |
|
|
236 | #include <sys/ioctl.h> |
234 | #include <sys/time.h> |
237 | #include <sys/time.h> |
235 | #include <sys/select.h> |
238 | #include <sys/select.h> |
236 | #include <unistd.h> |
239 | #include <unistd.h> |
237 | #include <signal.h> |
240 | #include <signal.h> |
238 | #include <dirent.h> |
241 | #include <dirent.h> |
… | |
… | |
280 | # include <utime.h> |
283 | # include <utime.h> |
281 | #endif |
284 | #endif |
282 | |
285 | |
283 | #if HAVE_SYS_SYSCALL_H |
286 | #if HAVE_SYS_SYSCALL_H |
284 | # include <sys/syscall.h> |
287 | # include <sys/syscall.h> |
285 | #endif |
|
|
286 | |
|
|
287 | #if HAVE_SYS_PRCTL_H |
|
|
288 | # include <sys/prctl.h> |
|
|
289 | #endif |
288 | #endif |
290 | |
289 | |
291 | #if HAVE_SENDFILE |
290 | #if HAVE_SENDFILE |
292 | # if __linux |
291 | # if __linux |
293 | # include <sys/sendfile.h> |
292 | # include <sys/sendfile.h> |
… | |
… | |
301 | # else |
300 | # else |
302 | # error sendfile support requested but not available |
301 | # error sendfile support requested but not available |
303 | # endif |
302 | # endif |
304 | #endif |
303 | #endif |
305 | |
304 | |
|
|
305 | #if HAVE_RENAMEAT2 |
|
|
306 | # include <sys/syscall.h> |
|
|
307 | # include <linux/fs.h> |
|
|
308 | #endif |
|
|
309 | |
306 | #ifndef D_TYPE |
310 | #ifndef D_TYPE |
307 | # define D_TYPE(de) 0 |
311 | # define D_TYPE(de) 0 |
308 | #endif |
312 | #endif |
309 | #ifndef D_INO |
313 | #ifndef D_INO |
310 | # define D_INO(de) 0 |
314 | # define D_INO(de) 0 |
… | |
… | |
318 | # define NAME_MAX 4096 |
322 | # define NAME_MAX 4096 |
319 | #endif |
323 | #endif |
320 | |
324 | |
321 | /* used for readlink etc. */ |
325 | /* used for readlink etc. */ |
322 | #ifndef PATH_MAX |
326 | #ifndef PATH_MAX |
323 | # define PATH_MAX 4096 |
327 | # define PATH_MAX 0 |
324 | #endif |
328 | #endif |
|
|
329 | |
|
|
330 | #ifndef O_CLOEXEC |
|
|
331 | #define O_CLOEXEC 0 |
|
|
332 | #endif |
|
|
333 | |
|
|
334 | #ifndef EIO_PATH_MIN |
|
|
335 | # define EIO_PATH_MIN 8160 |
|
|
336 | #endif |
|
|
337 | |
|
|
338 | #define EIO_PATH_MAX (PATH_MAX <= EIO_PATH_MIN ? EIO_PATH_MIN : PATH_MAX) |
325 | |
339 | |
326 | /* buffer size for various temporary buffers */ |
340 | /* buffer size for various temporary buffers */ |
327 | #define EIO_BUFSIZE 65536 |
341 | #define EIO_BUFSIZE 65536 |
328 | |
342 | |
329 | #define dBUF \ |
343 | #define dBUF \ |
… | |
… | |
335 | #define FUBd \ |
349 | #define FUBd \ |
336 | free (eio_buf) |
350 | free (eio_buf) |
337 | |
351 | |
338 | /*****************************************************************************/ |
352 | /*****************************************************************************/ |
339 | |
353 | |
340 | struct tmpbuf |
|
|
341 | { |
|
|
342 | void *ptr; |
|
|
343 | int len; |
|
|
344 | }; |
|
|
345 | |
|
|
346 | static void * |
|
|
347 | tmpbuf_get (struct tmpbuf *buf, int len) |
|
|
348 | { |
|
|
349 | if (buf->len < len) |
|
|
350 | { |
|
|
351 | free (buf->ptr); |
|
|
352 | buf->ptr = malloc (buf->len = len); |
|
|
353 | } |
|
|
354 | |
|
|
355 | return buf->ptr; |
|
|
356 | } |
|
|
357 | |
|
|
358 | struct tmpbuf; |
354 | struct etp_tmpbuf; |
359 | |
355 | |
360 | #if _POSIX_VERSION >= 200809L |
356 | #if _POSIX_VERSION >= 200809L |
361 | #define HAVE_AT 1 |
357 | #define HAVE_AT 1 |
362 | #define WD2FD(wd) ((wd) ? (wd)->fd : AT_FDCWD) |
358 | #define WD2FD(wd) ((wd) ? (wd)->fd : AT_FDCWD) |
363 | #ifndef O_SEARCH |
359 | #ifndef O_SEARCH |
364 | #define O_SEARCH O_RDONLY |
360 | #define O_SEARCH O_RDONLY |
365 | #endif |
361 | #endif |
366 | #else |
362 | #else |
367 | #define HAVE_AT 0 |
363 | #define HAVE_AT 0 |
368 | static const char *wd_expand (struct tmpbuf *tmpbuf, eio_wd wd, const char *path); |
364 | static const char *wd_expand (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path); |
369 | #endif |
365 | #endif |
370 | |
366 | |
371 | struct eio_pwd |
367 | struct eio_pwd |
372 | { |
368 | { |
373 | #if HAVE_AT |
369 | #if HAVE_AT |
… | |
… | |
383 | #define ETP_PRI_MAX EIO_PRI_MAX |
379 | #define ETP_PRI_MAX EIO_PRI_MAX |
384 | |
380 | |
385 | #define ETP_TYPE_QUIT -1 |
381 | #define ETP_TYPE_QUIT -1 |
386 | #define ETP_TYPE_GROUP EIO_GROUP |
382 | #define ETP_TYPE_GROUP EIO_GROUP |
387 | |
383 | |
|
|
384 | static void eio_nop_callback (void) { } |
|
|
385 | static void (*eio_want_poll_cb)(void) = eio_nop_callback; |
|
|
386 | static void (*eio_done_poll_cb)(void) = eio_nop_callback; |
|
|
387 | |
|
|
388 | #define ETP_WANT_POLL(pool) eio_want_poll_cb () |
|
|
389 | #define ETP_DONE_POLL(pool) eio_done_poll_cb () |
|
|
390 | |
388 | struct etp_worker; |
391 | struct etp_worker; |
389 | |
|
|
390 | #define ETP_REQ eio_req |
392 | #define ETP_REQ eio_req |
391 | #define ETP_DESTROY(req) eio_destroy (req) |
393 | #define ETP_DESTROY(req) eio_destroy (req) |
392 | static int eio_finish (eio_req *req); |
394 | static int eio_finish (eio_req *req); |
393 | #define ETP_FINISH(req) eio_finish (req) |
395 | #define ETP_FINISH(req) eio_finish (req) |
394 | static void eio_execute (struct etp_worker *self, eio_req *req); |
396 | static void eio_execute (struct etp_worker *self, eio_req *req); |
395 | #define ETP_EXECUTE(wrk,req) eio_execute (wrk, req) |
397 | #define ETP_EXECUTE(wrk,req) eio_execute (wrk, req) |
396 | |
398 | |
397 | #include "etp.c" |
399 | #include "etp.c" |
398 | |
400 | |
|
|
401 | static struct etp_pool eio_pool; |
|
|
402 | #define EIO_POOL (&eio_pool) |
|
|
403 | |
399 | /*****************************************************************************/ |
404 | /*****************************************************************************/ |
400 | |
405 | |
401 | static void |
406 | static void |
402 | grp_try_feed (eio_req *grp) |
407 | grp_try_feed (eio_req *grp) |
403 | { |
408 | { |
404 | while (grp->size < grp->int2 && !EIO_CANCELLED (grp)) |
409 | while (grp->size < grp->int2 && !EIO_CANCELLED (grp)) |
405 | { |
410 | { |
406 | grp->flags &= ~EIO_FLAG_GROUPADD; |
411 | grp->flags &= ~ETP_FLAG_GROUPADD; |
407 | |
412 | |
408 | EIO_FEED (grp); |
413 | EIO_FEED (grp); |
409 | |
414 | |
410 | /* stop if no progress has been made */ |
415 | /* stop if no progress has been made */ |
411 | if (!(grp->flags & EIO_FLAG_GROUPADD)) |
416 | if (!(grp->flags & ETP_FLAG_GROUPADD)) |
412 | { |
417 | { |
413 | grp->feed = 0; |
418 | grp->feed = 0; |
414 | break; |
419 | break; |
415 | } |
420 | } |
416 | } |
421 | } |
… | |
… | |
423 | |
428 | |
424 | /* call feeder, if applicable */ |
429 | /* call feeder, if applicable */ |
425 | grp_try_feed (grp); |
430 | grp_try_feed (grp); |
426 | |
431 | |
427 | /* finish, if done */ |
432 | /* finish, if done */ |
428 | if (!grp->size && grp->int1) |
433 | if (!grp->size && grp->flags & ETP_FLAG_DELAYED) |
429 | return eio_finish (grp); |
434 | return eio_finish (grp); |
430 | else |
435 | else |
431 | return 0; |
436 | return 0; |
432 | } |
437 | } |
433 | |
438 | |
… | |
… | |
469 | } |
474 | } |
470 | |
475 | |
471 | void |
476 | void |
472 | eio_grp_cancel (eio_req *grp) |
477 | eio_grp_cancel (eio_req *grp) |
473 | { |
478 | { |
474 | etp_grp_cancel (grp); |
479 | etp_grp_cancel (EIO_POOL, grp); |
475 | } |
480 | } |
476 | |
481 | |
477 | void |
482 | void |
478 | eio_cancel (eio_req *req) |
483 | eio_cancel (eio_req *req) |
479 | { |
484 | { |
480 | etp_cancel (req); |
485 | etp_cancel (EIO_POOL, req); |
481 | } |
486 | } |
482 | |
487 | |
483 | void |
488 | void |
484 | eio_submit (eio_req *req) |
489 | eio_submit (eio_req *req) |
485 | { |
490 | { |
486 | etp_submit (req); |
491 | etp_submit (EIO_POOL, req); |
487 | } |
492 | } |
488 | |
493 | |
489 | unsigned int |
494 | unsigned int |
490 | eio_nreqs (void) |
495 | eio_nreqs (void) |
491 | { |
496 | { |
492 | return etp_nreqs (); |
497 | return etp_nreqs (EIO_POOL); |
493 | } |
498 | } |
494 | |
499 | |
495 | unsigned int |
500 | unsigned int |
496 | eio_nready (void) |
501 | eio_nready (void) |
497 | { |
502 | { |
498 | return etp_nready (); |
503 | return etp_nready (EIO_POOL); |
499 | } |
504 | } |
500 | |
505 | |
501 | unsigned int |
506 | unsigned int |
502 | eio_npending (void) |
507 | eio_npending (void) |
503 | { |
508 | { |
504 | return etp_npending (); |
509 | return etp_npending (EIO_POOL); |
505 | } |
510 | } |
506 | |
511 | |
507 | unsigned int ecb_cold |
512 | unsigned int ecb_cold |
508 | eio_nthreads (void) |
513 | eio_nthreads (void) |
509 | { |
514 | { |
510 | return etp_nthreads (); |
515 | return etp_nthreads (EIO_POOL); |
511 | } |
516 | } |
512 | |
517 | |
513 | void ecb_cold |
518 | void ecb_cold |
514 | eio_set_max_poll_time (double nseconds) |
519 | eio_set_max_poll_time (double nseconds) |
515 | { |
520 | { |
516 | etp_set_max_poll_time (nseconds); |
521 | etp_set_max_poll_time (EIO_POOL, nseconds); |
517 | } |
522 | } |
518 | |
523 | |
519 | void ecb_cold |
524 | void ecb_cold |
520 | eio_set_max_poll_reqs (unsigned int maxreqs) |
525 | eio_set_max_poll_reqs (unsigned int maxreqs) |
521 | { |
526 | { |
522 | etp_set_max_poll_reqs (maxreqs); |
527 | etp_set_max_poll_reqs (EIO_POOL, maxreqs); |
523 | } |
528 | } |
524 | |
529 | |
525 | void ecb_cold |
530 | void ecb_cold |
526 | eio_set_max_idle (unsigned int nthreads) |
531 | eio_set_max_idle (unsigned int nthreads) |
527 | { |
532 | { |
528 | etp_set_max_idle (nthreads); |
533 | etp_set_max_idle (EIO_POOL, nthreads); |
529 | } |
534 | } |
530 | |
535 | |
531 | void ecb_cold |
536 | void ecb_cold |
532 | eio_set_idle_timeout (unsigned int seconds) |
537 | eio_set_idle_timeout (unsigned int seconds) |
533 | { |
538 | { |
534 | etp_set_idle_timeout (seconds); |
539 | etp_set_idle_timeout (EIO_POOL, seconds); |
535 | } |
540 | } |
536 | |
541 | |
537 | void ecb_cold |
542 | void ecb_cold |
538 | eio_set_min_parallel (unsigned int nthreads) |
543 | eio_set_min_parallel (unsigned int nthreads) |
539 | { |
544 | { |
540 | etp_set_min_parallel (nthreads); |
545 | etp_set_min_parallel (EIO_POOL, nthreads); |
541 | } |
546 | } |
542 | |
547 | |
543 | void ecb_cold |
548 | void ecb_cold |
544 | eio_set_max_parallel (unsigned int nthreads) |
549 | eio_set_max_parallel (unsigned int nthreads) |
545 | { |
550 | { |
546 | etp_set_max_parallel (nthreads); |
551 | etp_set_max_parallel (EIO_POOL, nthreads); |
547 | } |
552 | } |
548 | |
553 | |
549 | int eio_poll (void) |
554 | int eio_poll (void) |
550 | { |
555 | { |
551 | return etp_poll (); |
556 | return etp_poll (EIO_POOL); |
552 | } |
557 | } |
553 | |
558 | |
554 | /*****************************************************************************/ |
559 | /*****************************************************************************/ |
555 | /* work around various missing functions */ |
560 | /* work around various missing functions */ |
|
|
561 | |
|
|
562 | #if HAVE_POSIX_CLOSE && !__linux |
|
|
563 | # define eio__close(fd) posix_close (fd, 0) |
|
|
564 | #else |
|
|
565 | # define eio__close(fd) close (fd) |
|
|
566 | #endif |
|
|
567 | |
|
|
568 | /* close() without disturbing errno */ |
|
|
569 | static void |
|
|
570 | silent_close (int fd) |
|
|
571 | { |
|
|
572 | int saved_errno = errno; |
|
|
573 | eio__close (fd); |
|
|
574 | errno = saved_errno; |
|
|
575 | } |
556 | |
576 | |
557 | #ifndef HAVE_UTIMES |
577 | #ifndef HAVE_UTIMES |
558 | |
578 | |
559 | # undef utimes |
579 | # undef utimes |
560 | # define utimes(path,times) eio__utimes (path, times) |
580 | # define utimes(path,times) eio__utimes (path, times) |
… | |
… | |
939 | intptr_t end = addr + len; |
959 | intptr_t end = addr + len; |
940 | intptr_t page = eio_pagesize (); |
960 | intptr_t page = eio_pagesize (); |
941 | |
961 | |
942 | if (addr < end) |
962 | if (addr < end) |
943 | if (flags & EIO_MT_MODIFY) /* modify */ |
963 | if (flags & EIO_MT_MODIFY) /* modify */ |
944 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
964 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < end && !EIO_CANCELLED (req)); |
945 | else |
965 | else |
946 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
966 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < end && !EIO_CANCELLED (req)); |
947 | } |
967 | } |
948 | |
968 | |
949 | return 0; |
969 | return 0; |
950 | } |
970 | } |
951 | |
971 | |
… | |
… | |
966 | req->result = req->offs == (off_t)-1 ? -1 : 0; |
986 | req->result = req->offs == (off_t)-1 ? -1 : 0; |
967 | } |
987 | } |
968 | |
988 | |
969 | /* result will always end up in tmpbuf, there is always space for adding a 0-byte */ |
989 | /* result will always end up in tmpbuf, there is always space for adding a 0-byte */ |
970 | static int |
990 | static int |
971 | eio__realpath (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
991 | eio__realpath (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path) |
972 | { |
992 | { |
|
|
993 | char *res; |
973 | const char *rel = path; |
994 | const char *rel = path; |
974 | char *res; |
|
|
975 | char *tmp1, *tmp2; |
995 | char *tmp1, *tmp2; |
976 | #if SYMLOOP_MAX > 32 |
996 | #if SYMLOOP_MAX > 32 |
977 | int symlinks = SYMLOOP_MAX; |
997 | int symlinks = SYMLOOP_MAX; |
978 | #else |
998 | #else |
979 | int symlinks = 32; |
999 | int symlinks = 32; |
… | |
… | |
985 | |
1005 | |
986 | errno = ENOENT; |
1006 | errno = ENOENT; |
987 | if (!*rel) |
1007 | if (!*rel) |
988 | return -1; |
1008 | return -1; |
989 | |
1009 | |
990 | res = tmpbuf_get (tmpbuf, PATH_MAX * 3); |
1010 | res = etp_tmpbuf_get (tmpbuf, EIO_PATH_MAX * 3); |
|
|
1011 | #ifdef _WIN32 |
|
|
1012 | if (_access (rel, 4) != 0) |
|
|
1013 | return -1; |
|
|
1014 | |
|
|
1015 | symlinks = GetFullPathName (rel, EIO_PATH_MAX * 3, res, 0); |
|
|
1016 | |
|
|
1017 | errno = ENAMETOOLONG; |
|
|
1018 | if (symlinks >= EIO_PATH_MAX * 3) |
|
|
1019 | return -1; |
|
|
1020 | |
|
|
1021 | errno = EIO; |
|
|
1022 | if (symlinks <= 0) |
|
|
1023 | return -1; |
|
|
1024 | |
|
|
1025 | return symlinks; |
|
|
1026 | |
|
|
1027 | #else |
991 | tmp1 = res + PATH_MAX; |
1028 | tmp1 = res + EIO_PATH_MAX; |
992 | tmp2 = tmp1 + PATH_MAX; |
1029 | tmp2 = tmp1 + EIO_PATH_MAX; |
993 | |
1030 | |
994 | #if 0 /* disabled, the musl way to do things is just too racy */ |
1031 | #if 0 /* disabled, the musl way to do things is just too racy */ |
995 | #if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) |
1032 | #if __linux && defined(O_NONBLOCK) && defined(O_NOATIME) |
996 | /* on linux we may be able to ask the kernel */ |
1033 | /* on linux we may be able to ask the kernel */ |
997 | { |
1034 | { |
998 | int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME); |
1035 | int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME); |
999 | |
1036 | |
1000 | if (fd >= 0) |
1037 | if (fd >= 0) |
1001 | { |
1038 | { |
1002 | sprintf (tmp1, "/proc/self/fd/%d", fd); |
1039 | sprintf (tmp1, "/proc/self/fd/%d", fd); |
1003 | req->result = readlink (tmp1, res, PATH_MAX); |
1040 | req->result = readlink (tmp1, res, EIO_PATH_MAX); |
1004 | /* here we should probably stat the open file and the disk file, to make sure they still match */ |
1041 | /* here we should probably stat the open file and the disk file, to make sure they still match */ |
1005 | close (fd); |
1042 | eio__close (fd); |
1006 | |
1043 | |
1007 | if (req->result > 0) |
1044 | if (req->result > 0) |
1008 | goto done; |
1045 | goto done; |
1009 | } |
1046 | } |
1010 | else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO) |
1047 | else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO) |
… | |
… | |
1021 | if (wd == EIO_INVALID_WD) |
1058 | if (wd == EIO_INVALID_WD) |
1022 | return -1; |
1059 | return -1; |
1023 | |
1060 | |
1024 | if (wd == EIO_CWD) |
1061 | if (wd == EIO_CWD) |
1025 | { |
1062 | { |
1026 | if (!getcwd (res, PATH_MAX)) |
1063 | if (!getcwd (res, EIO_PATH_MAX)) |
1027 | return -1; |
1064 | return -1; |
1028 | |
1065 | |
1029 | len = strlen (res); |
1066 | len = strlen (res); |
1030 | } |
1067 | } |
1031 | else |
1068 | else |
… | |
… | |
1078 | |
1115 | |
1079 | /* zero-terminate, for readlink */ |
1116 | /* zero-terminate, for readlink */ |
1080 | res [len + 1] = 0; |
1117 | res [len + 1] = 0; |
1081 | |
1118 | |
1082 | /* now check if it's a symlink */ |
1119 | /* now check if it's a symlink */ |
1083 | linklen = readlink (tmpbuf->ptr, tmp1, PATH_MAX); |
1120 | linklen = readlink (tmpbuf->ptr, tmp1, EIO_PATH_MAX); |
1084 | |
1121 | |
1085 | if (linklen < 0) |
1122 | if (linklen < 0) |
1086 | { |
1123 | { |
1087 | if (errno != EINVAL) |
1124 | if (errno != EINVAL) |
1088 | return -1; |
1125 | return -1; |
… | |
… | |
1094 | { |
1131 | { |
1095 | /* yay, it was a symlink - build new path in tmp2 */ |
1132 | /* yay, it was a symlink - build new path in tmp2 */ |
1096 | int rellen = strlen (rel); |
1133 | int rellen = strlen (rel); |
1097 | |
1134 | |
1098 | errno = ENAMETOOLONG; |
1135 | errno = ENAMETOOLONG; |
1099 | if (linklen + 1 + rellen >= PATH_MAX) |
1136 | if (linklen + 1 + rellen >= EIO_PATH_MAX) /* also catch linklen >= EIO_PATH_MAX */ |
1100 | return -1; |
1137 | return -1; |
1101 | |
1138 | |
1102 | errno = ELOOP; |
1139 | errno = ELOOP; |
1103 | if (!--symlinks) |
1140 | if (!--symlinks) |
1104 | return -1; |
1141 | return -1; |
… | |
… | |
1118 | /* special case for the lone root path */ |
1155 | /* special case for the lone root path */ |
1119 | if (res == tmpbuf->ptr) |
1156 | if (res == tmpbuf->ptr) |
1120 | *res++ = '/'; |
1157 | *res++ = '/'; |
1121 | |
1158 | |
1122 | return res - (char *)tmpbuf->ptr; |
1159 | return res - (char *)tmpbuf->ptr; |
|
|
1160 | #endif |
1123 | } |
1161 | } |
1124 | |
1162 | |
1125 | static signed char |
1163 | static signed char |
1126 | eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) |
1164 | eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) |
1127 | { |
1165 | { |
… | |
… | |
1367 | return; |
1405 | return; |
1368 | |
1406 | |
1369 | dirp = fdopendir (fd); |
1407 | dirp = fdopendir (fd); |
1370 | |
1408 | |
1371 | if (!dirp) |
1409 | if (!dirp) |
1372 | close (fd); |
1410 | silent_close (fd); |
1373 | } |
1411 | } |
1374 | else |
1412 | else |
1375 | dirp = opendir (req->ptr1); |
1413 | dirp = opendir (req->ptr1); |
1376 | #else |
1414 | #else |
1377 | dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); |
1415 | dirp = opendir (wd_expand (&self->tmpbuf, req->wd, req->ptr1)); |
… | |
… | |
1586 | #if !HAVE_AT |
1624 | #if !HAVE_AT |
1587 | |
1625 | |
1588 | /* a bit like realpath, but usually faster because it doesn'T have to return */ |
1626 | /* a bit like realpath, but usually faster because it doesn'T have to return */ |
1589 | /* an absolute or canonical path */ |
1627 | /* an absolute or canonical path */ |
1590 | static const char * |
1628 | static const char * |
1591 | wd_expand (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
1629 | wd_expand (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path) |
1592 | { |
1630 | { |
1593 | if (!wd || *path == '/') |
1631 | if (!wd || *path == '/') |
1594 | return path; |
1632 | return path; |
1595 | |
1633 | |
1596 | if (path [0] == '.' && !path [1]) |
1634 | if (path [0] == '.' && !path [1]) |
… | |
… | |
1598 | |
1636 | |
1599 | { |
1637 | { |
1600 | int l1 = wd->len; |
1638 | int l1 = wd->len; |
1601 | int l2 = strlen (path); |
1639 | int l2 = strlen (path); |
1602 | |
1640 | |
1603 | char *res = tmpbuf_get (tmpbuf, l1 + l2 + 2); |
1641 | char *res = etp_tmpbuf_get (tmpbuf, l1 + l2 + 2); |
1604 | |
1642 | |
1605 | memcpy (res, wd->str, l1); |
1643 | memcpy (res, wd->str, l1); |
1606 | res [l1] = '/'; |
1644 | res [l1] = '/'; |
1607 | memcpy (res + l1 + 1, path, l2 + 1); |
1645 | memcpy (res + l1 + 1, path, l2 + 1); |
1608 | |
1646 | |
… | |
… | |
1611 | } |
1649 | } |
1612 | |
1650 | |
1613 | #endif |
1651 | #endif |
1614 | |
1652 | |
1615 | static eio_wd |
1653 | static eio_wd |
1616 | eio__wd_open_sync (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) |
1654 | eio__wd_open_sync (struct etp_tmpbuf *tmpbuf, eio_wd wd, const char *path) |
1617 | { |
1655 | { |
1618 | int fd; |
1656 | int fd; |
1619 | eio_wd res; |
1657 | eio_wd res; |
1620 | int len = eio__realpath (tmpbuf, wd, path); |
1658 | int len = eio__realpath (tmpbuf, wd, path); |
1621 | |
1659 | |
… | |
… | |
1643 | } |
1681 | } |
1644 | |
1682 | |
1645 | eio_wd |
1683 | eio_wd |
1646 | eio_wd_open_sync (eio_wd wd, const char *path) |
1684 | eio_wd_open_sync (eio_wd wd, const char *path) |
1647 | { |
1685 | { |
1648 | struct tmpbuf tmpbuf = { 0 }; |
1686 | struct etp_tmpbuf tmpbuf = { }; |
1649 | wd = eio__wd_open_sync (&tmpbuf, wd, path); |
1687 | wd = eio__wd_open_sync (&tmpbuf, wd, path); |
1650 | free (tmpbuf.ptr); |
1688 | free (tmpbuf.ptr); |
1651 | |
1689 | |
1652 | return wd; |
1690 | return wd; |
1653 | } |
1691 | } |
… | |
… | |
1656 | eio_wd_close_sync (eio_wd wd) |
1694 | eio_wd_close_sync (eio_wd wd) |
1657 | { |
1695 | { |
1658 | if (wd != EIO_INVALID_WD && wd != EIO_CWD) |
1696 | if (wd != EIO_INVALID_WD && wd != EIO_CWD) |
1659 | { |
1697 | { |
1660 | #if HAVE_AT |
1698 | #if HAVE_AT |
1661 | close (wd->fd); |
1699 | eio__close (wd->fd); |
1662 | #endif |
1700 | #endif |
1663 | free (wd); |
1701 | free (wd); |
1664 | } |
1702 | } |
1665 | } |
1703 | } |
1666 | |
1704 | |
1667 | #if HAVE_AT |
1705 | #if HAVE_AT |
1668 | |
1706 | |
|
|
1707 | static int |
|
|
1708 | eio__renameat2 (int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags) |
|
|
1709 | { |
|
|
1710 | #if HAVE_RENAMEAT2 |
|
|
1711 | return syscall (SYS_renameat2, olddirfd, oldpath, newdirfd, newpath, flags); |
|
|
1712 | #else |
|
|
1713 | if (flags) |
|
|
1714 | return EIO_ENOSYS (); |
|
|
1715 | |
|
|
1716 | return renameat (olddirfd, oldpath, newdirfd, newpath); |
|
|
1717 | #endif |
|
|
1718 | } |
|
|
1719 | |
1669 | /* they forgot these */ |
1720 | /* they forgot these */ |
1670 | |
1721 | |
1671 | static int |
1722 | static int |
1672 | eio__truncateat (int dirfd, const char *path, off_t length) |
1723 | eio__truncateat (int dirfd, const char *path, off_t length) |
1673 | { |
1724 | { |
… | |
… | |
1676 | |
1727 | |
1677 | if (fd < 0) |
1728 | if (fd < 0) |
1678 | return fd; |
1729 | return fd; |
1679 | |
1730 | |
1680 | res = ftruncate (fd, length); |
1731 | res = ftruncate (fd, length); |
1681 | close (fd); |
1732 | silent_close (fd); |
1682 | return res; |
1733 | return res; |
1683 | } |
1734 | } |
1684 | |
1735 | |
1685 | static int |
1736 | static int |
1686 | eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) |
1737 | eio__statvfsat (int dirfd, const char *path, struct statvfs *buf) |
… | |
… | |
1690 | |
1741 | |
1691 | if (fd < 0) |
1742 | if (fd < 0) |
1692 | return fd; |
1743 | return fd; |
1693 | |
1744 | |
1694 | res = fstatvfs (fd, buf); |
1745 | res = fstatvfs (fd, buf); |
1695 | close (fd); |
1746 | silent_close (fd); |
1696 | return res; |
1747 | return res; |
1697 | |
|
|
1698 | } |
1748 | } |
1699 | |
1749 | |
1700 | #endif |
1750 | #endif |
1701 | |
1751 | |
1702 | /*****************************************************************************/ |
1752 | /*****************************************************************************/ |
1703 | |
1753 | |
1704 | #define ALLOC(len) \ |
1754 | #define ALLOC(len) \ |
1705 | if (!req->ptr2) \ |
1755 | if (!req->ptr2) \ |
1706 | { \ |
1756 | { \ |
1707 | X_LOCK (wrklock); \ |
1757 | X_LOCK (EIO_POOL->wrklock); \ |
1708 | req->flags |= EIO_FLAG_PTR2_FREE; \ |
1758 | req->flags |= EIO_FLAG_PTR2_FREE; \ |
1709 | X_UNLOCK (wrklock); \ |
1759 | X_UNLOCK (EIO_POOL->wrklock); \ |
1710 | req->ptr2 = malloc (len); \ |
1760 | req->ptr2 = malloc (len); \ |
1711 | if (!req->ptr2) \ |
1761 | if (!req->ptr2) \ |
1712 | { \ |
1762 | { \ |
1713 | errno = ENOMEM; \ |
1763 | errno = ENOMEM; \ |
1714 | req->result = -1; \ |
1764 | req->result = -1; \ |
1715 | break; \ |
1765 | goto alloc_fail; \ |
1716 | } \ |
1766 | } \ |
1717 | } |
1767 | } |
1718 | |
1768 | |
1719 | static void ecb_noinline ecb_cold |
1769 | /*****************************************************************************/ |
1720 | etp_proc_init (void) |
|
|
1721 | { |
|
|
1722 | #if HAVE_PRCTL_SET_NAME |
|
|
1723 | /* provide a more sensible "thread name" */ |
|
|
1724 | char name[16 + 1]; |
|
|
1725 | const int namelen = sizeof (name) - 1; |
|
|
1726 | int len; |
|
|
1727 | |
1770 | |
1728 | prctl (PR_GET_NAME, (unsigned long)name, 0, 0, 0); |
1771 | static void |
1729 | name [namelen] = 0; |
1772 | eio__slurp (int fd, eio_req *req) |
1730 | len = strlen (name); |
|
|
1731 | strcpy (name + (len <= namelen - 4 ? len : namelen - 4), "/eio"); |
|
|
1732 | prctl (PR_SET_NAME, (unsigned long)name, 0, 0, 0); |
|
|
1733 | #endif |
|
|
1734 | } |
|
|
1735 | |
|
|
1736 | /* TODO: move somehow to etp.c */ |
|
|
1737 | X_THREAD_PROC (etp_proc) |
|
|
1738 | { |
1773 | { |
1739 | ETP_REQ *req; |
1774 | req->result = fd; |
1740 | struct timespec ts; |
|
|
1741 | etp_worker *self = (etp_worker *)thr_arg; |
|
|
1742 | |
1775 | |
1743 | etp_proc_init (); |
1776 | if (fd < 0) |
|
|
1777 | return; |
1744 | |
1778 | |
1745 | /* try to distribute timeouts somewhat evenly */ |
1779 | if (req->offs < 0 || !req->size) /* do we need the size? */ |
1746 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
|
|
1747 | |
|
|
1748 | for (;;) |
|
|
1749 | { |
1780 | { |
1750 | ts.tv_sec = 0; |
1781 | off_t size = lseek (fd, 0, SEEK_END); |
1751 | |
1782 | |
1752 | X_LOCK (reqlock); |
1783 | if (req->offs < 0) |
|
|
1784 | req->offs += size; |
1753 | |
1785 | |
1754 | for (;;) |
1786 | if (!req->size) |
1755 | { |
1787 | req->size = size - req->offs; |
1756 | req = reqq_shift (&req_queue); |
|
|
1757 | |
|
|
1758 | if (req) |
|
|
1759 | break; |
|
|
1760 | |
|
|
1761 | if (ts.tv_sec == 1) /* no request, but timeout detected, let's quit */ |
|
|
1762 | { |
|
|
1763 | X_UNLOCK (reqlock); |
|
|
1764 | X_LOCK (wrklock); |
|
|
1765 | --started; |
|
|
1766 | X_UNLOCK (wrklock); |
|
|
1767 | goto quit; |
|
|
1768 | } |
|
|
1769 | |
|
|
1770 | ++idle; |
|
|
1771 | |
|
|
1772 | if (idle <= max_idle) |
|
|
1773 | /* we are allowed to idle, so do so without any timeout */ |
|
|
1774 | X_COND_WAIT (reqwait, reqlock); |
|
|
1775 | else |
|
|
1776 | { |
|
|
1777 | /* initialise timeout once */ |
|
|
1778 | if (!ts.tv_sec) |
|
|
1779 | ts.tv_sec = time (0) + idle_timeout; |
|
|
1780 | |
|
|
1781 | if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT) |
|
|
1782 | ts.tv_sec = 1; /* assuming this is not a value computed above.,.. */ |
|
|
1783 | } |
|
|
1784 | |
|
|
1785 | --idle; |
|
|
1786 | } |
|
|
1787 | |
|
|
1788 | --nready; |
|
|
1789 | |
|
|
1790 | X_UNLOCK (reqlock); |
|
|
1791 | |
|
|
1792 | if (req->type == ETP_TYPE_QUIT) |
|
|
1793 | goto quit; |
|
|
1794 | |
|
|
1795 | ETP_EXECUTE (self, req); |
|
|
1796 | |
|
|
1797 | X_LOCK (reslock); |
|
|
1798 | |
|
|
1799 | ++npending; |
|
|
1800 | |
|
|
1801 | if (!reqq_push (&res_queue, req) && want_poll_cb) |
|
|
1802 | want_poll_cb (); |
|
|
1803 | |
|
|
1804 | etp_worker_clear (self); |
|
|
1805 | |
|
|
1806 | X_UNLOCK (reslock); |
|
|
1807 | } |
1788 | } |
1808 | |
1789 | |
1809 | quit: |
1790 | ALLOC (req->size); |
1810 | free (req); |
1791 | req->result = pread (fd, req->ptr2, req->size, req->offs); |
1811 | |
1792 | |
1812 | X_LOCK (wrklock); |
1793 | silent_close (fd); |
1813 | etp_worker_free (self); |
|
|
1814 | X_UNLOCK (wrklock); |
|
|
1815 | |
1794 | |
1816 | return 0; |
1795 | alloc_fail: |
|
|
1796 | ; |
1817 | } |
1797 | } |
1818 | |
|
|
1819 | /*****************************************************************************/ |
|
|
1820 | |
1798 | |
1821 | int ecb_cold |
1799 | int ecb_cold |
1822 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1800 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1823 | { |
1801 | { |
1824 | return etp_init (want_poll, done_poll); |
1802 | eio_want_poll_cb = want_poll; |
|
|
1803 | eio_done_poll_cb = done_poll; |
|
|
1804 | |
|
|
1805 | return etp_init (EIO_POOL, 0, 0, 0); |
1825 | } |
1806 | } |
1826 | |
1807 | |
1827 | ecb_inline void |
1808 | ecb_inline void |
1828 | eio_api_destroy (eio_req *req) |
1809 | eio_api_destroy (eio_req *req) |
1829 | { |
1810 | { |
… | |
… | |
1903 | : read (req->int1, req->ptr2, req->size); break; |
1884 | : read (req->int1, req->ptr2, req->size); break; |
1904 | case EIO_WRITE: req->result = req->offs >= 0 |
1885 | case EIO_WRITE: req->result = req->offs >= 0 |
1905 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
1886 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
1906 | : write (req->int1, req->ptr2, req->size); break; |
1887 | : write (req->int1, req->ptr2, req->size); break; |
1907 | |
1888 | |
|
|
1889 | case EIO_FCNTL: req->result = fcntl (req->int1, (int) req->int2, req->ptr2); break; |
|
|
1890 | case EIO_IOCTL: req->result = ioctl (req->int1, (unsigned long)req->int2, req->ptr2); break; |
|
|
1891 | |
1908 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
1892 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
1909 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; |
1893 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; |
1910 | |
1894 | |
1911 | #if HAVE_AT |
1895 | #if HAVE_AT |
1912 | |
1896 | |
… | |
… | |
1916 | req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; |
1900 | req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; |
1917 | case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break; |
1901 | case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break; |
1918 | case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break; |
1902 | case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break; |
1919 | case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break; |
1903 | case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break; |
1920 | case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break; |
1904 | case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break; |
|
|
1905 | case EIO_SLURP: eio__slurp ( openat (dirfd, req->ptr1, O_RDONLY | O_CLOEXEC), req); break; |
1921 | |
1906 | |
1922 | case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; |
1907 | case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; |
1923 | case EIO_RMDIR: /* complications arise because "." cannot be removed, so we might have to expand */ |
1908 | case EIO_RMDIR: /* complications arise because "." cannot be removed, so we might have to expand */ |
1924 | req->result = req->wd && SINGLEDOT (req->ptr1) |
1909 | req->result = req->wd && SINGLEDOT (req->ptr1) |
1925 | ? rmdir (req->wd->str) |
1910 | ? rmdir (req->wd->str) |
1926 | : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; |
1911 | : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; |
1927 | case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; |
1912 | case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; |
|
|
1913 | case EIO_RENAME: req->result = eio__renameat2 ( |
|
|
1914 | dirfd, |
1928 | case EIO_RENAME: /* complications arise because "." cannot be renamed, so we might have to expand */ |
1915 | /* complications arise because "." cannot be renamed, so we might have to expand */ |
1929 | req->result = req->wd && SINGLEDOT (req->ptr1) |
1916 | req->wd && SINGLEDOT (req->ptr1) ? req->wd->str : req->ptr1, |
1930 | ? rename (req->wd->str, req->ptr2) |
1917 | WD2FD ((eio_wd)req->int3), |
1931 | : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; |
1918 | req->ptr2, |
|
|
1919 | req->int2 |
|
|
1920 | ); |
|
|
1921 | break; |
1932 | case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; |
1922 | case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; |
1933 | case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; |
1923 | case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; |
1934 | case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; |
1924 | case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; |
1935 | case EIO_READLINK: ALLOC (PATH_MAX); |
|
|
1936 | req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break; |
|
|
1937 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
1925 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
1938 | req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
1926 | req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; |
|
|
1927 | case EIO_READLINK: ALLOC (EIO_PATH_MAX); |
|
|
1928 | req->result = readlinkat (dirfd, req->ptr1, req->ptr2, EIO_PATH_MAX); |
|
|
1929 | if (req->result == EIO_PATH_MAX) |
|
|
1930 | { |
|
|
1931 | req->result = -1; |
|
|
1932 | errno = ENAMETOOLONG; |
|
|
1933 | } |
|
|
1934 | break; |
1939 | case EIO_UTIME: |
1935 | case EIO_UTIME: |
1940 | case EIO_FUTIME: |
1936 | case EIO_FUTIME: |
1941 | { |
1937 | { |
1942 | struct timespec ts[2]; |
1938 | struct timespec ts[2]; |
1943 | struct timespec *times; |
1939 | struct timespec *times; |
… | |
… | |
1968 | req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
1964 | req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; |
1969 | case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; |
1965 | case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; |
1970 | case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break; |
1966 | case EIO_CHMOD: req->result = chmod (path , (mode_t)req->int2); break; |
1971 | case EIO_TRUNCATE: req->result = truncate (path , req->offs); break; |
1967 | case EIO_TRUNCATE: req->result = truncate (path , req->offs); break; |
1972 | case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break; |
1968 | case EIO_OPEN: req->result = open (path , req->int1, (mode_t)req->int2); break; |
|
|
1969 | case EIO_SLURP: eio__slurp ( open (path , O_RDONLY | O_CLOEXEC), req); break; |
1973 | |
1970 | |
1974 | case EIO_UNLINK: req->result = unlink (path ); break; |
1971 | case EIO_UNLINK: req->result = unlink (path ); break; |
1975 | case EIO_RMDIR: req->result = rmdir (path ); break; |
1972 | case EIO_RMDIR: req->result = rmdir (path ); break; |
1976 | case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; |
1973 | case EIO_MKDIR: req->result = mkdir (path , (mode_t)req->int2); break; |
1977 | case EIO_RENAME: req->result = rename (path , req->ptr2); break; |
1974 | case EIO_RENAME: req->result = req->int2 ? EIO_ENOSYS () : rename (path, req->ptr2); break; |
1978 | case EIO_LINK: req->result = link (path , req->ptr2); break; |
1975 | case EIO_LINK: req->result = link (path , req->ptr2); break; |
1979 | case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; |
1976 | case EIO_SYMLINK: req->result = symlink (path , req->ptr2); break; |
1980 | case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; |
1977 | case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; |
1981 | case EIO_READLINK: ALLOC (PATH_MAX); |
|
|
1982 | req->result = readlink (path, req->ptr2, PATH_MAX); break; |
|
|
1983 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
1978 | case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); |
1984 | req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; |
1979 | req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; |
|
|
1980 | case EIO_READLINK: ALLOC (EIO_PATH_MAX); |
|
|
1981 | req->result = readlink (path, req->ptr2, EIO_PATH_MAX); |
|
|
1982 | if (req->result == EIO_PATH_MAX) |
|
|
1983 | { |
|
|
1984 | req->result = -1; |
|
|
1985 | errno = ENAMETOOLONG; |
|
|
1986 | } |
|
|
1987 | break; |
1985 | |
1988 | |
1986 | case EIO_UTIME: |
1989 | case EIO_UTIME: |
1987 | case EIO_FUTIME: |
1990 | case EIO_FUTIME: |
1988 | { |
1991 | { |
1989 | struct timeval tv[2]; |
1992 | struct timeval tv[2]; |
… | |
… | |
2024 | |
2027 | |
2025 | case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; |
2028 | case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; |
2026 | case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break; |
2029 | case EIO_FCHMOD: req->result = fchmod (req->int1, (mode_t)req->int2); break; |
2027 | case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; |
2030 | case EIO_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; |
2028 | |
2031 | |
2029 | case EIO_CLOSE: req->result = close (req->int1); break; |
2032 | case EIO_CLOSE: req->result = eio__close (req->int1); break; |
2030 | case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; |
2033 | case EIO_DUP2: req->result = dup2 (req->int1, req->int2); break; |
2031 | case EIO_SYNC: req->result = 0; sync (); break; |
2034 | case EIO_SYNC: req->result = 0; sync (); break; |
2032 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2035 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
2033 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
2036 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
2034 | case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; |
2037 | case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break; |
… | |
… | |
2054 | req->result = select (0, 0, 0, 0, &tv); |
2057 | req->result = select (0, 0, 0, 0, &tv); |
2055 | } |
2058 | } |
2056 | #endif |
2059 | #endif |
2057 | break; |
2060 | break; |
2058 | |
2061 | |
|
|
2062 | #if 0 |
2059 | case EIO_GROUP: |
2063 | case EIO_GROUP: |
2060 | abort (); /* handled in eio_request */ |
2064 | abort (); /* handled in eio_request */ |
|
|
2065 | #endif |
2061 | |
2066 | |
2062 | case EIO_NOP: |
2067 | case EIO_NOP: |
2063 | req->result = 0; |
2068 | req->result = 0; |
2064 | break; |
2069 | break; |
2065 | |
2070 | |
… | |
… | |
2070 | default: |
2075 | default: |
2071 | req->result = EIO_ENOSYS (); |
2076 | req->result = EIO_ENOSYS (); |
2072 | break; |
2077 | break; |
2073 | } |
2078 | } |
2074 | |
2079 | |
|
|
2080 | alloc_fail: |
2075 | req->errorno = errno; |
2081 | req->errorno = errno; |
2076 | } |
2082 | } |
2077 | |
2083 | |
2078 | #ifndef EIO_NO_WRAPPERS |
2084 | #ifndef EIO_NO_WRAPPERS |
2079 | |
2085 | |
… | |
… | |
2168 | } |
2174 | } |
2169 | |
2175 | |
2170 | eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
2176 | eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
2171 | { |
2177 | { |
2172 | REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
2178 | REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
|
|
2179 | } |
|
|
2180 | |
|
|
2181 | eio_req *eio_fcntl (int fd, int cmd, void *arg, int pri, eio_cb cb, void *data) |
|
|
2182 | { |
|
|
2183 | REQ (EIO_IOCTL); req->int1 = fd; req->int2 = cmd; req->ptr2 = arg; SEND; |
|
|
2184 | } |
|
|
2185 | |
|
|
2186 | eio_req *eio_ioctl (int fd, unsigned long request, void *buf, int pri, eio_cb cb, void *data) |
|
|
2187 | { |
|
|
2188 | REQ (EIO_IOCTL); req->int1 = fd; req->int2 = request; req->ptr2 = buf; SEND; |
2173 | } |
2189 | } |
2174 | |
2190 | |
2175 | eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) |
2191 | eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) |
2176 | { |
2192 | { |
2177 | REQ (EIO_FSTAT); req->int1 = fd; SEND; |
2193 | REQ (EIO_FSTAT); req->int1 = fd; SEND; |
… | |
… | |
2322 | eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
2338 | eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
2323 | { |
2339 | { |
2324 | return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); |
2340 | return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); |
2325 | } |
2341 | } |
2326 | |
2342 | |
|
|
2343 | eio_req *eio_slurp (const char *path, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
|
|
2344 | { |
|
|
2345 | REQ (EIO_SLURP); PATH; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
|
|
2346 | } |
|
|
2347 | |
2327 | eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data) |
2348 | eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data) |
2328 | { |
2349 | { |
2329 | REQ (EIO_CUSTOM); req->feed = execute; SEND; |
2350 | REQ (EIO_CUSTOM); req->feed = execute; SEND; |
2330 | } |
2351 | } |
2331 | |
2352 | |
… | |
… | |
2365 | void |
2386 | void |
2366 | eio_grp_add (eio_req *grp, eio_req *req) |
2387 | eio_grp_add (eio_req *grp, eio_req *req) |
2367 | { |
2388 | { |
2368 | assert (("cannot add requests to IO::AIO::GRP after the group finished", grp->int1 != 2)); |
2389 | assert (("cannot add requests to IO::AIO::GRP after the group finished", grp->int1 != 2)); |
2369 | |
2390 | |
2370 | grp->flags |= EIO_FLAG_GROUPADD; |
2391 | grp->flags |= ETP_FLAG_GROUPADD; |
2371 | |
2392 | |
2372 | ++grp->size; |
2393 | ++grp->size; |
2373 | req->grp = grp; |
2394 | req->grp = grp; |
2374 | |
2395 | |
2375 | req->grp_prev = 0; |
2396 | req->grp_prev = 0; |