I have write a simple char device driver (mydev) with \"open\" file operation in it.
In user space application I open this driver node. using open(\"/dev/mydev\", O_
I found the answer in Understanding Linux Kernel book, at section 12.5.1
Steps are,
Invokes getname( ) to read the file pathname from the process address space.
Invokes get_unused_fd( ) to find an empty slot in current->files->fd. The corresponding index (the new file descriptor) is stored in the fd local variable.
Invokes the filp_open( ) function, passing as parameters the pathname, the access mode flags, and the permission bit mask. This function, in turn, executes the following steps:
a. Invokes get_empty_filp( ) to get a new file object.
b. Sets the f_flags and f_mode fields of the file object according to the values of the flags and modes parameters.
c. Invokes open_namei( ), which executes the following operations:
i. Invokes lookup_dentry( ) to interpret the file pathname and gets the
dentry object associated with the requested file.
ii. Performs a series of checks to verify whether the process is permitted
to open the file as specified by the values of the flags parameter. If so,
returns the address of the dentry object; otherwise, returns an error code.
d. If the access is for writing, checks the value of the i_writecount field of the inode object. A negative value means that the file has been memory-mapped, specifying that write accesses must be denied (see the section Section 15.2 in Chapter 15). In this case, returns an error code. Any other value specifies the number of processes that are actually writing into the file. In the latter case, increments the counter.
e. Initializes the fields of the file object; in particular, sets the f_op field to the contents of the i_op->default_file_ops field of the inode object. This sets up all the right functions for future file operations.
f. If the open method of the (default) file operations is defined, invokes it.
g. Clears the O_CREAT, O_EXCL, O_NOCTTY, and O_TRUNC flags in f_flags.
h. Returns the address of the file object.