summaryrefslogtreecommitdiff
path: root/src/partition/makefs.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-07-29 19:10:33 +0200
committerLennart Poettering <lennart@poettering.net>2020-08-24 22:00:07 +0200
commitda49710ef25887491861405c5bda9ee38946746c (patch)
tree6b77df5d119e16f1f1b0f74f0c313181a2395365 /src/partition/makefs.c
parentc95f9a2351ffd63b53a4c33fb683606e43677c89 (diff)
downloadsystemd-da49710ef25887491861405c5bda9ee38946746c.tar.gz
makefs: port to generic make_filesystem() call
Diffstat (limited to 'src/partition/makefs.c')
-rw-r--r--src/partition/makefs.c41
1 files changed, 10 insertions, 31 deletions
diff --git a/src/partition/makefs.c b/src/partition/makefs.c
index 97f50c9033..1ce6acd01e 100644
--- a/src/partition/makefs.c
+++ b/src/partition/makefs.c
@@ -11,40 +11,15 @@
#include "dissect-image.h"
#include "fd-util.h"
#include "main-func.h"
+#include "mkfs-util.h"
#include "process-util.h"
#include "signal-util.h"
#include "string-util.h"
-static int makefs(const char *type, const char *device) {
- const char *mkfs;
- pid_t pid;
- int r;
-
- if (streq(type, "swap"))
- mkfs = "/sbin/mkswap";
- else
- mkfs = strjoina("/sbin/mkfs.", type);
- if (access(mkfs, X_OK) != 0)
- return log_error_errno(errno, "%s is not executable: %m", mkfs);
-
- r = safe_fork("(mkfs)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pid);
- if (r < 0)
- return r;
- if (r == 0) {
- const char *cmdline[3] = { mkfs, device, NULL };
-
- /* Child */
-
- execv(cmdline[0], (char**) cmdline);
- _exit(EXIT_FAILURE);
- }
-
- return wait_for_terminate_and_check(mkfs, pid, WAIT_LOG);
-}
-
static int run(int argc, char *argv[]) {
- _cleanup_free_ char *device = NULL, *type = NULL, *detected = NULL;
+ _cleanup_free_ char *device = NULL, *fstype = NULL, *detected = NULL;
_cleanup_close_ int lock_fd = -1;
+ sd_id128_t uuid;
struct stat st;
int r;
@@ -55,8 +30,8 @@ static int run(int argc, char *argv[]) {
"This program expects two arguments.");
/* type and device must be copied because makefs calls safe_fork, which clears argv[] */
- type = strdup(argv[1]);
- if (!type)
+ fstype = strdup(argv[1]);
+ if (!fstype)
return log_oom();
device = strdup(argv[2]);
@@ -85,7 +60,11 @@ static int run(int argc, char *argv[]) {
return 0;
}
- return makefs(type, device);
+ r = sd_id128_randomize(&uuid);
+ if (r < 0)
+ return log_error_errno(r, "Failed to generate UUID for file system: %m");
+
+ return make_filesystem(device, fstype, basename(device), uuid, true);
}
DEFINE_MAIN_FUNCTION(run);