proc file system - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

proc file system

Description:

Is a special file system in the linux kernel. ... the function will return a pointer to the freshly created struct proc_dir_entry ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 10
Provided by: jennif69
Category:
Tags: file | freshly | proc | system

less

Transcript and Presenter's Notes

Title: proc file system


1
/proc file system
  • CS 397 Network Systems Lab
  • Jennifer Hou

2
Overview
  • The /proc file system (procfs)
  • Is a special file system in the linux kernel.
  • Is a virtual file system that is not associated
    with a block device but exists only in memory.
  • allows programs in the user space to access to
    certain information from the kernel.

3
/proc File System Entries
  • To use any of the procfs functions, you have to
    include the correct header file! include
    ltlinux/proc_fs.hgt
  • struct proc_dir_entry create_proc_entry(const
    char name, mode_t mode, struct proc_dir_entry
    parent)
  • This function creates a regular file with the
    name name, the mode mode in the directory parent.
  • To create a file in the root of the procfs, use
    NULL as parent parameter.
  • When successful, the function will return a
    pointer to the freshly created struct
    proc_dir_entry
  • foo_file create_proc_entry(foo, 0644,
    example_dir)


4
Creating a Directory and a Symlink
  • struct proc_dir_entry proc_mkdir(const char
    name, struct proc_dir_entry parent)
  • Create a directory name in the procfs directory
    parent.
  • struct proc_dir_entry proc_symlink(const char
    name, struct proc_dir_entry parent, const char
    dest)
  • This creates a symlink in the procfs directory
    parent that points from name to dest. This
    translates in userland to ln -s dest name.

5
Communication Between User Process Kernel
  • procfs works with call back functions for files
    functions that are called when a specific file is
    being read or written.
  • Such functions have to be initialized by setting
    the read_proc and/or write_proc fields in the
    struct proc_dir_entry that the function
    create_proc_entry returned
  • struct proc_dir_entry foo_file
  • foo_file-gtread_proc proc_read_foobar
  • foo_file-gtwrite_proc proc_write_foobar

6
Reading Data from Kernel
  • int read_func(char page, char start, off_t
    off, int count, int eof, void data)
  • The read function should write its information
    into the page.
  • The function should start writing at an offset of
    off in page and write at most count bytes.
  • eof should be used to signal that the end of the
    file has been reached by writing 1 to the memory
    location eof points to.

7
Writing Data into Kernel
  • The write call back function allows a user
    process to write data to the kernel.
  • int write_func(struct file file, const char
    buffer, unsigned long count, void data)
  • It reads count bytes at maximum from the buffer.
  • The buffer doesn't live in the kernel's memory
    space, and should first be copied to kernel space
    with copy_from_user.
  • The file parameter is usually ignored.

8
Reading Data from Kernel
  • struct proc_dir_entry create_proc_read_entry(cons
    t char name, mode_t mode, struct proc_dir_entry
    parent, read_proc_t read_proc, void data)
  • This function creates a regular file in exactly
    the same way as create_proc_entry, but also
    allows to set the read function read_proc in one
    call.

9
Removing an Entry
  • void remove_proc_entry(const char name, struct
    proc_dir_entry parent)
  • Removes the entry name in the directory parent
    from the procfs.
  • Be sure to free the data entry from the struct
    proc_dir_entry before remove_proc_entry is called
Write a Comment
User Comments (0)
About PowerShow.com