# Read/Write

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Input and output devices support the read() and write() function, respectively, when the V4L2_CAP_READWRITE flag in the capabilities field of struct v4l2_capability returned by the VIDIOC_QUERYCAP ioctl is set.

<a id="rst-read-write"></a>
<a id="rst-rw"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Input and output devices support the `read()` and `write()` function, respectively, when the `V4L2_CAP_READWRITE` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl is set.

Drivers may need the CPU to copy the data, but they may also support DMA to or from user memory, so this I/O method is not necessarily less efficient than other methods merely exchanging buffer pointers. It is considered inferior though because no meta-information like frame counters or timestamps are passed. This information is necessary to recognize frame dropping and to synchronize with other data streams. However this is also the simplest I/O method, requiring little or no setup to exchange data. It permits command line stunts like this (the vidctrl tool is fictitious):



```none
$ vidctrl /dev/video --input=0 --format=YUYV --size=352x288
$ dd if=/dev/video of=myimage.422 bs=202752 count=1
```

To read from the device applications use the `read()` function, to write the `write()` function. Drivers must implement one I/O method if they exchange data with applications, but it need not be this. <a id="rst-footnote-reference-1"></a>[1](#rst-f1) When reading or writing is supported, the driver must also support the `select()` and `poll()` function. <a id="rst-footnote-reference-2"></a>[2](#rst-f2)

<a id="rst-f1"></a>



**[1]** It would be desirable if applications could depend on drivers supporting all I/O interfaces, but as much as the complex memory mapping I/O can be inadequate for some devices we have no reason to require this interface, which is most useful for simple applications capturing still images.

<a id="rst-f2"></a>



**[2]** At the driver level `select()` and `poll()` are the same, and `select()` is too important to be optional.
