1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2407e84cdSMauro Carvalho Chehab.. c:namespace:: V4L 354f38fcaSMauro Carvalho Chehab 454f38fcaSMauro Carvalho Chehab.. _func-open: 554f38fcaSMauro Carvalho Chehab 654f38fcaSMauro Carvalho Chehab*********** 754f38fcaSMauro Carvalho ChehabV4L2 open() 854f38fcaSMauro Carvalho Chehab*********** 954f38fcaSMauro Carvalho Chehab 1054f38fcaSMauro Carvalho ChehabName 1154f38fcaSMauro Carvalho Chehab==== 1254f38fcaSMauro Carvalho Chehab 1354f38fcaSMauro Carvalho Chehabv4l2-open - Open a V4L2 device 1454f38fcaSMauro Carvalho Chehab 1554f38fcaSMauro Carvalho ChehabSynopsis 1654f38fcaSMauro Carvalho Chehab======== 1754f38fcaSMauro Carvalho Chehab 1854f38fcaSMauro Carvalho Chehab.. code-block:: c 1954f38fcaSMauro Carvalho Chehab 2054f38fcaSMauro Carvalho Chehab #include <fcntl.h> 2154f38fcaSMauro Carvalho Chehab 2254f38fcaSMauro Carvalho Chehab.. c:function:: int open( const char *device_name, int flags ) 2354f38fcaSMauro Carvalho Chehab 2454f38fcaSMauro Carvalho ChehabArguments 2554f38fcaSMauro Carvalho Chehab========= 2654f38fcaSMauro Carvalho Chehab 2754f38fcaSMauro Carvalho Chehab``device_name`` 2854f38fcaSMauro Carvalho Chehab Device to be opened. 2954f38fcaSMauro Carvalho Chehab 3054f38fcaSMauro Carvalho Chehab``flags`` 3154f38fcaSMauro Carvalho Chehab Open flags. Access mode must be ``O_RDWR``. This is just a 3254f38fcaSMauro Carvalho Chehab technicality, input devices still support only reading and output 3354f38fcaSMauro Carvalho Chehab devices only writing. 3454f38fcaSMauro Carvalho Chehab 35407e84cdSMauro Carvalho Chehab When the ``O_NONBLOCK`` flag is given, the :c:func:`read()` 3654f38fcaSMauro Carvalho Chehab function and the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will 3754f38fcaSMauro Carvalho Chehab return the ``EAGAIN`` error code when no data is available or no 3854f38fcaSMauro Carvalho Chehab buffer is in the driver outgoing queue, otherwise these functions 3954f38fcaSMauro Carvalho Chehab block until data becomes available. All V4L2 drivers exchanging data 4054f38fcaSMauro Carvalho Chehab with applications must support the ``O_NONBLOCK`` flag. 4154f38fcaSMauro Carvalho Chehab 4254f38fcaSMauro Carvalho Chehab Other flags have no effect. 4354f38fcaSMauro Carvalho Chehab 4454f38fcaSMauro Carvalho ChehabDescription 4554f38fcaSMauro Carvalho Chehab=========== 4654f38fcaSMauro Carvalho Chehab 47407e84cdSMauro Carvalho ChehabTo open a V4L2 device applications call :c:func:`open()` with the 4854f38fcaSMauro Carvalho Chehabdesired device name. This function has no side effects; all data format 4954f38fcaSMauro Carvalho Chehabparameters, current input or output, control values or other properties 50407e84cdSMauro Carvalho Chehabremain unchanged. At the first :c:func:`open()` call after loading the 5154f38fcaSMauro Carvalho Chehabdriver they will be reset to default values, drivers are never in an 5254f38fcaSMauro Carvalho Chehabundefined state. 5354f38fcaSMauro Carvalho Chehab 5454f38fcaSMauro Carvalho ChehabReturn Value 5554f38fcaSMauro Carvalho Chehab============ 5654f38fcaSMauro Carvalho Chehab 57407e84cdSMauro Carvalho ChehabOn success :c:func:`open()` returns the new file descriptor. On error 5854f38fcaSMauro Carvalho Chehab-1 is returned, and the ``errno`` variable is set appropriately. 5954f38fcaSMauro Carvalho ChehabPossible error codes are: 6054f38fcaSMauro Carvalho Chehab 6154f38fcaSMauro Carvalho ChehabEACCES 6254f38fcaSMauro Carvalho Chehab The caller has no permission to access the device. 6354f38fcaSMauro Carvalho Chehab 6454f38fcaSMauro Carvalho ChehabEBUSY 6554f38fcaSMauro Carvalho Chehab The driver does not support multiple opens and the device is already 6654f38fcaSMauro Carvalho Chehab in use. 6754f38fcaSMauro Carvalho Chehab 6854f38fcaSMauro Carvalho ChehabENXIO 6954f38fcaSMauro Carvalho Chehab No device corresponding to this device special file exists. 7054f38fcaSMauro Carvalho Chehab 7154f38fcaSMauro Carvalho ChehabENOMEM 7254f38fcaSMauro Carvalho Chehab Not enough kernel memory was available to complete the request. 7354f38fcaSMauro Carvalho Chehab 7454f38fcaSMauro Carvalho ChehabEMFILE 7554f38fcaSMauro Carvalho Chehab The process already has the maximum number of files open. 7654f38fcaSMauro Carvalho Chehab 7754f38fcaSMauro Carvalho ChehabENFILE 7854f38fcaSMauro Carvalho Chehab The limit on the total number of files open on the system has been 7954f38fcaSMauro Carvalho Chehab reached. 80