tree-wide: add FORMAT_BYTES()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-07-09 11:11:21 +02:00
parent 6c1abe8807
commit 2b59bf51a0
25 changed files with 170 additions and 258 deletions
+2 -6
View File
@@ -1492,7 +1492,6 @@ static int run_fsck(const char *node, const char *fstype) {
static int fs_grow(const char *node_path, const char *mount_path) {
_cleanup_close_ int mount_fd = -1, node_fd = -1;
char fb[FORMAT_BYTES_MAX];
uint64_t size, newsize;
int r;
@@ -1514,14 +1513,11 @@ static int fs_grow(const char *node_path, const char *mount_path) {
if (newsize == size)
log_debug("Successfully resized \"%s\" to %s bytes.",
mount_path,
format_bytes(fb, sizeof fb, newsize));
mount_path, FORMAT_BYTES(newsize));
else {
assert(newsize < size);
log_debug("Successfully resized \"%s\" to %s bytes (%"PRIu64" bytes lost due to blocksize).",
mount_path,
format_bytes(fb, sizeof fb, newsize),
size - newsize);
mount_path, FORMAT_BYTES(newsize), size - newsize);
}
return 0;
+5 -9
View File
@@ -579,10 +579,9 @@ static int output_short(
}
}
if (!(flags & OUTPUT_SHOW_ALL) && !utf8_is_printable(message, message_len)) {
char bytes[FORMAT_BYTES_MAX];
fprintf(f, "[%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len));
} else {
if (!(flags & OUTPUT_SHOW_ALL) && !utf8_is_printable(message, message_len))
fprintf(f, "[%s blob data]\n", FORMAT_BYTES(message_len));
else {
/* URLify config_file string in message, if the message starts with it.
* Skip URLification if the highlighted pattern overlaps. */
@@ -726,16 +725,13 @@ static int output_verbose(
p, valuelen,
NULL);
fputs(off, f);
} else {
char bytes[FORMAT_BYTES_MAX];
} else
fprintf(f, " %s%.*s=[%s blob data]%s\n",
on,
(int) (c - (const char*) data),
(const char*) data,
format_bytes(bytes, sizeof(bytes), length - (c - (const char *) data) - 1),
FORMAT_BYTES(length - (c - (const char *) data) - 1),
off);
}
}
if (r < 0)
+17 -32
View File
@@ -256,15 +256,11 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) {
if (hr->tasks_max != UINT64_MAX)
printf(" Tasks Max: %" PRIu64 "\n", hr->tasks_max);
if (hr->memory_high != UINT64_MAX) {
char buf[FORMAT_BYTES_MAX];
printf(" Memory High: %s\n", format_bytes(buf, sizeof(buf), hr->memory_high));
}
if (hr->memory_high != UINT64_MAX)
printf(" Memory High: %s\n", FORMAT_BYTES(hr->memory_high));
if (hr->memory_max != UINT64_MAX) {
char buf[FORMAT_BYTES_MAX];
printf(" Memory Max: %s\n", format_bytes(buf, sizeof(buf), hr->memory_max));
}
if (hr->memory_max != UINT64_MAX)
printf(" Memory Max: %s\n", FORMAT_BYTES(hr->memory_max));
if (hr->cpu_weight != UINT64_MAX)
printf(" CPU Weight: %" PRIu64 "\n", hr->cpu_weight);
@@ -301,10 +297,9 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) {
printf(" PBKDF Hash: %s\n", hr->luks_pbkdf_hash_algorithm);
if (hr->luks_pbkdf_time_cost_usec != UINT64_MAX)
printf(" PBKDF Time: %s\n", FORMAT_TIMESPAN(hr->luks_pbkdf_time_cost_usec, 0));
if (hr->luks_pbkdf_memory_cost != UINT64_MAX) {
char buf[FORMAT_BYTES_MAX];
printf(" PBKDF Bytes: %s\n", format_bytes(buf, sizeof(buf), hr->luks_pbkdf_memory_cost));
}
if (hr->luks_pbkdf_memory_cost != UINT64_MAX)
printf(" PBKDF Bytes: %s\n", FORMAT_BYTES(hr->luks_pbkdf_memory_cost));
if (hr->luks_pbkdf_parallel_threads != UINT64_MAX)
printf("PBKDF Thread: %" PRIu64 "\n", hr->luks_pbkdf_parallel_threads);
@@ -328,28 +323,22 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) {
if (hr->skeleton_directory)
printf(" Skel. Dir.: %s\n", user_record_skeleton_directory(hr));
if (hr->disk_size != UINT64_MAX) {
char buf[FORMAT_BYTES_MAX];
printf(" Disk Size: %s\n", format_bytes(buf, sizeof(buf), hr->disk_size));
}
if (hr->disk_size != UINT64_MAX)
printf(" Disk Size: %s\n", FORMAT_BYTES(hr->disk_size));
if (hr->disk_usage != UINT64_MAX) {
char buf[FORMAT_BYTES_MAX];
if (hr->disk_size != UINT64_MAX) {
unsigned permille;
permille = (unsigned) DIV_ROUND_UP(hr->disk_usage * 1000U, hr->disk_size); /* Round up! */
printf(" Disk Usage: %s (= %u.%01u%%)\n",
format_bytes(buf, sizeof(buf), hr->disk_usage),
FORMAT_BYTES(hr->disk_usage),
permille / 10, permille % 10);
} else
printf(" Disk Usage: %s\n", format_bytes(buf, sizeof(buf), hr->disk_usage));
printf(" Disk Usage: %s\n", FORMAT_BYTES(hr->disk_usage));
}
if (hr->disk_free != UINT64_MAX) {
char buf[FORMAT_BYTES_MAX];
if (hr->disk_size != UINT64_MAX) {
const char *color_on, *color_off;
unsigned permille;
@@ -372,22 +361,18 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) {
printf(" Disk Free: %s%s (= %u.%01u%%)%s\n",
color_on,
format_bytes(buf, sizeof(buf), hr->disk_free),
FORMAT_BYTES(hr->disk_free),
permille / 10, permille % 10,
color_off);
} else
printf(" Disk Free: %s\n", format_bytes(buf, sizeof(buf), hr->disk_free));
printf(" Disk Free: %s\n", FORMAT_BYTES(hr->disk_free));
}
if (hr->disk_floor != UINT64_MAX) {
char buf[FORMAT_BYTES_MAX];
printf(" Disk Floor: %s\n", format_bytes(buf, sizeof(buf), hr->disk_floor));
}
if (hr->disk_floor != UINT64_MAX)
printf(" Disk Floor: %s\n", FORMAT_BYTES(hr->disk_floor));
if (hr->disk_ceiling != UINT64_MAX) {
char buf[FORMAT_BYTES_MAX];
printf("Disk Ceiling: %s\n", format_bytes(buf, sizeof(buf), hr->disk_ceiling));
}
if (hr->disk_ceiling != UINT64_MAX)
printf("Disk Ceiling: %s\n", FORMAT_BYTES(hr->disk_ceiling));
if (hr->good_authentication_counter != UINT64_MAX)
printf(" Good Auth.: %" PRIu64 "\n", hr->good_authentication_counter);