• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Block Drivers
 

Block Drivers

on

  • 11,679 views

 

Statistics

Views

Total Views
11,679
Views on SlideShare
3,087
Embed Views
8,592

Actions

Likes
6
Downloads
0
Comments
0

19 Embeds 8,592

http://www.sysplay.in 3332
http://sysplay.in 2489
http://profession.sarika-pugs.com 2251
http://cheng-min-i-taiwan.blogspot.tw 232
http://cheng-min-i-taiwan.blogspot.com 222
http://www.cheng-min-i-taiwan.blogspot.tw 11
http://translate.googleusercontent.com 9
http://localhost 9
http://cheng-min-i-taiwan.blogspot.hk 8
http://www.userspace.org 7
http://www.linkedin.com 4
http://www.cheng-min-i-taiwan.blogspot.com 4
http://cheng-min-i-taiwan.blogspot.in 4
https://www.linkedin.com 3
url_unknown 3
http://www.cheng-min-i-taiwan.blogspot.kr 1
http://www.slideshare.net 1
http://cheng-min-i-taiwan.blogspot.ca 1
http://cheng-min-i-taiwan.blogspot.com.au 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Block Drivers Block Drivers Presentation Transcript

    • Block Drivers© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
    • What to Expect?Understand the need for Block LayerRole of Block DriversWriting a Block Driver © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 2 All Rights Reserved.
    • Block vs CharacterConcept Similarities Device Registration Usage of Device Files Major & Minor number File OperationsThen, 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 © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 3 All Rights Reserved.
    • Block Input / Output File I/O User Space Virtual File System (VFS) Layer Individual Filesystems (ext3, vfat, ...) Buffer Cache (Page Cache) I/O Schedulers Request Queue Request Queue Block Driver ...... Block DriverKernel Space Disk ...... CDStorage Space Drive © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 4 All Rights Reserved.
    • Understanding a Hard DiskExample (Hard Disk) Heads (or Platters): 0 – 9 Tracks (or Cylinders): 0 – 24 Sectors: 1 – 64Size of the Hard Disk 10 x 25 x 64 x 512 bytes = 8000KiBDevice independent numbering (h, t, s) → 64 * (10 * t + h) + s → (1 - 16000) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
    • Partitioning a Hard DiskFirst Sector – Master Boot Record (MBR) Contains Boot Info Contains Physical Partition TableMaximum Physical Partitions: 4 At max 1 as Extended Partition Rest as Primary PartitionExtended could be further partitioned into Logical PartitionsIn each partition First Sector – Boot Record (BR) Remaining for File System / Format Extended Partition BR contains the Logical Partition Table © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 6 All Rights Reserved.
    • Now, lets write a Driver to Achieve the Purpose© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 7 All Rights Reserved.
    • Block RegistrationDriver Registration Header: <linux/fs.h> APIs int register_blkdev(major, name); int unregister_blkdev(major, name);Disk Drive Registration Header: <linux/genhd.h> Type: struct gendisk *gd = alloc_disk(minors); APIs void put_disk(gd); void add_disk(gd); void del_gendisk(gd); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 8 All Rights Reserved.
    • struct gendiskint majorint first_minorint minorschar disk_name[32]struct block_device_operations *fopsstruct request_queue *queueint flags (GENHD_FL_REMOVABLE, ...)sector_t nr_sects → struct hd_struct part0void *private_data © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 9 All Rights Reserved.
    • struct hd_structsector_t start_sectsector_t nr_sectssector_t alignment_offset... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 10 All Rights Reserved.
    • Block Device OperationsHeader: <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; © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.
    • Block Device OperationsHeader: <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; © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 12 All Rights Reserved.
    • Request Queues & ProcessingHeader: <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); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 13 All Rights Reserved.
    • RequestsInterfaces 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_vecRequest Function typedef void (*request_fn_proc)(request_queue_t *queue); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 14 All Rights Reserved.
    • What all have we learnt?Understood the need for Block LayerRole of Block DriversWriting a Block Driver Registration Block Device Operations Request & Request Queues © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 15 All Rights Reserved.
    • Any Queries?© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 16 All Rights Reserved.