1 | /* 2 | super_block.h 3 | ------------- 4 | $Id: super_block.h,v 1.13 2003/10/20 07:18:11 stewart Exp $ 5 | 6 | Part of the FCFS object store. 7 | 8 | This file describes the super block and related data structures. 9 | 10 | (C)2003 Stewart Smith 11 | Distributed under the GNU Public License 12 | */ 13 | #ifndef __FCFS_SUPER_BLOCK_H__ 14 | #define __FCFS_SUPER_BLOCK_H__ 15 | 16 | #include "disk.h" 17 | 18 | /* fcfs_block_run 19 | -------------- 20 | We have a max of ~4billion alloction groups, 21 | within these, we can have up to 4billion blocks. 22 | and we can address these with *one* block_run structure. 23 | This means we don't have a lot of block address lookup on large files 24 | or contiguous files. Should lead to fast IO... 25 | */ 26 | struct fcfs_block_run { 27 | u32 allocation_group; /* Allocation group */ 28 | u32 start; /* Start Block */ 29 | u32 len; /* Length (blocks) */ 30 | }; 31 | 32 | #define FCFS_SB_MAGIC1 0x46436673 /* FCFS */ 33 | #define FCFS_SB_VERSION1 0x00010001 /* V1 SB, V1 FS */ 34 | #define FCFS_SB_BITS 0x00000040 /* We're 64bit - but could be bigger...*/ 35 | 36 | #define FCFS_NAME_LENGTH 128 /* Human Readable Name */ 37 | #define FCFS_SB_MAGIC2 0x3f8ec2a1 /* There is no meaning, just weird num */ 38 | 39 | enum fcfs_sb_flags { 40 | FCFS_FLAG_SBLocation1, /* Three flags make number */ 41 | FCFS_FLAG_SBLocation2, /* see: enum fcfs_sb_location */ 42 | FCFS_FLAG_SBLocation3, 43 | FCFS_FLAG_Dirty, /* Was uncleanly unmounted*/ 44 | FCFS_FLAG_Experimental, /* Has been written by experimental code */ 45 | FCFS_FLAG_JournalMeta, /* Journal meta-data */ 46 | FCFS_FLAG_JournalData, /* Journal all data writes*/ 47 | FCFS_FLAG_Versioned, /* Is versioned system */ 48 | }; 49 | 50 | enum fcfs_sb_location { 51 | FCFS_SBloc_start_volume, /* Start of volume */ 52 | FCFS_SBloc_start_ag, /* Start of allocation group */ 53 | FCFS_SBloc_end_volume /* Final block of volume */ 54 | }; 55 | 56 | struct fcfs_sb { 57 | u32 magic1; // first magic number. 58 | u32 version; // version of FS 59 | u32 bits; // number of bits to use as a 'base' bits. (64 default) 60 | u32 sblength; // length of sb (bytes) 61 | 62 | u64 flags; 63 | 64 | u32 bsize; // block size (bytes) 65 | u64 blocksnr; // number of blocks 66 | 67 | 68 | char name[FCFS_NAME_LENGTH]; // human readable name of volume 69 | u32 magic2; // magic2 70 | 71 | u32 allocation_groupsnr; /* Number of alloction groups on volume */ 72 | u32 ag_blocksnr; /* Blocks per allocation group */ 73 | 74 | u64 num_mounts; /* Number of successful read/write mounts */ 75 | u64 num_dirtymounts; /* Num dirty mounts */ 76 | u64 time_created; /* Time volume created*/ 77 | u64 time_clean; /* Time volume last unmounted cleanly*/ 78 | u64 time_dirtymount; /* Time volume last mounted dirty */ 79 | 80 | u64 onode_index_blocknr; /* Where we find our primary index */ 81 | 82 | u64 onindex_num_onodes; /* Num onodes in index */ 83 | u64 onindex_used; /* Num of used inodes in index */ 84 | u64 onindex_free; /* Num of free onodes in index */ 85 | u64 onindex_next_id; /* Next ID to use */ 86 | u32 onindex_node_size; /* In number of keys */ 87 | 88 | union space_tracking { 89 | 90 | char padding[50]; 91 | }space; 92 | }; 93 | 94 | #define FCFS_ONODE_MAGIC1 0x4f4e6f4465563101ULL /* ONoDeV1 0x01 */ 95 | 96 | enum fcfs_onode_flags { 97 | FCFS_OFLAG_NoVersion, /* Don't version track this onode */ 98 | FCFS_OFLAG_ForkLeaf /* We have a fork leaf, not a node */ 99 | }; 100 | 101 | #define FSFS_ONODE1_SPACE_LEAF_MAXNR 10 102 | 103 | struct fcfs_onode1_space_leaf { 104 | char nr; 105 | struct fcfs_block_run br[FSFS_ONODE1_SPACE_LEAF_MAXNR]; 106 | }; 107 | 108 | struct fcfs_onode1_space_node { 109 | u64 offset[7]; 110 | u64 block[7]; 111 | }; 112 | 113 | enum fcfs_fork_flags { 114 | FCFS_FORK_InForkData, /* We have data, not space nodes */ 115 | FCFS_FORK_SpaceNode /* Space is node, not leaf */ 116 | }; 117 | 118 | #define FCFS_FORK_SMALL_DATA_SIZE 112 119 | 120 | struct fcfs_fork { 121 | u64 fork_type; 122 | u64 fork_flags; 123 | u64 content_length; 124 | union data { 125 | union space { 126 | struct fcfs_onode1_space_leaf leaf; 127 | struct fcfs_onode1_space_node node; 128 | } space; 129 | 130 | char small_data[FCFS_FORK_SMALL_DATA_SIZE]; /* I wish this was neater, as part of the leaf */ 131 | } data ; 132 | }; 133 | 134 | struct fcfs_fork_leaf { 135 | char nr; 136 | struct fcfs_fork fork[10]; 137 | }; 138 | 139 | struct fcfs_fork_node { 140 | u64 offset[7]; 141 | u64 block[7]; 142 | }; 143 | 144 | struct fcfs_onode1 { 145 | u64 magic1; /* Identify as O-Node */ 146 | u64 onode_num; /* FS Specific Unique ID */ 147 | u64 onode_revision; /* Revision of onode */ 148 | u64 flags; /* fcfs_onode_flags */ 149 | u64 use_count; /* Reference Counter (for indicies) */ 150 | u32 onode_size; /* Length of o-node structure. */ 151 | union forks { 152 | struct fcfs_fork_leaf leaf; 153 | struct fcfs_fork_node node; 154 | } forks; 155 | char small_space[1]; /* used for in-onode data (or metadata) */ 156 | }; 157 | 158 | 159 | /* Functions for manipulating the Super Block */ 160 | int fcfs_write_sb(struct fcfs_disk *disk); 161 | int fcfs_sb_mark_dirty(struct fcfs_disk *disk); 162 | int fcfs_sb_mark_clean(struct fcfs_disk *disk); 163 | 164 | #endif 165 |