fscrypt_prepare_new_inode(9)
π« fscrypt_prepare_new_inode β like, the kernel API manual, bestie
okay so this is fscrypt_prepare_new_inode(9) from the Kernel API Manual and it's literally the glow-up routine you run before a brand-new inode gets created inside a directory. think of it as the pre-game. the vibe check before the main character (the inode) walks in. π
β¨ SYNOPSIS β¨
int fscrypt_prepare_new_inode (struct inode *dir , struct inode *inode ,
bool *encrypt_ret );
that's it. that's the whole aesthetic. three args, one int back. slay. π
πΈ ARGUMENTS πΈ
dirβ a possibly-encrypted directory. maybe it's encrypted, maybe it's not, we don't judge, we just check. π¦inodeβ the new inode, the fresh baby, the new addition to the group chat. heads up tho: its->i_modeand->i_blkbitsmust be set already. like, non-negotiable, already done. but->i_ino? doesn't need to be set yet. no pressure, it'll come later. πencrypt_retβ this one's an output (yes, a pointer, she writes back π) and it gets set totrueif the new inode will be encrypted.
π DESCRIPTION π
so here's the tea. if the directory is encrypted, this function sets up its encryption key in preparation for encrypting the name of the new file. got it? the directory's name-encrypting situation gets handled.
and also β if the new inode itself will be encrypted, it sets up its encryption key too, and sets *encrypt_ret=true. two keys, two setups, one function call. iconic behavior honestly. β¨
β οΈ important caveat time, do not skip this: this isn'tGFP_NOFS-safe. so because of that, you gotta call it before starting any filesystem transaction to create the inode. that's literally the reason->i_inoisn't required to be set yet β the filesystem may not have set it at that point. the ordering is the whole point, bestie. no cap. π₯
one more thing, and this is lowkey a big deal: this does not persist the new inode's encryption context. nope. nada. that part still needs to be done later by calling fscrypt_set_context. so don't be out here thinking you're done, because you are not done. π
β RETURN β
0on success β we love a clean win, periodt. π-ENOKEYif a key needs to be set up fordirorinodebut the needed master key is absent. that's the "where's the key, we can't find the key" situation. π- or another
-errnocode β because life is full of surprises. π
π«Ά SEE ALSO π«Ά
kernel file ./fs/crypto/keysetup.c, and these absolute icons:
fscrypt_get_encryption_info(9)fscrypt_put_encryption_info(9)fscrypt_free_inode(9)fscrypt_drop_inode(9)
iykyk. go read them, they're all part of the same lore. π§
and that's the page!! mwah π this whole thing lives in ./fs/crypto, dated October 2026, and it's the fscrypt_prepare_new_inode(9) page β hope that cleared everything up for you bestie, now go set up those keys before you start any transactions, 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