fscrypt_prepare_new_inode(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’« 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_mode and ->i_blkbits must 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 to true if 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't GFP_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_ino isn'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 ⭐

  • 0 on success β€” we love a clean win, periodt. πŸ‘‘
  • -ENOKEY if a key needs to be set up for dir or inode but the needed master key is absent. that's the "where's the key, we can't find the key" situation. πŸ’€
  • or another -errno code β€” because life is full of surprises. 🌈

🫢 SEE ALSO 🫢

kernel file ./fs/crypto/keysetup.c, and these absolute icons:

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