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

Comparing libeio/eio.c (file contents):
Revision 1.110 by root, Tue Sep 27 12:36:19 2011 UTC vs.
Revision 1.126 by root, Fri Dec 28 07:33:41 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 *
10 * 1. Redistributions of source code must retain the above copyright notice, 10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer. 11 * this list of conditions and the following disclaimer.
12 * 12 *
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
16 * 16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
132 #define sync() EIO_ENOSYS () 132 #define sync() EIO_ENOSYS ()
133 #define readlink(path,buf,s) EIO_ENOSYS () 133 #define readlink(path,buf,s) EIO_ENOSYS ()
134 #define statvfs(path,buf) EIO_ENOSYS () 134 #define statvfs(path,buf) EIO_ENOSYS ()
135 #define fstatvfs(fd,buf) EIO_ENOSYS () 135 #define fstatvfs(fd,buf) EIO_ENOSYS ()
136 136
137 #define pread(fd,buf,count,offset) eio__pread (fd, buf, count, offset)
138 #define pwrite(fd,buf,count,offset) eio__pwrite (fd, buf, count, offset)
139
140 #if __GNUC__
141 typedef long long eio_off_t; /* signed for compatibility to msvc */
142 #else
143 typedef __int64 eio_off_t; /* unsigned not supported by msvc */
144 #endif
145
146 static eio_ssize_t
147 eio__pread (int fd, void *buf, eio_ssize_t count, eio_off_t offset)
148 {
149 OVERLAPPED o = { 0 };
150 DWORD got;
151
152 o.Offset = offset;
153 o.OffsetHigh = offset >> 32;
154
155 return ReadFile ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd), buf, count, &got, &o)
156 ? got : -1;
157 }
158
159 static eio_ssize_t
160 eio__pwrite (int fd, void *buf, eio_ssize_t count, eio_off_t offset)
161 {
162 OVERLAPPED o = { 0 };
163 DWORD got;
164
165 o.Offset = offset;
166 o.OffsetHigh = offset >> 32;
167
168 return WriteFile ((HANDLE)EIO_FD_TO_WIN32_HANDLE (fd), buf, count, &got, &o)
169 ? got : -1;
170 }
171
137 /* rename() uses MoveFile, which fails to overwrite */ 172 /* rename() uses MoveFile, which fails to overwrite */
138 #define rename(old,neu) eio__rename (old, neu) 173 #define rename(old,neu) eio__rename (old, neu)
139 174
140 static int 175 static int
141 eio__rename (const char *old, const char *neu) 176 eio__rename (const char *old, const char *neu)
208 #endif 243 #endif
209 244
210 #define D_NAME(entp) entp->d_name 245 #define D_NAME(entp) entp->d_name
211 246
212 /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ 247 /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */
213 #if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ 248 #if __FreeBSD__ || __NetBSD__ || __OpenBSD__
214 #define _DIRENT_HAVE_D_TYPE /* sigh */ 249 #define _DIRENT_HAVE_D_TYPE /* sigh */
215 #define D_INO(de) (de)->d_fileno 250 #define D_INO(de) (de)->d_fileno
216 #define D_NAMLEN(de) (de)->d_namlen 251 #define D_NAMLEN(de) (de)->d_namlen
217 #elif __linux || defined d_ino || _XOPEN_SOURCE >= 600 252 #elif __linux || defined d_ino || _XOPEN_SOURCE >= 600
218 #define D_INO(de) (de)->d_ino 253 #define D_INO(de) (de)->d_ino
281#endif 316#endif
282 317
283/* buffer size for various temporary buffers */ 318/* buffer size for various temporary buffers */
284#define EIO_BUFSIZE 65536 319#define EIO_BUFSIZE 65536
285 320
286#define dBUF \ 321#define dBUF \
287 char *eio_buf = malloc (EIO_BUFSIZE); \ 322 char *eio_buf = malloc (EIO_BUFSIZE); \
288 errno = ENOMEM; \ 323 errno = ENOMEM; \
289 if (!eio_buf) \ 324 if (!eio_buf) \
290 return -1 325 return -1
291 326
379static xmutex_t wrklock; 414static xmutex_t wrklock;
380static xmutex_t reslock; 415static xmutex_t reslock;
381static xmutex_t reqlock; 416static xmutex_t reqlock;
382static xcond_t reqwait; 417static xcond_t reqwait;
383 418
384#if !HAVE_PREADWRITE
385/*
386 * make our pread/pwrite emulation safe against themselves, but not against
387 * normal read/write by using a mutex. slows down execution a lot,
388 * but that's your problem, not mine.
389 */
390static xmutex_t preadwritelock;
391#endif
392
393typedef struct etp_worker 419typedef struct etp_worker
394{ 420{
395 struct tmpbuf tmpbuf; 421 struct tmpbuf tmpbuf;
396 422
397 /* locked by wrklock */ 423 /* locked by wrklock */
576 /*TODO*/ 602 /*TODO*/
577 assert (("unable to allocate worker thread data", wrk)); 603 assert (("unable to allocate worker thread data", wrk));
578 604
579 X_LOCK (wrklock); 605 X_LOCK (wrklock);
580 606
581 if (thread_create (&wrk->tid, etp_proc, (void *)wrk)) 607 if (xthread_create (&wrk->tid, etp_proc, (void *)wrk))
582 { 608 {
583 wrk->prev = &wrk_first; 609 wrk->prev = &wrk_first;
584 wrk->next = wrk_first.next; 610 wrk->next = wrk_first.next;
585 wrk_first.next->prev = wrk; 611 wrk_first.next->prev = wrk;
586 wrk_first.next = wrk; 612 wrk_first.next = wrk;
943} 969}
944 970
945/*****************************************************************************/ 971/*****************************************************************************/
946/* work around various missing functions */ 972/* work around various missing functions */
947 973
948#if !HAVE_PREADWRITE
949# undef pread
950# undef pwrite
951# define pread eio__pread
952# define pwrite eio__pwrite
953
954static eio_ssize_t
955eio__pread (int fd, void *buf, size_t count, off_t offset)
956{
957 eio_ssize_t res;
958 off_t ooffset;
959
960 X_LOCK (preadwritelock);
961 ooffset = lseek (fd, 0, SEEK_CUR);
962 lseek (fd, offset, SEEK_SET);
963 res = read (fd, buf, count);
964 lseek (fd, ooffset, SEEK_SET);
965 X_UNLOCK (preadwritelock);
966
967 return res;
968}
969
970static eio_ssize_t
971eio__pwrite (int fd, void *buf, size_t count, off_t offset)
972{
973 eio_ssize_t res;
974 off_t ooffset;
975
976 X_LOCK (preadwritelock);
977 ooffset = lseek (fd, 0, SEEK_CUR);
978 lseek (fd, offset, SEEK_SET);
979 res = write (fd, buf, count);
980 lseek (fd, ooffset, SEEK_SET);
981 X_UNLOCK (preadwritelock);
982
983 return res;
984}
985#endif
986
987#ifndef HAVE_UTIMES 974#ifndef HAVE_UTIMES
988 975
989# undef utimes 976# undef utimes
990# define utimes(path,times) eio__utimes (path, times) 977# define utimes(path,times) eio__utimes (path, times)
991 978
1032 int res; 1019 int res;
1033 1020
1034#if HAVE_SYS_SYNCFS 1021#if HAVE_SYS_SYNCFS
1035 res = (int)syscall (__NR_syncfs, (int)(fd)); 1022 res = (int)syscall (__NR_syncfs, (int)(fd));
1036#else 1023#else
1037 res = -1; 1024 res = EIO_ENOSYS ();
1038 errno = ENOSYS;
1039#endif 1025#endif
1040 1026
1041 if (res < 0 && errno == ENOSYS && fd >= 0) 1027 if (res < 0 && errno == ENOSYS && fd >= 0)
1042 sync (); 1028 sync ();
1043 1029
1073} 1059}
1074 1060
1075static int 1061static int
1076eio__fallocate (int fd, int mode, off_t offset, size_t len) 1062eio__fallocate (int fd, int mode, off_t offset, size_t len)
1077{ 1063{
1078#if HAVE_FALLOCATE 1064#if HAVE_LINUX_FALLOCATE
1079 return fallocate (fd, mode, offset, len); 1065 return fallocate (fd, mode, offset, len);
1080#else 1066#else
1081 errno = ENOSYS; 1067 return EIO_ENOSYS ();
1082 return -1;
1083#endif 1068#endif
1084} 1069}
1085 1070
1086#if !HAVE_READAHEAD 1071#if !HAVE_READAHEAD
1087# undef readahead 1072# undef readahead
1102 todo -= len; 1087 todo -= len;
1103 } 1088 }
1104 1089
1105 FUBd; 1090 FUBd;
1106 1091
1107 errno = 0; 1092 /* linux's readahead basically only fails for EBADF or EINVAL (not mmappable) */
1093 /* but not for e.g. EIO or eof, so we also never fail */
1108 return count; 1094 return 0;
1109} 1095}
1110 1096
1111#endif 1097#endif
1112 1098
1113/* sendfile always needs emulation */ 1099/* sendfile always needs emulation */
1148 1134
1149 /* according to source inspection, this is correct, and useful behaviour */ 1135 /* according to source inspection, this is correct, and useful behaviour */
1150 if (sbytes) 1136 if (sbytes)
1151 res = sbytes; 1137 res = sbytes;
1152 1138
1153# elif defined (__APPLE__) 1139# elif defined __APPLE__
1154 off_t sbytes = count; 1140 off_t sbytes = count;
1155 res = sendfile (ifd, ofd, offset, &sbytes, 0, 0); 1141 res = sendfile (ifd, ofd, offset, &sbytes, 0, 0);
1156 1142
1157 /* according to the manpage, sbytes is always valid */ 1143 /* according to the manpage, sbytes is always valid */
1158 if (sbytes) 1144 if (sbytes)
1185 HANDLE h = TO_SOCKET (ifd); 1171 HANDLE h = TO_SOCKET (ifd);
1186 SetFilePointer (h, offset, 0, FILE_BEGIN); 1172 SetFilePointer (h, offset, 0, FILE_BEGIN);
1187 res = TransmitFile (TO_SOCKET (ofd), h, count, 0, 0, 0, 0); 1173 res = TransmitFile (TO_SOCKET (ofd), h, count, 0, 0, 0, 0);
1188 1174
1189#else 1175#else
1190 res = -1; 1176 res = EIO_ENOSYS ();
1191 errno = ENOSYS;
1192#endif 1177#endif
1193 1178
1194 /* we assume sendfile can copy at least 128mb in one go */ 1179 /* we assume sendfile can copy at least 128mb in one go */
1195 if (res <= 128 * 1024 * 1024) 1180 if (res <= 128 * 1024 * 1024)
1196 { 1181 {
1382} 1367}
1383 1368
1384/*****************************************************************************/ 1369/*****************************************************************************/
1385/* requests implemented outside eio_execute, because they are so large */ 1370/* requests implemented outside eio_execute, because they are so large */
1386 1371
1372static void
1373eio__lseek (eio_req *req)
1374{
1375 /* this usually gets optimised away completely, or your compiler sucks, */
1376 /* or the whence constants really are not 0, 1, 2 */
1377 int whence = req->int2 == EIO_SEEK_SET ? SEEK_SET
1378 : req->int2 == EIO_SEEK_CUR ? SEEK_CUR
1379 : req->int2 == EIO_SEEK_END ? SEEK_END
1380 : req->int2;
1381
1382 req->offs = lseek (req->int1, req->offs, whence);
1383 req->result = req->offs == (off_t)-1 ? -1 : 0;
1384}
1385
1387/* result will always end up in tmpbuf, there is always space for adding a 0-byte */ 1386/* result will always end up in tmpbuf, there is always space for adding a 0-byte */
1388static int 1387static int
1389eio__realpath (struct tmpbuf *tmpbuf, eio_wd wd, const char *path) 1388eio__realpath (struct tmpbuf *tmpbuf, eio_wd wd, const char *path)
1390{ 1389{
1391 const char *rel = path; 1390 const char *rel = path;
1417 1416
1418 if (fd >= 0) 1417 if (fd >= 0)
1419 { 1418 {
1420 sprintf (tmp1, "/proc/self/fd/%d", fd); 1419 sprintf (tmp1, "/proc/self/fd/%d", fd);
1421 req->result = readlink (tmp1, res, PATH_MAX); 1420 req->result = readlink (tmp1, res, PATH_MAX);
1421 /* here we should probably stat the open file and the disk file, to make sure they still match */
1422 close (fd); 1422 close (fd);
1423
1424 /* here we should probably stat the open file and the disk file, to make sure they still match */
1425 1423
1426 if (req->result > 0) 1424 if (req->result > 0)
1427 goto done; 1425 goto done;
1428 } 1426 }
1429 else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO) 1427 else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO)
1430 return; 1428 return -1;
1431 } 1429 }
1432#endif 1430#endif
1433#endif 1431#endif
1434 1432
1435 if (*rel != '/') 1433 if (*rel != '/')
1487 } 1485 }
1488 } 1486 }
1489 1487
1490 errno = ENAMETOOLONG; 1488 errno = ENAMETOOLONG;
1491 if (res + 1 + len + 1 >= tmp1) 1489 if (res + 1 + len + 1 >= tmp1)
1492 return; 1490 return -1;
1493 1491
1494 /* copy one component */ 1492 /* copy one component */
1495 *res = '/'; 1493 *res = '/';
1496 memcpy (res + 1, beg, len); 1494 memcpy (res + 1, beg, len);
1497 1495
1919 #ifdef DT_FIFO 1917 #ifdef DT_FIFO
1920 case DT_FIFO: ent->type = EIO_DT_FIFO; break; 1918 case DT_FIFO: ent->type = EIO_DT_FIFO; break;
1921 #endif 1919 #endif
1922 #ifdef DT_CHR 1920 #ifdef DT_CHR
1923 case DT_CHR: ent->type = EIO_DT_CHR; break; 1921 case DT_CHR: ent->type = EIO_DT_CHR; break;
1924 #endif 1922 #endif
1925 #ifdef DT_MPC 1923 #ifdef DT_MPC
1926 case DT_MPC: ent->type = EIO_DT_MPC; break; 1924 case DT_MPC: ent->type = EIO_DT_MPC; break;
1927 #endif 1925 #endif
1928 #ifdef DT_DIR 1926 #ifdef DT_DIR
1929 case DT_DIR: ent->type = EIO_DT_DIR; break; 1927 case DT_DIR: ent->type = EIO_DT_DIR; break;
1930 #endif 1928 #endif
1931 #ifdef DT_NAM 1929 #ifdef DT_NAM
1932 case DT_NAM: ent->type = EIO_DT_NAM; break; 1930 case DT_NAM: ent->type = EIO_DT_NAM; break;
1933 #endif 1931 #endif
1934 #ifdef DT_BLK 1932 #ifdef DT_BLK
1935 case DT_BLK: ent->type = EIO_DT_BLK; break; 1933 case DT_BLK: ent->type = EIO_DT_BLK; break;
1936 #endif 1934 #endif
1937 #ifdef DT_MPB 1935 #ifdef DT_MPB
1938 case DT_MPB: ent->type = EIO_DT_MPB; break; 1936 case DT_MPB: ent->type = EIO_DT_MPB; break;
1939 #endif 1937 #endif
1940 #ifdef DT_REG 1938 #ifdef DT_REG
1941 case DT_REG: ent->type = EIO_DT_REG; break; 1939 case DT_REG: ent->type = EIO_DT_REG; break;
1942 #endif 1940 #endif
1943 #ifdef DT_NWK 1941 #ifdef DT_NWK
1944 case DT_NWK: ent->type = EIO_DT_NWK; break; 1942 case DT_NWK: ent->type = EIO_DT_NWK; break;
1945 #endif 1943 #endif
1946 #ifdef DT_CMP 1944 #ifdef DT_CMP
1947 case DT_CMP: ent->type = EIO_DT_CMP; break; 1945 case DT_CMP: ent->type = EIO_DT_CMP; break;
1948 #endif 1946 #endif
1949 #ifdef DT_LNK 1947 #ifdef DT_LNK
1950 case DT_LNK: ent->type = EIO_DT_LNK; break; 1948 case DT_LNK: ent->type = EIO_DT_LNK; break;
1951 #endif 1949 #endif
1952 #ifdef DT_SOCK 1950 #ifdef DT_SOCK
1953 case DT_SOCK: ent->type = EIO_DT_SOCK; break; 1951 case DT_SOCK: ent->type = EIO_DT_SOCK; break;
1966 { 1964 {
1967 if (ent->type == EIO_DT_UNKNOWN) 1965 if (ent->type == EIO_DT_UNKNOWN)
1968 { 1966 {
1969 if (*name == '.') /* leading dots are likely directories, and, in any case, rare */ 1967 if (*name == '.') /* leading dots are likely directories, and, in any case, rare */
1970 ent->score = 1; 1968 ent->score = 1;
1971 else if (!strchr (name, '.')) /* absense of dots indicate likely dirs */ 1969 else if (!strchr (name, '.')) /* absence of dots indicate likely dirs */
1972 ent->score = len <= 2 ? 4 - len : len <= 4 ? 4 : len <= 7 ? 5 : 6; /* shorter == more likely dir, but avoid too many classes */ 1970 ent->score = len <= 2 ? 4 - len : len <= 4 ? 4 : len <= 7 ? 5 : 6; /* shorter == more likely dir, but avoid too many classes */
1973 } 1971 }
1974 else if (ent->type == EIO_DT_DIR) 1972 else if (ent->type == EIO_DT_DIR)
1975 ent->score = 0; 1973 ent->score = 0;
1976 } 1974 }
2133 req->result = -1; \ 2131 req->result = -1; \
2134 break; \ 2132 break; \
2135 } \ 2133 } \
2136 } 2134 }
2137 2135
2136static void ecb_noinline ecb_cold
2137etp_proc_init (void)
2138{
2139#if HAVE_PRCTL_SET_NAME
2140 /* provide a more sensible "thread name" */
2141 char name[16 + 1];
2142 const int namelen = sizeof (name) - 1;
2143 int len;
2144
2145 prctl (PR_GET_NAME, (unsigned long)name, 0, 0, 0);
2146 name [namelen] = 0;
2147 len = strlen (name);
2148 strcpy (name + (len <= namelen - 4 ? len : namelen - 4), "/eio");
2149 prctl (PR_SET_NAME, (unsigned long)name, 0, 0, 0);
2150#endif
2151}
2152
2138X_THREAD_PROC (etp_proc) 2153X_THREAD_PROC (etp_proc)
2139{ 2154{
2140 ETP_REQ *req; 2155 ETP_REQ *req;
2141 struct timespec ts; 2156 struct timespec ts;
2142 etp_worker *self = (etp_worker *)thr_arg; 2157 etp_worker *self = (etp_worker *)thr_arg;
2143 2158
2144#if HAVE_PRCTL_SET_NAME 2159 etp_proc_init ();
2145 prctl (PR_SET_NAME, (unsigned long)"eio_thread", 0, 0, 0);
2146#endif
2147 2160
2148 /* try to distribute timeouts somewhat evenly */ 2161 /* try to distribute timeouts somewhat evenly */
2149 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); 2162 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
2150 2163
2151 for (;;) 2164 for (;;)
2222/*****************************************************************************/ 2235/*****************************************************************************/
2223 2236
2224int ecb_cold 2237int ecb_cold
2225eio_init (void (*want_poll)(void), void (*done_poll)(void)) 2238eio_init (void (*want_poll)(void), void (*done_poll)(void))
2226{ 2239{
2227#if !HAVE_PREADWRITE
2228 X_MUTEX_CREATE (preadwritelock);
2229#endif
2230
2231 return etp_init (want_poll, done_poll); 2240 return etp_init (want_poll, done_poll);
2232} 2241}
2233 2242
2234ecb_inline void 2243ecb_inline void
2235eio_api_destroy (eio_req *req) 2244eio_api_destroy (eio_req *req)
2236{ 2245{
2237 free (req); 2246 free (req);
2238} 2247}
2239 2248
2240#define REQ(rtype) \ 2249#define REQ(rtype) \
2241 eio_req *req; \ 2250 eio_req *req; \
2242 \ 2251 \
2243 req = (eio_req *)calloc (1, sizeof *req); \ 2252 req = (eio_req *)calloc (1, sizeof *req); \
2244 if (!req) \ 2253 if (!req) \
2245 return 0; \ 2254 return 0; \
2259 { \ 2268 { \
2260 eio_api_destroy (req); \ 2269 eio_api_destroy (req); \
2261 return 0; \ 2270 return 0; \
2262 } 2271 }
2263 2272
2273#define SINGLEDOT(ptr) (0[(char *)(ptr)] == '.' && !1[(char *)(ptr)])
2274
2264static void 2275static void
2265eio_execute (etp_worker *self, eio_req *req) 2276eio_execute (etp_worker *self, eio_req *req)
2266{ 2277{
2267#if HAVE_AT 2278#if HAVE_AT
2268 int dirfd; 2279 int dirfd;
2299 req->result = req->wd == EIO_INVALID_WD ? -1 : 0; 2310 req->result = req->wd == EIO_INVALID_WD ? -1 : 0;
2300 break; 2311 break;
2301 case EIO_WD_CLOSE: req->result = 0; 2312 case EIO_WD_CLOSE: req->result = 0;
2302 eio_wd_close_sync (req->wd); break; 2313 eio_wd_close_sync (req->wd); break;
2303 2314
2315 case EIO_SEEK: eio__lseek (req); break;
2304 case EIO_READ: ALLOC (req->size); 2316 case EIO_READ: ALLOC (req->size);
2305 req->result = req->offs >= 0 2317 req->result = req->offs >= 0
2306 ? pread (req->int1, req->ptr2, req->size, req->offs) 2318 ? pread (req->int1, req->ptr2, req->size, req->offs)
2307 : read (req->int1, req->ptr2, req->size); break; 2319 : read (req->int1, req->ptr2, req->size); break;
2308 case EIO_WRITE: req->result = req->offs >= 0 2320 case EIO_WRITE: req->result = req->offs >= 0
2322 case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break; 2334 case EIO_CHMOD: req->result = fchmodat (dirfd, req->ptr1, (mode_t)req->int2, 0); break;
2323 case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break; 2335 case EIO_TRUNCATE: req->result = eio__truncateat (dirfd, req->ptr1, req->offs); break;
2324 case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break; 2336 case EIO_OPEN: req->result = openat (dirfd, req->ptr1, req->int1, (mode_t)req->int2); break;
2325 2337
2326 case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break; 2338 case EIO_UNLINK: req->result = unlinkat (dirfd, req->ptr1, 0); break;
2327 case EIO_RMDIR: req->result = unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break; 2339 case EIO_RMDIR: /* complications arise because "." cannot be removed, so we might have to expand */
2340 req->result = req->wd && SINGLEDOT (req->ptr1)
2341 ? rmdir (req->wd->str)
2342 : unlinkat (dirfd, req->ptr1, AT_REMOVEDIR); break;
2328 case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break; 2343 case EIO_MKDIR: req->result = mkdirat (dirfd, req->ptr1, (mode_t)req->int2); break;
2329 case EIO_RENAME: req->result = renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break; 2344 case EIO_RENAME: /* complications arise because "." cannot be renamed, so we might have to expand */
2345 req->result = req->wd && SINGLEDOT (req->ptr1)
2346 ? rename (req->wd->str, req->ptr2)
2347 : renameat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2); break;
2330 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break; 2348 case EIO_LINK: req->result = linkat (dirfd, req->ptr1, WD2FD ((eio_wd)req->int3), req->ptr2, 0); break;
2331 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break; 2349 case EIO_SYMLINK: req->result = symlinkat (req->ptr1, dirfd, req->ptr2); break;
2332 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; 2350 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break;
2333 case EIO_READLINK: ALLOC (PATH_MAX); 2351 case EIO_READLINK: ALLOC (PATH_MAX);
2334 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break; 2352 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break;
2464 case EIO_CUSTOM: 2482 case EIO_CUSTOM:
2465 req->feed (req); 2483 req->feed (req);
2466 break; 2484 break;
2467 2485
2468 default: 2486 default:
2469 errno = ENOSYS;
2470 req->result = -1; 2487 req->result = EIO_ENOSYS ();
2471 break; 2488 break;
2472 } 2489 }
2473 2490
2474 req->errorno = errno; 2491 req->errorno = errno;
2475} 2492}
2552} 2569}
2553 2570
2554eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data) 2571eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data)
2555{ 2572{
2556 REQ (EIO_READAHEAD); req->int1 = fd; req->offs = offset; req->size = length; SEND; 2573 REQ (EIO_READAHEAD); req->int1 = fd; req->offs = offset; req->size = length; SEND;
2574}
2575
2576eio_req *eio_seek (int fd, off_t offset, int whence, int pri, eio_cb cb, void *data)
2577{
2578 REQ (EIO_SEEK); req->int1 = fd; req->offs = offset; req->int2 = whence; SEND;
2557} 2579}
2558 2580
2559eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) 2581eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data)
2560{ 2582{
2561 REQ (EIO_READ); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; 2583 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