Presentation is loading. Please wait.

Presentation is loading. Please wait.

63 UQC152H3 Advanced OS Writing a Device Driver. 64 The SCULL Device Driver Simple Character Utility for Loading Localities 6 devices types –Scull-03.

Similar presentations


Presentation on theme: "63 UQC152H3 Advanced OS Writing a Device Driver. 64 The SCULL Device Driver Simple Character Utility for Loading Localities 6 devices types –Scull-03."— Presentation transcript:

1 63 UQC152H3 Advanced OS Writing a Device Driver

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

3 65 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 66 Major and Minor numbers Major number used for device identification Minor used by device Use –Register_chdev(unsigned int major, const char *name, struct file_ops *fops); Registers major number in static array of devices 128 entries!

5 67 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 Major number Minor number

6 68 Dynamic Allocation of Major Numbers It is better to use dynamic allocation of major numbers Use register_chrdev with intial arg=0 There is a limited number of driver numbers Many are already taken Requires script to run mknod

7 69 Dynamically creating a file node

8 70 Dynamically creating a file node

9 71 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 72 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 –Can’t be changed!

11 73 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 74 File Operations Pointed to from struct file –lseek –read, write & readdir –Select –mmap –ioctl –open & release –fsync & fasync –check_media_change & revalidate

13 75 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 76 Which minor number?

15 77 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 78

17 79 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; }


Download ppt "63 UQC152H3 Advanced OS Writing a Device Driver. 64 The SCULL Device Driver Simple Character Utility for Loading Localities 6 devices types –Scull-03."

Similar presentations


Ads by Google