Programming/Linux_Kernel
misc 에 sysfs 등록하기
decdream
2010. 2. 8. 20:03
커널버전 : 2.6.29
misc driver 에 sysfs 를 등록하려 했으나 device object 가 없어서 난감한 상황에 빠졌다.
sysfs 를 등록하려면 device 로 등록을 해야 하는데 misc를 사용하는 하위 device들은 register_device 로 등록을 하지 않기 때문이다.
구글링을 해보니 나같은 난감한 상황때문에 고민했던 사람이 있었고, 그 사람이 2003년에 패치를 만든것을 발견하였다.
역시 정식 커널 버전에도 적용되어 있었다.
소스 코드를 뒤져보니 패치로 인해서 misc structer 에 device 구조체가 추가 되었다.
struct miscdevice {
int minor;
const char *name;
const struct file_operations *fops;
struct list_head list;
struct device *parent;
struct device *this_device;
};
그디어 sysfs 를 등록할 수 있게 되었다.
int init_module(void)
{
ret = device_create_file(miscdev.this_device, &dev_attr_vibecontrol);
}
{
ret = device_create_file(miscdev.this_device, &dev_attr_vibecontrol);
}
짜잔...
# find . -name "vibecontrol"
./sys/class/misc/vtmdrv/vibecontrol
#
./sys/class/misc/vtmdrv/vibecontrol
#