Linux core-15. Linux kernel resources

Source: Internet
Author: User
Article title: Linux core-15. Linux kernel resources. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Original: David A Rusling
Translation: Banyan & fifa
Chapter 2 Linux core resources
  
This chapter describes the Linux core resources used to find a special core function.
  
This book does not require readers to have C programming language capabilities or Linux core source code to understand how Linux core works. However, reading the core source code will deepen your understanding of the Linux operating system. This chapter provides a summary of the core source code.
  
Where can I get the Linux core source code?
All major Linux distribution versions (such as Craftworks, Debian, Slackware, and Redhat) include the source code. Generally, the core of your Linux system is constructed from these source codes. Due to some obvious factors, these source codes are more or less outdated. You can get the latest version of the website in the www-appendix Chapter. These sites include ftp://ftp.cs.helsinki.fi and all other mirror sites. The Linux source code on helsinki's WEB site is obviously the latest, but it will not be too far behind in MIT and Sunsite.
If you are unable to access these WEB sites, many cd rom manufacturers provide mirror discs for these WEB sites at very reasonable prices. Some manufacturers also provide subscription services that are updated quarterly or even every month. In addition, your local Linux user group is also a good resource.
  
The version number of the Linux core code is very simple. The core of any even number (such as 2.0.30) is a stable release, and the core of the number (such as 2.1.42) is the core of development. This book is based on stable version 2.0.30. The core of the development edition has all the latest features and supports the latest devices. Although they are not as stable as you want, it is very important for the Linux user group to try out the new core. Because they will complete these evaluations. The backup system is always advantageous when you try a non-release version of the core.
  
Core modifications are distributed by patch files. The patch utility is used to edit some core source code. For example, if you already have the 2.0.39 core code but want to upgrade it to 2.0.30, you can use the following command to modify the existing core after obtaining the 2.0.30 patch file:
  
$ Cd/usr/src/linux
$ Patch-p1 <patch-2.0.30
  
A site that collects core patches is a http://www.linuxhq.com.
  
Organization of core source code
At the top layer of the core source code is the/usr/src/linux Directory, under which you can see a large number of subdirectories:
  
Arch
This subdirectory contains all core code related to the architecture. It also contains subdirectories of each supported architecture, such as i386.
Include
This directory contains most include files used to reconstruct the core. Each supported architecture has a subdirectory. The asm subdirectory in this directory is a symbolic connection to a certain processor, such as include/asm-i386. To modify the processor structure, you only need to edit the core makefile and re-run the Linux core configuration program.
Init
This directory contains the core startup code.
Mm
This directory contains all the memory management code. The memory management code related to the specific architecture is located in the arch/*/mm Directory, such as arch/i386/mm/fault. c.
Drivers
All device drivers in the system are located in this directory. It is further divided into several types of device drivers, such as block.
Ipc
This directory contains the core inter-process communication code.
Modules
This directory only contains the created modules.
Fs
All file system code. It is also divided into subdirectories corresponding to different file systems, such as vfat and ext2.
Kernel
The main core code. At the same time, the code related to the processor structure is stored in the arch/*/kernel directory.
Net
The core network code.
Lib
This directory contains the core library code. The library code related to the processor structure is stored in the arch/*/lib/directory.
Scripts
This directory contains the script files used to configure the core (such as awk and tk scripts ).
  
Where to start
Reading complex programs like Linux core code is daunting. It is like a snowball. Reading a part of the core often involves several other related documents, and you will soon forget what you did. This section provides some tips.
  
System startup and initialization
In intelbased systems, linuxcan use loadlin.exe or LILO to load the core into the memory and pass the control to it. This part of the program is located in arch/i386/kerneld/head. S. This file completes some processor-related operations and jumps to the main () routine in init/main. c.
  
Memory management
This part of the code is mainly located in the mm directory, but the processor structure is included in arch/*/mm. The page error handling code is located in the memory. c file under mm, and the memory ING and page cache code are located in filemap. c. Buffer cache is implemented in mm/buffer. c. swap cache is located in mm/swap_state.c and mm/swapfile. c.
  
Core
Most common code is located in the kernel directory, and the processor-related code is stored in arch/*/kernel. The scheduler is located in kernel/sched. c, and the fork code is located in kernel/fork. c. The underlying processing code is located in include/linux/interrupt. h. The description of task_struct can be found in/linux/sched. h.
  
PCI
The PCI pseudo-device driver is located in drivers/pci. c and its general system definition is put in include/linux/pci. h. Each processor structure has a special pci bios code, where Alpha AXP is located in arch/alpha/kernel/bios32.c.
Inter-process communication
All the code is in the ipc directory. The system v ipc object contains an ipc_perm structure, which is described in include/linux/ipc. h. The system V message is implemented in ipc/msg. c. the shared message contains ipc/shm. c, and the signal lamp is located in ipc/sem. c. Pipelines are implemented in ipc/pipe. c.
  
Interrupt Handling
The core interrupt processing code is always related to the microprocessor structure. The interrupt handling code for an Intel System is located in arch/i386/kernel/irq. c and is defined in include/asm-i386/irq. h.
  
Device Driver
Most of the Linux core source code is device-driven. The driver source code of all Linux devices is stored in the drivers directory and divided into the following categories:
  
/Block
The block device drivers include the IDE (in ide. c) drivers. If you want to find the initialization process for these devices that can contain the file system, you should find the device_setup () in drivers/block/genhd. c (). When installing an nfs file system, you must not only initialize the hard disk but also the network. Block devices include IDE and SCSI devices.
  
/Char
This directory contains the drivers of character devices, such as ttys, serial ports, and mouse.
  
/Cdrom
Contains all Linux CDROM code. Some special CDROM devices (such as Soundblaster CDROM) can be found here ). The CD driver for the IDE interface is located in drivers/block/ide-cd.c while the scsi cd driver is located in drivers/scsi. c.
  
/Pci
It contains the source code of the PCI pseudo-device driver. The pci ing and initialization code of the PCI subsystem can be found here. In addition, the alpha axp pci patch code in arch/Alpha/kernel/bios32.c is also worth reading.
  
/Scsi
We can find all the SCSI codes and the device drivers of Linux-supported SCSI devices.
  
/Net
Contains the source code of the network driver, such as the DECChip 21040 PCI Ethernet driver in tulip. c.
/Sound
Source code of all sound card drivers.
  
File system
The source code of the EXT2 file system is located in fs/ext2, and its data structure definition is located in include/linux/ext2_fs.h, ext2_fs_ I .h, and ext2_fs_sb.h. The data structure of the virtual file system is described in include/linux/fs. h and its code is in fs. The core background processes of buffer cache and update are implemented in fs/buffer. c.
  
Network
The network code is located in the net directory, and most of the contained files are located in include/net. The BSD interface code is located in net/socket. c. The INET set interface code of IPV4 is located in net/ipv4/af_inet.c. Common protocols support code (including the sk_buff processing process) in the net/core, while TCP/IP network code in the net/ipv4. The network device driver is located in drivers/net.
  
Module
The code part of the core module is located in the core module package. The core code is located in kernel/modules. c, and its data structure and kernel background process kerneld messages are located in the include/linux/module. h and include/linux/kerneld. h directories. When necessary, check the elf file format in include/linux/ELF. h.
  
  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.