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.90 by root, Sat Jul 16 16:46:10 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
73 75
74static void eio_destroy (eio_req *req); 76static void eio_destroy (eio_req *req);
75 77
76#ifndef EIO_FINISH 78#ifndef EIO_FINISH
77# define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 79# define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0
96 98
97#define EIO_ENOSYS() EIO_ERRNO (ENOSYS, -1) 99#define EIO_ENOSYS() EIO_ERRNO (ENOSYS, -1)
98 100
99#ifdef _WIN32 101#ifdef _WIN32
100 102
103 #undef PAGESIZE
101 #define PAGESIZE 4096 /* GetSystemInfo? */ 104 #define PAGESIZE 4096 /* GetSystemInfo? */
102 105
106 #ifdef EIO_STRUCT_STATI64
103 #define stat(path,buf) _stati64 (path,buf) 107 #define stat(path,buf) _stati64 (path,buf)
108 #define fstat(fd,buf) _fstati64 (path,buf)
109 #endif
104 #define lstat(path,buf) stat (path,buf) 110 #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)) 111 #define fsync(fd) (FlushFileBuffers ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1))
107 #define mkdir(path,mode) _mkdir (path) 112 #define mkdir(path,mode) _mkdir (path)
108 #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) 113 #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1))
109 114
115 #define chmod(path,mode) _chmod (path, mode)
116 #define fchmod(fd,mode) EIO_ENOSYS ()
110 #define chown(path,uid,gid) EIO_ENOSYS () 117 #define chown(path,uid,gid) EIO_ENOSYS ()
111 #define fchown(fd,uid,gid) EIO_ENOSYS () 118 #define fchown(fd,uid,gid) EIO_ENOSYS ()
112 #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */ 119 #define truncate(path,offs) EIO_ENOSYS () /* far-miss: SetEndOfFile */
113 #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */ 120 #define ftruncate(fd,offs) EIO_ENOSYS () /* near-miss: SetEndOfFile */
114 #define mknod(path,mode,dev) EIO_ENOSYS () 121 #define mknod(path,mode,dev) EIO_ENOSYS ()
115 #define sync() EIO_ENOSYS () 122 #define sync() EIO_ENOSYS ()
123 #define readlink(path,buf,s) EIO_ENOSYS ()
124 #define statvfs(path,buf) EIO_ENOSYS ()
125 #define fstatvfs(fd,buf) EIO_ENOSYS ()
116 126
117 /* we could even stat and see if it exists */ 127 /* we could even stat and see if it exists */
118 static int 128 static int
119 symlink (const char *old, const char *neu) 129 symlink (const char *old, const char *neu)
120 { 130 {
131 #if WINVER >= 0x0600
121 if (CreateSymbolicLink (neu, old, 1)) 132 if (CreateSymbolicLink (neu, old, 1))
122 return 0; 133 return 0;
123 134
124 if (CreateSymbolicLink (neu, old, 0)) 135 if (CreateSymbolicLink (neu, old, 0))
125 return 0; 136 return 0;
137 #endif
126 138
127 return EIO_ERRNO (ENOENT, -1); 139 return EIO_ERRNO (ENOENT, -1);
128 } 140 }
141
142 /* POSIX API only */
143 #define CreateHardLink(neu,old) 0
144 #define CreateSymbolicLink(neu,old,flags) 0
145
146 struct statvfs
147 {
148 int dummy;
149 };
129 150
130#else 151#else
131 152
132 #include <sys/time.h> 153 #include <sys/time.h>
133 #include <sys/select.h> 154 #include <sys/select.h>
876# undef pread 897# undef pread
877# undef pwrite 898# undef pwrite
878# define pread eio__pread 899# define pread eio__pread
879# define pwrite eio__pwrite 900# define pwrite eio__pwrite
880 901
881static ssize_t 902static eio_ssize_t
882eio__pread (int fd, void *buf, size_t count, off_t offset) 903eio__pread (int fd, void *buf, size_t count, off_t offset)
883{ 904{
884 ssize_t res; 905 eio_ssize_t res;
885 off_t ooffset; 906 off_t ooffset;
886 907
887 X_LOCK (preadwritelock); 908 X_LOCK (preadwritelock);
888 ooffset = lseek (fd, 0, SEEK_CUR); 909 ooffset = lseek (fd, 0, SEEK_CUR);
889 lseek (fd, offset, SEEK_SET); 910 lseek (fd, offset, SEEK_SET);
892 X_UNLOCK (preadwritelock); 913 X_UNLOCK (preadwritelock);
893 914
894 return res; 915 return res;
895} 916}
896 917
897static ssize_t 918static eio_ssize_t
898eio__pwrite (int fd, void *buf, size_t count, off_t offset) 919eio__pwrite (int fd, void *buf, size_t count, off_t offset)
899{ 920{
900 ssize_t res; 921 eio_ssize_t res;
901 off_t ooffset; 922 off_t ooffset;
902 923
903 X_LOCK (preadwritelock); 924 X_LOCK (preadwritelock);
904 ooffset = lseek (fd, 0, SEEK_CUR); 925 ooffset = lseek (fd, 0, SEEK_CUR);
905 lseek (fd, offset, SEEK_SET); 926 lseek (fd, offset, SEEK_SET);
994 1015
995#if !HAVE_READAHEAD 1016#if !HAVE_READAHEAD
996# undef readahead 1017# undef readahead
997# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) 1018# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self)
998 1019
999static ssize_t 1020static eio_ssize_t
1000eio__readahead (int fd, off_t offset, size_t count, etp_worker *self) 1021eio__readahead (int fd, off_t offset, size_t count, etp_worker *self)
1001{ 1022{
1002 size_t todo = count; 1023 size_t todo = count;
1003 dBUF; 1024 dBUF;
1004 1025
1016} 1037}
1017 1038
1018#endif 1039#endif
1019 1040
1020/* sendfile always needs emulation */ 1041/* sendfile always needs emulation */
1021static ssize_t 1042static eio_ssize_t
1022eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) 1043eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self)
1023{ 1044{
1024 ssize_t written = 0; 1045 eio_ssize_t written = 0;
1025 ssize_t res; 1046 eio_ssize_t res;
1026 1047
1027 if (!count) 1048 if (!count)
1028 return 0; 1049 return 0;
1029 1050
1030 for (;;) 1051 for (;;)
1125 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK 1146 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK
1126 /* BSDs */ 1147 /* BSDs */
1127#ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */ 1148#ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */
1128 || errno == ENOTSUP 1149 || errno == ENOTSUP
1129#endif 1150#endif
1151#ifdef EOPNOTSUPP /* windows */
1130 || errno == EOPNOTSUPP /* BSDs */ 1152 || errno == EOPNOTSUPP /* BSDs */
1153#endif
1131#if __solaris 1154#if __solaris
1132 || errno == EAFNOSUPPORT || errno == EPROTOTYPE 1155 || errno == EAFNOSUPPORT || errno == EPROTOTYPE
1133#endif 1156#endif
1134 ) 1157 )
1135 ) 1158 )
1139 1162
1140 res = 0; 1163 res = 0;
1141 1164
1142 while (count) 1165 while (count)
1143 { 1166 {
1144 ssize_t cnt; 1167 eio_ssize_t cnt;
1145 1168
1146 cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset); 1169 cnt = pread (ifd, eio_buf, count > EIO_BUFSIZE ? EIO_BUFSIZE : count, offset);
1147 1170
1148 if (cnt <= 0) 1171 if (cnt <= 0)
1149 { 1172 {
1197 /* round up length */ 1220 /* round up length */
1198 *length = (*length + mask) & ~mask; 1221 *length = (*length + mask) & ~mask;
1199} 1222}
1200 1223
1201#if !_POSIX_MEMLOCK 1224#if !_POSIX_MEMLOCK
1202# define eio__mlockall(a) eio_nosyscall() 1225# define eio__mlockall(a) EIO_ENOSYS ()
1203#else 1226#else
1204 1227
1205static int 1228static int
1206eio__mlockall (int flags) 1229eio__mlockall (int flags)
1207{ 1230{
1357 res += strlen (res); 1380 res += strlen (res);
1358 } 1381 }
1359 1382
1360 while (*rel) 1383 while (*rel)
1361 { 1384 {
1362 ssize_t len, linklen; 1385 eio_ssize_t len, linklen;
1363 char *beg = rel; 1386 char *beg = rel;
1364 1387
1365 while (*rel && *rel != '/') 1388 while (*rel && *rel != '/')
1366 ++rel; 1389 ++rel;
1367 1390
2178eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) 2201eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data)
2179{ 2202{
2180 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; 2203 REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND;
2181} 2204}
2182 2205
2183eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) 2206eio_req *eio_fchown (int fd, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data)
2184{ 2207{
2185 REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; 2208 REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND;
2186} 2209}
2187 2210
2188eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) 2211eio_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) 2231eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data)
2209{ 2232{
2210 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; 2233 REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND;
2211} 2234}
2212 2235
2213eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) 2236eio_req *eio_chown (const char *path, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data)
2214{ 2237{
2215 REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; 2238 REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND;
2216} 2239}
2217 2240
2218eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) 2241eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data)
2365} 2388}
2366 2389
2367/*****************************************************************************/ 2390/*****************************************************************************/
2368/* misc garbage */ 2391/* misc garbage */
2369 2392
2370ssize_t 2393eio_ssize_t
2371eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) 2394eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count)
2372{ 2395{
2373 etp_worker wrk; 2396 etp_worker wrk;
2374 ssize_t ret; 2397 eio_ssize_t ret;
2375 2398
2376 wrk.dbuf = 0; 2399 wrk.dbuf = 0;
2377 2400
2378 ret = eio__sendfile (ofd, ifd, offset, count, &wrk); 2401 ret = eio__sendfile (ofd, ifd, offset, count, &wrk);
2379 2402

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines