mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge pull request #284 from geekpi/master
[已翻译] 02 The Linux Kernel--The Source Code
This commit is contained in:
commit
2176d4b552
@ -1,136 +0,0 @@
|
||||
Translating---------------geekpi
|
||||
|
||||
02 The Linux Kernel: The Source Code
|
||||
================================================================================
|
||||
After the kernel source code is downloaded and uncompressed, users will see many folders and files. It may be a challenge trying to find a particular file. Thankfully, the source code is sorted in a specific way. This enables developers to find any given file or part of the kernel.
|
||||
|
||||
The root of the kernel source code contains the folders listed below.
|
||||
|
||||
arch
|
||||
block
|
||||
crypto
|
||||
Documentation
|
||||
drivers
|
||||
firmware
|
||||
fs
|
||||
include
|
||||
init
|
||||
ipc
|
||||
kernel
|
||||
lib
|
||||
mm
|
||||
net
|
||||
samples
|
||||
scripts
|
||||
security
|
||||
sound
|
||||
tools
|
||||
usr
|
||||
virt
|
||||
|
||||
There are also some files that are located in the root of the source code. They are listed in the table below.
|
||||
|
||||
**COPYING** - Information about licensing and rights. The Linux kernel is licensed under the GPLv2 license. This license grants anyone the right to use, modify, distribute, and share the source code and compiled code for free. However, no one can sell the source code.
|
||||
|
||||
**CREDITS** - List of contributors
|
||||
|
||||
**Kbuild** - This is a script that sets up some settings for making the kernel. For example, this script sets up a ARCH variable where ARCH is the processor type that a developer wants the kernel to support.
|
||||
|
||||
**Kconfig** - This script is used when developer configure the kernel which will be discussed in a later article.
|
||||
|
||||
**MAINTAINERS** - This is a list of the current maintainers, their email addresses, website, and the specific file or part of the kernel that they specialize in developing and fixing. This is useful for when a developer finds a bug in the kernel and they wish to report the bug to the maintainer that can handle the issue.
|
||||
|
||||
**Makefile** - This script is the main file that is used to compile the kernel. This file passes parameters to the compiler as well as the list of files to compile and any other necessary information.
|
||||
|
||||
**README** - This text file provides information to developers that want to know how to compile the kernel.
|
||||
|
||||
**REPORTING-BUGS** - This text document provides information on reporting bugs.
|
||||
|
||||
The coding for the kernel will be in files with the extension ".c", or ".h". The “.c” extension indicates that the kernel is written in C, one of many programming languages. The “.h” files are Header files, and they are also written in C. The header files contain code that many of the “.c” files use. This saves programmers' time because they can use the contained code instead of writing new code. Otherwise, a group of code that performs the same action would be in many or all of the “.c” files. That would also consume and waste hard drive space.
|
||||
|
||||
All of the files in the above listed folders are well organized. The folder names help developers to at least have a good guess on the contents of the folders. A directory tree and descriptions are provided below.
|
||||
|
||||
**arch** - This folder contains a Kconfig which sets up some settings for compiling the source code that belongs in this folder. Each supported processor architecture is in the corresponding folder. So, the source code for Alpha processors belong in the alpha folder. Keep in mind that as time goes on, some new processors will be supported, or some may be dropped. For Linux Kernel v3.9.4, these are the folders under arch:
|
||||
|
||||
alpha
|
||||
arc
|
||||
arm
|
||||
arm64
|
||||
avr32
|
||||
blackfin
|
||||
c6x
|
||||
cris
|
||||
frv
|
||||
h8300
|
||||
hexagon
|
||||
ia64
|
||||
m32r
|
||||
m68k
|
||||
metag
|
||||
microblaze
|
||||
mips
|
||||
mn10300
|
||||
openrisc
|
||||
parisc
|
||||
powerpc
|
||||
s390
|
||||
score
|
||||
sh
|
||||
sparc
|
||||
tile
|
||||
um
|
||||
unicore32
|
||||
x86
|
||||
xtensa
|
||||
|
||||
**block** – This folder holds code for block-device drivers. Block devices are devices that accept and send data in blocks. Data blocks are chunks of data instead of a continual stream.
|
||||
|
||||
**crypto** - This folder contains the source code for many encryption algorithms. For example, “sha1_generic.c” is the file that contains the code for the sha1 encryption algorithm.
|
||||
|
||||
**Documentation** - This folder contains plain-text documents that provide information on the kernel and many of the files. If a developer needs information, they may be able to find the needed information in here.
|
||||
|
||||
**drivers** - This directory contains the code for the drivers. A driver is software that controls a piece of hardware. For example, for a computer to understand the keyboard and make it usable, a keyboard driver is needed. Many folders exist in this folder. Each folder is named after each piece or type of hardware. For example, the bluetooth folder holds the code for bluetooth drivers. Other obvious drivers are scsi, usb, and firewire. Some drivers may be more difficult to find. For instance, joystick drivers are not in a joystick folder. Instead, they are under ./drivers/input/joystick. Keyboard and mouse drivers are also located in the input folder. The Macintosh folder contains code for hardware made by Apple. The xen folder contains code for the Xen hypervisor. A hypervisor is software or hardware that allows users to run multiple operating systems on a single computer. This means that the xen code would allow users to have two or more Linux system running on one computer at the same time. Users could also run Windows, Solaris, FreeBSD, or some other operating system on the Linux system. There are many other folders under drivers, but they are too numerous to mention in this article, but they will in a later article.
|
||||
|
||||
**firmware** - The firmware folder contains code that allows the computer to read and understand signals from devices. For illustration, a webcam manages its own hardware, but the computer must understand the signals that the webcam is sending the computer. The Linux system will then use the vicam firmware to understand the webcam. Otherwise, without firmware, the Linux system does not know how to process the information that the webcam is sending. Also, the firmware helps the Linux system to send messages to the device. The Linux system could then tell the webcam to refocus or turnoff.
|
||||
|
||||
**fs** - This is the FileSystem folder. All of the code needed to understand and use filesystems is here. Inside this folder, each filesystem's code is in its own folder. For instance, the ext4 filesystem's code is in the ext4 folder. Within the fs folder, developers will see some files not in folders. These files handle filesystems overall. For example, mount.h would contain code for mounting filesystems. A filesystem is a structured way to store and manage files and directories on a storage device. Each filesystem has its own advantages and disadvantages. These are due to the programming of the filesystem. For illustration, the NTFS filesystem supports transparent compression (when enabled, files are automatically compressed without the user noticing). Most filesystems lack this feature, but they could only possess this ability if it is programmed into the files in the fs folder.
|
||||
|
||||
**include** - The include folder contains miscellaneous header files that the kernel uses. The name for the folder comes from the C command "include" that is used to import a header into C code upon compilation.
|
||||
|
||||
**init** - The init folder has code that deals with the startup of the kernel (INITiation). The main.c file is the core of the kernel. This is the main source code file the connects all of the other files.
|
||||
|
||||
**ipc** - IPC stands for Inter-Process Communication. This folder has the code that handles the communication layer between the kernel and processes. The kernel controls the hardware and programs can only ask the kernel to perform a task. Assume a user has a program that opens the DVD tray. The program does not open the tray directly. Instead, the program informs the kernel that the tray should be opened. Then, the kernel opens the tray by sending a signal to the hardware. This code also manages the kill signals. For illustration, when a system administrator opens a process manager to close a program that has locked-up, the signal to close the program is called a kill signal. The kernel receives the signal and then the kernel (depending on which type of kill signal) will ask the program to stop or the kernel will simply take the process out of the memory and CPU. Pipes used in the command-line are also used by the IPC. The pipes tell the kernel to place the output data on a physical page on in memory. The program or command receiving the data is given a pointer to the page on memory.
|
||||
|
||||
**kernel** - The code in this folder controls the kernel itself. For instance, if a debugger needed to trace an issue, the kernel would use code that originated from source files in this folder to inform the debugger of all of the actions that the kernel performs. There is also code here for keeping track of time. In the kernel folder is a directory titled "power". Some code in this folder provide the abilities for the computer to restart, power-off, and suspend.
|
||||
|
||||
**lib** - the library folder has the code for the kernel's library which is a set of files that that the kernel will need to reference.
|
||||
|
||||
**mm** - The Memory Management folder contains the code for managing the memory. Memory is not randomly placed on the RAM. Instead, the kernel places the data on the RAM carefully. The kernel does not overwrite any memory that is being used or that holds important data.
|
||||
|
||||
**net** - The network folder contains the code for network protocols. This includes code for IPv6 and Appletalk as well as protocols for Ethernet, wifi, bluetooth, etc. Also, the code for handling network bridges and DNS name resolution is in the net directory.
|
||||
|
||||
**samples** - This folder contains programming examples and modules that are being started. Assume a new module with a helpful feature is wanted, but no programmer has announced that they would work on the project. Well, these modules go here. This gives new kernel programmers a chance to help by going through this folder and picking a module they would like to help develop.
|
||||
|
||||
**scripts** - This folder has the scripts needed for compiling the kernel. It is best to not change anything in this folder. Otherwise, you may not be able to configure or make a kernel.
|
||||
|
||||
**security** - This folder has the code for the security of the kernel. It is important to protect the kernel from computer viruses and hackers. Otherwise, the Linux system can be damaged. Kernel security will be discussed in a later article.
|
||||
|
||||
**sound** - This directory has sound driver code for sound/audio cards.
|
||||
|
||||
**tools** - This directory contains tools that interact with the kernel.
|
||||
|
||||
**usr** - Remember the vmlinuz file and similar files mentioned in the previous article? The code in this folder creates those files after the kernel is compiled.
|
||||
|
||||
**virt** - This folder contains code for virtualization which allows users to run multiple operating systems at once. This is different from Xen (mentioned previously). With virtualization, the guest operating system is acting like any other application within the Linux operating system (host system). With a hypervisor like Xen, the two operating systems are managing the hardware together and the same time. In virtualization, the guest OS runs on top of the Linux kernel while in a hypervisor, there is no guest OS and all of the operating systems do not depend on each other.
|
||||
|
||||
Tip: Never move a file in the kernel source unless you know what you are doing. Otherwise, the compilation with fail due to a "missing" file.
|
||||
|
||||
The Linux kernel folder structure has remained relatively constant. The kernel developers have made some modifications, but overall, this setup is the same throughout all kernel versions. The driver folder's layout also remains about the same.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.linux.org/threads/the-linux-kernel-the-source-code.4204/
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
4
sources/The Linux Kernel/03 The Linux Kernel--Drivers.md
Normal file → Executable file
4
sources/The Linux Kernel/03 The Linux Kernel--Drivers.md
Normal file → Executable file
@ -1,3 +1,5 @@
|
||||
translating-------------------geekpi
|
||||
|
||||
03 The Linux Kernel: Drivers
|
||||
================================================================================
|
||||
Drivers are small programs that enable the kernel to communicate and handle hardware or protocols (rules and standards). Without a driver, the kernel does not know how to communicate with the hardware or handle protocols (the kernel actually hands the commands to the BIOS and the BIOS passes them on the the hardware). The Linux Kernel source code contains many drivers (in the form of source code) in the drivers folder. Each folder within the drivers folder will be explained. When configuring and compiling the kernel, it helps to understand the drivers. Otherwise, a user may add drivers to the kernel that they do not need or leave out important drivers. The driver source code usually includes a commented line that states the purpose of the driver. For example, the source code for the tc driver has a single commented line that says the driver is for TURBOchannel buses. Because of the documentation, users should be able to look at the first few commented lines of future drivers to learn their purpose.
|
||||
@ -232,4 +234,4 @@ via: http://www.linux.org/threads/the-linux-kernel-drivers.4205/
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
136
translated/02 The Linux Kernel--The Source Code.md
Executable file
136
translated/02 The Linux Kernel--The Source Code.md
Executable file
@ -0,0 +1,136 @@
|
||||
02 Linux 内核: 源代码
|
||||
================================================================================
|
||||
在下载并解压内核源代码后,用户可以看到许多文件夹和文件。尝试去找一个特定的文件或许是一个挑战。谢天谢地,源代码以一个特定的方式排序。这使开发者能够轻松找到任何文件或者内核的一部分
|
||||
|
||||
内核源代码的根目录下包含了以下文件夹
|
||||
|
||||
arch
|
||||
block
|
||||
crypto
|
||||
Documentation
|
||||
drivers
|
||||
firmware
|
||||
fs
|
||||
include
|
||||
init
|
||||
ipc
|
||||
kernel
|
||||
lib
|
||||
mm
|
||||
net
|
||||
samples
|
||||
scripts
|
||||
security
|
||||
sound
|
||||
tools
|
||||
usr
|
||||
virt
|
||||
|
||||
这里另外还有一些文件在源代码的根目录下。它们在下表中列出。
|
||||
|
||||
**COPYING** -许可和授权信息。Linux内核在GPLv2许可证下授权。该许可证授予任何人有权免费去使用、修改、分发和共享源代码和编译代码。然而,没有人可以出售源代码。
|
||||
|
||||
**CREDITS** - 贡献者列表
|
||||
|
||||
**Kbuild** - 这是一个设置一些内核设定的脚本。打个比方,这个脚本设定一个ARCH变量,ARCH是处理器的类型,这是一个开发者想要内核支持的类型。
|
||||
|
||||
**Kconfig** - 这个脚本会在开发人员配置内核的时候用到,这会在以后的文章中讨论。
|
||||
|
||||
**MAINTAINERS** - 这是一个目前维护者列表,他们的电子邮件地址,主页,和特定的文件或者他们正在从事的开发和修复的内核的一部分。这对当一个开发者在内核中发现一个问题并希望能够报告这个问题给能够处理这个问题的维护者时是很有用的。
|
||||
|
||||
**Makefile** - This script is the main file that is used to compile the kernel. This file passes parameters to the compiler as well as the list of files to compile and any other necessary information.
|
||||
这个脚本是编译内核主文件。这个文件将编译参数和编译所需的文件和必要的信息传给编译器
|
||||
|
||||
**README** - 这个文档提供给开发者想要知道的如何编译内核的信息。
|
||||
|
||||
**REPORTING-BUGS** - 这个文档提供如何报告问题的信息。
|
||||
|
||||
为内核的代码是以“.c”或“.h”为扩展名的文件。 “.c”的扩展名表明内核是用众多的编程语言之一C写的, “h”的文件是头文件,而他们也是用C写成。头文件包含了许多“.c”文件需要使用的代码。,因为他们可以使用已经存在的代码而不是编写新的代码,这节省了程序员的时间。否则,一组执行相同的动作的代码,将存在许多或全部都是“c”文件。这也会消耗和浪费硬盘空间。
|
||||
|
||||
所有上面列出的文件夹中的文件都有良好的组织。文件夹名称至少可以帮助开发人员很好地猜测文件夹中的内容。下面提供了一个目录树和描述。
|
||||
|
||||
**arch** - This folder contains a Kconfig which sets up some settings for compiling the source code that belongs in this folder. Each supported processor architecture is in the corresponding folder. So, the source code for Alpha processors belong in the alpha folder. Keep in mind that as time goes on, some new processors will be supported, or some may be dropped. For Linux Kernel v3.9.4, these are the folders under arch:
|
||||
此文件夹包含了编译代码所需的一系列设定的Kconfig文件。每个支持的处理器架构都在它相应的文件夹中。所以,Alpha处理器的源代码在alpha文件夹中。请记住,随着时间的推移,一些新的处理器将被支持,有些会被放弃。对于Linux v3.9.4,arch下有以下文件夹:
|
||||
alpha
|
||||
arc
|
||||
arm
|
||||
arm64
|
||||
avr32
|
||||
blackfin
|
||||
c6x
|
||||
cris
|
||||
frv
|
||||
h8300
|
||||
hexagon
|
||||
ia64
|
||||
m32r
|
||||
m68k
|
||||
metag
|
||||
microblaze
|
||||
mips
|
||||
mn10300
|
||||
openrisc
|
||||
parisc
|
||||
powerpc
|
||||
s390
|
||||
score
|
||||
sh
|
||||
sparc
|
||||
tile
|
||||
um
|
||||
unicore32
|
||||
x86
|
||||
xtensa
|
||||
|
||||
**block** – 此文件夹包含块设备驱动程序的代码。块设备是以块接收和发送的数据的设备。数据块都是大块的数据而不是持续的数据流。
|
||||
|
||||
**crypto** - 这个文件夹包含许多加密算法的源代码。例如,“sha1_generic.c”这个文件包含了SHA1加密算法的代码。
|
||||
|
||||
**Documentation** - 此文件夹包含了内核信息和其他许多文件信息的纯文本文档。如果开发者需要一些信息,他们可以在这里找到所需要的信息。
|
||||
|
||||
**drivers** - 该目录包含了驱动代码。驱动是一块控制硬件的软件。例如,要让计算机知道键盘并使其可用,键盘驱动器是必要的。这个文件夹中存在许多文件夹。每个文件夹都以硬件的种类或者型号命名。例如,'bluetooth'包含了蓝牙驱动程序的代码。还有其他明显驱动器像SCSI,USB和火线。有些驱动程序可能会比较难找到。例如,操纵杆驱动不在'joystick'文件夹中。相反,它们在./drivers/input/joystick。同样键盘和鼠标驱动也在这个文件夹中。 'Macintosh'包含了苹果的硬件代码。 'Xen'包含了Xen hypervisor代码。hypervisor是一种允许用户在一台计算机上运行多个操作系统的软件或硬件。这意味着在Xen允许用户在一台计算机上同时运行的两个或两个以上的Linux系统。用户还可以运行Windows,Solaris,FreeBSD或其他操作系统在Linux系统上。driver文件夹下还有许多其他的文件夹,但他们在这篇文章中无法一一列举,他们将在以后的文章中提到。
|
||||
|
||||
**firmware** - fireware中包含了让计算机读取和理解从设备发来的信号的代码。举例来说,一个摄像头管理它自己的硬件,但计算机必须了解摄像头给计算机发送的信号。Linux系统会使用vicam固件了解摄像头。否则,没有了固件,Linux系统将不知道如何处理摄像头发来的信息。另外,固件同样有助于将Linux系统发送消息给该设备。这样Linux系统可以告诉摄像头重新调整或关闭摄像头。
|
||||
|
||||
**fs** - 这是文件系统的文件夹。理解和使用的文件系统所需要的所有的代码就在这里。在这个文件夹里,每种文件系统都有自己的文件夹。例如,ext4文件系统的代码在ext4文件夹内。 在fs文件夹内,开发者会看到一些不在文件夹中的文件。这些文件用来处理文件系统整体。例如,mount.h中会包含挂载文件系统的代码。文件系统是以结构化的方式来存储和管理的存储设备上的文件和目录。每个文件系统都有自己的优点和缺点。这是由文件系统的编写决定的。举例来说,NTFS文件系统支持的透明压缩(当启用时,会在用户没注意的情况下自动压缩文件)。大多数文件系统缺乏此功能,但如果在fs文件夹里编入相应的文件,它们也有这种能力。
|
||||
|
||||
**include** - include包含了内核所需的各种头文件.这个名字来自于C语言用"incluide"来在编译时导入头文件.
|
||||
|
||||
**init** - init文件夹包含了内核启动处理代码(INITiation).main.c是内核的核心文件.这是用来链接其他文件的主要源代码文件.
|
||||
|
||||
**ipc** - IPC代表进程间通讯。此文件夹中的代码是作为内核与进程之间的通信层。内核控制着硬件因此程序只能请求内核来执行任务。假设用户有一个打开DVD托盘的程序。程序不直接打开托盘。相反,该程序通知内核托盘应该被打开。然后,内核给硬件发送一个信号去打开托盘。这些代码同样管理kill信号。举例来说,当系统管理员打开进程管理器去关闭一个已经锁死的程序,这个关闭程序的信号被称为kill信号。内核接收到信号,然后会要求程序停止(取决于kill的类型)或内核直接把进程从内存和CPU中移除。命令行中的管道同样用于进程间通信 。管道会告诉内核在某个内存页上写入输出数据。程序或者命令得到的数据是来自内存页上的某个给定指针.
|
||||
|
||||
**kernel** - 这个文件夹中的代码控制内核本身。例如,如果一个调试器需要跟踪问题,内核将使用这个文件夹中代码来将内核指令通知调试器。这里还有踪时间的代码。内核文件夹下有个"power"文件夹 。这个文件夹中的代码可以使计算机重新启动,关机,挂起。
|
||||
|
||||
**lib** - 这个文件夹包含了内核需要引用的一系列内核库文件代码
|
||||
|
||||
**mm** - mm文件夹中包含了内存管理代码。内存并不是随机放置在RAM上 。相反,内核小心地将数据放在RAM上。内核不会覆盖任何正在使用或保存重要数据的内存区域。
|
||||
|
||||
**net** - net文件夹中包含了网络协议代码。这包括IPv6,AppleTalk,以太网, WiFi,蓝牙等的代码,此外,处理网桥和DNS解析的代码也在net目录。
|
||||
|
||||
**samples** -此文件夹包含了程序示例和正在编写中的模块代码。假设一个新的模块引入了一个希望的功能,但没有程序员声明可以正常运行在内核上。那么,这些模块就会移到这里。这给了新内核程序员一个机会通过这个文件夹获得帮助并选择一个他们想要帮助开发的模块。
|
||||
|
||||
**scripts** -这个文件夹有内核编译所需的脚本。最好不要改变这个文件夹内的任何东西。否则,您可能无法配置或编译内核。
|
||||
|
||||
|
||||
**security** - 这个文件夹是有关内核安全的代码。它对计算机免于受到病毒和黑客的侵害很重要。否则,Linux系统可能会遭到损坏。关于内核的安全性,将在以后的文章中讨论。
|
||||
|
||||
**sound** - 这个文件夹中包含了声卡驱动。
|
||||
|
||||
**tools** - 这个文件夹中包含了和内核交互的文件。
|
||||
|
||||
**usr** - 还记得在以前的文章中提到vmlinuz和其他类似的文件么?这个文件夹中的代码在内核编译完成后创建这些文件。
|
||||
|
||||
**virt** -此文件夹包含了虚拟化代码,它允许用户一次运行多个操作系统。 这与先前提到的Xen是不同的。通过虚拟化,客户机操作系统就像任何其他运行在Linux主机的应用程序一样运行。通过hypervisor(注:虚拟机管理程序)如Xen,这两个操作系统同时管理硬件。在虚拟化中,在客户机操作系统上运行在Linux内核上,而在hypervisor中,它没有客户系统并且所有的系统不互相依赖。
|
||||
|
||||
提示: 决不在内核源代码内动文件,除非你知道你在做什么。否则,编译会由于缺失文件失败。
|
||||
|
||||
Linux内核的文件夹结构保持相对稳定。内核开发者已经做了一些修改,但总体来说,这种设置对整个内核版本相同。驱动程序文件夹的布局也保持基本相同。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.linux.org/threads/the-linux-kernel-the-source-code.4204/
|
||||
|
||||
译者:[geekpi](https://github.com/geekpi) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user