diff --git a/kmod/src/kvec.c b/kmod/src/kvec.c index 349e55b6..5e49c6a3 100644 --- a/kmod/src/kvec.c +++ b/kmod/src/kvec.c @@ -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. diff --git a/kmod/src/kvec.h b/kmod/src/kvec.h index 93ddcd36..444a8116 100644 --- a/kmod/src/kvec.h +++ b/kmod/src/kvec.h @@ -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