print_hex_dump(9)
β¨ print_hex_dump(9) β¨
okay so bestie, we're reading the kernel API manual rn β this one's print_hex_dump from the Kernel API Manual, and honestly? it's giving "hex dump but make it fashion" π
πΈ NAME πΈ
print_hex_dump β prints a text hex dump to syslog for a binary blob of data πβ¨ lowkey iconic behaviour, fr fr.
π SYNOPSIS π
void print_hex_dump (const char *level , const char *prefix_str , int
prefix_type , int rowsize , int groupsize , const void *buf , size_t len
, bool ascii );
like, that's the whole vibe right there π one function, eight arguments, zero chill.
π¦ ARGUMENTS π¦
so there are EIGHT of these bad boys and you gotta get them all right, no cap. let's go one by one π«Ά
levelβ the kernel log level, likeKERN_DEBUG. basically how loud you want this dump to be screaming into the logs πprefix_strβ the string you want slapped in front of every single line. the caller supplies the trailing spaces for alignment if they want it all nice and lined up β that's on you, not on the function, periodt β¨prefix_typeβ controls whether you get a prefix of an offset, an address, or literally nothing at all. your options areDUMP_PREFIX_OFFSET,DUMP_PREFIX_ADDRESS,DUMP_PREFIX_NONEπ―rowsizeβ how many bytes you print per line. must be 16 or 32 β no other numbers, bestie, I don't make the rules π€groupsizeβ how many bytes you print at a time (1,2,4,8; default =1) πbufβ the data blob you're dumping. this is the main character, the actual content, the whole reason we're here πlenβ the number of bytes inbuf. gotta tell it how much to look at, or it's just guessing πasciiβ include ASCII after the hex output. set this and you get the cute little readable column on the side π
π DESCRIPTION π
Given a buffer of u8 data, print_hex_dump prints a hex + ASCII dump to the kernel log at the specified kernel log level, with an optional leading prefix. simple as that, slay π
print_hex_dump works on one "line" of output at a time β i.e., 16 or 32 bytes of input data converted to hex + ASCII output. then print_hex_dump iterates over the entire input buf, breaking it into "line size" chunks to format and print. one line at a time, over and over, till it's done β it's giving main character energy with a very repetitive routine π
E.g.:
print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, 16, 1, frame->data, frame->len, true);
Example output using DUMP_PREFIX_OFFSET and 1-byte mode:
0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f ABCDEFGHIJKLMNO
Example output using DUMP_PREFIX_ADDRESS and 4-byte mode:
ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~.
like... look at that formatting. the alignment. the little ASCII column just vibing on the right. obsessed πβ¨
π§ SEE ALSO π§
- Kernel file
./lib/hexdump.c hex_to_bin(9)hex2bin(9)bin2hex(9)hex_dump_to_buffer(9)
go read those next, iykyk π¦
and that's the whole page bestie π«Ά this one lives in ./lib and the date on it is October 2026 β so yeah, print it out and put it on your wall, it's a keeper πππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms