#include "fd-util.h"
#include "main-func.h"
#include "mkfs-util.h"
+#include "path-util.h"
#include "process-util.h"
#include "signal-util.h"
#include "string-util.h"
static int run(int argc, char *argv[]) {
- _cleanup_free_ char *device = NULL, *fstype = NULL, *detected = NULL;
+ _cleanup_free_ char *device = NULL, *fstype = NULL, *detected = NULL, *label = NULL;
_cleanup_close_ int lock_fd = -EBADF;
sd_id128_t uuid;
struct stat st;
if (r < 0)
return log_error_errno(r, "Failed to generate UUID for file system: %m");
- return make_filesystem(device, fstype, basename(device), NULL, uuid, true, NULL);
+ r = path_extract_filename(device, &label);
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract file name from '%s': %m", device);
+
+ return make_filesystem(device, fstype, label, NULL, uuid, true, NULL);
}
DEFINE_MAIN_FUNCTION(run);
/* Tries really hard to find a suitable description for this partition */
- if (p->definition_path) {
- buf = strdup(basename(p->definition_path));
- goto done;
- }
+ if (p->definition_path)
+ return path_extract_filename(p->definition_path, ret);
label = partition_label(p);
if (!isempty(label)) {