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

Comparing libeio/eio.c (file contents):
Revision 1.105 by root, Mon Sep 26 18:23:18 2011 UTC vs.
Revision 1.106 by root, Mon Sep 26 20:19:08 2011 UTC

57#include <sys/types.h> 57#include <sys/types.h>
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
63#if _POSIX_VERSION >= 200809L
64# define HAVE_AT 1
65#else
66# define HAVE_AT 0
67#endif
62 68
63/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ 69/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */
64/* intptr_t only comes from stdint.h, says idiot openbsd coder */ 70/* intptr_t only comes from stdint.h, says idiot openbsd coder */
65#if HAVE_STDINT_H 71#if HAVE_STDINT_H
66# include <stdint.h> 72# include <stdint.h>
2270 switch (req->type) 2276 switch (req->type)
2271 { 2277 {
2272 case EIO_WD_OPEN: req->wd = eio__wd_open_sync (&self->tmpbuf, req->wd, req->ptr1); 2278 case EIO_WD_OPEN: req->wd = eio__wd_open_sync (&self->tmpbuf, req->wd, req->ptr1);
2273 req->result = req->wd == EIO_INVALID_WD ? -1 : 0; 2279 req->result = req->wd == EIO_INVALID_WD ? -1 : 0;
2274 break; 2280 break;
2275 case EIO_WD_CLOSE: eio_wd_close_sync (req->wd); break; 2281 case EIO_WD_CLOSE: req->result = 0;
2282 eio_wd_close_sync (req->wd); break;
2276 2283
2277 case EIO_READ: ALLOC (req->size); 2284 case EIO_READ: ALLOC (req->size);
2278 req->result = req->offs >= 0 2285 req->result = req->offs >= 0
2279 ? pread (req->int1, req->ptr2, req->size, req->offs) 2286 ? pread (req->int1, req->ptr2, req->size, req->offs)
2280 : read (req->int1, req->ptr2, req->size); break; 2287 : read (req->int1, req->ptr2, req->size); break;
2284 2291
2285 case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break; 2292 case EIO_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break;
2286 case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break; 2293 case EIO_SENDFILE: req->result = eio__sendfile (req->int1, req->int2, req->offs, req->size); break;
2287 2294
2288#if HAVE_AT 2295#if HAVE_AT
2296
2289 case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); 2297 case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT));
2290 req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, 0); break; 2298 req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, 0); break;
2291 case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); 2299 case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT));
2292 req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break; 2300 req->result = fstatat (dirfd, req->ptr1, (EIO_STRUCT_STAT *)req->ptr2, AT_SYMLINK_NOFOLLOW); break;
2293 case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break; 2301 case EIO_CHOWN: req->result = fchownat (dirfd, req->ptr1, req->int2, req->int3, 0); break;
2304 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; 2312 case EIO_MKNOD: req->result = mknodat (dirfd, req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break;
2305 case EIO_READLINK: ALLOC (PATH_MAX); 2313 case EIO_READLINK: ALLOC (PATH_MAX);
2306 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break; 2314 req->result = readlinkat (dirfd, req->ptr1, req->ptr2, PATH_MAX); break;
2307 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 2315 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
2308 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; 2316 req->result = eio__statvfsat (dirfd, req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break;
2317 case EIO_UTIME:
2318 case EIO_FUTIME:
2319 {
2320 struct timespec ts[2];
2321 struct timespec *times;
2322
2323 if (req->nv1 != -1. || req->nv2 != -1.)
2324 {
2325 ts[0].tv_sec = req->nv1;
2326 ts[0].tv_nsec = (req->nv1 - ts[0].tv_sec) * 1e9;
2327 ts[1].tv_sec = req->nv2;
2328 ts[1].tv_nsec = (req->nv2 - ts[1].tv_sec) * 1e9;
2329
2330 times = ts;
2331 }
2332 else
2333 times = 0;
2334
2335 req->result = req->type == EIO_FUTIME
2336 ? futimens (req->int1, times)
2337 : utimensat (dirfd, req->ptr1, times, 0);
2338 }
2339 break;
2340
2309#else 2341#else
2342
2310 case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT)); 2343 case EIO_STAT: ALLOC (sizeof (EIO_STRUCT_STAT));
2311 req->result = stat (path , (EIO_STRUCT_STAT *)req->ptr2); break; 2344 req->result = stat (path , (EIO_STRUCT_STAT *)req->ptr2); break;
2312 case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); 2345 case EIO_LSTAT: ALLOC (sizeof (EIO_STRUCT_STAT));
2313 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break; 2346 req->result = lstat (path , (EIO_STRUCT_STAT *)req->ptr2); break;
2314 case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break; 2347 case EIO_CHOWN: req->result = chown (path , req->int2, req->int3); break;
2325 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break; 2358 case EIO_MKNOD: req->result = mknod (path , (mode_t)req->int2, (dev_t)req->offs); break;
2326 case EIO_READLINK: ALLOC (PATH_MAX); 2359 case EIO_READLINK: ALLOC (PATH_MAX);
2327 req->result = readlink (path, req->ptr2, PATH_MAX); break; 2360 req->result = readlink (path, req->ptr2, PATH_MAX); break;
2328 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); 2361 case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS));
2329 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break; 2362 req->result = statvfs (path , (EIO_STRUCT_STATVFS *)req->ptr2); break;
2363
2364 case EIO_UTIME:
2365 case EIO_FUTIME:
2366 {
2367 struct timeval tv[2];
2368 struct timeval *times;
2369
2370 if (req->nv1 != -1. || req->nv2 != -1.)
2371 {
2372 tv[0].tv_sec = req->nv1;
2373 tv[0].tv_usec = (req->nv1 - tv[0].tv_sec) * 1e6;
2374 tv[1].tv_sec = req->nv2;
2375 tv[1].tv_usec = (req->nv2 - tv[1].tv_sec) * 1e6;
2376
2377 times = tv;
2378 }
2379 else
2380 times = 0;
2381
2382 req->result = req->type == EIO_FUTIME
2383 ? futimes (req->int1, times)
2384 : utimes (req->ptr1, times);
2385 }
2386 break;
2387
2330#endif 2388#endif
2331 2389
2332 case EIO_REALPATH: if (0 <= (req->result = eio__realpath (&self->tmpbuf, req->wd, req->ptr1))) 2390 case EIO_REALPATH: if (0 <= (req->result = eio__realpath (&self->tmpbuf, req->wd, req->ptr1)))
2333 { 2391 {
2334 ALLOC (req->result); 2392 ALLOC (req->result);
2374 req->result = select (0, 0, 0, 0, &tv); 2432 req->result = select (0, 0, 0, 0, &tv);
2375 } 2433 }
2376#endif 2434#endif
2377 break; 2435 break;
2378 2436
2379 case EIO_UTIME:
2380 case EIO_FUTIME:
2381 {
2382 struct timeval tv[2];
2383 struct timeval *times;
2384
2385 if (req->nv1 != -1. || req->nv2 != -1.)
2386 {
2387 tv[0].tv_sec = req->nv1;
2388 tv[0].tv_usec = (req->nv1 - tv[0].tv_sec) * 1000000.;
2389 tv[1].tv_sec = req->nv2;
2390 tv[1].tv_usec = (req->nv2 - tv[1].tv_sec) * 1000000.;
2391
2392 times = tv;
2393 }
2394 else
2395 times = 0;
2396
2397 req->result = req->type == EIO_FUTIME
2398 ? futimes (req->int1, times)
2399 : utimes (req->ptr1, times);
2400 }
2401 break;
2402
2403 case EIO_GROUP: 2437 case EIO_GROUP:
2404 abort (); /* handled in eio_request */ 2438 abort (); /* handled in eio_request */
2405 2439
2406 case EIO_NOP: 2440 case EIO_NOP:
2407 req->result = 0; 2441 req->result = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines