diff options
author | phk <phk@FreeBSD.org> | 2002-09-13 10:33:10 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2002-09-13 10:33:10 +0000 |
commit | 0687f90dba5d628b9465c4c91626aec59638c29e (patch) | |
tree | a6c2aa2b6519a7f9c2a51850c254ca89d2a99ffb | |
parent | e48c2b856016caaa98feb0c86f13098e44f4a725 (diff) | |
download | FreeBSD-src-0687f90dba5d628b9465c4c91626aec59638c29e.zip FreeBSD-src-0687f90dba5d628b9465c4c91626aec59638c29e.tar.gz |
Add a couple more of the big/little-endian conversion routines and make
them visible from userland, if need be.
I wish that the C language contained this as part of struct definintions,
but failing that, I would settle for an agreed upon set of functions for
packing/unpacking integers in various sizes from byte-streams which may
have unfriendly alignment.
This really belongs in <sys/endian.h> I guess.
-rw-r--r-- | sys/geom/geom.h | 15 | ||||
-rw-r--r-- | sys/geom/geom_enc.c | 16 |
2 files changed, 25 insertions, 6 deletions
diff --git a/sys/geom/geom.h b/sys/geom/geom.h index 3bab33d..df7ecb5 100644 --- a/sys/geom/geom.h +++ b/sys/geom/geom.h @@ -178,12 +178,6 @@ void g_trace(int level, char *, ...); # define G_T_BIO 2 # define G_T_ACCESS 4 -/* geom_enc.c */ -uint32_t g_dec_be2(u_char *p); -uint32_t g_dec_be4(u_char *p); -uint32_t g_dec_le2(u_char *p); -uint32_t g_dec_le4(u_char *p); -void g_enc_le4(u_char *p, uint32_t u); /* geom_event.c */ void g_orphan_provider(struct g_provider *pp, int error); @@ -298,4 +292,13 @@ extern struct sx topology_lock; #define GEOMGETCONF _IOWR('G', 0, struct sbuf) +/* geom_enc.c */ +uint32_t g_dec_be2(u_char *p); +uint32_t g_dec_be4(u_char *p); +uint32_t g_dec_le2(u_char *p); +uint32_t g_dec_le4(u_char *p); +uint64_t g_dec_le8(u_char *p); +void g_enc_le4(u_char *p, uint32_t u); +void g_enc_le8(u_char *p, uint64_t u); + #endif /* _GEOM_GEOM_H_ */ diff --git a/sys/geom/geom_enc.c b/sys/geom/geom_enc.c index 657ac8c..ebb1bd1 100644 --- a/sys/geom/geom_enc.c +++ b/sys/geom/geom_enc.c @@ -101,3 +101,19 @@ g_enc_le4(u_char *p, uint32_t u) p[3] = (u >> 24) & 0xff; } +uint64_t +g_dec_le8(u_char *p) +{ + + return(g_dec_le4(p) | ((uint64_t)(g_dec_le4(p + 4)) << 32)); +} + + +void +g_enc_le8(u_char *p, uint64_t u) +{ + + g_enc_le4(p, u); + g_enc_le4(p + 4, u >> 32); +} + |