<?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; Block Driver</title>
	<atom:link href="https://www.emblogic.com/blog/category/device-drivers/block-driver/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>Introduction to Block Driver</title>
		<link>https://www.emblogic.com/blog/12/introduction-to-block-driver/</link>
		<comments>https://www.emblogic.com/blog/12/introduction-to-block-driver/#comments</comments>
		<pubDate>Wed, 16 Dec 2015 11:49:17 +0000</pubDate>
		<dc:creator><![CDATA[Jatin Mittal]]></dc:creator>
				<category><![CDATA[Block Driver]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13067</guid>
		<description><![CDATA[Overview :  Block Drivers are act as conduit between core memory and secondary storage. There is a virtual memory layer between core memory and secondary storage. Block Layer could be seen as a part of virtual memory subsystem. Block driver &#8230; <a href="https://www.emblogic.com/blog/12/introduction-to-block-driver/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Overview :</p>
<ul>
<li> Block Drivers are act as conduit between core memory and secondary storage.</li>
<li>There is a virtual memory layer between core memory and secondary storage.</li>
<li>Block Layer could be seen as a part of virtual memory subsystem.</li>
<li>Block driver provides access to devices that transfer randomly accessible data.</li>
<li>Block Driver controls the block layer, makes decision about collecting bytes into group of bytes, handle interaction between virtual layer and block layer, block layer and block devices.</li>
<li>Block Driver collect chunks of bytes into blocks.</li>
<li>As almost every block device consist of file system also. Therefore block device driver must take care of file system.</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/introduction-to-block-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Block Driver</title>
		<link>https://www.emblogic.com/blog/12/block-driver-6/</link>
		<comments>https://www.emblogic.com/blog/12/block-driver-6/#comments</comments>
		<pubDate>Mon, 30 Dec 2013 08:50:55 +0000</pubDate>
		<dc:creator><![CDATA[abhishek.gangwar]]></dc:creator>
				<category><![CDATA[Block Driver]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7947</guid>
		<description><![CDATA[Have you ever used VIM editer in the linux? If yes then you must have observed that whatever you type in the editor is visible to you and your system knows that what characters you have written. It means these &#8230; <a href="https://www.emblogic.com/blog/12/block-driver-6/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Have you ever used VIM editer in the linux? If yes then you must have observed that whatever you type in the editor is visible to you and your system knows that what characters you have written. It means these characters are stored somewhere in the system.<br />
What happens when you just gave the :q command in the VIM editor, the editor is closed now and whatever characters you have written in the Vim Editor is lost now.<br />
What happens when you gave the :wq command in VIM, the editor is closed but whatever you have written in the Editor is not lost. You can get this saved file even after rebooting your system. If you know the secondary memory then it simply means that now the file is in the secondary storage.</p>
<p>Both the times the file was saved in the system but only difference is that for the first observation the file was saved in you primary memory and the second time you just saved your file in the secondary storage.</p>
<p>Who did this stuff? The answer is block layer of the Operating system.</p>
<p>This is just a example to understand what is the role of Block layer of the Operating System but there are too many stuffs in the operating system where the block driver works. To implement the block driver we can simply have a conclusion i.e. whenever we need to save the primary storage data into the secondary storage or to fetch the data stored in the secondary storage into the primary one, the block layer comes into the picture.</p>
<p>The block driver simply writes the block of bytes into the secondary storage from the primary storage or reads the block of bytes from secodary storage to the primary storage.</p>
<p>The block driver deals with the data in fixed size of blocks. Mostly all the devices which are used as the secondary storage are the block devices.</p>
<p>We require to mount a filesystem on the block devices. Filesystem provides the way of arrangment in the device and meaning of the simple 0s and 1s(raw data stored on the device) to the Operating System. The device file provides the interface between the filesystem and the block device driver. Filesystem can divide the disk (Mostly the secondary storage) into multiple logical parts i.e. partitions of the disk.</p>
<p>Block devices support random access and generally use buffered input and output routines. The operating system allocates a data buffer to hold a single block each for input and output. When a program sends a request to read data from, or write data to, the device, the system stores each character of that data in the appropriate buffer. When the buffer fills up, the appropriate operation takes place (data transfer) and the system clears the buffer.</p>
<p>The sector is the smallest addressable unit of the disk. Each sector stores a fixed amount of user-accessible data, traditionally 512 bytes for hard drives and 2048 bytes for CD-ROMs and DVD-ROMs. Newer hard drives use 4096-byte sectors.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/block-driver-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Introduction to Block Driver</title>
		<link>https://www.emblogic.com/blog/12/an-introduction-to-block-driver/</link>
		<comments>https://www.emblogic.com/blog/12/an-introduction-to-block-driver/#comments</comments>
		<pubDate>Mon, 30 Dec 2013 07:46:57 +0000</pubDate>
		<dc:creator><![CDATA[mausam.devolia]]></dc:creator>
				<category><![CDATA[Block Driver]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7919</guid>
		<description><![CDATA[An Introduction to Block Driver When Unix was written 25 years ago, its design was eclectic. One unusual design feature was that every physical device connected to the computer was represented as a file. This was a bold decision, because &#8230; <a href="https://www.emblogic.com/blog/12/an-introduction-to-block-driver/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p style="text-align: center" lang="en"><strong><span style="text-decoration: underline">An Introduction to Block Driver</span></strong></p>
<p lang="en">When Unix was written 25 years ago, its design was eclectic. One unusual design feature was that every physical device connected to the computer was represented as a file. This was a bold decision, because many devices are very different from one another, especially at first glance. Why use the same interface to talk to a printer as to talk to a disk drive?</p>
<p lang="en">The short answer is that while the devices are very much different, they can be thought of as having most of the same characteristics as files. The entire system is then kept smaller and simpler by only using one interface with a few extensions.</p>
<p lang="en">This is fine, except that it hides important differences between devices. For example, it is possible to read any byte on a disk at any time, but it is only possible to read the <strong>next</strong> byte from a terminal.</p>
<p lang="en">There are other differences, but this is the most fundamental one: Some devices (like disks) are <strong>random-access</strong>, and others (like terminals) are <strong>sequential-access</strong>. Of course, it is possible to pretend that a random-access device is a sequential-access device, but it doesn&#8217;t work the other way around.</p>
<p lang="en">A practical effect of the difference is that file systems can only be mounted on block devices, not on character ones. For example, most tapes are <strong>character</strong> devices. It is possible to copy the contents of a raw, quiescent (unmounted and not being modified) file system to a tape, but you will not be able to mount the tape, even though it contains the same information as the disk.</p>
<p>Most textbooks and tutorials start by explaining character devices, the sequential-access ones, because a minimal character device driver is easier to write than a minimal block device driver. My own <em>Linux Kernel Hackers&#8217; Guide</em> (the <em>KHG</em>) is written the same way.</p>
<p lang="en">My reason for starting this column with block devices, the random-access devices, is that the KHG explains simple character devices better than it does block devices, and I think that there is a greater need for information on block devices right now. Furthermore, <strong>real</strong> character device drivers can be quite complex, just as complex as block device drivers, and fewer people know how to write block device drivers.</p>
<p lang="en">I am not going to give a complete example of a device driver here. I am going to explain the important parts, and let you discover the rest by examining the Linux source code. Reading this article and the ramdisk driver (<strong>drivers/block/ramdisk.c</strong>), and possibly some parts of the KHG, should make it possible for you to write a simple, non-interrupt-driven block device driver, good enough to mount a filesystem on. To write an interrupt-driven driver, read <strong>drivers/block/hd.c</strong>, the AT hard disk driver, and follow along. I&#8217;ve included a few hints in this article, as well.</p>
<p lang="en"><a name="N0xa50890.0xb453b0"></a>The Heart of the Driver</p>
<p lang="en">Whereas character device drivers provide procedures for directly reading and writing data from and to the device they drive, block devices do not. Instead, they provide a single <strong>request()</strong> procedure which is used for both reading and writing. There are generic <strong>block_read()</strong> and <strong>block_write()</strong> procedures which know how to call the <strong>request()</strong> procedure, but all you need to know about those functions is to place a reference to them in the right place, and that will be covered later.</p>
<p lang="en">The <strong>request()</strong> procedure (perhaps surprisingly for a function designed to do I/O) takes no arguments and returns void. Instead of explicit input and return values, it looks at a queue of requests for I/O, and processes the requests one at a time, in order. (The requests have already been sorted by the time the <strong>request()</strong> function reads the queue.) When it is called, if it is not interrupt-driven, it processes requests for blocks to be read from the device, until it has exhausted all pending requests. (Normally, there will be only one request in the queue, but the <strong>request()</strong> procedure should check until it is empty. Note that other requests may be added to the queue by other processes while the current request is being processed.)</p>
<p lang="en">On the other hand, if the device is interrupt-driven, the <strong>request()</strong> procedure will usually schedule an interrupt to take place, and then let the interrupt handling procedure call <strong>end_request()</strong> (more on <strong>end_request()</strong> later) and then call the <strong>request()</strong> procedure again to schedule the next request (if any) to be processed.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/12/an-introduction-to-block-driver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jatinder Kumar:</title>
		<link>https://www.emblogic.com/blog/10/jatinder-kumar-2/</link>
		<comments>https://www.emblogic.com/blog/10/jatinder-kumar-2/#comments</comments>
		<pubDate>Fri, 18 Oct 2013 08:47:56 +0000</pubDate>
		<dc:creator><![CDATA[Jatinder Kumar]]></dc:creator>
				<category><![CDATA[Block Driver]]></category>
		<category><![CDATA[Device Drivers]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=7323</guid>
		<description><![CDATA[Successfully implemented Basic Block driver. From registeration to alloc_dsik, add_disk, request and transfer function.Completed documentations also]]></description>
				<content:encoded><![CDATA[<p>Successfully implemented Basic Block driver. From registeration to alloc_dsik, add_disk, request and transfer function.Completed documentations also</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/10/jatinder-kumar-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>block driver crashes on add_disk</title>
		<link>https://www.emblogic.com/blog/08/block-driver-crashes-on-add_disk/</link>
		<comments>https://www.emblogic.com/blog/08/block-driver-crashes-on-add_disk/#comments</comments>
		<pubDate>Thu, 09 Aug 2012 04:24:36 +0000</pubDate>
		<dc:creator><![CDATA[zaffer]]></dc:creator>
				<category><![CDATA[Block Driver]]></category>

		<guid isPermaLink="false">http://emblogic.org/blog/?p=4583</guid>
		<description><![CDATA[here is the code #include&#8221;header.h&#8221; dev_t dev; &#160; &#160; void bulk_request(struct request_queue *q) { struct request *req; req = blk_fetch_request(q); while (req != NULL) { if (req == NULL &#124;&#124; (req-&#62;cmd_type != REQ_TYPE_FS)) { printk (KERN_NOTICE &#8220;Skip non-CMD request\n&#8221;); __blk_end_request_all(req, &#8230; <a href="https://www.emblogic.com/blog/08/block-driver-crashes-on-add_disk/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>here is the code</p>
<p>#include&#8221;header.h&#8221;</p>
<p>dev_t dev;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>void bulk_request(struct request_queue *q)</p>
<p>{<br />
struct request *req;</p>
<p>req = blk_fetch_request(q);</p>
<p>while (req != NULL)<br />
{</p>
<p>if (req == NULL || (req-&gt;cmd_type != REQ_TYPE_FS))<br />
{<br />
printk (KERN_NOTICE &#8220;Skip non-CMD request\n&#8221;);<br />
__blk_end_request_all(req, -EIO);<br />
continue;</p>
<p>}</p>
<p>}<br />
}</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>int __init start(void)<br />
{<br />
//int reg;</p>
<p>// struct request *disk;</p>
<p>static struct request_queue *Queue;</p>
<p>printk(KERN_INFO &#8220;Begin : %s\n&#8221;,__func__);</p>
<p>printk(KERN_INFO&#8221; HELLO KERNEL&#8221;);<br />
sbullmajor=register_blkdev(sbullmajor,device_name);</p>
<p>if(sbullmajor)<br />
{</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; Registration Sucessful\n &#8220;);</p>
<p>printk(KERN_INFO&#8221;Major no is %d\n&#8221;,sbullmajor);</p>
<p>#endif</p>
<p>}<br />
else</p>
<p>{</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8220;Registartion failed\n &#8220;);</p>
<p>#endif<br />
}<br />
sbulldev=kmalloc(sizeof(struct Sbulldev),GFP_KERNEL);</p>
<p>memset(sbulldev,&#8221;,sizeof(struct Sbulldev));</p>
<p>sbulldev-&gt;size=hardsect_size;</p>
<p>sbulldev-&gt;data=vmalloc(sbulldev-&gt;size);</p>
<p>if(sbulldev-&gt;data ==NULL )</p>
<p>{<br />
#ifdef DEBUG<br />
printk(KERN_INFO &#8221; Memory allocation failed\n &#8220;);</p>
<p>#endif</p>
<p>}<br />
else</p>
<p>{<br />
#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; Memory allocation of block device sucessful\n &#8220;);</p>
<p>#endif<br />
}</p>
<p>spin_lock_init(&amp;sbulldev-&gt;lock);</p>
<p>#ifdef DEBUG<br />
printk(KERN_INFO &#8221; after spin_lock\n &#8220;);</p>
<p>#endif<br />
sbulldev-&gt;gd=alloc_disk(16);</p>
<p>if(sbulldev-&gt;gd==NULL){ //no of minors is 1 no partioning;</p>
<p>#ifdef DEBUG<br />
printk(KERN_INFO &#8221; alloc_disk failed\n &#8220;);</p>
<p>#endif</p>
<p>goto OUT;</p>
<p>}</p>
<p>else</p>
<p>{<br />
#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; alloc_disk sucessful\n &#8220;);</p>
<p>#endif<br />
}<br />
Queue=blk_init_queue(bulk_request,NULL);</p>
<p>blk_queue_logical_block_size(Queue,hardsect_size);</p>
<p>sbulldev-&gt;gd-&gt;major=sbullmajor;</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; sbullmajor\n &#8220;);</p>
<p>#endif</p>
<p>sbulldev-&gt;gd-&gt;minors=sbullminor;<br />
#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; sbullminor\n &#8220;);</p>
<p>#endif</p>
<p>sbulldev-&gt;gd-&gt;first_minor=1;</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; first_minor\n &#8220;);</p>
<p>#endif</p>
<p>sbulldev-&gt;gd-&gt;fops=f_ops;</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; file_operations\n &#8220;);</p>
<p>#endif</p>
<p>sbulldev-&gt;gd-&gt;queue=Queue;</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; Queue\n &#8220;);</p>
<p>#endif</p>
<p>sbulldev-&gt;gd-&gt;private_data=sbulldev;</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; private_data\n &#8220;);</p>
<p>#endif</p>
<p>strcpy(sbulldev-&gt;gd-&gt;disk_name ,&#8221;sbulla&#8221; );</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; sbulla\n &#8220;);</p>
<p>#endif</p>
<p>set_capacity(sbulldev-&gt;gd,hardsect_size);</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; set_capacity\n &#8220;);</p>
<p>#endif<br />
add_disk(sbulldev-&gt;gd);</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; add disk\n &#8220;);</p>
<p>#endif</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8221; End of %s\n &#8220;,__func__);</p>
<p>#endif</p>
<p>OUT:</p>
<p>return -1;</p>
<p>&nbsp;</p>
<p>return 0;</p>
<p>}<br />
void __exit release(void)<br />
{</p>
<p>//int i;</p>
<p>#ifdef DEBUG</p>
<p>printk(KERN_INFO &#8220;exit : %s\n&#8221;,__func__);</p>
<p>#endif<br />
del_gendisk(sbulldev-&gt;gd);</p>
<p>printk(KERN_INFO &#8221; add disk\n &#8220;);</p>
<p>blk_cleanup_queue(sbulldev-&gt;queue);</p>
<p>printk(KERN_INFO &#8221; add disk\n &#8220;);</p>
<p>//put_disk(sbulldev-&gt;gd);</p>
<p>&nbsp;<br />
unregister_blkdev(sbullmajor,device_name);<br />
printk(KERN_INFO &#8220;BYE KERNEL&#8221;);<br />
}<br />
module_init(start);</p>
<p>module_exit(release);</p>
<p>}</p>
<p>the driver crashes  moment insmod ./modules/lkm.ko is done&#8230;..ha i have zero bytes of home drive  does this effect</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/08/block-driver-crashes-on-add_disk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
