How to create sysfs file and associate it with file operations like mmap

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Wed Sep 18 11:52:32 EDT 2013


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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130918/79e27b07/attachment.bin 


More information about the Kernelnewbies mailing list