lib/uuid.c: introduce a few more generic helpers
Subsystems (3)
[email protected]
maintainerPATCH 91/162 lib/uuid.c: introduce a few more generic helpers
From: Andy Shevchenko <[email protected]>
Subject: lib/uuid.c: introduce a few more generic helpers
There are new helpers in this patch:
uuid_is_valid checks if a UUID is validuuid_be_to_bin converts from string to binary (big endian)uuid_le_to_bin converts from string to binary (little endian)
They will be used in future, i.e. in the following patches in the series.
This also moves the indices arrays to lib/uuid.c to be shared accross modules.
[[email protected]: fix typo]
Signed-off-by Andy Shevchenko <[email protected]>
Reviewed-by Matt Fleming <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Rasmus Villemoes <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc "Theodore Ts'o" <[email protected]>
Cc Al Viro <[email protected]>
Cc Jens Axboe <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
include/linux/uuid.h | 13 ++++++++ lib/uuid.c | 65 +++++++++++++++++++++++++++++++++++++++++ lib/vsprintf.c | 9 ++--- 3 files changed, 82 insertions(+), 5 deletions(-)
include/linux/uuid.h renamed from include/linux/uuid.h~lib-uuid-introduce-few-more-generic-helpers-for-uuid +13 -0
@@ -22,6 +22,11 @@#include <uapi/linux/uuid.h> +/* +* The length of a UUID string ("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee") +* not including trailing NUL. +*/ +#define UUID_STRING_LEN 36static inline int uuid_le_cmp (const uuid_le u1,const uuid_le u2) {
@@ -38,4 +43,12 @@ void generate_random_uuid(unsigned charextern void uuid_le_gen (uuid_le *u);extern void uuid_be_gen (uuid_be *u); +bool __must_check uuid_is_valid (const char *uuid); + +extern const u8 uuid_le_index[16 ]; +extern const u8 uuid_be_index[16 ]; + +int uuid_le_to_bin (const char *uuid,uuid_le *u); +int uuid_be_to_bin (const char *uuid,uuid_be *u); +#endif
lib/uuid.c renamed from lib/uuid.c~lib-uuid-introduce-few-more-generic-helpers-for-uuid +65 -0
78 lines not on this page · raw message
lib/vsprintf.c renamed from lib/vsprintf.c~lib-uuid-introduce-few-more-generic-helpers-for-uuid +4 -5
@@ -30,6 +30,7 @@#include <linux/ioport.h> #include <linux/dcache.h> #include <linux/cred.h> +#include <linux/uuid.h> #include <net/addrconf.h> #ifdef CONFIG_BLOCK #include <linux/blkdev.h>
@@ -1304,19 +1305,17 @@ static noinline_for_stackchar *uuid_string (char *buf,char *end,const u8 *addr,struct printf_spec spec,const char *fmt) { -char uuid[sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" )]; +char uuid[UUID_STRING_LEN +1 ];char *p = uuid;int i; -static const u8 be[16 ] = {0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 }; -static const u8 le[16 ] = {3 ,2 ,1 ,0 ,5 ,4 ,7 ,6 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 }; -const u8 *index = be; +const u8 *index = uuid_be_index;bool uc = false;switch (*(++fmt)) {case 'L' : uc = true;/* fall-through */ case 'l' : - index = le; + index = uuid_le_index;break ;case 'B' : uc = true;
_