v4l2_ioctl 和 ioctl 之间的区别

difference between v4l2_ioctl and ioctl

我目前正在研究如何使用来自 python 的 v4l2 设备,发现 python 具有 ioctl (https://docs.python.org/3/library/fcntl.html) 的绑定。

我用C做了一些实现,但是我很难理解ioctl是否和v4l2_ioctl一样?

它们似乎采用完全相同的参数,在官方示例中我看到它们都包装在一个函数中,以相同的方式使用:

static void xioctl(int fh, int request, void *arg)
{
        int r;

        do {
                r = v4l2_ioctl(fh, request, arg);
        } while (r == -1 && ((errno == EINTR) || (errno == EAGAIN)));

        if (r == -1) {
                fprintf(stderr, "error %d, %s\n", errno, strerror(errno));
                exit(EXIT_FAILURE);
        }
}

对于正常的 ioctl:

static int xioctl(int fh, int request, void *arg)
{
        int r;

        do {
                r = ioctl(fh, request, arg);
        } while (-1 == r && EINTR == errno);

        return r;
}

我查看了 linux 存储库,但无法找出两者之间的确切区别。

我可以交替使用 ioctl 和 v4l2_ioctl 吗?
如果是,为什么两者都存在?
如果不是,那么 ioctl 与 v4l2_ioctl 相比的局限性是什么?

Can i use ioctl and v4l2_ioctl interchangeably?

没有

If so why does both exist?

ioctl 存在于设备上做一些特殊操作。

v4l2_ioctllibv4l2 的包装器,用于简化 v4l2 设备上的操作。

来自README

libv4l2

This offers functions like v4l2_open, v4l2_ioctl, etc. which can by used to quickly make v4l2 applications work with v4l2 devices with weird formats. libv4l2 mostly passes calls directly through to the v4l2 driver. When the app does a TRY_FMT / S_FMT with a not supported format libv4l2 will get in the middle and emulate the format (if an app wants to know which formats the hardware can really do it should use ENUM_FMT, not randomly try a bunch of S_FMT's). For more details on the v4l2_ functions see libv4l2.h .

the source found in libv4l project是最终的代码文档。