VN_DEALLOCATE(9)
π VN_DEALLOCATE π
okay so bestie, this is from the Kernel Developer's Manual, section 9 β yes, the kernel one, we're in the big leagues now π
. Sit down, hydrate, and let's talk about vn_deallocate.
β¨ NAME β¨
vn_deallocate β zero and/or deallocate storage from a file. that's it, that's the whole vibe. it zeroes stuff and frees up the backing storage. iconic behavior honestly π«Ά
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <sys/vnode.h>
int
vn_deallocate(struct vnode *vp, off_t *offset, off_t *length, int flags,
int ioflag, struct ucred *active_cred, struct ucred *file_cred);
like, you gotta include both headers, no skipping, they're a package deal π and the return type is int, okay?
β¨ DESCRIPTION β¨
so the vn_deallocate() function zeros and/or deallocates backing storage space from a file β literally both, that "and/or" is doing so much work and we love her for it. π
but here's the catch, bestie β this bad girl only works on vnodes with VREG type. only regular files. don't come at her with anything else, she will not entertain it π
the arguments (let me introduce you) π«Ά
vpβ the vnode of the file. the main character, literally.offsetβ the starting offset of the operation range. where the party begins.lengthβ the length of the operation range. this must be greater than 0 β no zero-length shenanigans, it's giving boundaries and honestly, respect.flagsβ the control flags of the operation. this should be set to0for now β yes, just zero, that's the assignment, don't overthink it.ioflagβ directives and hints to be given to the file system. the little whispers in the fs's ear β¨active_credβ the user credentials of the calling thread. who even are you, identify yourself πͺͺfile_credβ the credentials installed on the file description pointing to the vnode, orNOCRED. either you've got creds or you've gotNOCRED, no in-between.
the ioflag situation π
the ioflag() argument gives directives and hints to the file system, and it may include one or more of these babies:
IO_NODELOCKEDβ the vnode was locked before the call. you handled that already, look at you go πIO_RANGELOCKEDβ rangelock was owned around the call. rangelocked and ready πIO_NOMACCHECKβ skip MAC checking in the call. we're not doing the MAC check today, moving on πIO_SYNCβ do I/O synchronously. no shortcuts, we wait.IO_DIRECTβ attempt to bypass buffer cache. going straight to the source, main character energy fr fr π₯
what happens to *offset and *length after π
okay this is the part that actually matters, pay attention:
*offset and *length are updated to reflect the unprocessed operation range</u> of the call. so like, whatever didn't get processed? that's what they tell you afterwards. very transparent of them π
and for a successful completion:
*lengthis updated to be the value0β yup, zero, all done, nothing left πΈ*offsetis incremented by the number of bytes zeroed before the end-of-file. she moved up by exactly how much got zeroed before EOF, no more no less.
β¨ RETURN VALUES β¨
upon successful completion, the value 0 is returned; otherwise the appropriate error is returned.
so basically: zero = slay π , anything else = the appropriate error, and she will let you know.
β¨ SEE ALSO β¨
go read those too bestie, they're literally friends with this page π¦
β¨ AUTHORS β¨
vn_deallocate and this manual page was written by Ka Ho Ng <khng@FreeBSD.org> under sponsorship from the FreeBSD Foundation. give her a round of applause, we stan a sponsored kernel dev πππ
and that's the whole page bestie β no cap, every flag accounted for. this one shipped on Debian, dated August 25, 2021, so if you're citing it: Debian, August 25, 2021, VN_DEALLOCATE(9). mwah ππβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- π the page's license: BSD-2-Clause
- Copyright (c) 2021 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms