LINUX KERNEL
Source overview
Makefile
This is the top-level Makefile of the Linux source tree
Most of the important variables and rules (like the gcc compilation flags) are defined here
Documentation/
The good news: This contains useful information about configuring your kernel
The bad news: It’s often out of date
More information helping with configuration can be found in Kconfig files in each directory
Also, several shell commands exist to help us obtain configuration information regarding our machine
arch/
Contains all architecture specific code
Each architecture has its own directory here (for instance i386 or x86)
• You shall also find low level memory management, interrupt handling and others here•When you compile your kernel, your bootable image (bzImage file) shall show up under arch/yourArchitecture/boot
crypto/
This is where the cryptographic API’s used by the kernel are kept
drivers/
Code for peripheral devices is generally stored under a subdirectory of drivers/
Subdirectories here include drivers/bluetooth, drivers/net (network card drivers) and others
fs/
The generic file system code (VFS contract) and the code for each different file system is stored here
Examples:
proc
sysfs
include/
Herein lie most of the header files any .c file within the kernel may use
Architecture specific header files are in the include/asm directory
init/
Here is where the main.c lies as well as code for creating the early user space*.
version.c can also be located here. This file defines the Linux version string
*early user space is a set of libraries and programs that provide services that are important enough to be availablewhen the kernel is coming up but perhaps not important enough to be in the kernel itself
ipc/
The acronym IPC stands for “Inter Process Communication”.
This directory contains code pertinent to shared memory, semaphores, mutex, etc
kernel/
Code that didn’t seem to belong to anywhere else in particular shall usually be stored here
The scheduler, signal handling code and printk() are just a few
The good news: Once you’re here, the file names are pretty descriptive
The bad news: This is the last place you are likely to look for anything
lib/
Code of general usefulness to the all kernel code is stored here
Useful string operations and command line parsing code may be found in this directory
mm/
High level memory management code can be found here.
Memory mapping of files takes all its code from files in this directory as do management of page caches, malloc and page swapping
net/
Here the high-level networking code is stored
The ancillary code used by most network protocols is found in net/core
The actual code for the protocols themselves is stored in subdirectories. Examples
net/ethernet
net/ipv6
scripts/
No actual kernel incorporated code is stored here. The scripts do, however help in building the kernel
For instance, the kconfig subdirectory there contains the code for running menuconfig
security/
Socket and network security
hooks as well as the different
Linux security models code
can be found in this directory
How to search for stuff
If we know the title of a given file or even a part of its name we can use the following command:
$ find –name \*string\*Where “string” is the substring we are looking for.This command shall return all the files that contain the substring “string”
If we want to find the code around some string that was printed (say “cannot mount hsd1 on 0xcfff”) we could do
$ grep –r “cannot mount hsd1 on” If all else fails, google is your friend