[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ioctl
On 9/30/05, raja <vnagaraju@xxxxxxxxxxxx> wrote:
> Hi,
> I am writing a character device driver similar to that in the book LDD3
> by rubini.While undersatnding the code I have got some doubt regarding
> the ioctl implemtntation.
> In scull.h file it is defined SCULL_IOCTQUANTUM as
> #define SCULL_IOCTQUANTUM _IO(SCULL_IOC_MAGIC, 3)
> here while defining there is no arguments for this call.
> But while implementing that in the ioctl call
>
> case SCULL_IOCTQUANTUM: /* Tell: arg is the value */
> if (! capable (CAP_SYS_ADMIN))
> return -EPERM;
> scull_quantum = arg;
> break;
>
> but here arg is assigned to scull_quantum.is it the correct?I
Why not? : - ) Using the logic, do you think it need or doesn't need
the arg? Of course it need, or it'd have no functionality!
See: for the line
#define SCULL_IOCTQUANTUM _IO(SCULL_IOC_MAGIC, 3)
the macro (do you understand well what is a macro?) _IO (defined in
<asm/ioctl.h> ) will operate the parameters SCULL_IOC_MAGIC and 3 to
create -- in compilation time, not in run time -- a unique ioctl
number N. This number N is, so, associated to SCULL_IOCTQUANTUM, as
it was 'SCULL_IOCTQUANTUM = N'. Maybe I didn't understand you, but,
SCULL_IOCTQUANTUM is not a call (neither a macro); it's only a single
value that is assinged to a functionality in the ioctl system call for
the scull module.
So, when a user-space application ioctls the device:
#include <scull.h>
ioctl (dev, SCULL_IOCTQUANTUM, some_number);
it's done:
scull_quantum = some_number
> And wht is the use of capable (CAP_SYS_ADMIN)?
It's a better way to manipulate permissions by the linux. Imagine a
case where users must have read/write access to device, but they
mustn't change control parameters of a device. Read the section
"Capabilities and Restricted Operations", page 144 ldd 3rd edition.
Regards,
Riba
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/