Using the /proc File System with - PowerPoint PPT Presentation

About This Presentation
Title:

Using the /proc File System with

Description:

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 ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 11
Provided by: Sara3201
Learn more at: http://www.cs.uni.edu
Category:
Tags: entry | file | mode | proc | system | using

less

Transcript and Presenter's Notes

Title: Using the /proc File System with


1
Using the /proc File System with scull
  • Sarah Diesburg
  • COP 5641

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

3
Implementing Files in /proc
  • include ltlinux/proc_fs.hgt
  • 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

4
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

5
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 lt scull_nr_devs len lt limit
    i)
  • struct scull_dev d scull_devicesi
  • struct scull_qset qs d-gtdata
  • if (down_interruptible(d-gtsem))
  • return -ERESTARTSYS
  • len
  • sprintf(buflen,"\nDevice i qset i, q
    i, sz li\n",
  • i, d-gtqset, d-gtquantum, d-gtsize)

6
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 lt scull_nr_devs len lt limit
    i)
  • struct scull_dev d scull_devicesi
  • struct scull_qset qs d-gtdata
  • if (down_interruptible(d-gtsem))
  • return -ERESTARTSYS
  • len
  • sprintf(buflen,"\nDevice i qset i, q
    i, sz li\n",
  • i, d-gtqset, d-gtquantum, d-gtsize)

start and offset not used
7
Implementing Files in /proc
  • / scan the list /
  • for ( qs len lt limit qs qs-gtnext)
  • len sprintf(buf len, " item at p,
    qset at p\n",
  • qs, qs-gtdata)
  • if (qs-gtdata !qs-gtnext) / dump only the
    last item /
  • for (j 0 j lt d-gtqset j)
  • if (qs-gtdataj)
  • len sprintf(buf len, " 4i
    8p\n", j,
  • qs-gtdataj)
  • up(scull_devicesi.sem)
  • eof 1
  • return len

8
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)

9
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)

10
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
Write a Comment
User Comments (0)
About PowerShow.com