DEV_CLONE(9)
π 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 sameargyou specified back at handler registration time. consistency queen πcrβ the appropriate credentials, structucredand allnameβ the name we're looking for, with lengthnamelen
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
- Copyright (c) 2008 Konstantin Belousov
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms