DEV_CLONE(9)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… DEV_CLONE(9) β€” bestie edition πŸ’…

okay so this is a page from the Kernel Developer's Manual, section 9, and it's literally about dev_clone and drain_dev_clone_events β€” the eventhandler situation for name-based device cloning in devfs. buckle up, we're going in πŸŽ€


✨ NAME ✨

dev_clone, drain_dev_clone_events β€” no cap, this is the whole eventhandler for name-based device cloning in devfs. that's the vibe. πŸ¦‹


✨ SYNOPSIS ✨

first, the includes, keep them exactly like this bestie:

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

then the handler itself, she's got a whole signature:

void
clone_handler(void *arg, struct ucred *cr, char *name, int namelen,
    struct cdev **dev);

and the registration, iconic:

EVENTHANDLER_REGISTER(dev_clone, clone_handler, arg, priority);

and finally, the barrier function, no args, just vibes:

void
drain_dev_clone_events();

✨ DESCRIPTION ✨

so here's the tea, and it's genuinely good tea πŸ”₯: a device driver can register a listener, and that listener gets notified every single time a name lookup on the devfs(4) mount point fails to find the vnode. like, the lookup struck out and now the listener gets a little tap on the shoulder. πŸ’…

a listener shall be registered for the dev_clone event β€” that's the assignment, that's the move, do it.

when the handler gets called, it's handed these goodies:

  • arg β€” the first argument, literally the exact same arg you specified back at handler registration time. consistency queen πŸ‘‘
  • cr β€” the appropriate credentials, struct ucred and all
  • name β€” the name we're looking for, with length namelen

and here's the decision point: if the handler is like "yes, this name is appropriate," and it wants to create the device that'll be associated with that name, it should hand that device back to devfs in the dev argument. that's it, that's the whole handoff. 🫢

🌸 the barrier one 🌸

the drain_dev_clone_events() function is a barrier. translation: it's guaranteed that all the calls to eventhandlers for dev_clone that were started before the drain_dev_clone_events() call are finished before it returns control. so nothing's still running in the background when she hands control back to you. periodt. πŸ’–


✨ SEE ALSO ✨

go read those next, iykyk πŸ“š


πŸ’€ reminder that this is kernel code, so the details are load-bearing β€” don't go changing names, arguments or defaults because a vibe told you to.

mwah, that's the page ✨ this deliciousness is from Debian, dated January 3, 2009 β€” yes she's vintage, and she still ate. πŸ“πŸ‘‘

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms