Skip to content

Commit

Permalink
img: fix incorrect disk sizes in raw format
Browse files Browse the repository at this point in the history
The disk size in raw format was calculated incorrectly.
  • Loading branch information
0x501D committed Jan 11, 2025
1 parent f4de414 commit 0898ed9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/nm_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@

#define NM_UNUSED __attribute__((__unused__))

#ifndef S_BLKSIZE
#define S_BLKSIZE 512
#endif

static const int NM_OK;
static const int NM_ERR = -1;

Expand Down
4 changes: 2 additions & 2 deletions src/nm_vm_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1121,10 +1121,10 @@ nm_str_t nm_vmctl_info(const nm_str_t *name)
memset(&img_info, 0, sizeof(img_info));
stat(drive_path.data, &img_info);

nm_str_append_format(&info, "disk%zu%-7s%s [%.2gGb/%sGb real/virt, %s, "
nm_str_append_format(&info, "disk%zu%-7s%s [%.3gGb/%sGb real/virt, %s, "
"%s] %s\n", n, ":",
nm_vect_str_ctx(&vm.drives, NM_SQL_DRV_NAME + idx_shift),
(double) img_info.st_size / 1073741824,
(double) img_info.st_blocks * S_BLKSIZE / 1073741824,
nm_vect_str_ctx(&vm.drives, NM_SQL_DRV_SIZE + idx_shift),
nm_vect_str_ctx(&vm.drives, NM_SQL_DRV_TYPE + idx_shift),
nm_vect_str_ctx(&vm.drives, NM_SQL_DRV_FMT + idx_shift),
Expand Down
4 changes: 2 additions & 2 deletions src/nm_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,10 @@ nm_print_vm_info(const nm_str_t *name, const nm_vmctl_data_t *vm, int status)
stat(drive_path.data, &img_info);

nm_str_format(&buf,
"disk%zu%-7s%s [%.2gGb/%sGb real/virt, %s, %s, discard=%s] %s",
"disk%zu%-7s%s [%.3gGb/%sGb real/virt, %s, %s, discard=%s] %s",
n, ":",
nm_vect_str_ctx(&vm_->drives, NM_SQL_DRV_NAME + idx_shift),
(double) img_info.st_size / 1073741824,
(double) img_info.st_blocks * S_BLKSIZE / 1073741824,
nm_vect_str_ctx(&vm_->drives, NM_SQL_DRV_SIZE + idx_shift),
nm_vect_str_ctx(&vm_->drives, NM_SQL_DRV_TYPE + idx_shift),
nm_vect_str_ctx(&vm_->drives, NM_SQL_DRV_FMT + idx_shift),
Expand Down

0 comments on commit 0898ed9

Please sign in to comment.