TEAMFLY TEAM FLY ® Dear Valued Customer, We realize you’re a busy professional with deadlines to hit. Whether your goal is to learn a new technology or solve a critical problem, we want to be there to lend you a hand. Our primary objective is to provide you with the insight and knowledge you need to stay atop the highly competitive and ever- changing technology industry. Wiley Publishing, Inc., offers books on a wide variety of technical categories, including security, data warehousing, software development tools, and networking — everything you need to reach your peak. Regardless of your level of expertise, the Wiley family of books has you covered. • For Dummies – The fun and easy way to learn • The Weekend Crash Course –The fastest way to learn a new tool or technology • Visual – For those who prefer to learn a new topic visually • The Bible – The 100% comprehensive tutorial and reference • The Wiley Professional list – Practical and reliable resources for IT professionals The book you hold now, UNIX Filesystems: Evolution, Design, and Implementation, is the first book to cover filesystems from all versions of UNIX and Linux. The author gives you details about the file I/O aspects of UNIX programming, describes the various UNIX and Linux operating system internals, and gives cases studies of some of the most popular filesystems including UFS, ext2, and the VERITAS filesystem, VxFS. The book contains numerous examples including a fully working Linux filesystem that you can experiment with. Our commitment to you does not end at the last page of this book. We’d want to open a dialog with you to see what other solutions we can provide. Please be sure to visit us at www.wiley.com/compbooks to re- view our complete title list and explore the other resources we offer. If you have a comment, suggestion, or any other inquiry, please locate the “contact us” link at www.wiley.com. Thank you for your support and we look forward to hearing from you and serving your needs again in the future. Sincerely, Richard K. Swadley Vice President & Executive Group Publisher Wiley Technology Publishing WILEY advantage The UNIX ® Filesystems Evolution, Design, and Implementation (VERITAS Series) Steve D. Pate UNIX ® Filesystems: Evolution, Design, and Implementation (VERITAS Series) Publisher: Robert Ipsen Executive Editor: Carol Long Developmental Editor: James H. Russell Managing Editor: Angela Smith Text Design & Composition: Wiley Composition Services This book is printed on acid-free paper. ∞ Copyright © 2003 by Steve Pate. All rights reserved. Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA01923, (978) 750-8400, fax (978) 750-4470. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, E-mail: permcoordinator@wiley.com. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accu- racy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley Publishing logo and related trade dress are trademarks or registered trademarks of Wiley Publishing, Inc., in the United States and other countries, and may not be used without written permission. Unix is a trademark or registered trademark of Unix Systems Laborato- ries, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Cataloging-in-Publication Data: ISBN: 0-471-16483-6 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 vii Contents Foreword xvii Introduction xix Chapter 1 UNIX Evolution and Standardization 1 A Brief Walk through Time 1 How Many Versions of UNIX Are There? 3 Why Is UNIX So Successful? 3 The Early Days of UNIX 3 The Early History of the C Language 4 Research Editions of UNIX 5 AT&T’s Commercial Side of UNIX 5 The Evolution of BSD UNIX 7 BSD Networking Releases 8 UNIX Goes to Court 8 The NetBSD Operating System 8 The FreeBSD Operating System 9 The OpenBSD Operating System 9 Sun Microsystems and SunOS 9 System V Release 4 and Variants 10 Novell’s Entry into the UNIX Market 10 Linux and the Open Source Movement 11 UNIX Standardization 11 IEEE and POSIX 11 The X/Open Group 12 The System V Interface Definition 12 Spec 11/70 and the Single UNIX Specification 13 UNIX International and OSF 13 The Data Management Interfaces Group 14 The Large File Summit 14 Summary 15 viii Contents Chapter 2 File-Based Concepts 17 UNIX File Types 18 File Descriptors 19 Basic File Properties 20 The File Mode Creation Mask 23 Changing File Permissions 24 Changing File Ownership 26 Changing File Times 28 Truncating and Removing Files 29 Directories 30 Special Files 31 Symbolic Links and Hard Links 32 Named Pipes 33 Summary 34 Chapter 3 User File I/O 35 Library Functions versus System Calls 35 Which Header Files to Use? 36 The Six Basic File Operations 37 Duplicate File Descriptors 40 Seeking and I/O Combined 41 Data and Attribute Caching 42 VxFS Caching Advisories 43 Miscellaneous Open Options 46 File and Record Locking 46 Advisory Locking 47 Mandatory Locking 51 File Control Operations 51 Vectored Reads and Writes 52 Asynchronous I/O 54 Memory Mapped Files 59 64-Bit File Access (LFS) 65 Sparse Files 66 Summary 71 Chapter 4 The Standard I/O Library 73 The FILE Structure 74 Standard Input, Output, and Error 74 Opening and Closing a Stream 75 Standard I/O Library Buffering 77 Reading and Writing to/from a Stream 79 Seeking through the Stream 82 Summary 84 Contents ix Chapter 5 Filesystem-Based Concepts 85 What’s in a Filesystem? 85 The Filesystem Hierarchy 86 Disks, Slices, Partitions, and Volumes 88 Raw and Block Devices 90 Filesystem Switchout Commands 90 Creating New Filesystems 92 Mounting and Unmounting Filesystems 94 Mount and Umount System Call Handling 98 Mounting Filesystems Automatically 98 Mounting Filesystems During Bootstrap 99 Repairing Damaged Filesystems 100 The Filesystem Debugger 101 Per Filesystem Statistics 101 User and Group Quotas 103 Summary 104 Chapter 6 UNIX Kernel Concepts 105 5th to 7th Edition Internals 105 The UNIX Filesystem 106 Filesystem-Related Kernel Structures 107 User Mode and Kernel Mode 107 UNIX Process-Related Structures 109 File Descriptors and the File Table 110 The Inode Cache 112 The Buffer Cache 112 Mounting Filesystems 115 System Call Handling 115 Pathname Resolution 116 Putting It All Together 117 Opening a File 118 Reading the File 119 Closing the File 120 Summary 120 Chapter 7 Development of the SVR4 VFS/Vnode Architecture 121 The Need for Change 121 Pre-SVR3 Kernels 122 The File System Switch 122 Mounting Filesystems 123 The Sun VFS/Vnode Architecture 126 The uio Structure 129 The VFS Layer 129 The Vnode Operations Layer 130 [...]... more detail 1 2 UNIX Filesystems Evolution, Design, and Implementation 19 69 Development on UNIX starts in AT&T’s Bell Labs 19 71 1st Edition UNIX is released 19 73 4th Edition UNIX is released This is the first version of UNIX that had the kernel written in C 19 74 Ken Thompson and Dennis Ritchie publish their classic paper, “The UNIX Timesharing System” [RITC74] 19 75 6th Edition, also called V6 UNIX, becomes... Studies 18 9 The VERITAS Filesystem 18 9 VxFS Feature Overview 19 0 Extent-Based Allocation 19 0 VxFS Extent Attributes 19 1 Caching Advisories 19 3 User and Group Quotas 19 4 Filesystem Snapshots / Checkpoints 19 4 Panic Free and I/O Error Handling Policies 19 4 VxFS Clustered Filesystem 19 5 The VxFS Disk Layouts 19 5 VxFS Disk Layout Version 1. .. in 4.3BSD 15 7 The Introduction of Vnodes in BSD UNIX 15 7 VFS and Vnode Structure Differences 15 9 Digital UNIX / True64 UNIX 15 9 The AIX Filesystem Architecture 16 1 The Filesystem-Independent Layer of AIX 16 1 File Access in AIX 16 2 The HP-UX VFS Architecture 16 3 The HP-UX Filesystem-Independent Layer 16 4 The HP-UX VFS/Vnode Layer 16 4 File I/O in... QuickLog 211 VxFS DMAPI Support 212 The UFS Filesystem 212 xi xii Contents Early UFS History 213 Block Sizes and Fragments 214 FFS Allocation Policies 215 Performance Analysis of the FFS 216 Additional Filesystem Features 216 What’s Changed Since the Early UFS Implementation? 217 Solaris UFS History and Enhancements 217 Making UFS Filesystems. .. for UNIX Filesystems 18 0 High-Level Microkernel Concepts .18 1 The Chorus Microkernel 18 2 Handling Read Operations in Chorus 18 3 Handling Write Operations in Chorus .18 4 The Mach Microkernel 18 5 Handling Read Operations in Mach 18 5 Handling Write Operations in Mach 18 6 What Happened to Microkernel Technology? 18 6 Summary 18 7 Chapter 9 Disk-Based... 4 and Variants later in the chapter UNIX Evolution and Standardization The Evolution of BSD UNIX Following Thompson and Ritchie’s paper on UNIX at the Symposium on Operating System Principles in 19 74, Bob Fabry, a professor at the University of California at Berkeley wanted to get a copy to experiment with After buying a PDP 11 /45, he received the tapes for 4th Edition UNIX which was installed in 19 74... Management 310 Cluster Filesystem Management 311 Cluster Lock Management . 313 The VERITAS SANPoint Foundation Suite . 313 CFS Hardware Configuration 313 CFS Software Components 314 VERITAS Cluster Server (VCS) and Agents 315 Low Latency Transport (LLT) 316 Group Membership and Atomic Broadcast (GAB) 317 The VERITAS Global Lock Manager (GLM) . 317 The VERITAS Clustered... reference work for UNIX developers and system administrators Fred van den Bosch Executive Vice President and Chief Technology Officer VERITAS Software Corporation Introduction Welcome to UNIX Filesystems Evolution, Design, and Implementation, the first book that is solely dedicated to UNIX internals from a filesystem perspective Much has been written about the different UNIX and UNIX- like kernels since... the late 19 60s, the chapter follows the evolution of UNIX through BSD, System V, and the many UNIX and UNIX- like variants that followed such as Linux The latter part of the chapter describes the various standards bodies and the standards that they have produced which govern the filesystem level interfaces provided by UNIX Chapter 2: File-Based Concepts This chapter presents concepts and commands that... Clustered Filesystem xxiii xxiv UNIX Filesystems Evolution, Design, and Implementation Chapter 14 : Developing a Filesystem for the Linux Kernel In order to understand how filesystems are implemented and how they work, it is best to play with an existing filesystem and see how it works internally and responds to the various file-related system calls This chapter provides an implementation of the old System . Table 11 0 The Inode Cache 11 2 The Buffer Cache 11 2 Mounting Filesystems 11 5 System Call Handling 11 5 Pathname Resolution 11 6 Putting It All Together 11 7 Opening a File 11 8 Reading the File 11 9 Closing. 4 and Variants 10 Novell’s Entry into the UNIX Market 10 Linux and the Open Source Movement 11 UNIX Standardization 11 IEEE and POSIX 11 The X/Open Group 12 The System V Interface Definition 12 Spec. Interface Definition 12 Spec 11 /70 and the Single UNIX Specification 13 UNIX International and OSF 13 The Data Management Interfaces Group 14 The Large File Summit 14 Summary 15 viii Contents Chapter