MCPcopy Create free account
hub / github.com/ElementsProject/elements / NewRandomAccessFile

Method NewRandomAccessFile

src/leveldb/util/env_posix.cc:525–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

523 }
524
525 Status NewRandomAccessFile(const std::string& filename,
526 RandomAccessFile** result) override {
527 *result = nullptr;
528 int fd = ::open(filename.c_str(), O_RDONLY | kOpenBaseFlags);
529 if (fd < 0) {
530 return PosixError(filename, errno);
531 }
532
533 if (!mmap_limiter_.Acquire()) {
534 *result = new PosixRandomAccessFile(filename, fd, &fd_limiter_);
535 return Status::OK();
536 }
537
538 uint64_t file_size;
539 Status status = GetFileSize(filename, &file_size);
540 if (status.ok()) {
541 void* mmap_base =
542 ::mmap(/*addr=*/nullptr, file_size, PROT_READ, MAP_SHARED, fd, 0);
543 if (mmap_base != MAP_FAILED) {
544 *result = new PosixMmapReadableFile(filename,
545 reinterpret_cast<char*>(mmap_base),
546 file_size, &mmap_limiter_);
547 } else {
548 status = PosixError(filename, errno);
549 }
550 }
551 ::close(fd);
552 if (!status.ok()) {
553 mmap_limiter_.Release();
554 }
555 return status;
556 }
557
558 Status NewWritableFile(const std::string& filename,
559 WritableFile** result) override {

Callers 3

TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45

Calls 5

PosixErrorFunction · 0.85
OKFunction · 0.85
GetFileSizeFunction · 0.50
AcquireMethod · 0.45
ReleaseMethod · 0.45

Tested by 3

TESTFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36