<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EmbLogic &#187; deepak.jain</title>
	<atom:link href="https://www.emblogic.com/blog/author/deepak-jain/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Tue, 03 Mar 2020 13:00:06 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>PIPE : IPC mechanism</title>
		<link>https://www.emblogic.com/blog/03/pipe-ipc-mechanism/</link>
		<comments>https://www.emblogic.com/blog/03/pipe-ipc-mechanism/#comments</comments>
		<pubDate>Tue, 25 Mar 2014 10:12:30 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Project 03: Client Server Communication using Linux and IPC]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=9422</guid>
		<description><![CDATA[Pipe is a method of creating the standard output of one process to the standard input of another process.When a process creates a pipe using pipe() system call , the pipe() system call finds the first two available file-descriptors in &#8230; <a href="https://www.emblogic.com/blog/03/pipe-ipc-mechanism/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Pipe is a method of creating the standard output of one process to the standard input of another process.When a process creates a pipe using pipe() system call , the pipe() system call finds the first two available file-descriptors in the process file table and allocates them for reading and writing purposes.pipe() system call returns 0 on success and -1 on failure.</p>
<p>In half duplex pipes , fd[0] and fd[1] are set for reading and writing respectively.The pipe is automatically removed by the operating system when all the processes associated with the pipe terminates.</p>
<p>Certain points which should be kept in mind while implementing pipe:</p>
<p>1.If a process calls read() when the pipe is empty then the process is blocked untill some data is sent through the pipe.</p>
<p>2.If a process calls write() when the pipe is full then the calling process is blocked untill some data is read from the pipe.</p>
<p>3.The process must first call pipe() and then fork().Otherwise the two pipes will be entirely different from each other , i.e parent-child relationship must exist.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/pipe-ipc-mechanism/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code to show how to implement a semaphore(a type of locking technique) in scull to synchronize same operations issued by multiple applications.</title>
		<link>https://www.emblogic.com/blog/03/module-code-to-show-how-to-implement-a-semaphorea-type-of-locking-technique-in-scull-to-synchronize-same-operations-issued-by-multiple-applications/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-to-show-how-to-implement-a-semaphorea-type-of-locking-technique-in-scull-to-synchronize-same-operations-issued-by-multiple-applications/#comments</comments>
		<pubDate>Fri, 07 Mar 2014 14:17:51 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8944</guid>
		<description><![CDATA[Semaphore in Scull Scenario :Writer application must execute before the reader application. There are two applications which have to perform several operations on the node 1. Application 1: Application 1 is a multithreaded application in which open() , write() and &#8230; <a href="https://www.emblogic.com/blog/03/module-code-to-show-how-to-implement-a-semaphorea-type-of-locking-technique-in-scull-to-synchronize-same-operations-issued-by-multiple-applications/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong>Semaphore in Scull</strong></p>
<p>Scenario :Writer application must execute before the reader application.</p>
<p>There are two applications which have to perform several operations on the node</p>
<p>1. Application 1: Application 1 is a multithreaded application in which open() , write() and close() functions are called in multiple threads.And because this has to be done in this specific order ,synchronization is achieved with the help of thread semaphores.</p>
<p>2.Application 2:Application 2 is also a multithreaded application in which open() , read() and close() functions are also called in multiple threads and synchronization between them is achieved by thread semaphores.</p>
<p>As these two multi-threaded applications issues open() call.There is a need to implement the  semaphores at the kernel level also .<br />
RCS file: openf.c,v<br />
Working file: openf.c<br />
head: 1.15<br />
branch:<br />
locks: strict<br />
root: 1.15<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 15;    selected revisions: 15<br />
description:<br />
The functionality of chardev_open() is implemented here inside this file.Whenever the application calls the open function,this is always the first operation performed on the device file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15    locked by: root;<br />
date: 2014/03/07 19:18:40;  author: root;  state: Exp;  lines: +1 -1<br />
If the application issues open() system call in O_RDONLY mode , then it decrements the value of the semaphore sem which is initialized with 0 and blocks itself untill the writer executes up() on the same semaphore.</p>
<p>Status : chardev_open() , chardev_write() and chardev_read() are perfectly synchronized.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/03/07 19:12:31;  author: root;  state: Exp;  lines: +12 -15<br />
Logical bug fixed.<br />
Issue:&amp;&amp; is used instead of &amp; while bitwise ANDing O_ACCMODE with filep-&gt;f_flags.</p>
<p>Also added a check for O_RDONLY mode.<br />
Status : Open is working correctly.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/01 20:24:26;  author: root;  state: Exp;  lines: +12 -4<br />
Compilation successfull and chardev_trim() function is working fine.<br />
Issue:Trying the free the memory that is not allocated in case of quantum.<br />
Logical error fixed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/01 19:41:54;  author: root;  state: Exp;  lines: +4 -0<br />
kernel crash taking place inside chardev_trim() function.<br />
Issue inside chardev_trim() function.<br />
Debugging&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/01 19:38:30;  author: root;  state: Exp;  lines: +1 -1<br />
Syntax error fixed.<br />
Issue:Missing semicolon.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/01 19:37:04;  author: root;  state: Exp;  lines: +12 -4<br />
One bug fixed.<br />
Issue:qset_size variable is included using extern.<br />
Debugging&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/01 13:09:52;  author: root;  state: Exp;  lines: +49 -3<br />
Implementing chardev_trim() function.Inside this function,firstly certain checks are made to make sure that Sculldec , scullqset , qset and quantums exist or not.<br />
If any of such things do not exist an error message is reported.Now performing trimming&#8230;&#8230;&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/01 12:08:22;  author: root;  state: Exp;  lines: +23 -1<br />
Two printk statements are added inside the chardev_trim() function to mark its beginning and end.<br />
Checking&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/01 11:57:45;  author: root;  state: Exp;  lines: +5 -0<br />
O_ACCMODE is a macro that stands for a mask that can be bitwise-ANDed with the file status flag value to produce a value representing the file access mode.The mode will be O_WRONLY,O_RDONLY or O_RDWR.<br />
The O_ACCMODE macro is used inside the chardev_open() function to find out the file access mode.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/01 08:45:54;  author: root;  state: Exp;  lines: +5 -1<br />
Printing the address stored inside the lsculldev to check whether it matches with the filep-&gt;private data address printed inside the chardev_release() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/01 08:33:40;  author: root;  state: Exp;  lines: +1 -0<br />
Once the Sculldev structure is found by the container_of() macro,a pointer to the scull is stored in the private_data field of the file structure for easier access    .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/01 08:25:52;  author: root;  state: Exp;  lines: +11 -4<br />
A local variable of type struct Sculldev is declared.<br />
Used container_of() inside the open function.This macro has 3 arguments:<br />
1.A pointer to a field named container_field.<br />
2.This container field within a structure of type container_type,and<br />
3.ccontainer field.<br />
On success it returns a pointer to the containing structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/28 18:51:08;  author: root;  state: Exp;  lines: +2 -0<br />
Included the prototype of chardev_open() using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/28 18:42:56;  author: root;  state: Exp;  lines: +15 -0<br />
Two printk statements are used to test that whether the open function is actually begin and ended.\<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 18:33:28;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
<p>/home/Deepak/Desktop/wror</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-to-show-how-to-implement-a-semaphorea-type-of-locking-technique-in-scull-to-synchronize-same-operations-issued-by-multiple-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rotating a single linked list by k-nodes in counter-clockwise direction in C language.</title>
		<link>https://www.emblogic.com/blog/03/rotating-a-single-linked-list-by-k-nodes-in-counter-clockwise-direction-in-c-language/</link>
		<comments>https://www.emblogic.com/blog/03/rotating-a-single-linked-list-by-k-nodes-in-counter-clockwise-direction-in-c-language/#comments</comments>
		<pubDate>Fri, 07 Mar 2014 04:59:48 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8928</guid>
		<description><![CDATA[RCS file: rotate_linked_list.c,v Working file: rotate_linked_list.c head: 1.14 branch: locks: strict root: 1.14 access list: symbolic names: keyword substitution: kv total revisions: 14;    selected revisions: 14 description: Code to demonstrate how to rotate the single linked list counter clockwise by &#8230; <a href="https://www.emblogic.com/blog/03/rotating-a-single-linked-list-by-k-nodes-in-counter-clockwise-direction-in-c-language/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: rotate_linked_list.c,v<br />
Working file: rotate_linked_list.c<br />
head: 1.14<br />
branch:<br />
locks: strict<br />
root: 1.14<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 14;    selected revisions: 14<br />
description:<br />
Code to demonstrate how to rotate the single linked list counter clockwise by k-nodes.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14    locked by: root;<br />
date: 2014/03/07 15:23:54;  author: root;  state: Exp;  lines: +2 -1<br />
Status : Rotating a single linked list in the counter-clockwise direction by k-nodes where k is any number less than the total number of nodes in the linked list is implemented successfully.</p>
<p>Previous Issues:<br />
1.After rotating the list by k-nodes the last node is not getting displayed because the start node is not returned and collected correctly.<br />
2.Prototype mismatch.<br />
All these issues are identified and fixed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/07 15:14:58;  author: root;  state: Exp;  lines: +25 -5<br />
Implemented the rotate_list() function and fixed the errors by changing the prototype.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/07 14:54:00;  author: root;  state: Exp;  lines: +12 -2<br />
Changed the prototype of the display_nodes() function to int.A count variable is used to count the number of nodes in the linked list.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/07 14:50:07;  author: root;  state: Exp;  lines: +1 -0<br />
Gave prototype of the rotate_list() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/07 14:35:45;  author: root;  state: Exp;  lines: +10 -0<br />
Status : display_nodes() function is working fine.<br />
Added \n to make the output of the display_nodes() function more readable.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/07 14:30:05;  author: root;  state: Exp;  lines: +7 -0<br />
Gave prototype of the display_nodes() function.Before calling the display_nodes() function a check is made to ensure whether linked list already exists or not.<br />
Implementing the display_nodes() function&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/07 14:25:56;  author: root;  state: Exp;  lines: +1 -0<br />
Logical error fixed.<br />
Issue:A pointer variable of type struct node is not declared but used.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/07 14:24:15;  author: root;  state: Exp;  lines: +25 -0<br />
Gave prototype for insert_node() function.Also gave the definition of the insert_node() function which will insert the node at the end of the single linked list.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/07 14:16:54;  author: root;  state: Exp;  lines: +21 -2<br />
Gave definition of the create_list() function.Declared a flag variable that on creation of a start node is set to 1 and thus it avoids to create the start node again in case the user accidently chooses the create_list option again.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/07 14:12:30;  author: root;  state: Exp;  lines: +11 -0<br />
Declared two pointer variables of type struct node.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/07 14:10:12;  author: root;  state: Exp;  lines: +1 -0<br />
Gave prototype for create_list() function.<br />
Defining the body of the create_list() function&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/07 14:08:18;  author: root;  state: Exp;  lines: +17 -0<br />
exit() function is used to assist in ending the program.<br />
Also included header file:&lt;stdlib.h&gt; to support exit() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/03/07 14:01:19;  author: root;  state: Exp;  lines: +12 -1<br />
Created a main menu for the user to assist him/her in performing the operations on a single linked list.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/03/07 13:29:12;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/rotating-a-single-linked-list-by-k-nodes-in-counter-clockwise-direction-in-c-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementation of a generic double linked list in C.</title>
		<link>https://www.emblogic.com/blog/03/implementation-of-a-generic-double-linked-list-in-c/</link>
		<comments>https://www.emblogic.com/blog/03/implementation-of-a-generic-double-linked-list-in-c/#comments</comments>
		<pubDate>Fri, 07 Mar 2014 02:55:01 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8926</guid>
		<description><![CDATA[RCS file: generic_double_linkedlist.c,v Working file: generic_double_linkedlist.c head: 1.15 branch: locks: strict access list: symbolic names: keyword substitution: kv total revisions: 15;    selected revisions: 15 description: Code to demonstrate how to implement create , insert , display and delete operations in &#8230; <a href="https://www.emblogic.com/blog/03/implementation-of-a-generic-double-linked-list-in-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: generic_double_linkedlist.c,v<br />
Working file: generic_double_linkedlist.c<br />
head: 1.15<br />
branch:<br />
locks: strict<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 15;    selected revisions: 15<br />
description:<br />
Code to demonstrate how to implement create , insert , display and delete operations in a double linked list.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/03/07 12:33:11;  author: root;  state: Exp;  lines: +2 -0<br />
Status : Double linked list implementation is done successfully.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/03/07 12:30:01;  author: root;  state: Exp;  lines: +1 -1<br />
Syntax error fixed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/07 12:28:13;  author: root;  state: Exp;  lines: +25 -1<br />
Implemented delete_nodes() function that will delete the entire double linked list.<br />
Checking&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/07 04:04:35;  author: root;  state: Exp;  lines: +6 -0<br />
A check is made by printing an appropriate message in case the user chooses the display_nodes() function while there is no nodes in the double linked list.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/07 04:01:33;  author: root;  state: Exp;  lines: +4 -0<br />
Optimized the code by performing a break in the display_nodes when end-&gt;prev==NULL<br />
Implementing the code to delete all the nodes in the double linked list.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/07 03:57:33;  author: root;  state: Exp;  lines: +34 -2<br />
display_nodes() function implemented for a double linked list.The display_nodes() function asks the user to print the nodes in the double linked list in forward order using the start pointer and it also asks the user to print the nodes in the double linked list in reverse order using the new poiner which always points to the lst node of the double linked list.<br />
Status : display_nodes() function is implemented successfully.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/07 03:17:03;  author: root;  state: Exp;  lines: +3 -3<br />
Prototype mismatch error occured , bug fixed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/07 03:09:10;  author: root;  state: Exp;  lines: +25 -0<br />
Gave prototypes for insert_info() and insert_node() functions.After calling the insert_node() function a node gets created and is inserted at the end of the list.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/07 03:00:11;  author: root;  state: Exp;  lines: +8 -0<br />
gave definition of the create_list() function.<br />
Status:The start node of the double linked list is created successfully.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/07 02:52:13;  author: root;  state: Exp;  lines: +1 -0<br />
Gave prototype for create_list() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/07 02:49:53;  author: root;  state: Exp;  lines: +18 -1<br />
Declared two variables of type struct node and both are initialized to NULL.<br />
Also called the create_list() function to create the start node of the double linked list.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/07 02:44:08;  author: root;  state: Exp;  lines: +6 -0<br />
A structure called node is defined with three member fields namely :<br />
1.info part,<br />
2.a pointer to the next node of type struct node<br />
3.a pointer to the previous node.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/07 02:42:07;  author: root;  state: Exp;  lines: +20 -0<br />
Header file:&lt;stdlib.h&gt; is included to support exit() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/03/07 02:36:55;  author: root;  state: Exp;  lines: +9 -0<br />
A layout is prepared for the user that will help in selecting a specific task on a double linked list.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/03/07 01:56:03;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/implementation-of-a-generic-double-linked-list-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code showing the difference between *loff and filep-&gt;f_pos when multiple write() system calls are issued by the application.</title>
		<link>https://www.emblogic.com/blog/03/module-code-showing-the-difference-between-loff-and-filep-f_pos-when-multiple-write-system-calls-are-issued-by-the-application/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-showing-the-difference-between-loff-and-filep-f_pos-when-multiple-write-system-calls-are-issued-by-the-application/#comments</comments>
		<pubDate>Wed, 05 Mar 2014 04:23:49 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8888</guid>
		<description><![CDATA[&#160; Difference between loff_t *loff and filep-&#62;f_pos: When an application issues write() system call , chardev_write() function is called because it is mapped to (*write) function pointer.chardev_write() function contains 4 arguments namely: 1. A pointer to the struct file structure. &#8230; <a href="https://www.emblogic.com/blog/03/module-code-showing-the-difference-between-loff-and-filep-f_pos-when-multiple-write-system-calls-are-issued-by-the-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p><strong>Difference between loff_t *loff and filep-&gt;f_pos:</strong></p>
<p>When an application issues write() system call , chardev_write() function is called because it is mapped to (*write) function pointer.chardev_write() function contains 4 arguments namely:</p>
<p>1. A pointer to the struct file structure.</p>
<p>2.A pointer to the buffer in the user space.</p>
<p>3.Size of the data</p>
<p>4.Used for internal book-keeping.</p>
<p>Initially both filep-&gt;f_pos and *loff are 0.Only  *loff is updated with the number of characters successfully written whereas filep-&gt;f_pos remains at position 0.Now whenever an application issues another write() call without closing the file , the value of *loff is copied to filep-&gt;f_pos.After the file is closed both the filep-&gt;f_pos and the *loff are set to 0.<br />
RCS file: writef.c,v<br />
Working file: writef.c<br />
head: 1.40<br />
branch:<br />
locks: strict<br />
root: 1.40<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 40;    selected revisions: 40<br />
description:<br />
chardev_write() function reside here.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.40    locked by: root;<br />
date: 2014/03/05 14:15:21;  author: root;  state: Exp;  lines: +6 -1<br />
Updated loff while changing the nocsw.<br />
Status : loff is getting updated successfully and is pointing to the current position.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.39<br />
date: 2014/03/05 14:10:54;  author: root;  state: Exp;  lines: +1 -1<br />
Fixed the warning by typecasting loff_t to int.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.38<br />
date: 2014/03/05 14:08:44;  author: root;  state: Exp;  lines: +7 -2<br />
Gave two printk() statements to check the starting values of filep-&gt;f_pos and loff.<br />
Checking&#8230;&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.37<br />
date: 2014/03/04 18:55:04;  author: root;  state: Exp;  lines: +0 -21<br />
Status : Writing in multiple qsets is successfully implemented.</p>
<p>Issue:The data pointer to the qset array was updated to point to the last qset array.Because of this reason the crash is taking place.<br />
Bug fixed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.36<br />
date: 2014/03/04 18:43:52;  author: root;  state: Exp;  lines: +18 -4<br />
Input/output crash is taking place.<br />
Debugging&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.35<br />
date: 2014/03/04 07:36:31;  author: root;  state: Exp;  lines: +3 -1<br />
Logical error fixed.<br />
Issue : flag variable is not set to 1 due to which it is not able to link the scullqsets.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.34<br />
date: 2014/03/04 07:21:30;  author: root;  state: Exp;  lines: +7 -2<br />
Declared a count variable inside create_scullqset() function too to make sure that exactly how many scullqsets are created.<br />
The number of scullqsets are properly created inside the create_scullqset() function,but inside the chardev_write() it is showing 1 only same is the case with qset_arrays.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.33<br />
date: 2014/03/04 07:16:19;  author: root;  state: Exp;  lines: +10 -6<br />
The messages inside two error conditions are changed to make them more meaningful.Also declared a count variable to make sure exactly how many qset arrays are exactly created by the create_qset() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.32<br />
date: 2014/03/04 07:10:31;  author: root;  state: Exp;  lines: +5 -1<br />
Kernel crash taking place.The second qset array is not getting created or linked properly.<br />
Debugging&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.31<br />
date: 2014/03/04 07:05:36;  author: root;  state: Exp;  lines: +30 -33<br />
Properly placing the debugging statements to help finding out the error quickly.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.30<br />
date: 2014/03/03 23:19:07;  author: root;  state: Exp;  lines: +33 -2<br />
Logical error fixed.<br />
Issue:Kernel is crashing while running the module code.The problem lies in the check statement where the dereferencing of NULL pointer is taking placing.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.29<br />
date: 2014/03/03 22:58:55;  author: root;  state: Exp;  lines: +5 -2<br />
Declared a pointer variable of type struct Scullqset to verify whether the number of scullqsets , qset arrays and quantums are actually created or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.28<br />
date: 2014/03/03 22:22:42;  author: root;  state: Exp;  lines: +11 -1<br />
A check is made to move to the next lscullqset when the loop variable i equals to 7.Also a loop variable j is used to break the loop when the j becomes equal to noq variable.<br />
Checking&#8230;&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.27<br />
date: 2014/03/03 22:17:47;  author: root;  state: Exp;  lines: +9 -6<br />
Optimized the code by allocating the exact number of bytes required for each quantum.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.26<br />
date: 2014/03/03 21:58:52;  author: root;  state: Exp;  lines: +34 -10<br />
Modified the create_qset() function to create the required number of qset arrays.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.25<br />
date: 2014/03/03 21:05:42;  author: root;  state: Exp;  lines: +3 -0<br />
Declared a variable lscullqset of type struct Scullqset and it is initialized with fsculldev-&gt;scullqset.<br />
This is done inside create_qset().<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.24<br />
date: 2014/03/03 20:59:42;  author: root;  state: Exp;  lines: +2 -1<br />
Logical error fixed.<br />
Issue:kernel crash is taking place because the starting address of the lscullqset is not saved inside fsculldev-&gt;scullqset due to which while creating qset arrays it is not getting updated lscullqset address from fsculldev-&gt;scullqset.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.23<br />
date: 2014/03/03 20:53:32;  author: root;  state: Exp;  lines: +1 -1<br />
While compilation a warning is coming indicating mixed declerations.<br />
fixed the warning by placing all the declerations above the initializations.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.22<br />
date: 2014/03/03 20:52:17;  author: root;  state: Exp;  lines: +15 -0<br />
Linking between lscullqsets is done.<br />
Checking&#8230;&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.21<br />
date: 2014/03/03 20:44:14;  author: root;  state: Exp;  lines: +19 -11<br />
Modifying the code so that writing in multiple qset arrays can be performed.<br />
A flag variable is used to keep track on the number of scullqsets and with the help of this variable linking in lscullqset is also done.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.20<br />
date: 2014/03/03 20:38:05;  author: root;  state: Exp;  lines: +3 -0<br />
Declared a structure variable lscullqset of type struct Scullqset.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.19<br />
date: 2014/03/03 19:00:50;  author: root;  state: Exp;  lines: +2 -2<br />
Status : Writing in multiple quantums is successfully done.</p>
<p>Previous Issues:<br />
1.Allocating memory for qset array incorrectly.<br />
2.Wrongly calculating the number of qset arrays.<br />
Such logical errors are identified and corrected successfully.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.18<br />
date: 2014/03/03 18:55:17;  author: root;  state: Exp;  lines: +13 -13<br />
Corrected the argument inside kmalloc().The size of the qset array is calculated by multiplying the qset size with the size of the pointer.<br />
Also modified a message to display how many qset arrays are created.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.17<br />
date: 2014/03/01 21:01:35;  author: root;  state: Exp;  lines: +2 -2<br />
Status : Writing in multiple quantums successfully implemented.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.16<br />
date: 2014/03/01 20:53:57;  author: root;  state: Exp;  lines: +20 -10<br />
Modifying the code to work for writing in more than one quantums.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/03/01 11:19:07;  author: root;  state: Exp;  lines: +5 -0<br />
One printk statement is added to test whether the data is actually copied into the kernel buffer or not.<br />
Testing&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/03/01 11:13:18;  author: root;  state: Exp;  lines: +15 -7<br />
The copy_from_user() function is used to copy a block of data from user space into the kernel buffer.copy_from_user() function contains 3 arguments:<br />
1.A destination buffer,<br />
2.A source buffer,and<br />
3.length in bytes.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/01 11:06:21;  author: root;  state: Exp;  lines: +2 -1<br />
Done memset().<br />
Testing the code&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/01 11:01:16;  author: root;  state: Exp;  lines: +54 -5<br />
Implemented the create_quantums() function that will create the required number of quantums.<br />
Kmalloc() is used to allocate memory for each quantum.<br />
Filling the memory allocated using kmalloc() with memset() so that it does not contain any garbage.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/01 10:39:39;  author: root;  state: Exp;  lines: +1 -0<br />
memset() function is used to fill the memory allocated for the qset array to &#8221;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/01 10:36:59;  author: root;  state: Exp;  lines: +14 -4<br />
Using kmalloc() memory is allocated to the required number of qsets.<br />
Checking whether it is working fine or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/01 10:26:27;  author: root;  state: Exp;  lines: +36 -2<br />
Implemented create_scullqset() function.Now checking the number of qsets that needs to created by using the size argument of the chardev_write().After determining the number of qsets that needs to be created create_qset() function is called.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/01 10:07:44;  author: root;  state: Exp;  lines: +2 -1<br />
memset() function is used to fill the memory allocated using kmalloc() with &#8221; .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/01 10:04:21;  author: root;  state: Exp;  lines: +10 -0<br />
Allocating memory for 1 scullqset to check whether the create_scullqset() function is working properly or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/01 09:56:22;  author: root;  state: Exp;  lines: +22 -2<br />
After finding out the number of scullqsets,create_scullqset() function is called to create the specified number of scullqsets.<br />
Checking whether the function calling is taking place or not&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/01 09:47:56;  author: root;  state: Exp;  lines: +19 -0<br />
The size argument that specifies the size of the buffer pointed to by ubuff is used to find the number of scullqsets that needs to be created.<br />
After finding out the exact number of scullqsets that needs to be created,the number of scullqsets are printed.<br />
Creating scullqsets&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/01 09:32:34;  author: root;  state: Exp;  lines: +1 -1<br />
Fixed the warning by type-casting size_t to int.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/01 09:28:31;  author: root;  state: Exp;  lines: +6 -1<br />
Checking whether the ubuff pointer is actually pointing to the buffer in the application.Also checking the size field inside the 3rd argument of chardev_write().<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/03/01 09:20:00;  author: root;  state: Exp;  lines: +9 -1<br />
Printing the address inside filep-&gt;private_data to check whether it matches with the address returned by container_of() macro.<br />
A local variable of type Sculldev is declared which will store the address that is present inside filep-&gt;private_data.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 21:33:05;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-showing-the-difference-between-loff-and-filep-f_pos-when-multiple-write-system-calls-are-issued-by-the-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code to show  how to perform read operation in multiple qset arrays.</title>
		<link>https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-read-operation-in-multiple-qset-arrays/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-read-operation-in-multiple-qset-arrays/#comments</comments>
		<pubDate>Wed, 05 Mar 2014 03:20:09 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8886</guid>
		<description><![CDATA[RCS file: readf.c,v Working file: readf.c head: 1.18 branch: locks: strict root: 1.18 access list: symbolic names: keyword substitution: kv total revisions: 18;    selected revisions: 18 description: chardev_read() function reside here which is responsible for performing the read operation. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8230; <a href="https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-read-operation-in-multiple-qset-arrays/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: readf.c,v<br />
Working file: readf.c<br />
head: 1.18<br />
branch:<br />
locks: strict<br />
root: 1.18<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 18;    selected revisions: 18<br />
description:<br />
chardev_read() function reside here which is responsible for performing the read operation.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.18    locked by: root;<br />
date: 2014/03/05 08:19:18;  author: root;  state: Exp;  lines: +1 -1<br />
Modified the return value of the chardev_read() function to nocsr.This return value becomes the return type of the read() system call in the application.</p>
<p>Status : Read operation in multiple qset arrays is implemented successfully.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.17<br />
date: 2014/03/05 08:13:05;  author: root;  state: Exp;  lines: +1 -1<br />
Changed quantum_size to qset_size inside the loop.<br />
Checking&#8230;&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.16<br />
date: 2014/03/05 08:10:38;  author: root;  state: Exp;  lines: +13 -3<br />
Declared a variable j to keep track on how many quantums read operation is already performed.When it is equal to the number of quantums then break.<br />
Also a condition is included in which the variable i is set to 0 and lscullqset is updated when the i equals qset_size.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/03/05 08:06:46;  author: root;  state: Exp;  lines: +2 -1<br />
Declared a local pointer variable to point to a structure of type struct Scullqset.<br />
Extending the code further so that read can be performed in multiple qset arrays.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/03/04 22:36:51;  author: root;  state: Exp;  lines: +3 -2<br />
Status : Read operation from multiple quantums is implemented successfully.</p>
<p>All logical errors are fixed.<br />
To calculate the number of characters to read size argument is used instead of the data_size to ensure that always the size number of bytes.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/04 22:29:49;  author: root;  state: Exp;  lines: +1 -0<br />
Logical mistake,the number of characters successfully read was not updated.<br />
Fixed the bug.<br />
Checking&#8230;&#8230;&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/04 22:15:25;  author: root;  state: Exp;  lines: +21 -3<br />
Implemented the logic for copy_to_user() function for the multiple quantums.<br />
After reading the entire data from quantums,it is stored inside rbuff pointer.<br />
Checking&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/04 21:02:53;  author: root;  state: Exp;  lines: +8 -1<br />
Calculated the required number of quantums based on the data size.<br />
After calculating the number of quantums the number of quantums are printed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/04 20:57:26;  author: root;  state: Exp;  lines: +1 -1<br />
Bug fixed.<br />
Issue : Incorrect spelling of noqsa.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/04 20:54:34;  author: root;  state: Exp;  lines: +8 -0<br />
Added the logic to find out the number of qset arrays that are required using the data_size.<br />
After calculating the number of qset arrays are printed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/04 20:49:58;  author: root;  state: Exp;  lines: +16 -2<br />
Logic to find the number of scullqset required is added.The total number of scullqsets will depend on the data_size.<br />
After calculating the number of scullqsets required,the number of scullqsets are printed using printk() statements.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/04 20:15:29;  author: root;  state: Exp;  lines: +2 -0<br />
Another variable is added using extern called data_size which actually stores how much data is written to the quantums.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/04 20:14:01;  author: root;  state: Exp;  lines: +4 -0<br />
Three variables are added namely:quantum_size , qset_size and device_size using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/04 20:11:21;  author: root;  state: Exp;  lines: +8 -0<br />
Declared two variables i and noq.The variable is used to run the loop and the variable noq is used to store the number of quantums.<br />
Calculating the number of quantums&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/04 20:08:36;  author: root;  state: Exp;  lines: +2 -0<br />
Declared a pointer to a structure of type struct Sculldev,inside which the filep-&gt;private_data is stored.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/04 20:04:39;  author: root;  state: Exp;  lines: +8 -1<br />
Gave two printk() statements to mark the beginning and end of the chardev_read() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/03/04 20:02:14;  author: root;  state: Exp;  lines: +8 -0<br />
The prototype of the chardev_read() function is added here using extern.<br />
Defining the body of the chardev_read() function&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/03/04 19:30:01;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-read-operation-in-multiple-qset-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code to show how to perform read operation in multiple quantums.</title>
		<link>https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-read-operation-from-multiple-quantums/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-read-operation-from-multiple-quantums/#comments</comments>
		<pubDate>Tue, 04 Mar 2014 17:42:47 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8882</guid>
		<description><![CDATA[RCS file: readf.c,v Working file: readf.c head: 1.14 branch: locks: strict access list: symbolic names: keyword substitution: kv total revisions: 14;    selected revisions: 14 description: chardev_read() function reside here which is responsible for performing the read operation. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- revision 1.14 &#8230; <a href="https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-read-operation-from-multiple-quantums/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: readf.c,v<br />
Working file: readf.c<br />
head: 1.14<br />
branch:<br />
locks: strict<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 14;    selected revisions: 14<br />
description:<br />
chardev_read() function reside here which is responsible for performing the read operation.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/03/04 22:36:51;  author: root;  state: Exp;  lines: +3 -2<br />
Status : Read operation from multiple quantums is implemented successfully.</p>
<p>All logical errors are fixed.<br />
To calculate the number of characters to read size argument is used instead of the data_size to ensure that always the size number of bytes.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/04 22:29:49;  author: root;  state: Exp;  lines: +1 -0<br />
Logical mistake,the number of characters successfully read was not updated.<br />
Fixed the bug.<br />
Checking&#8230;&#8230;&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/04 22:15:25;  author: root;  state: Exp;  lines: +21 -3<br />
Implemented the logic for copy_to_user() function for the multiple quantums.<br />
After reading the entire data from quantums,it is stored inside rbuff pointer.<br />
Checking&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/04 21:02:53;  author: root;  state: Exp;  lines: +8 -1<br />
Calculated the required number of quantums based on the data size.<br />
After calculating the number of quantums the number of quantums are printed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/04 20:57:26;  author: root;  state: Exp;  lines: +1 -1<br />
Bug fixed.<br />
Issue : Incorrect spelling of noqsa.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/04 20:54:34;  author: root;  state: Exp;  lines: +8 -0<br />
Added the logic to find out the number of qset arrays that are required using the data_size.<br />
After calculating the number of qset arrays are printed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/04 20:49:58;  author: root;  state: Exp;  lines: +16 -2<br />
Logic to find the number of scullqset required is added.The total number of scullqsets will depend on the data_size.<br />
After calculating the number of scullqsets required,the number of scullqsets are printed using printk() statements.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/04 20:15:29;  author: root;  state: Exp;  lines: +2 -0<br />
Another variable is added using extern called data_size which actually stores how much data is written to the quantums.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/04 20:14:01;  author: root;  state: Exp;  lines: +4 -0<br />
Three variables are added namely:quantum_size , qset_size and device_size using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/04 20:11:21;  author: root;  state: Exp;  lines: +8 -0<br />
Declared two variables i and noq.The variable is used to run the loop and the variable noq is used to store the number of quantums.<br />
Calculating the number of quantums&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/04 20:08:36;  author: root;  state: Exp;  lines: +2 -0<br />
Declared a pointer to a structure of type struct Sculldev,inside which the filep-&gt;private_data is stored.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/04 20:04:39;  author: root;  state: Exp;  lines: +8 -1<br />
Gave two printk() statements to mark the beginning and end of the chardev_read() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/03/04 20:02:14;  author: root;  state: Exp;  lines: +8 -0<br />
The prototype of the chardev_read() function is added here using extern.<br />
Defining the body of the chardev_read() function&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/03/04 19:30:01;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: decleration.h,v<br />
Working file: decleration.h<br />
head: 1.10<br />
branch:<br />
locks: strict<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 10;    selected revisions: 10<br />
description:<br />
All the variable declerations are done inside this header file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/04 01:27:07;  author: root;  state: Exp;  lines: +1 -0<br />
Gave prototype for chardev_read() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/02/28 21:40:24;  author: root;  state: Exp;  lines: +1 -0<br />
Gave prototype for chardev_write() function .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/02/28 20:28:24;  author: root;  state: Exp;  lines: +1 -0<br />
Gave prototype for chardev_release() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/28 18:48:17;  author: root;  state: Exp;  lines: +2 -0<br />
Gave prototype of chardev_open() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/28 17:05:32;  author: root;  state: Exp;  lines: +1 -0<br />
A variable of type dev_t is declared that is used to store the updated device number obtained from mkdev.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/28 16:59:40;  author: root;  state: Exp;  lines: +3 -0<br />
Two variables are declared inside this file that will hold the information about major and minor numbers.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/28 16:39:07;  author: root;  state: Exp;  lines: +4 -0<br />
Variables quantum_size,qset_size,data_size and device_size are declared that will get initialized by the macros defined in header.h.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/28 15:30:46;  author: root;  state: Exp;  lines: +1 -0<br />
A variable of type Sculldev is declared in this file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 20:06:26;  author: root;  state: Exp;  lines: +1 -0<br />
A variable of type int is declared representing the number of devices.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 19:30:54;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-read-operation-from-multiple-quantums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code showing how to read data in a single quantum using copy_to_user() function.</title>
		<link>https://www.emblogic.com/blog/03/module-code-showing-how-to-read-data-from-a-single-quantum-using-copy_to_user-function/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-showing-how-to-read-data-from-a-single-quantum-using-copy_to_user-function/#comments</comments>
		<pubDate>Tue, 04 Mar 2014 13:53:01 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8872</guid>
		<description><![CDATA[RCS file: readf.c,v Working file: readf.c head: 1.11 branch: locks: strict root: 1.11 access list: symbolic names: keyword substitution: kv total revisions: 11;    selected revisions: 11 description: chardev_read() function is implemented here in this file. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- revision 1.11    locked by: &#8230; <a href="https://www.emblogic.com/blog/03/module-code-showing-how-to-read-data-from-a-single-quantum-using-copy_to_user-function/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: readf.c,v<br />
Working file: readf.c<br />
head: 1.11<br />
branch:<br />
locks: strict<br />
root: 1.11<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 11;    selected revisions: 11<br />
description:<br />
chardev_read() function is implemented here in this file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11    locked by: root;<br />
date: 2014/03/04 00:31:32;  author: root;  state: Exp;  lines: +1 -1<br />
Status : reading data from a single quantum is implemented successfully.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/02 17:33:44;  author: root;  state: Exp;  lines: +1 -1<br />
Typecasting is done.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/02 17:32:15;  author: root;  state: Exp;  lines: +4 -0<br />
Checking the data inside the quantum by printing it using lsculldev-&gt;scullqset-&gt;data[0].<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/02 17:30:51;  author: root;  state: Exp;  lines: +1 -0<br />
Logical error while using copy_to_read().<br />
Debugging&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/02 17:27:23;  author: root;  state: Exp;  lines: +1 -1<br />
Bug fixed.<br />
Issue:type-casting not performed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/02 17:24:51;  author: root;  state: Exp;  lines: +11 -0<br />
copy_to_user() function is used to copy the data from the quantum to the ubuff.It is similar to the copy_from_user() function.<br />
Declared an ret variable which represents the number of characters not successfully read.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/02 17:08:52;  author: root;  state: Exp;  lines: +7 -1<br />
Printing the address contained inside the filep-&gt;private_data.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/02 17:05:12;  author: root;  state: Exp;  lines: +2 -1<br />
Declared a pointer of type struct Sculldev.<br />
Assigning the filep-&gt;private_data to lsculldev.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/02 16:53:58;  author: root;  state: Exp;  lines: +6 -1<br />
ubuff is a user space pointer that points to the data in the application.Therefore, it cannot be directly dereferenced by kernel code.<br />
Using this pointer the data inside the application and its size is printed here.<br />
Checking&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/03/02 16:20:56;  author: root;  state: Exp;  lines: +13 -0<br />
Gave two printk() statements inside chardev_read() function to mark the start and end of this function.Also included the prototype of this function using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/03/02 16:14:35;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-showing-how-to-read-data-from-a-single-quantum-using-copy_to_user-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code showing how to write data in multiple quantums from a user application.</title>
		<link>https://www.emblogic.com/blog/03/module-code-showing-how-to-write-data-in-multiple-quantums-from-a-user-application/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-showing-how-to-write-data-in-multiple-quantums-from-a-user-application/#comments</comments>
		<pubDate>Tue, 04 Mar 2014 13:41:07 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8869</guid>
		<description><![CDATA[RCS file: writef.c,v Working file: writef.c head: 1.19 branch: locks: strict root: 1.19 access list: symbolic names: keyword substitution: kv total revisions: 19;    selected revisions: 19 description: chardev_write() function reside here. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- revision 1.19    locked by: root; date: 2014/03/03 19:00:50;  &#8230; <a href="https://www.emblogic.com/blog/03/module-code-showing-how-to-write-data-in-multiple-quantums-from-a-user-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: writef.c,v<br />
Working file: writef.c<br />
head: 1.19<br />
branch:<br />
locks: strict<br />
root: 1.19<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 19;    selected revisions: 19<br />
description:<br />
chardev_write() function reside here.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.19    locked by: root;<br />
date: 2014/03/03 19:00:50;  author: root;  state: Exp;  lines: +2 -2<br />
Status : Writing in multiple quantums is successfully done.</p>
<p>Previous Issues:<br />
1.Allocating memory for qset array incorrectly.<br />
2.Wrongly calculating the number of qset arrays.<br />
Such logical errors are identified and corrected successfully.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.18<br />
date: 2014/03/03 18:55:17;  author: root;  state: Exp;  lines: +13 -13<br />
Corrected the argument inside kmalloc().The size of the qset array is calculated by multiplying the qset size with the size of the pointer.<br />
Also modified a message to display how many qset arrays are created.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.17<br />
date: 2014/03/01 21:01:35;  author: root;  state: Exp;  lines: +2 -2<br />
Status : Writing in multiple quantums successfully implemented.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.16<br />
date: 2014/03/01 20:53:57;  author: root;  state: Exp;  lines: +20 -10<br />
Modifying the code to work for writing in more than one quantums.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/03/01 11:19:07;  author: root;  state: Exp;  lines: +5 -0<br />
One printk statement is added to test whether the data is actually copied into the kernel buffer or not.<br />
Testing&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/03/01 11:13:18;  author: root;  state: Exp;  lines: +15 -7<br />
The copy_from_user() function is used to copy a block of data from user space into the kernel buffer.copy_from_user() function contains 3 arguments:<br />
1.A destination buffer,<br />
2.A source buffer,and<br />
3.length in bytes.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/01 11:06:21;  author: root;  state: Exp;  lines: +2 -1<br />
Done memset().<br />
Testing the code&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/01 11:01:16;  author: root;  state: Exp;  lines: +54 -5<br />
Implemented the create_quantums() function that will create the required number of quantums.<br />
Kmalloc() is used to allocate memory for each quantum.<br />
Filling the memory allocated using kmalloc() with memset() so that it does not contain any garbage.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/01 10:39:39;  author: root;  state: Exp;  lines: +1 -0<br />
memset() function is used to fill the memory allocated for the qset array to &#8221;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/01 10:36:59;  author: root;  state: Exp;  lines: +14 -4<br />
Using kmalloc() memory is allocated to the required number of qsets.<br />
Checking whether it is working fine or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/01 10:26:27;  author: root;  state: Exp;  lines: +36 -2<br />
Implemented create_scullqset() function.Now checking the number of qsets that needs to created by using the size argument of the chardev_write().After determining the number of qsets that needs to be created create_qset() function is called.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/01 10:07:44;  author: root;  state: Exp;  lines: +2 -1<br />
memset() function is used to fill the memory allocated using kmalloc() with &#8221; .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/01 10:04:21;  author: root;  state: Exp;  lines: +10 -0<br />
Allocating memory for 1 scullqset to check whether the create_scullqset() function is working properly or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/01 09:56:22;  author: root;  state: Exp;  lines: +22 -2<br />
After finding out the number of scullqsets,create_scullqset() function is called to create the specified number of scullqsets.<br />
Checking whether the function calling is taking place or not&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/01 09:47:56;  author: root;  state: Exp;  lines: +19 -0<br />
The size argument that specifies the size of the buffer pointed to by ubuff is used to find the number of scullqsets that needs to be created.<br />
After finding out the exact number of scullqsets that needs to be created,the number of scullqsets are printed.<br />
Creating scullqsets&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/01 09:32:34;  author: root;  state: Exp;  lines: +1 -1<br />
Fixed the warning by type-casting size_t to int.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/01 09:28:31;  author: root;  state: Exp;  lines: +6 -1<br />
Checking whether the ubuff pointer is actually pointing to the buffer in the application.Also checking the size field inside the 3rd argument of chardev_write().<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/03/01 09:20:00;  author: root;  state: Exp;  lines: +9 -1<br />
Printing the address inside filep-&gt;private_data to check whether it matches with the address returned by container_of() macro.<br />
A local variable of type Sculldev is declared which will store the address that is present inside filep-&gt;private_data.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 21:33:05;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-showing-how-to-write-data-in-multiple-quantums-from-a-user-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code showing how to write data in multiple qset arrays from a user application.</title>
		<link>https://www.emblogic.com/blog/03/module-code-showing-how-to-write-data-in-multiple-qset-arrays-from-a-user-application/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-showing-how-to-write-data-in-multiple-qset-arrays-from-a-user-application/#comments</comments>
		<pubDate>Tue, 04 Mar 2014 13:34:32 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8867</guid>
		<description><![CDATA[RCS file: writef.c,v Working file: writef.c head: 1.37 branch: locks: strict root: 1.37 access list: symbolic names: keyword substitution: kv total revisions: 37;    selected revisions: 37 description: chardev_write() function reside here. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- revision 1.37    locked by: root; date: 2014/03/04 18:55:04;  &#8230; <a href="https://www.emblogic.com/blog/03/module-code-showing-how-to-write-data-in-multiple-qset-arrays-from-a-user-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: writef.c,v<br />
Working file: writef.c<br />
head: 1.37<br />
branch:<br />
locks: strict<br />
root: 1.37<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 37;    selected revisions: 37<br />
description:<br />
chardev_write() function reside here.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.37    locked by: root;<br />
date: 2014/03/04 18:55:04;  author: root;  state: Exp;  lines: +0 -21<br />
Status : Writing in multiple qset arrays is successfully implemented.</p>
<p>Issue:The data pointer to the qset array was updated to point to the last qset array.Because of this reason the crash is taking place.<br />
Bug fixed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.36<br />
date: 2014/03/04 18:43:52;  author: root;  state: Exp;  lines: +18 -4<br />
Input/output crash is taking place.<br />
Debugging&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.35<br />
date: 2014/03/04 07:36:31;  author: root;  state: Exp;  lines: +3 -1<br />
Logical error fixed.<br />
Issue : flag variable is not set to 1 due to which it is not able to link the scullqsets.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.34<br />
date: 2014/03/04 07:21:30;  author: root;  state: Exp;  lines: +7 -2<br />
Declared a count variable inside create_scullqset() function too to make sure that exactly how many scullqsets are created.<br />
The number of scullqsets are properly created inside the create_scullqset() function,but inside the chardev_write() it is showing 1 only same is the case with qset_arrays.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.33<br />
date: 2014/03/04 07:16:19;  author: root;  state: Exp;  lines: +10 -6<br />
The messages inside two error conditions are changed to make them more meaningful.Also declared a count variable to make sure exactly how many qset arrays are exactly created by the create_qset() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.32<br />
date: 2014/03/04 07:10:31;  author: root;  state: Exp;  lines: +5 -1<br />
Kernel crash taking place.The second qset array is not getting created or linked properly.<br />
Debugging&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.31<br />
date: 2014/03/04 07:05:36;  author: root;  state: Exp;  lines: +30 -33<br />
Properly placing the debugging statements to help finding out the error quickly.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.30<br />
date: 2014/03/03 23:19:07;  author: root;  state: Exp;  lines: +33 -2<br />
Logical error fixed.<br />
Issue:Kernel is crashing while running the module code.The problem lies in the check statement where the dereferencing of NULL pointer is taking placing.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.29<br />
date: 2014/03/03 22:58:55;  author: root;  state: Exp;  lines: +5 -2<br />
Declared a pointer variable of type struct Scullqset to verify whether the number of scullqsets , qset arrays and quantums are actually created or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.28<br />
date: 2014/03/03 22:22:42;  author: root;  state: Exp;  lines: +11 -1<br />
A check is made to move to the next lscullqset when the loop variable i equals to 7.Also a loop variable j is used to break the loop when the j becomes equal to noq variable.<br />
Checking&#8230;&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.27<br />
date: 2014/03/03 22:17:47;  author: root;  state: Exp;  lines: +9 -6<br />
Optimized the code by allocating the exact number of bytes required for each quantum.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.26<br />
date: 2014/03/03 21:58:52;  author: root;  state: Exp;  lines: +34 -10<br />
Modified the create_qset() function to create the required number of qset arrays.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.25<br />
date: 2014/03/03 21:05:42;  author: root;  state: Exp;  lines: +3 -0<br />
Declared a variable lscullqset of type struct Scullqset and it is initialized with fsculldev-&gt;scullqset.<br />
This is done inside create_qset().<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.24<br />
date: 2014/03/03 20:59:42;  author: root;  state: Exp;  lines: +2 -1<br />
Logical error fixed.<br />
Issue:kernel crash is taking place because the starting address of the lscullqset is not saved inside fsculldev-&gt;scullqset due to which while creating qset arrays it is not getting updated lscullqset address from fsculldev-&gt;scullqset.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.23<br />
date: 2014/03/03 20:53:32;  author: root;  state: Exp;  lines: +1 -1<br />
While compilation a warning is coming indicating mixed declerations.<br />
fixed the warning by placing all the declerations above the initializations.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.22<br />
date: 2014/03/03 20:52:17;  author: root;  state: Exp;  lines: +15 -0<br />
Linking between lscullqsets is done.<br />
Checking&#8230;&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.21<br />
date: 2014/03/03 20:44:14;  author: root;  state: Exp;  lines: +19 -11<br />
Modifying the code so that writing in multiple qset arrays can be performed.<br />
A flag variable is used to keep track on the number of scullqsets and with the help of this variable linking in lscullqset is also done.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.20<br />
date: 2014/03/03 20:38:05;  author: root;  state: Exp;  lines: +3 -0<br />
Declared a structure variable lscullqset of type struct Scullqset.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.19<br />
date: 2014/03/03 19:00:50;  author: root;  state: Exp;  lines: +2 -2<br />
Status : Writing in multiple quantums is successfully done.</p>
<p>Previous Issues:<br />
1.Allocating memory for qset array incorrectly.<br />
2.Wrongly calculating the number of qset arrays.<br />
Such logical errors are identified and corrected successfully.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.18<br />
date: 2014/03/03 18:55:17;  author: root;  state: Exp;  lines: +13 -13<br />
Corrected the argument inside kmalloc().The size of the qset array is calculated by multiplying the qset size with the size of the pointer.<br />
Also modified a message to display how many qset arrays are created.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.17<br />
date: 2014/03/01 21:01:35;  author: root;  state: Exp;  lines: +2 -2<br />
Status : Writing in multiple quantums successfully implemented.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.16<br />
date: 2014/03/01 20:53:57;  author: root;  state: Exp;  lines: +20 -10<br />
Modifying the code to work for writing in more than one quantums.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/03/01 11:19:07;  author: root;  state: Exp;  lines: +5 -0<br />
One printk statement is added to test whether the data is actually copied into the kernel buffer or not.<br />
Testing&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/03/01 11:13:18;  author: root;  state: Exp;  lines: +15 -7<br />
The copy_from_user() function is used to copy a block of data from user space into the kernel buffer.copy_from_user() function contains 3 arguments:<br />
1.A destination buffer,<br />
2.A source buffer,and<br />
3.length in bytes.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/01 11:06:21;  author: root;  state: Exp;  lines: +2 -1<br />
Done memset().<br />
Testing the code&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/01 11:01:16;  author: root;  state: Exp;  lines: +54 -5<br />
Implemented the create_quantums() function that will create the required number of quantums.<br />
Kmalloc() is used to allocate memory for each quantum.<br />
Filling the memory allocated using kmalloc() with memset() so that it does not contain any garbage.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/01 10:39:39;  author: root;  state: Exp;  lines: +1 -0<br />
memset() function is used to fill the memory allocated for the qset array to &#8221;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/01 10:36:59;  author: root;  state: Exp;  lines: +14 -4<br />
Using kmalloc() memory is allocated to the required number of qsets.<br />
Checking whether it is working fine or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/01 10:26:27;  author: root;  state: Exp;  lines: +36 -2<br />
Implemented create_scullqset() function.Now checking the number of qsets that needs to created by using the size argument of the chardev_write().After determining the number of qsets that needs to be created create_qset() function is called.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/01 10:07:44;  author: root;  state: Exp;  lines: +2 -1<br />
memset() function is used to fill the memory allocated using kmalloc() with &#8221; .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/01 10:04:21;  author: root;  state: Exp;  lines: +10 -0<br />
Allocating memory for 1 scullqset to check whether the create_scullqset() function is working properly or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/01 09:56:22;  author: root;  state: Exp;  lines: +22 -2<br />
After finding out the number of scullqsets,create_scullqset() function is called to create the specified number of scullqsets.<br />
Checking whether the function calling is taking place or not&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/01 09:47:56;  author: root;  state: Exp;  lines: +19 -0<br />
The size argument that specifies the size of the buffer pointed to by ubuff is used to find the number of scullqsets that needs to be created.<br />
After finding out the exact number of scullqsets that needs to be created,the number of scullqsets are printed.<br />
Creating scullqsets&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/01 09:32:34;  author: root;  state: Exp;  lines: +1 -1<br />
Fixed the warning by type-casting size_t to int.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/01 09:28:31;  author: root;  state: Exp;  lines: +6 -1<br />
Checking whether the ubuff pointer is actually pointing to the buffer in the application.Also checking the size field inside the 3rd argument of chardev_write().<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/03/01 09:20:00;  author: root;  state: Exp;  lines: +9 -1<br />
Printing the address inside filep-&gt;private_data to check whether it matches with the address returned by container_of() macro.<br />
A local variable of type Sculldev is declared which will store the address that is present inside filep-&gt;private_data.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 21:33:05;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-showing-how-to-write-data-in-multiple-qset-arrays-from-a-user-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code to show how to perform &#8220;trim&#8221; operation by calling chardev_trim() before the device is opened for writing.</title>
		<link>https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-trim-operation-by-calling-chardev_trim-before-the-device-is-opened-for-writing/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-trim-operation-by-calling-chardev_trim-before-the-device-is-opened-for-writing/#comments</comments>
		<pubDate>Sun, 02 Mar 2014 03:40:37 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8704</guid>
		<description><![CDATA[RCS file: openf.c,v Working file: openf.c head: 1.14 branch: locks: strict root: 1.14 access list: symbolic names: keyword substitution: kv total revisions: 14;    selected revisions: 14 description: The functionality of chardev_open() is implemented here inside this file.Whenever the application calls &#8230; <a href="https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-trim-operation-by-calling-chardev_trim-before-the-device-is-opened-for-writing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: openf.c,v<br />
Working file: openf.c<br />
head: 1.14<br />
branch:<br />
locks: strict<br />
root: 1.14<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 14;    selected revisions: 14<br />
description:<br />
The functionality of chardev_open() is implemented here inside this file.Whenever the application calls the open function,this is always the first operation performed on the device file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14    locked by: root;<br />
date: 2014/03/02 13:54:57;  author: root;  state: Exp;  lines: +0 -8<br />
Status : chardev_trim() is working fine.</p>
<p>The chardev_trim() function is called to perform an operation of truncating the device to a length of 0 when the device is opened for writing.<br />
For checking purposes,chardev_trim() function is called twice.One inside the chardev_open() and one inside the chardev_release().<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/01 20:24:26;  author: root;  state: Exp;  lines: +12 -4<br />
Compilation successfull and chardev_trim() function is working fine.<br />
Issue:Trying the free the memory that is not allocated in case of quantum.<br />
Logical error fixed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/01 19:41:54;  author: root;  state: Exp;  lines: +4 -0<br />
kernel crash taking place inside chardev_trim() function.<br />
Issue inside chardev_trim() function.<br />
Debugging&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/01 19:38:30;  author: root;  state: Exp;  lines: +1 -1<br />
Syntax error fixed.<br />
Issue:Missing semicolon.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/01 19:37:04;  author: root;  state: Exp;  lines: +12 -4<br />
One bug fixed.<br />
Issue:qset_size variable is included using extern.<br />
Debugging&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/01 13:09:52;  author: root;  state: Exp;  lines: +49 -3<br />
Implementing chardev_trim() function.Inside this function,firstly certain checks are made to make sure that Sculldec , scullqset , qset and quantums exist or not.<br />
If any of such things do not exist an error message is reported.Now performing trimming&#8230;&#8230;&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/01 12:08:22;  author: root;  state: Exp;  lines: +23 -1<br />
Two printk statements are added inside the chardev_trim() function to mark its beginning and end.<br />
Checking&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/01 11:57:45;  author: root;  state: Exp;  lines: +5 -0<br />
O_ACCMODE is a macro that stands for a mask that can be bitwise-ANDed with the file status flag value to produce a value representing the file access mode.The mode will be O_WRONLY,O_RDONLY or O_RDWR.<br />
The O_ACCMODE macro is used inside the chardev_open() function to find out the file access mode.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/01 08:45:54;  author: root;  state: Exp;  lines: +5 -1<br />
Printing the address stored inside the lsculldev to check whether it matches with the filep-&gt;private data address printed inside the chardev_release() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/01 08:33:40;  author: root;  state: Exp;  lines: +1 -0<br />
Once the Sculldev structure is found by the container_of() macro,a pointer to the scull is stored in the private_data field of the file structure for easier access    .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/01 08:25:52;  author: root;  state: Exp;  lines: +11 -4<br />
A local variable of type struct Sculldev is declared.<br />
Used container_of() inside the open function.This macro has 3 arguments:<br />
1.A pointer to a field named container_field.<br />
2.This container field within a structure of type container_type,and<br />
3.ccontainer field.<br />
On success it returns a pointer to the containing structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/28 18:51:08;  author: root;  state: Exp;  lines: +2 -0<br />
Included the prototype of chardev_open() using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/28 18:42:56;  author: root;  state: Exp;  lines: +15 -0<br />
Two printk statements are used to test that whether the open function is actually begin and ended.\<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 18:33:28;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: initial.c,v<br />
Working file: initial.c<br />
head: 1.13<br />
branch:<br />
locks: strict<br />
root: 1.13<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 13;    selected revisions: 13<br />
description:<br />
File containing the module&#8217;s initialization function that is called at module insertion time.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13    locked by: root;<br />
date: 2014/02/28 18:56:45;  author: root;  state: Exp;  lines: +1 -1<br />
Fixed the warning by giving void as an argument inside the initialize_parameters() function.<br />
Compilation is successfull.<br />
Checking the functionality by calling application&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/02/28 17:59:59;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&#8221;file_opr.h&#8221; is added to include the file_operations structure.The file_operations structure is used to access the driver&#8217;s functions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/02/28 17:49:26;  author: root;  state: Exp;  lines: +15 -4<br />
After a device number range has been obtained,the device needs to be activated by adding it to the character device database.This requires initializing an instance of cdev_init() followed by a call to cdev_add().cdev_add() tells te kernel about the cdev data structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/02/28 17:16:31;  author: root;  state: Exp;  lines: +16 -0<br />
Both the major and minor numbers are initialized to 0 inside the initialize_parameters() function.Macros like MAJOR() and MINOR() are used to extract the major and minor number from dev type variable.Another macro called MKDEV is used to create the device number.<br />
Checking&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/02/28 16:50:22;  author: root;  state: Exp;  lines: +25 -0<br />
From the initialization function,another function is called to initialize the parameters such as device size, quantum_size ,qset_size and data_size.</p>
<p>Status:The parameters are initialized successfully.<br />
Now before the kernel calls the device&#8217;s operations,a cdev structure must be initialized with cdev_init() and the kernel is being told about the initialization with cdev_add().Implementing this task&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/02/28 15:46:09;  author: root;  state: Exp;  lines: +1 -1<br />
Inside the alloc_chrdev_region(),the fourth argument is changed from DEVICE_NAME to DRIVER_NAME.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/28 15:32:31;  author: root;  state: Exp;  lines: +1 -0<br />
memset() is used to fill the memory allocated using kmalloc() function with &#8221;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/28 15:26:38;  author: root;  state: Exp;  lines: +12 -1<br />
kmalloc() function is used to allocate memory.kmalloc() function takes two arguments:<br />
1.size ,and<br />
2.set of flags.<br />
On success,kmalloc returns a pointer to the allocated memory otherwise it returns NULL.<br />
In the flag field,GFP_KERNEL is used.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 20:12:29;  author: root;  state: Exp;  lines: +7 -1<br />
module_param() macro is used.With the help of this macro parameters can be passed to the module while loading it,when using &#8220;insmod&#8221;.<br />
module_param() macro takes three arguments:<br />
1.The name of the variable,<br />
2.The type of the variable,<br />
3.Permissions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 19:58:09;  author: root;  state: Exp;  lines: +1 -1<br />
alloc_chrdev_region() function is used to allocate dynamically a major number.On success,the first parameter of this function stores the first device number.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 19:31:39;  author: root;  state: Exp;  lines: +11 -0<br />
Header file: &#8220;decleration.h&#8221; is added to include all the variable declerations.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:50:37;  author: root;  state: Exp;  lines: +7 -0<br />
module_init() macro is used to define which function is called during module&#8217;s insertion time.<br />
__init token hints to the kernel that the function is used only at the initialization time.<br />
The function specified by the module_init() macro is declared static because it is not meant to be visible outside the file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:49:06;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: closef.c,v<br />
Working file: closef.c<br />
head: 1.3<br />
branch:<br />
locks: strict<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 3;    selected revisions: 3<br />
description:<br />
chardev_release() function live here.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/02 14:08:43;  author: root;  state: Exp;  lines: +9 -1<br />
chardev_trim() function is called to truncate the device to a length 0 and also it is called here to check whether trimming is working properly or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/28 20:37:55;  author: root;  state: Exp;  lines: +2 -2<br />
chardev_release() function is called when the application calls close() system call.<br />
Two printk statements are used as debug statements to find out whether this function is called or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 20:37:08;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: header.h,v<br />
Working file: header.h<br />
head: 1.17<br />
branch:<br />
locks: strict<br />
root: 1.17<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 17;    selected revisions: 17<br />
description:<br />
Base header file that includes the definitions of all the macros,structures and contains the necessary header files required by the module code.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.17    locked by: root;<br />
date: 2014/03/01 11:21:47;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;asm/uaccess.h&gt; is added to support copy_from_user() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.16<br />
date: 2014/02/28 17:13:48;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/types.h&gt; is added to support dev_t type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/02/28 16:58:15;  author: root;  state: Exp;  lines: +6 -0<br />
Two macros are defined called MAJOR_NO and MINOR_NO.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/02/28 15:44:56;  author: root;  state: Exp;  lines: +2 -2<br />
The macro DEVICE_NAME is changed to DRIVER_NAME and the header file:&lt;string.h&gt; is removed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/02/28 15:41:31;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/cdev.h&gt; is added to support a cdev structure.The cdev structure is used to register the driver with the kernel.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/02/28 15:33:59;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;string.h&gt; is added to support memset() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/02/28 15:18:15;  author: root;  state: Exp;  lines: +16 -0<br />
Four macros are defined namely:DEVICE_SIZE , DATA_SIZE , QUANTUM and QSET.<br />
These macros are used to initialize the fields inside the Scull_Dev structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/02/28 15:10:35;  author: root;  state: Exp;  lines: +16 -0<br />
Two structures are defined of type Sculldev and Scullqset.Sculldev is a structure that is used to hold device information.Scullqset is a structure that holds a pointer to the qset array and another pointer to a structure of Scullqset type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/02/27 21:07:42;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/slab.h&gt; is added to support kmalloc() and kfree() functions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/02/27 20:02:53;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/moduleparam.h&gt; is added to support the module_param() macro.With the help of this macro parameters can be passed to a module while loading it.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/27 19:28:38;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEVICE_NAME is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/27 19:20:01;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/fs.h&gt; is added to the base header file to support various functions like alloc_chrdev_region(),unregister_chrdev_region(),etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 18:44:36;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEBUG is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 18:41:13;  author: root;  state: Exp;  lines: +2 -0<br />
A special macro called MODULE_LICENSE is used to tell the kernel that the module bears a free license without such a decleration the kernel complains.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 18:38:11;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/module.h&gt; is added to the base header file to provide support for a great many number of macros like:MODULE_LICENSE , MODULE_AUTHOR,etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:36:07;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/init.h&gt; is added to the base header file to provide support for module_init() and module_exit() macros.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:35:18;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-to-show-how-to-perform-trim-operation-by-calling-chardev_trim-before-the-device-is-opened-for-writing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code to show how to write data in a single quantum using copy_from_user() function.</title>
		<link>https://www.emblogic.com/blog/03/module-code-to-show-how-to-write-data-in-a-single-quantum-using-copy_from_user-function/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-to-show-how-to-write-data-in-a-single-quantum-using-copy_from_user-function/#comments</comments>
		<pubDate>Sat, 01 Mar 2014 06:05:14 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8682</guid>
		<description><![CDATA[RCS file: writef.c,v Working file: writef.c head: 1.15 branch: locks: strict root: 1.15 access list: symbolic names: keyword substitution: kv total revisions: 15;    selected revisions: 15 description: chardev_write() function reside here. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- revision 1.15    locked by: root; date: 2014/03/01 11:19:07;  &#8230; <a href="https://www.emblogic.com/blog/03/module-code-to-show-how-to-write-data-in-a-single-quantum-using-copy_from_user-function/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: writef.c,v<br />
Working file: writef.c<br />
head: 1.15<br />
branch:<br />
locks: strict<br />
root: 1.15<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 15;    selected revisions: 15<br />
description:<br />
chardev_write() function reside here.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15    locked by: root;<br />
date: 2014/03/01 11:19:07;  author: root;  state: Exp;  lines: +5 -0<br />
One printk statement is added to test whether the data is actually copied into the kernel buffer or not.<br />
Testing&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/03/01 11:13:18;  author: root;  state: Exp;  lines: +15 -7<br />
The copy_from_user() function is used to copy a block of data from user space into the kernel buffer.copy_from_user() function contains 3 arguments:<br />
1.A destination buffer,<br />
2.A source buffer,and<br />
3.length in bytes.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/03/01 11:06:21;  author: root;  state: Exp;  lines: +2 -1<br />
Done memset().<br />
Testing the code&#8230;..<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/03/01 11:01:16;  author: root;  state: Exp;  lines: +54 -5<br />
Implemented the create_quantums() function that will create the required number of quantums.<br />
Kmalloc() is used to allocate memory for each quantum.<br />
Filling the memory allocated using kmalloc() with memset() so that it does not contain any garbage.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/03/01 10:39:39;  author: root;  state: Exp;  lines: +1 -0<br />
memset() function is used to fill the memory allocated for the qset array to &#8221;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/03/01 10:36:59;  author: root;  state: Exp;  lines: +14 -4<br />
Using kmalloc() memory is allocated to the required number of qsets.<br />
Checking whether it is working fine or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/03/01 10:26:27;  author: root;  state: Exp;  lines: +36 -2<br />
Implemented create_scullqset() function.Now checking the number of qsets that needs to created by using the size argument of the chardev_write().After determining the number of qsets that needs to be created create_qset() function is called.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/03/01 10:07:44;  author: root;  state: Exp;  lines: +2 -1<br />
memset() function is used to fill the memory allocated using kmalloc() with &#8221; .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/03/01 10:04:21;  author: root;  state: Exp;  lines: +10 -0<br />
Allocating memory for 1 scullqset to check whether the create_scullqset() function is working properly or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/03/01 09:56:22;  author: root;  state: Exp;  lines: +22 -2<br />
After finding out the number of scullqsets,create_scullqset() function is called to create the specified number of scullqsets.<br />
Checking whether the function calling is taking place or not&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/01 09:47:56;  author: root;  state: Exp;  lines: +19 -0<br />
The size argument that specifies the size of the buffer pointed to by ubuff is used to find the number of scullqsets that needs to be created.<br />
After finding out the exact number of scullqsets that needs to be created,the number of scullqsets are printed.<br />
Creating scullqsets&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/01 09:32:34;  author: root;  state: Exp;  lines: +1 -1<br />
Fixed the warning by type-casting size_t to int.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/03/01 09:28:31;  author: root;  state: Exp;  lines: +6 -1<br />
Checking whether the ubuff pointer is actually pointing to the buffer in the application.Also checking the size field inside the 3rd argument of chardev_write().<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/03/01 09:20:00;  author: root;  state: Exp;  lines: +9 -1<br />
Printing the address inside filep-&gt;private_data to check whether it matches with the address returned by container_of() macro.<br />
A local variable of type Sculldev is declared which will store the address that is present inside filep-&gt;private_data.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 21:33:05;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: openf.c,v<br />
Working file: openf.c<br />
head: 1.6<br />
branch:<br />
locks: strict<br />
root: 1.6<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 6;    selected revisions: 6<br />
description:<br />
The functionality of chardev_open() is implemented here inside this file.Whenever the application calls the open function,this is always the first operation performed on the device file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6    locked by: root;<br />
date: 2014/03/01 08:45:54;  author: root;  state: Exp;  lines: +5 -1<br />
Printing the address stored inside the lsculldev to check whether it matches with the filep-&gt;private data address printed inside the chardev_release() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/01 08:33:40;  author: root;  state: Exp;  lines: +1 -0<br />
Once the Sculldev structure is found by the container_of() macro,a pointer to the scull is stored in the private_data field of the file structure for easier access    .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/01 08:25:52;  author: root;  state: Exp;  lines: +11 -4<br />
A local variable of type struct Sculldev is declared.<br />
Used container_of() inside the open function.This macro has 3 arguments:<br />
1.A pointer to a field named container_field.<br />
2.This container field within a structure of type container_type,and<br />
3.ccontainer field.<br />
On success it returns a pointer to the containing structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/28 18:51:08;  author: root;  state: Exp;  lines: +2 -0<br />
Included the prototype of chardev_open() using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/28 18:42:56;  author: root;  state: Exp;  lines: +15 -0<br />
Two printk statements are used to test that whether the open function is actually begin and ended.\<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 18:33:28;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: header.h,v<br />
Working file: header.h<br />
head: 1.17<br />
branch:<br />
locks: strict<br />
root: 1.17<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 17;    selected revisions: 17<br />
description:<br />
Base header file that includes the definitions of all the macros,structures and contains the necessary header files required by the module code.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.17    locked by: root;<br />
date: 2014/03/01 11:21:47;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;asm/uaccess.h&gt; is added to support copy_from_user() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.16<br />
date: 2014/02/28 17:13:48;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/types.h&gt; is added to support dev_t type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/02/28 16:58:15;  author: root;  state: Exp;  lines: +6 -0<br />
Two macros are defined called MAJOR_NO and MINOR_NO.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/02/28 15:44:56;  author: root;  state: Exp;  lines: +2 -2<br />
The macro DEVICE_NAME is changed to DRIVER_NAME and the header file:&lt;string.h&gt; is removed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/02/28 15:41:31;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/cdev.h&gt; is added to support a cdev structure.The cdev structure is used to register the driver with the kernel.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/02/28 15:33:59;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;string.h&gt; is added to support memset() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/02/28 15:18:15;  author: root;  state: Exp;  lines: +16 -0<br />
Four macros are defined namely:DEVICE_SIZE , DATA_SIZE , QUANTUM and QSET.<br />
These macros are used to initialize the fields inside the Scull_Dev structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/02/28 15:10:35;  author: root;  state: Exp;  lines: +16 -0<br />
Two structures are defined of type Sculldev and Scullqset.Sculldev is a structure that is used to hold device information.Scullqset is a structure that holds a pointer to the qset array and another pointer to a structure of Scullqset type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/02/27 21:07:42;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/slab.h&gt; is added to support kmalloc() and kfree() functions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/02/27 20:02:53;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/moduleparam.h&gt; is added to support the module_param() macro.With the help of this macro parameters can be passed to a module while loading it.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/27 19:28:38;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEVICE_NAME is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/27 19:20:01;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/fs.h&gt; is added to the base header file to support various functions like alloc_chrdev_region(),unregister_chrdev_region(),etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 18:44:36;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEBUG is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 18:41:13;  author: root;  state: Exp;  lines: +2 -0<br />
A special macro called MODULE_LICENSE is used to tell the kernel that the module bears a free license without such a decleration the kernel complains.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 18:38:11;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/module.h&gt; is added to the base header file to provide support for a great many number of macros like:MODULE_LICENSE , MODULE_AUTHOR,etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:36:07;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/init.h&gt; is added to the base header file to provide support for module_init() and module_exit() macros.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:35:18;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: closef.c,v<br />
Working file: closef.c<br />
head: 1.2<br />
branch:<br />
locks: strict<br />
root: 1.2<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 2;    selected revisions: 2<br />
description:<br />
chardev_release() function live here.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2    locked by: root;<br />
date: 2014/02/28 20:37:55;  author: root;  state: Exp;  lines: +2 -2<br />
chardev_release() function is called when the application calls close() system call.<br />
Two printk statements are used as debug statements to find out whether this function is called or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 20:37:08;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: cleanup.c,v<br />
Working file: cleanup.c<br />
head: 1.6<br />
branch:<br />
locks: strict<br />
root: 1.6<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 6;    selected revisions: 6<br />
description:<br />
File that contains the cleanup function which returns all the resources back to the system.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6    locked by: root;<br />
date: 2014/02/28 15:35:01;  author: root;  state: Exp;  lines: +1 -0<br />
kfree() function is used for freeing the memory.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 20:15:39;  author: root;  state: Exp;  lines: +3 -1<br />
A variable of type int representing the number of devices is included here using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 19:36:03;  author: root;  state: Exp;  lines: +1 -0<br />
A variable dev of type dev_t storing the device number is included here using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 19:33:49;  author: root;  state: Exp;  lines: +3 -1<br />
Called unregister_chrdev_region() which is having 2 arguments: device number and the total number of device numbers to unregister.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:58:02;  author: root;  state: Exp;  lines: +14 -0<br />
module_exit() macro is used to define which function is to be called at module removal time.\<br />
The function specified by the module_exit() macro is declared static because it is not meant to be visible outside the file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:55:42;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-to-show-how-to-write-data-in-a-single-quantum-using-copy_from_user-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Module code to show how to use container_of() macro inside driver&#8217;s open function and storing the return value of container_of() inside filep-&gt;private_data.</title>
		<link>https://www.emblogic.com/blog/03/module-code-to-show-how-to-use-container_of-macro-inside-drivers-open-function-and-storing-the-return-value-of-container_of-inside-filep-private_data/</link>
		<comments>https://www.emblogic.com/blog/03/module-code-to-show-how-to-use-container_of-macro-inside-drivers-open-function-and-storing-the-return-value-of-container_of-inside-filep-private_data/#comments</comments>
		<pubDate>Sat, 01 Mar 2014 03:36:53 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8680</guid>
		<description><![CDATA[RCS file: openf.c,v Working file: openf.c head: 1.6 branch: locks: strict root: 1.6 access list: symbolic names: keyword substitution: kv total revisions: 6;    selected revisions: 6 description: The functionality of chardev_open() is implemented here inside this file.Whenever the application calls &#8230; <a href="https://www.emblogic.com/blog/03/module-code-to-show-how-to-use-container_of-macro-inside-drivers-open-function-and-storing-the-return-value-of-container_of-inside-filep-private_data/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: openf.c,v<br />
Working file: openf.c<br />
head: 1.6<br />
branch:<br />
locks: strict<br />
root: 1.6<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 6;    selected revisions: 6<br />
description:<br />
The functionality of chardev_open() is implemented here inside this file.Whenever the application calls the open function,this is always the first operation performed on the device file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6    locked by: root;<br />
date: 2014/03/01 08:45:54;  author: root;  state: Exp;  lines: +5 -1<br />
Printing the address stored inside the lsculldev to check whether it matches with the filep-&gt;private data address printed inside the chardev_release() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/03/01 08:33:40;  author: root;  state: Exp;  lines: +1 -0<br />
Once the Sculldev structure is found by the container_of() macro,a pointer to the scull is stored in the private_data field of the file structure for easier access    .<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/03/01 08:25:52;  author: root;  state: Exp;  lines: +11 -4<br />
A local variable of type struct Sculldev is declared.<br />
Used container_of() inside the open function.This macro has 3 arguments:<br />
1.A pointer to a field named container_field.<br />
2.This container field within a structure of type container_type,and<br />
3.ccontainer field.<br />
On success it returns a pointer to the containing structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/28 18:51:08;  author: root;  state: Exp;  lines: +2 -0<br />
Included the prototype of chardev_open() using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/28 18:42:56;  author: root;  state: Exp;  lines: +15 -0<br />
Two printk statements are used to test that whether the open function is actually begin and ended.\<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 18:33:28;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: cleanup.c,v<br />
Working file: cleanup.c<br />
head: 1.6<br />
branch:<br />
locks: strict<br />
root: 1.6<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 6;    selected revisions: 6<br />
description:<br />
File that contains the cleanup function which returns all the resources back to the system.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6    locked by: root;<br />
date: 2014/02/28 15:35:01;  author: root;  state: Exp;  lines: +1 -0<br />
kfree() function is used for freeing the memory.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 20:15:39;  author: root;  state: Exp;  lines: +3 -1<br />
A variable of type int representing the number of devices is included here using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 19:36:03;  author: root;  state: Exp;  lines: +1 -0<br />
A variable dev of type dev_t storing the device number is included here using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 19:33:49;  author: root;  state: Exp;  lines: +3 -1<br />
Called unregister_chrdev_region() which is having 2 arguments: device number and the total number of device numbers to unregister.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:58:02;  author: root;  state: Exp;  lines: +14 -0<br />
module_exit() macro is used to define which function is to be called at module removal time.\<br />
The function specified by the module_exit() macro is declared static because it is not meant to be visible outside the file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:55:42;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: closef.c,v<br />
Working file: closef.c<br />
head: 1.3<br />
branch:<br />
locks: strict<br />
root: 1.3<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 3;    selected revisions: 3<br />
description:<br />
chardev_release() function live here.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3    locked by: root;<br />
date: 2014/03/01 08:42:45;  author: root;  state: Exp;  lines: +5 -1<br />
Making a check by printing the address stored inside the filep-&gt;private_data matches with the lsculldev value returned by the container_of() macro.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/28 20:37:55;  author: root;  state: Exp;  lines: +2 -2<br />
chardev_release() function is called when the application calls close() system call.<br />
Two printk statements are used as debug statements to find out whether this function is called or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 20:37:08;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: header.h,v<br />
Working file: header.h<br />
head: 1.16<br />
branch:<br />
locks: strict<br />
root: 1.16<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 16;    selected revisions: 16<br />
description:<br />
Base header file that includes the definitions of all the macros,structures and contains the necessary header files required by the module code.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.16    locked by: root;<br />
date: 2014/02/28 17:13:48;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/types.h&gt; is added to support dev_t type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/02/28 16:58:15;  author: root;  state: Exp;  lines: +6 -0<br />
Two macros are defined called MAJOR_NO and MINOR_NO.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/02/28 15:44:56;  author: root;  state: Exp;  lines: +2 -2<br />
The macro DEVICE_NAME is changed to DRIVER_NAME and the header file:&lt;string.h&gt; is removed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/02/28 15:41:31;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/cdev.h&gt; is added to support a cdev structure.The cdev structure is used to register the driver with the kernel.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/02/28 15:33:59;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;string.h&gt; is added to support memset() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/02/28 15:18:15;  author: root;  state: Exp;  lines: +16 -0<br />
Four macros are defined namely:DEVICE_SIZE , DATA_SIZE , QUANTUM and QSET.<br />
These macros are used to initialize the fields inside the Scull_Dev structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/02/28 15:10:35;  author: root;  state: Exp;  lines: +16 -0<br />
Two structures are defined of type Sculldev and Scullqset.Sculldev is a structure that is used to hold device information.Scullqset is a structure that holds a pointer to the qset array and another pointer to a structure of Scullqset type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/02/27 21:07:42;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/slab.h&gt; is added to support kmalloc() and kfree() functions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/02/27 20:02:53;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/moduleparam.h&gt; is added to support the module_param() macro.With the help of this macro parameters can be passed to a module while loading it.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/27 19:28:38;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEVICE_NAME is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/27 19:20:01;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/fs.h&gt; is added to the base header file to support various functions like alloc_chrdev_region(),unregister_chrdev_region(),etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 18:44:36;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEBUG is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 18:41:13;  author: root;  state: Exp;  lines: +2 -0<br />
A special macro called MODULE_LICENSE is used to tell the kernel that the module bears a free license without such a decleration the kernel complains.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 18:38:11;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/module.h&gt; is added to the base header file to provide support for a great many number of macros like:MODULE_LICENSE , MODULE_AUTHOR,etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:36:07;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/init.h&gt; is added to the base header file to provide support for module_init() and module_exit() macros.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:35:18;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/03/module-code-to-show-how-to-use-container_of-macro-inside-drivers-open-function-and-storing-the-return-value-of-container_of-inside-filep-private_data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>module code to show how to perform an open and release operation, when an application issues open() and close() system call.</title>
		<link>https://www.emblogic.com/blog/02/module-code-to-show-how-to-perform-an-open-and-release-operation-when-an-application-issues-open-and-close-system-call/</link>
		<comments>https://www.emblogic.com/blog/02/module-code-to-show-how-to-perform-an-open-and-release-operation-when-an-application-issues-open-and-close-system-call/#comments</comments>
		<pubDate>Fri, 28 Feb 2014 15:30:08 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8673</guid>
		<description><![CDATA[RCS file: header.h,v Working file: header.h head: 1.16 branch: locks: strict root: 1.16 access list: symbolic names: keyword substitution: kv total revisions: 16;    selected revisions: 16 description: Base header file that includes the definitions of all the macros,structures and contains &#8230; <a href="https://www.emblogic.com/blog/02/module-code-to-show-how-to-perform-an-open-and-release-operation-when-an-application-issues-open-and-close-system-call/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: header.h,v<br />
Working file: header.h<br />
head: 1.16<br />
branch:<br />
locks: strict<br />
root: 1.16<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 16;    selected revisions: 16<br />
description:<br />
Base header file that includes the definitions of all the macros,structures and contains the necessary header files required by the module code.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.16    locked by: root;<br />
date: 2014/02/28 17:13:48;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/types.h&gt; is added to support dev_t type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/02/28 16:58:15;  author: root;  state: Exp;  lines: +6 -0<br />
Two macros are defined called MAJOR_NO and MINOR_NO.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/02/28 15:44:56;  author: root;  state: Exp;  lines: +2 -2<br />
The macro DEVICE_NAME is changed to DRIVER_NAME and the header file:&lt;string.h&gt; is removed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/02/28 15:41:31;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/cdev.h&gt; is added to support a cdev structure.The cdev structure is used to register the driver with the kernel.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/02/28 15:33:59;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;string.h&gt; is added to support memset() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/02/28 15:18:15;  author: root;  state: Exp;  lines: +16 -0<br />
Four macros are defined namely:DEVICE_SIZE , DATA_SIZE , QUANTUM and QSET.<br />
These macros are used to initialize the fields inside the Scull_Dev structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/02/28 15:10:35;  author: root;  state: Exp;  lines: +16 -0<br />
Two structures are defined of type Sculldev and Scullqset.Sculldev is a structure that is used to hold device information.Scullqset is a structure that holds a pointer to the qset array and another pointer to a structure of Scullqset type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/02/27 21:07:42;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/slab.h&gt; is added to support kmalloc() and kfree() functions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/02/27 20:02:53;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/moduleparam.h&gt; is added to support the module_param() macro.With the help of this macro parameters can be passed to a module while loading it.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/27 19:28:38;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEVICE_NAME is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/27 19:20:01;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/fs.h&gt; is added to the base header file to support various functions like alloc_chrdev_region(),unregister_chrdev_region(),etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 18:44:36;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEBUG is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 18:41:13;  author: root;  state: Exp;  lines: +2 -0<br />
A special macro called MODULE_LICENSE is used to tell the kernel that the module bears a free license without such a decleration the kernel complains.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 18:38:11;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/module.h&gt; is added to the base header file to provide support for a great many number of macros like:MODULE_LICENSE , MODULE_AUTHOR,etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:36:07;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/init.h&gt; is added to the base header file to provide support for module_init() and module_exit() macros.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:35:18;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: initial.c,v<br />
Working file: initial.c<br />
head: 1.13<br />
branch:<br />
locks: strict<br />
root: 1.13<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 13;    selected revisions: 13<br />
description:<br />
File containing the module&#8217;s initialization function that is called at module insertion time.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13    locked by: root;<br />
date: 2014/02/28 18:56:45;  author: root;  state: Exp;  lines: +1 -1<br />
Fixed the warning by giving void as an argument inside the initialize_parameters() function.<br />
Compilation is successfull.<br />
Checking the functionality by calling application&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/02/28 17:59:59;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&#8221;file_opr.h&#8221; is added to include the file_operations structure.The file_operations structure is used to access the driver&#8217;s functions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/02/28 17:49:26;  author: root;  state: Exp;  lines: +15 -4<br />
After a device number range has been obtained,the device needs to be activated by adding it to the character device database.This requires initializing an instance of cdev_init() followed by a call to cdev_add().cdev_add() tells te kernel about the cdev data structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/02/28 17:16:31;  author: root;  state: Exp;  lines: +16 -0<br />
Both the major and minor numbers are initialized to 0 inside the initialize_parameters() function.Macros like MAJOR() and MINOR() are used to extract the major and minor number from dev type variable.Another macro called MKDEV is used to create the device number.<br />
Checking&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/02/28 16:50:22;  author: root;  state: Exp;  lines: +25 -0<br />
From the initialization function,another function is called to initialize the parameters such as device size, quantum_size ,qset_size and data_size.</p>
<p>Status:The parameters are initialized successfully.<br />
Now before the kernel calls the device&#8217;s operations,a cdev structure must be initialized with cdev_init() and the kernel is being told about the initialization with cdev_add().Implementing this task&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/02/28 15:46:09;  author: root;  state: Exp;  lines: +1 -1<br />
Inside the alloc_chrdev_region(),the fourth argument is changed from DEVICE_NAME to DRIVER_NAME.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/28 15:32:31;  author: root;  state: Exp;  lines: +1 -0<br />
memset() is used to fill the memory allocated using kmalloc() function with &#8221;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/28 15:26:38;  author: root;  state: Exp;  lines: +12 -1<br />
kmalloc() function is used to allocate memory.kmalloc() function takes two arguments:<br />
1.size ,and<br />
2.set of flags.<br />
On success,kmalloc returns a pointer to the allocated memory otherwise it returns NULL.<br />
In the flag field,GFP_KERNEL is used.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 20:12:29;  author: root;  state: Exp;  lines: +7 -1<br />
module_param() macro is used.With the help of this macro parameters can be passed to the module while loading it,when using &#8220;insmod&#8221;.<br />
module_param() macro takes three arguments:<br />
1.The name of the variable,<br />
2.The type of the variable,<br />
3.Permissions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 19:58:09;  author: root;  state: Exp;  lines: +1 -1<br />
alloc_chrdev_region() function is used to allocate dynamically a major number.On success,the first parameter of this function stores the first device number.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 19:31:39;  author: root;  state: Exp;  lines: +11 -0<br />
Header file: &#8220;decleration.h&#8221; is added to include all the variable declerations.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:50:37;  author: root;  state: Exp;  lines: +7 -0<br />
module_init() macro is used to define which function is called during module&#8217;s insertion time.<br />
__init token hints to the kernel that the function is used only at the initialization time.<br />
The function specified by the module_init() macro is declared static because it is not meant to be visible outside the file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:49:06;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: cleanup.c,v<br />
Working file: cleanup.c<br />
head: 1.6<br />
branch:<br />
locks: strict<br />
root: 1.6<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 6;    selected revisions: 6<br />
description:<br />
File that contains the cleanup function which returns all the resources back to the system.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6    locked by: root;<br />
date: 2014/02/28 15:35:01;  author: root;  state: Exp;  lines: +1 -0<br />
kfree() function is used for freeing the memory.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 20:15:39;  author: root;  state: Exp;  lines: +3 -1<br />
A variable of type int representing the number of devices is included here using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 19:36:03;  author: root;  state: Exp;  lines: +1 -0<br />
A variable dev of type dev_t storing the device number is included here using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 19:33:49;  author: root;  state: Exp;  lines: +3 -1<br />
Called unregister_chrdev_region() which is having 2 arguments: device number and the total number of device numbers to unregister.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:58:02;  author: root;  state: Exp;  lines: +14 -0<br />
module_exit() macro is used to define which function is to be called at module removal time.\<br />
The function specified by the module_exit() macro is declared static because it is not meant to be visible outside the file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:55:42;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: closef.c,v<br />
Working file: closef.c<br />
head: 1.2<br />
branch:<br />
locks: strict<br />
root: 1.2<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 2;    selected revisions: 2<br />
description:<br />
chardev_release() function live here.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2    locked by: root;<br />
date: 2014/02/28 20:37:55;  author: root;  state: Exp;  lines: +2 -2<br />
chardev_release() function is called when the application calls close() system call.<br />
Two printk statements are used as debug statements to find out whether this function is called or not.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 20:37:08;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: decleration.h,v<br />
Working file: decleration.h<br />
head: 1.8<br />
branch:<br />
locks: strict<br />
root: 1.8<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 8;    selected revisions: 8<br />
description:<br />
All the variable declerations are done inside this header file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8    locked by: root;<br />
date: 2014/02/28 20:28:24;  author: root;  state: Exp;  lines: +1 -0<br />
Gave prototype for chardev_release() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/28 18:48:17;  author: root;  state: Exp;  lines: +2 -0<br />
Gave prototype of chardev_open() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/28 17:05:32;  author: root;  state: Exp;  lines: +1 -0<br />
A variable of type dev_t is declared that is used to store the updated device number obtained from mkdev.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/28 16:59:40;  author: root;  state: Exp;  lines: +3 -0<br />
Two variables are declared inside this file that will hold the information about major and minor numbers.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/28 16:39:07;  author: root;  state: Exp;  lines: +4 -0<br />
Variables quantum_size,qset_size,data_size and device_size are declared that will get initialized by the macros defined in header.h.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/28 15:30:46;  author: root;  state: Exp;  lines: +1 -0<br />
A variable of type Sculldev is declared in this file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 20:06:26;  author: root;  state: Exp;  lines: +1 -0<br />
A variable of type int is declared representing the number of devices.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 19:30:54;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: openf.c,v<br />
Working file: openf.c<br />
head: 1.3<br />
branch:<br />
locks: strict<br />
root: 1.3<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 3;    selected revisions: 3<br />
description:<br />
The functionality of chardev_open() is implemented here inside this file.Whenever the application calls the open function,this is always the first operation performed on the device file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3    locked by: root;<br />
date: 2014/02/28 18:51:08;  author: root;  state: Exp;  lines: +2 -0<br />
Included the prototype of chardev_open() using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/28 18:42:56;  author: root;  state: Exp;  lines: +15 -0<br />
Two printk statements are used to test that whether the open function is actually begin and ended.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 18:33:28;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/02/module-code-to-show-how-to-perform-an-open-and-release-operation-when-an-application-issues-open-and-close-system-call/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>module code to show how an open operation is performed on the device file when an application calls &#8221; open() function&#8221;.</title>
		<link>https://www.emblogic.com/blog/02/module-code-to-show-how-an-open-operation-is-performed-on-the-device-file-when-an-application-calls-open-function/</link>
		<comments>https://www.emblogic.com/blog/02/module-code-to-show-how-an-open-operation-is-performed-on-the-device-file-when-an-application-calls-open-function/#comments</comments>
		<pubDate>Fri, 28 Feb 2014 14:46:19 +0000</pubDate>
		<dc:creator><![CDATA[deepak.jain]]></dc:creator>
				<category><![CDATA[Character Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=8669</guid>
		<description><![CDATA[RCS file: header.h,v Working file: header.h head: 1.16 branch: locks: strict root: 1.16 access list: symbolic names: keyword substitution: kv total revisions: 16;    selected revisions: 16 description: Base header file that includes the definitions of all the macros,structures and contains &#8230; <a href="https://www.emblogic.com/blog/02/module-code-to-show-how-an-open-operation-is-performed-on-the-device-file-when-an-application-calls-open-function/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>RCS file: header.h,v<br />
Working file: header.h<br />
head: 1.16<br />
branch:<br />
locks: strict<br />
root: 1.16<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 16;    selected revisions: 16<br />
description:<br />
Base header file that includes the definitions of all the macros,structures and contains the necessary header files required by the module code.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.16    locked by: root;<br />
date: 2014/02/28 17:13:48;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/types.h&gt; is added to support dev_t type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.15<br />
date: 2014/02/28 16:58:15;  author: root;  state: Exp;  lines: +6 -0<br />
Two macros are defined called MAJOR_NO and MINOR_NO.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.14<br />
date: 2014/02/28 15:44:56;  author: root;  state: Exp;  lines: +2 -2<br />
The macro DEVICE_NAME is changed to DRIVER_NAME and the header file:&lt;string.h&gt; is removed.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13<br />
date: 2014/02/28 15:41:31;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/cdev.h&gt; is added to support a cdev structure.The cdev structure is used to register the driver with the kernel.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/02/28 15:33:59;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;string.h&gt; is added to support memset() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/02/28 15:18:15;  author: root;  state: Exp;  lines: +16 -0<br />
Four macros are defined namely:DEVICE_SIZE , DATA_SIZE , QUANTUM and QSET.<br />
These macros are used to initialize the fields inside the Scull_Dev structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/02/28 15:10:35;  author: root;  state: Exp;  lines: +16 -0<br />
Two structures are defined of type Sculldev and Scullqset.Sculldev is a structure that is used to hold device information.Scullqset is a structure that holds a pointer to the qset array and another pointer to a structure of Scullqset type.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/02/27 21:07:42;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/slab.h&gt; is added to support kmalloc() and kfree() functions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/02/27 20:02:53;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/moduleparam.h&gt; is added to support the module_param() macro.With the help of this macro parameters can be passed to a module while loading it.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/27 19:28:38;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEVICE_NAME is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/27 19:20:01;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&lt;linux/fs.h&gt; is added to the base header file to support various functions like alloc_chrdev_region(),unregister_chrdev_region(),etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 18:44:36;  author: root;  state: Exp;  lines: +4 -0<br />
A macro called DEBUG is defined using #define.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 18:41:13;  author: root;  state: Exp;  lines: +2 -0<br />
A special macro called MODULE_LICENSE is used to tell the kernel that the module bears a free license without such a decleration the kernel complains.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 18:38:11;  author: root;  state: Exp;  lines: +1 -1<br />
Header file:&lt;linux/module.h&gt; is added to the base header file to provide support for a great many number of macros like:MODULE_LICENSE , MODULE_AUTHOR,etc.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:36:07;  author: root;  state: Exp;  lines: +2 -0<br />
Header file:&lt;linux/init.h&gt; is added to the base header file to provide support for module_init() and module_exit() macros.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:35:18;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: initial.c,v<br />
Working file: initial.c<br />
head: 1.13<br />
branch:<br />
locks: strict<br />
root: 1.13<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 13;    selected revisions: 13<br />
description:<br />
File containing the module&#8217;s initialization function that is called at module insertion time.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.13    locked by: root;<br />
date: 2014/02/28 18:56:45;  author: root;  state: Exp;  lines: +1 -1<br />
Fixed the warning by giving void as an argument inside the initialize_parameters() function.<br />
Compilation is successfull.<br />
Checking the functionality by calling application&#8230;&#8230;&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.12<br />
date: 2014/02/28 17:59:59;  author: root;  state: Exp;  lines: +1 -0<br />
Header file:&#8221;file_opr.h&#8221; is added to include the file_operations structure.The file_operations structure is used to access the driver&#8217;s functions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.11<br />
date: 2014/02/28 17:49:26;  author: root;  state: Exp;  lines: +15 -4<br />
After a device number range has been obtained,the device needs to be activated by adding it to the character device database.This requires initializing an instance of cdev_init() followed by a call to cdev_add().cdev_add() tells te kernel about the cdev data structure.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.10<br />
date: 2014/02/28 17:16:31;  author: root;  state: Exp;  lines: +16 -0<br />
Both the major and minor numbers are initialized to 0 inside the initialize_parameters() function.Macros like MAJOR() and MINOR() are used to extract the major and minor number from dev type variable.Another macro called MKDEV is used to create the device number.<br />
Checking&#8230;&#8230;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.9<br />
date: 2014/02/28 16:50:22;  author: root;  state: Exp;  lines: +25 -0<br />
From the initialization function,another function is called to initialize the parameters such as device size, quantum_size ,qset_size and data_size.</p>
<p>Status:The parameters are initialized successfully.<br />
Now before the kernel calls the device&#8217;s operations,a cdev structure must be initialized with cdev_init() and the kernel is being told about the initialization with cdev_add().Implementing this task&#8230;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.8<br />
date: 2014/02/28 15:46:09;  author: root;  state: Exp;  lines: +1 -1<br />
Inside the alloc_chrdev_region(),the fourth argument is changed from DEVICE_NAME to DRIVER_NAME.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7<br />
date: 2014/02/28 15:32:31;  author: root;  state: Exp;  lines: +1 -0<br />
memset() is used to fill the memory allocated using kmalloc() function with &#8221;.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/28 15:26:38;  author: root;  state: Exp;  lines: +12 -1<br />
kmalloc() function is used to allocate memory.kmalloc() function takes two arguments:<br />
1.size ,and<br />
2.set of flags.<br />
On success,kmalloc returns a pointer to the allocated memory otherwise it returns NULL.<br />
In the flag field,GFP_KERNEL is used.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 20:12:29;  author: root;  state: Exp;  lines: +7 -1<br />
module_param() macro is used.With the help of this macro parameters can be passed to the module while loading it,when using &#8220;insmod&#8221;.<br />
module_param() macro takes three arguments:<br />
1.The name of the variable,<br />
2.The type of the variable,<br />
3.Permissions.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 19:58:09;  author: root;  state: Exp;  lines: +1 -1<br />
alloc_chrdev_region() function is used to allocate dynamically a major number.On success,the first parameter of this function stores the first device number.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 19:31:39;  author: root;  state: Exp;  lines: +11 -0<br />
Header file: &#8220;decleration.h&#8221; is added to include all the variable declerations.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:50:37;  author: root;  state: Exp;  lines: +7 -0<br />
module_init() macro is used to define which function is called during module&#8217;s insertion time.<br />
__init token hints to the kernel that the function is used only at the initialization time.<br />
The function specified by the module_init() macro is declared static because it is not meant to be visible outside the file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:49:06;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: cleanup.c,v<br />
Working file: cleanup.c<br />
head: 1.6<br />
branch:<br />
locks: strict<br />
root: 1.6<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 6;    selected revisions: 6<br />
description:<br />
File that contains the cleanup function which returns all the resources back to the system.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6    locked by: root;<br />
date: 2014/02/28 15:35:01;  author: root;  state: Exp;  lines: +1 -0<br />
kfree() function is used for freeing the memory.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/27 20:15:39;  author: root;  state: Exp;  lines: +3 -1<br />
A variable of type int representing the number of devices is included here using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/27 19:36:03;  author: root;  state: Exp;  lines: +1 -0<br />
A variable dev of type dev_t storing the device number is included here using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/27 19:33:49;  author: root;  state: Exp;  lines: +3 -1<br />
Called unregister_chrdev_region() which is having 2 arguments: device number and the total number of device numbers to unregister.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 18:58:02;  author: root;  state: Exp;  lines: +14 -0<br />
module_exit() macro is used to define which function is to be called at module removal time.\<br />
The function specified by the module_exit() macro is declared static because it is not meant to be visible outside the file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 18:55:42;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: openf.c,v<br />
Working file: openf.c<br />
head: 1.3<br />
branch:<br />
locks: strict<br />
root: 1.3<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 3;    selected revisions: 3<br />
description:<br />
The functionality of chardev_open() is implemented here inside this file.Whenever the application calls the open function,this is always the first operation performed on the device file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3    locked by: root;<br />
date: 2014/02/28 18:51:08;  author: root;  state: Exp;  lines: +2 -0<br />
Included the prototype of chardev_open() using extern.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/28 18:42:56;  author: root;  state: Exp;  lines: +15 -0<br />
Two printk statements are used to test that whether the open function is actually begin and ended.\<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/28 18:33:28;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================<br />
RCS file: decleration.h,v<br />
Working file: decleration.h<br />
head: 1.7<br />
branch:<br />
locks: strict<br />
root: 1.7<br />
access list:<br />
symbolic names:<br />
keyword substitution: kv<br />
total revisions: 7;    selected revisions: 7<br />
description:<br />
All the variable declerations are done inside this header file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.7    locked by: root;<br />
date: 2014/02/28 18:48:17;  author: root;  state: Exp;  lines: +2 -0<br />
Gave prototype of chardev_open() function.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.6<br />
date: 2014/02/28 17:05:32;  author: root;  state: Exp;  lines: +1 -0<br />
A variable of type dev_t is declared that is used to store the updated device number obtained from mkdev.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.5<br />
date: 2014/02/28 16:59:40;  author: root;  state: Exp;  lines: +3 -0<br />
Two variables are declared inside this file that will hold the information about major and minor numbers.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.4<br />
date: 2014/02/28 16:39:07;  author: root;  state: Exp;  lines: +4 -0<br />
Variables quantum_size,qset_size,data_size and device_size are declared that will get initialized by the macros defined in header.h.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.3<br />
date: 2014/02/28 15:30:46;  author: root;  state: Exp;  lines: +1 -0<br />
A variable of type Sculldev is declared in this file.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.2<br />
date: 2014/02/27 20:06:26;  author: root;  state: Exp;  lines: +1 -0<br />
A variable of type int is declared representing the number of devices.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
revision 1.1<br />
date: 2014/02/27 19:30:54;  author: root;  state: Exp;<br />
Initial revision<br />
=============================================================================</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/02/module-code-to-show-how-an-open-operation-is-performed-on-the-device-file-when-an-application-calls-open-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
