diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:25 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:25 +0300 |
commit | 344ea37b4a345701ab0e67de2266a1c1bd7baf2d (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/system/file.h | |
parent | 706b83ed7de5a473436620367af31fc0ceecde07 (diff) | |
download | ydb-344ea37b4a345701ab0e67de2266a1c1bd7baf2d.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 2 of 2.
Diffstat (limited to 'util/system/file.h')
-rw-r--r-- | util/system/file.h | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/util/system/file.h b/util/system/file.h index efe1e59b4a..9502e159b6 100644 --- a/util/system/file.h +++ b/util/system/file.h @@ -52,7 +52,7 @@ enum EOpenModeFlag { Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag) Y_DECLARE_OPERATORS_FOR_FLAGS(EOpenMode) -TString DecodeOpenMode(ui32 openMode); +TString DecodeOpenMode(ui32 openMode); enum SeekDir { sSet = 0, @@ -62,68 +62,68 @@ enum SeekDir { class TFileHandle: public TNonCopyable { public: - constexpr TFileHandle() = default; - + constexpr TFileHandle() = default; + /// Warning: takes ownership of fd, so closes it in destructor. - inline TFileHandle(FHANDLE fd) noexcept + inline TFileHandle(FHANDLE fd) noexcept : Fd_(fd) { } - inline TFileHandle(TFileHandle&& other) noexcept + inline TFileHandle(TFileHandle&& other) noexcept : Fd_(other.Fd_) { other.Fd_ = INVALID_FHANDLE; } - TFileHandle(const TString& fName, EOpenMode oMode) noexcept; + TFileHandle(const TString& fName, EOpenMode oMode) noexcept; - inline ~TFileHandle() { + inline ~TFileHandle() { Close(); } - bool Close() noexcept; + bool Close() noexcept; - inline FHANDLE Release() noexcept { + inline FHANDLE Release() noexcept { FHANDLE ret = Fd_; Fd_ = INVALID_FHANDLE; return ret; } - inline void Swap(TFileHandle& r) noexcept { + inline void Swap(TFileHandle& r) noexcept { DoSwap(Fd_, r.Fd_); } - inline operator FHANDLE() const noexcept { + inline operator FHANDLE() const noexcept { return Fd_; } - inline bool IsOpen() const noexcept { + inline bool IsOpen() const noexcept { return Fd_ != INVALID_FHANDLE; } - i64 GetPosition() const noexcept; - i64 GetLength() const noexcept; + i64 GetPosition() const noexcept; + i64 GetLength() const noexcept; - i64 Seek(i64 offset, SeekDir origin) noexcept; - bool Resize(i64 length) noexcept; - bool Reserve(i64 length) noexcept; + i64 Seek(i64 offset, SeekDir origin) noexcept; + bool Resize(i64 length) noexcept; + bool Reserve(i64 length) noexcept; bool FallocateNoResize(i64 length) noexcept; bool ShrinkToFit() noexcept; - bool Flush() noexcept; + bool Flush() noexcept; //flush data only, without file metadata - bool FlushData() noexcept; - i32 Read(void* buffer, ui32 byteCount) noexcept; - i32 Write(const void* buffer, ui32 byteCount) noexcept; - i32 Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept; - i32 Pwrite(const void* buffer, ui32 byteCount, i64 offset) const noexcept; - int Flock(int op) noexcept; - - FHANDLE Duplicate() const noexcept; + bool FlushData() noexcept; + i32 Read(void* buffer, ui32 byteCount) noexcept; + i32 Write(const void* buffer, ui32 byteCount) noexcept; + i32 Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept; + i32 Pwrite(const void* buffer, ui32 byteCount, i64 offset) const noexcept; + int Flock(int op) noexcept; + + FHANDLE Duplicate() const noexcept; int Duplicate2Posix(int dstHandle) const noexcept; //dup2 - like semantics, return true on success - bool LinkTo(const TFileHandle& fh) const noexcept; + bool LinkTo(const TFileHandle& fh) const noexcept; //very low-level methods bool SetDirect(); @@ -141,7 +141,7 @@ public: bool FlushCache(i64 offset = 0, i64 length = 0, bool wait = true) noexcept; private: - FHANDLE Fd_ = INVALID_FHANDLE; + FHANDLE Fd_ = INVALID_FHANDLE; }; class TFile { @@ -149,17 +149,17 @@ public: TFile(); /// Takes ownership of handle, so closes it when the last holder of descriptor dies. explicit TFile(FHANDLE fd); - TFile(FHANDLE fd, const TString& fname); - TFile(const TString& fName, EOpenMode oMode); - ~TFile(); + TFile(FHANDLE fd, const TString& fname); + TFile(const TString& fName, EOpenMode oMode); + ~TFile(); void Close(); - const TString& GetName() const noexcept; - i64 GetPosition() const noexcept; - i64 GetLength() const noexcept; - bool IsOpen() const noexcept; - FHANDLE GetHandle() const noexcept; + const TString& GetName() const noexcept; + i64 GetPosition() const noexcept; + i64 GetLength() const noexcept; + bool IsOpen() const noexcept; + FHANDLE GetHandle() const noexcept; i64 Seek(i64 offset, SeekDir origin); void Resize(i64 length); @@ -211,8 +211,8 @@ public: //flush unwritten data in this range and optionally wait for completion void FlushCache(i64 offset = 0, i64 length = 0, bool wait = true); - static TFile Temporary(const TString& prefix); - static TFile ForAppend(const TString& path); + static TFile Temporary(const TString& prefix); + static TFile ForAppend(const TString& path); private: class TImpl; @@ -222,4 +222,4 @@ private: TFile Duplicate(FILE*); TFile Duplicate(int); -bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept; +bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept; |