요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: DTV.dmx
.. _dmx-mmap:
*****************
Digital TV mmap()
*****************
Name
====
dmx-mmap - Map device memory into application address space
.. warning:: this API is still experimental
Synopsis
========
.. code-block:: c
#include <unistd.h>
#include <sys/mman.h>
.. c:function:: void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset )
Arguments
=========
``start``
Map the buffer to this address in the application's address space.
When the ``MAP_FIXED`` flag is specified, ``start`` must be a
multiple of the pagesize and mmap will fail when the specified
address cannot be used. Use of this option is discouraged;
applications should just specify a ``NULL`` pointer here.
``length``
Length of the memory area to map. This must be a multiple of the
DVB packet length (188, on most drivers).
``prot``
The ``prot`` argument describes the desired memory protection.
Regardless of the device type and the direction of data exchange it
should be set to ``PROT_READ`` | ``PROT_WRITE``, permitting read
and write access to image buffers. Drivers should support at least
this combination of flags.
``flags``
The ``flags`` parameter specifies the type of the mapped object,
mapping options and whether modifications made to the mapped copy of
the page are private to the process or are to be shared with other
references.
``MAP_FIXED`` requests that the driver selects no other address than
the one specified. If the specified address cannot be used,
:c:func:`mmap()` will fail. If ``MAP_FIXED`` is specified,
``start`` must be a multiple of the pagesize. Use of this option is
discouraged.
One of the ``MAP_SHARED`` or ``MAP_PRIVATE`` flags must be set.
``MAP_SHARED`` allows applications to share the mapped memory with
other (e. g. child-) processes.
.. note::
The Linux Digital TV applications should not set the
``MAP_PRIVATE``, ``MAP_DENYWRITE``, ``MAP_EXECUTABLE`` or ``MAP_ANON``
flags.
``fd``
File descriptor returned by :c:func:`open()`.
``offset``
Offset of the buffer in device memory, as returned by
:ref:`DMX_QUERYBUF` ioctl.
Description
===========
The :c:func:`mmap()` function asks to map ``length`` bytes starting at
``offset`` in the memory of the device specified by ``fd`` into the
application address space, preferably at address ``start``. This latter
address is a hint only, and is usually specified as 0.
Suitable length and offset parameters are queried with the
:ref:`DMX_QUERYBUF` ioctl. Buffers must be allocated with the
:ref:`DMX_REQBUFS` ioctl before they can be queried.
To unmap buffers the :c:func:`munmap()` function is used.
Return Value
============
On success :c:func:`mmap()` returns a pointer to the mapped buffer. On
error ``MAP_FAILED`` (-1) is returned, and the ``errno`` variable is set
appropriately. Possible error codes are:
EBADF
``fd`` is not a valid file descriptor.
EACCES
``fd`` is not open for reading and writing.
EINVAL
The ``start`` or ``length`` or ``offset`` are not suitable. (E. g.
they are too large, or not aligned on a ``PAGESIZE`` boundary.)
The ``flags`` or ``prot`` value is not supported.
No buffers have been allocated with the
:ref:`DMX_REQBUFS` ioctl.
ENOMEM
Not enough physical or virtual memory was available to complete the
request.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
이름, 실험 상태와 호출 형식
1-25이 문서는 GFDL-1.1-no-invariants-or-later 라이선스와 `DTV.dmx` C namespace를 사용하며 Digital TV의 `mmap()` 인터페이스를 설명합니다.
`dmx-mmap`은 장치 메모리를 애플리케이션 주소 공간에 매핑합니다. 이 API는 아직 실험적입니다.
사용자는 `unistd.h`와 `sys/mman.h`를 포함하며, 함수 원형은 `void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)`입니다.
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: DTV.dmx
.. _dmx-mmap:
*****************
Digital TV mmap()
*****************
Name
====
dmx-mmap - Map device memory into application address space
.. warning:: this API is still experimental
Synopsis
========
.. code-block:: c
#include <unistd.h>
#include <sys/mman.h>
.. c:function:: void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset )
주소, 길이와 보호 속성
26-46`start`는 애플리케이션 주소 공간에서 버퍼를 배치할 주소입니다. `MAP_FIXED`를 지정하면 페이지 크기의 배수여야 하고 그 주소를 사용할 수 없을 때 실패합니다. 이 옵션은 권장하지 않으며 애플리케이션은 보통 `NULL`을 지정해야 합니다.
`length`는 매핑할 메모리 영역 길이이며 DVB 패킷 길이의 배수여야 합니다. 대부분의 드라이버에서 패킷 길이는 188바이트입니다.
`prot`는 원하는 메모리 보호 속성입니다. 장치 종류와 데이터 교환 방향에 관계없이 읽기·쓰기를 모두 허용하는 `PROT_READ | PROT_WRITE`로 설정해야 하며, 드라이버는 적어도 이 조합을 지원해야 합니다.
초기 세 인자의 제약을 정리합니다.
Arguments
=========
``start``
Map the buffer to this address in the application's address space.
When the ``MAP_FIXED`` flag is specified, ``start`` must be a
multiple of the pagesize and mmap will fail when the specified
address cannot be used. Use of this option is discouraged;
applications should just specify a ``NULL`` pointer here.
``length``
Length of the memory area to map. This must be a multiple of the
DVB packet length (188, on most drivers).
``prot``
The ``prot`` argument describes the desired memory protection.
Regardless of the device type and the direction of data exchange it
should be set to ``PROT_READ`` | ``PROT_WRITE``, permitting read
and write access to image buffers. Drivers should support at least
this combination of flags.
매핑 플래그
47-68`flags`는 매핑할 객체의 종류와 옵션, 매핑된 페이지 사본의 변경을 프로세스 전용으로 둘지 다른 참조와 공유할지를 지정합니다.
`MAP_FIXED`는 지정 주소 외의 다른 주소를 선택하지 말라고 드라이버에 요구합니다. 주소를 쓸 수 없으면 실패하고 `start`는 페이지 크기의 배수여야 하므로 사용을 권장하지 않습니다.
`MAP_SHARED`와 `MAP_PRIVATE` 중 하나는 반드시 설정해야 합니다. `MAP_SHARED`를 사용하면 자식 프로세스 같은 다른 프로세스와 매핑 메모리를 공유할 수 있습니다.
Linux Digital TV 애플리케이션은 `MAP_PRIVATE`, `MAP_DENYWRITE`, `MAP_EXECUTABLE`, `MAP_ANON` 플래그를 설정하지 않아야 합니다. 즉, 형식상 둘 중 하나를 요구하는 앞 문장과 함께 읽을 때 이 API의 실제 권장 선택은 `MAP_SHARED`입니다.
요구·권장·금지 상태를 구분합니다.
``flags``
The ``flags`` parameter specifies the type of the mapped object,
mapping options and whether modifications made to the mapped copy of
the page are private to the process or are to be shared with other
references.
``MAP_FIXED`` requests that the driver selects no other address than
the one specified. If the specified address cannot be used,
:c:func:`mmap()` will fail. If ``MAP_FIXED`` is specified,
``start`` must be a multiple of the pagesize. Use of this option is
discouraged.
One of the ``MAP_SHARED`` or ``MAP_PRIVATE`` flags must be set.
``MAP_SHARED`` allows applications to share the mapped memory with
other (e. g. child-) processes.
.. note::
The Linux Digital TV applications should not set the
``MAP_PRIVATE``, ``MAP_DENYWRITE``, ``MAP_EXECUTABLE`` or ``MAP_ANON``
flags.
fd, offset과 버퍼 준비
69-89`fd`는 `open()`이 반환한 file descriptor입니다.
`offset`은 장치 메모리에서 버퍼의 오프셋이며 `DMX_QUERYBUF` ioctl이 반환한 값을 사용합니다.
`mmap()`은 `fd`가 지정한 장치 메모리의 `offset`부터 `length`바이트를 애플리케이션 주소 공간에 매핑하도록 요청합니다. `start`는 선호 주소를 나타내는 힌트일 뿐이며 보통 0입니다.
적절한 `length`와 `offset`은 `DMX_QUERYBUF`로 질의합니다. 버퍼는 질의하기 전에 `DMX_REQBUFS`로 할당해야 합니다.
버퍼 매핑을 해제할 때는 `munmap()`을 사용합니다.
할당·질의·매핑·해제를 순서대로 수행합니다.
``fd``
File descriptor returned by :c:func:`open()`.
``offset``
Offset of the buffer in device memory, as returned by
:ref:`DMX_QUERYBUF` ioctl.
Description
===========
The :c:func:`mmap()` function asks to map ``length`` bytes starting at
``offset`` in the memory of the device specified by ``fd`` into the
application address space, preferably at address ``start``. This latter
address is a hint only, and is usually specified as 0.
Suitable length and offset parameters are queried with the
:ref:`DMX_QUERYBUF` ioctl. Buffers must be allocated with the
:ref:`DMX_REQBUFS` ioctl before they can be queried.
To unmap buffers the :c:func:`munmap()` function is used.
반환값과 오류
90-115성공하면 `mmap()`은 매핑된 버퍼를 가리키는 포인터를 반환합니다. 오류가 발생하면 `MAP_FAILED`(-1)를 반환하고 `errno`를 적절히 설정합니다.
문서에 열거된 실패 조건입니다.
Return Value
============
On success :c:func:`mmap()` returns a pointer to the mapped buffer. On
error ``MAP_FAILED`` (-1) is returned, and the ``errno`` variable is set
appropriately. Possible error codes are:
EBADF
``fd`` is not a valid file descriptor.
EACCES
``fd`` is not open for reading and writing.
EINVAL
The ``start`` or ``length`` or ``offset`` are not suitable. (E. g.
they are too large, or not aligned on a ``PAGESIZE`` boundary.)
The ``flags`` or ``prot`` value is not supported.
No buffers have been allocated with the
:ref:`DMX_REQBUFS` ioctl.
ENOMEM
Not enough physical or virtual memory was available to complete the
request.
요약·해설
dmx-mmap.rst:1-115Digital TV mmap 경로는 DMX_REQBUFS 할당과 DMX_QUERYBUF 질의가 선행되어야 합니다. PROT_READ | PROT_WRITE와 MAP_SHARED가 권장 조합이며 길이는 보통 188바이트 패킷 단위입니다.