1.. Permission is granted to copy, distribute and/or modify this
2.. document under the terms of the GNU Free Documentation License,
3.. Version 1.1 or any later version published by the Free Software
4.. Foundation, with no Invariant Sections, no Front-Cover Texts
5.. and no Back-Cover Texts. A copy of the license is included at
6.. Documentation/userspace-api/media/fdl-appendix.rst.
7..
8.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9
10.. _func-open:
11
12***********
13V4L2 open()
14***********
15
16Name
17====
18
19v4l2-open - Open a V4L2 device
20
21
22Synopsis
23========
24
25.. code-block:: c
26
27    #include <fcntl.h>
28
29
30.. c:function:: int open( const char *device_name, int flags )
31    :name: v4l2-open
32
33Arguments
34=========
35
36``device_name``
37    Device to be opened.
38
39``flags``
40    Open flags. Access mode must be ``O_RDWR``. This is just a
41    technicality, input devices still support only reading and output
42    devices only writing.
43
44    When the ``O_NONBLOCK`` flag is given, the :ref:`read() <func-read>`
45    function and the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will
46    return the ``EAGAIN`` error code when no data is available or no
47    buffer is in the driver outgoing queue, otherwise these functions
48    block until data becomes available. All V4L2 drivers exchanging data
49    with applications must support the ``O_NONBLOCK`` flag.
50
51    Other flags have no effect.
52
53
54Description
55===========
56
57To open a V4L2 device applications call :ref:`open() <func-open>` with the
58desired device name. This function has no side effects; all data format
59parameters, current input or output, control values or other properties
60remain unchanged. At the first :ref:`open() <func-open>` call after loading the
61driver they will be reset to default values, drivers are never in an
62undefined state.
63
64
65Return Value
66============
67
68On success :ref:`open() <func-open>` returns the new file descriptor. On error
69-1 is returned, and the ``errno`` variable is set appropriately.
70Possible error codes are:
71
72EACCES
73    The caller has no permission to access the device.
74
75EBUSY
76    The driver does not support multiple opens and the device is already
77    in use.
78
79ENXIO
80    No device corresponding to this device special file exists.
81
82ENOMEM
83    Not enough kernel memory was available to complete the request.
84
85EMFILE
86    The process already has the maximum number of files open.
87
88ENFILE
89    The limit on the total number of files open on the system has been
90    reached.
91