Re: ioctl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/1/05, raja <vnagaraju@xxxxxxxxxxxx> wrote:
> yaa,thank you,
> I agree with you but,here we are specifying the value for quantum to be
> set with.
> I thing here instead of _IO we have to use _IOW() and we have to specify
> the lat parameter as int?
> Am i right?
> Wht is wrong with me?

I think you're confusing what means data transfer between kernel and userspace.

#define SCULL_IOCSQUANTUM _IOW(SCULL_IOC_MAGIC,  1, int)
#define SCULL_IOCTQUANTUM _IO(SCULL_IOC_MAGIC,   3)

do the same thing, but IOCS gets the value to set through a pointer,
id est, using data transfer. IOCT gets the value directly from the
argument value, it doesn't use that data transfer. There is a write to
the former. There's not a write to the latter.

I thinks this confusing wouldn't lead you to create a buggy module
since the macros just use it to create a unique number, and this
unique number will be create whatever macro you choose. But creating
ioctl mistakes-free modules makes these things worthy to pay
attention.

If someone see any mistakes from me, please notify me.

Regards,
Riba



>
>
> thanks in advance
> raja
>
>
>
> On Sat, 2005-10-01 at 00:29 -0300, Ribamar Santarosa de Sousa wrote:
> > 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/
> >
>
>

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux