“preparing (or initializing) a device
”通常发生在加载设备驱动模块时,举例如下:
static int hello_modevent(module_t mod __unused, int /* modeventtype_t */ event, void *arg __unused)
{
......
switch (event)
{
case MOD_LOAD:
{
make_dev_args_init(&args);
args.mda_devsw = &hello_cdevsw;
args.mda_uid = UID_ROOT;
args.mda_gid = GID_WHEEL;
args.mda_mode = 0600;
uprintf("Hello is loaded:%d\n", make_dev_s(&args, &hello_dev, "hello"));
break;
}
......
}
return error;
}
“preparing a device for I/O
”则是发生在open
这个设备时,比如cdevsw
结构体的d_open
函数:
struct cdevsw {
......
d_open_t *d_open;
......
}