get_anon_bdev(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… get_anon_bdev πŸ’…

okay so bestie, welcome to the Kernel API Manual ✨ β€” today's main character is get_anon_bdev(9), and she's literally the friend who hooks you up when you don't have your own block device. let's get into it 🫢


✨ NAME ✨

get_anon_bdev β€” allocate a block device for filesystems which don't have one. no cap, that's the whole job πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

int get_anon_bdev (dev_t *p );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • p β€” a pointer to a dev_t. that's it, that's the argument. she takes one (1) pointer and she takes it seriously ✨

🌸 DESCRIPTION 🌸

so like, some filesystems don't use real block devices β€” they're doing their own thing, living their truth πŸ’… β€” and those filesystems can call this function to allocate a virtual block device.

that's the vibe. no physical hardware required, just a cute little virtual bdev to call your own πŸŽ€


πŸ’œ CONTEXT πŸ’œ

Any context. literally any. she's flexible like that 🧚

though highkey, she's frequently called while holding sb_lock β€” so like, know that going in, iykyk 😌


⭐ RETURN ⭐

here's the vibe check on what you get back:

  • 0 β€” slay, success πŸ’–
  • -EMFILE β€” no anonymous bdevs left 😭 they're all taken, the shelf is empty
  • -ENOMEM β€” memory allocation failed πŸ’€ the malloc said no

🌈 SEE ALSO 🌈

buckle up bestie, this is a whole friend group β€” all from the kernel file ./fs/super.c:

super_lock(9), alloc_super(9), deactivate_locked_super(9), deactivate_super(9), grab_super(9), retire_super(9), generic_shutdown_super(9), sget_fc(9), iterate_supers_type(9), reconfigure_super(9), emergency_thaw_all(9), sget_dev(9), fs_bdev_freeze(9), fs_bdev_thaw(9), fs_bdev_file_open_by_dev(9), fs_bdev_file_open_by_path(9), fs_bdev_unregister(9), fs_bdev_file_release(9), get_tree_bdev_flags(9), get_tree_bdev(9), vfs_get_tree(9), sb_wait_write(9), freeze_super(9), thaw_super(9)

like i said. a whole friend group. go say hi πŸ‘‹πŸ’œ


remembe: virtual bdevs are a limited resource, so when -EMFILE hits, that's your sign to actually clean up after yourself. be the friend who returns the tupperware πŸ“

okay that's the page!! this one lives in ./fs and it's dated October 2026 β€” so like, mark your calendar, she's a whole era πŸ‘‘βœ¨ bye bestie, go allocate responsibly πŸ’…πŸŽ€

πŸ“¦ where this page comes from