debugfs_create_file(9)
π debugfs_create_file β the Kernel API Manual moment
okay so bestie, welcome to debugfs_create_file(9) from the Kernel API Manual, and no cap this one is genuinely the main character of debugfs file creation. let's get into it π
β¨ NAME β¨
debugfs_create_file β create a file in the debugfs filesystem π
πΈ SYNOPSIS πΈ
debugfs_create_file (name , mode , parent , data , fops );
literally that's the whole vibe. five args, go off π
π¦ ARGUMENTS π¦
nameβ a pointer to a string containing the name of the file to create. like the actual name-name, the label on the door π·οΈmodeβ the permission that the file should have. yes the permission bits, be responsible with these fr frparentβ a pointer to the parent dentry for this file. this should be a directory dentry if set. if this parameter isNULL, then the file will be created in the root of the debugfs filesystem π (rootless orphan behaviour, we love a flexible queen)dataβ a pointer to something that the caller will want to get to later on. theinode.i_privatepointer will point to this value on the open call. so it's like the little note you pass to future-you πfopsβ a pointer to astruct file_operationsorstruct debugfs_short_fopsthat should be used for this file. your operations, your rules π«Ά
π DESCRIPTION π
so this is the basic "create a file" function for debugfs, and she ATE. it allows for a wide range of flexibility in creating a file, or a directory β but heads up, if you want to create a directory, the debugfs_create_dir function is recommended to be used instead. different function for a different function, iykyk π§
this function will return a pointer to a dentry if it succeeds. π« and this pointer must be passed to the debugfs_remove function when the file is to be removed. no automatic cleanup happens if your module is unloaded β you are responsible here. like, that's on you bestie, nobody's coming to tidy up π
if an error occurs, ERR_PTR(-ERROR) will be returned.
if debugfs is not enabled in the kernel, the value -ENODEV will be returned. sad but valid π
and if fops points to a struct debugfs_short_fops, then simple_open will be used for the open, and only read/write/llseek are supported and are proxied, so no module reference or release are needed. short and sweet, lowkey iconic β¨
π NOTE π
it's expected that most callers should _ignore_ the errors returned by this function. like literally ignore them, it's giving unbothered π
other debugfs functions handle the fact that the "dentry" passed to them could be an error and they don't crash in that case. drivers should generally work fine even if debugfs fails to init anyway. resilient king behaviour fr fr π₯
π«Ά SEE ALSO π«Ά
Kernel file ./include/linux/debugfs.h and debugfs_create_xul(9) β go read those too, bestie, knowledge is free π
and that's the whole page!! this adorable little doc lives under ./include/linux in the Kernel API Manual, and it's stamped October 2026 π so whenever you see that date, just know the debugfs girlies were thriving. mwah, bye bestie πππ¦
π¦ 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