summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-09 08:40:24 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-12 15:51:24 +0100
commit4f05a11c553580b370f9884f66b01ecfbd9f56a7 (patch)
treeb98fef529f60595a962ced4e3cfcf50d42eba3be
parent8e93a614e7c20ee28f1d3b4aa51c0e4200aa2c52 (diff)
downloadsystemd-4f05a11c553580b370f9884f66b01ecfbd9f56a7.tar.gz
makefs: supress mkfs output, but print one line on success
$ for i in ext2 ext3 ext4 btrfs xfs vfat swap minix; do echo $i && wipefs -q -a /var/tmp/test2_img && build/systemd-makefs $i /var/tmp/test2_img done ext2 /var/tmp/test2_img successfully formatted as ext2 (label "test2_img", uuid ad584a5b-037b-497a-825d-eaf2ba90da2d) ext3 /var/tmp/test2_img successfully formatted as ext3 (label "test2_img", uuid 95239fff-55f4-44d5-bae0-11ef75d13166) ext4 /var/tmp/test2_img successfully formatted as ext4 (label "test2_img", uuid 8c7ea699-05ab-4ce6-8df6-bc20d53dfd29) btrfs /var/tmp/test2_img successfully formatted as btrfs (label "test2_img", uuid 860bb061-4d92-4607-8821-a9d00216490e) xfs /var/tmp/test2_img successfully formatted as xfs (label "test2_img", uuid f32499ea-7311-47bb-be57-da62e51d33ae) vfat mkfs.fat 4.2 (2021-01-31) /var/tmp/test2_img successfully formatted as vfat (label "TEST2_IMG", uuid d1e4ae63) swap mkswap: /var/tmp/test2_img: insecure permissions 0644, fix with: chmod 0600 /var/tmp/test2_img mkswap: /var/tmp/test2_img contains holes or other unsupported extents. This swap file can be rejected by kernel on swap activation! Use --verbose for more details. Setting up swapspace version 1, size = 256 MiB (268431360 bytes) LABEL=test2_img, UUID=16bc3d8c-98d4-462b-8ff8-338467cde871 /var/tmp/test2_img successfully formatted as swap (no label or uuid specified) minix 21856 inodes 65535 blocks Firstdatazone=696 (696) Zonesize=1024 Maxsize=268966912 /var/tmp/test2_img successfully formatted as minix (no label or uuid specified)
-rw-r--r--src/partition/makefs.c2
-rw-r--r--src/shared/mkfs-util.c64
2 files changed, 44 insertions, 22 deletions
diff --git a/src/partition/makefs.c b/src/partition/makefs.c
index 7c94fbfedb..b6979b7e4f 100644
--- a/src/partition/makefs.c
+++ b/src/partition/makefs.c
@@ -49,7 +49,7 @@ static int run(int argc, char *argv[]) {
if (lock_fd < 0)
return log_error_errno(lock_fd, "Failed to lock whole block device of \"%s\": %m", device);
} else
- log_info("%s is not a block device.", device);
+ log_debug("%s is not a block device, no need to lock.", device);
r = probe_filesystem(device, &detected);
if (r == -EUCLEAN)
diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c
index 1056de1bec..fbf04aa7ae 100644
--- a/src/shared/mkfs-util.c
+++ b/src/shared/mkfs-util.c
@@ -39,6 +39,8 @@ int make_filesystem(
bool discard) {
_cleanup_free_ char *mkfs = NULL;
+ char mangled_label[8 + 3 + 1],
+ vol_id[CONST_MAX(ID128_UUID_STRING_MAX, 8 + 1)] = {};
int r;
assert(node);
@@ -63,15 +65,35 @@ int make_filesystem(
return log_oom();
}
+ if (streq(fstype, "vfat")) {
+ /* Classic FAT only allows 11 character uppercase labels */
+ strncpy(mangled_label, label, sizeof(mangled_label)-1);
+ mangled_label[sizeof(mangled_label)-1] = 0;
+ ascii_strupper(mangled_label);
+ label = mangled_label;
+
+ xsprintf(vol_id, "%08" PRIx32,
+ ((uint32_t) uuid.bytes[0] << 24) |
+ ((uint32_t) uuid.bytes[1] << 16) |
+ ((uint32_t) uuid.bytes[2] << 8) |
+ ((uint32_t) uuid.bytes[3])); /* Take first 32 bytes of UUID */
+ }
+
+ if (isempty(vol_id))
+ id128_to_uuid_string(uuid, vol_id);
+
r = safe_fork("(mkfs)", FORK_RESET_SIGNALS|FORK_RLIMIT_NOFILE_SAFE|FORK_DEATHSIG|FORK_LOG|FORK_WAIT|FORK_STDOUT_TO_STDERR, NULL);
if (r < 0)
return r;
if (r == 0) {
/* Child */
+
+ /* When changing this conditional, also adjust the log statement below. */
if (streq(fstype, "ext2"))
(void) execlp(mkfs, mkfs,
+ "-q",
"-L", label,
- "-U", ID128_TO_UUID_STRING(uuid),
+ "-U", vol_id,
"-I", "256",
"-m", "0",
"-E", discard ? "discard,lazy_itable_init=1" : "nodiscard,lazy_itable_init=1",
@@ -79,8 +101,9 @@ int make_filesystem(
else if (STR_IN_SET(fstype, "ext3", "ext4"))
(void) execlp(mkfs, mkfs,
+ "-q",
"-L", label,
- "-U", ID128_TO_UUID_STRING(uuid),
+ "-U", vol_id,
"-I", "256",
"-O", "has_journal",
"-m", "0",
@@ -89,8 +112,9 @@ int make_filesystem(
else if (streq(fstype, "btrfs")) {
(void) execlp(mkfs, mkfs,
+ "-q",
"-L", label,
- "-U", ID128_TO_UUID_STRING(uuid),
+ "-U", vol_id,
node,
discard ? NULL : "--nodiscard",
NULL);
@@ -98,9 +122,10 @@ int make_filesystem(
} else if (streq(fstype, "xfs")) {
const char *j;
- j = strjoina("uuid=", ID128_TO_UUID_STRING(uuid));
+ j = strjoina("uuid=", vol_id);
(void) execlp(mkfs, mkfs,
+ "-q",
"-L", label,
"-m", j,
"-m", "reflink=1",
@@ -108,34 +133,24 @@ int make_filesystem(
discard ? NULL : "-K",
NULL);
- } else if (streq(fstype, "vfat")) {
- char mangled_label[8 + 3 + 1], vol_id[8 + 1];
-
- /* Classic FAT only allows 11 character uppercase labels */
- strncpy(mangled_label, label, sizeof(mangled_label)-1);
- mangled_label[sizeof(mangled_label)-1] = 0;
- ascii_strupper(mangled_label);
-
- xsprintf(vol_id, "%08" PRIx32,
- ((uint32_t) uuid.bytes[0] << 24) |
- ((uint32_t) uuid.bytes[1] << 16) |
- ((uint32_t) uuid.bytes[2] << 8) |
- ((uint32_t) uuid.bytes[3])); /* Take first 32 byte of UUID */
+ } else if (streq(fstype, "vfat"))
(void) execlp(mkfs, mkfs,
"-i", vol_id,
- "-n", mangled_label,
+ "-n", label,
"-F", "32", /* yes, we force FAT32 here */
node, NULL);
- } else if (streq(fstype, "swap")) {
+ else if (streq(fstype, "swap"))
+ /* TODO: add --quiet here if
+ * https://github.com/util-linux/util-linux/issues/1499 resolved. */
(void) execlp(mkfs, mkfs,
"-L", label,
- "-U", ID128_TO_UUID_STRING(uuid),
+ "-U", vol_id,
node, NULL);
- } else
+ else
/* Generic fallback for all other file systems */
(void) execlp(mkfs, mkfs, node, NULL);
@@ -144,5 +159,12 @@ int make_filesystem(
_exit(EXIT_FAILURE);
}
+ if (STR_IN_SET(fstype, "ext2", "ext3", "ext4", "btrfs", "xfs", "vfat", "swap"))
+ log_info("%s successfully formatted as %s (label \"%s\", uuid %s)",
+ node, fstype, label, vol_id);
+ else
+ log_info("%s successfully formatted as %s (no label or uuid specified)",
+ node, fstype);
+
return 0;
}