kernel_read_file(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

okay so bestie, welcome to kernel_read_file(9) from the Kernel API Manual β€” the little kernel API that reads file contents into a kernel buffer, and we're gonna make it make sense πŸ’…βœ¨

🌸 NAME 🌸

kernel_read_file β€” read file contents into a kernel buffer

✨ SYNOPSIS ✨

ssize_t kernel_read_file (struct file *file , loff_t offset , void **buf
, size_t buf_size , size_t *file_size , enum kernel_read_file_id id );

πŸŽ€ ARGUMENTS πŸŽ€

  • file β€” the file to read from, literally.
  • offset β€” where to start reading from (see below, bestie).
  • buf β€” pointer to a "void *" buffer for reading into. If *buf is NULL, a buffer will be allocated, and buf_size will be ignored. no cap.
  • buf_size β€” size of buf, if already allocated. If buf not allocated, this is the largest size to allocate.
  • file_size β€” if non-NULL, the full size of file will be written here.
  • id β€” the kernel_read_file_id identifying the type of file contents being read (for LSMs to examine, iykyk).

πŸ’… DESCRIPTION πŸ’…

okay so the offset situation is a whole vibe check: offset must be 0 unless both buf and file_size are non-NULL (i.e. the caller must be expecting to read partial file contents via an already-allocated buf, in at most buf_size chunks, and will be able to determine when the entire file was read by checking file_size). This isn't a recommended way to read a file, though, since it is possible that the contents might change between calls to kernel_read_file. 🫢

Returns number of bytes read (no single read will be bigger than SSIZE_MAX), or negative on error. periodt.

πŸ¦‹ SEE ALSO πŸ¦‹

  • Kernel file ./fs/kernel_read_file.c β€” that's the source file, go look πŸ’–

this page is from source/version ./fs, dated October 2026, and it's the kernel_read_file(9) manual β€” mwah πŸ’‹πŸŽ€

πŸ“¦ where this page comes from