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 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> |
… | |
… | |
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) |
125 | #define pipe(fds) _pipe (fds, 4096, O_BINARY) |
120 | #define pipe(fds) _pipe (fds, 4096, O_BINARY) |
126 | |
121 | |
|
|
122 | #define fcntl(fd,cmd,arg) EIO_ENOSYS () |
|
|
123 | #define ioctl(fd,cmd,arg) EIO_ENOSYS () |
127 | #define fchmod(fd,mode) EIO_ENOSYS () |
124 | #define fchmod(fd,mode) EIO_ENOSYS () |
128 | #define chown(path,uid,gid) EIO_ENOSYS () |
125 | #define chown(path,uid,gid) EIO_ENOSYS () |
129 | #define fchown(fd,uid,gid) EIO_ENOSYS () |
126 | #define fchown(fd,uid,gid) EIO_ENOSYS () |
130 | #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */ |
127 | #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */ |
131 | #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */ |
128 | #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */ |
… | |
… | |
204 | /* we could even stat and see if it exists */ |
201 | /* we could even stat and see if it exists */ |
205 | static int |
202 | static int |
206 | symlink (const char *old, const char *neu) |
203 | symlink (const char *old, const char *neu) |
207 | { |
204 | { |
208 | #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) |
209 | if (CreateSymbolicLink (neu, old, 1)) |
213 | if (CreateSymbolicLink (neu, old, flags)) |
210 | return 0; |
214 | return 0; |
211 | |
|
|
212 | if (CreateSymbolicLink (neu, old, 0)) |
|
|
213 | return 0; |
|
|
214 | #endif |
215 | #endif |
215 | |
216 | |
216 | return EIO_ERRNO (ENOENT, -1); |
217 | return EIO_ERRNO (ENOENT, -1); |
217 | } |
218 | } |
218 | |
219 | |
… | |
… | |
281 | # include <utime.h> |
282 | # include <utime.h> |
282 | #endif |
283 | #endif |
283 | |
284 | |
284 | #if HAVE_SYS_SYSCALL_H |
285 | #if HAVE_SYS_SYSCALL_H |
285 | # include <sys/syscall.h> |
286 | # include <sys/syscall.h> |
286 | #endif |
|
|
287 | |
|
|
288 | #if HAVE_SYS_PRCTL_H |
|
|
289 | # include <sys/prctl.h> |
|
|
290 | #endif |
287 | #endif |
291 | |
288 | |
292 | #if HAVE_SENDFILE |
289 | #if HAVE_SENDFILE |
293 | # if __linux |
290 | # if __linux |
294 | # include <sys/sendfile.h> |
291 | # include <sys/sendfile.h> |
… | |
… | |
366 | #define ETP_PRI_MAX EIO_PRI_MAX |
363 | #define ETP_PRI_MAX EIO_PRI_MAX |
367 | |
364 | |
368 | #define ETP_TYPE_QUIT -1 |
365 | #define ETP_TYPE_QUIT -1 |
369 | #define ETP_TYPE_GROUP EIO_GROUP |
366 | #define ETP_TYPE_GROUP EIO_GROUP |
370 | |
367 | |
|
|
368 | static void eio_nop_callback (void) { } |
|
|
369 | static void (*eio_want_poll_cb)(void) = eio_nop_callback; |
|
|
370 | static void (*eio_done_poll_cb)(void) = eio_nop_callback; |
|
|
371 | |
|
|
372 | #define ETP_WANT_POLL(pool) eio_want_poll_cb () |
|
|
373 | #define ETP_DONE_POLL(pool) eio_done_poll_cb () |
|
|
374 | |
371 | struct etp_worker; |
375 | struct etp_worker; |
372 | |
|
|
373 | #define ETP_REQ eio_req |
376 | #define ETP_REQ eio_req |
374 | #define ETP_DESTROY(req) eio_destroy (req) |
377 | #define ETP_DESTROY(req) eio_destroy (req) |
375 | static int eio_finish (eio_req *req); |
378 | static int eio_finish (eio_req *req); |
376 | #define ETP_FINISH(req) eio_finish (req) |
379 | #define ETP_FINISH(req) eio_finish (req) |
377 | static void eio_execute (struct etp_worker *self, eio_req *req); |
380 | static void eio_execute (struct etp_worker *self, eio_req *req); |
… | |
… | |
1706 | /*****************************************************************************/ |
1709 | /*****************************************************************************/ |
1707 | |
1710 | |
1708 | #define ALLOC(len) \ |
1711 | #define ALLOC(len) \ |
1709 | if (!req->ptr2) \ |
1712 | if (!req->ptr2) \ |
1710 | { \ |
1713 | { \ |
1711 | X_LOCK (wrklock); \ |
1714 | X_LOCK (EIO_POOL->wrklock); \ |
1712 | req->flags |= EIO_FLAG_PTR2_FREE; \ |
1715 | req->flags |= EIO_FLAG_PTR2_FREE; \ |
1713 | X_UNLOCK (wrklock); \ |
1716 | X_UNLOCK (EIO_POOL->wrklock); \ |
1714 | req->ptr2 = malloc (len); \ |
1717 | req->ptr2 = malloc (len); \ |
1715 | if (!req->ptr2) \ |
1718 | if (!req->ptr2) \ |
1716 | { \ |
1719 | { \ |
1717 | errno = ENOMEM; \ |
1720 | errno = ENOMEM; \ |
1718 | req->result = -1; \ |
1721 | req->result = -1; \ |
… | |
… | |
1723 | /*****************************************************************************/ |
1726 | /*****************************************************************************/ |
1724 | |
1727 | |
1725 | int ecb_cold |
1728 | int ecb_cold |
1726 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1729 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1727 | { |
1730 | { |
1728 | return etp_init (EIO_POOL, want_poll, done_poll); |
1731 | eio_want_poll_cb = want_poll; |
|
|
1732 | eio_done_poll_cb = done_poll; |
|
|
1733 | |
|
|
1734 | return etp_init (EIO_POOL, 0, 0, 0); |
1729 | } |
1735 | } |
1730 | |
1736 | |
1731 | ecb_inline void |
1737 | ecb_inline void |
1732 | eio_api_destroy (eio_req *req) |
1738 | eio_api_destroy (eio_req *req) |
1733 | { |
1739 | { |
… | |
… | |
1806 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
1812 | ? pread (req->int1, req->ptr2, req->size, req->offs) |
1807 | : read (req->int1, req->ptr2, req->size); break; |
1813 | : read (req->int1, req->ptr2, req->size); break; |
1808 | case EIO_WRITE: req->result = req->offs >= 0 |
1814 | case EIO_WRITE: req->result = req->offs >= 0 |
1809 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
1815 | ? pwrite (req->int1, req->ptr2, req->size, req->offs) |
1810 | : write (req->int1, req->ptr2, req->size); break; |
1816 | : write (req->int1, req->ptr2, req->size); break; |
|
|
1817 | |
|
|
1818 | case EIO_FCNTL: req->result = fcntl (req->int1, (int) req->int2, req->ptr2); break; |
|
|
1819 | case EIO_IOCTL: req->result = ioctl (req->int1, (unsigned long)req->int2, req->ptr2); break; |
1811 | |
1820 | |
1812 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
1821 | case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; |
1813 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; |
1822 | case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; |
1814 | |
1823 | |
1815 | #if HAVE_AT |
1824 | #if HAVE_AT |
… | |
… | |
2076 | eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
2085 | eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) |
2077 | { |
2086 | { |
2078 | REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
2087 | REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; |
2079 | } |
2088 | } |
2080 | |
2089 | |
|
|
2090 | eio_req *eio_fcntl (int fd, int cmd, void *arg, int pri, eio_cb cb, void *data) |
|
|
2091 | { |
|
|
2092 | REQ (EIO_IOCTL); req->int1 = fd; req->int2 = cmd; req->ptr2 = arg; SEND; |
|
|
2093 | } |
|
|
2094 | |
|
|
2095 | eio_req *eio_ioctl (int fd, unsigned long request, void *buf, int pri, eio_cb cb, void *data) |
|
|
2096 | { |
|
|
2097 | REQ (EIO_IOCTL); req->int1 = fd; req->int2 = request; req->ptr2 = buf; SEND; |
|
|
2098 | } |
|
|
2099 | |
2081 | eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) |
2100 | eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) |
2082 | { |
2101 | { |
2083 | REQ (EIO_FSTAT); req->int1 = fd; SEND; |
2102 | REQ (EIO_FSTAT); req->int1 = fd; SEND; |
2084 | } |
2103 | } |
2085 | |
2104 | |