PAGEFLOP
FORWARD
SELECTOR
SELAGAIN
WRONGSEL
YOUR SELECTION IS NOT IN THE 0 - #SELIMIT RANGE Please Try Again
AANVANG
Copyright CourseWare Technologies Inc. 1985-88
Lesson - 5
THE INTERNAL STRUCTURE OF UNIX
MENU
Internal Structure|Topics to Learn|5-0|10,38
# Topic
--- -------
1 - Booting Your System
2 - UNIX Kernel Structure
3 - The Swapping Process
4 - Managing Processes
5 - Managing I/O
6 - File System Structure
7 - Lesson Review
0 - Return to the Main Menu
P1
Internal Structure|Booting Your System|5-1.1|15,56
When you start or boot your UNIX system, two
processes are created:
* swapper
* init
At this point the system is in single-user mode,
that is, it accepts only those commands entered at the
console terminal. No other user is allowed to log on.
The process swapper executes only the kernel
functions and takes care of swapping the processes
between the primary and the secondary memory.
P2
Internal Structure|Booting Your System|5-1.2|13,54
The process init creates one process for each
terminal attached to the system. This allows other
users to log on.
All other processes on the system will be created
by a low-level function called fork() (which will
be covered in a later lesson).
The process identification number (PID) for the
process swapper is 0. The PID for the init process
is 1.
P3
Internal Structure|Booting Your System|5-1.3|14,54
If you are on a multi-user UNIX system, and
you want to change from the single-user mode to
multi-user mode, the following actions occur:
1. You must enter <CONTROL-d> to terminate the
single-user session.
2. This causes the init process to invoke the
file /etc/rc.
3. /etc/rc is a shell script containing commands to
start the processes update (which synchronizes the
file system), cron (the constant process scheduler),
and sh (the login shell).
P4
Internal Structure|Kernel Structure|5-2.1|12,56
The kernel assures the interaction of the physical
resources (processor, memory, peripherals) and the
software (processes and files).
Normally, the kernel is made up of about 1000 lines
of assembler code and 10000-12000 lines of C code.
The actual kernel size varies between 40K bytes
and 90K bytes, depending on the peripheral configuration
of your machine and your system's parameters.
P5
Internal Structure|Kernel Structure|5-2.2|15,58
UNIX provides the user with many functions or
system calls.
These functions are normally called from a C program.
When functions execute kernel-level utilities,
like writing to peripheral devices, they are said to
operate in kernel mode.
When functions execute user-level utilities, like
listing a directory or printing a file, they are said
to operate in user mode.
P6
Internal Structure|Swapping Process|5-3.1|17,54
Swapping is the process of transferring a
program between primary and secondary memory.
The process called swapper controls this
swapping procedure.
The process with the longest residence in the
primary memory is the most likely candidate to be
swapped.
A program normally occupies a contiguous space
and is stored in the secondary memory according to
the first-fit algorithm, i.e., it will be placed in
the first available space large enough to hold it.
P7
Internal Structure|Managing Processes|5-4.1|16,56
Every process has a certain priority assigned to it.
Every process has higher priority in kernel mode
than in user mode.
The allocation algorithm that assigns memory
has the following responsibilities:
* It must guarantee a satisfactory response to
external events like program termination.
* It must assign priorities to the interactive
processes.
* It must control the amount of time allocated to
each process.
P8
Internal Structure|Managing Processes|5-4.2|14,58
In kernel mode the process priority is adjusted
depending upon the event to which the process responds.
The priority will be higher for serving the system disk
than for serving slower peripheral devices like terminals.
Processes are executed in primary memory one
after another, in sequence, with each program being
allocated a specific amount of time (known as a
round robin).
The priority of a process is inversely proportional
to the time spent in the primary memory.
P9
Internal Structure|Managing I/O|5-5.1|13,54
The management of I/O is based on two types of
devices:
* those that support block transfer
(parallel devices like a disk drive), and
* those that support serial or asynchronous transfer
(like terminals).
Each device has a device driver (a special file)
associated with it (see your reference manual). Each
device file has both a major and minor device number
associated with it.
P10
Internal Structure|Managing I/O|5-5.2|13,54
The first number (major) indicates the type of the
controller and the second number (minor) indicates the
device ID controlled by that controller.
In the output of ls -l below, for example, hd0a
is a logical device with a controller whose device ID
is 1 and whose disk partition ID is 47. rfd096 has a
controller whose device ID is 2 and whose disk partition
ID is 52.
brw------- 1 root root 1, 47 Apr 17 1987 hd0a
crw-rw-rw- 2 root root 2, 52 Aug 30 18:21 /dev/rfd096ds15
P11
Internal Structure|Managing I/O|5-5.3| 15,54
The mkconf device driver or handler performs
the actual data transfer.
The block transfer involves 1 block (512 bytes
or 1024 bytes on System V and 4096 bytes on 4.3 BSD)
While the disk is a block-type device and
the terminal is a character or serial-type device,
a magnetic tape is neither!
The data on a magnetic tape may be read or
written in either in blocks (i.e., 512 bytes) or in
raw mode, 1 byte at a time.
P12
Internal Structure|File System Structure|5-6.1|14,54
A file system is a complete directory structure,
all files of which live under the root directory.
One or more file systems reside on a physical
device like a disk.
Every file system has four basic parts:
* the boot block
* the super block
* inodes,
* data blocks
P13
Internal Structure|File System Structure|5-6.2|11,54
One of the essential functions of the file system
is to establish a correspondence between the file name
and its place in the file system tree and its physical
representation.
Directory files hold records that contain two
pieces of information about each file in the directory:
* the file name (up to 14 characters long) and
* the file's inode number.
P14
Internal Structure|File System Structure|5-6.3|8,54
An inode is the file descriptor record which
contains information about:
* the file location
* the file length
* the access mode (file protection)
* the relevant dates
* the owner of the file
P15
Internal Structure|File System Structure|5-6.4|16,54
The 0th block of the file system is called the
boot block and is reserved for the bootstrap program.
The 1st block is the file system header or the
super block, which contains information about:
* the size of the file system
* the number of inodes in the file system
* several parameters about the free list
( the list of free inodes).
The inodes are stored in the file system starting
at block two.
P16
Internal Structure|File System Structure|5-6.5|8,54
File systems of different sizes contain different
numbers of inodes; the exact count is stored in the
super block.
Since inodes are fixed in size and are numbered
consecutively from zero, it is possible to locate any
inode given its inode number.
P17
Internal Structure|File System Structure|5-6.6|12,58
The data blocks of a file may be physically scattered
throughout the disk, but logically the blocks form a long
chain which contains the information in the file.
In addition to the information on the file length,
file owner, access mode and the relevant dates, the inode
also has a list of 13 disk block numbers stored in the inode.
The first 10 block numbers in the inode list specify
the first 10 blocks in the file.
P18
Internal Structure|File System Structure|5-6.7|10,54
If the file is longer than 10 blocks (5120 bytes),
then the 11th address entry holds the address of the
indirect block, which contains the list of the next 128
blocks.
For files longer than (128+10) = 138 blocks, the
12th entry in the inode list contains the address of a
double indirect block, which contains the addresses of
128 indirect blocks.
P19
Internal Structure|File System Structure|5-6.8|8,59
For files longer than 16522(10+128 + 128*128) blocks,
the 13th entry contains the address of a triple indirect
block which holds the addresses of 128 double indirect
blocks, thus a total of
(10 + 128 + 128*128 + 128*128*128) * 512 = 1 gigabyte
may be spanned by a UNIX file.
P20
Internal Structure|File System Structure|5-6.9|6,54
If a file uses 15,000 blocks, then to access those
blocks, the system would have to access:
* 1 double indirect block
* 117 indirect blocks
* 15000 (regular blocks)
P21
Internal Structure|Files System Structure|5-6.10|14,54
Let's look at how the system would access a file in the
directory ../parent/list
1. Fetch the inode for the current directory.
2. Use the information in the inode for the current
directory in order to fetch and search the current
directory for the name .. and retrieve its inode number.
3. Fetch the inode for ...
4. Use the information in the .. inode in order to
fetch and search the parent directory for the file
parent and retrieve its inode number . . .
P22
Internal Structure|Files System Structure|5-6.11|9,54
5. Fetch the inode for parent.
6. Use the information in the parent inode in order to
fetch and search the parent directory for the
file list.
7. Fetch the inode for the file list.
8. Access the file list.