Skip to content

Commit

Permalink
Fix block device size calculcation code (#7341)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvru authored Aug 1, 2024
1 parent f81bd79 commit b08c9a5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ydb/library/pdisk_io/wcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,15 @@ std::optional<TDriveData> 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) {
Expand Down

0 comments on commit b08c9a5

Please sign in to comment.