Re: Cannot open from user space a misc device - why ?

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

 



On Tue, Feb 24, 2009 at 3:38 AM, Thomas Petazzoni
<thomas.petazzoni@xxxxxxxxxxxxxxxxxx> wrote:
> Le Tue, 24 Feb 2009 09:11:53 +0800,
> Peter Teoh <htmldeveloper@xxxxxxxxx> a écrit :
>
>> But then it also puzzled me, because ioctl() in user space required a
>> open file descriptor as the first parameter, which is derived from
>> open() (as specified from "man ioctl").   so then how is the open()
>> from userspace passed down to kernel?
>
> When userspace uses the open() system call, the kernel function
> sys_open() gets called. This kernel function does all the job, and
> calls the ->open() operation of the device driver if it exists.
> Otherwise, it just doesn't call it, and it works perfectly fine. The
> sys_open() function does all what's needed, the ->open() operation is
> only here *if* your device driver needs to do something when the device
> is opened. This operation is optional.
>
>  sys_open()
>  http://lxr.free-electrons.com/source/fs/open.c#L1032
>
>  calls
>
>  do_sys_open()
>  http://lxr.free-electrons.com/source/fs/open.c#L1010
>
>  which calls
>
>  do_filp_open()
>  http://lxr.free-electrons.com/source/fs/namei.c#L1637
>
>  which calls
>
>  nameidata_to_filp()
>  http://lxr.free-electrons.com/source/fs/open.c#L918
>
>  which calls
>
>  __dentry_open()
>  http://lxr.free-electrons.com/source/fs/open.c#L793
>
>  which does
>
> 823         if (!open && f->f_op)
> 824                 open = f->f_op->open;
> 825         if (open) {
> 826                 error = open(inode, f);
> 827                 if (error)
> 828                         goto cleanup_all;
> 829         }
>
> (ouf)
>
> Sincerly,
>
> Thomas

Thank you Thomas, I think the lxr source code navigator is really
useful, as compared with "vi" :-).   Thank you for the contribution
:-).

-- 
Regards,
Peter Teoh

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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