|
16 | 16 |
|
17 | 17 | namespace slash {
|
18 | 18 |
|
| 19 | +int port_fdatasync(int fd) { |
| 20 | +#ifdef __APPLE__ |
| 21 | + return fcntl(fd, F_FULLFSYNC, 0); |
| 22 | +#else |
| 23 | + return fdatasync(fd); |
| 24 | +#endif |
| 25 | +} |
19 | 26 | /*
|
20 | 27 | * Set the resource limits of a process
|
21 | 28 | */
|
@@ -348,7 +355,11 @@ class PosixSequentialFile: public SequentialFile {
|
348 | 355 |
|
349 | 356 | virtual Status Read(size_t n, Slice* result, char* scratch) override {
|
350 | 357 | Status s;
|
| 358 | +#ifdef __APPLE__ |
| 359 | + size_t r = fread(scratch, 1, n, file_); |
| 360 | +#else |
351 | 361 | size_t r = fread_unlocked(scratch, 1, n, file_);
|
| 362 | +#endif |
352 | 363 |
|
353 | 364 | *result = Slice(scratch, r);
|
354 | 365 |
|
@@ -449,10 +460,12 @@ class PosixMmapFile : public WritableFile
|
449 | 460 |
|
450 | 461 | bool MapNewRegion() {
|
451 | 462 | assert(base_ == NULL);
|
| 463 | +#ifndef __APPLE__ |
452 | 464 | if (posix_fallocate(fd_, file_offset_, map_size_) != 0) {
|
453 | 465 | log_warn("ftruncate error");
|
454 | 466 | return false;
|
455 | 467 | }
|
| 468 | +#endif |
456 | 469 | //log_info("map_size %d fileoffset %llu", map_size_, file_offset_);
|
457 | 470 | void* ptr = mmap(NULL, map_size_, PROT_READ | PROT_WRITE, MAP_SHARED,
|
458 | 471 | fd_, file_offset_);
|
@@ -551,7 +564,7 @@ class PosixMmapFile : public WritableFile
|
551 | 564 | if (pending_sync_) {
|
552 | 565 | // Some unmapped data was not synced
|
553 | 566 | pending_sync_ = false;
|
554 |
| - if (fdatasync(fd_) < 0) { |
| 567 | + if (port_fdatasync(fd_) < 0) { |
555 | 568 | s = IOError(filename_, errno);
|
556 | 569 | }
|
557 | 570 | }
|
@@ -611,9 +624,11 @@ class MmapRWFile : public RWFile
|
611 | 624 | }
|
612 | 625 |
|
613 | 626 | bool DoMapRegion() {
|
| 627 | +#ifndef __APPLE__ |
614 | 628 | if (posix_fallocate(fd_, 0, map_size_) != 0) {
|
615 | 629 | return false;
|
616 | 630 | }
|
| 631 | +#endif |
617 | 632 | void* ptr = mmap(NULL, map_size_, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0);
|
618 | 633 | if (ptr == MAP_FAILED) {
|
619 | 634 | return false;
|
@@ -718,7 +733,7 @@ class PosixRandomRWFile : public RandomRWFile {
|
718 | 733 | }
|
719 | 734 |
|
720 | 735 | virtual Status Sync() override {
|
721 |
| - if (pending_sync_ && fdatasync(fd_) < 0) { |
| 736 | + if (pending_sync_ && port_fdatasync(fd_) < 0) { |
722 | 737 | return IOError(filename_, errno);
|
723 | 738 | }
|
724 | 739 | pending_sync_ = false;
|
|
0 commit comments