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

Comparing libeio/eio.c (file contents):
Revision 1.115 by root, Tue Mar 27 18:54:45 2012 UTC vs.
Revision 1.120 by root, Tue Apr 24 18:47:50 2012 UTC

1/* 1/*
2 * libeio implementation 2 * libeio implementation
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libeio@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann <libeio@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
208 #endif 208 #endif
209 209
210 #define D_NAME(entp) entp->d_name 210 #define D_NAME(entp) entp->d_name
211 211
212 /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ 212 /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */
213 #if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ 213 #if __FreeBSD__ || __NetBSD__ || __OpenBSD__
214 #define _DIRENT_HAVE_D_TYPE /* sigh */ 214 #define _DIRENT_HAVE_D_TYPE /* sigh */
215 #define D_INO(de) (de)->d_fileno 215 #define D_INO(de) (de)->d_fileno
216 #define D_NAMLEN(de) (de)->d_namlen 216 #define D_NAMLEN(de) (de)->d_namlen
217 #elif __linux || defined d_ino || _XOPEN_SOURCE >= 600 217 #elif __linux || defined d_ino || _XOPEN_SOURCE >= 600
218 #define D_INO(de) (de)->d_ino 218 #define D_INO(de) (de)->d_ino
1032 int res; 1032 int res;
1033 1033
1034#if HAVE_SYS_SYNCFS 1034#if HAVE_SYS_SYNCFS
1035 res = (int)syscall (__NR_syncfs, (int)(fd)); 1035 res = (int)syscall (__NR_syncfs, (int)(fd));
1036#else 1036#else
1037 res = -1; 1037 res = EIO_ENOSYS ();
1038 errno = ENOSYS;
1039#endif 1038#endif
1040 1039
1041 if (res < 0 && errno == ENOSYS && fd >= 0) 1040 if (res < 0 && errno == ENOSYS && fd >= 0)
1042 sync (); 1041 sync ();
1043 1042
1073} 1072}
1074 1073
1075static int 1074static int
1076eio__fallocate (int fd, int mode, off_t offset, size_t len) 1075eio__fallocate (int fd, int mode, off_t offset, size_t len)
1077{ 1076{
1078#if HAVE_FALLOCATE 1077#if HAVE_LINUX_FALLOCATE
1079 return fallocate (fd, mode, offset, len); 1078 return fallocate (fd, mode, offset, len);
1080#else 1079#else
1081 errno = ENOSYS; 1080 return EIO_ENOSYS ();
1082 return -1;
1083#endif 1081#endif
1084} 1082}
1085 1083
1086#if !HAVE_READAHEAD 1084#if !HAVE_READAHEAD
1087# undef readahead 1085# undef readahead
1094 dBUF; 1092 dBUF;
1095 1093
1096 while (todo > 0) 1094 while (todo > 0)
1097 { 1095 {
1098 size_t len = todo < EIO_BUFSIZE ? todo : EIO_BUFSIZE; 1096 size_t len = todo < EIO_BUFSIZE ? todo : EIO_BUFSIZE;
1097
1098 pread (fd, eio_buf, len, offset);
1099 offset += len; 1099 offset += len;
1100 todo -= len; 1100 todo -= len;
1101 } 1101 }
1102 1102
1103 FUBd; 1103 FUBd;
1147 1147
1148 /* according to source inspection, this is correct, and useful behaviour */ 1148 /* according to source inspection, this is correct, and useful behaviour */
1149 if (sbytes) 1149 if (sbytes)
1150 res = sbytes; 1150 res = sbytes;
1151 1151
1152# elif defined (__APPLE__) 1152# elif defined __APPLE__
1153 off_t sbytes = count; 1153 off_t sbytes = count;
1154 res = sendfile (ifd, ofd, offset, &sbytes, 0, 0); 1154 res = sendfile (ifd, ofd, offset, &sbytes, 0, 0);
1155 1155
1156 /* according to the manpage, sbytes is always valid */ 1156 /* according to the manpage, sbytes is always valid */
1157 if (sbytes) 1157 if (sbytes)
1184 HANDLE h = TO_SOCKET (ifd); 1184 HANDLE h = TO_SOCKET (ifd);
1185 SetFilePointer (h, offset, 0, FILE_BEGIN); 1185 SetFilePointer (h, offset, 0, FILE_BEGIN);
1186 res = TransmitFile (TO_SOCKET (ofd), h, count, 0, 0, 0, 0); 1186 res = TransmitFile (TO_SOCKET (ofd), h, count, 0, 0, 0, 0);
1187 1187
1188#else 1188#else
1189 res = -1; 1189 res = EIO_ENOSYS ();
1190 errno = ENOSYS;
1191#endif 1190#endif
1192 1191
1193 /* we assume sendfile can copy at least 128mb in one go */ 1192 /* we assume sendfile can copy at least 128mb in one go */
1194 if (res <= 128 * 1024 * 1024) 1193 if (res <= 128 * 1024 * 1024)
1195 { 1194 {
1380 return 0; 1379 return 0;
1381} 1380}
1382 1381
1383/*****************************************************************************/ 1382/*****************************************************************************/
1384/* requests implemented outside eio_execute, because they are so large */ 1383/* requests implemented outside eio_execute, because they are so large */
1384
1385static void
1386eio__lseek (eio_req *req)
1387{
1388 /* this usually gets optimised away completely, or your compiler sucks, */
1389 /* or the whence constants really are not 0, 1, 2 */
1390 int whence = req->int2 == EIO_SEEK_SET ? SEEK_SET
1391 : req->int2 == EIO_SEEK_CUR ? SEEK_CUR
1392 : req->int2 == EIO_SEEK_END ? SEEK_END
1393 : req->int2;
1394
1395 req->offs = lseek (req->int1, req->offs, whence);
1396 req->result = req->offs == (off_t)-1 ? -1 : 0;
1397}
1385 1398
1386/* result will always end up in tmpbuf, there is always space for adding a 0-byte */ 1399/* result will always end up in tmpbuf, there is always space for adding a 0-byte */
1387static int 1400static int
1388eio__realpath (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) 1401eio__realpath (struct tmpbuf *tmpbuf, eio_wd wd, const char *path)
1389{ 1402{
2227 free (req); 2240 free (req);
2228 2241
2229 X_LOCK (wrklock); 2242 X_LOCK (wrklock);
2230 etp_worker_free (self); 2243 etp_worker_free (self);
2231 X_UNLOCK (wrklock); 2244 X_UNLOCK (wrklock);
2232
2233 return 0;
2234} 2245}
2235 2246
2236/*****************************************************************************/ 2247/*****************************************************************************/
2237 2248
2238int ecb_cold 2249int ecb_cold
2313 req->result = req->wd == EIO_INVALID_WD ? -1 : 0; 2324 req->result = req->wd == EIO_INVALID_WD ? -1 : 0;
2314 break; 2325 break;
2315 case EIO_WD_CLOSE: req->result = 0; 2326 case EIO_WD_CLOSE: req->result = 0;
2316 eio_wd_close_sync (req->wd); break; 2327 eio_wd_close_sync (req->wd); break;
2317 2328
2329 case EIO_SEEK: eio__lseek (req); break;
2318 case EIO_READ: ALLOC (req->size); 2330 case EIO_READ: ALLOC (req->size);
2319 req->result = req->offs >= 0 2331 req->result = req->offs >= 0
2320 ? pread (req->int1, req->ptr2, req->size, req->offs) 2332 ? pread (req->int1, req->ptr2, req->size, req->offs)
2321 : read (req->int1, req->ptr2, req->size); break; 2333 : read (req->int1, req->ptr2, req->size); break;
2322 case EIO_WRITE: req->result = req->offs >= 0 2334 case EIO_WRITE: req->result = req->offs >= 0
2478 case EIO_CUSTOM: 2490 case EIO_CUSTOM:
2479 req->feed (req); 2491 req->feed (req);
2480 break; 2492 break;
2481 2493
2482 default: 2494 default:
2483 errno = ENOSYS;
2484 req->result = -1; 2495 req->result = EIO_ENOSYS ();
2485 break; 2496 break;
2486 } 2497 }
2487 2498
2488 req->errorno = errno; 2499 req->errorno = errno;
2489} 2500}
2566} 2577}
2567 2578
2568eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data) 2579eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data)
2569{ 2580{
2570 REQ (EIO_READAHEAD); req->int1 = fd; req->offs = offset; req->size = length; SEND; 2581 REQ (EIO_READAHEAD); req->int1 = fd; req->offs = offset; req->size = length; SEND;
2582}
2583
2584eio_req *eio_seek (int fd, off_t offset, int whence, int pri, eio_cb cb, void *data)
2585{
2586 REQ (EIO_SEEK); req->int1 = fd; req->offs = offset; req->int2 = whence; SEND;
2571} 2587}
2572 2588
2573eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) 2589eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data)
2574{ 2590{
2575 REQ (EIO_READ); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; 2591 REQ (EIO_READ); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines