From: Jes Sorensen <jsorensen@xxxxxx> There is no need for these to live in the shared library. In addition move get_default_block_size() to the library and rename it appropriately. Signed-off-by: Jes Sorensen <jsorensen@xxxxxx> --- cmd_sign.c | 2 +- fsverity.c | 25 +++++++++---------------- fsverity.h | 8 +------- util.c | 13 +++++++++++++ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cmd_sign.c b/cmd_sign.c index 42779f2..a0bd168 100644 --- a/cmd_sign.c +++ b/cmd_sign.c @@ -497,7 +497,7 @@ int fsverity_cmd_sign(char *filename, const struct fsverity_hash_alg *hash_alg, } if (block_size == 0) - block_size = get_default_block_size(); + block_size = fsverity_get_default_block_size(); if (keyfile == NULL) { status = -EINVAL; diff --git a/fsverity.c b/fsverity.c index f0e94bf..45bf0cc 100644 --- a/fsverity.c +++ b/fsverity.c @@ -18,6 +18,12 @@ #include "fsverity.h" #include "hash_algs.h" +struct fsverity_command; + +static bool parse_block_size_option(const char *arg, u32 *size_ptr); +static bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr); +static void usage(const struct fsverity_command *cmd, FILE *fp); + enum { OPT_HASH_ALG, OPT_BLOCK_SIZE, @@ -310,7 +316,7 @@ int wrap_cmd_enable(const struct fsverity_command *cmd, arg.hash_algorithm = FS_VERITY_HASH_ALG_DEFAULT; if (arg.block_size == 0) - arg.block_size = get_default_block_size(); + arg.block_size = fsverity_get_default_block_size(); status = fsverity_cmd_enable(argv[0], &arg); @@ -437,7 +443,7 @@ static const struct fsverity_command *find_command(const char *name) return NULL; } -bool parse_block_size_option(const char *arg, u32 *size_ptr) +static bool parse_block_size_option(const char *arg, u32 *size_ptr) { char *end; unsigned long n = strtoul(arg, &end, 10); @@ -455,7 +461,7 @@ bool parse_block_size_option(const char *arg, u32 *size_ptr) return true; } -bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr) +static bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr) { if (*salt_ptr != NULL) { error_msg("--salt can only be specified once"); @@ -470,19 +476,6 @@ bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr) return true; } -u32 get_default_block_size(void) -{ - long n = sysconf(_SC_PAGESIZE); - - if (n <= 0 || n >= INT_MAX || !is_power_of_2(n)) { - fprintf(stderr, - "Warning: invalid _SC_PAGESIZE (%ld). Assuming 4K blocks.\n", - n); - return 4096; - } - return n; -} - int main(int argc, char *argv[]) { const struct fsverity_command *cmd; diff --git a/fsverity.h b/fsverity.h index e490c25..bb2f337 100644 --- a/fsverity.h +++ b/fsverity.h @@ -8,8 +8,6 @@ #include "hash_algs.h" #include "fsverity_uapi.h" -struct fsverity_command; - /* * Format in which verity file measurements are signed. This is the same as * 'struct fsverity_digest', except here some magic bytes are prepended to @@ -24,7 +22,7 @@ struct fsverity_signed_digest { }; -void usage(const struct fsverity_command *cmd, FILE *fp); +u32 fsverity_get_default_block_size(void); int fsverity_cmd_enable(char *filename, struct fsverity_enable_arg *arg); int fsverity_cmd_measure(char *filename, struct fsverity_digest *d); @@ -34,8 +32,4 @@ int fsverity_cmd_sign(char *filename, const struct fsverity_hash_alg *hash_alg, struct fsverity_signed_digest **retdigest, u8 **sig, u32 *sig_size); -bool parse_block_size_option(const char *arg, u32 *size_ptr); -u32 get_default_block_size(void); -bool parse_salt_option(const char *arg, u8 **salt_ptr, u32 *salt_size_ptr); - #endif /* COMMANDS_H */ diff --git a/util.c b/util.c index 2218f2e..e4ccd2a 100644 --- a/util.c +++ b/util.c @@ -213,3 +213,16 @@ void bin2hex(const u8 *bin, size_t bin_len, char *hex) } *hex = '\0'; } + +u32 fsverity_get_default_block_size(void) +{ + long n = sysconf(_SC_PAGESIZE); + + if (n <= 0 || n >= INT_MAX || !is_power_of_2(n)) { + fprintf(stderr, + "Warning: invalid _SC_PAGESIZE (%ld). Assuming 4K blocks.\n", + n); + return 4096; + } + return n; +} -- 2.24.1