I would like to read a structure from a device driver via an ioctl, change a value in the structure in userspace and then write it back. Is this possible to do atomically without some other process changing the structure inbetween read and write?
Could I lock the file descriptor (flock()) before the calls and unlock afterwards? Or, could I implement a lock and unlock ioctl command that sets an internal lock variable in the driver? What would happen if the process dies, how could the variable get cleared?
Could I use sysfs rather than ioctl to achieve the same effect?