VOP_RENAME(9)

πŸ’– VOP_RENAME πŸ’–

okay bestie, welcome to VOP_RENAME(9), straight out of the Kernel Developer's Manual. yes you read that right, we're in the kernel developer section, main character energy only πŸ”₯

this one's all about renaming a file. let's get into it 🫢


✨ NAME ✨

VOP_RENAME β€” rename a file

like. that's the whole job. rename a file. iconic behaviour honestly.


🌸 SYNOPSIS 🌸

#include <sys/param.h>
#include <sys/vnode.h>

int
VOP_RENAME(struct vnode *fdvp, struct vnode *fvp,
    struct componentname *fcnp, struct vnode *tdvp, struct vnode *tvp,
    struct componentname *tcnp);

look at all those args. six of them. she's busy πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so this renames a file, and it might also move it to a whole different parent directory, which is lowkey a glow-up. and if the destination object already exists? yeah, it gets removed first. sorry to that file 😭

its arguments are, in order:

  • fdvp β€” the vnode of the old parent directory (where the file is currently living, rent free).
  • fvp β€” the vnode of the file that's getting renamed. the star of the show πŸ‘‘
  • fcnp β€” pathname information about the file's current name.
  • tdvp β€” the vnode of the new parent directory (the new address, no moving truck required).
  • tvp β€” the vnode of the target file, if it exists. if it doesn't, no worries.
  • tcnp β€” pathname information about the file's new name.

πŸ”’ LOCKS πŸ”’

okay this part is important so pay attention bestie, no skimming πŸ™ˆ

the source directory and the file are unlocked, but they're expected to have their ref count bumped when you enter. the VOP routine is expected to call vrele(9) on both of them before it returns. both. prior to returning. don't forget, fr fr.

the destination directory and file are locked and have their ref count bumped. the VOP routine is expected to call vput(9) on both before returning. yes, vput not vrele. different function. don't mix them up, i'm begging 🫢

so to recap: source = unlocked + ref bumped + vrele(9). destination = locked + ref bumped + vput(9). write it on your hand if you have to.

πŸ’€ ERRORS πŸ’€

here's the list of ways this can go wrong. she's dramatic but she's honest:

  • [EPERM] β€” the file is immutable. it said no. periodt.
  • [EXDEV] β€” you literally cannot rename a file between different file systems. different filesystem, different vibe, no crossover episodes allowed βœ‹
  • [EINVAL] β€” someone tried to rename . or .., or tried an operation that would break the directory tree structure. absolutely not. we do not break the tree, the tree is sacred 🌳
  • [ENOTDIR] β€” an attempt was made to rename a directory to a file, or a file to a directory. pick a lane bestie 😭
  • [ENOTEMPTY] β€” an attempt was made to remove a directory that is not empty. she's still got stuff in her. let her keep her stuff.

🌈 SEE ALSO 🌈

go read that one too, it's the whole ecosystem. iykyk πŸ’œ


πŸ’… AUTHORS πŸ’…

this manual page was written by Doug Rabson. we love and respect Doug in this house 🫢✨


okay and that's the whole page! this version came from Debian, dated July 24, 1996 β€” yeah, 1996, this manpage is older than most of us and she's still serving ⭐

slay, go rename something (responsibly). bye bestie πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from