10 #include <linux/types.h>
11 #include <linux/ctype.h>
12 #include <linux/kernel.h>
13 #include <linux/export.h>
15 const char hex_asc[] =
"0123456789abcdef";
27 if ((ch >=
'0') && (ch <=
'9'))
30 if ((ch >=
'a') && (ch <=
'f'))
50 if ((hi < 0) || (lo < 0))
53 *dst++ = (hi << 4) | lo;
84 int groupsize,
char *linebuf,
size_t linebuflen,
92 if (rowsize != 16 && rowsize != 32)
99 if ((len % groupsize) != 0)
105 int ngroups = len / groupsize;
107 for (j = 0; j < ngroups; j++)
108 lx +=
scnprintf(linebuf + lx, linebuflen - lx,
109 "%s%16.16llx", j ?
" " :
"",
110 (
unsigned long long)*(ptr8 + j));
111 ascii_column = 17 * ngroups + 2;
117 int ngroups = len / groupsize;
119 for (j = 0; j < ngroups; j++)
120 lx +=
scnprintf(linebuf + lx, linebuflen - lx,
121 "%s%8.8x", j ?
" " :
"", *(ptr4 + j));
122 ascii_column = 9 * ngroups + 2;
128 int ngroups = len / groupsize;
130 for (j = 0; j < ngroups; j++)
131 lx +=
scnprintf(linebuf + lx, linebuflen - lx,
132 "%s%4.4x", j ?
" " :
"", *(ptr2 + j));
133 ascii_column = 5 * ngroups + 2;
138 for (j = 0; (j < len) && (lx + 3) <= linebuflen; j++) {
147 ascii_column = 3 * rowsize + 2;
153 while (lx < (linebuflen - 1) && lx < (ascii_column - 1))
155 for (j = 0; (j < len) && (lx + 2) < linebuflen; j++) {
160 linebuf[lx++] =
'\0';
196 void print_hex_dump(
const char *
level,
const char *prefix_str,
int prefix_type,
197 int rowsize,
int groupsize,
198 const void *
buf,
size_t len,
bool ascii)
201 int i, linelen, remaining = len;
202 unsigned char linebuf[32 * 3 + 2 + 32 + 1];
204 if (rowsize != 16 && rowsize != 32)
207 for (i = 0; i < len; i += rowsize) {
208 linelen =
min(remaining, rowsize);
209 remaining -= rowsize;
212 linebuf,
sizeof(linebuf), ascii);
214 switch (prefix_type) {
217 level, prefix_str, ptr + i, linebuf);
220 printk(
"%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
223 printk(
"%s%s%s\n", level, prefix_str, linebuf);
242 void print_hex_dump_bytes(
const char *prefix_str,
int prefix_type,
243 const void *buf,
size_t len)
245 print_hex_dump(
KERN_DEBUG, prefix_str, prefix_type, 16, 1,