1 | /* |
1 | /* |
2 | * libeio implementation |
2 | * libeio implementation |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann <libeio@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010 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 | * |
… | |
… | |
113 | # include <sys/uio.h> |
113 | # include <sys/uio.h> |
114 | # elif __hpux |
114 | # elif __hpux |
115 | # include <sys/socket.h> |
115 | # include <sys/socket.h> |
116 | # elif __solaris |
116 | # elif __solaris |
117 | # include <sys/sendfile.h> |
117 | # include <sys/sendfile.h> |
118 | # elif defined _WIN32 |
|
|
119 | # else |
118 | # else |
120 | # error sendfile support requested but not available |
119 | # error sendfile support requested but not available |
121 | # endif |
120 | # endif |
122 | #endif |
121 | #endif |
123 | |
122 | |
… | |
… | |
924 | if (res < 0 && sbytes) |
923 | if (res < 0 && sbytes) |
925 | /* maybe only on EAGAIN: as usual, the manpage leaves you guessing */ |
924 | /* maybe only on EAGAIN: as usual, the manpage leaves you guessing */ |
926 | res = sbytes; |
925 | res = sbytes; |
927 | } |
926 | } |
928 | |
927 | |
929 | # elif defined __APPLE__ |
928 | # elif defined (__APPLE__) |
930 | |
929 | |
931 | { |
930 | { |
932 | off_t bytes = count; |
931 | off_t sbytes = count; |
933 | res = sendfile (ifd, ofd, offset, &bytes, 0, 0); |
932 | res = sendfile (ifd, ofd, offset, &sbytes, 0, 0); |
934 | |
933 | |
935 | if (res < 0 && errno == EAGAIN && bytes) |
934 | if (res < 0 && errno == EAGAIN && sbytes) |
936 | res = sbytes; |
935 | res = sbytes; |
937 | } |
936 | } |
938 | |
937 | |
939 | # elif __hpux |
938 | # elif __hpux |
940 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
939 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
… | |
… | |
954 | if (res < 0 && sbytes) |
953 | if (res < 0 && sbytes) |
955 | res = sbytes; |
954 | res = sbytes; |
956 | } |
955 | } |
957 | |
956 | |
958 | # endif |
957 | # endif |
|
|
958 | |
959 | #elif defined _WIN32 |
959 | #elif defined (_WIN32) |
960 | |
960 | |
961 | /* does not work, just for documentation of what would need to be done */ |
961 | /* does not work, just for documentation of what would need to be done */ |
962 | { |
962 | { |
963 | HANDLE h = TO_SOCKET (ifd); |
963 | HANDLE h = TO_SOCKET (ifd); |
964 | SetFilePointer (h, offset, 0, FILE_BEGIN); |
964 | SetFilePointer (h, offset, 0, FILE_BEGIN); |
… | |
… | |
970 | errno = ENOSYS; |
970 | errno = ENOSYS; |
971 | #endif |
971 | #endif |
972 | |
972 | |
973 | if (res < 0 |
973 | if (res < 0 |
974 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
974 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
|
|
975 | /* BSDs */ |
|
|
976 | #ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */ |
|
|
977 | || errno == ENOTSUP |
|
|
978 | #endif |
|
|
979 | || errno == EOPNOTSUPP /* BSDs */ |
975 | #if __solaris |
980 | #if __solaris |
976 | || errno == EAFNOSUPPORT || errno == EPROTOTYPE |
981 | || errno == EAFNOSUPPORT || errno == EPROTOTYPE |
977 | #endif |
982 | #endif |
978 | ) |
983 | ) |
979 | ) |
984 | ) |
… | |
… | |
1373 | } |
1378 | } |
1374 | } |
1379 | } |
1375 | } |
1380 | } |
1376 | |
1381 | |
1377 | #if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) |
1382 | #if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) |
1378 | # undef msync |
|
|
1379 | # define msync(a,b,c) ((errno = ENOSYS), -1) |
1383 | # define eio__msync(a,b,c) ((errno = ENOSYS), -1) |
|
|
1384 | #else |
|
|
1385 | |
|
|
1386 | int |
|
|
1387 | eio__msync (void *mem, size_t len, int flags) |
|
|
1388 | { |
|
|
1389 | if (EIO_MS_ASYNC != MS_SYNC |
|
|
1390 | || EIO_MS_INVALIDATE != MS_INVALIDATE |
|
|
1391 | || EIO_MS_SYNC != MS_SYNC) |
|
|
1392 | { |
|
|
1393 | flags = 0 |
|
|
1394 | | (flags & EIO_MS_ASYNC ? MS_ASYNC : 0) |
|
|
1395 | | (flags & EIO_MS_INVALIDATE ? MS_INVALIDATE : 0) |
|
|
1396 | | (flags & EIO_MS_SYNC ? MS_SYNC : 0); |
|
|
1397 | } |
|
|
1398 | |
|
|
1399 | return msync (mem, len, flags); |
|
|
1400 | } |
|
|
1401 | |
1380 | #endif |
1402 | #endif |
1381 | |
1403 | |
1382 | int |
1404 | int |
1383 | eio__mtouch (void *mem, size_t len, int flags) |
1405 | eio__mtouch (void *mem, size_t len, int flags) |
1384 | { |
1406 | { |
… | |
… | |
1395 | |
1417 | |
1396 | /* round down to start of page, although this is probably useless */ |
1418 | /* round down to start of page, although this is probably useless */ |
1397 | addr &= ~(page - 1); /* assume page size is always a power of two */ |
1419 | addr &= ~(page - 1); /* assume page size is always a power of two */ |
1398 | |
1420 | |
1399 | if (addr < end) |
1421 | if (addr < end) |
1400 | if (flags) /* modify */ |
1422 | if (flags & EIO_MT_MODIFY) /* modify */ |
1401 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len); |
1423 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len); |
1402 | else |
1424 | else |
1403 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len); |
1425 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len); |
1404 | |
1426 | |
1405 | return 0; |
1427 | return 0; |
… | |
… | |
1577 | req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; |
1599 | req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; |
1578 | |
1600 | |
1579 | case EIO_SYNC: req->result = 0; sync (); break; |
1601 | case EIO_SYNC: req->result = 0; sync (); break; |
1580 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
1602 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
1581 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
1603 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
1582 | case EIO_MSYNC: req->result = msync (req->ptr2, req->size, req->int1); break; |
1604 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
1583 | case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break; |
1605 | case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break; |
1584 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
1606 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
1585 | |
1607 | |
1586 | case EIO_READDIR: eio__scandir (req, self); break; |
1608 | case EIO_READDIR: eio__scandir (req, self); break; |
1587 | |
1609 | |