0
votes

I'm trying to register a char device, and I'm not sure what is the difference between the file_opreation, that is used when registering the device with register_chrdev, and the device_attribute, that is used when creating the device with device_create_file.

Both of those structs hold functions, that should be called when read&write operations are preformed on the device. So what is the difference between them? can I implement the functions only for one of them?

Thanks.

1

1 Answers

1
votes

The interface where you use the functions are different. device_attribute is specific to sysfs and file_operations has a larger scope. If you can provide all the required functionalities and interface to your device through just show and store operations on sysfs entries, you can choose device_Attribute.

Have a look at the members of both the structures. Operations like seek, ioctl, mmap, flush can only be supported through file_operations.

May be, in short, file_operations in general are associated with device nodes in /dev and device_attributes with special files in /sys