How to create sysfs file and associate it with file operations like mmap
Hi all, I want to create a sysfs file and associate it with several file opeations like open,close and mmap. But when coming across sysfs file creation I saw that I can create a file using device_create_file(struct device*,struct device_attributes*); The device attributes were initialized using following DEVICE_ATTR(_name,_permission,_show,_store); But I want to associate my file with following operations struct file_operations my_fops { .open = my_open, .close = my_close, .mmap = my_mmap, }; I was able to do this using debugfs_create_file(...,&my_fops); But is there anyway if I want to put this file in sec_class. Thanking you in advance. Thanks and Regards, Niroj Pokhrel
On Wed, 18 Sep 2013 15:49:56 +0530, Niroj Pokhrel said:
I want to create a sysfs file and associate it with several file opeations like open,close and mmap.
Actually, probably not. There's some rules (like "one value per file") that sysfs should follow, which makes it a poor fit for mmap. Similarly, you probably don't want to override its open/close functions.
DEVICE_ATTR(_name,_permission,_show,_store);
Right. Because all sysfs files are supposed to have the same semantics, which means there's only 2 file-specific operations - one to produce a printable representation of a kernel data value for reading, and one to parse a string into the kernel value for writing.
But I want to associate my file with following operations struct file_operations my_fops { .open = my_open, .close = my_close, .mmap = my_mmap, };
I was able to do this using debugfs_create_file(...,&my_fops);
That's one reason why debugfs exists - so you can have someplace to put files that don't follow the sysfs semantics. There's also configfs if that's a good fit. There's also stuff like netlink for moving bulk data in and out of the kernel.
participants (2)
-
Niroj Pokhrel -
Valdis.Kletnieks@vt.edu