ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/eio.c
(Generate patch)

Comparing libeio/eio.c (file contents):
Revision 1.85 by root, Wed Jul 13 00:53:03 2011 UTC vs.
Revision 1.99 by root, Tue Jul 26 11:07:08 2011 UTC

54#include <stdlib.h> 54#include <stdlib.h>
55#include <string.h> 55#include <string.h>
56#include <errno.h> 56#include <errno.h>
57#include <sys/types.h> 57#include <sys/types.h>
58#include <sys/stat.h> 58#include <sys/stat.h>
59#include <sys/statvfs.h>
60#include <limits.h> 59#include <limits.h>
61#include <fcntl.h> 60#include <fcntl.h>
62#include <assert.h> 61#include <assert.h>
63 62
64/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ 63/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */
68#endif 67#endif
69 68
70#ifndef ECANCELED 69#ifndef ECANCELED
71# define ECANCELED EDOM 70# define ECANCELED EDOM
72#endif 71#endif
72#ifndef ELOOP
73# define ELOOP EDOM
74#endif
75
76#if !defined(ENOTSOCK) && defined(WSAENOTSOCK)
77# define ENOTSOCK WSAENOTSOCK
78#endif
73 79
74static void eio_destroy (eio_req *req); 80static void eio_destroy (eio_req *req);
75 81
76#ifndef EIO_FINISH 82#ifndef EIO_FINISH
77# 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
83 89
84#ifndef EIO_FEED 90#ifndef EIO_FEED
85# define EIO_FEED(req) do { if ((req)->feed ) (req)->feed (req); } while (0) 91# define EIO_FEED(req) do { if ((req)->feed ) (req)->feed (req); } while (0)
86#endif 92#endif
87 93
94#ifndef EIO_FD_TO_WIN32_HANDLE
95# define EIO_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd)
96#endif
97#ifndef EIO_WIN32_HANDLE_TO_FD
98# define EIO_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (handle, 0)
99#endif
100
101#define EIO_ERRNO(errval,retval) ((errno = errval), retval)
102
103#define EIO_ENOSYS() EIO_ERRNO (ENOSYS, -1)
104
88#ifdef _WIN32 105#ifdef _WIN32
89 106
90 /*doh*/ 107 #undef PAGESIZE
108 #define PAGESIZE 4096 /* GetSystemInfo? */
109
110 #ifdef EIO_STRUCT_STATI64
111 #define stat(path,buf) _stati64 (path,buf)
112 #define fstat(fd,buf) _fstati64 (fd,buf)
113 #endif
114 #define lstat(path,buf) stat (path,buf)
115 #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1))
116 #define mkdir(path,mode) _mkdir (path)
117 #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1))
118
119 #define chmod(path,mode) _chmod (path, mode)
120 #define dup(fd) _dup (fd)
121 #define dup2(fd1,fd2) _dup2 (fd1, fd2)
122
123 #define fchmod(fd,mode) EIO_ENOSYS ()
124 #define chown(path,uid,gid) EIO_ENOSYS ()
125 #define fchown(fd,uid,gid) EIO_ENOSYS ()
126 #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */
127 #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */
128 #define mknod(path,mode,dev) EIO_ENOSYS ()
129 #define sync() EIO_ENOSYS ()
130 #define readlink(path,buf,s) EIO_ENOSYS ()
131 #define statvfs(path,buf) EIO_ENOSYS ()
132 #define fstatvfs(fd,buf) EIO_ENOSYS ()
133
134 /* rename() uses MoveFile, which fails to overwrite */
135 #define rename(old,neu) eio__rename (old, neu)
136
137 static int
138 eio__rename (const char *old, const char *neu)
139 {
140 if (MoveFileEx (old, neu, MOVEFILE_REPLACE_EXISTING))
141 return 0;
142
143 /* should steal _dosmaperr */
144 switch (GetLastError ())
145 {
146 case ERROR_FILE_NOT_FOUND:
147 case ERROR_PATH_NOT_FOUND:
148 case ERROR_INVALID_DRIVE:
149 case ERROR_NO_MORE_FILES:
150 case ERROR_BAD_NETPATH:
151 case ERROR_BAD_NET_NAME:
152 case ERROR_BAD_PATHNAME:
153 case ERROR_FILENAME_EXCED_RANGE:
154 errno = ENOENT;
155 break;
156
157 default:
158 errno = EACCES;
159 break;
160 }
161
162 return -1;
163 }
164
165 /* we could even stat and see if it exists */
166 static int
167 symlink (const char *old, const char *neu)
168 {
169 #if WINVER >= 0x0600
170 if (CreateSymbolicLink (neu, old, 1))
171 return 0;
172
173 if (CreateSymbolicLink (neu, old, 0))
174 return 0;
175 #endif
176
177 return EIO_ERRNO (ENOENT, -1);
178 }
179
180 /* POSIX API only */
181 #define CreateHardLink(neu,old,flags) 0
182 #define CreateSymbolicLink(neu,old,flags) 0
183
184 struct statvfs
185 {
186 int dummy;
187 };
188
189 #define DT_DIR EIO_DT_DIR
190 #define DT_REG EIO_DT_REG
191 #define D_NAME(entp) entp.cFileName
192 #define D_TYPE(entp) (entp.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? DT_DIR : DT_REG)
193
91#else 194#else
92 195
93# include <sys/time.h> 196 #include <sys/time.h>
94# include <sys/select.h> 197 #include <sys/select.h>
198 #include <sys/statvfs.h>
95# include <unistd.h> 199 #include <unistd.h>
200 #include <signal.h>
201 #include <dirent.h>
202
203 #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
204 #include <sys/mman.h>
205 #endif
206
207 #define D_NAME(entp) entp->d_name
208
209 /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */
210 #if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
211 #define _DIRENT_HAVE_D_TYPE /* sigh */
212 #define D_INO(de) (de)->d_fileno
213 #define D_NAMLEN(de) (de)->d_namlen
214 #elif __linux || defined d_ino || _XOPEN_SOURCE >= 600
215 #define D_INO(de) (de)->d_ino
216 #endif
217
218 #ifdef _D_EXACT_NAMLEN
219 #undef D_NAMLEN
220 #define D_NAMLEN(de) _D_EXACT_NAMLEN (de)
221 #endif
222
223 #ifdef _DIRENT_HAVE_D_TYPE
224 #define D_TYPE(de) (de)->d_type
225 #endif
226
227 #ifndef EIO_STRUCT_DIRENT
228 #define EIO_STRUCT_DIRENT struct dirent
229 #endif
230
231#endif
232
233#if HAVE_UTIMES
96# include <utime.h> 234# include <utime.h>
97# include <signal.h>
98# include <dirent.h>
99
100#if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
101# include <sys/mman.h>
102#endif
103
104/* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */
105# if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
106# define _DIRENT_HAVE_D_TYPE /* sigh */
107# define D_INO(de) (de)->d_fileno
108# define D_NAMLEN(de) (de)->d_namlen
109# elif __linux || defined d_ino || _XOPEN_SOURCE >= 600
110# define D_INO(de) (de)->d_ino
111# endif 235#endif
112 236
113#ifdef _D_EXACT_NAMLEN 237#if HAVE_SYS_SYSCALL_H
114# undef D_NAMLEN 238# include <sys/syscall.h>
115# define D_NAMLEN(de) _D_EXACT_NAMLEN (de)
116#endif
117
118# ifdef _DIRENT_HAVE_D_TYPE
119# define D_TYPE(de) (de)->d_type
120# endif 239#endif
121 240
122# ifndef EIO_STRUCT_DIRENT 241#if HAVE_SYS_PRCTL_H
123# define EIO_STRUCT_DIRENT struct dirent 242# include <sys/prctl.h>
124# endif
125
126#endif 243#endif
127 244
128#if HAVE_SENDFILE 245#if HAVE_SENDFILE
129# if __linux 246# if __linux
130# include <sys/sendfile.h> 247# include <sys/sendfile.h>
145#endif 262#endif
146#ifndef D_INO 263#ifndef D_INO
147# define D_INO(de) 0 264# define D_INO(de) 0
148#endif 265#endif
149#ifndef D_NAMLEN 266#ifndef D_NAMLEN
150# define D_NAMLEN(de) strlen ((de)->d_name) 267# define D_NAMLEN(entp) strlen (D_NAME (entp))
151#endif 268#endif
152 269
153/* used for struct dirent, AIX doesn't provide it */ 270/* used for struct dirent, AIX doesn't provide it */
154#ifndef NAME_MAX 271#ifndef NAME_MAX
155# define NAME_MAX 4096 272# define NAME_MAX 4096
162 279
163/* buffer size for various temporary buffers */ 280/* buffer size for various temporary buffers */
164#define EIO_BUFSIZE 65536 281#define EIO_BUFSIZE 65536
165 282
166#define dBUF \ 283#define dBUF \
167 char *eio_buf; \
168 ETP_WORKER_LOCK (self); \
169 self->dbuf = eio_buf = malloc (EIO_BUFSIZE); \ 284 char *eio_buf = malloc (EIO_BUFSIZE); \
170 ETP_WORKER_UNLOCK (self); \
171 errno = ENOMEM; \ 285 errno = ENOMEM; \
172 if (!eio_buf) \ 286 if (!eio_buf) \
173 return -1; 287 return -1
288
289#define FUBd \
290 free (eio_buf)
174 291
175#define EIO_TICKS ((1000000 + 1023) >> 10) 292#define EIO_TICKS ((1000000 + 1023) >> 10)
176 293
177#define ETP_PRI_MIN EIO_PRI_MIN 294#define ETP_PRI_MIN EIO_PRI_MIN
178#define ETP_PRI_MAX EIO_PRI_MAX 295#define ETP_PRI_MAX EIO_PRI_MAX
184static int eio_finish (eio_req *req); 301static int eio_finish (eio_req *req);
185#define ETP_FINISH(req) eio_finish (req) 302#define ETP_FINISH(req) eio_finish (req)
186static void eio_execute (struct etp_worker *self, eio_req *req); 303static void eio_execute (struct etp_worker *self, eio_req *req);
187#define ETP_EXECUTE(wrk,req) eio_execute (wrk,req) 304#define ETP_EXECUTE(wrk,req) eio_execute (wrk,req)
188 305
189#define ETP_WORKER_CLEAR(req) \
190 if (wrk->dbuf) \
191 { \
192 free (wrk->dbuf); \
193 wrk->dbuf = 0; \
194 } \
195 \
196 if (wrk->dirp) \
197 { \
198 closedir (wrk->dirp); \
199 wrk->dirp = 0; \
200 }
201
202#define ETP_WORKER_COMMON \
203 void *dbuf; \
204 DIR *dirp;
205
206/*****************************************************************************/ 306/*****************************************************************************/
207 307
208#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) 308#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1)
209 309
210/* calculate time difference in ~1/EIO_TICKS of a second */ 310/* calculate time difference in ~1/EIO_TICKS of a second */
238/* 338/*
239 * make our pread/pwrite emulation safe against themselves, but not against 339 * make our pread/pwrite emulation safe against themselves, but not against
240 * normal read/write by using a mutex. slows down execution a lot, 340 * normal read/write by using a mutex. slows down execution a lot,
241 * but that's your problem, not mine. 341 * but that's your problem, not mine.
242 */ 342 */
243static xmutex_t preadwritelock = X_MUTEX_INIT; 343static xmutex_t preadwritelock;
244#endif 344#endif
245 345
246typedef struct etp_worker 346typedef struct etp_worker
247{ 347{
248 /* locked by wrklock */ 348 /* locked by wrklock */
251 xthread_t tid; 351 xthread_t tid;
252 352
253 /* locked by reslock, reqlock or wrklock */ 353 /* locked by reslock, reqlock or wrklock */
254 ETP_REQ *req; /* currently processed request */ 354 ETP_REQ *req; /* currently processed request */
255 355
356#ifdef ETP_WORKER_COMMON
256 ETP_WORKER_COMMON 357 ETP_WORKER_COMMON
358#endif
257} etp_worker; 359} etp_worker;
258 360
259static etp_worker wrk_first = { &wrk_first, &wrk_first, 0 }; /* NOT etp */ 361static etp_worker wrk_first; /* NOT etp */
260 362
261#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) 363#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock)
262#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock) 364#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock)
263 365
264/* worker threads management */ 366/* worker threads management */
265 367
266static void ecb_cold 368static void ecb_cold
267etp_worker_clear (etp_worker *wrk) 369etp_worker_clear (etp_worker *wrk)
268{ 370{
269 ETP_WORKER_CLEAR (wrk);
270} 371}
271 372
272static void ecb_cold 373static void ecb_cold
273etp_worker_free (etp_worker *wrk) 374etp_worker_free (etp_worker *wrk)
274{ 375{
335} etp_reqq; 436} etp_reqq;
336 437
337static etp_reqq req_queue; 438static etp_reqq req_queue;
338static etp_reqq res_queue; 439static etp_reqq res_queue;
339 440
441static void ecb_noinline ecb_cold
442reqq_init (etp_reqq *q)
443{
444 int pri;
445
446 for (pri = 0; pri < ETP_NUM_PRI; ++pri)
447 q->qs[pri] = q->qe[pri] = 0;
448
449 q->size = 0;
450}
451
340static int ecb_noinline 452static int ecb_noinline
341reqq_push (etp_reqq *q, ETP_REQ *req) 453reqq_push (etp_reqq *q, ETP_REQ *req)
342{ 454{
343 int pri = req->pri; 455 int pri = req->pri;
344 req->next = 0; 456 req->next = 0;
378 } 490 }
379 491
380 abort (); 492 abort ();
381} 493}
382 494
383static void ecb_cold 495static int ecb_cold
384etp_thread_init (void) 496etp_init (void (*want_poll)(void), void (*done_poll)(void))
385{ 497{
386#if !HAVE_PREADWRITE
387 X_MUTEX_CREATE (preadwritelock);
388#endif
389 X_MUTEX_CREATE (wrklock); 498 X_MUTEX_CREATE (wrklock);
390 X_MUTEX_CREATE (reslock); 499 X_MUTEX_CREATE (reslock);
391 X_MUTEX_CREATE (reqlock); 500 X_MUTEX_CREATE (reqlock);
392 X_COND_CREATE (reqwait); 501 X_COND_CREATE (reqwait);
393}
394 502
395static void ecb_cold 503 reqq_init (&req_queue);
396etp_atfork_prepare (void) 504 reqq_init (&res_queue);
397{
398}
399 505
400static void ecb_cold 506 wrk_first.next =
401etp_atfork_parent (void) 507 wrk_first.prev = &wrk_first;
402{
403}
404
405static void ecb_cold
406etp_atfork_child (void)
407{
408 ETP_REQ *prv;
409
410 while ((prv = reqq_shift (&req_queue)))
411 ETP_DESTROY (prv);
412
413 while ((prv = reqq_shift (&res_queue)))
414 ETP_DESTROY (prv);
415
416 while (wrk_first.next != &wrk_first)
417 {
418 etp_worker *wrk = wrk_first.next;
419
420 if (wrk->req)
421 ETP_DESTROY (wrk->req);
422
423 etp_worker_clear (wrk);
424 etp_worker_free (wrk);
425 }
426 508
427 started = 0; 509 started = 0;
428 idle = 0; 510 idle = 0;
429 nreqs = 0; 511 nreqs = 0;
430 nready = 0; 512 nready = 0;
431 npending = 0; 513 npending = 0;
432
433 etp_thread_init ();
434}
435
436static void ecb_cold
437etp_once_init (void)
438{
439 etp_thread_init ();
440 X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child);
441}
442
443static int ecb_cold
444etp_init (void (*want_poll)(void), void (*done_poll)(void))
445{
446 static pthread_once_t doinit = PTHREAD_ONCE_INIT;
447
448 pthread_once (&doinit, etp_once_init);
449 514
450 want_poll_cb = want_poll; 515 want_poll_cb = want_poll;
451 done_poll_cb = done_poll; 516 done_poll_cb = done_poll;
452 517
453 return 0; 518 return 0;
836# undef pread 901# undef pread
837# undef pwrite 902# undef pwrite
838# define pread eio__pread 903# define pread eio__pread
839# define pwrite eio__pwrite 904# define pwrite eio__pwrite
840 905
841static ssize_t 906static eio_ssize_t
842eio__pread (int fd, void *buf, size_t count, off_t offset) 907eio__pread (int fd, void *buf, size_t count, off_t offset)
843{ 908{
844 ssize_t res; 909 eio_ssize_t res;
845 off_t ooffset; 910 off_t ooffset;
846 911
847 X_LOCK (preadwritelock); 912 X_LOCK (preadwritelock);
848 ooffset = lseek (fd, 0, SEEK_CUR); 913 ooffset = lseek (fd, 0, SEEK_CUR);
849 lseek (fd, offset, SEEK_SET); 914 lseek (fd, offset, SEEK_SET);
852 X_UNLOCK (preadwritelock); 917 X_UNLOCK (preadwritelock);
853 918
854 return res; 919 return res;
855} 920}
856 921
857static ssize_t 922static eio_ssize_t
858eio__pwrite (int fd, void *buf, size_t count, off_t offset) 923eio__pwrite (int fd, void *buf, size_t count, off_t offset)
859{ 924{
860 ssize_t res; 925 eio_ssize_t res;
861 off_t ooffset; 926 off_t ooffset;
862 927
863 X_LOCK (preadwritelock); 928 X_LOCK (preadwritelock);
864 ooffset = lseek (fd, 0, SEEK_CUR); 929 ooffset = lseek (fd, 0, SEEK_CUR);
865 lseek (fd, offset, SEEK_SET); 930 lseek (fd, offset, SEEK_SET);
910 975
911#if !HAVE_FDATASYNC 976#if !HAVE_FDATASYNC
912# undef fdatasync 977# undef fdatasync
913# define fdatasync(fd) fsync (fd) 978# define fdatasync(fd) fsync (fd)
914#endif 979#endif
980
981static int
982eio__syncfs (int fd)
983{
984 int res;
985
986#if HAVE_SYS_SYNCFS
987 res = (int)syscall (__NR_syncfs, (int)(fd));
988#else
989 res = -1;
990 errno = ENOSYS;
991#endif
992
993 if (res < 0 && errno == ENOSYS && fd >= 0)
994 sync ();
995
996 return res;
997}
915 998
916/* sync_file_range always needs emulation */ 999/* sync_file_range always needs emulation */
917static int 1000static int
918eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) 1001eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags)
919{ 1002{
954 1037
955#if !HAVE_READAHEAD 1038#if !HAVE_READAHEAD
956# undef readahead 1039# undef readahead
957# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) 1040# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self)
958 1041
959static ssize_t 1042static eio_ssize_t
960eio__readahead (int fd, off_t offset, size_t count, etp_worker *self) 1043eio__readahead (int fd, off_t offset, size_t count, etp_worker *self)
961{ 1044{
962 size_t todo = count; 1045 size_t todo = count;
963 dBUF; 1046 dBUF;
964 1047
969 pread (fd, eio_buf, len, offset); 1052 pread (fd, eio_buf, len, offset);
970 offset += len; 1053 offset += len;
971 todo -= len; 1054 todo -= len;
972 } 1055 }
973 1056
1057 FUBd;
1058
974 errno = 0; 1059 errno = 0;
975 return count; 1060 return count;
976} 1061}
977 1062
978#endif 1063#endif
979 1064
980/* sendfile always needs emulation */ 1065/* sendfile always needs emulation */
981static ssize_t 1066static eio_ssize_t
982eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) 1067eio__sendfile (int ofd, int ifd, off_t offset, size_t count)
983{ 1068{
984 ssize_t written = 0; 1069 eio_ssize_t written = 0;
985 ssize_t res; 1070 eio_ssize_t res;
986 1071
987 if (!count) 1072 if (!count)
988 return 0; 1073 return 0;
989 1074
990 for (;;) 1075 for (;;)
1042 if (res < 0 && sbytes) 1127 if (res < 0 && sbytes)
1043 res = sbytes; 1128 res = sbytes;
1044 1129
1045# endif 1130# endif
1046 1131
1047#elif defined (_WIN32) 1132#elif defined (_WIN32) && 0
1048 /* does not work, just for documentation of what would need to be done */ 1133 /* does not work, just for documentation of what would need to be done */
1049 /* actually, cannot be done like this, as TransmitFile changes the file offset, */ 1134 /* actually, cannot be done like this, as TransmitFile changes the file offset, */
1050 /* libeio guarantees that the file offset does not change, and windows */ 1135 /* libeio guarantees that the file offset does not change, and windows */
1051 /* has no way to get an independent handle to the same file description */ 1136 /* has no way to get an independent handle to the same file description */
1052 HANDLE h = TO_SOCKET (ifd); 1137 HANDLE h = TO_SOCKET (ifd);
1085 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK 1170 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK
1086 /* BSDs */ 1171 /* BSDs */
1087#ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */ 1172#ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */
1088 || errno == ENOTSUP 1173 || errno == ENOTSUP
1089#endif 1174#endif
1175#ifdef EOPNOTSUPP /* windows */
1090 || errno == EOPNOTSUPP /* BSDs */ 1176 || errno == EOPNOTSUPP /* BSDs */
1177#endif
1091#if __solaris 1178#if __solaris
1092 || errno == EAFNOSUPPORT || errno == EPROTOTYPE 1179 || errno == EAFNOSUPPORT || errno == EPROTOTYPE
1093#endif 1180#endif
1094 ) 1181 )
1095 ) 1182 )
1099 1186
1100 res = 0; 1187 res = 0;
1101 1188
1102 while (count) 1189 while (count)
1103 { 1190 {
1104 ssize_t cnt; 1191 eio_ssize_t cnt;
1105 1192
1106 cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset); 1193 cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset);
1107 1194
1108 if (cnt <= 0) 1195 if (cnt <= 0)
1109 { 1196 {
1121 1208
1122 offset += cnt; 1209 offset += cnt;
1123 res += cnt; 1210 res += cnt;
1124 count -= cnt; 1211 count -= cnt;
1125 } 1212 }
1213
1214 FUBd;
1126 } 1215 }
1127 1216
1128 return res; 1217 return res;
1129} 1218}
1130 1219
1157 /* round up length */ 1246 /* round up length */
1158 *length = (*length + mask) & ~mask; 1247 *length = (*length + mask) & ~mask;
1159} 1248}
1160 1249
1161#if !_POSIX_MEMLOCK 1250#if !_POSIX_MEMLOCK
1162# define eio__mlockall(a) ((errno = ENOSYS), -1) 1251# define eio__mlockall(a) EIO_ENOSYS ()
1163#else 1252#else
1164 1253
1165static int 1254static int
1166eio__mlockall (int flags) 1255eio__mlockall (int flags)
1167{ 1256{
1181 return mlockall (flags); 1270 return mlockall (flags);
1182} 1271}
1183#endif 1272#endif
1184 1273
1185#if !_POSIX_MEMLOCK_RANGE 1274#if !_POSIX_MEMLOCK_RANGE
1186# define eio__mlock(a,b) ((errno = ENOSYS), -1) 1275# define eio__mlock(a,b) EIO_ENOSYS ()
1187#else 1276#else
1188 1277
1189static int 1278static int
1190eio__mlock (void *addr, size_t length) 1279eio__mlock (void *addr, size_t length)
1191{ 1280{
1195} 1284}
1196 1285
1197#endif 1286#endif
1198 1287
1199#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) 1288#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO)
1200# define eio__msync(a,b,c) ((errno = ENOSYS), -1) 1289# define eio__msync(a,b,c) EIO_ENOSYS ()
1201#else 1290#else
1202 1291
1203static int 1292static int
1204eio__msync (void *mem, size_t len, int flags) 1293eio__msync (void *mem, size_t len, int flags)
1205{ 1294{
1317 res += strlen (res); 1406 res += strlen (res);
1318 } 1407 }
1319 1408
1320 while (*rel) 1409 while (*rel)
1321 { 1410 {
1322 ssize_t len, linklen; 1411 eio_ssize_t len, linklen;
1323 char *beg = rel; 1412 char *beg = rel;
1324 1413
1325 while (*rel && *rel != '/') 1414 while (*rel && *rel != '/')
1326 ++rel; 1415 ++rel;
1327 1416
1420 1509
1421#define EIO_SORT_CUTOFF 30 /* quite high, but performs well on many filesystems */ 1510#define EIO_SORT_CUTOFF 30 /* quite high, but performs well on many filesystems */
1422#define EIO_SORT_FAST 60 /* when to only use insertion sort */ 1511#define EIO_SORT_FAST 60 /* when to only use insertion sort */
1423 1512
1424static void 1513static void
1425eio_dent_radix_sort (eio_dirent *dents, int size, signed char score_bits, ino_t inode_bits) 1514eio_dent_radix_sort (eio_dirent *dents, int size, signed char score_bits, eio_ino_t inode_bits)
1426{ 1515{
1427 unsigned char bits [9 + sizeof (ino_t) * 8]; 1516 unsigned char bits [9 + sizeof (eio_ino_t) * 8];
1428 unsigned char *bit = bits; 1517 unsigned char *bit = bits;
1429 1518
1430 assert (CHAR_BIT == 8); 1519 assert (CHAR_BIT == 8);
1431 assert (sizeof (eio_dirent) * 8 < 256); 1520 assert (sizeof (eio_dirent) * 8 < 256);
1432 assert (offsetof (eio_dirent, inode)); /* we use bit #0 as sentinel */ 1521 assert (offsetof (eio_dirent, inode)); /* we use bit #0 as sentinel */
1434 1523
1435 if (size <= EIO_SORT_FAST) 1524 if (size <= EIO_SORT_FAST)
1436 return; 1525 return;
1437 1526
1438 /* first prepare an array of bits to test in our radix sort */ 1527 /* first prepare an array of bits to test in our radix sort */
1439 /* try to take endianness into account, as well as differences in ino_t sizes */ 1528 /* try to take endianness into account, as well as differences in eio_ino_t sizes */
1440 /* inode_bits must contain all inodes ORed together */ 1529 /* inode_bits must contain all inodes ORed together */
1441 /* which is used to skip bits that are 0 everywhere, which is very common */ 1530 /* which is used to skip bits that are 0 everywhere, which is very common */
1442 { 1531 {
1443 ino_t endianness; 1532 eio_ino_t endianness;
1444 int i, j; 1533 int i, j;
1445 1534
1446 /* we store the byte offset of byte n into byte n of "endianness" */ 1535 /* we store the byte offset of byte n into byte n of "endianness" */
1447 for (i = 0; i < sizeof (ino_t); ++i) 1536 for (i = 0; i < sizeof (eio_ino_t); ++i)
1448 ((unsigned char *)&endianness)[i] = i; 1537 ((unsigned char *)&endianness)[i] = i;
1449 1538
1450 *bit++ = 0; 1539 *bit++ = 0;
1451 1540
1452 for (i = 0; i < sizeof (ino_t); ++i) 1541 for (i = 0; i < sizeof (eio_ino_t); ++i)
1453 { 1542 {
1454 /* shifting off the byte offsets out of "endianness" */ 1543 /* shifting off the byte offsets out of "endianness" */
1455 int offs = (offsetof (eio_dirent, inode) + (endianness & 0xff)) * 8; 1544 int offs = (offsetof (eio_dirent, inode) + (endianness & 0xff)) * 8;
1456 endianness >>= 8; 1545 endianness >>= 8;
1457 1546
1458 for (j = 0; j < 8; ++j) 1547 for (j = 0; j < 8; ++j)
1459 if (inode_bits & (((ino_t)1) << (i * 8 + j))) 1548 if (inode_bits & (((eio_ino_t)1) << (i * 8 + j)))
1460 *bit++ = offs + j; 1549 *bit++ = offs + j;
1461 } 1550 }
1462 1551
1463 for (j = 0; j < 8; ++j) 1552 for (j = 0; j < 8; ++j)
1464 if (score_bits & (1 << j)) 1553 if (score_bits & (1 << j))
1465 *bit++ = offsetof (eio_dirent, score) * 8 + j; 1554 *bit++ = offsetof (eio_dirent, score) * 8 + j;
1466 } 1555 }
1467 1556
1468 /* now actually do the sorting (a variant of MSD radix sort) */ 1557 /* now actually do the sorting (a variant of MSD radix sort) */
1469 { 1558 {
1470 eio_dirent *base_stk [9 + sizeof (ino_t) * 8], *base; 1559 eio_dirent *base_stk [9 + sizeof (eio_ino_t) * 8], *base;
1471 eio_dirent *end_stk [9 + sizeof (ino_t) * 8], *end; 1560 eio_dirent *end_stk [9 + sizeof (eio_ino_t) * 8], *end;
1472 unsigned char *bit_stk [9 + sizeof (ino_t) * 8]; 1561 unsigned char *bit_stk [9 + sizeof (eio_ino_t) * 8];
1473 int stk_idx = 0; 1562 int stk_idx = 0;
1474 1563
1475 base_stk [stk_idx] = dents; 1564 base_stk [stk_idx] = dents;
1476 end_stk [stk_idx] = dents + size; 1565 end_stk [stk_idx] = dents + size;
1477 bit_stk [stk_idx] = bit - 1; 1566 bit_stk [stk_idx] = bit - 1;
1556 } 1645 }
1557 } 1646 }
1558} 1647}
1559 1648
1560static void 1649static void
1561eio_dent_sort (eio_dirent *dents, int size, signed char score_bits, ino_t inode_bits) 1650eio_dent_sort (eio_dirent *dents, int size, signed char score_bits, eio_ino_t inode_bits)
1562{ 1651{
1563 if (size <= 1) 1652 if (size <= 1)
1564 return; /* our insertion sort relies on size > 0 */ 1653 return; /* our insertion sort relies on size > 0 */
1565 1654
1566 /* first we use a radix sort, but only for dirs >= EIO_SORT_FAST */ 1655 /* first we use a radix sort, but only for dirs >= EIO_SORT_FAST */
1574 1663
1575/* read a full directory */ 1664/* read a full directory */
1576static void 1665static void
1577eio__scandir (eio_req *req, etp_worker *self) 1666eio__scandir (eio_req *req, etp_worker *self)
1578{ 1667{
1579 DIR *dirp;
1580 EIO_STRUCT_DIRENT *entp;
1581 char *name, *names; 1668 char *name, *names;
1582 int namesalloc = 4096; 1669 int namesalloc = 4096 - sizeof (void *) * 4;
1583 int namesoffs = 0; 1670 int namesoffs = 0;
1584 int flags = req->int1; 1671 int flags = req->int1;
1585 eio_dirent *dents = 0; 1672 eio_dirent *dents = 0;
1586 int dentalloc = 128; 1673 int dentalloc = 128;
1587 int dentoffs = 0; 1674 int dentoffs = 0;
1588 ino_t inode_bits = 0; 1675 eio_ino_t inode_bits = 0;
1676#ifdef _WIN32
1677 HANDLE dirp;
1678 WIN32_FIND_DATA entp;
1679#else
1680 DIR *dirp;
1681 EIO_STRUCT_DIRENT *entp;
1682#endif
1589 1683
1590 req->result = -1; 1684 req->result = -1;
1591 1685
1592 if (!(flags & EIO_READDIR_DENTS)) 1686 if (!(flags & EIO_READDIR_DENTS))
1593 flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER); 1687 flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER);
1594 1688
1595 X_LOCK (wrklock); 1689#ifdef _WIN32
1596 /* the corresponding closedir is in ETP_WORKER_CLEAR */ 1690 {
1691 int len = strlen ((const char *)req->ptr1);
1692 char *path = malloc (MAX_PATH);
1693 const char *fmt;
1694
1695 if (!len)
1696 fmt = "./*";
1697 else if (((const char *)req->ptr1)[len - 1] == '/' || ((const char *)req->ptr1)[len - 1] == '\\')
1698 fmt = "%s*";
1699 else
1700 fmt = "%s/*";
1701
1702 _snprintf (path, MAX_PATH, fmt, (const char *)req->ptr1);
1703 dirp = FindFirstFile (path, &entp);
1704 free (path);
1705
1706 if (dirp == INVALID_HANDLE_VALUE)
1707 {
1708 dirp = 0;
1709
1710 /* should steal _dosmaperr */
1711 switch (GetLastError ())
1712 {
1713 case ERROR_FILE_NOT_FOUND:
1714 req->result = 0;
1715 break;
1716
1717 case ERROR_INVALID_NAME:
1718 case ERROR_PATH_NOT_FOUND:
1719 case ERROR_NO_MORE_FILES:
1720 errno = ENOENT;
1721 break;
1722
1723 case ERROR_NOT_ENOUGH_MEMORY:
1724 errno = ENOMEM;
1725 break;
1726
1727 default:
1728 errno = EINVAL;
1729 break;
1730 }
1731 }
1732 }
1733#else
1597 self->dirp = dirp = opendir (req->ptr1); 1734 dirp = opendir (req->ptr1);
1735#endif
1598 1736
1599 if (req->flags & EIO_FLAG_PTR1_FREE) 1737 if (req->flags & EIO_FLAG_PTR1_FREE)
1600 free (req->ptr1); 1738 free (req->ptr1);
1601 1739
1602 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; 1740 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE;
1603 req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; 1741 req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0;
1604 req->ptr2 = names = malloc (namesalloc); 1742 req->ptr2 = names = malloc (namesalloc);
1605 X_UNLOCK (wrklock);
1606 1743
1607 if (dirp && names && (!flags || dents)) 1744 if (dirp && names && (!flags || dents))
1608 for (;;) 1745 for (;;)
1609 { 1746 {
1747 int done;
1748
1749#ifdef _WIN32
1750 done = !dirp;
1751#else
1610 errno = 0; 1752 errno = 0;
1611 entp = readdir (dirp); 1753 entp = readdir (dirp);
1754 done = !entp;
1755#endif
1612 1756
1613 if (!entp) 1757 if (done)
1614 { 1758 {
1759#ifndef _WIN32
1760 int old_errno = errno;
1761 closedir (dirp);
1762 errno = old_errno;
1763
1615 if (errno) 1764 if (errno)
1616 break; 1765 break;
1766#endif
1617 1767
1618 /* sort etc. */ 1768 /* sort etc. */
1619 req->int1 = flags; 1769 req->int1 = flags;
1620 req->result = dentoffs; 1770 req->result = dentoffs;
1621 1771
1650 1800
1651 break; 1801 break;
1652 } 1802 }
1653 1803
1654 /* now add the entry to our list(s) */ 1804 /* now add the entry to our list(s) */
1655 name = entp->d_name; 1805 name = D_NAME (entp);
1656 1806
1657 /* skip . and .. entries */ 1807 /* skip . and .. entries */
1658 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) 1808 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2])))
1659 { 1809 {
1660 int len = D_NAMLEN (entp) + 1; 1810 int len = D_NAMLEN (entp) + 1;
1661 1811
1662 while (ecb_expect_false (namesoffs + len > namesalloc)) 1812 while (ecb_expect_false (namesoffs + len > namesalloc))
1663 { 1813 {
1664 namesalloc *= 2; 1814 namesalloc *= 2;
1665 X_LOCK (wrklock);
1666 req->ptr2 = names = realloc (names, namesalloc); 1815 req->ptr2 = names = realloc (names, namesalloc);
1667 X_UNLOCK (wrklock);
1668 1816
1669 if (!names) 1817 if (!names)
1670 break; 1818 break;
1671 } 1819 }
1672 1820
1677 struct eio_dirent *ent; 1825 struct eio_dirent *ent;
1678 1826
1679 if (ecb_expect_false (dentoffs == dentalloc)) 1827 if (ecb_expect_false (dentoffs == dentalloc))
1680 { 1828 {
1681 dentalloc *= 2; 1829 dentalloc *= 2;
1682 X_LOCK (wrklock);
1683 req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent)); 1830 req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent));
1684 X_UNLOCK (wrklock);
1685 1831
1686 if (!dents) 1832 if (!dents)
1687 break; 1833 break;
1688 } 1834 }
1689 1835
1769 if (EIO_CANCELLED (req)) 1915 if (EIO_CANCELLED (req))
1770 { 1916 {
1771 errno = ECANCELED; 1917 errno = ECANCELED;
1772 break; 1918 break;
1773 } 1919 }
1920
1921#ifdef _WIN32
1922 if (!FindNextFile (dirp, &entp))
1923 {
1924 FindClose (dirp);
1925 dirp = 0;
1926 }
1927#endif
1774 } 1928 }
1775} 1929}
1776 1930
1777/*****************************************************************************/ 1931/*****************************************************************************/
1778 1932
1794X_THREAD_PROC (etp_proc) 1948X_THREAD_PROC (etp_proc)
1795{ 1949{
1796 ETP_REQ *req; 1950 ETP_REQ *req;
1797 struct timespec ts; 1951 struct timespec ts;
1798 etp_worker *self = (etp_worker *)thr_arg; 1952 etp_worker *self = (etp_worker *)thr_arg;
1799 int timeout; 1953
1954#if HAVE_PRCTL_SET_NAME
1955 prctl (PR_SET_NAME, (unsigned long)"eio_thread", 0, 0, 0);
1956#endif
1800 1957
1801 /* try to distribute timeouts somewhat evenly */ 1958 /* try to distribute timeouts somewhat evenly */
1802 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 1959 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
1803 1960
1804 for (;;) 1961 for (;;)
1874/*****************************************************************************/ 2031/*****************************************************************************/
1875 2032
1876int ecb_cold 2033int ecb_cold
1877eio_init (void (*want_poll)(void), void (*done_poll)(void)) 2034eio_init (void (*want_poll)(void), void (*done_poll)(void))
1878{ 2035{
2036#if !HAVE_PREADWRITE
2037 X_MUTEX_CREATE (preadwritelock);
2038#endif
2039
1879 return etp_init (want_poll, done_poll); 2040 return etp_init (want_poll, done_poll);
1880} 2041}
1881 2042
1882ecb_inline void 2043ecb_inline void
1883eio_api_destroy (eio_req *req) 2044eio_api_destroy (eio_req *req)
1928 case EIO_WRITE: req->result = req->offs >= 0 2089 case EIO_WRITE: req->result = req->offs >= 0
1929 ? pwrite (req->int1, req->ptr2, req->size, req->offs) 2090 ? pwrite (req->int1, req->ptr2, req->size, req->offs)
1930 : write (req->int1, req->ptr2, req->size); break; 2091 : write (req->int1, req->ptr2, req->size); break;
1931 2092
1932 case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; 2093 case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break;
1933 case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size, self); break; 2094 case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break;
1934 2095
1935 case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); 2096 case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT));
1936 req->result = stat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; 2097 req->result = stat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break;
1937 case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); 2098 case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT));
1938 req->result = lstat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; 2099 req->result = lstat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break;
1968 req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; 2129 req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break;
1969 2130
1970 case EIO_SYNC: req->result = 0; sync (); break; 2131 case EIO_SYNC: req->result = 0; sync (); break;
1971 case EIO_FSYNC: req->result = fsync (req->int1); break; 2132 case EIO_FSYNC: req->result = fsync (req->int1); break;
1972 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; 2133 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break;
2134 case EIO_SYNCFS: req->result = eio__syncfs (req->int1); break;
2135 case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break;
1973 case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; 2136 case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break;
1974 case EIO_MTOUCH: req->result = eio__mtouch (req); break; 2137 case EIO_MTOUCH: req->result = eio__mtouch (req); break;
1975 case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; 2138 case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break;
1976 case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; 2139 case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break;
1977 case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break;
1978 case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break; 2140 case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break;
1979 2141
1980 case EIO_READDIR: eio__scandir (req, self); break; 2142 case EIO_READDIR: eio__scandir (req, self); break;
1981 2143
1982 case EIO_BUSY: 2144 case EIO_BUSY:
2063eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) 2225eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data)
2064{ 2226{
2065 REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; 2227 REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND;
2066} 2228}
2067 2229
2230eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data)
2231{
2232 REQ (EIO_FDATASYNC); req->int1 = fd; SEND;
2233}
2234
2235eio_req *eio_syncfs (int fd, int pri, eio_cb cb, void *data)
2236{
2237 REQ (EIO_SYNCFS); req->int1 = fd; SEND;
2238}
2239
2240eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data)
2241{
2242 REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND;
2243}
2244
2068eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) 2245eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data)
2069{ 2246{
2070 REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND; 2247 REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND;
2071} 2248}
2072 2249
2078eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data) 2255eio_req *eio_mlockall (int flags, int pri, eio_cb cb, void *data)
2079{ 2256{
2080 REQ (EIO_MLOCKALL); req->int1 = flags; SEND; 2257 REQ (EIO_MLOCKALL); req->int1 = flags; SEND;
2081} 2258}
2082 2259
2083eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data)
2084{
2085 REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND;
2086}
2087
2088eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data) 2260eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data)
2089{ 2261{
2090 REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND; 2262 REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND;
2091} 2263}
2092 2264
2093eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data)
2094{
2095 REQ (EIO_FDATASYNC); req->int1 = fd; SEND;
2096}
2097
2098eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) 2265eio_req *eio_close (int fd, int pri, eio_cb cb, void *data)
2099{ 2266{
2100 REQ (EIO_CLOSE); req->int1 = fd; SEND; 2267 REQ (EIO_CLOSE); req->int1 = fd; SEND;
2101} 2268}
2102 2269
2138eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) 2305eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data)
2139{ 2306{
2140 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; 2307 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND;
2141} 2308}
2142 2309
2143eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) 2310eio_req *eio_fchown (int fd, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data)
2144{ 2311{
2145 REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; 2312 REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND;
2146} 2313}
2147 2314
2148eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) 2315eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data)
2168eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) 2335eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data)
2169{ 2336{
2170 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; 2337 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND;
2171} 2338}
2172 2339
2173eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) 2340eio_req *eio_chown (const char *path, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data)
2174{ 2341{
2175 REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; 2342 REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND;
2176} 2343}
2177 2344
2178eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) 2345eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data)
2325} 2492}
2326 2493
2327/*****************************************************************************/ 2494/*****************************************************************************/
2328/* misc garbage */ 2495/* misc garbage */
2329 2496
2330ssize_t 2497eio_ssize_t
2331eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) 2498eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count)
2332{ 2499{
2333 etp_worker wrk;
2334 ssize_t ret;
2335
2336 wrk.dbuf = 0;
2337
2338 ret = eio__sendfile (ofd, ifd, offset, count, &wrk); 2500 return eio__sendfile (ofd, ifd, offset, count);
2339
2340 if (wrk.dbuf)
2341 free (wrk.dbuf);
2342
2343 return ret;
2344} 2501}
2345 2502

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines