linux源码组织

linux源代码在https://www.kernel.org/就可以下。现在的稳定版本是3.16.3.

因为简历上有个项目是内核有关的,为了准备一下面试,还是要重温一下内核才行。最基本的,哪些文件在哪个项目总要知道吧。。。

为什么还没有offer。。

tar没法直接角解压,只能先用xz解压,再用tar分开。整个压缩比还挺高的,xz文件是76.8MB,解压后是500多MB。

1 [email protected]:~# xz -d linux-3.16.3.tar.xz
2 [email protected]:~# tar xvf linux-3.16.3.tar

解压出来,根目录是这样子的。根目录下的目录大部分为操作系统的通用代码,drivers、arch下才是特殊的硬件处理。

 1 [email protected]:~/win7Download/linux-3.16.3# tree -L 1
 2 .
 3 ├── arch
 4 ├── block
 5 ├── COPYING
 6 ├── CREDITS
 7 ├── crypto
 8 ├── Documentation
 9 ├── drivers
10 ├── firmware
11 ├── fs
12 ├── include
13 ├── init
14 ├── ipc
15 ├── Kbuild
16 ├── Kconfig
17 ├── kernel
18 ├── lib
19 ├── MAINTAINERS
20 ├── Makefile
21 ├── mm
22 ├── net
23 ├── README
24 ├── REPORTING-BUGS
25 ├── samples
26 ├── scripts
27 ├── security
28 ├── sound
29 ├── tools
30 ├── usr
31 └── virt

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.

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.

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.

 1 [email protected]:~/win7Download/linux-3.16.3/arch# tree -L 1
 2 .
 3 ├── alpha
 4 ├── arc
 5 ├── arm
 6 ├── arm64
 7 ├── avr32
 8 ├── blackfin
 9 ├── c6x
10 ├── cris
11 ├── frv
12 ├── hexagon
13 ├── ia64
14 ├── Kconfig
15 ├── m32r
16 ├── m68k
17 ├── metag
18 ├── microblaze
19 ├── mips
20 ├── mn10300
21 ├── openrisc
22 ├── parisc
23 ├── powerpc
24 ├── s390
25 ├── score
26 ├── sh
27 ├── sparc
28 ├── tile
29 ├── um
30 ├── unicore32
31 ├── x86
32 └── 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. 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.

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. 这里有锁、共享内存、消息队列的代码。

1 [email protected]:~/win7Download/linux-3.16.3/ipc# ls
2 compat.c     ipcns_notifier.c  Makefile     mqueue.c  msgutil.c    sem.c  syscall.c  util.h
3 compat_mq.c  ipc_sysctl.c      mq_sysctl.c  msg.c     namespace.c  shm.c  util.c

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. 这里有Printk\trace等用于内核调试的代码。还有fork\time\irq\kthread\sigal等代码。

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. xz的加缩代码也在这。二分查找啊、位图、哈希啊、红黑树,很多代码。

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.DMA、swap、mmap、分页、分段都在这里有。slab分配器是Linux内存管理中非常重要和复杂的一部分。

内存管理的通用代码放在这,其处理器结构相关部分被放在arch/*/mm中。页面出错处理代码位于mm下的memory.c文件中而内存映射与页面cache代码位于filemap.c中。 swap cache位于mm/swap_state.c和mm/swapfile.c中。

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. 通用代码,协议等。

网络代码位于net目录而大多数包含文件位于include/net中。BSD套接口代码位于net/socket.c中。IPV4的INET套接口代码位于net/ipv4/af_inet.c中。通用协议支撑代码(包括sk_buff处理过程)位于net/core中,同时TCP/IP网络代码位于net/ipv4中。网络设备驱动位于drivers/net中。

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. 新的特性,这里一看有,kdb、kprobe之类的,不过都没实现。

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.  selinux的代码在这。

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. 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.

大部分摘自:http://www.linux.org/threads/the-linux-kernel-the-source-code.4204/

http://klinux.h.baike.com/article-80253.html

时间: 2024-11-02 00:38:27

linux源码组织的相关文章

从linux源码看epoll

从linux源码看epoll前言在linux的高性能网络编程中,绕不开的就是epoll.和select.poll等系统调用相比,epoll在需要监视大量文件描述符并且其中只有少数活跃的时候,表现出无可比拟的优势.epoll能让内核记住所关注的描述符,并在对应的描述符事件就绪的时候,在epoll的就绪链表中添加这些就绪元素,并唤醒对应的epoll等待进程.本文就是笔者在探究epoll源码过程中,对kernel将就绪描述符添加到epoll并唤醒对应进程的一次源码分析(基于linux-2.6.32内核

linux源码包的安装

一.基础知识    编译源程序的步骤:     # tar xf testapp-version.tar.{xz|bz2|gz}     # cd testapp-version     # ./configure      还需通过许多选项指定编译特性     # make     # make install    ./configure脚本的使用:     1.获取帮助      ./configure --help     2.较通用的一些选项      安装路径相关:       --

linux源码编译安装php出现 cannot find -lltdl

原因: 在编辑php时添加的“–with-mcrypt”选项造成. 解决方法: 1.如果不需要mcrypt,那么编辑php时去掉该选项,然后再make.make install. 2.如果需要mcrypt,那么需要安装libltdl libltdl在libmcrypt软件包中就有,具体过程: #cd /software/libmcrypt-2.5.8/libltdl #./configure –enable-ltdl-install #make #make install 这个时候再回到php的

用linux源码构建xen的domU

linux源码版本linux-3.14,可以从https://www.kernel.org/获取. 由于已经有了dom0(fedora19),现在需要安装domU,domU可以用xen源码自带的miniOS,这个os是xen客户机的最小系统,有机会一定安装一下试试.这次我配置安装的是linux. 参考xen的wiki页 http://wiki.xenproject.org/wiki/Mainline_Linux_Kernel_Configs Configuring the Kernel for

linux源码升级内核

 当前环境: [[email protected] ~]# uname -r 2.6.18-348.el5 配置流程: 1.准备yum库安装g++ gcc [[email protected] ~]# cat /etc/yum.repos.d/rh_5.9.repo [rhel-server] name=Red server baseurl=file:///misc/cd/Server enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM

如何从Linux源码获知版本信息

/*************************************************************************** * 如何从Linux源码获知版本信息 * 声明: * 本文主要在移植BQ27441-G1电量监测计驱动过程中,发现I2C获取的值有异常, * 之前移植官方的驱动发现驱动与当前版本的Linux版本好像是不兼容的,但没有进行 * 更进一步的深究,这里记录一下. * * 2016-2-15 深圳 南山平山村 曾剑锋 *****************

Linux源码学习(7) 2013-3-1

Linux源码学习(7) 2013-3-1 空间 内存管理Memory.c 主要用于内存分页管理.实现对主内存页面的动态分配和回收 Linux通过一个字节数组来管理所有的物理页面.每个字节用来表示其对应的物理页面被占用的次数 1. invalidate宏 :通过重新赋值CR3寄存的方法使CPU缓存的页表数据刷新.用于页表相关属性变化时 2. CODE_SPACE(addr)宏:判断addr是否位于当前进程的代码段 3. copy_page(from,to)宏 :复制一页内存 4. unsigne

Linux源码安装软件

Linux源码安装软件 源码安装:最原始最有效的安装方式 三部曲(1)—./configure xxx 生成makefile文件,随后需要的安装信息都是从这一步中获取 (2)make 根据makefile的指示开展编译工作,利用gcc将原始码编译为目标文件目标文件使用动态或静态函数库产生一个完整的可执行文件 (3)make install根据makefile文件里关于install的项目,将所编译完成的文件安装到指定目录一般有etc.lib.bin.man等目录 源码安装是费力不讨好的,这种方式

如何准备阅读Linux源码

Linux 0.11虽然不是什么"珠穆朗玛峰",但它肯定还是"华山"或"泰山".虽然有路但你还是需要最基本的努力和花费一定的代价才能"攀登"上去. 1. PC兼容机硬件工作原理(比如8259A,8253, 8042,UART等硬件):2. Intel 32位 运行模式工作原理,寻址方式:3. 传统C语言:4. 一些Intel asm基础.5. 会使用Linux操作系统,懂得Linux系统的基本操作. 推荐参考书籍: =====