Changeset View
Changeset View
Standalone View
Standalone View
src/leveldb/util/env_posix.cc
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
virtual Status Skip(uint64_t n) { | virtual Status Skip(uint64_t n) { | ||||
if (fseek(file_, n, SEEK_CUR)) { | if (fseek(file_, n, SEEK_CUR)) { | ||||
return IOError(filename_, errno); | return IOError(filename_, errno); | ||||
} | } | ||||
return Status::OK(); | return Status::OK(); | ||||
} | } | ||||
virtual std::string GetName() const { return filename_; } | |||||
}; | }; | ||||
// pread() based random-access | // pread() based random-access | ||||
class PosixRandomAccessFile: public RandomAccessFile { | class PosixRandomAccessFile: public RandomAccessFile { | ||||
private: | private: | ||||
std::string filename_; | std::string filename_; | ||||
bool temporary_fd_; // If true, fd_ is -1 and we open on every read. | bool temporary_fd_; // If true, fd_ is -1 and we open on every read. | ||||
int fd_; | int fd_; | ||||
Show All 35 Lines | if (r < 0) { | ||||
s = IOError(filename_, errno); | s = IOError(filename_, errno); | ||||
} | } | ||||
if (temporary_fd_) { | if (temporary_fd_) { | ||||
// Close the temporary file descriptor opened earlier. | // Close the temporary file descriptor opened earlier. | ||||
close(fd); | close(fd); | ||||
} | } | ||||
return s; | return s; | ||||
} | } | ||||
virtual std::string GetName() const { return filename_; } | |||||
}; | }; | ||||
// mmap() based random-access | // mmap() based random-access | ||||
class PosixMmapReadableFile: public RandomAccessFile { | class PosixMmapReadableFile: public RandomAccessFile { | ||||
private: | private: | ||||
std::string filename_; | std::string filename_; | ||||
void* mmapped_region_; | void* mmapped_region_; | ||||
size_t length_; | size_t length_; | ||||
Show All 18 Lines | virtual Status Read(uint64_t offset, size_t n, Slice* result, | ||||
if (offset + n > length_) { | if (offset + n > length_) { | ||||
*result = Slice(); | *result = Slice(); | ||||
s = IOError(filename_, EINVAL); | s = IOError(filename_, EINVAL); | ||||
} else { | } else { | ||||
*result = Slice(reinterpret_cast<char*>(mmapped_region_) + offset, n); | *result = Slice(reinterpret_cast<char*>(mmapped_region_) + offset, n); | ||||
} | } | ||||
return s; | return s; | ||||
} | } | ||||
virtual std::string GetName() const { return filename_; } | |||||
}; | }; | ||||
class PosixWritableFile : public WritableFile { | class PosixWritableFile : public WritableFile { | ||||
private: | private: | ||||
std::string filename_; | std::string filename_; | ||||
FILE* file_; | FILE* file_; | ||||
public: | public: | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | if (!s.ok()) { | ||||
return s; | return s; | ||||
} | } | ||||
if (fflush_unlocked(file_) != 0 || | if (fflush_unlocked(file_) != 0 || | ||||
fdatasync(fileno(file_)) != 0) { | fdatasync(fileno(file_)) != 0) { | ||||
s = Status::IOError(filename_, strerror(errno)); | s = Status::IOError(filename_, strerror(errno)); | ||||
} | } | ||||
return s; | return s; | ||||
} | } | ||||
virtual std::string GetName() const { return filename_; } | |||||
}; | }; | ||||
static int LockOrUnlock(int fd, bool lock) { | static int LockOrUnlock(int fd, bool lock) { | ||||
errno = 0; | errno = 0; | ||||
struct flock f; | struct flock f; | ||||
memset(&f, 0, sizeof(f)); | memset(&f, 0, sizeof(f)); | ||||
f.l_type = (lock ? F_WRLCK : F_UNLCK); | f.l_type = (lock ? F_WRLCK : F_UNLCK); | ||||
f.l_whence = SEEK_SET; | f.l_whence = SEEK_SET; | ||||
▲ Show 20 Lines • Show All 401 Lines • Show Last 20 Lines |