kernel_read_file(9)
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*bufisNULL, a buffer will be allocated, andbuf_sizewill be ignored. no cap.buf_sizeβ size ofbuf, if already allocated. Ifbufnot allocated, this is the largest size to allocate.file_sizeβ if non-NULL, the full size offilewill be written here.idβ thekernel_read_file_ididentifying 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
- 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