… | |
… | |
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 |
… | |
… | |
98 | |
97 | |
99 | #ifdef _WIN32 |
98 | #ifdef _WIN32 |
100 | |
99 | |
101 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
100 | #define PAGESIZE 4096 /* GetSystemInfo? */ |
102 | |
101 | |
|
|
102 | #ifdef EIO_STRUCT_STATI64 |
103 | #define stat(path,buf) _stati64 (path,buf) |
103 | #define stat(path,buf) _stati64 (path,buf) |
|
|
104 | #define fstat(fd,buf) _fstati64 (path,buf) |
|
|
105 | #endif |
104 | #define lstat(path,buf) stat (path,buf) |
106 | #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)) |
107 | #define fsync(fd) (FlushFileBuffers (EIO_FD_TO_WIN32_HANDLE (fd)) ? 0 : EIO_ERRNO (EBADF, -1)) |
107 | #define mkdir(path,mode) _mkdir (path) |
108 | #define mkdir(path,mode) _mkdir (path) |
108 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
109 | #define link(old,neu) (CreateHardLink (neu, old, 0) ? 0 : EIO_ERRNO (ENOENT, -1)) |
109 | |
110 | |
110 | #define chown(path,uid,gid) EIO_ENOSYS () |
111 | #define chown(path,uid,gid) EIO_ENOSYS () |
… | |
… | |
876 | # undef pread |
877 | # undef pread |
877 | # undef pwrite |
878 | # undef pwrite |
878 | # define pread eio__pread |
879 | # define pread eio__pread |
879 | # define pwrite eio__pwrite |
880 | # define pwrite eio__pwrite |
880 | |
881 | |
881 | static ssize_t |
882 | static eio_ssize_t |
882 | eio__pread (int fd, void *buf, size_t count, off_t offset) |
883 | eio__pread (int fd, void *buf, size_t count, off_t offset) |
883 | { |
884 | { |
884 | ssize_t res; |
885 | eio_ssize_t res; |
885 | off_t ooffset; |
886 | off_t ooffset; |
886 | |
887 | |
887 | X_LOCK (preadwritelock); |
888 | X_LOCK (preadwritelock); |
888 | ooffset = lseek (fd, 0, SEEK_CUR); |
889 | ooffset = lseek (fd, 0, SEEK_CUR); |
889 | lseek (fd, offset, SEEK_SET); |
890 | lseek (fd, offset, SEEK_SET); |
… | |
… | |
892 | X_UNLOCK (preadwritelock); |
893 | X_UNLOCK (preadwritelock); |
893 | |
894 | |
894 | return res; |
895 | return res; |
895 | } |
896 | } |
896 | |
897 | |
897 | static ssize_t |
898 | static eio_ssize_t |
898 | eio__pwrite (int fd, void *buf, size_t count, off_t offset) |
899 | eio__pwrite (int fd, void *buf, size_t count, off_t offset) |
899 | { |
900 | { |
900 | ssize_t res; |
901 | eio_ssize_t res; |
901 | off_t ooffset; |
902 | off_t ooffset; |
902 | |
903 | |
903 | X_LOCK (preadwritelock); |
904 | X_LOCK (preadwritelock); |
904 | ooffset = lseek (fd, 0, SEEK_CUR); |
905 | ooffset = lseek (fd, 0, SEEK_CUR); |
905 | lseek (fd, offset, SEEK_SET); |
906 | lseek (fd, offset, SEEK_SET); |
… | |
… | |
994 | |
995 | |
995 | #if !HAVE_READAHEAD |
996 | #if !HAVE_READAHEAD |
996 | # undef readahead |
997 | # undef readahead |
997 | # define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) |
998 | # define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) |
998 | |
999 | |
999 | static ssize_t |
1000 | static eio_ssize_t |
1000 | eio__readahead (int fd, off_t offset, size_t count, etp_worker *self) |
1001 | eio__readahead (int fd, off_t offset, size_t count, etp_worker *self) |
1001 | { |
1002 | { |
1002 | size_t todo = count; |
1003 | size_t todo = count; |
1003 | dBUF; |
1004 | dBUF; |
1004 | |
1005 | |
… | |
… | |
1016 | } |
1017 | } |
1017 | |
1018 | |
1018 | #endif |
1019 | #endif |
1019 | |
1020 | |
1020 | /* sendfile always needs emulation */ |
1021 | /* sendfile always needs emulation */ |
1021 | static ssize_t |
1022 | static eio_ssize_t |
1022 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) |
1023 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) |
1023 | { |
1024 | { |
1024 | ssize_t written = 0; |
1025 | eio_ssize_t written = 0; |
1025 | ssize_t res; |
1026 | eio_ssize_t res; |
1026 | |
1027 | |
1027 | if (!count) |
1028 | if (!count) |
1028 | return 0; |
1029 | return 0; |
1029 | |
1030 | |
1030 | for (;;) |
1031 | for (;;) |
… | |
… | |
1139 | |
1140 | |
1140 | res = 0; |
1141 | res = 0; |
1141 | |
1142 | |
1142 | while (count) |
1143 | while (count) |
1143 | { |
1144 | { |
1144 | ssize_t cnt; |
1145 | eio_ssize_t cnt; |
1145 | |
1146 | |
1146 | 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); |
1147 | |
1148 | |
1148 | if (cnt <= 0) |
1149 | if (cnt <= 0) |
1149 | { |
1150 | { |
… | |
… | |
1197 | /* round up length */ |
1198 | /* round up length */ |
1198 | *length = (*length + mask) & ~mask; |
1199 | *length = (*length + mask) & ~mask; |
1199 | } |
1200 | } |
1200 | |
1201 | |
1201 | #if !_POSIX_MEMLOCK |
1202 | #if !_POSIX_MEMLOCK |
1202 | # define eio__mlockall(a) eio_nosyscall() |
1203 | # define eio__mlockall(a) EIO_ENOSYS () |
1203 | #else |
1204 | #else |
1204 | |
1205 | |
1205 | static int |
1206 | static int |
1206 | eio__mlockall (int flags) |
1207 | eio__mlockall (int flags) |
1207 | { |
1208 | { |
… | |
… | |
1357 | res += strlen (res); |
1358 | res += strlen (res); |
1358 | } |
1359 | } |
1359 | |
1360 | |
1360 | while (*rel) |
1361 | while (*rel) |
1361 | { |
1362 | { |
1362 | ssize_t len, linklen; |
1363 | eio_ssize_t len, linklen; |
1363 | char *beg = rel; |
1364 | char *beg = rel; |
1364 | |
1365 | |
1365 | while (*rel && *rel != '/') |
1366 | while (*rel && *rel != '/') |
1366 | ++rel; |
1367 | ++rel; |
1367 | |
1368 | |
… | |
… | |
2178 | eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) |
2179 | eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) |
2179 | { |
2180 | { |
2180 | REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; |
2181 | REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; |
2181 | } |
2182 | } |
2182 | |
2183 | |
2183 | eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
2184 | eio_req *eio_fchown (int fd, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data) |
2184 | { |
2185 | { |
2185 | 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; |
2186 | } |
2187 | } |
2187 | |
2188 | |
2188 | eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) |
2189 | eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) |
… | |
… | |
2208 | eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) |
2209 | eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) |
2209 | { |
2210 | { |
2210 | REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; |
2211 | REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; |
2211 | } |
2212 | } |
2212 | |
2213 | |
2213 | eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) |
2214 | eio_req *eio_chown (const char *path, eio_uid_t uid, eio_gid_t gid, int pri, eio_cb cb, void *data) |
2214 | { |
2215 | { |
2215 | 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; |
2216 | } |
2217 | } |
2217 | |
2218 | |
2218 | eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
2219 | eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) |
… | |
… | |
2365 | } |
2366 | } |
2366 | |
2367 | |
2367 | /*****************************************************************************/ |
2368 | /*****************************************************************************/ |
2368 | /* misc garbage */ |
2369 | /* misc garbage */ |
2369 | |
2370 | |
2370 | ssize_t |
2371 | eio_ssize_t |
2371 | eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) |
2372 | eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) |
2372 | { |
2373 | { |
2373 | etp_worker wrk; |
2374 | etp_worker wrk; |
2374 | ssize_t ret; |
2375 | eio_ssize_t ret; |
2375 | |
2376 | |
2376 | wrk.dbuf = 0; |
2377 | wrk.dbuf = 0; |
2377 | |
2378 | |
2378 | ret = eio__sendfile (ofd, ifd, offset, count, &wrk); |
2379 | ret = eio__sendfile (ofd, ifd, offset, count, &wrk); |
2379 | |
2380 | |