File System

This file system is based on earlier file systems like ext2 and works the same way. This document outlines differences between ext2 and this file system. If something is unclear ext2 documentation would be a good reference. Most of the structures are similar. Some of the field sizes and offsets are different mainly to make it easier for the processor to handle. Although some fields are larger due to the evolution of technology. For instance the i_size field is expanded to eight bytes rather than being broken into two four byte portions, as file sizes over 32 bits are more common. Also date/times are represented with an absolute eight byte BCD format. The compressed four byte format relative to 1970 was developed originally for small memory systems. Also character fields use a two byte character set to allow for internationalization.

File System Layout

       
Block Group 0 Superblock    
  Block Group Descriptor Table    
  Block Bitmap    
  Inode Bitmap    
  Inode Table    
  Data Blocks    
       
Block Group 1 Superblock (copy)    
  Block Group Descriptor Table (copy)    
  Block Bitmap    
  Inode Bitmap    
  Inode Table    
  Data Blocks    
       
Block Group 2 Block Bitmap }Repeats as many as needed  
  Inode Bitmap  
  Inode Table  
  Data Blocks  
  ...    
Block Group n      

Superblock:

The Superblock contains information governing the overall workings of the file system. It is always located at at address 1024 relative to the boot sector. This may be in either block 0 or 1 depending on the block size.

Offset (bytes) Size (bytes) Description
0 4 s_inodes_count
4 4 s_blocks_count
8 4 s_r_blocks_count
12 4 s_free_blocks_count
16 4 s_free_inodes_count
20 4 s_first_data_block
24 4 s_log_block_size
28 4 s_log_frag_size
32 4 s_blocks_per_group
36 4 s_frags_per_group
40 4 s_inodes_per_group
44 4 s_pad
48 8 s_mtime
56 8 s_wtime
64 4 s_mnt_count
68 4 s_max_mnt_count
72 4 s_magic
76 4 s_state
80 4 s_errors
84 4 s_minor_rev_level
88 8 s_lastcheck
96 8 s_check_interval
104 4 s_creator_os
108 4 s_rev_level
112 4 s_def_resuid
116 4 s_def_resgid
     
120 4 s_first_ino
124 4 s_inode_size
128 4 s_block_group_nr
132 4 s_feature_compat
136 4 s_feature_incompat
140 4 s_feature_ro_compat
144 16 s_uuid
160 16 * 2 s_volume_name
192 64 * 2 s_last_mounted
320 4 s_algo_bitmap
Performance Hints
324 4 s_prealloc_blocks
328 4 s_prealloc_dir_blocks
Journaling Support
332 16 s_journal_uuid
348 4 s_journal_inum
352 4 s_journal_dev
356 4 s_last_orphan
Directory Indexing Support
360 4 * 4 s_hash_seed
376 4 s_def_hash_version
Other Options:
380 4 s_default_mount_options
384 4 s_first_meta_bg
Memory Resident DOS software management fields
500 4 s_dev
504 4 s_dirty
512   SUPERBLOCK_SIZE

s_log_block_size

This value controls the size of blocks on disk. The block size must be a multiple of the sector size (512 bytes).

Value Block Size
0 1024
1 2048
2 4096
3 8192
4 16384
5 32768
6 65536

s_inode_size

This value is the size of an inode in bytes. It does not have to be a perfect power of two. The inode size must be less than the block size.

s_dev

This field identifies which device the superblock is for when the superblock is resident in memory and being used by the DOS.

s_dirty

This field indicates that the superblock has been altered and needs to be updated on disk. It is used by the DOS.

Block Group Descriptor Table

Once again several field sizes have been increased from two to four bytes. The total structure size remains the same. The block group descriptor table occupies as many consecutive blocks as is required to manage the entire disk.

Offset (Words) Offset (bytes) Size (bytes) Description
0 0 4 bg_block_bitmap
1 4 4 bg_inode_bitmap
2 8 4 bg_inode_table
3 12 4 bg_free_blocks_count
4 16 4 bg_free_inodes_count
5 20 4 bg_used_dirs_count
6 24 8 bg_reserved
  32   BGDESC_SIZE

bg_inode_bitmap

This field contains a value identifying the absolute block number of the inode bitmap. This value will normally be one greater than the bg_block_bitmap as it normally follows in the disk layout.

bg_inode_table

This field contains a value identifying the absolute block number of the inode table. This value will normally be one greater than the bg_inode_bitmap as it normally follows in the disk layout.

 

Block Bitmap

The block bitmap is a map of free or used data blocks. 1 = allocated, 0 = free. The block bitmap is just a single block in size; the number of data blocks that can be managed with the block bitmap depends on the block size.

Inode Bitmap

The inode bitmap is a map of free or used inodes. 1 = allocated, 0 = free. The inode bitmap is just a single block in size; the number of inodes that can be managed with the inode bitmap depends on the block size. Usually there are fewer inodes managed than could be for the size of the block. The inode bitmap typically follows immediately after the block bitmap on disk.

Inode Table

The inode table is a table full of inodes. Inodes must fit entirely within blocks within the table. Partial inodes crossing block boundaries are not supported. For example six inodes will fit per block in the inode table when the block size is 1kB. (1kB / 164 = 6.24).

Inodes:

Inodes are a great way to store information about files and if it ain't broke don't fix it. This file system reuses the concept from prior systems like ext2. The processor does not handle sub-word sizes very well, so some of the fields from the original spec have been expanded to four bytes from two bytes. Note the inode structure size is no longer a power of two in order to avoid wasting too much memory.

Inode Structure:

Offset (bytes) Size (bytes) Description
0 4 i_mode
4 4 i_uid
8 8 i_size
16 8 i_atime
24 8 i_ctime
32 8 i_mtime
40 8 i_dtime
48 4 i_gid
52 4 i_links_count
56 4 i_blocks
60 4 i_flags
64 4 i_osd1
68 15 * 4 i_block
128 4 i_generation
132 4 i_file_acl
136 4 i_dir_acl
140 4 i_faddr
144 4 i_dir_prop
Operating System Defined Fields (Memory Resident)
148 4 i_dev
152 4 i_inum
156 4 i_icount
160 4 i_dirty
164   INODE_SIZE
     

i_size

A 64 bit value containing the size of the file in bytes.

i_atime

64 bit BCD value containing the date and time of the last time this inode was accessed.

Date format: YYYYMMDDhhmmsscc

i_ctime

64 bit BCD value containing the date and time when this inode was created.

i_dir_prop

32 bit value containing directory file properties. This information may include the directory sort order and directory format type. (flat file, linked list, btree).

i_dev

The device number that this inode is located on.

i_inum

The inode index number of this inode.

i_icount

This field contains the number of times this inode has been referenced.

i_dirty

This field indicates that the inode has been altered and needs to be updated to disk.

Directories

A directory is just a special predefined type of file in the file system. Directories use a simple flat format file for simplicity.

Directory Structure

Offset (bytes) Size (bytes) Description
0 64 First directory entry
64 64 second directory entry
...   subsequent directory entries
     

 

Directory Entry Structure

Offset (bytes) Size (bytes) Description
0 28 * 2 de_name
56 4 de_type
60 4 de_inode
64    

de_name

A 28 character file name. 16 bit characters are allowed for, for internationalization.

de_type

Bits 15-0
0 Unknown
1 Regular file
2 Directory file
3 Character Device
4 Block Device
5 Buffer file
6 Socket File
7 Symbolic Link
8 Long filename; concatenate with next entry
Bits 31- 16
0 Unused

de_inode

A four byte index number of the inode associated with the directory entry. A number of zero indicates the directory entry is unused.