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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines