]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: add FORMAT_BYTES()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 6 Jul 2021 07:14:01 +0000 (09:14 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Jul 2021 09:11:21 +0000 (11:11 +0200)
25 files changed:
src/basic/format-util.h
src/core/cgroup.c
src/core/dbus-manager.c
src/core/unit.c
src/coredump/coredumpctl.c
src/dissect/dissect.c
src/home/homework-luks.c
src/import/import-fs.c
src/import/pull-job.c
src/journal/journalctl.c
src/journal/journald-server.c
src/libsystemd/sd-journal/journal-file.c
src/libsystemd/sd-journal/journal-vacuum.c
src/machine/machinectl.c
src/oom/oomd-util.c
src/partition/growfs.c
src/partition/repart.c
src/run/run.c
src/shared/dissect-image.c
src/shared/logs-show.c
src/shared/user-record-show.c
src/systemctl/systemctl-show.c
src/test/test-btrfs.c
src/test/test-procfs-util.c
src/test/test-util.c

index b7e18768e392e034d0a56b056192dbdc040cf800..148a847102781dcfe9f26c02018ba44799085e8d 100644 (file)
@@ -80,6 +80,11 @@ static inline char *format_bytes(char *buf, size_t l, uint64_t t) {
         return format_bytes_full(buf, l, t, FORMAT_BYTES_USE_IEC | FORMAT_BYTES_BELOW_POINT | FORMAT_BYTES_TRAILING_B);
 }
 
+/* Note: the lifetime of the compound literal is the immediately surrounding block,
+ * see C11 §6.5.2.5, and
+ * https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */
+#define FORMAT_BYTES(t) format_bytes((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t)
+
 static inline char *format_bytes_cgroup_protection(char *buf, size_t l, uint64_t t) {
         if (t == CGROUP_LIMIT_MAX) {
                 (void) snprintf(buf, l, "%s", "infinity");
index fe68a9ac7b6c6da57cd7dbd6b40d5e1c7c591c90..e5fd6672bb3482d6cdf97e9555497e20746f0870 100644 (file)
@@ -514,9 +514,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
                         l->path,
                         FORMAT_TIMESPAN(l->target_usec, 1));
 
-        LIST_FOREACH(device_limits, il, c->io_device_limits) {
-                char buf[FORMAT_BYTES_MAX];
-
+        LIST_FOREACH(device_limits, il, c->io_device_limits)
                 for (CGroupIOLimitType type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++)
                         if (il->limits[type] != cgroup_io_limit_defaults[type])
                                 fprintf(f,
@@ -524,8 +522,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
                                         prefix,
                                         cgroup_io_limit_type_to_string(type),
                                         il->path,
-                                        format_bytes(buf, sizeof(buf), il->limits[type]));
-        }
+                                        FORMAT_BYTES(il->limits[type]));
 
         LIST_FOREACH(device_weights, w, c->blockio_device_weights)
                 fprintf(f,
@@ -535,20 +532,18 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
                         w->weight);
 
         LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) {
-                char buf[FORMAT_BYTES_MAX];
-
                 if (b->rbps != CGROUP_LIMIT_MAX)
                         fprintf(f,
                                 "%sBlockIOReadBandwidth: %s %s\n",
                                 prefix,
                                 b->path,
-                                format_bytes(buf, sizeof(buf), b->rbps));
+                                FORMAT_BYTES(b->rbps));
                 if (b->wbps != CGROUP_LIMIT_MAX)
                         fprintf(f,
                                 "%sBlockIOWriteBandwidth: %s %s\n",
                                 prefix,
                                 b->path,
-                                format_bytes(buf, sizeof(buf), b->wbps));
+                                FORMAT_BYTES(b->wbps));
         }
 
         LIST_FOREACH(items, iaai, c->ip_address_allow) {
index de057a024529ab5afb7eded1b21c968f2c2b130b..1f2ac8152c2f2867d19384d5a5f335837c1a38cf 100644 (file)
@@ -1324,16 +1324,14 @@ static int verify_run_space(const char *message, sd_bus_error *error) {
 
         available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize;
 
-        if (available < RELOAD_DISK_SPACE_MIN) {
-                char fb_available[FORMAT_BYTES_MAX], fb_need[FORMAT_BYTES_MAX];
+        if (available < RELOAD_DISK_SPACE_MIN)
                 return sd_bus_error_setf(error,
                                          BUS_ERROR_DISK_FULL,
                                          "%s, not enough space available on /run/systemd. "
                                          "Currently, %s are free, but a safety buffer of %s is enforced.",
                                          message,
-                                         format_bytes(fb_available, sizeof(fb_available), available),
-                                         format_bytes(fb_need, sizeof(fb_need), RELOAD_DISK_SPACE_MIN));
-        }
+                                         FORMAT_BYTES(available),
+                                         FORMAT_BYTES(RELOAD_DISK_SPACE_MIN));
 
         return 0;
 }
@@ -1530,13 +1528,11 @@ static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_er
 
         available = (uint64_t) svfs.f_bfree * (uint64_t) svfs.f_bsize;
 
-        if (available < RELOAD_DISK_SPACE_MIN) {
-                char fb_available[FORMAT_BYTES_MAX], fb_need[FORMAT_BYTES_MAX];
+        if (available < RELOAD_DISK_SPACE_MIN)
                 log_warning("Dangerously low amount of free space on /run/systemd, root switching might fail.\n"
                             "Currently, %s are free, but %s are suggested. Proceeding anyway.",
-                            format_bytes(fb_available, sizeof(fb_available), available),
-                            format_bytes(fb_need, sizeof(fb_need), RELOAD_DISK_SPACE_MIN));
-        }
+                            FORMAT_BYTES(available),
+                            FORMAT_BYTES(RELOAD_DISK_SPACE_MIN));
 
         r = mac_selinux_access_check(message, "reboot", error);
         if (r < 0)
index 3265f8d6a2d8136a37f3dc1294289b7162065962..c32317c863d4e4b75585958542a94258c30a9259 100644 (file)
@@ -2295,7 +2295,6 @@ static int unit_log_resources(Unit *u) {
         }
 
         for (CGroupIOAccountingMetric k = 0; k < _CGROUP_IO_ACCOUNTING_METRIC_MAX; k++) {
-                char buf[FORMAT_BYTES_MAX] = "";
                 uint64_t value = UINT64_MAX;
 
                 assert(io_fields[k]);
@@ -2319,14 +2318,14 @@ static int unit_log_resources(Unit *u) {
                  * for the bytes counters (and not for the operations counters) */
                 if (k == CGROUP_IO_READ_BYTES) {
                         assert(!rr);
-                        rr = strjoin("read ", format_bytes(buf, sizeof(buf), value), " from disk");
+                        rr = strjoin("read ", strna(FORMAT_BYTES(value)), " from disk");
                         if (!rr) {
                                 r = log_oom();
                                 goto finish;
                         }
                 } else if (k == CGROUP_IO_WRITE_BYTES) {
                         assert(!wr);
-                        wr = strjoin("written ", format_bytes(buf, sizeof(buf), value), " to disk");
+                        wr = strjoin("written ", strna(FORMAT_BYTES(value)), " to disk");
                         if (!wr) {
                                 r = log_oom();
                                 goto finish;
@@ -2360,7 +2359,6 @@ static int unit_log_resources(Unit *u) {
         }
 
         for (CGroupIPAccountingMetric m = 0; m < _CGROUP_IP_ACCOUNTING_METRIC_MAX; m++) {
-                char buf[FORMAT_BYTES_MAX] = "";
                 uint64_t value = UINT64_MAX;
 
                 assert(ip_fields[m]);
@@ -2384,14 +2382,14 @@ static int unit_log_resources(Unit *u) {
                  * bytes counters (and not for the packets counters) */
                 if (m == CGROUP_IP_INGRESS_BYTES) {
                         assert(!igress);
-                        igress = strjoin("received ", format_bytes(buf, sizeof(buf), value), " IP traffic");
+                        igress = strjoin("received ", strna(FORMAT_BYTES(value)), " IP traffic");
                         if (!igress) {
                                 r = log_oom();
                                 goto finish;
                         }
                 } else if (m == CGROUP_IP_EGRESS_BYTES) {
                         assert(!egress);
-                        egress = strjoin("sent ", format_bytes(buf, sizeof(buf), value), " IP traffic");
+                        egress = strjoin("sent ", strna(FORMAT_BYTES(value)), " IP traffic");
                         if (!egress) {
                                 r = log_oom();
                                 goto finish;
index c1969d12f5278b2fa3a67dac53625aac9a72508f..8261bff21301942f882914755c77b68562db32d1 100644 (file)
@@ -693,7 +693,6 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
         if (filename) {
                 const char *state = NULL, *color = NULL;
                 uint64_t size = UINT64_MAX;
-                char buf[FORMAT_BYTES_MAX];
 
                 analyze_coredump_file(filename, &state, &color, &size);
 
@@ -708,9 +707,8 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
                         ansi_normal());
 
                 if (size != UINT64_MAX)
-                        fprintf(file,
-                                "     Disk Size: %s\n",
-                                format_bytes(buf, sizeof(buf), size));
+                        fprintf(file, "     Disk Size: %s\n", FORMAT_BYTES(size));
+
         } else if (coredump)
                 fprintf(file, "       Storage: journal\n");
         else
index 47feba3d627119dd9bbf3b89412f19ae9b9a8f2a..88bb3de40f776e14cd8c8f29870a97d0a80f9eee 100644 (file)
@@ -385,10 +385,8 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
 
         if (ioctl(d->fd, BLKGETSIZE64, &size) < 0)
                 log_debug_errno(errno, "Failed to query size of loopback device: %m");
-        else if (arg_json_format_flags & JSON_FORMAT_OFF) {
-                char s[FORMAT_BYTES_MAX];
-                printf("      Size: %s\n", format_bytes(s, sizeof(s), size));
-        }
+        else if (arg_json_format_flags & JSON_FORMAT_OFF)
+                printf("      Size: %s\n", FORMAT_BYTES(size));
 
         if (arg_json_format_flags & JSON_FORMAT_OFF)
                 putc('\n', stdout);
index 6448883fe0455d1e6ea368a34bc8112b67038d3b..3d4361c4ecfa705e33f28aca4dce694cdd4c7f9b 100644 (file)
@@ -949,7 +949,6 @@ int home_store_header_identity_luks(
 }
 
 int run_fitrim(int root_fd) {
-        char buf[FORMAT_BYTES_MAX];
         struct fstrim_range range = {
                 .len = UINT64_MAX,
         };
@@ -968,8 +967,7 @@ int run_fitrim(int root_fd) {
                 return log_warning_errno(errno, "Failed to invoke FITRIM, ignoring: %m");
         }
 
-        log_info("Discarded unused %s.",
-                 format_bytes(buf, sizeof(buf), range.len));
+        log_info("Discarded unused %s.", FORMAT_BYTES(range.len));
         return 1;
 }
 
@@ -984,7 +982,6 @@ int run_fitrim_by_path(const char *root_path) {
 }
 
 int run_fallocate(int backing_fd, const struct stat *st) {
-        char buf[FORMAT_BYTES_MAX];
         struct stat stbuf;
 
         assert(backing_fd >= 0);
@@ -1023,7 +1020,7 @@ int run_fallocate(int backing_fd, const struct stat *st) {
         }
 
         log_info("Allocated additional %s.",
-                 format_bytes(buf, sizeof(buf), (DIV_ROUND_UP(st->st_size, 512) - st->st_blocks) * 512));
+                 FORMAT_BYTES((DIV_ROUND_UP(st->st_size, 512) - st->st_blocks) * 512));
         return 1;
 }
 
@@ -1278,15 +1275,13 @@ fail:
 }
 
 static void print_size_summary(uint64_t host_size, uint64_t encrypted_size, struct statfs *sfs) {
-        char buffer1[FORMAT_BYTES_MAX], buffer2[FORMAT_BYTES_MAX], buffer3[FORMAT_BYTES_MAX], buffer4[FORMAT_BYTES_MAX];
-
         assert(sfs);
 
         log_info("Image size is %s, file system size is %s, file system payload size is %s, file system free is %s.",
-                 format_bytes(buffer1, sizeof(buffer1), host_size),
-                 format_bytes(buffer2, sizeof(buffer2), encrypted_size),
-                 format_bytes(buffer3, sizeof(buffer3), (uint64_t) sfs->f_blocks * (uint64_t) sfs->f_frsize),
-                 format_bytes(buffer4, sizeof(buffer4), (uint64_t) sfs->f_bfree * (uint64_t) sfs->f_frsize));
+                 FORMAT_BYTES(host_size),
+                 FORMAT_BYTES(encrypted_size),
+                 FORMAT_BYTES((uint64_t) sfs->f_blocks * (uint64_t) sfs->f_frsize),
+                 FORMAT_BYTES((uint64_t) sfs->f_bfree * (uint64_t) sfs->f_frsize));
 }
 
 int home_activate_luks(
@@ -1793,7 +1788,6 @@ static int wait_for_devlink(const char *path) {
 }
 
 static int calculate_disk_size(UserRecord *h, const char *parent_dir, uint64_t *ret) {
-        char buf[FORMAT_BYTES_MAX];
         struct statfs sfs;
         uint64_t m;
 
@@ -1820,14 +1814,14 @@ static int calculate_disk_size(UserRecord *h, const char *parent_dir, uint64_t *
 
                 log_info("Sizing home to %u%% of available disk space, which is %s.",
                          USER_DISK_SIZE_DEFAULT_PERCENT,
-                         format_bytes(buf, sizeof(buf), *ret));
+                         FORMAT_BYTES(*ret));
         } else {
                 *ret = DISK_SIZE_ROUND_DOWN((uint64_t) ((double) m * (double) h->disk_size_relative / (double) UINT32_MAX));
 
                 log_info("Sizing home to %" PRIu64 ".%01" PRIu64 "%% of available disk space, which is %s.",
                          (h->disk_size_relative * 100) / UINT32_MAX,
                          ((h->disk_size_relative * 1000) / UINT32_MAX) % 10,
-                         format_bytes(buf, sizeof(buf), *ret));
+                         FORMAT_BYTES(*ret));
         }
 
         if (*ret < USER_DISK_SIZE_MIN)
@@ -2631,8 +2625,6 @@ int home_resize_luks(
                 HomeSetup *setup,
                 UserRecord **ret_home) {
 
-        char buffer1[FORMAT_BYTES_MAX], buffer2[FORMAT_BYTES_MAX], buffer3[FORMAT_BYTES_MAX],
-                buffer4[FORMAT_BYTES_MAX], buffer5[FORMAT_BYTES_MAX], buffer6[FORMAT_BYTES_MAX];
         uint64_t old_image_size, new_image_size, old_fs_size, new_fs_size, crypto_offset, new_partition_size;
         _cleanup_(user_record_unrefp) UserRecord *header_home = NULL, *embedded_home = NULL, *new_home = NULL;
         _cleanup_(fdisk_unref_tablep) struct fdisk_table *table = NULL;
@@ -2770,12 +2762,12 @@ int home_resize_luks(
                 return log_error_errno(SYNTHETIC_ERRNO(ETXTBSY), "File systems of this type can only be resized offline, but is currently online.");
 
         log_info("Ready to resize image size %s → %s, partition size %s → %s, file system size %s → %s.",
-                 format_bytes(buffer1, sizeof(buffer1), old_image_size),
-                 format_bytes(buffer2, sizeof(buffer2), new_image_size),
-                 format_bytes(buffer3, sizeof(buffer3), setup->partition_size),
-                 format_bytes(buffer4, sizeof(buffer4), new_partition_size),
-                 format_bytes(buffer5, sizeof(buffer5), old_fs_size),
-                 format_bytes(buffer6, sizeof(buffer6), new_fs_size));
+                 FORMAT_BYTES(old_image_size),
+                 FORMAT_BYTES(new_image_size),
+                 FORMAT_BYTES(setup->partition_size),
+                 FORMAT_BYTES(new_partition_size),
+                 FORMAT_BYTES(old_fs_size),
+                 FORMAT_BYTES(new_fs_size));
 
         r = prepare_resize_partition(
                         image_fd,
index a12ee77ef9fc7fb6bdc85ad9d15ed85d7449b4a3..e8c3740879b1f8016a63abf989d9ca19a3919386 100644 (file)
@@ -62,11 +62,8 @@ static void progress_show(ProgressInfo *p) {
 
         if (p->size == 0)
                 log_info("Copying tree, currently at '%s'...", p->path);
-        else {
-                char buffer[FORMAT_BYTES_MAX];
-
-                log_info("Copying tree, currently at '%s' (@%s)...", p->path, format_bytes(buffer, sizeof(buffer), p->size));
-        }
+        else
+                log_info("Copying tree, currently at '%s' (@%s)...", p->path, FORMAT_BYTES(p->size));
 }
 
 static int progress_path(const char *path, const struct stat *st, void *userdata) {
index 7215a0064896669e641399195a50b541a2bf7450..cd32ecc18876112ad7853664530f26d21acaa263 100644 (file)
@@ -501,15 +501,13 @@ static size_t pull_job_header_callback(void *contents, size_t size, size_t nmemb
                 (void) safe_atou64(length, &j->content_length);
 
                 if (j->content_length != UINT64_MAX) {
-                        char bytes[FORMAT_BYTES_MAX];
-
                         if (j->content_length > j->compressed_max) {
                                 log_error("Content too large.");
                                 r = -EFBIG;
                                 goto fail;
                         }
 
-                        log_info("Downloading %s for %s.", format_bytes(bytes, sizeof(bytes), j->content_length), j->url);
+                        log_info("Downloading %s for %s.", FORMAT_BYTES(j->content_length), j->url);
                 }
 
                 return sz;
@@ -556,7 +554,6 @@ static int pull_job_progress_callback(void *userdata, curl_off_t dltotal, curl_o
             dlnow < dltotal) {
 
                 if (n - j->start_usec > USEC_PER_SEC && dlnow > 0) {
-                        char y[FORMAT_BYTES_MAX];
                         usec_t left, done;
 
                         done = n - j->start_usec;
@@ -566,7 +563,7 @@ static int pull_job_progress_callback(void *userdata, curl_off_t dltotal, curl_o
                                  percent,
                                  j->url,
                                  FORMAT_TIMESPAN(left, USEC_PER_SEC),
-                                 format_bytes(y, sizeof(y), (uint64_t) ((double) dlnow / ((double) done / (double) USEC_PER_SEC))));
+                                 FORMAT_BYTES((uint64_t) ((double) dlnow / ((double) done / (double) USEC_PER_SEC))));
                 } else
                         log_info("Got %u%% of %s.", percent, j->url);
 
index 6e1a392f587cae3fb485b9575ec097535d9e6e31..fe98aecf51bbe28624db8239352c97e14a2b1c2f 100644 (file)
@@ -2327,14 +2327,13 @@ int main(int argc, char *argv[]) {
 
         case ACTION_DISK_USAGE: {
                 uint64_t bytes = 0;
-                char sbytes[FORMAT_BYTES_MAX];
 
                 r = sd_journal_get_usage(j, &bytes);
                 if (r < 0)
                         goto finish;
 
                 printf("Archived and active journals take up %s in the file system.\n",
-                       format_bytes(sbytes, sizeof(sbytes), bytes));
+                       FORMAT_BYTES(bytes));
                 goto finish;
         }
 
index af616e97a70dda8d093f4dc3a82488c6cc76db5f..7770df41f1f7e065249aef643fe8950498707575 100644 (file)
@@ -199,10 +199,6 @@ static int determine_space(Server *s, uint64_t *available, uint64_t *limit) {
 }
 
 void server_space_usage_message(Server *s, JournalStorage *storage) {
-        char fb1[FORMAT_BYTES_MAX], fb2[FORMAT_BYTES_MAX], fb3[FORMAT_BYTES_MAX],
-             fb4[FORMAT_BYTES_MAX], fb5[FORMAT_BYTES_MAX], fb6[FORMAT_BYTES_MAX];
-        JournalMetrics *metrics;
-
         assert(s);
 
         if (!storage)
@@ -211,32 +207,31 @@ void server_space_usage_message(Server *s, JournalStorage *storage) {
         if (cache_space_refresh(s, storage) < 0)
                 return;
 
-        metrics = &storage->metrics;
-        format_bytes(fb1, sizeof(fb1), storage->space.vfs_used);
-        format_bytes(fb2, sizeof(fb2), metrics->max_use);
-        format_bytes(fb3, sizeof(fb3), metrics->keep_free);
-        format_bytes(fb4, sizeof(fb4), storage->space.vfs_available);
-        format_bytes(fb5, sizeof(fb5), storage->space.limit);
-        format_bytes(fb6, sizeof(fb6), storage->space.available);
+        const JournalMetrics *metrics = &storage->metrics;
+
+        const char
+                *vfs_used  = FORMAT_BYTES(storage->space.vfs_used),
+                *limit     = FORMAT_BYTES(storage->space.limit),
+                *available = FORMAT_BYTES(storage->space.available);
 
         server_driver_message(s, 0,
                               "MESSAGE_ID=" SD_MESSAGE_JOURNAL_USAGE_STR,
                               LOG_MESSAGE("%s (%s) is %s, max %s, %s free.",
-                                          storage->name, storage->path, fb1, fb5, fb6),
+                                          storage->name, storage->path, vfs_used, limit, available),
                               "JOURNAL_NAME=%s", storage->name,
                               "JOURNAL_PATH=%s", storage->path,
                               "CURRENT_USE=%"PRIu64, storage->space.vfs_used,
-                              "CURRENT_USE_PRETTY=%s", fb1,
+                              "CURRENT_USE_PRETTY=%s", vfs_used,
                               "MAX_USE=%"PRIu64, metrics->max_use,
-                              "MAX_USE_PRETTY=%s", fb2,
+                              "MAX_USE_PRETTY=%s", FORMAT_BYTES(metrics->max_use),
                               "DISK_KEEP_FREE=%"PRIu64, metrics->keep_free,
-                              "DISK_KEEP_FREE_PRETTY=%s", fb3,
+                              "DISK_KEEP_FREE_PRETTY=%s", FORMAT_BYTES(metrics->keep_free),
                               "DISK_AVAILABLE=%"PRIu64, storage->space.vfs_available,
-                              "DISK_AVAILABLE_PRETTY=%s", fb4,
+                              "DISK_AVAILABLE_PRETTY=%s", FORMAT_BYTES(storage->space.vfs_available),
                               "LIMIT=%"PRIu64, storage->space.limit,
-                              "LIMIT_PRETTY=%s", fb5,
+                              "LIMIT_PRETTY=%s", limit,
                               "AVAILABLE=%"PRIu64, storage->space.available,
-                              "AVAILABLE_PRETTY=%s", fb6,
+                              "AVAILABLE_PRETTY=%s", available,
                               NULL);
 }
 
index 6ca6048ec720916cb1c61108d8e6000c25b047dd..abbe35c33b0b94375bede6013006fbef918f2ec4 100644 (file)
@@ -3275,7 +3275,6 @@ fail:
 void journal_file_print_header(JournalFile *f) {
         char a[SD_ID128_STRING_MAX], b[SD_ID128_STRING_MAX], c[SD_ID128_STRING_MAX], d[SD_ID128_STRING_MAX];
         struct stat st;
-        char bytes[FORMAT_BYTES_MAX];
 
         assert(f);
         assert(f->header);
@@ -3356,7 +3355,7 @@ void journal_file_print_header(JournalFile *f) {
                        f->header->data_hash_chain_depth);
 
         if (fstat(f->fd, &st) >= 0)
-                printf("Disk usage: %s\n", format_bytes(bytes, sizeof(bytes), (uint64_t) st.st_blocks * 512ULL));
+                printf("Disk usage: %s\n", FORMAT_BYTES((uint64_t) st.st_blocks * 512ULL));
 }
 
 static int journal_file_warn_btrfs(JournalFile *f) {
@@ -3461,7 +3460,6 @@ int journal_file_open(
         if (DEBUG_LOGGING) {
                 static int last_seal = -1, last_compress = -1, last_keyed_hash = -1;
                 static uint64_t last_bytes = UINT64_MAX;
-                char bytes[FORMAT_BYTES_MAX];
 
                 if (last_seal != f->seal ||
                     last_keyed_hash != f->keyed_hash ||
@@ -3470,7 +3468,7 @@ int journal_file_open(
 
                         log_debug("Journal effective settings seal=%s keyed_hash=%s compress=%s compress_threshold_bytes=%s",
                                   yes_no(f->seal), yes_no(f->keyed_hash), yes_no(JOURNAL_FILE_COMPRESS(f)),
-                                  format_bytes(bytes, sizeof bytes, f->compress_threshold_bytes));
+                                  FORMAT_BYTES(f->compress_threshold_bytes));
                         last_seal = f->seal;
                         last_keyed_hash = f->keyed_hash;
                         last_compress = JOURNAL_FILE_COMPRESS(f);
@@ -3970,7 +3968,6 @@ void journal_reset_metrics(JournalMetrics *m) {
 }
 
 void journal_default_metrics(JournalMetrics *m, int fd) {
-        char a[FORMAT_BYTES_MAX], b[FORMAT_BYTES_MAX], c[FORMAT_BYTES_MAX], d[FORMAT_BYTES_MAX], e[FORMAT_BYTES_MAX];
         struct statvfs ss;
         uint64_t fs_size = 0;
 
@@ -4040,11 +4037,11 @@ void journal_default_metrics(JournalMetrics *m, int fd) {
                 m->n_max_files = DEFAULT_N_MAX_FILES;
 
         log_debug("Fixed min_use=%s max_use=%s max_size=%s min_size=%s keep_free=%s n_max_files=%" PRIu64,
-                  format_bytes(a, sizeof(a), m->min_use),
-                  format_bytes(b, sizeof(b), m->max_use),
-                  format_bytes(c, sizeof(c), m->max_size),
-                  format_bytes(d, sizeof(d), m->min_size),
-                  format_bytes(e, sizeof(e), m->keep_free),
+                  FORMAT_BYTES(m->min_use),
+                  FORMAT_BYTES(m->max_use),
+                  FORMAT_BYTES(m->max_size),
+                  FORMAT_BYTES(m->min_size),
+                  FORMAT_BYTES(m->keep_free),
                   m->n_max_files);
 }
 
index 494a54d33b16d761ccdf93573c0d1d858cd84f94..6d761b78ebd45653cc17b4c216d6c47a66c8d74f 100644 (file)
@@ -131,7 +131,6 @@ int journal_directory_vacuum(
         _cleanup_closedir_ DIR *d = NULL;
         struct vacuum_info *list = NULL;
         usec_t retention_limit = 0;
-        char sbytes[FORMAT_BYTES_MAX];
         struct dirent *de;
         int r;
 
@@ -148,7 +147,6 @@ int journal_directory_vacuum(
                 return -errno;
 
         FOREACH_DIRENT_ALL(de, d, r = -errno; goto finish) {
-
                 unsigned long long seqnum = 0, realtime;
                 _cleanup_free_ char *p = NULL;
                 sd_id128_t seqnum_id;
@@ -254,7 +252,7 @@ int journal_directory_vacuum(
                         if (r >= 0) {
 
                                 log_full(verbose ? LOG_INFO : LOG_DEBUG,
-                                         "Deleted empty archived journal %s/%s (%s).", directory, p, format_bytes(sbytes, sizeof(sbytes), size));
+                                         "Deleted empty archived journal %s/%s (%s).", directory, p, FORMAT_BYTES(size));
 
                                 freed += size;
                         } else if (r != -ENOENT)
@@ -296,7 +294,8 @@ int journal_directory_vacuum(
 
                 r = unlinkat_deallocate(dirfd(d), list[i].filename, 0);
                 if (r >= 0) {
-                        log_full(verbose ? LOG_INFO : LOG_DEBUG, "Deleted archived journal %s/%s (%s).", directory, list[i].filename, format_bytes(sbytes, sizeof(sbytes), list[i].usage));
+                        log_full(verbose ? LOG_INFO : LOG_DEBUG, "Deleted archived journal %s/%s (%s).",
+                                 directory, list[i].filename, FORMAT_BYTES(list[i].usage));
                         freed += list[i].usage;
 
                         if (list[i].usage < sum)
@@ -318,7 +317,8 @@ finish:
                 free(list[i].filename);
         free(list);
 
-        log_full(verbose ? LOG_INFO : LOG_DEBUG, "Vacuuming done, freed %s of archived journals from %s.", format_bytes(sbytes, sizeof(sbytes), freed), directory);
+        log_full(verbose ? LOG_INFO : LOG_DEBUG, "Vacuuming done, freed %s of archived journals from %s.",
+                 FORMAT_BYTES(freed), directory);
 
         return r;
 }
index f05179734b7b56af5e9ea7cb91cc29279009406d..06ca335cff96a7678b93debdbc5a049909dbbd17 100644 (file)
@@ -826,8 +826,6 @@ typedef struct ImageStatusInfo {
 } ImageStatusInfo;
 
 static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
-        char bs[FORMAT_BYTES_MAX];
-        char bs_exclusive[FORMAT_BYTES_MAX];
         const char *s1, *s2, *s3, *s4;
 
         assert(bus);
@@ -869,15 +867,15 @@ static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
         else if (s2)
                 printf("\tModified: %s\n", s2);
 
-        s3 = format_bytes(bs, sizeof(bs), i->usage);
-        s4 = i->usage_exclusive != i->usage ? format_bytes(bs_exclusive, sizeof(bs_exclusive), i->usage_exclusive) : NULL;
+        s3 = FORMAT_BYTES(i->usage);
+        s4 = i->usage_exclusive != i->usage ? FORMAT_BYTES(i->usage_exclusive) : NULL;
         if (s3 && s4)
                 printf("\t   Usage: %s (exclusive: %s)\n", s3, s4);
         else if (s3)
                 printf("\t   Usage: %s\n", s3);
 
-        s3 = format_bytes(bs, sizeof(bs), i->limit);
-        s4 = i->limit_exclusive != i->limit ? format_bytes(bs_exclusive, sizeof(bs_exclusive), i->limit_exclusive) : NULL;
+        s3 = FORMAT_BYTES(i->limit);
+        s4 = i->limit_exclusive != i->limit ? FORMAT_BYTES(i->limit_exclusive) : NULL;
         if (s3 && s4)
                 printf("\t   Limit: %s (exclusive: %s)\n", s3, s4);
         else if (s3)
@@ -936,16 +934,16 @@ typedef struct PoolStatusInfo {
 } PoolStatusInfo;
 
 static void print_pool_status_info(sd_bus *bus, PoolStatusInfo *i) {
-        char bs[FORMAT_BYTES_MAX], *s;
+        char *s;
 
         if (i->path)
                 printf("\t    Path: %s\n", i->path);
 
-        s = format_bytes(bs, sizeof(bs), i->usage);
+        s = FORMAT_BYTES(i->usage);
         if (s)
                 printf("\t   Usage: %s\n", s);
 
-        s = format_bytes(bs, sizeof(bs), i->limit);
+        s = FORMAT_BYTES(i->limit);
         if (s)
                 printf("\t   Limit: %s\n", s);
 }
@@ -2405,7 +2403,6 @@ static int clean_images(int argc, char *argv[], void *userdata) {
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         uint64_t usage, total = 0;
-        char fb[FORMAT_BYTES_MAX];
         sd_bus *bus = userdata;
         const char *name;
         unsigned c = 0;
@@ -2436,7 +2433,7 @@ static int clean_images(int argc, char *argv[], void *userdata) {
                         total = UINT64_MAX;
                 } else {
                         log_info("Removed image '%s'. Freed exclusive disk space: %s",
-                                 name, format_bytes(fb, sizeof(fb), usage));
+                                 name, FORMAT_BYTES(usage));
                         if (total != UINT64_MAX)
                                 total += usage;
                 }
@@ -2451,7 +2448,7 @@ static int clean_images(int argc, char *argv[], void *userdata) {
                 log_info("Removed %u images in total.", c);
         else
                 log_info("Removed %u images in total. Total freed exclusive disk space: %s.",
-                         c, format_bytes(fb, sizeof(fb), total));
+                         c, FORMAT_BYTES(total));
 
         return 0;
 }
index ddcceae697f9b330056ef09d2161a6cea1033e18..4bf7db8c3e4b5031a2402910de51a3eea0a8c387 100644 (file)
@@ -503,8 +503,6 @@ void oomd_update_cgroup_contexts_between_hashmaps(Hashmap *old_h, Hashmap *curr_
 }
 
 void oomd_dump_swap_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *prefix) {
-        char swap[FORMAT_BYTES_MAX];
-
         assert(ctx);
         assert(f);
 
@@ -513,7 +511,7 @@ void oomd_dump_swap_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const
                         "%sPath: %s\n"
                         "%s\tSwap Usage: %s\n",
                         strempty(prefix), ctx->path,
-                        strempty(prefix), format_bytes(swap, sizeof(swap), ctx->swap_usage));
+                        strempty(prefix), FORMAT_BYTES(ctx->swap_usage));
         else
                 fprintf(f,
                         "%sPath: %s\n"
@@ -523,7 +521,7 @@ void oomd_dump_swap_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const
 }
 
 void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *prefix) {
-        char mem_use[FORMAT_BYTES_MAX], mem_min[FORMAT_BYTES_MAX], mem_low[FORMAT_BYTES_MAX];
+        char mem_min[FORMAT_BYTES_MAX], mem_low[FORMAT_BYTES_MAX];
 
         assert(ctx);
         assert(f);
@@ -540,7 +538,7 @@ void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE
                 LOAD_INT(ctx->memory_pressure.avg60), LOAD_FRAC(ctx->memory_pressure.avg60),
                 LOAD_INT(ctx->memory_pressure.avg300), LOAD_FRAC(ctx->memory_pressure.avg300),
                 FORMAT_TIMESPAN(ctx->memory_pressure.total, USEC_PER_SEC),
-                strempty(prefix), format_bytes(mem_use, sizeof(mem_use), ctx->current_memory_usage));
+                strempty(prefix), FORMAT_BYTES(ctx->current_memory_usage));
 
         if (!empty_or_root(ctx->path))
                 fprintf(f,
@@ -555,9 +553,6 @@ void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE
 }
 
 void oomd_dump_system_context(const OomdSystemContext *ctx, FILE *f, const char *prefix) {
-        char mem_used[FORMAT_BYTES_MAX], mem_total[FORMAT_BYTES_MAX];
-        char swap_used[FORMAT_BYTES_MAX], swap_total[FORMAT_BYTES_MAX];
-
         assert(ctx);
         assert(f);
 
@@ -565,9 +560,9 @@ void oomd_dump_system_context(const OomdSystemContext *ctx, FILE *f, const char
                 "%sMemory: Used: %s Total: %s\n"
                 "%sSwap: Used: %s Total: %s\n",
                 strempty(prefix),
-                format_bytes(mem_used, sizeof(mem_used), ctx->mem_used),
-                format_bytes(mem_total, sizeof(mem_total), ctx->mem_total),
+                FORMAT_BYTES(ctx->mem_used),
+                FORMAT_BYTES(ctx->mem_total),
                 strempty(prefix),
-                format_bytes(swap_used, sizeof(swap_used), ctx->swap_used),
-                format_bytes(swap_total, sizeof(swap_total), ctx->swap_total));
+                FORMAT_BYTES(ctx->swap_used),
+                FORMAT_BYTES(ctx->swap_total));
 }
index 15c56d058437d7c33ac19c9a3f2e60857b4274b1..0497c6cfc602ba5ba7d00e7d030123acfb7044ce 100644 (file)
@@ -197,7 +197,6 @@ static int run(int argc, char *argv[]) {
         _cleanup_close_ int mountfd = -1, devfd = -1;
         _cleanup_free_ char *devpath = NULL;
         uint64_t size, newsize;
-        char fb[FORMAT_BYTES_MAX];
         dev_t devno;
         int r;
 
@@ -248,11 +247,11 @@ static int run(int argc, char *argv[]) {
         if (newsize == size)
                 log_info("Successfully resized \"%s\" to %s bytes.",
                          arg_target,
-                         format_bytes(fb, sizeof fb, newsize));
+                         FORMAT_BYTES(newsize));
         else
                 log_info("Successfully resized \"%s\" to %s bytes (%"PRIu64" bytes lost due to blocksize).",
                          arg_target,
-                         format_bytes(fb, sizeof fb, newsize),
+                         FORMAT_BYTES(newsize),
                          size - newsize);
         return 0;
 }
index ac317f6adca3a0c809401fa7e24e78b61e45f6f1..6d535a3bab05334bb655d53f34efee7314deaac0 100644 (file)
@@ -1932,29 +1932,24 @@ static void context_unload_partition_table(Context *context) {
 }
 
 static int format_size_change(uint64_t from, uint64_t to, char **ret) {
-        char format_buffer1[FORMAT_BYTES_MAX], format_buffer2[FORMAT_BYTES_MAX], *buf;
-
-        if (from != UINT64_MAX)
-                format_bytes(format_buffer1, sizeof(format_buffer1), from);
-        if (to != UINT64_MAX)
-                format_bytes(format_buffer2, sizeof(format_buffer2), to);
+        char *t;
 
         if (from != UINT64_MAX) {
                 if (from == to || to == UINT64_MAX)
-                        buf = strdup(format_buffer1);
+                        t = strdup(FORMAT_BYTES(from));
                 else
-                        buf = strjoin(format_buffer1, " ", special_glyph(SPECIAL_GLYPH_ARROW), " ", format_buffer2);
+                        t = strjoin(FORMAT_BYTES(from), " ", special_glyph(SPECIAL_GLYPH_ARROW), " ", FORMAT_BYTES(to));
         } else if (to != UINT64_MAX)
-                buf = strjoin(special_glyph(SPECIAL_GLYPH_ARROW), " ", format_buffer2);
+                t = strjoin(special_glyph(SPECIAL_GLYPH_ARROW), " ", FORMAT_BYTES(to));
         else {
                 *ret = NULL;
                 return 0;
         }
 
-        if (!buf)
+        if (!t)
                 return log_oom();
 
-        *ret = TAKE_PTR(buf);
+        *ret = t;
         return 1;
 }
 
@@ -2051,11 +2046,10 @@ static int context_dump_partitions(Context *context, const char *node) {
         }
 
         if ((arg_json_format_flags & JSON_FORMAT_OFF) && (sum_padding > 0 || sum_size > 0)) {
-                char s[FORMAT_BYTES_MAX];
                 const char *a, *b;
 
-                a = strjoina(special_glyph(SPECIAL_GLYPH_SIGMA), " = ", format_bytes(s, sizeof(s), sum_size));
-                b = strjoina(special_glyph(SPECIAL_GLYPH_SIGMA), " = ", format_bytes(s, sizeof(s), sum_padding));
+                a = strjoina(special_glyph(SPECIAL_GLYPH_SIGMA), " = ", FORMAT_BYTES(sum_size));
+                b = strjoina(special_glyph(SPECIAL_GLYPH_SIGMA), " = ", FORMAT_BYTES(sum_padding));
 
                 r = table_add_many(
                                 t,
@@ -2734,7 +2728,6 @@ static int context_copy_blocks(Context *context) {
                 _cleanup_(loop_device_unrefp) LoopDevice *d = NULL;
                 _cleanup_free_ char *encrypted = NULL;
                 _cleanup_close_ int encrypted_dev_fd = -1;
-                char buf[FORMAT_BYTES_MAX];
                 int target_fd;
 
                 if (p->copy_blocks_fd < 0)
@@ -2777,7 +2770,8 @@ static int context_copy_blocks(Context *context) {
                         target_fd = whole_fd;
                 }
 
-                log_info("Copying in '%s' (%s) on block level into future partition %" PRIu64 ".", p->copy_blocks_path, format_bytes(buf, sizeof(buf), p->copy_blocks_size), p->partno);
+                log_info("Copying in '%s' (%s) on block level into future partition %" PRIu64 ".",
+                         p->copy_blocks_path, FORMAT_BYTES(p->copy_blocks_size), p->partno);
 
                 r = copy_bytes_full(p->copy_blocks_fd, target_fd, p->copy_blocks_size, 0, NULL, NULL, NULL, NULL);
                 if (r < 0)
@@ -4637,7 +4631,6 @@ static int resize_backing_fd(
                 const char *backing_file,   /* If the above refers to a loopback device, the backing regular file for that, which we can grow */
                 LoopDevice *loop_device) {
 
-        char buf1[FORMAT_BYTES_MAX], buf2[FORMAT_BYTES_MAX];
         _cleanup_close_ int writable_fd = -1;
         uint64_t current_size;
         struct stat st;
@@ -4678,11 +4671,9 @@ static int resize_backing_fd(
                 current_size = st.st_size;
         }
 
-        assert_se(format_bytes(buf1, sizeof(buf1), current_size));
-        assert_se(format_bytes(buf2, sizeof(buf2), arg_size));
-
         if (current_size >= arg_size) {
-                log_info("File '%s' already is of requested size or larger, not growing. (%s >= %s)", node, buf1, buf2);
+                log_info("File '%s' already is of requested size or larger, not growing. (%s >= %s)",
+                         node, FORMAT_BYTES(current_size), FORMAT_BYTES(arg_size));
                 return 0;
         }
 
@@ -4705,7 +4696,8 @@ static int resize_backing_fd(
 
                 if ((uint64_t) st.st_size != current_size)
                         return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                               "Size of backing file '%s' of loopback block device '%s' don't match, refusing.", node, backing_file);
+                                               "Size of backing file '%s' of loopback block device '%s' don't match, refusing.",
+                                               node, backing_file);
         } else {
                 assert(S_ISREG(st.st_mode));
                 assert(!backing_file);
@@ -4723,15 +4715,16 @@ static int resize_backing_fd(
                 if (fallocate(writable_fd, 0, 0, arg_size) < 0) {
                         if (!ERRNO_IS_NOT_SUPPORTED(errno))
                                 return log_error_errno(errno, "Failed to grow '%s' from %s to %s by allocation: %m",
-                                                       node, buf1, buf2);
+                                                       node, FORMAT_BYTES(current_size), FORMAT_BYTES(arg_size));
 
                         /* Fallback to truncation, if fallocate() is not supported. */
                         log_debug("Backing file system does not support fallocate(), falling back to ftruncate().");
                 } else {
                         if (current_size == 0) /* Likely regular file just created by us */
-                                log_info("Allocated %s for '%s'.", buf2, node);
+                                log_info("Allocated %s for '%s'.", FORMAT_BYTES(arg_size), node);
                         else
-                                log_info("File '%s' grown from %s to %s by allocation.", node, buf1, buf2);
+                                log_info("File '%s' grown from %s to %s by allocation.",
+                                         node, FORMAT_BYTES(current_size), FORMAT_BYTES(arg_size));
 
                         goto done;
                 }
@@ -4739,12 +4732,13 @@ static int resize_backing_fd(
 
         if (ftruncate(writable_fd, arg_size) < 0)
                 return log_error_errno(errno, "Failed to grow '%s' from %s to %s by truncation: %m",
-                                       node, buf1, buf2);
+                                       node, FORMAT_BYTES(current_size), FORMAT_BYTES(arg_size));
 
         if (current_size == 0) /* Likely regular file just created by us */
-                log_info("Sized '%s' to %s.", node, buf2);
+                log_info("Sized '%s' to %s.", node, FORMAT_BYTES(arg_size));
         else
-                log_info("File '%s' grown from %s to %s by truncation.", node, buf1, buf2);
+                log_info("File '%s' grown from %s to %s by truncation.",
+                         node, FORMAT_BYTES(current_size), FORMAT_BYTES(arg_size));
 
 done:
         r = resize_pt(writable_fd);
@@ -4762,7 +4756,6 @@ done:
 
 static int determine_auto_size(Context *c) {
         uint64_t sum = round_up_size(GPT_METADATA_SIZE, 4096);
-        char buf[FORMAT_BYTES_MAX];
         Partition *p;
 
         assert_se(c);
@@ -4780,13 +4773,14 @@ static int determine_auto_size(Context *c) {
                 sum += m;
         }
 
-        assert_se(format_bytes(buf, sizeof(buf), sum));
-        if (c->total != UINT64_MAX) { /* Image already allocated? Then show its size */
-                char buf2[FORMAT_BYTES_MAX];
-                assert_se(format_bytes(buf2, sizeof(buf2), c->total));
-                log_info("Automatically determined minimal disk image size as %s, current image size is %s.", buf, buf2);
-        } else /* If the image is being created right now, then it has no previous size, suppress any comment about it hence */
-                log_info("Automatically determined minimal disk image size as %s.", buf);
+        if (c->total != UINT64_MAX)
+                /* Image already allocated? Then show its size. */
+                log_info("Automatically determined minimal disk image size as %s, current image size is %s.",
+                         FORMAT_BYTES(sum), FORMAT_BYTES(c->total));
+        else
+                /* If the image is being created right now, then it has no previous size, suppress any comment about it hence. */
+                log_info("Automatically determined minimal disk image size as %s.",
+                         FORMAT_BYTES(sum));
 
         arg_size = sum;
         return 0;
@@ -4962,11 +4956,9 @@ static int run(int argc, char *argv[]) {
                         break; /* Success! */
 
                 if (!context_drop_one_priority(context)) {
-                        char buf[FORMAT_BYTES_MAX];
                         r = log_error_errno(SYNTHETIC_ERRNO(ENOSPC),
                                             "Can't fit requested partitions into available free space (%s), refusing.",
-                                            format_bytes(buf, sizeof(buf), largest_free_area));
-
+                                            FORMAT_BYTES(largest_free_area));
                         determine_auto_size(context);
                         return r;
                 }
index 7378658ce9d34e2f659617bad112e45cb100831b..344c8f66412f2098a6a794bd370bddfbbdf82f29 100644 (file)
@@ -1330,22 +1330,17 @@ static int start_transient_service(
                                 log_info("CPU time consumed: %s",
                                          FORMAT_TIMESPAN(DIV_ROUND_UP(c.cpu_usage_nsec, NSEC_PER_USEC), USEC_PER_MSEC));
 
-                        if (c.ip_ingress_bytes != UINT64_MAX) {
-                                char bytes[FORMAT_BYTES_MAX];
-                                log_info("IP traffic received: %s", format_bytes(bytes, sizeof bytes, c.ip_ingress_bytes));
-                        }
-                        if (c.ip_egress_bytes != UINT64_MAX) {
-                                char bytes[FORMAT_BYTES_MAX];
-                                log_info("IP traffic sent: %s", format_bytes(bytes, sizeof bytes, c.ip_egress_bytes));
-                        }
-                        if (c.io_read_bytes != UINT64_MAX) {
-                                char bytes[FORMAT_BYTES_MAX];
-                                log_info("IO bytes read: %s", format_bytes(bytes, sizeof bytes, c.io_read_bytes));
-                        }
-                        if (c.io_write_bytes != UINT64_MAX) {
-                                char bytes[FORMAT_BYTES_MAX];
-                                log_info("IO bytes written: %s", format_bytes(bytes, sizeof bytes, c.io_write_bytes));
-                        }
+                        if (c.ip_ingress_bytes != UINT64_MAX)
+                                log_info("IP traffic received: %s", FORMAT_BYTES(c.ip_ingress_bytes));
+
+                        if (c.ip_egress_bytes != UINT64_MAX)
+                                log_info("IP traffic sent: %s", FORMAT_BYTES(c.ip_egress_bytes));
+
+                        if (c.io_read_bytes != UINT64_MAX)
+                                log_info("IO bytes read: %s", FORMAT_BYTES(c.io_read_bytes));
+
+                        if (c.io_write_bytes != UINT64_MAX)
+                                log_info("IO bytes written: %s", FORMAT_BYTES(c.io_write_bytes));
                 }
 
                 /* Try to propagate the service's return value. But if the service defines
index ddb6ea147a16a4a65abf84782beb1af8b88a97e5..27b9ac9569e7674e094b2cbcffc8fc85e15219b3 100644 (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;
index e63c59bd94e324b686a42b1d6986a941ac0c677f..3165cf29da13a4eed73c46e35be64a2e420a6223 100644 (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)
index b50c6185daf38a583c6f2aed41137d5ffffd7ec6..29aa5c0c7c4abbc68ec04fe673b31915c461ba2a 100644 (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);
index 621631c6010e2a23d618c6133a7b7af98555279a..00b6948cdf74ddd94e408101be0dafe6fb13099c 100644 (file)
@@ -644,21 +644,15 @@ static void print_status_info(
         if (i->status_errno > 0)
                 printf("      Error: %i (%s)\n", i->status_errno, strerror_safe(i->status_errno));
 
-        if (i->ip_ingress_bytes != UINT64_MAX && i->ip_egress_bytes != UINT64_MAX) {
-                char buf_in[FORMAT_BYTES_MAX], buf_out[FORMAT_BYTES_MAX];
-
+        if (i->ip_ingress_bytes != UINT64_MAX && i->ip_egress_bytes != UINT64_MAX)
                 printf("         IP: %s in, %s out\n",
-                        format_bytes(buf_in, sizeof(buf_in), i->ip_ingress_bytes),
-                        format_bytes(buf_out, sizeof(buf_out), i->ip_egress_bytes));
-        }
-
-        if (i->io_read_bytes != UINT64_MAX && i->io_write_bytes != UINT64_MAX) {
-                char buf_in[FORMAT_BYTES_MAX], buf_out[FORMAT_BYTES_MAX];
+                       FORMAT_BYTES(i->ip_ingress_bytes),
+                       FORMAT_BYTES(i->ip_egress_bytes));
 
+        if (i->io_read_bytes != UINT64_MAX && i->io_write_bytes != UINT64_MAX)
                 printf("         IO: %s read, %s written\n",
-                        format_bytes(buf_in, sizeof(buf_in), i->io_read_bytes),
-                        format_bytes(buf_out, sizeof(buf_out), i->io_write_bytes));
-        }
+                        FORMAT_BYTES(i->io_read_bytes),
+                        FORMAT_BYTES(i->io_write_bytes));
 
         if (i->tasks_current != UINT64_MAX) {
                 printf("      Tasks: %" PRIu64, i->tasks_current);
@@ -670,15 +664,14 @@ static void print_status_info(
         }
 
         if (i->memory_current != UINT64_MAX) {
-                char buf[FORMAT_BYTES_MAX];
-
-                printf("     Memory: %s", format_bytes(buf, sizeof(buf), i->memory_current));
+                printf("     Memory: %s", FORMAT_BYTES(i->memory_current));
 
                 if (i->memory_min > 0 || i->memory_low > 0 ||
                     i->memory_high != CGROUP_LIMIT_MAX || i->memory_max != CGROUP_LIMIT_MAX ||
                     i->memory_swap_max != CGROUP_LIMIT_MAX ||
                     i->memory_available != CGROUP_LIMIT_MAX ||
                     i->memory_limit != CGROUP_LIMIT_MAX) {
+                        char buf[FORMAT_BYTES_MAX];
                         const char *prefix = "";
 
                         printf(" (");
@@ -691,23 +684,23 @@ static void print_status_info(
                                 prefix = " ";
                         }
                         if (i->memory_high != CGROUP_LIMIT_MAX) {
-                                printf("%shigh: %s", prefix, format_bytes(buf, sizeof(buf), i->memory_high));
+                                printf("%shigh: %s", prefix, FORMAT_BYTES(i->memory_high));
                                 prefix = " ";
                         }
                         if (i->memory_max != CGROUP_LIMIT_MAX) {
-                                printf("%smax: %s", prefix, format_bytes(buf, sizeof(buf), i->memory_max));
+                                printf("%smax: %s", prefix, FORMAT_BYTES(i->memory_max));
                                 prefix = " ";
                         }
                         if (i->memory_swap_max != CGROUP_LIMIT_MAX) {
-                                printf("%sswap max: %s", prefix, format_bytes(buf, sizeof(buf), i->memory_swap_max));
+                                printf("%sswap max: %s", prefix, FORMAT_BYTES(i->memory_swap_max));
                                 prefix = " ";
                         }
                         if (i->memory_limit != CGROUP_LIMIT_MAX) {
-                                printf("%slimit: %s", prefix, format_bytes(buf, sizeof(buf), i->memory_limit));
+                                printf("%slimit: %s", prefix, FORMAT_BYTES(i->memory_limit));
                                 prefix = " ";
                         }
                         if (i->memory_available != CGROUP_LIMIT_MAX) {
-                                printf("%savailable: %s", prefix, format_bytes(buf, sizeof(buf), i->memory_available));
+                                printf("%savailable: %s", prefix, FORMAT_BYTES(i->memory_available));
                                 prefix = " ";
                         }
                         printf(")");
index 829fc24c3837669cebb029baccd6e3669a3bfed6..77ec80190313556a3ab7c5edc81c82b73f543acb 100644 (file)
@@ -18,7 +18,6 @@ int main(int argc, char *argv[]) {
         if (fd < 0)
                 log_error_errno(errno, "Failed to open root directory: %m");
         else {
-                char bs[FORMAT_BYTES_MAX];
                 BtrfsSubvolInfo info;
 
                 r = btrfs_subvol_get_info_fd(fd, 0, &info);
@@ -33,10 +32,10 @@ int main(int argc, char *argv[]) {
                 if (r < 0)
                         log_error_errno(r, "Failed to get quota info: %m");
                 else {
-                        log_info("referenced: %s", strna(format_bytes(bs, sizeof(bs), quota.referenced)));
-                        log_info("exclusive: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive)));
-                        log_info("referenced_max: %s", strna(format_bytes(bs, sizeof(bs), quota.referenced_max)));
-                        log_info("exclusive_max: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive_max)));
+                        log_info("referenced: %s", strna(FORMAT_BYTES(quota.referenced)));
+                        log_info("exclusive: %s", strna(FORMAT_BYTES(quota.exclusive)));
+                        log_info("referenced_max: %s", strna(FORMAT_BYTES(quota.referenced_max)));
+                        log_info("exclusive_max: %s", strna(FORMAT_BYTES(quota.exclusive_max)));
                 }
 
                 r = btrfs_subvol_get_read_only_fd(fd);
index 42d6884e188fff5f1d0aaaf830a76ef8eb8b6004..a961436b40a6a2b29983e001064f2f77f19f721d 100644 (file)
@@ -9,7 +9,6 @@
 #include "tests.h"
 
 int main(int argc, char *argv[]) {
-        char buf[FORMAT_BYTES_MAX];
         nsec_t nsec;
         uint64_t v;
         int r;
@@ -21,7 +20,7 @@ int main(int argc, char *argv[]) {
         log_info("Current system CPU time: %s", FORMAT_TIMESPAN(nsec/NSEC_PER_USEC, 1));
 
         assert_se(procfs_memory_get_used(&v) >= 0);
-        log_info("Current memory usage: %s", format_bytes(buf, sizeof(buf), v));
+        log_info("Current memory usage: %s", FORMAT_BYTES(v));
 
         assert_se(procfs_tasks_get_current(&v) >= 0);
         log_info("Current number of tasks: %" PRIu64, v);
index 3eef2c30198dfd1bb1a1b7bb4d2713ebc9c2a06f..fa36f54fcb9dc536582d4dc535269416259b4e1e 100644 (file)
@@ -321,7 +321,6 @@ static void test_raw_clone(void) {
 
 static void test_physical_memory(void) {
         uint64_t p;
-        char buf[FORMAT_BYTES_MAX];
 
         log_info("/* %s */", __func__);
 
@@ -330,7 +329,7 @@ static void test_physical_memory(void) {
         assert_se(p < UINT64_MAX);
         assert_se(p % page_size() == 0);
 
-        log_info("Memory: %s (%" PRIu64 ")", format_bytes(buf, sizeof(buf), p), p);
+        log_info("Memory: %s (%" PRIu64 ")", FORMAT_BYTES(p), p);
 }
 
 static void test_physical_memory_scale(void) {