README revision 1.3
11.3Sperseant#	$NetBSD: README,v 1.3 1999/03/15 00:46:47 perseant Exp $
21.2Scgd
31.2Scgd#	@(#)README	8.1 (Berkeley) 6/11/93
41.1Smycroft
51.3SperseantThe file system is reasonably stable...I think.
61.1Smycroft
71.3SperseantFor details on the implementation, performance and why garbage
81.3Sperseantcollection always wins, see Dr. Margo Seltzer's thesis available for
91.3Sperseantanonymous ftp from toe.cs.berkeley.edu, in the directory
101.3Sperseantpub/personal/margo/thesis.ps.Z, or the January 1993 USENIX paper.
111.1Smycroft
121.1Smycroft----------
131.1SmycroftThe disk is laid out in segments.  The first segment starts 8K into the
141.1Smycroftdisk (the first 8K is used for boot information).  Each segment is composed
151.1Smycroftof the following:
161.1Smycroft
171.1Smycroft	An optional super block
181.1Smycroft	One or more groups of:
191.1Smycroft		segment summary
201.1Smycroft		0 or more data blocks
211.1Smycroft		0 or more inode blocks
221.1Smycroft
231.1SmycroftThe segment summary and inode/data blocks start after the super block (if
241.1Smycroftpresent), and grow toward the end of the segment.
251.1Smycroft
261.1Smycroft	_______________________________________________
271.1Smycroft	|         |            |         |            |
281.1Smycroft	| summary | data/inode | summary | data/inode |
291.1Smycroft	|  block  |   blocks   |  block  |   blocks   | ...
301.1Smycroft	|_________|____________|_________|____________|
311.1Smycroft
321.1SmycroftThe data/inode blocks following a summary block are described by the
331.1Smycroftsummary block.  In order to permit the segment to be written in any order
341.1Smycroftand in a forward direction only, a checksum is calculated across the
351.1Smycroftblocks described by the summary.  Additionally, the summary is checksummed
361.1Smycroftand timestamped.  Both of these are intended for recovery; the former is
371.1Smycroftto make it easy to determine that it *is* a summary block and the latter
381.1Smycroftis to make it easy to determine when recovery is finished for partially
391.1Smycroftwritten segments.  These checksums are also used by the cleaner.
401.1Smycroft
411.1Smycroft	Summary block (detail)
421.1Smycroft	________________
431.1Smycroft	| sum cksum    |
441.1Smycroft	| data cksum   |
451.1Smycroft	| next segment |
461.1Smycroft	| timestamp    |
471.1Smycroft	| FINFO count  |
481.1Smycroft	| inode count  |
491.1Smycroft	| flags        |
501.1Smycroft	|______________|
511.1Smycroft	|   FINFO-1    | 0 or more file info structures, identifying the
521.1Smycroft	|     .        | blocks in the segment.
531.1Smycroft	|     .        |
541.1Smycroft	|     .        |
551.1Smycroft	|   FINFO-N    |
561.1Smycroft	|   inode-N    |
571.1Smycroft	|     .        |
581.1Smycroft	|     .        |
591.1Smycroft	|     .        | 0 or more inode daddr_t's, identifying the inode
601.1Smycroft	|   inode-1    | blocks in the segment.
611.1Smycroft	|______________|
621.1Smycroft
631.1SmycroftInode blocks are blocks of on-disk inodes in the same format as those in
641.1Smycroftthe FFS.  However, spare[0] contains the inode number of the inode so we
651.1Smycroftcan find a particular inode on a page.  They are packed page_size /
661.1Smycroftsizeof(inode) to a block.  Data blocks are exactly as in the FFS.  Both
671.1Smycroftinodes and data blocks move around the file system at will.
681.1Smycroft
691.1SmycroftThe file system is described by a super-block which is replicated and
701.1Smycroftoccurs as the first block of the first and other segments.  (The maximum
711.1Smycroftnumber of super-blocks is MAXNUMSB).  Each super-block maintains a list
721.1Smycroftof the disk addresses of all the super-blocks.  The super-block maintains
731.1Smycrofta small amount of checkpoint information, essentially just enough to find
741.1Smycroftthe inode for the IFILE (fs->lfs_idaddr).
751.1Smycroft
761.1SmycroftThe IFILE is visible in the file system, as inode number IFILE_INUM.  It
771.1Smycroftcontains information shared between the kernel and various user processes.
781.1Smycroft
791.1Smycroft	Ifile (detail)
801.1Smycroft	________________
811.1Smycroft	| cleaner info | Cleaner information per file system.  (Page
821.1Smycroft	|              | granularity.)
831.1Smycroft	|______________|
841.1Smycroft	| segment      | Space available and last modified times per
851.1Smycroft	| usage table  | segment.  (Page granularity.)
861.1Smycroft	|______________|
871.1Smycroft	|   IFILE-1    | Per inode status information: current version #,
881.1Smycroft	|     .        | if currently allocated, last access time and
891.1Smycroft	|     .        | current disk address of containing inode block.
901.1Smycroft	|     .        | If current disk address is LFS_UNUSED_DADDR, the
911.1Smycroft	|   IFILE-N    | inode is not in use, and it's on the free list.
921.1Smycroft	|______________|
931.1Smycroft
941.1Smycroft
951.1SmycroftFirst Segment at Creation Time:
961.1Smycroft_____________________________________________________________
971.1Smycroft|        |       |         |       |       |       |       |
981.1Smycroft| 8K pad | Super | summary | inode | ifile | root  | l + f |
991.1Smycroft|        | block |         | block |       | dir   | dir   |
1001.1Smycroft|________|_______|_________|_______|_______|_______|_______|
1011.1Smycroft	  ^
1021.1Smycroft           Segment starts here.
1031.1Smycroft
1041.1SmycroftSome differences from the Sprite LFS implementation.
1051.1Smycroft
1061.1Smycroft1. The LFS implementation placed the ifile metadata and the super block
1071.1Smycroft   at fixed locations.  This implementation replicates the super block
1081.1Smycroft   and puts each at a fixed location.  The checkpoint data is divided into
1091.1Smycroft   two parts -- just enough information to find the IFILE is stored in
1101.1Smycroft   two of the super blocks, although it is not toggled between them as in
1111.1Smycroft   the Sprite implementation.  (This was deliberate, to avoid a single
1121.1Smycroft   point of failure.)  The remaining checkpoint information is treated as
1131.1Smycroft   a regular file, which means that the cleaner info, the segment usage
1141.1Smycroft   table and the ifile meta-data are stored in normal log segments.
1151.1Smycroft   (Tastes great, less filling...)
1161.1Smycroft
1171.1Smycroft2. The segment layout is radically different in Sprite; this implementation
1181.1Smycroft   uses something a lot like network framing, where data/inode blocks are
1191.1Smycroft   written asynchronously, and a checksum is used to validate any set of
1201.1Smycroft   summary and data/inode blocks.  Sprite writes summary blocks synchronously
1211.1Smycroft   after the data/inode blocks have been written and the existence of the
1221.1Smycroft   summary block validates the data/inode blocks.  This permits us to write
1231.1Smycroft   everything contiguously, even partial segments and their summaries, whereas
1241.1Smycroft   Sprite is forced to seek (from the end of the data inode to the summary
1251.1Smycroft   which lives at the end of the segment).  Additionally, writing the summary
1261.1Smycroft   synchronously should cost about 1/2 a rotation per summary.
1271.1Smycroft
1281.1Smycroft3. Sprite LFS distinguishes between different types of blocks in the segment.
1291.1Smycroft   Other than inode blocks and data blocks, we don't.
1301.1Smycroft
1311.1Smycroft4. Sprite LFS traverses the IFILE looking for free blocks.  We maintain a
1321.1Smycroft   free list threaded through the IFILE entries.
1331.1Smycroft
1341.1Smycroft5. The cleaner runs in user space, as opposed to kernel space.  It shares
1351.1Smycroft   information with the kernel by reading/writing the IFILE and through
1361.1Smycroft   cleaner specific system calls.
1371.1Smycroft
138