Linux driver: ioctl or sysfs? -


i'm writing driver control custom hardware.

in old days (i.e. 15yrs ago) doing ioctls, digging sysfs possible alternative.

  • as understand it, ioctls aren't totally deprecated, sysfs preferred (?)
  • i need read/write sets of values simultaneously i.e. through 1 sysfs entry. i've read isn't ideal, acceptable if necessary (?)
  • there needs 'mutex' protection on driver, 1 app can write @ time. (i have read-only 'info' entries i'd prefer keep accessible @ times).

given above, best way proceed - ioctl or sysfs?

if sysfs, how can implement exclusive access?

if sysfs, if driver has no read/write/ioctl fops, need open/release?!

(this 'private' driver, don't care massively ;), figured if new ways more applicable might grips them!)

thanks.

i try @ least partly answer question. feel free comment ask me expand (or shrink!)

  • first of all, these days ioctls no longer considered deprecated, people haven't found better solutions problems solve. people expected more disciplined defining ioctl interfaces though, , truthfully express read , write in ioctl number encoding if @ possible. ioctls , sysfs have different strengths.
  • sysfs useful exposing particular attributes of devices user space, particularly user on console or shell script, , letting attributes or device configuration changed. single sysfs file maps single attribute , readable (and/or writable) simple text string. example might expose current power management state of device (e.g. "off") , let write new 1 using "cat" shell command.
  • sysfs indeed not tied open/release session (and should not have implement use it), suitable global attributes. should not problem if user expected performing single operation on device @ time, makes harder enforce (so not ideal "sets of data simultaneously", unless encode them 1 string). , yes, want protect driver data access sysfs handlers mutexes, 1 mutex per logical set of data (or 1 several logical sets).
  • ioctl better suited passing binary information between user-space , driver, , needs c programme or similar use it. custom ioctls well-suited writing minimal driver in kernel , putting logic in matching user-space programme. unlike sysfs doesn't need logic interpreting text strings - can read , write data straight user process memory - means less unnecessary code, more opportunities not safety check data thoroughly.

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -