Find the answer to your Linux question:
Results 1 to 3 of 3

Thread: Sysfs Use

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Sysfs Use

    Hi All

    I want to pass certain information from the user space to my driver, whenever the user apps. open my driver.
    I have considered 2 options:
    1. Call an ioctl to my device with the data I want to pass.
    2. Use the sysfs FS.

    But I am not sure about the procedure to create a sysfs entry for my driver, and how to access it from kernel space, how to write into it from User space etc...

    Can anyone provide a pointer to this. Sorry if it has already been answered, I tried to search but could find relevant post.


  2. #2

  3. #3
    Linux Newbie dilbert's Avatar
    Join Date
    Sep 2006
    Lima, Peru
    I'm not sure if a user app could write into the sys file system, but I doubt it.

    USB has with the 2.6 kernel moved some info from the proc file system to the sys file system. So, in the driver source for USB are examples how to write into the proc file system. That could be a pointer.

    If you search this forum or better the whole Internet for "copy_to_user" you will get some links.

    At the first link

    shows some example code, but there are surely better and more comprehensive examples.

    The important thing is to use a special type for the structure (caddr_t or something like that) used in copy_to_user and copy_from_user. At least during development, make use of the return values of those functions to know what's going on.

    There are also functions to validate the memory for those structure to put in front of the copy_xx_user functions. Could become complicated if you don't have the proper examples.
    Bus Error: Passengers dumped. Hech gap yo'q.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts