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 | * |
… | |
… | |
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 | || errno == ENOTSUP || errno == EOPNOTSUPP /* BSDs */ |
975 | #if __solaris |
976 | #if __solaris |
976 | || errno == EAFNOSUPPORT || errno == EPROTOTYPE |
977 | || errno == EAFNOSUPPORT || errno == EPROTOTYPE |
977 | #endif |
978 | #endif |
978 | || errno == ENOTSUP || errno == EOPNOTSUPP |
|
|
979 | ) |
979 | ) |
980 | ) |
980 | ) |
981 | { |
981 | { |
982 | /* emulate sendfile. this is a major pain in the ass */ |
982 | /* emulate sendfile. this is a major pain in the ass */ |
983 | dBUF; |
983 | dBUF; |
… | |
… | |
1374 | } |
1374 | } |
1375 | } |
1375 | } |
1376 | } |
1376 | } |
1377 | |
1377 | |
1378 | #if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) |
1378 | #if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO) |
1379 | # undef msync |
|
|
1380 | # define msync(a,b,c) ((errno = ENOSYS), -1) |
1379 | # define eio__msync(a,b,c) ((errno = ENOSYS), -1) |
|
|
1380 | #else |
|
|
1381 | |
|
|
1382 | int |
|
|
1383 | eio__msync (void *mem, size_t len, int flags) |
|
|
1384 | { |
|
|
1385 | if (EIO_MS_ASYNC != MS_SYNC |
|
|
1386 | || EIO_MS_INVALIDATE != MS_INVALIDATE |
|
|
1387 | || EIO_MS_SYNC != MS_SYNC) |
|
|
1388 | { |
|
|
1389 | flags = 0 |
|
|
1390 | | (flags & EIO_MS_ASYNC ? MS_ASYNC : 0) |
|
|
1391 | | (flags & EIO_MS_INVALIDATE ? MS_INVALIDATE : 0) |
|
|
1392 | | (flags & EIO_MS_SYNC ? MS_SYNC : 0); |
|
|
1393 | } |
|
|
1394 | |
|
|
1395 | return msync (mem, len, flags); |
|
|
1396 | } |
|
|
1397 | |
1381 | #endif |
1398 | #endif |
1382 | |
1399 | |
1383 | int |
1400 | int |
1384 | eio__mtouch (void *mem, size_t len, int flags) |
1401 | eio__mtouch (void *mem, size_t len, int flags) |
1385 | { |
1402 | { |
… | |
… | |
1396 | |
1413 | |
1397 | /* round down to start of page, although this is probably useless */ |
1414 | /* round down to start of page, although this is probably useless */ |
1398 | addr &= ~(page - 1); /* assume page size is always a power of two */ |
1415 | addr &= ~(page - 1); /* assume page size is always a power of two */ |
1399 | |
1416 | |
1400 | if (addr < end) |
1417 | if (addr < end) |
1401 | if (flags) /* modify */ |
1418 | if (flags & EIO_MT_MODIFY) /* modify */ |
1402 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len); |
1419 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len); |
1403 | else |
1420 | else |
1404 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len); |
1421 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len); |
1405 | |
1422 | |
1406 | return 0; |
1423 | return 0; |
… | |
… | |
1578 | req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; |
1595 | req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; |
1579 | |
1596 | |
1580 | case EIO_SYNC: req->result = 0; sync (); break; |
1597 | case EIO_SYNC: req->result = 0; sync (); break; |
1581 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
1598 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
1582 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
1599 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
1583 | case EIO_MSYNC: req->result = msync (req->ptr2, req->size, req->int1); break; |
1600 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
1584 | case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break; |
1601 | case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break; |
1585 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
1602 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
1586 | |
1603 | |
1587 | case EIO_READDIR: eio__scandir (req, self); break; |
1604 | case EIO_READDIR: eio__scandir (req, self); break; |
1588 | |
1605 | |