punch_hole(9)
β¨ punch_hole(9) β¨
okay bestie, welcome to the Kernel API Manual β todayβs main character is punch_hole(9), and she is literally here to deallocate blocks in a file π
πΈ NAME πΈ
punch_hole β deallocate blocks in a file
π¦ SYNOPSIS π¦
int punch_hole (struct gfs2_inode *ip , u64 offset , u64 length );
π ARGUMENTS π
ipβ inode to truncateoffsetβ the start of the holelengthβ the size of the hole (or0for truncate)
π DESCRIPTION π
okay so punch_hole punches a hole into a file or truncates a file at a given position. Thatβs the whole vibe β¨
It operates in whole blocks β offset and length are rounded accordingly β and partially filled blocks must be cleared otherwise. No cap, that part matters.
This function works from the bottom up, and from the right to the left. In other words, it strips off the highest layer (data) before stripping any of the metadata. Doing it this way is best in case the operation is interrupted by power failure, etc. And the dinode is rewritten in every transaction to guarantee integrity. Iconic behavior, honestly π
π SEE ALSO π
lowkey go read these too, iykyk:
- Kernel file:
./fs/gfs2/bmap.c gfs2_unstuffer_folio(9)gfs2_unstuff_dinode(9)find_metapath(9)metaptr1(9)metapointer(9)lookup_metapath(9)fillup_metapath(9)gfs2_extent_length(9)gfs2_hole_size(9)__gfs2_iomap_alloc(9)gfs2_alloc_size(9)__gfs2_iomap_get(9)gfs2_block_map(9)gfs2_journaled_truncate(9)sweep_bh_for_rgrps(9)find_nonnull_ptr(9)do_shrink(9)do_grow(9)gfs2_setattr_size(9)gfs2_free_journal_extents(9)gfs2_add_jextent(9)gfs2_map_journal_extents(9)gfs2_write_alloc_required(9)
k bye bestie π«Ά source: ./fs/gfs2 Β· date: October 2026 Β· page: punch_hole(9) π
π¦ 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