Home | History | Annotate | Line # | Download | only in efs
efs.h revision 1.1
      1 /*	$NetBSD: efs.h,v 1.1 2007/06/29 23:30:27 rumble Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2006 Stephen M. Rumble <rumble (at) ephemeral.org>
      5  *
      6  * Permission to use, copy, modify, and distribute this software for any
      7  * purpose with or without fee is hereby granted, provided that the above
      8  * copyright notice and this permission notice appear in all copies.
      9  *
     10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     17  */
     18 
     19 /*
     20  * See IRIX efs(4)
     21  */
     22 
     23 #ifndef _FS_EFS_EFS_H_
     24 #define _FS_EFS_EFS_H_
     25 
     26 #define EFS_DEBUG
     27 
     28 /*
     29  * SGI EFS - Extent File System
     30  *
     31  * The EFS filesystem is comprised of 512-byte sectors, or "basic blocks" (bb).
     32  * These blocks are divided into cylinder groups (cg), from which extents are
     33  * allocated. An extent is a contiguous region of blocks with minimal length
     34  * of 1 and maximal length of 248.
     35  *
     36  * The filesystem is limited to 8GB by struct efs_extent's ex_bn field, which
     37  * specifies an extent's offset in terms of basic blocks. Unfortunately, it was
     38  * squished into a bitfield and given only 24bits so we are left with
     39  * 2**24 * 512 bytes. Individual files are maximally 2GB, but not due to any
     40  * limitation of on-disk structures. All sizes and offsets are stored as block,
     41  * not byte values, with the exception of sb.sb_bmsize and efs_dinode.di_size.
     42  *
     43  * An EFS filesystem begins with the superblock (struct efs_sb) at bb offset 1
     44  * (offset 0 is reserved for bootblocks and other forms of contraband). The
     45  * superblock contains various parameters including magic, checksum, filesystem
     46  * size, number of cylinder groups, size of cylinder groups, and location of the
     47  * first cylinder group. A bitmap may begin at offset bb 2. This is true of
     48  * filesystems whose magic flag is EFS_MAGIC. However, the ability to grow an
     49  * efs filesystem was added in IRIX 3.3 and a grown efs's bitmap is located
     50  * toward the end of the disk, pointed to by sb.sb_bmblock. A grown filesystem
     51  * is detected with the EFS_NEWMAGIC flag. See below for more details and
     52  * differences.
     53  *
     54  * In order to promote inode and data locality, the disk is separated into
     55  * sb.sb_ncg cylinder groups, which consist of sb.sb_cgfsize blocks each.
     56  * The cylinder groups are laid out consecutively beginning from block offset
     57  * sb.sb_firstcg. The beginning of each cylinder group is comprised of
     58  * sb.sb_cgisize inodes (struct efs_dinode). The remaining space contains
     59  * file extents, which are preferentially allocated to files whose inodes are
     60  * within the same cylinder group.
     61  *
     62  * EFS increases I/O performance by storing files in contiguous chunks called
     63  * 'extents' (struct efs_extent). Extents are variably sized from 1 to 248
     64  * blocks, but please don't ask me why 256 isn't the limit.
     65  *
     66  * Each inode (struct efs_dinode) contains space for twelve extent descriptors,
     67  * allowing for up to 1,523,712 byte files (12 * 248 * 512) to be described
     68  * without indirection. When indirection is employed, each of the twelve
     69  * descriptors may reference extents that contain up to 248 more direct
     70  * descriptors. Since each descriptor is 8 bytes we have in total 15,872 * 12
     71  * direct descriptors, allowing for 15,872 * 12 * 248 * 512 = ~22GB. Of course,
     72  * with a maximum filesystem size of 8GB, such a configuration would be invalid.
     73  *
     74  * The bitmap referred to by sb_bmsize and (optionally) sb_bmblock contains
     75  * data block allocation information. I haven't looked at this at all, nor
     76  * am I aware of how inode allocation is performed.
     77  *
     78  * An EFS disk layout looks like the following:
     79  *     ____________________________________________________________________
     80  *    | unused | superblock | bitmap | pad | cyl grp | ..cyl grps... | pad |
     81  *     --------------------------------------------------------------------
     82  * bb:     0          1         2          ^-sb.sb_firstcg      sb.sb_size-^
     83  *
     84  * A cylinder group looks like the following:
     85  *     ____________________________________________________________________
     86  *    |    inodes    |           ... extents and free space ...            |
     87  *     --------------------------------------------------------------------
     88  *           0       ^-(sb.sb_cgisize *                      sb.sb_cgfsize-^
     89  *                      sizeof(struct efs_dinode))
     90  *
     91  * So far as I am aware, EFS file systems have always been big endian, existing
     92  * on mips (and perhaps earlier on m68k) machines only. While mips chips are
     93  * bi-endian, I am unaware of any sgimips machine that was used in mipsel mode.
     94  *
     95  * See efs_sb.h, efs_dir.h, and efs_dinode.h for more information regarding
     96  * directory layout and on-disk inodes, and the superblock accordingly.
     97  */
     98 
     99 /*
    100  * Basic blocks are always 512 bytes.
    101  */
    102 #define EFS_BB_SHFT	9
    103 #define EFS_BB_SIZE	(1 << EFS_BB_SHFT)
    104 
    105 /*
    106  * EFS basic block layout:
    107  */
    108 #define EFS_BB_UNUSED	0	/* bb 0 is unused */
    109 #define EFS_BB_SB	1	/* bb 1 is superblock */
    110 #define EFS_BB_BITMAP	2	/* bb 2 is bitmap (unless moved by growfs) */
    111 /* bitmap continues, then padding up to first aligned cylinder group */
    112 
    113 /*
    114  * basic block <-> byte conversions
    115  */
    116 #define EFS_BB2BY(_x)		((_x) << EFS_BB_SHFT)
    117 #define EFS_BY2BB(_x)		(((_x) + EFS_BB_SIZE - 1) >> EFS_BB_SHFT)
    118 
    119 /*
    120  * Struct efs_extent limits us to 24 bit offsets, therefore the maximum
    121  * efs.sb_size is 2**24 blocks (8GB).
    122  *
    123  * Trivia: IRIX's mkfs_efs(1M) has claimed the maximum to be 0xfffffe for years.
    124  */
    125 #define EFS_SIZE_MAX		0x01000000
    126 
    127 #ifdef _KERNEL
    128 
    129 #define	VFSTOEFS(mp)    ((struct efs_mount *)(mp)->mnt_data)
    130 
    131 /* debug goo */
    132 #ifdef DEBUG
    133 #define EFS_DEBUG
    134 #endif
    135 #ifdef EFS_DEBUG
    136 #define EFS_DPRINTF(_x)	printf _x
    137 #else
    138 #define EFS_DPRINTF(_x)
    139 #endif
    140 
    141 #endif
    142 
    143 #endif /* !_FS_EFS_EFS_H_ */
    144