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

Comparing libeio/eio.c (file contents):
Revision 1.87 by root, Thu Jul 14 19:19:22 2011 UTC vs.
Revision 1.99 by root, Tue Jul 26 11:07:08 2011 UTC

58#include <sys/stat.h> 58#include <sys/stat.h>
59#include <limits.h> 59#include <limits.h>
60#include <fcntl.h> 60#include <fcntl.h>
61#include <assert.h> 61#include <assert.h>
62 62
63#include <sys/statvfs.h>
64/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ 63/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */
65/* intptr_t only comes from stdint.h, says idiot openbsd coder */ 64/* intptr_t only comes from stdint.h, says idiot openbsd coder */
66#if HAVE_STDINT_H 65#if HAVE_STDINT_H
67# include <stdint.h> 66# include <stdint.h>
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
96 102
97#define EIO_ENOSYS() EIO_ERRNO (ENOSYS, -1) 103#define EIO_ENOSYS() EIO_ERRNO (ENOSYS, -1)
98 104
99#ifdef _WIN32 105#ifdef _WIN32
100 106
107 #undef PAGESIZE
101 #define PAGESIZE 4096 /* GetSystemInfo? */ 108 #define PAGESIZE 4096 /* GetSystemInfo? */
102 109
103 #ifdef EIO_STRUCT_STATI64 110 #ifdef EIO_STRUCT_STATI64
104 #define stat(path,buf) _stati64 (path,buf) 111 #define stat(path,buf) _stati64 (path,buf)
105 #define fstat(fd,buf) _fstati64 (path,buf) 112 #define fstat(fd,buf) _fstati64 (fd,buf)
106 #endif 113 #endif
107 #define lstat(path,buf) stat (path,buf) 114 #define lstat(path,buf) stat (path,buf)
108 #define fsync(fd) (FlushFileBuffers (EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) 115 #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1))
109 #define mkdir(path,mode) _mkdir (path) 116 #define mkdir(path,mode) _mkdir (path)
110 #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) 117 #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1))
111 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 ()
112 #define chown(path,uid,gid) EIO_ENOSYS () 124 #define chown(path,uid,gid) EIO_ENOSYS ()
113 #define fchown(fd,uid,gid) EIO_ENOSYS () 125 #define fchown(fd,uid,gid) EIO_ENOSYS ()
114 #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */ 126 #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */
115 #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */ 127 #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */
116 #define mknod(path,mode,dev) EIO_ENOSYS () 128 #define mknod(path,mode,dev) EIO_ENOSYS ()
117 #define sync() 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 }
118 164
119 /* we could even stat and see if it exists */ 165 /* we could even stat and see if it exists */
120 static int 166 static int
121 symlink (const char *old, const char *neu) 167 symlink (const char *old, const char *neu)
122 { 168 {
169 #if WINVER >= 0x0600
123 if (CreateSymbolicLink (neu, old, 1)) 170 if (CreateSymbolicLink (neu, old, 1))
124 return 0; 171 return 0;
125 172
126 if (CreateSymbolicLink (neu, old, 0)) 173 if (CreateSymbolicLink (neu, old, 0))
127 return 0; 174 return 0;
175 #endif
128 176
129 return EIO_ERRNO (ENOENT, -1); 177 return EIO_ERRNO (ENOENT, -1);
130 } 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)
131 193
132#else 194#else
133 195
134 #include <sys/time.h> 196 #include <sys/time.h>
135 #include <sys/select.h> 197 #include <sys/select.h>
136 #include <sys/statvfs.h> 198 #include <sys/statvfs.h>
137 #include <unistd.h> 199 #include <unistd.h>
138 #include <utime.h>
139 #include <signal.h> 200 #include <signal.h>
140 #include <dirent.h> 201 #include <dirent.h>
141 202
142 #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES 203 #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES
143 #include <sys/mman.h> 204 #include <sys/mman.h>
144 #endif 205 #endif
206
207 #define D_NAME(entp) entp->d_name
145 208
146 /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ 209 /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */
147 #if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ 210 #if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
148 #define _DIRENT_HAVE_D_TYPE /* sigh */ 211 #define _DIRENT_HAVE_D_TYPE /* sigh */
149 #define D_INO(de) (de)->d_fileno 212 #define D_INO(de) (de)->d_fileno
163 226
164 #ifndef EIO_STRUCT_DIRENT 227 #ifndef EIO_STRUCT_DIRENT
165 #define EIO_STRUCT_DIRENT struct dirent 228 #define EIO_STRUCT_DIRENT struct dirent
166 #endif 229 #endif
167 230
231#endif
232
233#if HAVE_UTIMES
234# include <utime.h>
235#endif
236
237#if HAVE_SYS_SYSCALL_H
238# include <sys/syscall.h>
239#endif
240
241#if HAVE_SYS_PRCTL_H
242# include <sys/prctl.h>
168#endif 243#endif
169 244
170#if HAVE_SENDFILE 245#if HAVE_SENDFILE
171# if __linux 246# if __linux
172# include <sys/sendfile.h> 247# include <sys/sendfile.h>
187#endif 262#endif
188#ifndef D_INO 263#ifndef D_INO
189# define D_INO(de) 0 264# define D_INO(de) 0
190#endif 265#endif
191#ifndef D_NAMLEN 266#ifndef D_NAMLEN
192# define D_NAMLEN(de) strlen ((de)->d_name) 267# define D_NAMLEN(entp) strlen (D_NAME (entp))
193#endif 268#endif
194 269
195/* used for struct dirent, AIX doesn't provide it */ 270/* used for struct dirent, AIX doesn't provide it */
196#ifndef NAME_MAX 271#ifndef NAME_MAX
197# define NAME_MAX 4096 272# define NAME_MAX 4096
204 279
205/* buffer size for various temporary buffers */ 280/* buffer size for various temporary buffers */
206#define EIO_BUFSIZE 65536 281#define EIO_BUFSIZE 65536
207 282
208#define dBUF \ 283#define dBUF \
209 char *eio_buf; \
210 ETP_WORKER_LOCK (self); \
211 self->dbuf = eio_buf = malloc (EIO_BUFSIZE); \ 284 char *eio_buf = malloc (EIO_BUFSIZE); \
212 ETP_WORKER_UNLOCK (self); \
213 errno = ENOMEM; \ 285 errno = ENOMEM; \
214 if (!eio_buf) \ 286 if (!eio_buf) \
215 return -1; 287 return -1
288
289#define FUBd \
290 free (eio_buf)
216 291
217#define EIO_TICKS ((1000000 + 1023) >> 10) 292#define EIO_TICKS ((1000000 + 1023) >> 10)
218 293
219#define ETP_PRI_MIN EIO_PRI_MIN 294#define ETP_PRI_MIN EIO_PRI_MIN
220#define ETP_PRI_MAX EIO_PRI_MAX 295#define ETP_PRI_MAX EIO_PRI_MAX
226static int eio_finish (eio_req *req); 301static int eio_finish (eio_req *req);
227#define ETP_FINISH(req) eio_finish (req) 302#define ETP_FINISH(req) eio_finish (req)
228static void eio_execute (struct etp_worker *self, eio_req *req); 303static void eio_execute (struct etp_worker *self, eio_req *req);
229#define ETP_EXECUTE(wrk,req) eio_execute (wrk,req) 304#define ETP_EXECUTE(wrk,req) eio_execute (wrk,req)
230 305
231#define ETP_WORKER_CLEAR(req) \
232 if (wrk->dbuf) \
233 { \
234 free (wrk->dbuf); \
235 wrk->dbuf = 0; \
236 } \
237 \
238 if (wrk->dirp) \
239 { \
240 closedir (wrk->dirp); \
241 wrk->dirp = 0; \
242 }
243
244#define ETP_WORKER_COMMON \
245 void *dbuf; \
246 DIR *dirp;
247
248/*****************************************************************************/ 306/*****************************************************************************/
249 307
250#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) 308#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1)
251 309
252/* calculate time difference in ~1/EIO_TICKS of a second */ 310/* calculate time difference in ~1/EIO_TICKS of a second */
280/* 338/*
281 * make our pread/pwrite emulation safe against themselves, but not against 339 * make our pread/pwrite emulation safe against themselves, but not against
282 * 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,
283 * but that's your problem, not mine. 341 * but that's your problem, not mine.
284 */ 342 */
285static xmutex_t preadwritelock = X_MUTEX_INIT; 343static xmutex_t preadwritelock;
286#endif 344#endif
287 345
288typedef struct etp_worker 346typedef struct etp_worker
289{ 347{
290 /* locked by wrklock */ 348 /* locked by wrklock */
293 xthread_t tid; 351 xthread_t tid;
294 352
295 /* locked by reslock, reqlock or wrklock */ 353 /* locked by reslock, reqlock or wrklock */
296 ETP_REQ *req; /* currently processed request */ 354 ETP_REQ *req; /* currently processed request */
297 355
356#ifdef ETP_WORKER_COMMON
298 ETP_WORKER_COMMON 357 ETP_WORKER_COMMON
358#endif
299} etp_worker; 359} etp_worker;
300 360
301static etp_worker wrk_first = { &wrk_first, &wrk_first, 0 }; /* NOT etp */ 361static etp_worker wrk_first; /* NOT etp */
302 362
303#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) 363#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock)
304#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock) 364#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock)
305 365
306/* worker threads management */ 366/* worker threads management */
307 367
308static void ecb_cold 368static void ecb_cold
309etp_worker_clear (etp_worker *wrk) 369etp_worker_clear (etp_worker *wrk)
310{ 370{
311 ETP_WORKER_CLEAR (wrk);
312} 371}
313 372
314static void ecb_cold 373static void ecb_cold
315etp_worker_free (etp_worker *wrk) 374etp_worker_free (etp_worker *wrk)
316{ 375{
377} etp_reqq; 436} etp_reqq;
378 437
379static etp_reqq req_queue; 438static etp_reqq req_queue;
380static etp_reqq res_queue; 439static etp_reqq res_queue;
381 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
382static int ecb_noinline 452static int ecb_noinline
383reqq_push (etp_reqq *q, ETP_REQ *req) 453reqq_push (etp_reqq *q, ETP_REQ *req)
384{ 454{
385 int pri = req->pri; 455 int pri = req->pri;
386 req->next = 0; 456 req->next = 0;
420 } 490 }
421 491
422 abort (); 492 abort ();
423} 493}
424 494
425static void ecb_cold 495static int ecb_cold
426etp_thread_init (void) 496etp_init (void (*want_poll)(void), void (*done_poll)(void))
427{ 497{
428#if !HAVE_PREADWRITE
429 X_MUTEX_CREATE (preadwritelock);
430#endif
431 X_MUTEX_CREATE (wrklock); 498 X_MUTEX_CREATE (wrklock);
432 X_MUTEX_CREATE (reslock); 499 X_MUTEX_CREATE (reslock);
433 X_MUTEX_CREATE (reqlock); 500 X_MUTEX_CREATE (reqlock);
434 X_COND_CREATE (reqwait); 501 X_COND_CREATE (reqwait);
435}
436 502
437static void ecb_cold 503 reqq_init (&req_queue);
438etp_atfork_prepare (void) 504 reqq_init (&res_queue);
439{
440}
441 505
442static void ecb_cold 506 wrk_first.next =
443etp_atfork_parent (void) 507 wrk_first.prev = &wrk_first;
444{
445}
446
447static void ecb_cold
448etp_atfork_child (void)
449{
450 ETP_REQ *prv;
451
452 while ((prv = reqq_shift (&req_queue)))
453 ETP_DESTROY (prv);
454
455 while ((prv = reqq_shift (&res_queue)))
456 ETP_DESTROY (prv);
457
458 while (wrk_first.next != &wrk_first)
459 {
460 etp_worker *wrk = wrk_first.next;
461
462 if (wrk->req)
463 ETP_DESTROY (wrk->req);
464
465 etp_worker_clear (wrk);
466 etp_worker_free (wrk);
467 }
468 508
469 started = 0; 509 started = 0;
470 idle = 0; 510 idle = 0;
471 nreqs = 0; 511 nreqs = 0;
472 nready = 0; 512 nready = 0;
473 npending = 0; 513 npending = 0;
474
475 etp_thread_init ();
476}
477
478static void ecb_cold
479etp_once_init (void)
480{
481 etp_thread_init ();
482 X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child);
483}
484
485static int ecb_cold
486etp_init (void (*want_poll)(void), void (*done_poll)(void))
487{
488 static pthread_once_t doinit = PTHREAD_ONCE_INIT;
489
490 pthread_once (&doinit, etp_once_init);
491 514
492 want_poll_cb = want_poll; 515 want_poll_cb = want_poll;
493 done_poll_cb = done_poll; 516 done_poll_cb = done_poll;
494 517
495 return 0; 518 return 0;
878# undef pread 901# undef pread
879# undef pwrite 902# undef pwrite
880# define pread eio__pread 903# define pread eio__pread
881# define pwrite eio__pwrite 904# define pwrite eio__pwrite
882 905
883static ssize_t 906static eio_ssize_t
884eio__pread (int fd, void *buf, size_t count, off_t offset) 907eio__pread (int fd, void *buf, size_t count, off_t offset)
885{ 908{
886 ssize_t res; 909 eio_ssize_t res;
887 off_t ooffset; 910 off_t ooffset;
888 911
889 X_LOCK (preadwritelock); 912 X_LOCK (preadwritelock);
890 ooffset = lseek (fd, 0, SEEK_CUR); 913 ooffset = lseek (fd, 0, SEEK_CUR);
891 lseek (fd, offset, SEEK_SET); 914 lseek (fd, offset, SEEK_SET);
894 X_UNLOCK (preadwritelock); 917 X_UNLOCK (preadwritelock);
895 918
896 return res; 919 return res;
897} 920}
898 921
899static ssize_t 922static eio_ssize_t
900eio__pwrite (int fd, void *buf, size_t count, off_t offset) 923eio__pwrite (int fd, void *buf, size_t count, off_t offset)
901{ 924{
902 ssize_t res; 925 eio_ssize_t res;
903 off_t ooffset; 926 off_t ooffset;
904 927
905 X_LOCK (preadwritelock); 928 X_LOCK (preadwritelock);
906 ooffset = lseek (fd, 0, SEEK_CUR); 929 ooffset = lseek (fd, 0, SEEK_CUR);
907 lseek (fd, offset, SEEK_SET); 930 lseek (fd, offset, SEEK_SET);
952 975
953#if !HAVE_FDATASYNC 976#if !HAVE_FDATASYNC
954# undef fdatasync 977# undef fdatasync
955# define fdatasync(fd) fsync (fd) 978# define fdatasync(fd) fsync (fd)
956#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}
957 998
958/* sync_file_range always needs emulation */ 999/* sync_file_range always needs emulation */
959static int 1000static int
960eio__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)
961{ 1002{
996 1037
997#if !HAVE_READAHEAD 1038#if !HAVE_READAHEAD
998# undef readahead 1039# undef readahead
999# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) 1040# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self)
1000 1041
1001static ssize_t 1042static eio_ssize_t
1002eio__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)
1003{ 1044{
1004 size_t todo = count; 1045 size_t todo = count;
1005 dBUF; 1046 dBUF;
1006 1047
1011 pread (fd, eio_buf, len, offset); 1052 pread (fd, eio_buf, len, offset);
1012 offset += len; 1053 offset += len;
1013 todo -= len; 1054 todo -= len;
1014 } 1055 }
1015 1056
1057 FUBd;
1058
1016 errno = 0; 1059 errno = 0;
1017 return count; 1060 return count;
1018} 1061}
1019 1062
1020#endif 1063#endif
1021 1064
1022/* sendfile always needs emulation */ 1065/* sendfile always needs emulation */
1023static ssize_t 1066static eio_ssize_t
1024eio__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)
1025{ 1068{
1026 ssize_t written = 0; 1069 eio_ssize_t written = 0;
1027 ssize_t res; 1070 eio_ssize_t res;
1028 1071
1029 if (!count) 1072 if (!count)
1030 return 0; 1073 return 0;
1031 1074
1032 for (;;) 1075 for (;;)
1127 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK 1170 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK
1128 /* BSDs */ 1171 /* BSDs */
1129#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... */
1130 || errno == ENOTSUP 1173 || errno == ENOTSUP
1131#endif 1174#endif
1175#ifdef EOPNOTSUPP /* windows */
1132 || errno == EOPNOTSUPP /* BSDs */ 1176 || errno == EOPNOTSUPP /* BSDs */
1177#endif
1133#if __solaris 1178#if __solaris
1134 || errno == EAFNOSUPPORT || errno == EPROTOTYPE 1179 || errno == EAFNOSUPPORT || errno == EPROTOTYPE
1135#endif 1180#endif
1136 ) 1181 )
1137 ) 1182 )
1141 1186
1142 res = 0; 1187 res = 0;
1143 1188
1144 while (count) 1189 while (count)
1145 { 1190 {
1146 ssize_t cnt; 1191 eio_ssize_t cnt;
1147 1192
1148 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);
1149 1194
1150 if (cnt <= 0) 1195 if (cnt <= 0)
1151 { 1196 {
1163 1208
1164 offset += cnt; 1209 offset += cnt;
1165 res += cnt; 1210 res += cnt;
1166 count -= cnt; 1211 count -= cnt;
1167 } 1212 }
1213
1214 FUBd;
1168 } 1215 }
1169 1216
1170 return res; 1217 return res;
1171} 1218}
1172 1219
1199 /* round up length */ 1246 /* round up length */
1200 *length = (*length + mask) & ~mask; 1247 *length = (*length + mask) & ~mask;
1201} 1248}
1202 1249
1203#if !_POSIX_MEMLOCK 1250#if !_POSIX_MEMLOCK
1204# define eio__mlockall(a) eio_nosyscall() 1251# define eio__mlockall(a) EIO_ENOSYS ()
1205#else 1252#else
1206 1253
1207static int 1254static int
1208eio__mlockall (int flags) 1255eio__mlockall (int flags)
1209{ 1256{
1359 res += strlen (res); 1406 res += strlen (res);
1360 } 1407 }
1361 1408
1362 while (*rel) 1409 while (*rel)
1363 { 1410 {
1364 ssize_t len, linklen; 1411 eio_ssize_t len, linklen;
1365 char *beg = rel; 1412 char *beg = rel;
1366 1413
1367 while (*rel && *rel != '/') 1414 while (*rel && *rel != '/')
1368 ++rel; 1415 ++rel;
1369 1416
1462 1509
1463#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 */
1464#define EIO_SORT_FAST 60 /* when to only use insertion sort */ 1511#define EIO_SORT_FAST 60 /* when to only use insertion sort */
1465 1512
1466static void 1513static void
1467eio_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)
1468{ 1515{
1469 unsigned char bits [9 + sizeof (ino_t) * 8]; 1516 unsigned char bits [9 + sizeof (eio_ino_t) * 8];
1470 unsigned char *bit = bits; 1517 unsigned char *bit = bits;
1471 1518
1472 assert (CHAR_BIT == 8); 1519 assert (CHAR_BIT == 8);
1473 assert (sizeof (eio_dirent) * 8 < 256); 1520 assert (sizeof (eio_dirent) * 8 < 256);
1474 assert (offsetof (eio_dirent, inode)); /* we use bit #0 as sentinel */ 1521 assert (offsetof (eio_dirent, inode)); /* we use bit #0 as sentinel */
1476 1523
1477 if (size <= EIO_SORT_FAST) 1524 if (size <= EIO_SORT_FAST)
1478 return; 1525 return;
1479 1526
1480 /* 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 */
1481 /* 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 */
1482 /* inode_bits must contain all inodes ORed together */ 1529 /* inode_bits must contain all inodes ORed together */
1483 /* 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 */
1484 { 1531 {
1485 ino_t endianness; 1532 eio_ino_t endianness;
1486 int i, j; 1533 int i, j;
1487 1534
1488 /* 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" */
1489 for (i = 0; i < sizeof (ino_t); ++i) 1536 for (i = 0; i < sizeof (eio_ino_t); ++i)
1490 ((unsigned char *)&endianness)[i] = i; 1537 ((unsigned char *)&endianness)[i] = i;
1491 1538
1492 *bit++ = 0; 1539 *bit++ = 0;
1493 1540
1494 for (i = 0; i < sizeof (ino_t); ++i) 1541 for (i = 0; i < sizeof (eio_ino_t); ++i)
1495 { 1542 {
1496 /* shifting off the byte offsets out of "endianness" */ 1543 /* shifting off the byte offsets out of "endianness" */
1497 int offs = (offsetof (eio_dirent, inode) + (endianness & 0xff)) * 8; 1544 int offs = (offsetof (eio_dirent, inode) + (endianness & 0xff)) * 8;
1498 endianness >>= 8; 1545 endianness >>= 8;
1499 1546
1500 for (j = 0; j < 8; ++j) 1547 for (j = 0; j < 8; ++j)
1501 if (inode_bits & (((ino_t)1) << (i * 8 + j))) 1548 if (inode_bits & (((eio_ino_t)1) << (i * 8 + j)))
1502 *bit++ = offs + j; 1549 *bit++ = offs + j;
1503 } 1550 }
1504 1551
1505 for (j = 0; j < 8; ++j) 1552 for (j = 0; j < 8; ++j)
1506 if (score_bits & (1 << j)) 1553 if (score_bits & (1 << j))
1507 *bit++ = offsetof (eio_dirent, score) * 8 + j; 1554 *bit++ = offsetof (eio_dirent, score) * 8 + j;
1508 } 1555 }
1509 1556
1510 /* now actually do the sorting (a variant of MSD radix sort) */ 1557 /* now actually do the sorting (a variant of MSD radix sort) */
1511 { 1558 {
1512 eio_dirent *base_stk [9 + sizeof (ino_t) * 8], *base; 1559 eio_dirent *base_stk [9 + sizeof (eio_ino_t) * 8], *base;
1513 eio_dirent *end_stk [9 + sizeof (ino_t) * 8], *end; 1560 eio_dirent *end_stk [9 + sizeof (eio_ino_t) * 8], *end;
1514 unsigned char *bit_stk [9 + sizeof (ino_t) * 8]; 1561 unsigned char *bit_stk [9 + sizeof (eio_ino_t) * 8];
1515 int stk_idx = 0; 1562 int stk_idx = 0;
1516 1563
1517 base_stk [stk_idx] = dents; 1564 base_stk [stk_idx] = dents;
1518 end_stk [stk_idx] = dents + size; 1565 end_stk [stk_idx] = dents + size;
1519 bit_stk [stk_idx] = bit - 1; 1566 bit_stk [stk_idx] = bit - 1;
1598 } 1645 }
1599 } 1646 }
1600} 1647}
1601 1648
1602static void 1649static void
1603eio_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)
1604{ 1651{
1605 if (size <= 1) 1652 if (size <= 1)
1606 return; /* our insertion sort relies on size > 0 */ 1653 return; /* our insertion sort relies on size > 0 */
1607 1654
1608 /* 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 */
1616 1663
1617/* read a full directory */ 1664/* read a full directory */
1618static void 1665static void
1619eio__scandir (eio_req *req, etp_worker *self) 1666eio__scandir (eio_req *req, etp_worker *self)
1620{ 1667{
1621 DIR *dirp;
1622 EIO_STRUCT_DIRENT *entp;
1623 char *name, *names; 1668 char *name, *names;
1624 int namesalloc = 4096; 1669 int namesalloc = 4096 - sizeof (void *) * 4;
1625 int namesoffs = 0; 1670 int namesoffs = 0;
1626 int flags = req->int1; 1671 int flags = req->int1;
1627 eio_dirent *dents = 0; 1672 eio_dirent *dents = 0;
1628 int dentalloc = 128; 1673 int dentalloc = 128;
1629 int dentoffs = 0; 1674 int dentoffs = 0;
1630 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
1631 1683
1632 req->result = -1; 1684 req->result = -1;
1633 1685
1634 if (!(flags & EIO_READDIR_DENTS)) 1686 if (!(flags & EIO_READDIR_DENTS))
1635 flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER); 1687 flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER);
1636 1688
1637 X_LOCK (wrklock); 1689#ifdef _WIN32
1638 /* 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
1639 self->dirp = dirp = opendir (req->ptr1); 1734 dirp = opendir (req->ptr1);
1735#endif
1640 1736
1641 if (req->flags & EIO_FLAG_PTR1_FREE) 1737 if (req->flags & EIO_FLAG_PTR1_FREE)
1642 free (req->ptr1); 1738 free (req->ptr1);
1643 1739
1644 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; 1740 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE;
1645 req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; 1741 req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0;
1646 req->ptr2 = names = malloc (namesalloc); 1742 req->ptr2 = names = malloc (namesalloc);
1647 X_UNLOCK (wrklock);
1648 1743
1649 if (dirp && names && (!flags || dents)) 1744 if (dirp && names && (!flags || dents))
1650 for (;;) 1745 for (;;)
1651 { 1746 {
1747 int done;
1748
1749#ifdef _WIN32
1750 done = !dirp;
1751#else
1652 errno = 0; 1752 errno = 0;
1653 entp = readdir (dirp); 1753 entp = readdir (dirp);
1754 done = !entp;
1755#endif
1654 1756
1655 if (!entp) 1757 if (done)
1656 { 1758 {
1759#ifndef _WIN32
1760 int old_errno = errno;
1761 closedir (dirp);
1762 errno = old_errno;
1763
1657 if (errno) 1764 if (errno)
1658 break; 1765 break;
1766#endif
1659 1767
1660 /* sort etc. */ 1768 /* sort etc. */
1661 req->int1 = flags; 1769 req->int1 = flags;
1662 req->result = dentoffs; 1770 req->result = dentoffs;
1663 1771
1692 1800
1693 break; 1801 break;
1694 } 1802 }
1695 1803
1696 /* now add the entry to our list(s) */ 1804 /* now add the entry to our list(s) */
1697 name = entp->d_name; 1805 name = D_NAME (entp);
1698 1806
1699 /* skip . and .. entries */ 1807 /* skip . and .. entries */
1700 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) 1808 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2])))
1701 { 1809 {
1702 int len = D_NAMLEN (entp) + 1; 1810 int len = D_NAMLEN (entp) + 1;
1703 1811
1704 while (ecb_expect_false (namesoffs + len > namesalloc)) 1812 while (ecb_expect_false (namesoffs + len > namesalloc))
1705 { 1813 {
1706 namesalloc *= 2; 1814 namesalloc *= 2;
1707 X_LOCK (wrklock);
1708 req->ptr2 = names = realloc (names, namesalloc); 1815 req->ptr2 = names = realloc (names, namesalloc);
1709 X_UNLOCK (wrklock);
1710 1816
1711 if (!names) 1817 if (!names)
1712 break; 1818 break;
1713 } 1819 }
1714 1820
1719 struct eio_dirent *ent; 1825 struct eio_dirent *ent;
1720 1826
1721 if (ecb_expect_false (dentoffs == dentalloc)) 1827 if (ecb_expect_false (dentoffs == dentalloc))
1722 { 1828 {
1723 dentalloc *= 2; 1829 dentalloc *= 2;
1724 X_LOCK (wrklock);
1725 req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent)); 1830 req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent));
1726 X_UNLOCK (wrklock);
1727 1831
1728 if (!dents) 1832 if (!dents)
1729 break; 1833 break;
1730 } 1834 }
1731 1835
1811 if (EIO_CANCELLED (req)) 1915 if (EIO_CANCELLED (req))
1812 { 1916 {
1813 errno = ECANCELED; 1917 errno = ECANCELED;
1814 break; 1918 break;
1815 } 1919 }
1920
1921#ifdef _WIN32
1922 if (!FindNextFile (dirp, &entp))
1923 {
1924 FindClose (dirp);
1925 dirp = 0;
1926 }
1927#endif
1816 } 1928 }
1817} 1929}
1818 1930
1819/*****************************************************************************/ 1931/*****************************************************************************/
1820 1932
1836X_THREAD_PROC (etp_proc) 1948X_THREAD_PROC (etp_proc)
1837{ 1949{
1838 ETP_REQ *req; 1950 ETP_REQ *req;
1839 struct timespec ts; 1951 struct timespec ts;
1840 etp_worker *self = (etp_worker *)thr_arg; 1952 etp_worker *self = (etp_worker *)thr_arg;
1841 int timeout; 1953
1954#if HAVE_PRCTL_SET_NAME
1955 prctl (PR_SET_NAME, (unsigned long)"eio_thread", 0, 0, 0);
1956#endif
1842 1957
1843 /* try to distribute timeouts somewhat evenly */ 1958 /* try to distribute timeouts somewhat evenly */
1844 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 1959 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
1845 1960
1846 for (;;) 1961 for (;;)
1916/*****************************************************************************/ 2031/*****************************************************************************/
1917 2032
1918int ecb_cold 2033int ecb_cold
1919eio_init (void (*want_poll)(void), void (*done_poll)(void)) 2034eio_init (void (*want_poll)(void), void (*done_poll)(void))
1920{ 2035{
2036#if !HAVE_PREADWRITE
2037 X_MUTEX_CREATE (preadwritelock);
2038#endif
2039
1921 return etp_init (want_poll, done_poll); 2040 return etp_init (want_poll, done_poll);
1922} 2041}
1923 2042
1924ecb_inline void 2043ecb_inline void
1925eio_api_destroy (eio_req *req) 2044eio_api_destroy (eio_req *req)
1970 case EIO_WRITE: req->result = req->offs >= 0 2089 case EIO_WRITE: req->result = req->offs >= 0
1971 ? pwrite (req->int1, req->ptr2, req->size, req->offs) 2090 ? pwrite (req->int1, req->ptr2, req->size, req->offs)
1972 : write (req->int1, req->ptr2, req->size); break; 2091 : write (req->int1, req->ptr2, req->size); break;
1973 2092
1974 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;
1975 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;
1976 2095
1977 case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); 2096 case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT));
1978 req->result = stat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; 2097 req->result = stat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break;
1979 case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); 2098 case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT));
1980 req->result = lstat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break; 2099 req->result = lstat (req->ptr1, (EIO_STRUCT_STAT *)req->ptr2); break;
2010 req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; 2129 req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break;
2011 2130
2012 case EIO_SYNC: req->result = 0; sync (); break; 2131 case EIO_SYNC: req->result = 0; sync (); break;
2013 case EIO_FSYNC: req->result = fsync (req->int1); break; 2132 case EIO_FSYNC: req->result = fsync (req->int1); break;
2014 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;
2015 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;
2016 case EIO_MTOUCH: req->result = eio__mtouch (req); break; 2137 case EIO_MTOUCH: req->result = eio__mtouch (req); break;
2017 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;
2018 case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; 2139 case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break;
2019 case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break;
2020 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;
2021 2141
2022 case EIO_READDIR: eio__scandir (req, self); break; 2142 case EIO_READDIR: eio__scandir (req, self); break;
2023 2143
2024 case EIO_BUSY: 2144 case EIO_BUSY:
2105eio_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)
2106{ 2226{
2107 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;
2108} 2228}
2109 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
2110eio_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)
2111{ 2246{
2112 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;
2113} 2248}
2114 2249
2120eio_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)
2121{ 2256{
2122 REQ (EIO_MLOCKALL); req->int1 = flags; SEND; 2257 REQ (EIO_MLOCKALL); req->int1 = flags; SEND;
2123} 2258}
2124 2259
2125eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data)
2126{
2127 REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND;
2128}
2129
2130eio_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)
2131{ 2261{
2132 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;
2133} 2263}
2134 2264
2135eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data)
2136{
2137 REQ (EIO_FDATASYNC); req->int1 = fd; SEND;
2138}
2139
2140eio_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)
2141{ 2266{
2142 REQ (EIO_CLOSE); req->int1 = fd; SEND; 2267 REQ (EIO_CLOSE); req->int1 = fd; SEND;
2143} 2268}
2144 2269
2180eio_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)
2181{ 2306{
2182 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; 2307 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND;
2183} 2308}
2184 2309
2185eio_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)
2186{ 2311{
2187 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;
2188} 2313}
2189 2314
2190eio_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)
2210eio_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)
2211{ 2336{
2212 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; 2337 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND;
2213} 2338}
2214 2339
2215eio_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)
2216{ 2341{
2217 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;
2218} 2343}
2219 2344
2220eio_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)
2367} 2492}
2368 2493
2369/*****************************************************************************/ 2494/*****************************************************************************/
2370/* misc garbage */ 2495/* misc garbage */
2371 2496
2372ssize_t 2497eio_ssize_t
2373eio_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)
2374{ 2499{
2375 etp_worker wrk;
2376 ssize_t ret;
2377
2378 wrk.dbuf = 0;
2379
2380 ret = eio__sendfile (ofd, ifd, offset, count, &wrk); 2500 return eio__sendfile (ofd, ifd, offset, count);
2381
2382 if (wrk.dbuf)
2383 free (wrk.dbuf);
2384
2385 return ret;
2386} 2501}
2387 2502

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines