diff options
Diffstat (limited to 'lib/vsprintf.c')
-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) { |