print_hex_dump(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

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, like KERN_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 are DUMP_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 in buf. 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 🧚

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