Before we get too far into all the issues surrounding resource managers, we have to get acquainted with the QNX Neutrino resource manager library. Note that this library actually consists of several distinct pieces:
While you certainly could write resource managers from scratch (as was done in the QNX 4 world), that's far more hassle than it's worth.
Just to show you the utility of the library approach, here's the source for a single-threaded version of /dev/null:
/* * resmgr1.c * * /dev/null using the resource manager library */ #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <sys/iofunc.h> #include <sys/dispatch.h> int main (int argc, char **argv) { dispatch_t *dpp; resmgr_attr_t resmgr_attr; dispatch_context_t *ctp; resmgr_connect_funcs_t connect_func; resmgr_io_funcs_t io_func; iofunc_attr_t attr; // create the dispatch structure if ((dpp = dispatch_create ()) == NULL) { perror ("Unable to dispatch_create"); exit (EXIT_FAILURE); } // initialize the various data structures memset (&resmgr_attr, 0, sizeof (resmgr_attr)); resmgr_attr.nparts_max = 1; resmgr_attr.msg_max_size = 2048; // bind default functions into the outcall tables iofunc_func_init (_RESMGR_CONNECT_NFUNCS, &connect_func, _RESMGR_IO_NFUNCS, &io_func); iofunc_attr_init (&attr, S_IFNAM | 0666, 0, 0); // establish a name in the pathname space if (resmgr_attach (dpp, &resmgr_attr, "/dev/mynull", _FTYPE_ANY, 0, &connect_func, &io_func, &attr) == -1) { perror ("Unable to resmgr_attach"); exit (EXIT_FAILURE); } ctp = dispatch_context_alloc (dpp); // wait here forever, handling messages while (1) { if ((ctp = dispatch_block (ctp)) == NULL) { perror ("Unable to dispatch_block"); exit (EXIT_FAILURE); } dispatch_handler (ctp); } }
There you have it! A complete /dev/null resource manager implemented in a few function calls!
If you were to write this from scratch, and have it support all the functionality that this one does (e.g., stat() works, chown() and chmod() work, and so on), you'd be looking at many hundreds if not thousands of lines of C code.