Skip to content

Commit 1cfb39e

Browse files
committed
reswap if (m_raw_device)
1 parent 235510c commit 1cfb39e

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

Utilities/File.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -670,20 +670,20 @@ namespace fs
670670

671671
u64 size() override
672672
{
673-
if (m_raw_device)
673+
if (!m_raw_device)
674674
{
675-
// For a raw device, we need to use DeviceIoControl.
676-
DISK_GEOMETRY_EX geometry;
675+
// NOTE: this can fail if we access a mounted empty drive (e.g. after unmounting an iso).
676+
LARGE_INTEGER size;
677677

678-
ensure(DeviceIoControl(m_handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, nullptr, 0, &geometry, sizeof(geometry), nullptr, nullptr));
679-
return geometry.DiskSize.QuadPart;
678+
ensure(GetFileSizeEx(m_handle, &size)); // "file::size"
679+
return size.QuadPart;
680680
}
681681

682-
// NOTE: this can fail if we access a mounted empty drive (e.g. after unmounting an iso).
683-
LARGE_INTEGER size;
682+
// For a raw device, we need to use DeviceIoControl.
683+
DISK_GEOMETRY_EX geometry;
684684

685-
ensure(GetFileSizeEx(m_handle, &size)); // "file::size"
686-
return size.QuadPart;
685+
ensure(DeviceIoControl(m_handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, nullptr, 0, &geometry, sizeof(geometry), nullptr, nullptr));
686+
return geometry.DiskSize.QuadPart;
687687
}
688688

689689
native_handle get_handle() override
@@ -852,16 +852,16 @@ namespace fs
852852

853853
u64 size() override
854854
{
855-
if (m_raw_device)
855+
if (!m_raw_device)
856856
{
857-
// For a raw device, we need to use an ioctl ("fstat()" would always report a null size)
858-
return get_raw_device_size(m_fd);
859-
}
857+
struct ::stat file_info;
858+
ensure(::fstat(m_fd, &file_info) == 0); // "file::size"
860859

861-
struct ::stat file_info;
862-
ensure(::fstat(m_fd, &file_info) == 0); // "file::size"
860+
return file_info.st_size;
861+
}
863862

864-
return file_info.st_size;
863+
// For a raw device, we need to use an ioctl ("fstat()" would always report a null size)
864+
return get_raw_device_size(m_fd);
865865
}
866866

867867
native_handle get_handle() override

0 commit comments

Comments
 (0)