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
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1996 Doug Rabson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms