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.
This commit is contained in:
parent
2dfbcdd46d
commit
85b62edb84
@ -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_ */
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user