uuid: Add a glue layer macros for raw buffers
Subsystems (2)
Andy Shevchenko
reviewerPATCH v2 1/2 uuid: Add a glue layer macros for raw buffers
When the ID comes from or we would like to pass it to a raw buffer, the casting is needed.
Instead of doing it each time, provide a helpful set of macros.
--- include/linux/uuid.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/linux/uuid.h +13 -0
@@ -51,11 +51,16 @@ static inline void guid_copy(guid_t *dst, const guid_t *src)memcpy (dst, src,sizeof (guid_t)); } +#define guid_copy_from_raw (dst, src) guid_copy(dst, (const guid_t *)src) +#define guid_copy_to_raw (dst, src) guid_copy((void *)dst, src) +static inline bool guid_is_null (const guid_t *guid) {return guid_equal (guid, &guid_null); } +#define guid_is_null_raw (guid) guid_is_null((const guid_t *)guid) +static inline bool uuid_equal (const uuid_t *u1,const uuid_t *u2) {return memcmp (u1, u2,sizeof (uuid_t)) ==0 ;
@@ -66,16 +71,24 @@ static inline void uuid_copy(uuid_t *dst, const uuid_t *src)memcpy (dst, src,sizeof (uuid_t)); } +#define uuid_copy_from_raw (dst, src) uuid_copy(dst, (const uuid_t *)src) +#define uuid_copy_to_raw (dst, src) uuid_copy((void *)dst, src) +static inline bool uuid_is_null (const uuid_t *uuid) {return uuid_equal (uuid, &uuid_null); } +#define uuid_is_null_raw (uuid) uuid_is_null((const uuid_t *)uuid) +void generate_random_uuid (unsigned char uuid[16 ]);extern void guid_gen (guid_t *u);extern void uuid_gen (uuid_t *u); +#define guid_gen_raw (guid) guid_gen((guid_t *)guid) +#define uuid_gen_raw (uuid) uuid_gen((uuid_t *)uuid) +bool __must_check uuid_is_valid (const char *uuid);extern const u8 guid_index[16 ];
Signature · 1 line
2.20.1
Quoted 2 lines · Andy Shevchenko
When the ID comes from or we would like to pass it to a raw buffer, the casting is needed.
Something is missing in this sentence.
Andy Shevchenko
reviewerQuoted 5 lines · Christoph Hellwig
Quoted 2 lines · Andy Shevchenko
When the ID comes from or we would like to pass it to a raw buffer, the casting is needed.
Something is missing in this sentence.
What I meant there is if we got a raw buffer, consider u8 * pointer to it, and we would like to either take a UUID in binary form from it or pass it to that buffer, we have to cast due to type inequivalence.
Can you suggest how to compress it nicely to few words?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · Andy Shevchenko
When the ID comes from or we would like to pass it to a raw buffer, the casting is needed.
Quoted 7 lines
Quoted 1 line
Something is missing in this sentence.
What I meant there is if we got a raw buffer, consider u8 * pointer to it, and we would like to either take a UUID in binary form from it or pass it to that buffer, we have to cast due to type inequivalence.
Can you suggest how to compress it nicely to few words?
Well, the usual way is to memcpy it out, and I'm not sure how this is so much better. But maybe a detailed changelog that actuall parses and properly typed inline functions might convince me :)