Using the /proc File System with “scull” Sarah Diesburg COP 5641.

Slides:



Advertisements
Similar presentations
RT_FIFO, Device driver.
Advertisements

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,
Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
Daemon Processes Long lived utility processes Often started at system boot and ended when system shuts down Run in the background with no controlling terminal.
CS 241 Section Week #5 2/23/12. 2 Topics This Section MP4 overview Function Pointers Pthreads File I/O.
The ‘system-call’ ID-numbers How can Linux applications written in assembly language create and access files?
Firewall Lab Zutao Zhu 02/05/2010. Outline Preliminaries getopt LKM /proc filesystem Netfilter.
CS 311 – Lecture 10 Outline Review open() and close() Difference between fopen() and open() File management system calls – read() – write() – lseek() –
1 System Calls and Standard I/O Professor Jennifer Rexford
CSE 451 Section 4 Project 2 Design Considerations.
Lecture 17 FS APIs and vsfs. File and File Name What is a File? Array of bytes. Ranges of bytes can be read/written. File system consists of many files,
Data Structures in the Kernel Sarah Diesburg COP 5641.
POSIX: Files Introduction to Operating Systems: Discussion 1 Read Solaris System Interface Guide: Ch. 5.1 Basic File I/O.
1 Week 6 Intro to Kernel Modules, Project 2 Sarah Diesburg Florida State University.
Lecture 3: System Calls & API Standards. Lecture 3 / Page 2AE4B33OSS Silberschatz, Galvin and Gagne ©2005 Contents Implementation of API System call types.
CSCC69: Operating Systems Assignment 3 Review. Assignment Review Implement the file-related system calls – open, close, dup2 – read, write, lseek – chdir,
Concurrency and Race Conditions Sarah Diesburg 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.
Debugging Techniques Ted Baker  Andy Wang COP 5641 / CIS 4930.
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?
Recitation 9: Error Handling, I/O, Man Andrew Faulring Section A 4 November 2002.
1-1 NET+OS Software Group Flash API Multiple flash memory bank support New Flash API introduction Detailed Flash API Function presentation Supporting.
File System Review bottomupcs.com J. Kubiatowicz, UC Berkeley.
Kyu Ho Park Sept. 22, Lecture 4 proc file system(procfs) (Project 2 included) Sept.19,4pm.
Adv. UNIX: dirs/181 Advanced UNIX v Objectives –look at how to program with directories –briefly describe the UNIX file system Special.
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.
UNIX Files File organization and a few primitives.
1 Shared Memory. 2  Introduction  Creating a Shared Memory Segment  Shared Memory Control  Shared Memory Operations  Using a File as Shared Memory.
Files and Directories File types stat functions for file information
Linux Device Model Part 1
Operating Systems Process Creation
Debugging Techniques Ted Baker  Andy Wang COP 5641 / CIS 4930.
Today’s topic Access and manipulate meta data for files –File type, ownership, access permissions, access time, etc How to determine if a file is not there?
CSCI 330 UNIX and Network Programming Unit VII: I/O Management I.
Laface 2007 File system 2.1 Operating System Design Filesystem system calls buffer allocation algorithms getblk brelse bread breada bwrite iget iput bmap.
NCHU System & Network Lab Lab 14 File and Directory.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
CSCC69: Operating Systems Tutorial 10. Hints on testing Assignment 3 How to test tlb replacement algorithms? – Write a program that creates an array larger.
Recitation 9: Error Handling, I/O, Man Anubhav Gupta Section D.
January 7, 2003Serguei Mokhov, 1 File I/O System Calls Reference COMP 229, 444, 5201 Revision 1.2 Date: July 21, 2004.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Tarek Abdelzaher Vikram Adve CS241 Systems Programming System Calls and I/O.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
Pointer Lecture 2 Course Name: High Level Programming Language Year : 2010.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Virtual Filesystem.
Introduction to FUSE (File system in USEr space) Speaker:Zong-shuo Jheng Date:March 14, 2008.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level connection.Establishing.
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.
Files. FILE * u In C, we use a FILE * data type to access files. u FILE * is defined in /usr/include/stdio.h u An example: #include int main() { FILE.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
File table: a list of opened files Each entry contains: – Index: file descriptors – Pointer to the file in memory – Access mode File descriptor is a positive.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
OPERATING SYSTEMS COURSE THE HEBREW UNIVERSITY SPRING FUSE File System.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
Files in UNIX u UNIX deals with two different classes of files:  Special Files  Regular Files u Regular files are just ordinary data files on disk -
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 4: Managing File System State Dr. Xiao Qin Auburn University.
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
Linux Device Model A device model after 2.5
Linux Kernel Driver.
Scull device 사용 예 강서일( ) 최정욱( ).
Sarah Diesburg Operating Systems CS 3430
Unix File Interface int open(const char* path, int flags, mode_t permissions); ssize_t read(int fd, void* buffer, size_t count); ssize_t write(int fd,
null, true, and false are also reserved.
TCP Sockets Programming
CSE 333 – Section 3 POSIX I/O Functions.
File I/O (1) Prof. Ikjun Yeom TA – Mugyo
CSE 333 – Section 3 POSIX I/O Functions.
CSE 333 – Section 3 POSIX I/O Functions.
CSE 333 – Section 3 POSIX I/O Functions.
Presentation transcript:

Using the /proc File System with “scull” Sarah Diesburg COP 5641

Using the /proc Filesystem Exports kernel information Each file under /proc tied to a kernel function

Implementing Files in /proc #include For a read-only file, your driver must implement the following function int (*read_proc) (char *page, char **start, off_t offset, int count, int *eof, void *data); page points to a buffer with PAGE_SIZE bytes

Implementing Files in /proc start points to where to store the read data start == NULL indicates the offset is 0 eof points to an integer, which signals that it has no more data to return data is device-specific, for internal bookkeeping

Implementing Files in /proc int scull_read_procmem(char *buf, char **start, off_t offset, int count, int *eof, void *data) { int i, j, len = 0; int limit = count - 80; /* Don't print more than this */ for (i = 0; i < scull_nr_devs && len <= limit; i++) { struct scull_dev *d = &scull_devices[i]; struct scull_qset *qs = d->data; if (down_interruptible(&d->sem)) { return -ERESTARTSYS; } len += sprintf(buf+len,"\nDevice %i: qset %i, q %i, sz %li\n", i, d->qset, d->quantum, d->size);

Implementing Files in /proc int scull_read_procmem(char *buf, char **start, off_t offset, int count, int *eof, void *data) { int i, j, len = 0; int limit = count - 80; /* Don't print more than this */ for (i = 0; i < scull_nr_devs && len <= limit; i++) { struct scull_dev *d = &scull_devices[i]; struct scull_qset *qs = d->data; if (down_interruptible(&d->sem)) { return -ERESTARTSYS; } len += sprintf(buf+len,"\nDevice %i: qset %i, q %i, sz %li\n", i, d->qset, d->quantum, d->size); start and offset not used

Implementing Files in /proc /* scan the list */ for (; qs && len next) { len += sprintf(buf + len, " item at %p, qset at %p\n", qs, qs->data); if (qs->data && !qs->next) /* dump only the last item */ for (j = 0; j qset; j++) { if (qs->data[j]) { len += sprintf(buf + len, " % 4i: %8p\n", j, qs->data[j]); } up(&scull_devices[i].sem); } *eof = 1; return len; }

Creating Your /proc File To connect the read_proc function to /proc, call the following struct proc_dir_entry *create_proc_read_entry( const char *name, mode_t mode, struct proc_dir_entry *base, read_proc_t *read_proc, void *data); name : name of the /proc file Note: kernel does not check duplicate names mode : protection mask (0 for default)

Creating Your /proc File base : directory ( NULL for /proc root) read_proc : read function defined to access a kernel data structure data : ignored by the kernel, but passed to read_proc To make scull_read_procmem available, call the following create_proc_read_entry(“scullmem”, 0, NULL, scull_read_procmem, NULL);

Creating Your /proc File To remove scull_read_procmem, call the following remove_proc_entry(“scullmem”, NULL /* parent directory */); Note: /proc has no reference count Make sure that no one is reading the file