UQC152H3 Advanced OS - PowerPoint PPT Presentation

About This Presentation
Title:

UQC152H3 Advanced OS

Description:

Global & persistent, can be opened many times. Scullpipe0-3 ... check_media_change & revalidate. 75. Struct file. Very important kernel data structure ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 18
Provided by: craig60
Category:

less

Transcript and Presenter's Notes

Title: UQC152H3 Advanced OS


1
UQC152H3 Advanced OS
  • Writing a Device Driver

2
The SCULL Device Driver
  • Simple Character Utility for Loading Localities
  • 6 devices types
  • Scull-03
  • Scullpipe0-3
  • Scullsingle
  • Scullpriv
  • Sculluid
  • Scullwuid

3
Types of SCULL
  • Scull0-3
  • Global persistent, can be opened many times
  • Scullpipe0-3
  • Works like a normal pipe example of blocking
  • Scullsingle, scullpriv, sculluid, scullwuid
  • Access versions of scull

4
Major and Minor numbers
  • Major number used for device identification
  • Minor used by device
  • Use ltlinux/fs.hgt
  • Register_chdev(unsigned int major, const char
    name, struct file_ops fops)
  • Registers major number in static array of devices
    128 entries!

5
Mknod creating a file access point
  • Once we have a device table entry we need some
    way for programs and utilities to access it.
  • Use mknod to create file access point
  • mknod /dev/scull c 127 0

Device name
Device type
Minor number
Major number
6
Dynamic Allocation of Major Numbers
  • It is better to use dynamic allocation of major
    numbers
  • Use register_chrdev with intial arg0
  • There is a limited number of driver numbers
  • Many are already taken
  • Requires script to run mknod

7
Dynamically creating a file node
8
Dynamically creating a file node
9
Deregistering devices
  • Unloaded drivers should be de-registered using
  • Unregister_chrdev(unsigned int major, const char
    name)
  • Can cause procs problems if not de-registered

10
dev_t and k_dev
  • System passes the major number to called code
    through the major number
  • Passed as i_rdev in struct inode
  • i_rdev is 16 bits
  • Only allows 256 minor numbers
  • Cant be changed!

11
kdev_t
  • Linux kernels greater then 1.2 has introduced
    kdev_t
  • It allows larger minor numbers
  • It has a number of macros
  • MAJOR, get a major dev_t from kdev_t
  • MINOR, get a minor dev_t from kdev_t
  • MKDEV return a kdev_t from a dev_t

12
File Operations
  • Pointed to from struct file
  • lseek
  • read , write readdir
  • Select
  • mmap
  • ioctl
  • open release
  • fsync fasync
  • check_media_change revalidate

13
Struct file
  • Very important kernel data structure
  • Not the same of FILE of library calls
  • Has
  • Pointer to file operations
  • Flag data
  • Read/write position
  • Inode
  • Mode

14
Which minor number?
15
Opening a device
  • Open does the following
  • Check for errors device not ready?
  • Initialises the device if this is the first open
    call
  • Identifies the minor numbers selects correct
    file op
  • Allocates private data
  • Increments the usage count

16
(No Transcript)
17
Close or release method
  • This should
  • Decrement the usage count
  • Deallocate anything allocated by open
  • Last one out turn off the lights!

void scull_release (struct inode inode, struct
file filp) MOD_DEC_USE_COUNT
Write a Comment
User Comments (0)
About PowerShow.com