Resize the mmap and file to the specified size. Resize on memory mapped file region is not supported.
| 474 | // Resize the mmap and file to the specified size. |
| 475 | // Resize on memory mapped file region is not supported. |
| 476 | Status Resize(const int64_t new_size) { |
| 477 | if (!writable()) { |
| 478 | return Status::IOError("Cannot resize a readonly memory map"); |
| 479 | } |
| 480 | if (map_len_ != file_size_) { |
| 481 | return Status::IOError("Cannot resize a partial memory map"); |
| 482 | } |
| 483 | if (region_.use_count() > 1) { |
| 484 | // There are buffer exports currently, the MemoryMapRemap() call |
| 485 | // would make the buffers invalid |
| 486 | return Status::IOError("Cannot resize memory map while there are active readers"); |
| 487 | } |
| 488 | |
| 489 | if (new_size == 0) { |
| 490 | if (map_len_ > 0) { |
| 491 | // Just unmap the mmap and truncate the file to 0 size |
| 492 | region_.reset(); |
| 493 | RETURN_NOT_OK(::arrow::internal::FileTruncate(file_->fd(), 0)); |
| 494 | map_len_ = offset_ = file_size_ = 0; |
| 495 | } |
| 496 | position_ = 0; |
| 497 | return Status::OK(); |
| 498 | } |
| 499 | |
| 500 | if (map_len_ > 0) { |
| 501 | void* result; |
| 502 | auto data = region_->data(); |
| 503 | RETURN_NOT_OK(::arrow::internal::MemoryMapRemap(data, map_len_, new_size, |
| 504 | file_->fd(), &result)); |
| 505 | region_->Detach(); // avoid munmap() on destruction |
| 506 | region_ = std::make_shared<Region>(shared_from_this(), |
| 507 | static_cast<uint8_t*>(result), new_size); |
| 508 | map_len_ = file_size_ = new_size; |
| 509 | offset_ = 0; |
| 510 | if (position_ > map_len_) { |
| 511 | position_ = map_len_; |
| 512 | } |
| 513 | } else { |
| 514 | DCHECK_EQ(position_, 0); |
| 515 | // the mmap is not yet initialized, resize the underlying |
| 516 | // file, since it might have been 0-sized |
| 517 | RETURN_NOT_OK(InitMMap(new_size, /*resize_file*/ true)); |
| 518 | } |
| 519 | return Status::OK(); |
| 520 | } |
| 521 | |
| 522 | Status Seek(int64_t position) { |
| 523 | if (position < 0) { |
nothing calls this directly
no test coverage detected