Skip to content

Commit 773efda

Browse files
committed
btrfs-progs: factor out builtin feature string
We have more optionally built features, like compression for mkfs and want to print that too. Factor out the common code. Signed-off-by: David Sterba <[email protected]>
1 parent 6e52a4e commit 773efda

File tree

3 files changed

+61
-56
lines changed

3 files changed

+61
-56
lines changed

btrfs.c

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -221,62 +221,7 @@ static const char * const cmd_version_usage[] = {
221221

222222
static int cmd_version(const struct cmd_struct *unused, int argc, char **argv)
223223
{
224-
static const char *features[] = {
225-
#if EXPERIMENTAL
226-
"+"
227-
#else
228-
"-"
229-
#endif
230-
"EXPERIMENTAL",
231-
#ifdef INJECT
232-
"+"
233-
#else
234-
"-"
235-
#endif
236-
"INJECT",
237-
#ifdef STATIC_BUILD
238-
"+"
239-
#else
240-
"-"
241-
#endif
242-
"STATIC",
243-
#if defined(COMPRESSION_LZO) && COMPRESSION_LZO == 1
244-
"+"
245-
#else
246-
"-"
247-
#endif
248-
"LZO",
249-
#if defined(COMPRESSION_ZSTD) && COMPRESSION_ZSTD == 1
250-
"+"
251-
#else
252-
"-"
253-
#endif
254-
"ZSTD",
255-
#if defined(HAVE_LIBUDEV) && HAVE_LIBUDEV == 1
256-
"+"
257-
#else
258-
"-"
259-
#endif
260-
"UDEV",
261-
#if defined(HAVE_LINUX_FSVERITY_H) && HAVE_LINUX_FSVERITY_H == 1
262-
"+"
263-
#else
264-
"-"
265-
#endif
266-
"FSVERITY",
267-
#if defined(BTRFS_ZONED) && BTRFS_ZONED == 1
268-
"+"
269-
#else
270-
"-"
271-
#endif
272-
"ZONED",
273-
"CRYPTO=" CRYPTOPROVIDER,
274-
};
275-
276-
printf("%s\n", PACKAGE_STRING);
277-
for (int i = 0; i < ARRAY_SIZE(features); i++)
278-
printf("%s%s", (i == 0 ? "" : " "), features[i]);
279-
putchar('\n');
224+
help_builtin_features("");
280225
return 0;
281226
}
282227
static DEFINE_SIMPLE_COMMAND(version, "version");

common/help.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,3 +540,62 @@ void help_command_group(const struct cmd_group *grp, int argc, char **argv)
540540
usage_command_group(grp, full, false);
541541
}
542542

543+
void help_builtin_features(const char *prefix)
544+
{
545+
static const char *features[] = {
546+
#if EXPERIMENTAL
547+
"+"
548+
#else
549+
"-"
550+
#endif
551+
"EXPERIMENTAL",
552+
#ifdef INJECT
553+
"+"
554+
#else
555+
"-"
556+
#endif
557+
"INJECT",
558+
#ifdef STATIC_BUILD
559+
"+"
560+
#else
561+
"-"
562+
#endif
563+
"STATIC",
564+
#if defined(COMPRESSION_LZO) && COMPRESSION_LZO == 1
565+
"+"
566+
#else
567+
"-"
568+
#endif
569+
"LZO",
570+
#if defined(COMPRESSION_ZSTD) && COMPRESSION_ZSTD == 1
571+
"+"
572+
#else
573+
"-"
574+
#endif
575+
"ZSTD",
576+
#if defined(HAVE_LIBUDEV) && HAVE_LIBUDEV == 1
577+
"+"
578+
#else
579+
"-"
580+
#endif
581+
"UDEV",
582+
#if defined(HAVE_LINUX_FSVERITY_H) && HAVE_LINUX_FSVERITY_H == 1
583+
"+"
584+
#else
585+
"-"
586+
#endif
587+
"FSVERITY",
588+
#if defined(BTRFS_ZONED) && BTRFS_ZONED == 1
589+
"+"
590+
#else
591+
"-"
592+
#endif
593+
"ZONED",
594+
"CRYPTO=" CRYPTOPROVIDER,
595+
};
596+
597+
printf("%s%s\n", prefix, PACKAGE_STRING);
598+
for (int i = 0; i < ARRAY_SIZE(features); i++)
599+
printf("%s%s", (i == 0 ? "" : " "), features[i]);
600+
putchar('\n');
601+
}

common/help.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ __attribute__((noreturn))
115115
void help_ambiguous_token(const char *arg, const struct cmd_group *grp);
116116

117117
void help_command_group(const struct cmd_group *grp, int argc, char **argv);
118+
void help_builtin_features(const char *prefix);
118119

119120
int check_argc_exact(int nargs, int expected);
120121
int check_argc_min(int nargs, int expected);

0 commit comments

Comments
 (0)