int rsrcdbmgr_minor_attach(int major, int minor_guess) { dev_t ret; char buffer[20]; itoa(major, buffer, 10); ret = rsrcdbmgr_devno_attach(buffer, minor_guess, 0); return((ret == (dev_t)-1) ? ret : minor(ret)); }
int resmgr_create_device(event_bus_line_t *line) { devi_attr_t *attr; resmgr_attr_t res_attr; static resmgr_connect_funcs_t connect_funcs; static resmgr_io_funcs_t io_funcs; static int once = 0; int i; char name[48]; char path[_POSIX_PATH_MAX]; int id; dev_t d; if ((attr = malloc(sizeof(devi_attr_t))) == NULL) { errno_print("malloc"); return (-1); } if (!once) { iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs, _RESMGR_IO_NFUNCS, &io_funcs); connect_funcs.open = devi_open; io_funcs.devctl = devi_devctl; io_funcs.read = devi_read; io_funcs.close_ocb = devi_close; io_funcs.unblock = devi_unblock; io_funcs.notify = devi_notify; once = 1; } iofunc_attr_init(&attr->attr, 0666 | S_IFCHR, NULL, NULL); attr->flags = line->type; attr->ocb_list = NULL; line->attr = attr; switch (attr->flags) { case DEVI_CLASS_KBD: strcpy(name, "keyboard"); break; case DEVI_CLASS_REL: strcpy(name, "mouse"); break; case DEVI_CLASS_ABS: strcpy(name, "touch"); break; } attr->line = line; memset(&res_attr, 0, sizeof(res_attr)); res_attr.msg_max_size = 2048; res_attr.nparts_max = 3; for (i = 0; i < 10; i++) { sprintf(path, DEVICE_NAME, name, i); if (access(path, F_OK) != 0) break; } if (i == 10) { char * pMsgTxt = "Error: unable to create device %s\n"; fprintf(stderr, pMsgTxt, path); slogf(_SLOG_SETCODE(_SLOGC_INPUT, 0), _SLOG_ERROR, pMsgTxt, path); free(attr); return (-1); } id = resmgr_attach(devi_get_dispatch_handle(), &res_attr, path, _FTYPE_ANY, 0, &connect_funcs, &io_funcs, (void *) &attr->attr); if (id < 0) { char * pMsgTxt = "Error: could not attach resource manager\n"; fprintf(stderr, pMsgTxt); slogf(_SLOG_SETCODE(_SLOGC_INPUT, 0), _SLOG_ERROR, pMsgTxt); free(attr); return (-1); } attr->attr.rdev = rsrcdbmgr_devno_attach(name, -1, 0); resmgr_devino(id, &d, &attr->attr.inode); return (0); }