| 47 | } // namespace |
| 48 | |
| 49 | TDirectIOBufferedFile::TDirectIOBufferedFile(const TString& path, EOpenMode oMode, size_t buflen /*= 1 << 17*/) |
| 50 | : File(path, oMode) |
| 51 | , Alignment(0) |
| 52 | , DataLen(0) |
| 53 | , ReadPosition(0) |
| 54 | , WritePosition(0) |
| 55 | , DirectIO(false) |
| 56 | { |
| 57 | if (buflen == 0) { |
| 58 | ythrow TFileError() << "unbuffered usage is not supported"; |
| 59 | } |
| 60 | |
| 61 | if (oMode & Direct) { |
| 62 | Alignment = Singleton<TAlignmentCalcer>()->Alignment; |
| 63 | SetDirectIO(true); |
| 64 | } |
| 65 | |
| 66 | WritePosition = File.GetLength(); |
| 67 | FlushedBytes = WritePosition; |
| 68 | FlushedToDisk = FlushedBytes; |
| 69 | BufLen = (!!Alignment) ? AlignUp(buflen, Alignment) : buflen; |
| 70 | BufferStorage.Resize(BufLen + Alignment); |
| 71 | Buffer = (!!Alignment) ? AlignUp(BufferStorage.Data(), Alignment) : BufferStorage.Data(); |
| 72 | } |
| 73 | |
| 74 | #define DIRECT_IO_FLAGS (O_DIRECT | O_SYNC) |
| 75 | |