Hi,
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?
Thanks!
Yicheng