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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


Attachment: pgpIoZyQwzTbS.pgp
Description: PGP signature

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux