Skip to content

Commit

Permalink
Utilities/du: Use apparent size on devices that don't report blocks
Browse files Browse the repository at this point in the history
Certain virtual filesystems (RAMFS) always report 0 used blocks, even
for files that are not empty. In this case, we should fall back to
reporting the apparent size, as showing zero is somewhat misleading.
  • Loading branch information
sdomi authored and timschumi committed Oct 4, 2024
1 parent b227115 commit 66a4095
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Userland/Utilities/du.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,12 @@ u64 print_space_usage(ByteString const& path, DuOption const& du_option, size_t
return 0;
}

if (!du_option.apparent_size) {
// If the underlying FS reports 0 used blocks, apparent size may be more accurate
if (du_option.apparent_size || path_stat.st_blocks == 0) {
size += path_stat.st_size;
} else {
constexpr auto block_size = 512;
size += path_stat.st_blocks * block_size;
} else {
size += path_stat.st_size;
}

bool is_beyond_depth = current_depth > du_option.max_depth;
Expand Down

0 comments on commit 66a4095

Please sign in to comment.