1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <stdio.h>
5 
6 #include "main-func.h"
7 
8 int generator_open_unit_file(
9         const char *dest,
10         const char *source,
11         const char *name,
12         FILE **file);
13 
14 int generator_add_symlink(const char *dir, const char *dst, const char *dep_type, const char *src);
15 
16 int generator_write_fsck_deps(
17         FILE *f,
18         const char *dir,
19         const char *what,
20         const char *where,
21         const char *type);
22 
23 int generator_write_timeouts(
24         const char *dir,
25         const char *what,
26         const char *where,
27         const char *opts,
28         char **filtered);
29 
30 int generator_write_blockdev_dependency(
31                 FILE *f,
32                 const char *what);
33 
34 int generator_write_cryptsetup_unit_section(
35                 FILE *f,
36                 const char *source);
37 
38 int generator_write_cryptsetup_service_section(
39                 FILE *f,
40                 const char *name,
41                 const char *what,
42                 const char *password,
43                 const char *options);
44 
45 int generator_write_veritysetup_unit_section(
46                 FILE *f,
47                 const char *source);
48 
49 int generator_write_veritysetup_service_section(
50                 FILE *f,
51                 const char *name,
52                 const char *data_what,
53                 const char *hash_what,
54                 const char *roothash,
55                 const char *options);
56 
57 int generator_write_device_deps(
58         const char *dir,
59         const char *what,
60         const char *where,
61         const char *opts);
62 
63 int generator_write_initrd_root_device_deps(
64         const char *dir,
65         const char *what);
66 
67 int generator_hook_up_mkswap(
68         const char *dir,
69         const char *what);
70 int generator_hook_up_mkfs(
71         const char *dir,
72         const char *what,
73         const char *where,
74         const char *type);
75 int generator_hook_up_growfs(
76         const char *dir,
77         const char *where,
78         const char *target);
79 
80 int generator_enable_remount_fs_service(const char *dir);
81 
82 void log_setup_generator(void);
83 
84 /* Similar to DEFINE_MAIN_FUNCTION, but initializes logging and assigns positional arguments. */
85 #define DEFINE_MAIN_GENERATOR_FUNCTION(impl)                            \
86         _DEFINE_MAIN_FUNCTION(                                          \
87                 ({                                                      \
88                         log_setup_generator();                          \
89                         if (argc > 1 && argc != 4)                      \
90                                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), \
91                                                        "This program takes zero or three arguments."); \
92                 }),                                                     \
93                 impl(argc > 1 ? argv[1] : "/tmp",                       \
94                      argc > 1 ? argv[2] : "/tmp",                       \
95                      argc > 1 ? argv[3] : "/tmp"),                      \
96                 r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)
97