0

ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);

Used to retrieve data from the device. A null pointer in this position causes thereadsystem call to fail with-EINVAL(“Invalid argument”). A nonnegative returnvalue represents the number of bytes successfully read (the return value is a “signed size” type, usually the native integer type for the target platform).

ssize_t (*aio_read)(struct kiocb *, char __user *, size_t,loff_t);

Initiates an asynchronous read—a read operation that might not complete before the function returns. If this method isNULL, all operations will be pro-cessed (synchronously) byread instead.

ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);

Sends data to the device. IfNULL,-EINVALis returned to the program calling thewritesystem call. The return value, if nonnegative, represents the number ofbytes successfully written.

ssize_t (*aio_write)(struct kiocb *, const char __user *, size_t, loff_t *);

Initiates an asynchronous write operation on the device.

Took this statement from LDD3, can anyone please explain what will happen if a device driver not implemented the asyn write function? Will, it upgrades to sync silently like asyn read does (if it is NULL).

2

1 Answer 1

1

The aio_read and aio_write entries in file_operations are obsolete, replaced (albeit not identically) by read_iter and write_iter. Write-capable file_operations need to have at least one of write and/or write_iter, and the VFS will use whichever one is available. (The availability is checked earlier, and recorded using FMODE_CAN_WRITE.)

aio_write itself does need write_iter, and will return -EINVAL if it’s not available. There’s a generic implementation available which can be used in many cases, but it won’t be used as a fallback automatically.

2
  • ohh nice, in newer version if async io read is not implemented, will it throws error? Feb 18, 2020 at 6:12
  • If you mean aio_read and read_iter, the answer is yes. Feb 18, 2020 at 8:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .