did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780201719758

Linux Kernel Programming

by ; ; ; ; ; ;
  • ISBN13:

    9780201719758

  • ISBN10:

    0201719754

  • Edition: 3rd
  • Format: Paperback
  • Copyright: 2002-08-22
  • Publisher: Addison-Wesley Professional
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $80.99

Summary

Preface to the 3rd edition

In a competition at this year's CeBIT, one of the questions was: which linux version came before version 0.95? I have to admit that I don't know the answer, but I know for sure that it was not 0.94.

This reminds us of the early days of linux, and the creative chaos that surrounded it. At that time it was a challenge for many co-developers of linux to understand and modify the sources of an operating system.

Since then, linux has not only reached the magical milestone of version 2.4, but also won a solid position in the highly competitive software field. With regard to the challenge of understanding an operating system, nothing has changed, in fact it has become even greater.

Many of the features added since the last milestone version not only embody the very simple functions of an operating system, but more and more functions which provide compatibility with large software products, support new hardware, or improve the performance of the system. Version 2.4 also offers exciting new concepts like IP tables and improved plug-and-play.

As with every new milestone of the linux kernel, a kernel book must also be revised to cover the new features. Despite big changes to interfaces and concepts, the book again gives an insight into the workings of linux. We hope you will not only enjoy reading it, but also enjoy experimenting with the linux kernel.

Michael Beck, Ulrich Kunitz, Harald Böhme,
Robert Magnus, Mirko Dziadzka, Claus Schröter
Berlin/Frankfurt/Furtwangen, 24. 4. 2001

Authors' preface to the 1st edition

linux has been around for about two years. What started as a programming exercise by the computer science student Linus Torvalds, has become one of the most successfulfree software projects of today, and gives serious competition to commercial systems. This is the result of the voluntary work of a worldwide programming community connected by the internet, an effective communication medium. The free availability of linux has contributed to its quick distribution. Therefore it is hard to estimate the number of linux users. In Germany there are more than ten thousand.

We discovered the linux system about 18 months ago. One result of this is that we now have a "correct" Unix system for our local PCs, without having to put thousands of dollars on the table, which, as students, we didn't have anyway.

The other, perhaps more important, benefit for us, and possibly for the majority of the linux community in the world, is the availability of the source code of the linux system. It is quite simply fun to root about in the internals of an operating system to try out your own ideas, and out of pure interest to adapt the system to your own wishes. This book is aimed at everybody who thinks the same way, but also at those who simply want to find out how a 32-bit operating system works.

The linux kernel has increased in size over time, and one can no longer obtain a good overview. Since the documentation is thin (the only documentation we know of is the outline of the linux Kernel Hackers Guide Joh95), in 1993 we started a linux seminar in the summer semester. Everybody involved in linux at our workplace, gave an insight into his or her area of interest, knowledge, and experience with "kernel hacking." In the seminar there were often discussions about modeling concepts, implementation variants, and implementation details, which were grasped in various ways. In the context of this seminar we began to write down our knowledge about the system, to make it simpler for others. This knowledge is revised and represented here.

As the development of linux progresses so quickly, we couldn't allow ourselves too much time to write the book. We therefore divided the book into chapters according to the respective area of interest of the authors. Ulrich Kunitz wrote the introduction, the chapter about memory management and the chapter about interprocess communication. Mirko Dziadzka took responsibility for the introduction to the kernel. Harald Bohme, our net expert, surely ought to have written a whole book explaining the network implementation extensively. He could only write an introduction to the matter here. The thankless task of working out the referencing of system calls and explaining system commands was given to Robert Magnus. The other authors split the rest of the chapters between them.

Identifiers from the source code are set in a sanserif font in the text. Parameters are set in an italic serif font. For example:
% make Argument

Since not all readers of this book have access to the internet, the enclosed CD contains the Slackware distribution 1.2.0 and German LST distribution 1.7. They allow you to install corresponding startup disks from the CD, which have been produced with the assistance of the MS-DOS programs GZIP.EXE and RAWRITE.EXE. The authors would like to express their thanks to Patrick J.Volkerding and the linux support team, consisting of Ralf Flaxa and Stefan Probst, for the very extensive work that has been put into this book.

The CD contains the linux-Kernel version 1.0.91 and the sources of the programs explained in Appendix B as well as the sources of the GNU C library and the G ++ library. It also contains texts from the linux Documentation Project and the internet RFCs. The files aren't compressed and can be integrated in the directory structure in linux using the mount command.

The contents of the book correspond to our present knowledge of the linux kernel 1.0 but this knowledge is not yet complete. We would be grateful for any corrections, suggestions, notes, and comments.

We can be reached by e-mail at this address: linux@informatik.hu-berlin.de

Those who do not have access to e-mail can write to us at: linux-Team
Humboldt-Universität zu Berlin
Institut für Informatik
10099 Berlin

Linus Torvalds' Preface to the 1st Edition

Creating an operating system has been (and still is) an exciting project, and has been made even more rewarding through the extensive (and almost uniformly positive) feedback from users and developers alike.

One of the problems for people wanting to get to know the kernel internals better has been the lack of documentation, and fledgling kernel hackers have had to resort to reading the actual source code of the system for most of the details. While I think that is still a good idea, I'm happy that there is now more documentation like this which explains the use of linux and its internals.

I hope you enjoy linux and this book.

Linus Torvalds
Helsinki, 28. 4. 1994

Acknowledgments

This book would not have been possible without the work of several other people.

First we would like to thank all the linux hackers in the world, and of course Linus Torvalds. A further thank you goes to the Free Software Foundation (also known as GNU). Without GNU software, linux would not be what it is today.

We would also like to thank the employees and students at the Institute of Computer Science of the Humboldt-University of Berlin and the Faculty of Computer Science at Furtwangen Technical College who have supported us in our work.

Finally we would like to thank the innumerable copy editors, first of all Ralf Kühnel; the meticulous corrections were a great help to us.

Martin von Löwis also deserves to be mentioned, as he gave constructive criticism and supported us in the implementation of the Windows NT file system for linux.

Have a good time reading and working with linux!
Michael Beck,
Ulrich Kunitz, Harald Böh

Author Biography

Michael Beck is the director of software development for the DResearch Digital Media Systems GmbH.  Harold Boehme teaches computer science at Humboldt University.  Ulrich Kunitz is a software project manager for Internet Banking Solutions.  Claus Schroeter works in the Chemie.De information service.

Table of Contents

Prefacep. xi
Preface to the 3rd editionp. xi
Preface to the 1st editionp. xii
Linus Torvalds' preface to the 1st editionp. xiii
Acknowledgmentsp. xiv
Linux - The Operating Systemp. 1
Main characteristicsp. 2
Linux distributionsp. 5
Compiling the Kernelp. 6
Where is everything?p. 6
Compilingp. 8
Additional configuration facilitiesp. 10
Introduction to the Kernelp. 12
Important data structuresp. 16
The task structurep. 16
The process tablep. 24
Files and inodesp. 25
Dynamic memory managementp. 27
Queues and semaphoresp. 28
System time and timersp. 30
Main algorithmsp. 31
Signalsp. 31
Hardware interruptsp. 32
Software interruptsp. 33
Booting the systemp. 34
Timer interruptsp. 36
The schedulerp. 39
Implementation of system callsp. 42
How do system calls actually work?p. 42
Examples of simple system callsp. 44
Examples of more complex system callsp. 45
Memory Managementp. 55
The architecture-independent memory modelp. 57
Pages of memoryp. 57
Virtual address spacep. 57
Converting the linear addressp. 59
Page directoriesp. 61
The page tablep. 63
The virtual address space of a processp. 65
The user segmentp. 65
Virtual memory areasp. 67
The system call brkp. 70
Mapping functionsp. 71
The kernel segmentp. 71
Memory allocation in the kernel segment during bootingp. 72
Dynamic memory management in the kernel segmentp. 72
Block device cachingp. 75
Block bufferingp. 75
Bdflush and kupdatep. 77
List structures for the buffer cachep. 78
Using the buffer cachep. 79
Paging under Linuxp. 80
Memory management and the memory cachep. 82
Reserving a page of memoryp. 84
Optimization of memory page management via kernel threadsp. 87
Page errors and reloading a pagep. 88
Interprocess Communicationp. 90
Synchronization in the kernelp. 92
Communication via filesp. 97
Locking entire filesp. 98
Locking file areasp. 99
Pipesp. 103
Debugging using ptracep. 105
System V IPCp. 108
Access rights, numbers, and keysp. 109
Semaphoresp. 110
Message queuesp. 114
Shared memoryp. 117
The ipcs and ipcrm commandsp. 120
IPC with socketsp. 121
A simple examplep. 122
The implementation of Unix domain socketsp. 126
The Linux File Systemp. 129
Basic principlesp. 130
The representation of file systems in the kernelp. 132
Mountingp. 134
The superblockp. 134
Superblock operationsp. 136
The directory cachep. 139
Dentry operationsp. 141
The inodep. 142
Inode operationsp. 144
The file structurep. 147
File operationsp. 148
Opening a filep. 152
The Ext2 file systemp. 156
The structure of the Ext2 file systemp. 156
Directories in the Ext2 file systemp. 159
Block allocation in the Ext2 file systemp. 160
Extensions of the Ext2 file systemp. 161
The Proc file systemp. 162
Structures of the Proc file systemp. 163
Implementation of the Proc file systemp. 164
Device Drivers Under Linuxp. 169
Character and block devicesp. 171
Hardwarep. 172
Port I/Op. 172
The PCI busp. 173
The dinosaur--the ISA busp. 184
ISA-PnPp. 193
Polling, interrupts, and waiting queuesp. 198
Pollingp. 199
Interrupt modep. 200
Interrupt sharingp. 201
Software interruptsp. 202
Bottom halves--the lower interrupt halvesp. 203
Task queuesp. 204
Timersp. 206
Implementing a driverp. 207
Example of a PC loudspeaker driverp. 207
A simple driverp. 210
The setup functionp. 212
Initp. 213
Open and releasep. 215
Read and writep. 216
IOCTLp. 219
Pollp. 221
Llseekp. 223
Mmapp. 223
Fasyncp. 225
Readdir, Fsyncp. 228
Dynamic and static driversp. 228
Network Implementationp. 230
Introduction and overviewp. 231
The layer model of the network implementationp. 232
Getting the data from A to Bp. 232
Important structuresp. 236
The socket structurep. 236
The sk_buff structure--buffer management in the networkp. 238
The INET socket--a special part of the socketp. 241
Protocol operations in the proto structurep. 246
The general structure of a socket addressp. 248
Network devices under Linuxp. 248
Ethernetp. 255
SLIP and PLIPp. 256
The loopback devicep. 257
The dummy devicep. 257
An example devicep. 257
Modules and Debuggingp. 261
What are modules?p. 261
Implementation in the kernelp. 262
Signatures of symbolsp. 264
The meaning of object sections for modules and kernelsp. 264
Parameter transfer and examplesp. 267
What can be implemented as a module?p. 268
The kernel daemonp. 270
Simple data swapping between modulesp. 270
An example modulep. 271
Debuggingp. 272
Changes are the beginning of the endp. 272
The best debugger--printk ()p. 273
Debugging with gdbp. 274
Multiprocessingp. 276
The Intel multiprocessor specificationp. 276
Problems with multiprocessor systemsp. 277
Changes to the kernelp. 278
Kernel initializationp. 278
Schedulingp. 279
Interrupt handlingp. 279
Atomic operationsp. 279
The atomic data typep. 280
Accessing the atomic data typep. 280
Changing and testing atomic variablesp. 280
Spin locksp. 281
Access functionsp. 281
Read-write spin locksp. 282
System Callsp. 283
Process managementp. 284
The file systemp. 329
Communicationp. 362
Memory managementp. 365
All that remainsp. 371
Kernel-Related Commandsp. 373
free--overview of the system's memoryp. 373
ps--output of process statisticsp. 374
top--the CPU chartsp. 378
init--primus inter paresp. 380
shutdown--shutting down the systemp. 388
strace--monitoring a processp. 389
Configuring the network interfacep. 392
traceroute--Ariadne's paths in the internetp. 393
Configuring a serial interfacep. 395
Configuring a parallel interfacep. 397
Building a directory treep. 398
The Proc File Systemp. 406
The /PROC/ directoryp. 406
The NET/ directoryp. 414
The SELF/ directoryp. 416
The SYS/ directoryp. 420
The Booting Processp. 423
Carrying out the booting processp. 423
LILO--the Linux loaderp. 425
Useful Kernel Functionsp. 434
Referencesp. 449
Indexp. 455
Table of Contents provided by Syndetics. All Rights Reserved.

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

Preface to the 3rd edition In a competition at this year's CeBIT, one of the questions was: which linux version came before version 0.95? I have to admit that I don't know the answer, but I know for sure that it was not 0.94. This reminds us of the early days of linux, and the creative chaos that surrounded it. At that time it was a challenge for many co-developers of linux to understand and modify the sources of an operating system. Since then, linux has not only reached the magical milestone of version 2.4, but also won a solid position in the highly competitive software field. With regard to the challenge of understanding an operating system, nothing has changed, in fact it has become even greater. Many of the features added since the last milestone version not only embody the very simple functions of an operating system, but more and more functions which provide compatibility with large software products, support new hardware, or improve the performance of the system. Version 2.4 also offers exciting new concepts like IP tables and improved plug-and-play. As with every new milestone of the linux kernel, a kernel book must also be revised to cover the new features. Despite big changes to interfaces and concepts, the book again gives an insight into the workings of linux. We hope you will not only enjoy reading it, but also enjoy experimenting with the linux kernel. Michael Beck, Ulrich Kunitz, Harald Bouml;hme, Robert Magnus, Mirko Dziadzka, Claus Schrouml;ter Berlin/Frankfurt/Furtwangen, 24. 4. 2001 Authors' preface to the 1st edition linux has been around for about two years. What started as a programming exercise by the computer science student Linus Torvalds, has become one of the most successfulfree software projects of today, and gives serious competition to commercial systems. This is the result of the voluntary work of a worldwide programming community connected by the internet, an effective communication medium. The free availability of linux has contributed to its quick distribution. Therefore it is hard to estimate the number of linux users. In Germany there are more than ten thousand. We discovered the linux system about 18 months ago. One result of this is that we now have a "correct" Unix system for our local PCs, without having to put thousands of dollars on the table, which, as students, we didn't have anyway. The other, perhaps more important, benefit for us, and possibly for the majority of the linux community in the world, is the availability of the source code of the linux system. It is quite simply fun to root about in the internals of an operating system to try out your own ideas, and out of pure interest to adapt the system to your own wishes. This book is aimed at everybody who thinks the same way, but also at those who simply want to find out how a 32-bit operating system works. The linux kernel has increased in size over time, and one can no longer obtain a good overview. Since the documentation is thin (the only documentation we know of is the outline of the linux Kernel Hackers GuideJoh95), in 1993 we started a linux seminar in the summer semester. Everybody involved in linux at our workplace, gave an insight into his or her area of interest, knowledge, and experience with "kernel hacking." In the seminar there were often discussions about modeling concepts, implementation variants, and implementation details, which were grasped in various ways. In the context of this seminar we began to write down our knowledge about the system, to make it simpler for others. This knowledge is revised and represented here. As the development of linux progresses so quickly, we couldn't allow ourselves too much time to write the book. We therefore divided the book into chapters according to the respective area of interest of the authors. Ulrich Kunitz wrote

Rewards Program