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 <zab@versity.com>
This commit is contained in:
Zach Brown
2017-01-24 14:42:56 -08:00
parent 2ac239a4cb
commit 8f63196318
2 changed files with 22 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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);
/*