func-open.rst 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9
.. Permission is granted to copy, distribute and/or modify this
.. document under the terms of the GNU Free Documentation License,
.. Version 1.1 or any later version published by the Free Software
.. Foundation, with no Invariant Sections, no Front-Cover Texts
.. and no Back-Cover Texts. A copy of the license is included at
.. Documentation/media/uapi/fdl-appendix.rst.
..
.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections

10 11 12 13 14 15
.. _func-open:

***********
V4L2 open()
***********

16
Name
17
====
18

19
v4l2-open - Open a V4L2 device
20

21 22

Synopsis
23 24 25 26 27 28 29
========

.. code-block:: c

    #include <fcntl.h>


30
.. c:function:: int open( const char *device_name, int flags )
31
    :name: v4l2-open
32

33
Arguments
34 35 36 37 38 39 40 41 42 43
=========

``device_name``
    Device to be opened.

``flags``
    Open flags. Access mode must be ``O_RDWR``. This is just a
    technicality, input devices still support only reading and output
    devices only writing.

44 45 46 47 48 49
    When the ``O_NONBLOCK`` flag is given, the :ref:`read() <func-read>`
    function and the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will
    return the ``EAGAIN`` error code when no data is available or no
    buffer is in the driver outgoing queue, otherwise these functions
    block until data becomes available. All V4L2 drivers exchanging data
    with applications must support the ``O_NONBLOCK`` flag.
50 51 52 53

    Other flags have no effect.


54
Description
55 56
===========

57
To open a V4L2 device applications call :ref:`open() <func-open>` with the
58 59
desired device name. This function has no side effects; all data format
parameters, current input or output, control values or other properties
60
remain unchanged. At the first :ref:`open() <func-open>` call after loading the
61 62 63 64
driver they will be reset to default values, drivers are never in an
undefined state.


65
Return Value
66 67
============

68
On success :ref:`open() <func-open>` returns the new file descriptor. On error
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
-1 is returned, and the ``errno`` variable is set appropriately.
Possible error codes are:

EACCES
    The caller has no permission to access the device.

EBUSY
    The driver does not support multiple opens and the device is already
    in use.

ENXIO
    No device corresponding to this device special file exists.

ENOMEM
    Not enough kernel memory was available to complete the request.

EMFILE
    The process already has the maximum number of files open.

ENFILE
    The limit on the total number of files open on the system has been
    reached.