mirror of
https://github.com/versity/scoutfs.git
synced 2026-02-07 11:10:44 +00:00
Add kvec big endian inc and dec
Add helpers that increment or decrement kvec vectors as theough they're big endian values. Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
@@ -258,6 +258,36 @@ void scoutfs_kvec_set_max_key(struct kvec *kvec)
|
||||
scoutfs_kvec_init(kvec, type, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Increase the kvec as though it is a big endian value. Carry
|
||||
* increments of the least significant byte as long as it wraps.
|
||||
*/
|
||||
void scoutfs_kvec_be_inc(struct kvec *kvec)
|
||||
{
|
||||
int i;
|
||||
int b;
|
||||
|
||||
for (i = SCOUTFS_KVEC_NR - 1; i >= 0; i--) {
|
||||
for (b = (int)kvec[i].iov_len - 1; b >= 0; b--) {
|
||||
if (++((u8 *)kvec[i].iov_base)[b])
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void scoutfs_kvec_be_dec(struct kvec *kvec)
|
||||
{
|
||||
int i;
|
||||
int b;
|
||||
|
||||
for (i = SCOUTFS_KVEC_NR - 1; i >= 0; i--) {
|
||||
for (b = (int)kvec[i].iov_len - 1; b >= 0; b--) {
|
||||
if (--((u8 *)kvec[i].iov_base)[b] != 0xff)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Clone the source kvec into the dst if the dst is empty or if
|
||||
* the src kvec is less than the dst.
|
||||
|
||||
@@ -68,5 +68,7 @@ void scoutfs_kvec_set_max_key(struct kvec *kvec);
|
||||
void scoutfs_kvec_clone_less(struct kvec *dst, struct kvec *src);
|
||||
unsigned scoutfs_kvec_key_strlen(struct kvec *key);
|
||||
void scoutfs_kvec_key_sprintf(char *buf, struct kvec *key);
|
||||
void scoutfs_kvec_be_inc(struct kvec *kvec);
|
||||
void scoutfs_kvec_be_dec(struct kvec *kvec);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user