Commit e39ed66
btrfs-progs: Fixing invalid device size output when "btrfs device usage /" called as normal user
When "btrfs device usage /" is being called as a normal user,
the function device_get_partition_size in device-utils.c calls
device_get_partition_size_sysfs() as a fallback, which reads
the size of the partition from "/sys/class/block/[partition]/size".
The problem here is that the size read is not actually the size of
the partition but rather a number of how many 512B (or whatever the
devices sector size is) sectors the partition contains.
Ex: if read value is 104857600 the size is not 100MB but 104857600 *
512B = 50GB
This patch adds a function named get_partition_sector_size_sysfs which
based on the partition name returns the sector size of the device, and
replaces "return size" with "return size * sector_size" in
device_get_partition_size_sysfs.
Issue: #979
Reviewed-by: Qu Wenruo <wqu@suse.com>1 parent b299793 commit e39ed66
1 file changed
+53
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
342 | 343 | | |
343 | 344 | | |
344 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
345 | 390 | | |
346 | 391 | | |
347 | 392 | | |
| |||
351 | 396 | | |
352 | 397 | | |
353 | 398 | | |
| 399 | + | |
354 | 400 | | |
355 | 401 | | |
356 | 402 | | |
| |||
375 | 421 | | |
376 | 422 | | |
377 | 423 | | |
378 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
379 | 431 | | |
380 | 432 | | |
381 | 433 | | |
| |||
0 commit comments