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

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

 



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
-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers and embedded Linux development,
consulting, training and support.
http://free-electrons.com

--
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