Home
Explore
Submit Search
Upload
Login
Signup
Advertisement
Block Drivers
Report
Anil Kumar Pugalia
Follow
Linux Geek and Open Source Hardware & Software Freak, Corporate Trainer, Entrepreneur in Automation
Jun. 21, 2010
•
0 likes
5 likes
×
Be the first to like this
Show More
•
37,881 views
views
×
Total views
0
On Slideshare
0
From embeds
0
Number of embeds
0
Check these out next
Linux Ethernet device driver
艾鍗科技
Linux booting process
Prashant Hegde
Character Drivers
Anil Kumar Pugalia
LCU14 500 ARM Trusted Firmware
Linaro
linux device driver
Rahul Batra
Linux Porting to a Custom Board
Patrick Bellasi
Audio Drivers
Anil Kumar Pugalia
U boot-boot-flow
BabuSubashChandar Chandra Mohan
1
of
21
Top clipped slide
Block Drivers
Jun. 21, 2010
•
0 likes
5 likes
×
Be the first to like this
Show More
•
37,881 views
views
×
Total views
0
On Slideshare
0
From embeds
0
Number of embeds
0
Report
Technology
Anil Kumar Pugalia
Follow
Linux Geek and Open Source Hardware & Software Freak, Corporate Trainer, Entrepreneur in Automation
Advertisement
Advertisement
Advertisement
Recommended
Introduction to Linux Drivers
Anil Kumar Pugalia
64.1K views
•
29 slides
PCI Drivers
Anil Kumar Pugalia
43.9K views
•
16 slides
Linux device drivers
Emertxe Information Technologies Pvt Ltd
40.4K views
•
114 slides
USB Drivers
Anil Kumar Pugalia
42.4K views
•
31 slides
I2C Drivers
SysPlay eLearning Academy for You
28.4K views
•
28 slides
Pcie drivers basics
Venkatesh Malla
797 views
•
34 slides
More Related Content
Slideshows for you
(20)
Linux Ethernet device driver
艾鍗科技
•
2.6K views
Linux booting process
Prashant Hegde
•
1.6K views
Character Drivers
Anil Kumar Pugalia
•
56.3K views
LCU14 500 ARM Trusted Firmware
Linaro
•
11.8K views
linux device driver
Rahul Batra
•
11.4K views
Linux Porting to a Custom Board
Patrick Bellasi
•
28.5K views
Audio Drivers
Anil Kumar Pugalia
•
20.4K views
U boot-boot-flow
BabuSubashChandar Chandra Mohan
•
1.1K views
Bootloaders (U-Boot)
Omkar Rane
•
506 views
Linux booting procedure
Dhaval Kaneria
•
3.1K views
Arm device tree and linux device drivers
Houcheng Lin
•
17.4K views
Linux Kernel Booting Process (1) - For NLKB
shimosawa
•
12.4K views
SPI Drivers
SysPlay eLearning Academy for You
•
13.1K views
malloc & vmalloc in Linux
Adrian Huang
•
781 views
Embedded Recipes 2019 - Remote update adventures with RAUC, Yocto and Barebox
Anne Nicolas
•
1K views
BeagleBone Black Bootloaders
SysPlay eLearning Academy for You
•
4.4K views
Linux Initialization Process (2)
shimosawa
•
6.7K views
Linux Kernel MMC Storage driver Overview
RajKumar Rampelli
•
17.1K views
Linux booting process!!
sourav verma
•
2.6K views
BeagleBone Black Booting Process
SysPlay eLearning Academy for You
•
18K views
Similar to Block Drivers
(20)
File System Modules
Anil Kumar Pugalia
•
20.4K views
File System Modules
Anil Kumar Pugalia
•
24.9K views
Linux File System
Anil Kumar Pugalia
•
24.2K views
Introduction to Linux
Anil Kumar Pugalia
•
3.8K views
Introduction to Linux
Anil Kumar Pugalia
•
11.1K views
Network Drivers
Anil Kumar Pugalia
•
38.6K views
Linux IO
Liran Ben Haim
•
2.5K views
Low-level Accesses
Anil Kumar Pugalia
•
24.9K views
Linux Memory Management
Anil Kumar Pugalia
•
27.2K views
Let Me Pick Your Brain - Remote Forensics in Hardened Environments
Nicolas Collery
•
1.3K views
101 2.1 design hard disk layout v2
Acácio Oliveira
•
329 views
TLPI Chapter 14 File Systems
Shu-Yu Fu
•
691 views
2.1 design hard disk layout v2
Acácio Oliveira
•
424 views
[Defcon] Hardware backdooring is practical
Moabi.com
•
129.9K views
Bootloaders
Anil Kumar Pugalia
•
9.7K views
Linux Network Management
Anil Kumar Pugalia
•
11.1K views
BeagleBoard-xM Booting Process
SysPlay eLearning Academy for You
•
3.7K views
Linux
keydak11
•
1.1K views
File Systems
Anil Kumar Pugalia
•
17.8K views
Hardware backdooring is practical : slides
Moabi.com
•
1.3K views
Advertisement
More from Anil Kumar Pugalia
(20)
Kernel Debugging & Profiling
Anil Kumar Pugalia
•
5.8K views
Processes
Anil Kumar Pugalia
•
6.8K views
System Calls
Anil Kumar Pugalia
•
4K views
Embedded C
Anil Kumar Pugalia
•
25.6K views
Embedded Software Design
Anil Kumar Pugalia
•
6.9K views
Playing with R L C Circuits
Anil Kumar Pugalia
•
2.8K views
Video Drivers
Anil Kumar Pugalia
•
23K views
Mobile Hacking using Linux Drivers
Anil Kumar Pugalia
•
5.9K views
Shell Scripting
Anil Kumar Pugalia
•
6.1K views
References
Anil Kumar Pugalia
•
21.7K views
Functional Programming with LISP
Anil Kumar Pugalia
•
6.1K views
Power of vi
Anil Kumar Pugalia
•
2.9K views
gcc and friends
Anil Kumar Pugalia
•
14.2K views
"make" system
Anil Kumar Pugalia
•
4.1K views
Hardware Design for Software Hackers
Anil Kumar Pugalia
•
1.7K views
RPM Building
Anil Kumar Pugalia
•
4K views
Linux User Space Debugging & Profiling
Anil Kumar Pugalia
•
6.4K views
System Calls
Anil Kumar Pugalia
•
9.7K views
Timers
Anil Kumar Pugalia
•
6.3K views
Threads
Anil Kumar Pugalia
•
10K views
Recently uploaded
(20)
Antenna_Design__Measurements_Laboratory_Lectures.pdf
Fredrick Isingo
•
0 views
Storybook, the best friend we all need
AnnaSala22
•
0 views
Medical Termination of Pregnancy Act.pptx
Sudipta Roy
•
0 views
DIGITAL-ELECTRONICS-DESIGN.pptx
SofiaArquero2
•
0 views
Good Regulatory Practices.pptx
Sudipta Roy
•
0 views
Photoshop Tools.pptx
yelnatz
•
2 views
CS401_M2_L6_Solid Area Scan Conversion.pptx
lara333479
•
2 views
NahamConEU2022.pdf
seed4mexyz
•
1 view
EN-04 (1).pptx
TienTran779192
•
3 views
DSH Week 3 – Storytelling with Place.pdf
StefanAngelDx
•
2 views
SUBMIT YOUR PAPERS - International Journal of Data Mining & Knowledge Managem...
IJDKP
•
0 views
Blockchain Technology
Aryan Chaudhary
•
0 views
different-os.pptx
leilibarekatin
•
0 views
Why should your startup outsource software development.pdf
MaryLogan11
•
0 views
Computerized AIS (AIS, TPS and Double-Entry).ppt
franciskishushu
•
0 views
DIMT 2023 SG - Hands-on Workshop_ Getting started with Confluent Cloud.pdf
confluent
•
4 views
PLG Assignment 1_Sourabh Pal.pptx
SourabhPAL42
•
0 views
d9f0992b5cb6478fa0dfff092cccc2d2.pdf
ThnhNguynVn97
•
0 views
ictpresentation-201013093225.pdf
ThnhNguynVn97
•
0 views
Unveiling the Versatility of NEMA 1-15 Power Cords
Sf Cable, Inc
•
3 views
Advertisement
Block Drivers
© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Block Drivers
2© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. What to Expect? Why the need for the Block Layer? Decoding a Block Device in Linux Role of Block Drivers Writing a Block Driver
3© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Block vs Character Concept Similarities Device Registration Usage of Device Files Major & Minor number File Operations Then, why a different category? To access block-oriented devices (Really?) To achieve buffering for efficiency To enable a generic caching abstraction To provide a device independent block access of data
4© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. System-wide Block Devices Category is to Major IDE: 3; SCSI: 8; ... Naming Convention (Try: ls -l /dev/sd*) IDE: hd*; SCSI: sd*; ... Disk is to Minor Typically limited to 4 per system, represented using a, b, ... Partition also is to Minor 256 / 4 = 64 to each disk First one for the whole disk, e.g. hda Remaining for the partitions, thus limiting to 63, e.g. hda1
5© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. The Generic Hard Disk Disk or Platter Tracks Sectors
6© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. The Generic Hard Disk . . . . . . Spindle Heads Cylinder
7© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Computing a Generic Hard Disk Example (Hard Disk) Heads (or Platters): 0 – 9 Tracks (or Cylinders): 0 – 24 Sectors: 1 – 64 Size of the Hard Disk 10 x 25 x 64 x 512 bytes = 8000KiB Device independent numbering (h, t, s) → 64 * (10 * t + h) + s → (1 - 16000)
8© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Partitioning Visualization 2 3 4 5 7 86 N-5 N-4 N-3 N-2 N-1 N Linearized sector numbers 1MBR MBR P1 P2 P4P3ExtBR BR BR BR ExtL1 RemLBR L2 RemL3LBR L4LBR LnLBR Boot Code Partition Table Sec. Boot Code Logical Part. Table BRLBR
9© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Partitioning a Block Device First Sector – Master Boot Record (MBR) Contains Boot Info Contains Physical Partition Table Maximum Physical Partitions: 4 At max 1 as Extended Partition Rest as Primary Partition Extended could be further partitioned into Logical Partitions In each partition First Sector – Boot Record (BR) Remaining for File System / Format Extended Partition BR contains the Logical Partition Table
10© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Block Input / Output Virtual File System (VFS) Layer Block Driver Individual Filesystems (ext3, vfat, ...) Buffer Cache (Page Cache) I/O Schedulers Block Driver User Space Storage Space Kernel Space CD Drive ...... Disk File I/O Request Queue Request Queue ......
11© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Now, let's write a Driver to Achieve the Purpose
12© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Block Registration Driver Registration Header: <linux/fs.h> APIs int register_blkdev(major, name); int unregister_blkdev(major, name); Disk Drive Registration Header: <linux/genhd.h> Data Structure: struct gendisk *gd APIs struct gendisk *alloc_disk(minors); void put_disk(gd); void add_disk(gd); void del_gendisk(gd);
13© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. struct gendisk int major int first_minor int minors char disk_name[32] struct block_device_operations *fops struct request_queue *queue int flags (GENHD_FL_REMOVABLE, ...) sector_t nr_sects → struct hd_struct part0 void *private_data
14© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. struct hd_struct sector_t start_sect sector_t nr_sects sector_t alignment_offset ...
15© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Block Device Operations Header: <linux/blkdev.h> System Calls (till <= 2.6.27) int open(struct inode *i, struct file *f); int close(struct inode *i, struct file *f); int ioctl(struct inode *i, struct file *f, cmd, arg); int media_changed(struct gendisk *gd); int revalidate_disk(struct gendisk *gd); ... Other Important Fields struct module *owner;
16© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Block Device Operations Header: <linux/blkdev.h> System Calls (after 2.6.27) int (*open)(struct block_device *, fmode_t); int (*release)(struct block_device *, fmode_t); int (*ioctl)(struct block_device *, fmode_t, cmd, arg); int (*media_changed)(struct gendisk *gd); int (*revalidate_disk)(struct gendisk *gd); int (*getgeo)(struct block_device *, struct hd_geometry *); ... Other Important Fields struct module *owner;
17© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Request Queues & Processing Header: <linux/blkdev.h> Types request_queue_t *q; request_fn_proc rqf; struct request *req; APIs q = blk_init_queue(rqf, lock); blk_cleanup_queue(q); req = blk_fetch_request(q);
18© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Requests Interfaces rq_data_dir(req) – Operation type zero: read from device non-zero: write to the device blk_req_pos(req) – Starting sector blk_req_sectors(req) – Total sectors Iterator for extracting buffers from bio_vec Request Function typedef void (*request_fn_proc)(request_queue_t *queue);
19© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Disk on RAM Let's try out the RAM Block Driver Horizontal: Disk on RAM ram_device.c, ram_device.h Vertical: Block Driver ram_block.c Useful commands blockdev dd fdisk
20© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. What all have we learnt? Understood the need for the Block Layer Decoding a Block Device in Linux Role of Block Drivers Writing a Block Driver Registration Block Device Operations Request & Request Queues
21© 2010-16 SysPlay
Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?
Advertisement