'ioctl return -1 with errno set to EPERM

I have a C program which calls ioctl() but it returns -1 and errno set to EPERM. But I have changed mode of that file to "777".

Can you please tell me why ioctl() still returns -1 with errno set to EPERM?



Solution 1:[1]

The device you are calling ioctl on may include some code that checks for capabilities before performing the action you requested. Setting the permissions for the special file to 777 will not be sufficient in this case. If you want to dig into the source for the driver that supports the device in question you can look for something like the following to figure out what capability is actually required.

if (! capable (CAP_SYS_ADMIN))
    return -EPERM;

You may want to read up on capabilities or just run your application as root as others have suggested.

Linux Man Page for Capabilities

Solution 2:[2]

Yea, EPERM (Operation not permitted) error indicate you don't have sufficient permissions to execute the operation.As liw.fi suggested,try executing with root privilege or tell us what is the operation to be done.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Kryger
Solution 2 AIB