All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jes Sorensen <jes.sorensen@gmail.com>
To: linux-fscrypt@vger.kernel.org
Cc: kernel-team@fb.com, Jes Sorensen <jsorensen@fb.com>
Subject: [PATCH 6/7] Move cmdline helper functions to fsverity.c
Date: Mon, 10 Feb 2020 19:00:36 -0500	[thread overview]
Message-ID: <20200211000037.189180-7-Jes.Sorensen@gmail.com> (raw)
In-Reply-To: <20200211000037.189180-1-Jes.Sorensen@gmail.com>

From: Jes Sorensen <jsorensen@fb.com>

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@fb.com>
---
 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


  parent reply	other threads:[~2020-02-11  0:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11  0:00 [PATCH 0/7] Split fsverity-utils into a shared library Jes Sorensen
2020-02-11  0:00 ` [PATCH 1/7] Build basic " Jes Sorensen
2020-02-11  0:00 ` [PATCH 2/7] Restructure fsverity_cmd_sign for shared libraries Jes Sorensen
2020-02-11  0:00 ` [PATCH 3/7] Make fsverity_cmd_measure() a library function Jes Sorensen
2020-02-11  0:00 ` [PATCH 4/7] Make fsverity_cmd_enable a library call() Jes Sorensen
2020-02-11  0:00 ` [PATCH 5/7] Rename commands.h to fsverity.h Jes Sorensen
2020-02-11  0:00 ` Jes Sorensen [this message]
2020-02-11  0:00 ` [PATCH 7/7] cmd_sign: fsverity_cmd_sign() into two functions Jes Sorensen
2020-02-11 19:22 ` [PATCH 0/7] Split fsverity-utils into a shared library Eric Biggers
2020-02-11 22:09   ` Jes Sorensen
2020-02-11 23:14     ` Eric Biggers
2020-02-11 23:35       ` Jes Sorensen
2020-02-14 20:35         ` Eric Biggers
2020-02-19 23:49           ` Jes Sorensen
2020-07-30 17:52             ` Eric Biggers
2020-07-31 17:40               ` Jes Sorensen
2020-07-31 17:47                 ` Chris Mason
2020-07-31 19:14                   ` Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200211000037.189180-7-Jes.Sorensen@gmail.com \
    --to=jes.sorensen@gmail.com \
    --cc=jsorensen@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-fscrypt@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.