From 8f631963186e5b4a3b1d5a875511b83aa9cfeb3a Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 24 Jan 2017 14:42:56 -0800 Subject: [PATCH] Add key inc/dec variants for partial keys Some callers know that it's safe to increment their partial keys. Let them do so without trying to expand the keys to full precision and triggering warnings that their buffers aren't large enough. Signed-off-by: Zach Brown --- kmod/src/key.c | 24 ++++++++++++++++++++---- kmod/src/key.h | 2 ++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/kmod/src/key.c b/kmod/src/key.c index 9795f797..04891839 100644 --- a/kmod/src/key.c +++ b/kmod/src/key.c @@ -65,20 +65,30 @@ static void extend_zeros(struct scoutfs_key_buf *key) } } -void scoutfs_key_inc(struct scoutfs_key_buf *key) +/* + * There are callers that work with a range of keys of a uniform length + * who know that it's safe to increment their keys that aren't full + * precision. These are exceptional so a specific function variant + * marks them. + */ +void scoutfs_key_inc_cur_len(struct scoutfs_key_buf *key) { u8 *bytes = key->data; int i; - extend_zeros(key); - for (i = key->key_len - 1; i >= 0; i--) { if (++bytes[i] != 0) break; } } -void scoutfs_key_dec(struct scoutfs_key_buf *key) +void scoutfs_key_inc(struct scoutfs_key_buf *key) +{ + extend_zeros(key); + scoutfs_key_inc_cur_len(key); +} + +void scoutfs_key_dec_cur_len(struct scoutfs_key_buf *key) { u8 *bytes = key->data; int i; @@ -90,3 +100,9 @@ void scoutfs_key_dec(struct scoutfs_key_buf *key) break; } } + +void scoutfs_key_dec(struct scoutfs_key_buf *key) +{ + extend_zeros(key); + scoutfs_key_dec_cur_len(key); +} diff --git a/kmod/src/key.h b/kmod/src/key.h index a63244ba..2ed2f3f6 100644 --- a/kmod/src/key.h +++ b/kmod/src/key.h @@ -15,7 +15,9 @@ struct scoutfs_key_buf *scoutfs_key_dup(struct super_block *sb, struct scoutfs_key_buf *key); void scoutfs_key_free(struct super_block *sb, struct scoutfs_key_buf *key); void scoutfs_key_inc(struct scoutfs_key_buf *key); +void scoutfs_key_inc_cur_len(struct scoutfs_key_buf *key); void scoutfs_key_dec(struct scoutfs_key_buf *key); +void scoutfs_key_dec_cur_len(struct scoutfs_key_buf *key); /*