Linux kernel device driver proc file system note collation

  • 2020-12-22 17:50:44
  • OfStack


/*****************
 * proc The file system 
 *****************/

(1) Features of /proc file system and description of /proc files

/proc file system is a special type of file system created by software, which is used by the kernel to export information to the outside world. /proc system only exists in memory, but does not occupy external memory space.

Each file under proc is bound to a kernel function that dynamically generates the contents of the file when the user reads it. Kernel parameters can also be modified by writing /proc files

File analysis under /proc /proc/$pid Information directory about the process $pid. Each process has a directory named its process number under /proc. Ex. : $ > strings -f /proc/[0-9]*/cmdline

/proc/cmdline kernel starts the command line /proc/cpuinfo processor information, such as type, manufacturer, model, and performance. /proc/devices lists the major device numbers of characters and block devices, as well as the device names assigned to them /proc/dma displays the DMA channel currently in use. /proc/filesystems lists the file system types that are available, usually encoded into the kernel, but new types can be added via modules /proc/interrupts displays the interrupt number used, the interrupt name, and the number of times these interrupts have been generated since the system started The I/O port currently in use. /proc/kallsyms kernel symbol table. After installing the new module, it will be shown here /proc/kcore system physical memory mapping. It's exactly the same size as physical memory, but it doesn't actually use that much memory. (Remember: nothing under proc takes up any disk space unless copied to a file.) /proc/kmsg kernel output message. Also sent to syslog. The average load of /proc/loadavg system, the first 3 is the load of the past 1 minute, 5 minutes, and 15 minutes, then the number of running tasks and the total number of tasks, and finally the process number of the last run /proc/meminfo memory usage information, including physical memory and swap. /proc/modules Which core modules are currently loaded. /proc/partitions system currently mounts partition information for the hard disk pci bus information for proc/pci system /proc/net Network protocol status information. Symbolic link from /proc/self to the process directory of the program viewing /proc. When two processes view /proc, they are different connections. This mainly makes it easier for the program to get its own process directory. /proc/slabinfo system slab cache allocation information proc/stat system 1 some status information /proc/swaps system uses the exchange area information /proc/ ES73en-ES74en is used to start the sysRq key $ > echo 1 > sysrq-trigger /proc/uptime System boot time and idle time. For the use of uptime /proc/version kernel version

(2) Self-implement 1 /proc file

A header file needs to be included < linux/proc_fs.h > , function definition in the/fs proc/generic c

a. Create the file under /proc

Call create_proc_read_entry to create a new file under /proc


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)

b. Uninstalls files under /proc

proc file is unmounted using remove_proc_entry


void remove_proc_entry(
    const char *name, 
    struct proc_dir_entry *parent);

c. Defines the function that returns the data

When the process reads the /proc file, the kernel allocates a memory page (that is, an PAGE_SIZE byte memory block) through which the data to be written is driven back to user space.


typedef int (read_proc_t)(char *page, char **start, off_t off,
int count, int *eof, void *data);

conclusion


Related articles: