当前位置:Linux教程 - Linux文化 - Kernel source code的介绍

Kernel source code的介绍


首先, 我们来看看, kernel source code 中有哪些目录:

69 ./fs/ext
26 ./fs/msdos
86 ./fs/proc
79 ./fs/minix
68 ./fs/isofs
142 ./fs/nfs
150 ./fs/ext2
76 ./fs/xiafs
133 ./fs/umsdos
69 ./fs/hpfs
101 ./fs/sysv
143 ./fs/smbfs
93 ./fs/fat
42 ./fs/vfat
95 ./fs/ncpfs
41 ./fs/ufs
95 ./fs/affs
1867 ./fs
26 ./init
174 ./kernel
53 ./lib
171 ./mm
1 ./include/linux/modules
1085 ./include/linux
4 ./include/asm-generic
197 ./include/asm-i386
265 ./include/asm-mips
198 ./include/asm-alpha
255 ./include/asm-m68k
344 ./include/asm-sparc
107 ./include/net
109 ./include/asm-ppc
11 ./include/scsi
2576 ./include
38 ./net/unix
30 ./net/802
68 ./net/appletalk
147 ./net/ax25
114 ./net/core
12 ./net/ethernet
620 ./net/ipv4
61 ./net/ipx
91 ./net/netrom
2 ./net/decnet
2 ./net/ipv6
55 ./net/bridge
1314 ./net
69 ./ipc
3031 ./drivers/net
814 ./drivers/block
348 ./drivers/char/ftape
1792 ./drivers/char
3063 ./drivers/scsi
1000 ./drivers/sound
35 ./drivers/pci
628 ./drivers/cdrom
80 ./drivers/isdn/icn
219 ./drivers/isdn/teles
104 ./drivers/isdn/pcbit
721 ./drivers/isdn
205 ./drivers/sbus/char
218 ./drivers/sbus
11305 ./drivers
1 ./modules
21 ./arch/i386/boot/compressed
8 ./arch/i386/boot/tools
96 ./arch/i386/boot
14 ./arch/i386/mm
369 ./arch/i386/math-emu
9 ./arch/i386/lib
185 ./arch/i386/kernel
684 ./arch/i386
9 ./arch/alpha/boot/tools
22 ./arch/alpha/boot
25 ./arch/alpha/lib
10 ./arch/alpha/mm
198 ./arch/alpha/kernel
48 ./arch/alpha/math-emu
316 ./arch/alpha
13 ./arch/sparc/boot
369 ./arch/sparc/kernel
81 ./arch/sparc/lib
139 ./arch/sparc/mm
40 ./arch/sparc/prom
652 ./arch/sparc
3 ./arch/mips/boot
12 ./arch/mips/mm
190 ./arch/mips/kernel
5 ./arch/mips/lib
224 ./arch/mips
35 ./arch/ppc/mm
156 ./arch/ppc/kernel
4 ./arch/ppc/boot
216 ./arch/ppc
263 ./arch/m68k/amiga
195 ./arch/m68k/atari
33 ./arch/m68k/boot/amiga
34 ./arch/m68k/boot/atari
69 ./arch/m68k/boot
533 ./arch/m68k/ifpsp060
208 ./arch/m68k/kernel
15 ./arch/m68k/lib
44 ./arch/m68k/mm
502 ./arch/m68k/fpsp040
314 ./arch/m68k/console
3 ./arch/m68k/tools/amiga
4 ./arch/m68k/tools
2163 ./arch/m68k
4256 ./arch
80 ./scripts/lxdialog
228 ./scripts
34 ./Documentation/filesystems
192 ./Documentation/networking
178 ./Documentation/cdrom
74 ./Documentation/isdn
917 ./Documentation
23049 .

这是 du 我的 /usr/src/linux (1.99.7) 所看到的。
以下我们来分析各子目录。


这些是 Linux 所支援的 file systems:

* ext2 : 这在 Linux 中是最重要的档案系统。
一般来讲 Linux 现在均使用它为主要的档案系统。

* ext, xiafs : 虽说这是 Linux 中很基本的档案系统, 但
这两个已经没什麽人在用了。

* proc : 这个是 Linux 依照 SysV 的 proc file system
来做的, 其中有一堆 processes information。

Root@Henry:/proc# ls
1/ 12263/ 12514/ 1893/ 3369/ kmsg
107/ 12264/ 12527/ 1909/ 4943/ ksyms
11007/ 12387/ 126/ 191/ 4944/ loadavg
11008/ 12389/ 132/ 1910/ 6/ locks
11009/ 12413/ 136/ 196/ 709/ mdstat
11010/ 12414/ 138/ 199/ 8906/ meminfo
11011/ 12415/ 141/ 2/ 8907/ misc
11176/ 12418/ 143/ 200/ 9886/ modules
11177/ 12423/ 146/ 201/ 9887/ mounts
112/ 12428/ 148/ 205/ 9889/ net/
116/ 12429/ 156/ 206/ cmdline pci
120/ 12473/ 160/ 208/ cpuinfo rtc
12004/ 12479/ 162/ 209/ devices scsi/
12030/ 12481/ 163/ 212/ dma self@
12031/ 12482/ 187/ 3/ filesystems stat
12139/ 12504/ 188/ 3066/ interrupts sys/
12141/ 12505/ 189/ 3296/ ioports uptime
122/ 12513/ 1891/ 3368/ kcore version

在此我们看个例子:

root@Henry:/proc# cat interrupts
0: 5862172 timer
1: 153446 keyboard
2: 0 cascade
3: 0 + serial
4: 156449 + serial
5: 5 SoundBlaster
8: 0 + rtc
9: 1172 aha1542
10: 613417 + aic7xxx
11: 371123 + eata_dma
12: 1540252 DE434/5 (eth0)
13: 1 math error
14: 3182 + ide0
15: 340720 + ide1

就可以知道 interrupts 0~15 的状态。很多 ps 类的程式
都是以此为基础来得知一些 processes information。

* msdos, fat, vfat : 可以使用 DOS/Windows95 用的档案系统。

* smbfs : 是 samba protocol, 可以使用 Windows Work Groups
export 出来的 file system。

* ncpfs : 是 NCP protocol, 可以 mount novell 的 volumn。

* nfs : 这是 Unix 上用的 network file system。

* isofs : 使用 iso file system, CDROM 的。

* minix : 现今 Linux 也很常用, 但是都用在软碟。

* sysv : System V and Coherent filesystem

* affs : Amiga FFS filesystem

* ufs : UFS filesystem (readonly) 为 BSD 及 SunOS 使用。

* hpfs : OS/2 HPFS filesystem

* umsdos: Unix like fs on top of std MSDOS FAT fs

除了这些 fs/ 下的子目录外, 有一些档案也是很重要的,
例如在 file system 中把一个档案载入要执行时, 会先
分辨出它是那一种执行格式 (a.out, elf, java, script)
再使用对应的执行方式。 或例如处理 dcache, buffer, fifo,
fcntl, file locks, quota, iotcl 等等和档案有关的控制。


再来看看 net/ 下有有些什麽。

* unix : AF_UNIX
* ipv4 : 就是 Linux 中的 TCP/IP 罗, 包括了 icmp, igmp, ip alias,
ip forward, route, arp, rarp.......等等。
* core : 包括了 multicast、firewall
* 802 : The 802.x protocol
* ethernet : ethernet & ethernet II
* ipx : The IPX protocol
* appletalk : Appletalk DDP
* ax25 : Amateur Radio AX.25 Level 2
* netrom : Amateur Radio NET/ROM
* bridge : Bridging (实验中)
* ipv6 及 decnet 尚在发展中

这就是我们硬体方面的重头戏了。

* net : 一堆网路卡的 drivers, 主要有 ne2000, D-link (DEC),
AMD 的、HP 的......等等, 甚至连 ArcNET 都支援。

* scsi : 这就是我们多工作业系统中的最爱了。
它所支援的类别有 Disk, Tape, CDROM, 及一般类。
卡 (host) 主要支援的有 AHA-152X/1542/1740/274X~294X/
3940/3985/2940U/UW、BusLogic、AdvanSys、DPT、NCR53c810
等常见的卡, 其中以 DPT 的稳定度最为人津津乐道, 而现在
的 2940 driver 也渐渐令人感到满意。 NCR 及 AMD 则令人
觉得便宜又大碗 (Tekram 390 有一型是用 AMD 的 chip)

* isdn : Linux 终於也开始支援 ISDN 的卡了, 这些 drivers 主要
是由一群德国人所发展的, 所以卡也是欧陆规格的, 计有:
ICN 2B and 4B、PCBIT-D、Teles/NICCY1016PC/Creatix。
而 synchronous PPP、VJ-compression with synchronous PPP、
generic MP (RFC 1717) 及 audio via ISDN 这些功能也做了。

* block : 这□主要是 IDE 类的 drivers, 包括了各类 ide chip,
ide-cd, ide-tape, floppy, 及 /dev/ 下各种 block
special device 的控制。

* cdrom : 这□放的是除了 SCSI 及 IDE 的 CDROM 外, 需要专用界
面及 drivers 的光碟机, 这些都是较旧的机型, 例如一票
单速、倍速的 AT-BUS 光碟机。

* sound : 这是音效卡的支援 drivers, 例如 SB16, UltraSound 这些
常见的都有支援, 但 PnP 类的卡都尚未支援。

* char : 这些是 character special device 类的 driver, 包括了
console, keyboard, pty/tty, 一些 mouse driver, real
time clock, lp 等等。 现今 Linux 已支援 256 个 pty
了 (但还要改 telnetd、rlogind 及 mknod 出新的 ptys)

* sbus : 是 Sun Sparc 的 sbus, 在此不介绍。


最後剩下这些我们一次介绍完。

* init : 就只有 main.c 及 version.c 这两个程式而已.

* kernel : □头主要是 fork, exec, exit, sched, signal
等等 kernel 的 resource control

* lib : 包括 ctype, errno, inflate(压缩、解压),
string, vsprintf 等工具。

* mm : Memory Management 类的东西, 包括了 filemap, mmap,
kmalloc, mlock, memory, page_io, swap 等等。

* ipc : Inter-Process Communications, 包括了 messages,
semaphores, share memory 等等。

* include : 一堆 include 档。

* arch : 机器(平台) 相关度很高的程式, 包括了 alpha, i386,
m68k, mips, ppc 及 sparc。

* script : 一些 compile 及 config 时要用到的工具 scripts。

* Documentation 最近放了很新、很值得一看的文件, 其中包括了重要的
注意事项 (例如 libc 换新), 各类 drivers 的说明等。

* modules : 这是在 make modules 後所放的 *.o 档, 尔後再打
make modules_install 後就可以安装在 /lib/modules
下了。

大略上来说, kernel source code 就是这麽回事。
--
Hanky@FruitTea1