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:
Zach Brown
2017-01-09 14:13:20 -08:00
parent a15d37783e
commit eb94092f2f
2 changed files with 32 additions and 0 deletions

View File

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

View File

@@ -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