fscrypt_prepare_rename(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… fscrypt_prepare_rename(9) β€” kernel API manual, bestie edition ✨

okay so picture this: you're deep in the kernel, in fscrypt land, and somebody wants to rename a file where the source dir, the target dir, or honestly both of them, might be encrypted πŸŽ€. That's literally what this function is for. It lives in the Kernel API Manual, and it's here to do the vibe check before the rename actually happens πŸ¦‹.


✨ SYNOPSIS ✨

int fscrypt_prepare_rename (struct inode *old_dir , struct dentry
*old_dentry , struct inode *new_dir , struct dentry *new_dentry ,
unsigned int flags );

like, look at all those parameters. she's got range πŸ’…


🌸 ARGUMENTS 🌸

  • old_dir β€” the source directory, aka where the file is right now 🏠
  • old_dentry β€” the dentry for the source file, the actual thing being moved
  • new_dir β€” the target directory, where it's headed πŸ‘€
  • new_dentry β€” the dentry for the target location. quick note: this one may be negative unless you're exchanging (iykyk)
  • flags β€” the rename flags. we care at least about RENAME_EXCHANGE, so don't be weird about it fr fr

πŸ’– DESCRIPTION πŸ’–

so this is the prep step for ->rename, and the whole point is that the source and/or target directories may be encrypted πŸ”. and here's the tea:

a new link can only be added to an encrypted directory if that directory's encryption key is available β€” because otherwise, bestie, we'd literally have no way to encrypt the filename 😭. that's just math.

but a rename to an existing name? that one is cryptographically possible without the key. yes, technically doable. and yet β€” we take the more conservative approach and just forbid all no-key renames. periodt. no key, no rename πŸ™…β€β™€οΈ

we also verify that the rename won't violate the constraint that all files in an encrypted directory tree use the same encryption policy. consistency is the moment πŸ’…βœ¨

ngl this one's strict on purpose β€” the whole point is not letting a rename sneak past the encryption rules πŸ‘‘

⭐ RETURN ⭐

  • 0 on success β€” slay πŸŽ‰
  • -ENOKEY if an encryption key is missing πŸ”‘πŸ’€
  • -EXDEV if the rename would cause inconsistent encryption policies 🚫
  • or another -errno code, because sometimes life gives you surprises πŸ™ˆ

πŸ¦‹ SEE ALSO πŸ¦‹


that's the whole page, bestie, go forth and rename responsibly πŸ§šπŸ’œ

source/version: ./include/linux Β· dated October 2026 Β· fscrypt_prepare_rename(9) β€” mwah, that's a wrap πŸŽ€βœ¨

πŸ“¦ where this page comes from