Scull device 사용 예 강서일(20059032) 최정욱(20059033).

Slides:



Advertisements
Similar presentations
A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Advertisements

DEVICE DRIVER VINOD KAMATH CS691X PROJECT WORK. Introduction How to write/install device drivers Systems, Kernel Programming Character, Block and Network.
Linux device-driver issues
RT_FIFO, Device driver.
Lecture for Lab 3, Exp1 of EE505 (Developing Device Driver) T.A. Chulmin Kim CoreLab. Mar, 11, 2011 [XenSchedulerPaper_Hotcloud-commits] r21 - /
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
USERSPACE I/O Reporter: R 張凱富.
File and I/O system calls int open(const char* path, int flags, mode_t modes) int creat(const char *path, mode_t mode) ssize_t read(int fd, void *buf,
LCS Non-Dynamic Version int function lcs (x, y, i, j) begin if (i = 0) or (j = 0) return 0; else if (x[i] = y[j]) return lcs(x, y, i-1, j-1)+1; else return.
Union, bitfield, typedef, enum union nama_u{ }; union nama_u{ struct nama_s byte; }; enum{ }; Tipedef var BYTE.
Linux Kernel Implementation of Pipes, FIFOs and other Filesystems Divye Kapoor B.Tech (IDD) CSI – IV
報告者 : 彭敏君 ANT 實驗室 2011/03/24 Concurrency and Race Conditions.
Character Driver Issues Implementing ‘/dev/physmem’
63 UQC152H3 Advanced OS Writing a Device Driver. 64 The SCULL Device Driver Simple Character Utility for Loading Localities 6 devices types –Scull-03.
CSSE221: Software Dev. Honors Day 27 Announcements Announcements Projects turned in? Projects turned in? The 2 required Angel surveys are due by 9 pm tonight.
EECS 498 Advanced Embedded Systems Lecture 4: Linux device drivers and loadable kernel modules.
Char Drivers Linux Kernel Programming CIS 4930/COP 5641.
Char Drivers Sarah Diesburg COP5641. Resources LDD Chapter 3 Red font in slides where up-to-date code diverges from book LDD module source code for 3.2.x.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
Kernel module programming Nezer J. Zaidenberg. reference This guide is built on top of The Linux Kernel Module Programming Guide The guide is available.
Interrupt Handling Sarah Diesburg COP Interrupt Handling One big responsibility of an operating system is to handle hardware connected to the machine.
Concurrency and Race Conditions Sarah Diesburg COP 5641.
Real-time Systems Lab, Computer Science and Engineering, ASU Linux Modules and Device Drivers (ESP – Fall 2014) Computer Science & Engineering Department.
Concurrency and Race Conditions Linux Kernel Programming CIS 4930/COP 5641.
1 UNIX System Programming v Objectives –look at how to program with directories –briefly describe the UNIX file system Directories and File System.
C questions A great programmer codes excellent code in C and Java. The code does video decoding. Java code works faster then C on my computer. how come?
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
Directory structure. Slide 2 Directory Structure  A directory ‘file’ is a sequence of lines; each line holds an i-node number and a file name.  The.
Using the /proc File System with “scull” Sarah Diesburg COP 5641.
Stepper Motor 디바이스 드라이버
Implementing System Calls CS552 Kartik Gopalan. CS552/BU/Spring2008 Steps in writing a system call 1.Create an entry for the system call in the kernel’s.
(language, compilation and debugging) David 09/16/2011.
Advanced Char Driver Operations Linux Kernel Programming CIS 4930/COP 5641.
K ERNEL D EVELOPMENT CSC585 Class Project Dawn Nelson December 2009.
Linux Device Driver 2009/04/08. Reference Book Another Reference Book Embedded Linux Primer: A Practical, Real-World Approach By Christopher Hallinan.
编写 Linux 下的设备驱动程序. What we have learned? 用 module 实现设备驱动程序 init_module, cleanup_module 设备也是文件;设备由主设备号、次设备号唯 一标识 mknod /dev/status c 0 登记 / 注销设备 register_chrdev,
Interfacing Device Drivers with the Kernel
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Ted Baker  Andy Wang COP 5641 / CIS 4930
Interrupt Handling Ted Baker  Andy Wang CIS 4930 / COP 5641.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
OS interface: file and I/O system calls File operations in C/C++? –fopen(), fread(), fwrite(), fclose(), fseek() in C f.open(…), f.close(…) in C++ I/O.
2009/12/8 Report 報告學生 : 黃健瑋 指導教授 : 李正帆 1. Content seq_file structure proc file Data structure(not completed) 2.
Finish up OS topics Group plans. Today Finish up and review Linux device driver stuff – Walk example again – See how it all goes together – Discuss talking.
Revisiting building. Preprocessing + Compiling 2 Creates an object file for each code file (.c ->.o) Each.o file contains code of the functions and structs.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
 LED 를 직접 제어하는 디바이스 드라이버를 작성해 보자  Reminder: LED 는 SPI 를 통해 ARM7 과 연결된다. ◦ 그렇다면 고쳐야 하는 코드는 어디에 ?  linux-2.6.x/arch/arm/mach-nds/arm7 ◦ Hardware spec.
Linux Device Model A device model after 2.5
Device Driver_Skeleton
Chapter 7-Android HAL 中国科学技术大学软件学院.
Introduction to Developing Embedded Linux Device Drivers
Operating Systems Moti Geva
Lecture 3 Module Programming and Device Driver (Homework#1 included)
Concurrency and Race Conditions
Linux Kernel Driver.
Advanced Char Driver Operations
NetSilicon & Digi Confidential
Operating System Hebrew University Spring 2004
null, true, and false are also reserved.
Govt. Polytechnic,Dhangar
chapter 3-Char Device Driver
CSE 333 – Section 3 POSIX I/O Functions.
Constructors and Destructors
CSE 333 – Section 3 POSIX I/O Functions.
Programming Language C Language.
Loadable Kernel Modules
Implementing System Calls
Review.
Linked Lists.
Presentation transcript:

scull device 사용 예 강서일(20059032) 최정욱(20059033)

목차 소스 코드 분석 예제 실행 및 결과 분석 Makefile scull.h main.c scull_load scull_init_module, scull_open, scull_write, scull_read scull_load scull_unload 예제 실행 및 결과 분석

소스 코드 분석 : Makefile main.c main.o pipe.c Makefile pipe.o access.c scull.h main.c main.o pipe.c Makefile pipe.o access.c access.o

소스 코드 분석 : scull.h #define SCULL_MAJOR 0 /* dynamic major by default */ #define SCULL_QUANTUM 4000 #define SCULL_QSET 1000 typedef struct Scull_Dev { void **data; struct Scull_Dev *next; /* next listitem */ int quantum; /* the current quantum size */ int qset; /* the current array size */ unsigned long size; devfs_handle_t handle; /* only used if devfs is there */ unsigned int access_key; /* used by sculluid and scullpriv */ struct semaphore sem; /* mutual exclusion semaphore */ } Scull_Dev; #define TYPE(dev) (MINOR(dev) >> 4) /* high nibble */ #define NUM(dev) (MINOR(dev) & 0xf) /* low nibble */

소스 코드 분석 : main.c 분석 대상 함수 int scull_init_module int scull_open ssize_t scull_write ssize_t scull_read

소스 코드 분석 : scull_init_module() int scull_init_module(void) { /////////////생략///////////// result = register_chrdev(scull_major, "scull", &scull_fops); if (result < 0) { printk(KERN_WARNING "scull: can't get major %d\n",scull_major); return result; } if (scull_major == 0) scull_major = result; /* dynamic */ return 0; /* succeed */

소스 코드 분석 : scull_open() int scull_open(struct inode *inode, struct file *filp) { Scull_Dev *dev; /* device information */ int num = NUM(inode->i_rdev); int type = TYPE(inode->i_rdev); if (!filp->private_data && type) { if (type > SCULL_MAX_TYPE) return -ENODEV; filp->f_op = scull_fop_array[type]; return filp->f_op->open(inode, filp); /* dispatch to specific open */ } if ( (filp->f_flags & O_ACCMODE) == O_WRONLY) { if (down_interruptible(&dev->sem)) { MOD_DEC_USE_COUNT; return -ERESTARTSYS; scull_trim(dev); /* ignore errors */ up(&dev->sem); return 0; /* success */

소스 코드 분석 : scull_trim() int scull_trim(Scull_Dev *dev) { Scull_Dev *next, *dptr; int qset = dev->qset; /* "dev" is not-null */ int i; for (dptr = dev; dptr; dptr = next) { /* all the list items */ if (dptr->data) { for (i = 0; i < qset; i++) if (dptr->data[i]) kfree(dptr->data[i]); kfree(dptr->data); dptr->data=NULL; } next=dptr->next; if (dptr != dev) kfree(dptr); /* all of them but the first */ dev->size = 0; dev->quantum = scull_quantum; dev->qset = scull_qset; dev->next = NULL; return 0;

소스 코드 분석 : scull_write()(1/3) ssize_t scull_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos) { Scull_Dev *dev = filp->private_data; Scull_Dev *dptr; int quantum = dev->quantum; int qset = dev->qset; int itemsize = quantum * qset; int item, s_pos, q_pos, rest; ssize_t ret = -ENOMEM; if (down_interruptible(&dev->sem)) return -ERESTARTSYS;

소스 코드 분석 : scull_write()(2/3) item = (long)*f_pos / itemsize; rest = (long)*f_pos % itemsize; s_pos = rest / quantum; q_pos = rest % quantum; dptr = scull_follow(dev, item); if (!dptr->data) { dptr->data = kmalloc(qset * sizeof(char *), GFP_KERNEL); if (!dptr->data) goto out; memset(dptr->data, 0, qset * sizeof(char *)); } if (!dptr->data[s_pos]) { dptr->data[s_pos] = kmalloc(quantum, GFP_KERNEL); if (!dptr->data[s_pos])

소스 코드 분석 : scull_write()(3/3) if (count > quantum - q_pos) count = quantum - q_pos; if (copy_from_user(dptr->data[s_pos]+q_pos, buf, count)) { ret = -EFAULT; goto out; } *f_pos += count; ret = count; if (dev->size < *f_pos) dev-> size = *f_pos; out: up(&dev->sem); return ret;

소스 코드 분석 : scull_load module="scull" device="scull" mode="664" /sbin/insmod -f ./$module.o $* || exit 1 major=`cat /proc/devices | awk "\\$2==\"$module\" {print \\$1}"` rm -f /dev/${device}[0-3] mknod /dev/${device}0 c $major 0 mknod /dev/${device}1 c $major 1 mknod /dev/${device}2 c $major 2 mknod /dev/${device}3 c $major 3 ln -sf ${device}0 /dev/${device} chgrp $group /dev/${device}[0-3] chmod $mode /dev/${device}[0-3] ////////////////////////이하 생략////////////////////////

소스 코드 분석 : scull_unload module="scull" device="scull" /sbin/rmmod $module $* || exit 1 rm -f /dev/${device} /dev/${device}[0-3] rm -f /dev/${device}priv rm -f /dev/${device}pipe /dev/${device}pipe[0-3] rm -f /dev/${device}single rm -f /dev/${device}uid rm -f /dev/${device}wuid

예제 실행 및 결과 분석(1/3)

예제 실행 및 결과 분석(2/3)

예제 실행 및 결과 분석(3/3)