SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
Linux Char Device Driver
Gary 2013/03/20
Outline
• Introduction
• Module
• Major Number and Minor Number
• Data Structure
• Registration
• Open and Release
• Read and Write
• Future Work
Introduction
• Device driver is a bridge between physical
devices and programs, and it’s part of kernel.
User program can manage physical devices via
device driver.
• Driver can be roughly divided into Block
device driver and Character device driver. The
former transfer a fixed amount of data each
time, and Character device driver transfer no-
fixed amount of data.
Module
Module
Advantage:
• Reduce kernel image space
• Speed up the boot time
• Facilitate the development of the kernel
function
Module
Linking a module to a kernel
Major Number and Minor Number
• Major number(0-255)
When the kernel receives open() system call,
it selects the driver based on major number.
• Minor number(0-255)
Identify individuals of similar devices.
Meaningless to kernel. Only the driver itself
knows the significance of the minor number.
Major Number and Minor Number
• “c” represents special file of char driver.
• “b” represents device file of block driver.
Major number Minor number
Major Number and Minor Number
• Use mknod command to create device node.
Needs superuser priviledges and four
arguments.
- <name> <device type> <major> <minor>
$mknod /dev/ant c 252 0
• Use rm command to delete device node.
$rm /dev/ant
Data Structure
• Struct file represents an opened-device.
• Struct file_operations is used for kernel to
access the method in driver.
- defined in <linux/fs.h>
• Struct file has field f_op, which is the pointer
point to struct file_operations
File_operations
File_operations
• struct module *owner;
Not a function pointer. For kernel to maintain
the usage count of module.
• loff_t (*llseek) (struct file *, loff_t, int);
Change the position of current file read write
point.
File
• The file mentioned here has no concerned
with the file in normal application.
• For every file which is opened, there is a
correspond struct file.
• The pointer point to file is named filp.
File
Old Registration Method
• Call register_chrdev()
- define in <linux/fs.h>
- /usr/src/<kernel version>/include/linux/fs.h
Old Registration Method
• $cat /proc/devices
New Registration Method
• Kernel uses struct cdev to represent char
device driver. You need to include
<linux/cdev.h>
• Use cdev_alloc() to configure struct cdev
• If you have your own designed struct, you
need to use cdev_init()
Struct cdev *my_cdev = cdev_alloc();
My_cdev->ops = &my_fops;
Void cdev_init(struct cdev *dev, struct file_operations *fops);
New Registration Method
• No matter how to initialize struct cdev, the
owner field must be set
• The last step, use cdev_add() to add to kernel
struct cdev my_cdev;
my_cdev.owner = THIS_MODULE;
int cdev_add(struct cdev *dev, dev_t num, unsigned int count);
Struct cdev you set
Major number
Total amount of device number
New Registration Method
• Destroy cdev
void cdev_del(struct cdev *dev);
Open and Release
• Open operation offers driver initialization, and
increase usage count.
• Release operation decrease usage count.
- Defined in <linux/module.h>
Open
• Most of the open operation of driver should do the
following jobs.
- increase usage count
- check for device specific errors
(ex : no CD in CD-ROM)
- if the target device is opened the first time,
do initializtion
- Identify the minor number and update the f_op
pointer
- allocate and fill data structure in filp->private data
Open
• The first step of open operation is to check the
target device’s minor number.
Release
• Release anything that open operation allocate
to flip->private_data.
• Shut down the target device on the last close.
• Decrease usage count
Read and Write
• flip : file pointer
• buff : argument to the buffer in user-space
• count : transfer data amount
• offp : the file location
ssize_t read(struct file *filp, char *buff, size_t count, loff_t *offp);
ssize_t write(struct file *filp, const char *buff, size_t count, loff_t *offp);
Read and Write
• Data transfer between kernel space and user
space.
• Use the function defined in <asm/uaccess.h>
Read and Write
• The arguments to read
Future Work
• Read more
• Ioctl

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
Run Qt on Linux embedded systems using Yocto
Run Qt on Linux embedded systems using YoctoRun Qt on Linux embedded systems using Yocto
Run Qt on Linux embedded systems using Yocto
 
Linux PCI device driver
Linux PCI device driverLinux PCI device driver
Linux PCI device driver
 
PCI Drivers
PCI DriversPCI Drivers
PCI Drivers
 
Character drivers
Character driversCharacter drivers
Character drivers
 
linux device driver
linux device driverlinux device driver
linux device driver
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24I2C Subsystem In Linux-2.6.24
I2C Subsystem In Linux-2.6.24
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Linux booting process
Linux booting processLinux booting process
Linux booting process
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
Introduction to Kernel and Device Drivers
Introduction to Kernel and Device DriversIntroduction to Kernel and Device Drivers
Introduction to Kernel and Device Drivers
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKB
 
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 

Destaque

Kernel overview
Kernel overviewKernel overview
Kernel overviewKai Sasaki
 
10分で分かるLinuxブロックレイヤ
10分で分かるLinuxブロックレイヤ10分で分かるLinuxブロックレイヤ
10分で分かるLinuxブロックレイヤTakashi Hoshino
 
Linux device driver for dummies
Linux device driver for dummiesLinux device driver for dummies
Linux device driver for dummiesHirohito Kato
 
Yocto bspを作ってみた
Yocto bspを作ってみたYocto bspを作ってみた
Yocto bspを作ってみたwata2ki
 
オペレーティングシステム 第1回-公開用
オペレーティングシステム 第1回-公開用オペレーティングシステム 第1回-公開用
オペレーティングシステム 第1回-公開用Ruo Ando
 
Yocto Project ハンズオン プレゼン用資料
Yocto Project ハンズオン プレゼン用資料Yocto Project ハンズオン プレゼン用資料
Yocto Project ハンズオン プレゼン用資料Nobuhiro Iwamatsu
 
Ethernetの受信処理
Ethernetの受信処理Ethernetの受信処理
Ethernetの受信処理Takuya ASADA
 
10GbE時代のネットワークI/O高速化
10GbE時代のネットワークI/O高速化10GbE時代のネットワークI/O高速化
10GbE時代のネットワークI/O高速化Takuya ASADA
 

Destaque (9)

Mosquito Attack
Mosquito AttackMosquito Attack
Mosquito Attack
 
Kernel overview
Kernel overviewKernel overview
Kernel overview
 
10分で分かるLinuxブロックレイヤ
10分で分かるLinuxブロックレイヤ10分で分かるLinuxブロックレイヤ
10分で分かるLinuxブロックレイヤ
 
Linux device driver for dummies
Linux device driver for dummiesLinux device driver for dummies
Linux device driver for dummies
 
Yocto bspを作ってみた
Yocto bspを作ってみたYocto bspを作ってみた
Yocto bspを作ってみた
 
オペレーティングシステム 第1回-公開用
オペレーティングシステム 第1回-公開用オペレーティングシステム 第1回-公開用
オペレーティングシステム 第1回-公開用
 
Yocto Project ハンズオン プレゼン用資料
Yocto Project ハンズオン プレゼン用資料Yocto Project ハンズオン プレゼン用資料
Yocto Project ハンズオン プレゼン用資料
 
Ethernetの受信処理
Ethernetの受信処理Ethernetの受信処理
Ethernetの受信処理
 
10GbE時代のネットワークI/O高速化
10GbE時代のネットワークI/O高速化10GbE時代のネットワークI/O高速化
10GbE時代のネットワークI/O高速化
 

Semelhante a Linux Char Device Driver

Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesYourHelper1
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgSam Bowne
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgSam Bowne
 
Windows internals
Windows internalsWindows internals
Windows internalsPiyush Jain
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsnullowaspmumbai
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh Naik
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O YourHelper1
 
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbgPractical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbgSam Bowne
 
Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers Ahmed El-Arabawy
 
System Device Tree and Lopper: Concrete Examples - ELC NA 2022
System Device Tree and Lopper: Concrete Examples - ELC NA 2022System Device Tree and Lopper: Concrete Examples - ELC NA 2022
System Device Tree and Lopper: Concrete Examples - ELC NA 2022Stefano Stabellini
 
OS Internals and Portable Executable File Format
OS Internals and Portable Executable File FormatOS Internals and Portable Executable File Format
OS Internals and Portable Executable File FormatAitezaz Mohsin
 
Linux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/OLinux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/OYourHelper1
 
Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-reviewabinaya m
 
Part 03 File System Implementation in Linux
Part 03 File System Implementation in LinuxPart 03 File System Implementation in Linux
Part 03 File System Implementation in LinuxTushar B Kute
 
Linux io introduction-fudcon-2015-with-demo-slides
Linux io introduction-fudcon-2015-with-demo-slidesLinux io introduction-fudcon-2015-with-demo-slides
Linux io introduction-fudcon-2015-with-demo-slidesKASHISH BHATIA
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel DevelopmentPriyank Kapadia
 

Semelhante a Linux Char Device Driver (20)

Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging Techniques
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbg
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbg
 
Windows internals
Windows internalsWindows internals
Windows internals
 
Device Drivers
Device DriversDevice Drivers
Device Drivers
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O
 
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbgPractical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
 
Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers
 
System Device Tree and Lopper: Concrete Examples - ELC NA 2022
System Device Tree and Lopper: Concrete Examples - ELC NA 2022System Device Tree and Lopper: Concrete Examples - ELC NA 2022
System Device Tree and Lopper: Concrete Examples - ELC NA 2022
 
OS Internals and Portable Executable File Format
OS Internals and Portable Executable File FormatOS Internals and Portable Executable File Format
OS Internals and Portable Executable File Format
 
Linux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/OLinux System Programming - Advanced File I/O
Linux System Programming - Advanced File I/O
 
Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-review
 
Part 03 File System Implementation in Linux
Part 03 File System Implementation in LinuxPart 03 File System Implementation in Linux
Part 03 File System Implementation in Linux
 
redhat_by_Cbitss.ppt
redhat_by_Cbitss.pptredhat_by_Cbitss.ppt
redhat_by_Cbitss.ppt
 
Linux io introduction-fudcon-2015-with-demo-slides
Linux io introduction-fudcon-2015-with-demo-slidesLinux io introduction-fudcon-2015-with-demo-slides
Linux io introduction-fudcon-2015-with-demo-slides
 
Linux
Linux Linux
Linux
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 

Mais de Gary Yeh

Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSPGary Yeh
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGLGary Yeh
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsGary Yeh
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript EngineGary Yeh
 
jQuery Mobile and JavaScript
jQuery Mobile and JavaScriptjQuery Mobile and JavaScript
jQuery Mobile and JavaScriptGary Yeh
 
JQuery mobile
JQuery mobileJQuery mobile
JQuery mobileGary Yeh
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database ConnectivityGary Yeh
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
Git Workflow
Git WorkflowGit Workflow
Git WorkflowGary Yeh
 

Mais de Gary Yeh (10)

Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript Engine
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
 
jQuery Mobile and JavaScript
jQuery Mobile and JavaScriptjQuery Mobile and JavaScript
jQuery Mobile and JavaScript
 
JQuery mobile
JQuery mobileJQuery mobile
JQuery mobile
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
Git Workflow
Git WorkflowGit Workflow
Git Workflow
 

Último

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 

Último (20)

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 

Linux Char Device Driver

  • 1. Linux Char Device Driver Gary 2013/03/20
  • 2. Outline • Introduction • Module • Major Number and Minor Number • Data Structure • Registration • Open and Release • Read and Write • Future Work
  • 3. Introduction • Device driver is a bridge between physical devices and programs, and it’s part of kernel. User program can manage physical devices via device driver. • Driver can be roughly divided into Block device driver and Character device driver. The former transfer a fixed amount of data each time, and Character device driver transfer no- fixed amount of data.
  • 5. Module Advantage: • Reduce kernel image space • Speed up the boot time • Facilitate the development of the kernel function
  • 7. Major Number and Minor Number • Major number(0-255) When the kernel receives open() system call, it selects the driver based on major number. • Minor number(0-255) Identify individuals of similar devices. Meaningless to kernel. Only the driver itself knows the significance of the minor number.
  • 8. Major Number and Minor Number • “c” represents special file of char driver. • “b” represents device file of block driver. Major number Minor number
  • 9. Major Number and Minor Number • Use mknod command to create device node. Needs superuser priviledges and four arguments. - <name> <device type> <major> <minor> $mknod /dev/ant c 252 0 • Use rm command to delete device node. $rm /dev/ant
  • 10. Data Structure • Struct file represents an opened-device. • Struct file_operations is used for kernel to access the method in driver. - defined in <linux/fs.h> • Struct file has field f_op, which is the pointer point to struct file_operations
  • 12. File_operations • struct module *owner; Not a function pointer. For kernel to maintain the usage count of module. • loff_t (*llseek) (struct file *, loff_t, int); Change the position of current file read write point.
  • 13. File • The file mentioned here has no concerned with the file in normal application. • For every file which is opened, there is a correspond struct file. • The pointer point to file is named filp.
  • 14. File
  • 15. Old Registration Method • Call register_chrdev() - define in <linux/fs.h> - /usr/src/<kernel version>/include/linux/fs.h
  • 16. Old Registration Method • $cat /proc/devices
  • 17. New Registration Method • Kernel uses struct cdev to represent char device driver. You need to include <linux/cdev.h> • Use cdev_alloc() to configure struct cdev • If you have your own designed struct, you need to use cdev_init() Struct cdev *my_cdev = cdev_alloc(); My_cdev->ops = &my_fops; Void cdev_init(struct cdev *dev, struct file_operations *fops);
  • 18. New Registration Method • No matter how to initialize struct cdev, the owner field must be set • The last step, use cdev_add() to add to kernel struct cdev my_cdev; my_cdev.owner = THIS_MODULE; int cdev_add(struct cdev *dev, dev_t num, unsigned int count); Struct cdev you set Major number Total amount of device number
  • 19. New Registration Method • Destroy cdev void cdev_del(struct cdev *dev);
  • 20. Open and Release • Open operation offers driver initialization, and increase usage count. • Release operation decrease usage count. - Defined in <linux/module.h>
  • 21. Open • Most of the open operation of driver should do the following jobs. - increase usage count - check for device specific errors (ex : no CD in CD-ROM) - if the target device is opened the first time, do initializtion - Identify the minor number and update the f_op pointer - allocate and fill data structure in filp->private data
  • 22. Open • The first step of open operation is to check the target device’s minor number.
  • 23. Release • Release anything that open operation allocate to flip->private_data. • Shut down the target device on the last close. • Decrease usage count
  • 24. Read and Write • flip : file pointer • buff : argument to the buffer in user-space • count : transfer data amount • offp : the file location ssize_t read(struct file *filp, char *buff, size_t count, loff_t *offp); ssize_t write(struct file *filp, const char *buff, size_t count, loff_t *offp);
  • 25. Read and Write • Data transfer between kernel space and user space. • Use the function defined in <asm/uaccess.h>
  • 26. Read and Write • The arguments to read
  • 27. Future Work • Read more • Ioctl