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