From f5105bfbfeb4215ae2aa42b1f088821d3ccf161f Mon Sep 17 00:00:00 2001 From: Alexander Rutkovsky Date: Thu, 1 Aug 2024 07:24:56 +0000 Subject: [PATCH] Fix block device size calculcation code --- ydb/library/pdisk_io/wcache.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ydb/library/pdisk_io/wcache.cpp b/ydb/library/pdisk_io/wcache.cpp index 5425c0b020ce..28d22cdd1008 100644 --- a/ydb/library/pdisk_io/wcache.cpp +++ b/ydb/library/pdisk_io/wcache.cpp @@ -668,9 +668,15 @@ std::optional GetDriveData(const TString &path, TStringStream *outDe try { TFile f(path, OpenExisting | RdOnly); TDriveData data; - long size = 0; - if (ioctl(f.GetHandle(), BLKGETSIZE, &size) == 0) { - data.Size = size << 9; + if (off64_t off = lseek64(f.GetHandle(), 0, SEEK_END); off != (off64_t)-1) { + data.Size = off; + } else { + long size = 0; + if (!ioctl(f.GetHandle(), BLKGETSIZE64, &size)) { + data.Size = size; + } else if (!ioctl(f.GetHandle(), BLKGETSIZE, &size)) { + data.Size = size << 9; + } } EWriteCacheResult res = GetWriteCache(f.GetHandle(), path, &data, outDetails); if (res == EWriteCacheResult::WriteCacheResultOk) {