mirror of
https://github.com/versity/scoutfs.git
synced 2026-02-07 11:10:44 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user