diff options
| author | Joe Perches <joe@perches.com> | 2009-12-14 21:01:09 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-15 11:53:33 -0500 |
| commit | 9ac6e44ee5caa5f0babfc87f2613e1296d2c2d11 (patch) | |
| tree | 2309170eef8e4fc5c78e00c297cd0e2344d559b0 /lib | |
| parent | b5f54b07c06f6e438a4fee92c27423e880d8816b (diff) | |
lib/vsprintf.c: add %pU to print UUID/GUIDs
UUID/GUIDs are somewhat common in kernel source.
Standardize the printed style of UUID/GUIDs by using
another extension to %p.
%pUb: 01020304-0506-0708-090a-0b0c0d0e0f10
%pUB: 01020304-0506-0708-090A-0B0C0D0E0F10 (upper case)
%pUl: 04030201-0605-0807-090a-0b0c0d0e0f10
%pUL: 04030201-0605-0807-090A-0B0C0D0E0F10 (upper case)
%pU defaults to %pUb
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Jeff Garzik <jgarzik@redhat.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Alex Elder <aelder@sgi.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Artem Bityutskiy <dedekind@infradead.org>
Cc: Adrian Hunter <adrian.hunter@nokia.com>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
Cc: Matt Mackall <mpm@selenic.com>
Cc: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/vsprintf.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 7857d4dd62d3..735343fc857a 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
| @@ -834,6 +834,52 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
| 834 | return string(buf, end, ip4_addr, spec); | 834 | return string(buf, end, ip4_addr, spec); |
| 835 | } | 835 | } |
| 836 | 836 | ||
| 837 | static char *uuid_string(char *buf, char *end, const u8 *addr, | ||
| 838 | struct printf_spec spec, const char *fmt) | ||
| 839 | { | ||
| 840 | char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]; | ||
| 841 | char *p = uuid; | ||
| 842 | int i; | ||
| 843 | static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; | ||
| 844 | static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; | ||
| 845 | const u8 *index = be; | ||
| 846 | bool uc = false; | ||
| 847 | |||
| 848 | switch (*(++fmt)) { | ||
| 849 | case 'L': | ||
| 850 | uc = true; /* fall-through */ | ||
| 851 | case 'l': | ||
| 852 | index = le; | ||
| 853 | break; | ||
| 854 | case 'B': | ||
| 855 | uc = true; | ||
| 856 | break; | ||
| 857 | } | ||
| 858 | |||
| 859 | for (i = 0; i < 16; i++) { | ||
| 860 | p = pack_hex_byte(p, addr[index[i]]); | ||
| 861 | switch (i) { | ||
| 862 | case 3: | ||
| 863 | case 5: | ||
| 864 | case 7: | ||
| 865 | case 9: | ||
| 866 | *p++ = '-'; | ||
| 867 | break; | ||
| 868 | } | ||
| 869 | } | ||
| 870 | |||
| 871 | *p = 0; | ||
| 872 | |||
| 873 | if (uc) { | ||
| 874 | p = uuid; | ||
| 875 | do { | ||
| 876 | *p = toupper(*p); | ||
| 877 | } while (*(++p)); | ||
| 878 | } | ||
| 879 | |||
| 880 | return string(buf, end, uuid, spec); | ||
| 881 | } | ||
| 882 | |||
| 837 | /* | 883 | /* |
| 838 | * Show a '%p' thing. A kernel extension is that the '%p' is followed | 884 | * Show a '%p' thing. A kernel extension is that the '%p' is followed |
| 839 | * by an extra set of alphanumeric characters that are extended format | 885 | * by an extra set of alphanumeric characters that are extended format |
| @@ -858,6 +904,18 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr, | |||
| 858 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) | 904 | * IPv4 uses dot-separated decimal with leading 0's (010.123.045.006) |
| 859 | * - 'I6c' for IPv6 addresses printed as specified by | 905 | * - 'I6c' for IPv6 addresses printed as specified by |
| 860 | * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt | 906 | * http://www.ietf.org/id/draft-kawamura-ipv6-text-representation-03.txt |
| 907 | * - 'U' For a 16 byte UUID/GUID, it prints the UUID/GUID in the form | ||
| 908 | * "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
| 909 | * Options for %pU are: | ||
| 910 | * b big endian lower case hex (default) | ||
| 911 | * B big endian UPPER case hex | ||
| 912 | * l little endian lower case hex | ||
| 913 | * L little endian UPPER case hex | ||
| 914 | * big endian output byte order is: | ||
| 915 | * [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15] | ||
| 916 | * little endian output byte order is: | ||
| 917 | * [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15] | ||
| 918 | * | ||
| 861 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 | 919 | * Note: The difference between 'S' and 'F' is that on ia64 and ppc64 |
| 862 | * function pointers are really function descriptors, which contain a | 920 | * function pointers are really function descriptors, which contain a |
| 863 | * pointer to the real address. | 921 | * pointer to the real address. |
| @@ -873,8 +931,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
| 873 | case 'f': | 931 | case 'f': |
| 874 | ptr = dereference_function_descriptor(ptr); | 932 | ptr = dereference_function_descriptor(ptr); |
| 875 | /* Fallthrough */ | 933 | /* Fallthrough */ |
| 876 | case 's': | ||
| 877 | case 'S': | 934 | case 'S': |
| 935 | case 's': | ||
| 878 | return symbol_string(buf, end, ptr, spec, *fmt); | 936 | return symbol_string(buf, end, ptr, spec, *fmt); |
| 879 | case 'R': | 937 | case 'R': |
| 880 | case 'r': | 938 | case 'r': |
| @@ -898,6 +956,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, | |||
| 898 | return ip4_addr_string(buf, end, ptr, spec, fmt); | 956 | return ip4_addr_string(buf, end, ptr, spec, fmt); |
| 899 | } | 957 | } |
| 900 | break; | 958 | break; |
| 959 | case 'U': | ||
| 960 | return uuid_string(buf, end, ptr, spec, fmt); | ||
| 901 | } | 961 | } |
| 902 | spec.flags |= SMALL; | 962 | spec.flags |= SMALL; |
| 903 | if (spec.field_width == -1) { | 963 | if (spec.field_width == -1) { |
