如同我们提过的, 例子源码包含一个虚拟总线实现称为 lddbus. 这个总线建立它的 bus_type 结构, 如下:
struct bus_type ldd_bus_type = { .name = "ldd", .match = ldd_match, .hotplug = ldd_hotplug, };
注意很少 bus_type 成员要求初始化; 大部分由设备模型核心处理. 但是, 我们确实不得 不指定总线的名子, 以及任何伴随它的方法.
不可避免地, 一个新总线必须注册到系统, 通过一个对 bus_register 的调用. lddbus 代码这样做以这样的方式:
ret = bus_register(&ldd_bus_type); if (ret)
return ret;
这个调用可能失败, 当然, 因此返回值必须一直检查. 如果它成功, 新总线子系统已被添 加到系统; 在 sysfs 中 /sys/bus 的下面可以见到, 并且可能启动添加设备.
如果有必要从系统中去除一个总线(当关联模块被去除, 例如), 调用调用 bus_unregister:
void bus_unregister(struct bus_type *bus);