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.89 by root, Thu Jul 14 22:36:17 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
878# undef pread 877# undef pread
879# undef pwrite 878# undef pwrite
880# define pread eio__pread 879# define pread eio__pread
881# define pwrite eio__pwrite 880# define pwrite eio__pwrite
882 881
883static ssize_t 882static eio_ssize_t
884eio__pread (int fd, void *buf, size_t count, off_t offset) 883eio__pread (int fd, void *buf, size_t count, off_t offset)
885{ 884{
886 ssize_t res; 885 eio_ssize_t res;
887 off_t ooffset; 886 off_t ooffset;
888 887
889 X_LOCK (preadwritelock); 888 X_LOCK (preadwritelock);
890 ooffset = lseek (fd, 0, SEEK_CUR); 889 ooffset = lseek (fd, 0, SEEK_CUR);
891 lseek (fd, offset, SEEK_SET); 890 lseek (fd, offset, SEEK_SET);
894 X_UNLOCK (preadwritelock); 893 X_UNLOCK (preadwritelock);
895 894
896 return res; 895 return res;
897} 896}
898 897
899static ssize_t 898static eio_ssize_t
900eio__pwrite (int fd, void *buf, size_t count, off_t offset) 899eio__pwrite (int fd, void *buf, size_t count, off_t offset)
901{ 900{
902 ssize_t res; 901 eio_ssize_t res;
903 off_t ooffset; 902 off_t ooffset;
904 903
905 X_LOCK (preadwritelock); 904 X_LOCK (preadwritelock);
906 ooffset = lseek (fd, 0, SEEK_CUR); 905 ooffset = lseek (fd, 0, SEEK_CUR);
907 lseek (fd, offset, SEEK_SET); 906 lseek (fd, offset, SEEK_SET);
996 995
997#if !HAVE_READAHEAD 996#if !HAVE_READAHEAD
998# undef readahead 997# undef readahead
999# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) 998# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self)
1000 999
1001static ssize_t 1000static eio_ssize_t
1002eio__readahead (int fd, off_t offset, size_t count, etp_worker *self) 1001eio__readahead (int fd, off_t offset, size_t count, etp_worker *self)
1003{ 1002{
1004 size_t todo = count; 1003 size_t todo = count;
1005 dBUF; 1004 dBUF;
1006 1005
1018} 1017}
1019 1018
1020#endif 1019#endif
1021 1020
1022/* sendfile always needs emulation */ 1021/* sendfile always needs emulation */
1023static ssize_t 1022static eio_ssize_t
1024eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) 1023eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self)
1025{ 1024{
1026 ssize_t written = 0; 1025 eio_ssize_t written = 0;
1027 ssize_t res; 1026 eio_ssize_t res;
1028 1027
1029 if (!count) 1028 if (!count)
1030 return 0; 1029 return 0;
1031 1030
1032 for (;;) 1031 for (;;)
1141 1140
1142 res = 0; 1141 res = 0;
1143 1142
1144 while (count) 1143 while (count)
1145 { 1144 {
1146 ssize_t cnt; 1145 eio_ssize_t cnt;
1147 1146
1148 cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset); 1147 cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset);
1149 1148
1150 if (cnt <= 0) 1149 if (cnt <= 0)
1151 { 1150 {
1199 /* round up length */ 1198 /* round up length */
1200 *length = (*length + mask) & ~mask; 1199 *length = (*length + mask) & ~mask;
1201} 1200}
1202 1201
1203#if !_POSIX_MEMLOCK 1202#if !_POSIX_MEMLOCK
1204# define eio__mlockall(a) eio_nosyscall() 1203# define eio__mlockall(a) EIO_ENOSYS ()
1205#else 1204#else
1206 1205
1207static int 1206static int
1208eio__mlockall (int flags) 1207eio__mlockall (int flags)
1209{ 1208{
1359 res += strlen (res); 1358 res += strlen (res);
1360 } 1359 }
1361 1360
1362 while (*rel) 1361 while (*rel)
1363 { 1362 {
1364 ssize_t len, linklen; 1363 eio_ssize_t len, linklen;
1365 char *beg = rel; 1364 char *beg = rel;
1366 1365
1367 while (*rel && *rel != '/') 1366 while (*rel && *rel != '/')
1368 ++rel; 1367 ++rel;
1369 1368
2180eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) 2179eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data)
2181{ 2180{
2182 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; 2181 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND;
2183} 2182}
2184 2183
2185eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) 2184eio_req *eio_fchown (int fd, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data)
2186{ 2185{
2187 REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; 2186 REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND;
2188} 2187}
2189 2188
2190eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) 2189eio_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) 2209eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data)
2211{ 2210{
2212 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; 2211 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND;
2213} 2212}
2214 2213
2215eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) 2214eio_req *eio_chown (const char *path, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data)
2216{ 2215{
2217 REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; 2216 REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND;
2218} 2217}
2219 2218
2220eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) 2219eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data)
2367} 2366}
2368 2367
2369/*****************************************************************************/ 2368/*****************************************************************************/
2370/* misc garbage */ 2369/* misc garbage */
2371 2370
2372ssize_t 2371eio_ssize_t
2373eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) 2372eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count)
2374{ 2373{
2375 etp_worker wrk; 2374 etp_worker wrk;
2376 ssize_t ret; 2375 eio_ssize_t ret;
2377 2376
2378 wrk.dbuf = 0; 2377 wrk.dbuf = 0;
2379 2378
2380 ret = eio__sendfile (ofd, ifd, offset, count, &wrk); 2379 ret = eio__sendfile (ofd, ifd, offset, count, &wrk);
2381 2380

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines