History

uuid: rename uuid types

Our "little endian" UUID really is a Wintel GUID, so rename it and its helpers such (guid_t). The big endian UUID is the only true one, so give it the name uuid_t. The uuid_le and uuid_be names are retained for now, but will hopefully go away soon. The exception to that are the _cmp helpers that will be replaced by better primitives ASAP and thus don't get the new names. Also the _to_bin helpers are named to match the better named uuid_parse routine in userspace. Also remove the existing typedef in XFS that's now been superceeded by the generic type name. Signed-off-by: Christoph Hellwig <hch@lst.de> [andy: also update the UUID_LE/UUID_BE macros including fallout] Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Christoph Hellwig committed 9 years ago

Commit f9727a11 parent 60927bc6 files · +73 −62Browse files

Unified · Split

6 files
  1. fs/xfs/xfs_linux.h +0 −2
  2. include/linux/uuid.h +32 −23
  3. include/uapi/linux/uuid.h +8 −4
  4. lib/test_uuid.c +16 −16
  5. lib/uuid.c +15 −15
  6. lib/vsprintf.c +2 −2
fs/xfs/xfs_linux.h+0−2
@@ -39,8 +39,6 @@ typedef __s64 xfs_daddr_t; /* <disk address> type */ · 38 unmodified lines
3939 typedef __u32 xfs_dev_t;
4040 typedef __u32 xfs_nlink_t;
4141
42−typedef uuid_be uuid_t;
43−
4442 #include "xfs_types.h"
4543
4644 #include "kmem.h"
include/linux/uuid.h+32−23
@@ -20,46 +20,55 @@ · 19 unmodified lines
2020
2121 typedef struct {
2222 __u8 b[16];
23−} uuid_be;
23+} uuid_t;
2424
25−#define UUID_BE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
26−((uuid_be) \
25+#define UUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
26+((uuid_t) \
2727 {{ ((a) >> 24) & 0xff, ((a) >> 16) & 0xff, ((a) >> 8) & 0xff, (a) & 0xff, \
2828 ((b) >> 8) & 0xff, (b) & 0xff, \
2929 ((c) >> 8) & 0xff, (c) & 0xff, \
3030 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
3131
32−#define NULL_UUID_BE \
33− UUID_BE(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, \
34− 0x00, 0x00, 0x00, 0x00)
35−
3632 /*
3733 * The length of a UUID string ("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
3834 * not including trailing NUL.
3935 */
4036 #define UUID_STRING_LEN 36
4137
42−static inline int uuid_le_cmp(const uuid_le u1, const uuid_le u2)
43−{
44− return memcmp(&u1, &u2, sizeof(uuid_le));
45−}
46−
47−static inline int uuid_be_cmp(const uuid_be u1, const uuid_be u2)
48−{
49− return memcmp(&u1, &u2, sizeof(uuid_be));
50−}
51−
5238 void generate_random_uuid(unsigned char uuid[16]);
5339
54−extern void uuid_le_gen(uuid_le *u);
55−extern void uuid_be_gen(uuid_be *u);
40+extern void guid_gen(guid_t *u);
41+extern void uuid_gen(uuid_t *u);
5642
5743 bool __must_check uuid_is_valid(const char *uuid);
5844
59−extern const u8 uuid_le_index[16];
60−extern const u8 uuid_be_index[16];
45+extern const u8 guid_index[16];
46+extern const u8 uuid_index[16];
47+
48+int guid_parse(const char *uuid, guid_t *u);
49+int uuid_parse(const char *uuid, uuid_t *u);
6150
62−int uuid_le_to_bin(const char *uuid, uuid_le *u);
63−int uuid_be_to_bin(const char *uuid, uuid_be *u);
51+/* backwards compatibility, don't use in new code */
52+typedef uuid_t uuid_be;
53+#define UUID_BE(a, _b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
54+ UUID_INIT(a, _b, c, d0, d1, d2, d3, d4, d5, d6, d7)
55+#define NULL_UUID_BE \
56+ UUID_BE(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, \
57+ 0x00, 0x00, 0x00, 0x00)
58+
59+#define uuid_le_gen(u) guid_gen(u)
60+#define uuid_be_gen(u) uuid_gen(u)
61+#define uuid_le_to_bin(guid, u) guid_parse(guid, u)
62+#define uuid_be_to_bin(uuid, u) uuid_parse(uuid, u)
63+
64+static inline int uuid_le_cmp(const guid_t u1, const guid_t u2)
65+{
66+ return memcmp(&u1, &u2, sizeof(guid_t));
67+}
68+
69+static inline int uuid_be_cmp(const uuid_t u1, const uuid_t u2)
70+{
71+ return memcmp(&u1, &u2, sizeof(uuid_t));
72+}
6473
6574 #endif
include/uapi/linux/uuid.h+8−4
@@ -22,17 +22,21 @@ · 21 unmodified lines
2222
2323 typedef struct {
2424 __u8 b[16];
25−} uuid_le;
25+} guid_t;
2626
27−#define UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
28−((uuid_le) \
27+#define GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
28+((guid_t) \
2929 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
3030 (b) & 0xff, ((b) >> 8) & 0xff, \
3131 (c) & 0xff, ((c) >> 8) & 0xff, \
3232 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
3333
34+/* backwards compatibility, don't use in new code */
35+typedef guid_t uuid_le;
36+#define UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
37+ GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
3438 #define NULL_UUID_LE \
3539 UUID_LE(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, \
36− 0x00, 0x00, 0x00, 0x00)
40+ 0x00, 0x00, 0x00, 0x00)
3741
3842 #endif /* _UAPI_LINUX_UUID_H_ */
lib/test_uuid.c+16−16
@@ -11,25 +11,25 @@ · 10 unmodified lines
1111
1212 struct test_uuid_data {
1313 const char *uuid;
14− uuid_le le;
15− uuid_be be;
14+ guid_t le;
15+ uuid_t be;
1616 };
1717
1818 static const struct test_uuid_data test_uuid_test_data[] = {
1919 {
2020 .uuid = "c33f4995-3701-450e-9fbf-206a2e98e576",
21− .le = UUID_LE(0xc33f4995, 0x3701, 0x450e, 0x9f, 0xbf, 0x20, 0x6a, 0x2e, 0x98, 0xe5, 0x76),
22− .be = UUID_BE(0xc33f4995, 0x3701, 0x450e, 0x9f, 0xbf, 0x20, 0x6a, 0x2e, 0x98, 0xe5, 0x76),
21+ .le = GUID_INIT(0xc33f4995, 0x3701, 0x450e, 0x9f, 0xbf, 0x20, 0x6a, 0x2e, 0x98, 0xe5, 0x76),
22+ .be = UUID_INIT(0xc33f4995, 0x3701, 0x450e, 0x9f, 0xbf, 0x20, 0x6a, 0x2e, 0x98, 0xe5, 0x76),
2323 },
2424 {
2525 .uuid = "64b4371c-77c1-48f9-8221-29f054fc023b",
26− .le = UUID_LE(0x64b4371c, 0x77c1, 0x48f9, 0x82, 0x21, 0x29, 0xf0, 0x54, 0xfc, 0x02, 0x3b),
27− .be = UUID_BE(0x64b4371c, 0x77c1, 0x48f9, 0x82, 0x21, 0x29, 0xf0, 0x54, 0xfc, 0x02, 0x3b),
26+ .le = GUID_INIT(0x64b4371c, 0x77c1, 0x48f9, 0x82, 0x21, 0x29, 0xf0, 0x54, 0xfc, 0x02, 0x3b),
27+ .be = UUID_INIT(0x64b4371c, 0x77c1, 0x48f9, 0x82, 0x21, 0x29, 0xf0, 0x54, 0xfc, 0x02, 0x3b),
2828 },
2929 {
3030 .uuid = "0cb4ddff-a545-4401-9d06-688af53e7f84",
31− .le = UUID_LE(0x0cb4ddff, 0xa545, 0x4401, 0x9d, 0x06, 0x68, 0x8a, 0xf5, 0x3e, 0x7f, 0x84),
32− .be = UUID_BE(0x0cb4ddff, 0xa545, 0x4401, 0x9d, 0x06, 0x68, 0x8a, 0xf5, 0x3e, 0x7f, 0x84),
31+ .le = GUID_INIT(0x0cb4ddff, 0xa545, 0x4401, 0x9d, 0x06, 0x68, 0x8a, 0xf5, 0x3e, 0x7f, 0x84),
32+ .be = UUID_INIT(0x0cb4ddff, 0xa545, 0x4401, 0x9d, 0x06, 0x68, 0x8a, 0xf5, 0x3e, 0x7f, 0x84),
3333 },
3434 };
3535
@@ -61,13 +61,13 @@ static void __init test_uuid_failed(const char *prefix, bool wrong, bool be, · 25 unmodified lines
6161
6262 static void __init test_uuid_test(const struct test_uuid_data *data)
6363 {
64− uuid_le le;
65− uuid_be be;
64+ guid_t le;
65+ uuid_t be;
6666 char buf[48];
6767
6868 /* LE */
6969 total_tests++;
70− if (uuid_le_to_bin(data->uuid, &le))
70+ if (guid_parse(data->uuid, &le))
7171 test_uuid_failed("conversion", false, false, data->uuid, NULL);
7272
7373 total_tests++;
@@ -78,7 +78,7 @@ static void __init test_uuid_test(const struct test_uuid_data *data) · 4 unmodified lines
7878
7979 /* BE */
8080 total_tests++;
81− if (uuid_be_to_bin(data->uuid, &be))
81+ if (uuid_parse(data->uuid, &be))
8282 test_uuid_failed("conversion", false, true, data->uuid, NULL);
8383
8484 total_tests++;
@@ -90,17 +90,17 @@ static void __init test_uuid_test(const struct test_uuid_data *data) · 5 unmodified lines
9090
9191 static void __init test_uuid_wrong(const char *data)
9292 {
93− uuid_le le;
94− uuid_be be;
93+ guid_t le;
94+ uuid_t be;
9595
9696 /* LE */
9797 total_tests++;
98− if (!uuid_le_to_bin(data, &le))
98+ if (!guid_parse(data, &le))
9999 test_uuid_failed("negative", true, false, data, NULL);
100100
101101 /* BE */
102102 total_tests++;
103− if (!uuid_be_to_bin(data, &be))
103+ if (!uuid_parse(data, &be))
104104 test_uuid_failed("negative", true, true, data, NULL);
105105 }
106106
lib/uuid.c+15−15
@@ -21,10 +21,10 @@ · 20 unmodified lines
2121 #include <linux/uuid.h>
2222 #include <linux/random.h>
2323
24−const u8 uuid_le_index[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
25−EXPORT_SYMBOL(uuid_le_index);
26−const u8 uuid_be_index[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
27−EXPORT_SYMBOL(uuid_be_index);
24+const u8 guid_index[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
25+EXPORT_SYMBOL(guid_index);
26+const u8 uuid_index[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
27+EXPORT_SYMBOL(uuid_index);
2828
2929 /***************************************************************
3030 * Random UUID interface
@@ -53,21 +53,21 @@ static void __uuid_gen_common(__u8 b[16]) · 22 unmodified lines
5353 b[8] = (b[8] & 0x3F) | 0x80;
5454 }
5555
56−void uuid_le_gen(uuid_le *lu)
56+void guid_gen(guid_t *lu)
5757 {
5858 __uuid_gen_common(lu->b);
5959 /* version 4 : random generation */
6060 lu->b[7] = (lu->b[7] & 0x0F) | 0x40;
6161 }
62−EXPORT_SYMBOL_GPL(uuid_le_gen);
62+EXPORT_SYMBOL_GPL(guid_gen);
6363
64−void uuid_be_gen(uuid_be *bu)
64+void uuid_gen(uuid_t *bu)
6565 {
6666 __uuid_gen_common(bu->b);
6767 /* version 4 : random generation */
6868 bu->b[6] = (bu->b[6] & 0x0F) | 0x40;
6969 }
70−EXPORT_SYMBOL_GPL(uuid_be_gen);
70+EXPORT_SYMBOL_GPL(uuid_gen);
7171
7272 /**
7373 * uuid_is_valid - checks if UUID string valid
@@ -97,7 +97,7 @@ bool uuid_is_valid(const char *uuid) · 23 unmodified lines
9797 }
9898 EXPORT_SYMBOL(uuid_is_valid);
9999
100−static int __uuid_to_bin(const char *uuid, __u8 b[16], const u8 ei[16])
100+static int __uuid_parse(const char *uuid, __u8 b[16], const u8 ei[16])
101101 {
102102 static const u8 si[16] = {0,2,4,6,9,11,14,16,19,21,24,26,28,30,32,34};
103103 unsigned int i;
@@ -115,14 +115,14 @@ static int __uuid_to_bin(const char *uuid, __u8 b[16], const u8 ei[16]) · 11 unmodified lines
115115 return 0;
116116 }
117117
118−int uuid_le_to_bin(const char *uuid, uuid_le *u)
118+int guid_parse(const char *uuid, guid_t *u)
119119 {
120− return __uuid_to_bin(uuid, u->b, uuid_le_index);
120+ return __uuid_parse(uuid, u->b, guid_index);
121121 }
122−EXPORT_SYMBOL(uuid_le_to_bin);
122+EXPORT_SYMBOL(guid_parse);
123123
124−int uuid_be_to_bin(const char *uuid, uuid_be *u)
124+int uuid_parse(const char *uuid, uuid_t *u)
125125 {
126− return __uuid_to_bin(uuid, u->b, uuid_be_index);
126+ return __uuid_parse(uuid, u->b, uuid_index);
127127 }
128−EXPORT_SYMBOL(uuid_be_to_bin);
128+EXPORT_SYMBOL(uuid_parse);
lib/vsprintf.c+2−2
@@ -1308,14 +1308,14 @@ char *uuid_string(char *buf, char *end, const u8 *addr, · 1307 unmodified lines
13081308 char uuid[UUID_STRING_LEN + 1];
13091309 char *p = uuid;
13101310 int i;
1311− const u8 *index = uuid_be_index;
1311+ const u8 *index = uuid_index;
13121312 bool uc = false;
13131313
13141314 switch (*(++fmt)) {
13151315 case 'L':
13161316 uc = true; /* fall-through */
13171317 case 'l':
1318− index = uuid_le_index;
1318+ index = guid_index;
13191319 break;
13201320 case 'B':
13211321 uc = true;