fscrypt_prepare_rename(9)
π 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 movednew_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 aboutRENAME_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 β
0on success β slay π-ENOKEYif an encryption key is missing ππ-EXDEVif the rename would cause inconsistent encryption policies π«- or another
-errnocode, because sometimes life gives you surprises π
π¦ SEE ALSO π¦
- Kernel file
./include/linux/fscrypt.hβ the source of truth, go read it π«Ά fscrypt_needs_contents_encryption(9)fscrypt_is_nokey_name(9)fscrypt_has_encryption_key(9)fscrypt_prepare_link(9)fscrypt_prepare_lookup(9)fscrypt_prepare_readdir(9)fscrypt_prepare_setattr(9)fscrypt_encrypt_symlink(9)
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
- 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