… | |
… | |
35 | * and other provisions required by the GPL. If you do not delete the |
35 | * and other provisions required by the GPL. If you do not delete the |
36 | * provisions above, a recipient may use your version of this file under |
36 | * provisions above, a recipient may use your version of this file under |
37 | * either the BSD or the GPL. |
37 | * either the BSD or the GPL. |
38 | */ |
38 | */ |
39 | |
39 | |
|
|
40 | #ifndef _WIN32 |
|
|
41 | # include "config.h" |
|
|
42 | #endif |
|
|
43 | |
40 | #include "eio.h" |
44 | #include "eio.h" |
41 | |
45 | |
42 | #ifdef EIO_STACKSIZE |
46 | #ifdef EIO_STACKSIZE |
43 | # define XTHREAD_STACKSIZE EIO_STACKSIZE |
47 | # define XTHREAD_STACKSIZE EIO_STACKSIZE |
44 | #endif |
48 | #endif |
… | |
… | |
54 | #include <sys/statvfs.h> |
58 | #include <sys/statvfs.h> |
55 | #include <limits.h> |
59 | #include <limits.h> |
56 | #include <fcntl.h> |
60 | #include <fcntl.h> |
57 | #include <assert.h> |
61 | #include <assert.h> |
58 | |
62 | |
|
|
63 | /* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ |
|
|
64 | /* intptr_t only comes form stdint.h, says idiot openbsd coder */ |
|
|
65 | #if HAVE_STDINT_H |
|
|
66 | # include <stdint.h> |
|
|
67 | #endif |
|
|
68 | |
59 | #ifndef EIO_FINISH |
69 | #ifndef EIO_FINISH |
60 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
70 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
61 | #endif |
71 | #endif |
62 | |
72 | |
63 | #ifndef EIO_DESTROY |
73 | #ifndef EIO_DESTROY |
… | |
… | |
71 | #ifdef _WIN32 |
81 | #ifdef _WIN32 |
72 | |
82 | |
73 | /*doh*/ |
83 | /*doh*/ |
74 | #else |
84 | #else |
75 | |
85 | |
76 | # include "config.h" |
|
|
77 | # include <sys/time.h> |
86 | # include <sys/time.h> |
78 | # include <sys/select.h> |
87 | # include <sys/select.h> |
79 | # include <unistd.h> |
88 | # include <unistd.h> |
80 | # include <utime.h> |
89 | # include <utime.h> |
81 | # include <signal.h> |
90 | # include <signal.h> |
… | |
… | |
1279 | eio_dirent *oth = dents + dentoffs; |
1288 | eio_dirent *oth = dents + dentoffs; |
1280 | eio_dirent *dir = dents; |
1289 | eio_dirent *dir = dents; |
1281 | |
1290 | |
1282 | /* now partition dirs to the front, and non-dirs to the back */ |
1291 | /* now partition dirs to the front, and non-dirs to the back */ |
1283 | /* by walking from both sides and swapping if necessary */ |
1292 | /* by walking from both sides and swapping if necessary */ |
1284 | /* also clear score, so it doesn't influence sorting */ |
|
|
1285 | while (oth > dir) |
1293 | while (oth > dir) |
1286 | { |
1294 | { |
1287 | if (dir->type == EIO_DT_DIR) |
1295 | if (dir->type == EIO_DT_DIR) |
1288 | ++dir; |
1296 | ++dir; |
1289 | else if ((--oth)->type == EIO_DT_DIR) |
1297 | else if ((--oth)->type == EIO_DT_DIR) |
… | |
… | |
1292 | |
1300 | |
1293 | ++dir; |
1301 | ++dir; |
1294 | } |
1302 | } |
1295 | } |
1303 | } |
1296 | |
1304 | |
1297 | /* now sort the dirs only */ |
1305 | /* now sort the dirs only (dirs all have the same score) */ |
1298 | eio_dent_sort (dents, dir - dents, 0, inode_bits); |
1306 | eio_dent_sort (dents, dir - dents, 0, inode_bits); |
1299 | } |
1307 | } |
1300 | |
1308 | |
1301 | break; |
1309 | break; |
1302 | } |
1310 | } |
… | |
… | |
1515 | } |
1523 | } |
1516 | |
1524 | |
1517 | #endif |
1525 | #endif |
1518 | |
1526 | |
1519 | int |
1527 | int |
1520 | eio__mtouch (void *mem, size_t len, int flags) |
1528 | eio__mtouch (eio_req *req) |
1521 | { |
1529 | { |
|
|
1530 | void *mem = req->ptr2; |
|
|
1531 | size_t len = req->size; |
|
|
1532 | int flags = req->int1; |
|
|
1533 | |
1522 | eio_page_align (&mem, &len); |
1534 | eio_page_align (&mem, &len); |
1523 | |
1535 | |
1524 | { |
1536 | { |
1525 | intptr_t addr = (intptr_t)mem; |
1537 | intptr_t addr = (intptr_t)mem; |
1526 | intptr_t end = addr + len; |
1538 | intptr_t end = addr + len; |
1527 | intptr_t page = eio_pagesize (); |
1539 | intptr_t page = eio_pagesize (); |
1528 | |
1540 | |
1529 | if (addr < end) |
1541 | if (addr < end) |
1530 | if (flags & EIO_MT_MODIFY) /* modify */ |
1542 | if (flags & EIO_MT_MODIFY) /* modify */ |
1531 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len); |
1543 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
1532 | else |
1544 | else |
1533 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len); |
1545 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
1534 | } |
1546 | } |
1535 | |
1547 | |
1536 | return 0; |
1548 | return 0; |
1537 | } |
1549 | } |
1538 | |
1550 | |
… | |
… | |
1712 | |
1724 | |
1713 | case EIO_SYNC: req->result = 0; sync (); break; |
1725 | case EIO_SYNC: req->result = 0; sync (); break; |
1714 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
1726 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
1715 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
1727 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
1716 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
1728 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
1717 | case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break; |
1729 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
1718 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
1730 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
1719 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
1731 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
1720 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
1732 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
1721 | |
1733 | |
1722 | case EIO_READDIR: eio__scandir (req, self); break; |
1734 | case EIO_READDIR: eio__scandir (req, self); break; |