There are few steps to follow to open a file inside kernel from application layer.
1. Insert your character device driver inside the kernel using insmod and check its entry in the device driver table using cat /proc/devices and note down its major minor number.
2. Now make a node using mknod following with node name character and major minor number example : mknod nod c 250 0
3. Next step is to run a file (application.c) in the application layer and through the help of node open the file inside the kernel : fd=open(“nod”,O_RDWR);
include this statement in the file (application.c) which is in the application layer
4. After executing the application.c file which is in the application layer. check the fd returned by open function. If it is positive, that means file is opened successfully.
5.Last step to unlink the node using unlink node and remove the driver using rmmod
/////////////////////////////////////////////////////////////////////////////
RCS file: clean.c,v
Working file: open.c
head: 1.5
branch:
locks: strict
raghav: 1.5
access list:
symbolic names:
keyword substitution: kv
total revisions: 5; selected revisions: 5
description:
Creating a node between user and kernerl level using mknod following with node name and c for character device driver and combination of major minor no.
—————————-
revision 1.5 locked by: raghav;
date: 2014/02/13 11:20:48; author: raghav; state: Exp; lines: +2 -0
creating a file in application layer and now this file will open the file inside the kernel level using node
we can check it: whether its working or not by printing the fd returned from open func. if its negative then operation unsuccessful.
—————————-
revision 1.4
date: 2014/02/13 10:19:28; author: raghav; state: Exp; lines: +1 -1
Error detected: defination of scull_open function whose arguments are struct i node and struct file
—————————-
revision 1.3
date: 2014/02/13 10:18:05; author: raghav; state: Exp; lines: +6 -5
Including the open.o in the Make file.
—————————-
revision 1.2
date: 2014/02/13 06:09:06; author: raghav; state: Exp; lines: +3 -5
included the struct file_operation Scull_ops.
—————————-
revision 1.1
date: 2014/02/13 05:58:43; author: raghav; state: Exp;
Initial revision
=============================================================================