cat: write error: Invalid argument

120

In the kernel, each driver provides a series of methods for the various operations that can be performed on a file: open, close, read, write, seek, ioctl, etc. These methods are stored in a struct file_operations. For devices, the methods are provided by the driver that registered that particular device (i.e. that particular combination of block/char, major number and minor number).

A driver may implement only some of the methods; defaults are provided. The defaults generally do nothing and return either success (if it's sensible to do nothing for that method) or EINVAL (if there is no sensible default and the lack of a method means that the feature is not supported).

“Write error: Invalid argument” means that the write method of the driver returns EINVAL. The most likely explanation is that this driver doesn't have a write method at all. It is fairly routine for drivers not to support certain actions, e.g. some drivers only support ioctl and not read/write, some drivers are intrinsically unidirectional (e.g. an input device) and only support read and not write or vice versa.

“Invalid argument” has nothing to do with permissions, it's what the device is able to do. You'd get a permission error if you didn't have write permission, but you do have permission to talk to the driver. It's just that what you're asking the driver to do is something that it has no concept of.

Share:
120

Related videos on Youtube

friartuck
Author by

friartuck

Updated on September 18, 2022

Comments

  • friartuck
    friartuck over 1 year

    I can't seem to find a decent answer on the interwebs, though I'm sure it's been asked before.

    Basically, I have an object that is composed of another object - so black diamond and line. When the parent dies, the object it composes dies. However, the object that is it composed of has a pointer back to the parent. What does this look like in UML?

    EDIT: For example, a building may be composed of rooms, but the rooms contain pointers back to the building object

    Thanks

    • Admin
      Admin over 7 years
      You need to show details about the custom chardev. If this is your own source code, I think that makes it a StackOverflow Q, you can flag it for migration.
  • xmojmr
    xmojmr almost 9 years
  • Saketh Kaparthi
    Saketh Kaparthi over 7 years
    Thanks. 1)I did not notice that i used the EINVAL(i copied the code from a book). 2)I was expecting it to print the custom error message like it did in the success on the terminal. But it was infact logging the message. So dmesg did give the error message