| 450 | } |
| 451 | |
| 452 | Status Open(const std::string& path, FileMode::type mode, const int64_t offset = 0, |
| 453 | const int64_t length = -1) { |
| 454 | file_ = std::make_unique<OSFile>(); |
| 455 | |
| 456 | if (mode != FileMode::READ) { |
| 457 | // Memory mapping has permission failures if PROT_READ not set |
| 458 | prot_flags_ = PROT_READ | PROT_WRITE; |
| 459 | map_mode_ = MAP_SHARED; |
| 460 | constexpr bool append = false; |
| 461 | constexpr bool truncate = false; |
| 462 | constexpr bool write_only = false; |
| 463 | RETURN_NOT_OK(file_->OpenWritable(path, truncate, append, write_only)); |
| 464 | } else { |
| 465 | prot_flags_ = PROT_READ; |
| 466 | map_mode_ = MAP_PRIVATE; // Changes are not to be committed back to the file |
| 467 | RETURN_NOT_OK(file_->OpenReadable(path)); |
| 468 | } |
| 469 | map_len_ = offset_ = 0; |
| 470 | |
| 471 | // Memory mapping fails when file size is 0 |
| 472 | // delay it until the first resize |
| 473 | if (file_->size() > 0) { |
| 474 | RETURN_NOT_OK(InitMMap(file_->size(), false, offset, length)); |
| 475 | } |
| 476 | |
| 477 | position_ = 0; |
| 478 | |
| 479 | return Status::OK(); |
| 480 | } |
| 481 | |
| 482 | // Resize the mmap and file to the specified size. |
| 483 | // Resize on memory mapped file region is not supported. |
nothing calls this directly
no test coverage detected