]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/mkfs-util.c
Reflect the fact that main config files can be installed in /usr
[thirdparty/systemd.git] / src / shared / mkfs-util.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <sys/mount.h>
4 #include <unistd.h>
5
6 #include "dirent-util.h"
7 #include "fd-util.h"
8 #include "fileio.h"
9 #include "fs-util.h"
10 #include "id128-util.h"
11 #include "mkfs-util.h"
12 #include "mount-util.h"
13 #include "mountpoint-util.h"
14 #include "path-util.h"
15 #include "process-util.h"
16 #include "recurse-dir.h"
17 #include "rm-rf.h"
18 #include "stat-util.h"
19 #include "stdio-util.h"
20 #include "string-util.h"
21 #include "tmpfile-util.h"
22 #include "utf8.h"
23
24 int mkfs_exists(const char *fstype) {
25 const char *mkfs;
26 int r;
27
28 assert(fstype);
29
30 if (STR_IN_SET(fstype, "auto", "swap")) /* these aren't real file system types, refuse early */
31 return -EINVAL;
32
33 mkfs = strjoina("mkfs.", fstype);
34 if (!filename_is_valid(mkfs)) /* refuse file system types with slashes and similar */
35 return -EINVAL;
36
37 r = find_executable(mkfs, NULL);
38 if (r == -ENOENT)
39 return false;
40 if (r < 0)
41 return r;
42
43 return true;
44 }
45
46 int mkfs_supports_root_option(const char *fstype) {
47 return fstype_is_ro(fstype) || STR_IN_SET(fstype, "ext2", "ext3", "ext4", "btrfs", "vfat", "xfs");
48 }
49
50 static int mangle_linux_fs_label(const char *s, size_t max_len, char **ret) {
51 /* Not more than max_len bytes (12 or 16) */
52
53 assert(s);
54 assert(max_len > 0);
55 assert(ret);
56
57 const char *q;
58 char *ans;
59
60 for (q = s; *q;) {
61 int l;
62
63 l = utf8_encoded_valid_unichar(q, SIZE_MAX);
64 if (l < 0)
65 return l;
66
67 if ((size_t) (q - s + l) > max_len)
68 break;
69 q += l;
70 }
71
72 ans = memdup_suffix0(s, q - s);
73 if (!ans)
74 return -ENOMEM;
75
76 *ret = ans;
77 return 0;
78 }
79
80 static int mangle_fat_label(const char *s, char **ret) {
81 assert(s);
82
83 _cleanup_free_ char *q = NULL;
84 int r;
85
86 r = utf8_to_ascii(s, '_', &q);
87 if (r < 0)
88 return r;
89
90 /* Classic FAT only allows 11 character uppercase labels */
91 strshorten(q, 11);
92 ascii_strupper(q);
93
94 /* mkfs.vfat: Labels with characters *?.,;:/\|+=<>[]" are not allowed.
95 * Let's also replace any control chars. */
96 for (char *p = q; *p; p++)
97 if (strchr("*?.,;:/\\|+=<>[]\"", *p) || char_is_cc(*p))
98 *p = '_';
99
100 *ret = TAKE_PTR(q);
101 return 0;
102 }
103
104 static int do_mcopy(const char *node, const char *root) {
105 _cleanup_free_ char *mcopy = NULL;
106 _cleanup_strv_free_ char **argv = NULL;
107 _cleanup_close_ int rfd = -EBADF;
108 _cleanup_free_ DirectoryEntries *de = NULL;
109 int r;
110
111 assert(node);
112 assert(root);
113
114 /* Return early if there's nothing to copy. */
115 if (dir_is_empty(root, /*ignore_hidden_or_backup=*/ false))
116 return 0;
117
118 r = find_executable("mcopy", &mcopy);
119 if (r == -ENOENT)
120 return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "Could not find mcopy binary.");
121 if (r < 0)
122 return log_error_errno(r, "Failed to determine whether mcopy binary exists: %m");
123
124 argv = strv_new(mcopy, "-s", "-p", "-Q", "-m", "-i", node);
125 if (!argv)
126 return log_oom();
127
128 /* mcopy copies the top level directory instead of everything in it so we have to pass all
129 * the subdirectories to mcopy instead to end up with the correct directory structure. */
130
131 rfd = open(root, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
132 if (rfd < 0)
133 return log_error_errno(errno, "Failed to open directory '%s': %m", root);
134
135 r = readdir_all(rfd, RECURSE_DIR_SORT|RECURSE_DIR_ENSURE_TYPE, &de);
136 if (r < 0)
137 return log_error_errno(r, "Failed to read '%s' contents: %m", root);
138
139 for (size_t i = 0; i < de->n_entries; i++) {
140 _cleanup_free_ char *p = NULL;
141
142 p = path_join(root, de->entries[i]->d_name);
143 if (!p)
144 return log_oom();
145
146 if (!IN_SET(de->entries[i]->d_type, DT_REG, DT_DIR)) {
147 log_debug("%s is not a file/directory which are the only file types supported by vfat, ignoring", p);
148 continue;
149 }
150
151 if (strv_consume(&argv, TAKE_PTR(p)) < 0)
152 return log_oom();
153 }
154
155 if (strv_extend(&argv, "::") < 0)
156 return log_oom();
157
158 r = safe_fork("(mcopy)", FORK_RESET_SIGNALS|FORK_RLIMIT_NOFILE_SAFE|FORK_DEATHSIG|FORK_LOG|FORK_WAIT|FORK_STDOUT_TO_STDERR|FORK_CLOSE_ALL_FDS, NULL);
159 if (r < 0)
160 return r;
161 if (r == 0) {
162 /* Avoid failures caused by mismatch in expectations between mkfs.vfat and mcopy by disabling
163 * the stricter mcopy checks using MTOOLS_SKIP_CHECK. */
164 execve(mcopy, argv, STRV_MAKE("MTOOLS_SKIP_CHECK=1", strv_find_prefix(environ, "SOURCE_DATE_EPOCH=")));
165
166 log_error_errno(errno, "Failed to execute mcopy: %m");
167
168 _exit(EXIT_FAILURE);
169 }
170
171 return 0;
172 }
173
174 typedef struct ProtofileData {
175 FILE *file;
176 bool has_filename_with_spaces;
177 const char *tmpdir;
178 } ProtofileData;
179
180 static int protofile_print_item(
181 RecurseDirEvent event,
182 const char *path,
183 int dir_fd,
184 int inode_fd,
185 const struct dirent *de,
186 const struct statx *sx,
187 void *userdata) {
188
189 ProtofileData *data = ASSERT_PTR(userdata);
190 _cleanup_free_ char *copy = NULL;
191 int r;
192
193 if (event == RECURSE_DIR_LEAVE) {
194 fputs("$\n", data->file);
195 return 0;
196 }
197
198 if (!IN_SET(event, RECURSE_DIR_ENTER, RECURSE_DIR_ENTRY))
199 return RECURSE_DIR_CONTINUE;
200
201 char type = S_ISDIR(sx->stx_mode) ? 'd' :
202 S_ISREG(sx->stx_mode) ? '-' :
203 S_ISLNK(sx->stx_mode) ? 'l' :
204 S_ISFIFO(sx->stx_mode) ? 'p' :
205 S_ISBLK(sx->stx_mode) ? 'b' :
206 S_ISCHR(sx->stx_mode) ? 'c' : 0;
207 if (type == 0)
208 return RECURSE_DIR_CONTINUE;
209
210 /* The protofile format does not support spaces in filenames as whitespace is used as a token
211 * delimiter. To work around this limitation, mkfs.xfs allows escaping whitespace by using the /
212 * character (which isn't allowed in filenames and as such can be used to escape whitespace). See
213 * https://lore.kernel.org/linux-xfs/20230222090303.h6tujm7y32gjhgal@andromeda/T/#m8066b3e7d62a080ee7434faac4861d944e64493b
214 * for more information.*/
215
216 if (strchr(de->d_name, ' ')) {
217 copy = strdup(de->d_name);
218 if (!copy)
219 return log_oom();
220
221 string_replace_char(copy, ' ', '/');
222 data->has_filename_with_spaces = true;
223 }
224
225 fprintf(data->file, "%s %c%c%c%03o 0 0 ",
226 copy ?: de->d_name,
227 type,
228 sx->stx_mode & S_ISUID ? 'u' : '-',
229 sx->stx_mode & S_ISGID ? 'g' : '-',
230 (unsigned) (sx->stx_mode & 0777));
231
232 if (S_ISREG(sx->stx_mode)) {
233 _cleanup_free_ char *p = NULL;
234
235 /* While we can escape whitespace in the filename, we cannot escape whitespace in the source
236 * path, so hack around that by creating a symlink to the path in a temporary directory and
237 * using the symlink as the source path instead. */
238
239 if (strchr(path, ' ')) {
240 r = tempfn_random_child(data->tmpdir, "mkfs-xfs", &p);
241 if (r < 0)
242 return log_error_errno(r, "Failed to generate random child name in %s: %m", data->tmpdir);
243
244 if (symlink(path, p) < 0)
245 return log_error_errno(errno, "Failed to symlink %s to %s: %m", p, path);
246 }
247
248 fputs(p ?: path, data->file);
249 } else if (S_ISLNK(sx->stx_mode)) {
250 _cleanup_free_ char *p = NULL;
251
252 r = readlinkat_malloc(dir_fd, de->d_name, &p);
253 if (r < 0)
254 return log_error_errno(r, "Failed to read symlink %s: %m", path);
255
256 /* If we have a symlink to a path with whitespace in it, we're out of luck, as there's no way
257 * to encode that in the mkfs.xfs protofile format. */
258
259 if (strchr(p, ' '))
260 return log_error_errno(r, "Symlinks to paths containing whitespace are not supported by mkfs.xfs: %m");
261
262 fputs(p, data->file);
263 } else if (S_ISBLK(sx->stx_mode) || S_ISCHR(sx->stx_mode))
264 fprintf(data->file, "%" PRIu32 " %" PRIu32, sx->stx_rdev_major, sx->stx_rdev_minor);
265
266 fputc('\n', data->file);
267
268 return RECURSE_DIR_CONTINUE;
269 }
270
271 static int make_protofile(const char *root, char **ret_path, bool *ret_has_filename_with_spaces, char **ret_tmpdir) {
272 _cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
273 _cleanup_fclose_ FILE *f = NULL;
274 _cleanup_(unlink_and_freep) char *p = NULL;
275 struct ProtofileData data = {};
276 const char *vt;
277 int r;
278
279 assert(ret_path);
280 assert(ret_has_filename_with_spaces);
281 assert(ret_tmpdir);
282
283 r = var_tmp_dir(&vt);
284 if (r < 0)
285 return log_error_errno(r, "Failed to get persistent temporary directory: %m");
286
287 r = fopen_temporary_child(vt, &f, &p);
288 if (r < 0)
289 return log_error_errno(r, "Failed to open temporary file: %m");
290
291 /* Explicitly use /tmp here because this directory cannot have spaces its path. */
292 r = mkdtemp_malloc("/tmp/systemd-mkfs-XXXXXX", &tmpdir);
293 if (r < 0)
294 return log_error_errno(r, "Failed to create temporary directory: %m");
295
296 data.file = f;
297 data.tmpdir = tmpdir;
298
299 fputs("/\n"
300 "0 0\n"
301 "d--755 0 0\n", f);
302
303 r = recurse_dir_at(AT_FDCWD, root, STATX_TYPE|STATX_MODE, UINT_MAX, RECURSE_DIR_SORT, protofile_print_item, &data);
304 if (r < 0)
305 return log_error_errno(r, "Failed to recurse through %s: %m", root);
306
307 fputs("$\n", f);
308
309 r = fflush_and_check(f);
310 if (r < 0)
311 return log_error_errno(r, "Failed to flush %s: %m", p);
312
313 *ret_path = TAKE_PTR(p);
314 *ret_has_filename_with_spaces = data.has_filename_with_spaces;
315 *ret_tmpdir = TAKE_PTR(tmpdir);
316
317 return 0;
318 }
319
320 int make_filesystem(
321 const char *node,
322 const char *fstype,
323 const char *label,
324 const char *root,
325 sd_id128_t uuid,
326 bool discard,
327 bool quiet,
328 uint64_t sector_size,
329 char * const *extra_mkfs_args) {
330
331 _cleanup_free_ char *mkfs = NULL, *mangled_label = NULL;
332 _cleanup_strv_free_ char **argv = NULL, **env = NULL;
333 _cleanup_(rm_rf_physical_and_freep) char *protofile_tmpdir = NULL;
334 _cleanup_(unlink_and_freep) char *protofile = NULL;
335 char vol_id[CONST_MAX(SD_ID128_UUID_STRING_MAX, 8U + 1U)] = {};
336 int stdio_fds[3] = { -EBADF, STDERR_FILENO, STDERR_FILENO};
337 int r;
338
339 assert(node);
340 assert(fstype);
341 assert(label);
342
343 if (fstype_is_ro(fstype) && !root)
344 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
345 "Cannot generate read-only filesystem %s without a source tree.",
346 fstype);
347
348 if (streq(fstype, "swap")) {
349 if (root)
350 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
351 "A swap filesystem can't be populated, refusing");
352 r = find_executable("mkswap", &mkfs);
353 if (r == -ENOENT)
354 return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mkswap binary not available.");
355 if (r < 0)
356 return log_error_errno(r, "Failed to determine whether mkswap binary exists: %m");
357 } else if (streq(fstype, "squashfs")) {
358 r = find_executable("mksquashfs", &mkfs);
359 if (r == -ENOENT)
360 return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mksquashfs binary not available.");
361 if (r < 0)
362 return log_error_errno(r, "Failed to determine whether mksquashfs binary exists: %m");
363
364 } else if (streq(fstype, "erofs")) {
365 r = find_executable("mkfs.erofs", &mkfs);
366 if (r == -ENOENT)
367 return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mkfs.erofs binary not available.");
368 if (r < 0)
369 return log_error_errno(r, "Failed to determine whether mkfs.erofs binary exists: %m");
370
371 } else if (fstype_is_ro(fstype)) {
372 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
373 "Don't know how to create read-only file system '%s', refusing.",
374 fstype);
375 } else {
376 if (root && !mkfs_supports_root_option(fstype))
377 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
378 "Populating with source tree is not supported for %s", fstype);
379 r = mkfs_exists(fstype);
380 if (r < 0)
381 return log_error_errno(r, "Failed to determine whether mkfs binary for %s exists: %m", fstype);
382 if (r == 0)
383 return log_error_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT), "mkfs binary for %s is not available.", fstype);
384
385 mkfs = strjoin("mkfs.", fstype);
386 if (!mkfs)
387 return log_oom();
388 }
389
390 if (STR_IN_SET(fstype, "ext2", "ext3", "ext4", "xfs", "swap")) {
391 size_t max_len =
392 streq(fstype, "xfs") ? 12 :
393 streq(fstype, "swap") ? 15 :
394 16;
395
396 r = mangle_linux_fs_label(label, max_len, &mangled_label);
397 if (r < 0)
398 return log_error_errno(r, "Failed to determine volume label from string \"%s\": %m", label);
399 label = mangled_label;
400
401 } else if (streq(fstype, "vfat")) {
402 r = mangle_fat_label(label, &mangled_label);
403 if (r < 0)
404 return log_error_errno(r, "Failed to determine FAT label from string \"%s\": %m", label);
405 label = mangled_label;
406
407 xsprintf(vol_id, "%08" PRIx32,
408 ((uint32_t) uuid.bytes[0] << 24) |
409 ((uint32_t) uuid.bytes[1] << 16) |
410 ((uint32_t) uuid.bytes[2] << 8) |
411 ((uint32_t) uuid.bytes[3])); /* Take first 32 bytes of UUID */
412 }
413
414 if (isempty(vol_id))
415 assert_se(sd_id128_to_uuid_string(uuid, vol_id));
416
417 /* When changing this conditional, also adjust the log statement below. */
418 if (STR_IN_SET(fstype, "ext2", "ext3", "ext4")) {
419 argv = strv_new(mkfs,
420 "-L", label,
421 "-U", vol_id,
422 "-I", "256",
423 "-m", "0",
424 "-E", discard ? "discard,lazy_itable_init=1" : "nodiscard,lazy_itable_init=1",
425 "-b", "4096",
426 "-T", "default",
427 node);
428
429 if (root && strv_extend_strv(&argv, STRV_MAKE("-d", root), false) < 0)
430 return log_oom();
431
432 if (quiet && strv_extend(&argv, "-q") < 0)
433 return log_oom();
434
435 if (sector_size > 0) {
436 if (strv_extend(&env, "MKE2FS_DEVICE_SECTSIZE") < 0)
437 return log_oom();
438
439 if (strv_extendf(&env, "%"PRIu64, sector_size) < 0)
440 return log_oom();
441 }
442
443 } else if (streq(fstype, "btrfs")) {
444 argv = strv_new(mkfs,
445 "-L", label,
446 "-U", vol_id,
447 node);
448 if (!argv)
449 return log_oom();
450
451 if (!discard && strv_extend(&argv, "--nodiscard") < 0)
452 return log_oom();
453
454 if (root && strv_extend_strv(&argv, STRV_MAKE("-r", root), false) < 0)
455 return log_oom();
456
457 if (quiet && strv_extend(&argv, "-q") < 0)
458 return log_oom();
459
460 /* mkfs.btrfs unconditionally warns about several settings changing from v5.15 onwards which
461 * isn't silenced by "-q", so let's redirect stdout to /dev/null as well. */
462 if (quiet)
463 stdio_fds[1] = -EBADF;
464
465 } else if (streq(fstype, "f2fs")) {
466 argv = strv_new(mkfs,
467 "-g", /* "default options" */
468 "-f", /* force override, without this it doesn't seem to want to write to an empty partition */
469 "-l", label,
470 "-U", vol_id,
471 "-t", one_zero(discard),
472 node);
473
474 if (quiet && strv_extend(&argv, "-q") < 0)
475 return log_oom();
476
477 if (sector_size > 0) {
478 if (strv_extend(&argv, "-w") < 0)
479 return log_oom();
480
481 if (strv_extendf(&argv, "%"PRIu64, sector_size) < 0)
482 return log_oom();
483 }
484
485 } else if (streq(fstype, "xfs")) {
486 const char *j;
487
488 j = strjoina("uuid=", vol_id);
489
490 argv = strv_new(mkfs,
491 "-L", label,
492 "-m", j,
493 "-m", "reflink=1",
494 node);
495 if (!argv)
496 return log_oom();
497
498 if (!discard && strv_extend(&argv, "-K") < 0)
499 return log_oom();
500
501 if (root) {
502 bool has_filename_with_spaces = false;
503 _cleanup_free_ char *protofile_with_opt = NULL;
504
505 r = make_protofile(root, &protofile, &has_filename_with_spaces, &protofile_tmpdir);
506 if (r < 0)
507 return r;
508
509 /* Gross hack to make mkfs.xfs interpret slashes as spaces so we can encode filenames
510 * with spaces in the protofile format. */
511 if (has_filename_with_spaces)
512 protofile_with_opt = strjoin("slashes_are_spaces=1,", protofile);
513 else
514 protofile_with_opt = strdup(protofile);
515 if (!protofile_with_opt)
516 return -ENOMEM;
517
518 if (strv_extend_strv(&argv, STRV_MAKE("-p", protofile_with_opt), false) < 0)
519 return log_oom();
520 }
521
522 if (sector_size > 0) {
523 if (strv_extend(&argv, "-s") < 0)
524 return log_oom();
525
526 if (strv_extendf(&argv, "size=%"PRIu64, sector_size) < 0)
527 return log_oom();
528 }
529
530 if (quiet && strv_extend(&argv, "-q") < 0)
531 return log_oom();
532
533 } else if (streq(fstype, "vfat")) {
534
535 argv = strv_new(mkfs,
536 "-i", vol_id,
537 "-n", label,
538 "-F", "32", /* yes, we force FAT32 here */
539 node);
540
541 if (sector_size > 0) {
542 if (strv_extend(&argv, "-S") < 0)
543 return log_oom();
544
545 if (strv_extendf(&argv, "%"PRIu64, sector_size) < 0)
546 return log_oom();
547 }
548
549 /* mkfs.vfat does not have a --quiet option so let's redirect stdout to /dev/null instead. */
550 if (quiet)
551 stdio_fds[1] = -EBADF;
552
553 } else if (streq(fstype, "swap")) {
554 /* TODO: add --quiet once util-linux v2.38 is available everywhere. */
555
556 argv = strv_new(mkfs,
557 "-L", label,
558 "-U", vol_id,
559 node);
560
561 if (quiet)
562 stdio_fds[1] = -EBADF;
563
564 } else if (streq(fstype, "squashfs")) {
565
566 argv = strv_new(mkfs,
567 root, node,
568 "-noappend");
569
570 /* mksquashfs -quiet option is pretty new so let's redirect stdout to /dev/null instead. */
571 if (quiet)
572 stdio_fds[1] = -EBADF;
573
574 } else if (streq(fstype, "erofs")) {
575
576 argv = strv_new(mkfs,
577 "-U", vol_id,
578 node, root);
579
580 if (quiet && strv_extend(&argv, "--quiet") < 0)
581 return log_oom();
582
583 } else
584 /* Generic fallback for all other file systems */
585 argv = strv_new(mkfs, node);
586
587 if (!argv)
588 return log_oom();
589
590 if (extra_mkfs_args && strv_extend_strv(&argv, extra_mkfs_args, false) < 0)
591 return log_oom();
592
593 if (DEBUG_LOGGING) {
594 _cleanup_free_ char *j = NULL;
595
596 j = strv_join(argv, " ");
597 log_debug("Executing mkfs command: %s", strna(j));
598 }
599
600 r = safe_fork_full(
601 "(mkfs)",
602 stdio_fds,
603 /*except_fds=*/ NULL,
604 /*n_except_fds=*/ 0,
605 FORK_RESET_SIGNALS|FORK_RLIMIT_NOFILE_SAFE|FORK_DEATHSIG|FORK_LOG|FORK_WAIT|
606 FORK_CLOSE_ALL_FDS|FORK_REARRANGE_STDIO|FORK_NEW_MOUNTNS|FORK_REOPEN_LOG,
607 /*ret_pid=*/ NULL);
608 if (r < 0)
609 return r;
610 if (r == 0) {
611 /* Child */
612
613 STRV_FOREACH_PAIR(k, v, env)
614 if (setenv(*k, *v, /* replace = */ true) < 0) {
615 log_error_errno(r, "Failed to set %s=%s environment variable: %m", *k, *v);
616 _exit(EXIT_FAILURE);
617 }
618
619 /* mkfs.btrfs refuses to operate on block devices with mounted partitions, even if operating
620 * on unformatted free space, so let's trick it and other mkfs tools into thinking no
621 * partitions are mounted. See https://github.com/kdave/btrfs-progs/issues/640 for more
622 ° information. */
623 (void) mount_nofollow_verbose(LOG_DEBUG, "/dev/null", "/proc/self/mounts", NULL, MS_BIND, NULL);
624
625 execvp(mkfs, argv);
626
627 log_error_errno(errno, "Failed to execute %s: %m", mkfs);
628
629 _exit(EXIT_FAILURE);
630 }
631
632 if (root && streq(fstype, "vfat")) {
633 r = do_mcopy(node, root);
634 if (r < 0)
635 return r;
636 }
637
638 if (STR_IN_SET(fstype, "ext2", "ext3", "ext4", "btrfs", "f2fs", "xfs", "vfat", "swap"))
639 log_info("%s successfully formatted as %s (label \"%s\", uuid %s)",
640 node, fstype, label, vol_id);
641 else if (streq(fstype, "erofs"))
642 log_info("%s successfully formatted as %s (uuid %s, no label)",
643 node, fstype, vol_id);
644 else
645 log_info("%s successfully formatted as %s (no label or uuid specified)",
646 node, fstype);
647
648 return 0;
649 }
650
651 int mkfs_options_from_env(const char *component, const char *fstype, char ***ret) {
652 _cleanup_strv_free_ char **l = NULL;
653 const char *e;
654 char *n;
655
656 assert(component);
657 assert(fstype);
658 assert(ret);
659
660 n = strjoina("SYSTEMD_", component, "_MKFS_OPTIONS_", fstype);
661 e = getenv(ascii_strupper(n));
662 if (e) {
663 l = strv_split(e, NULL);
664 if (!l)
665 return -ENOMEM;
666 }
667
668 *ret = TAKE_PTR(l);
669 return 0;
670 }