func-open.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _func-open:
  4. ***********
  5. V4L2 open()
  6. ***********
  7. Name
  8. ====
  9. v4l2-open - Open a V4L2 device
  10. Synopsis
  11. ========
  12. .. code-block:: c
  13. #include <fcntl.h>
  14. .. c:function:: int open( const char *device_name, int flags )
  15. Arguments
  16. =========
  17. ``device_name``
  18. Device to be opened.
  19. ``flags``
  20. Open flags. Access mode must be ``O_RDWR``. This is just a
  21. technicality, input devices still support only reading and output
  22. devices only writing.
  23. When the ``O_NONBLOCK`` flag is given, the :c:func:`read()`
  24. function and the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will
  25. return the ``EAGAIN`` error code when no data is available or no
  26. buffer is in the driver outgoing queue, otherwise these functions
  27. block until data becomes available. All V4L2 drivers exchanging data
  28. with applications must support the ``O_NONBLOCK`` flag.
  29. Other flags have no effect.
  30. Description
  31. ===========
  32. To open a V4L2 device applications call :c:func:`open()` with the
  33. desired device name. This function has no side effects; all data format
  34. parameters, current input or output, control values or other properties
  35. remain unchanged. At the first :c:func:`open()` call after loading the
  36. driver they will be reset to default values, drivers are never in an
  37. undefined state.
  38. Return Value
  39. ============
  40. On success :c:func:`open()` returns the new file descriptor. On error
  41. -1 is returned, and the ``errno`` variable is set appropriately.
  42. Possible error codes are:
  43. EACCES
  44. The caller has no permission to access the device.
  45. EBUSY
  46. The driver does not support multiple opens and the device is already
  47. in use.
  48. ENODEV
  49. Device not found or was removed.
  50. ENOMEM
  51. Not enough kernel memory was available to complete the request.
  52. EMFILE
  53. The process already has the maximum number of files open.
  54. ENFILE
  55. The limit on the total number of files open on the system has been
  56. reached.