multiple dirs/files in single mount point filesystem


I need to implement a device virtual filesystem which is similar to “sysfs” in Linux. There are more than a hundred files/directories under this device root directory, so my idea is using “resmgr_attach” to mount a single root entry “/mydev” and handling open and read operation with my own code.

For every file/directory open request, I create its own individual infunc_attr_t handle and ibfunc_ocb_t structure like this:

iofunc_attr_t *newattr = malloc(sizeof(struct iofunc_attr_t));

iofunc_attr_init(newattr, S_IFNAM | 0666, NULL, 0);

if ( (status = iofunc_open( ctp, msg, &newattr, NULL, 0 )) != EOK ) {
iofunc_attr_unlock( attr );
printf(“iofunc_open status: %d\n”, status);
return status;

if ( (ocb = ocb_calloc( ctp, (IOFUNC_ATTR_T *)attr )) == NULL ) {
iofunc_attr_unlock( attr );
printf(“ocb_calloc returned NULL\n”);
return ENOMEM;

ocb->private = (void *)file;
ocb->hdr.ioflag = msg->connect.ioflag;

if ( (status = iofunc_ocb_attach( ctp, msg, &ocb->hdr, attr, NULL)) != EOK ) {
iofunc_attr_unlock( attr );
printf(“iofunc_ocb_attach status: %d\n”, status);
return status;

Then when “io_open” operation is called, the system library passes the following parameters to the function:
io_read( resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb )

My question is, since there are only one io_funcs and connect_funcs function entry for the single mount point device (attached using “resmgr_attach”), how can the system library tell which ocb pointer is passed to the “io_read” function? For example, 2 files opened with ocb1 and ocb2, both call “io_open”, can the system library pass the correct ocb pointer to it? Or there are some extra work need to be done to ensure that correct ocb pointer is passed.

Is there any code example for the filesystem resource manager like this?


There is one one per open call, the library takes care of that for you.

so the library knows how to pass the correct ocb pointer to “io_read” as long as “iofunc_ocb_attach” is called in the open operation.

Do “opendir” and “readdir” from the user trigger “io_open” and “io_read” call from the resource manager?

Any code example for the filesystem resource manager?

If you use the default io_open it’s all taken care of for you. If you provide your own io_open and call iofunc_open_default then again it’s all taken care of.

Yes opendir and readdir are routed to io_open and io_read.

I have my own “io_open”, and I also have my own “ocb” data and “ocb_alloc” function, should “iofunc_open_default” be replaced with “iofunc_open” and “iofunc_ocb_attach”?

Also from “iofunc_open” document, it says “Note that if you’re handling a request to read directory entry, you must return data formatted to match the struct dirent type.” I’m wondering how to “return data formatted to match the struct dirent type”? Should I use something like this:
ptr = new struct dirent;
len = sizeof(struct dirent);

msg->ftype_reply.status = 0;
msg->ftype_reply.file_type = _FTYPE_ANY;
memncpy((char *)(msg->ftype_reply + 1), ptr, len);
len += sizeof(msg->ftype_reply);

return(_RESMGR_PTR(ctp, &msg->ftype_reply, len));

How to fill the dirent struct?