DEV_CLONE(9)

πŸ’– DEV_CLONE πŸ’–

okay bestie, welcome to the Kernel Developer's Manual entry for DEV_CLONE(9) β€” yes that's the section number, we're in the big-kid kernel docs now, iykyk 🫢


✨ NAME ✨

dev_clone, drain_dev_clone_events β€” eventhandler for name-based device cloning in devfs 🌸


πŸŽ€ SYNOPSIS πŸŽ€

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

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

EVENTHANDLER_REGISTER(dev_clone, clone_handler, arg, priority);

void
drain_dev_clone_events();

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: a device driver can register a listener, and that listener gets pinged every single time a name lookup on the devfs(5) mount point fails to find the vnode. like, the lookup came up empty, so now the handler gets a shot at it. the way that you sign up for this is by registering a listener for the dev_clone event β€” that's the whole gig πŸ’…

when your handler gets called, it's handed:

  • the first argument arg β€” exactly the one you specified at handler registration time, no substitutions, no surprises
  • the appropriate credentials cr πŸ‘‘
  • a name name of length namelen that we look for πŸ”

and here's the moment of truth, bestie: if the handler decides that the name is appropriate and it actually wants to create the device that will be associated with that name, it should return it to devfs in the dev argument. that's the handoff. that's the slay. ✨


πŸ’œ drain_dev_clone_events() β€” the barrier πŸ’œ

the drain_dev_clone_events() function is a barrier. and it's guaranteed that all calls to eventhandlers for dev_clone that were started before the drain_dev_clone_events() call are finished before it returns control. so when it hands the CPU back to you, everything that was already in flight is done. periodt 🫢


🌈 SEE ALSO 🌈


ngl, that's the whole page β€” short, sweet, and absolutely iconic πŸ’–

okay and before you go, the boring-but-important receipts: this came from Debian, dated January 3, 2009, and it's the DEV_CLONE(9) page out of the Kernel Developer's Manual. love that for us πŸŽ€πŸ’…βœ¨

πŸ“¦ where this page comes from