PureFS

From OSDev.wiki
Jump to navigation Jump to search
This page is a work in progress.
This page may thus be incomplete. Its content may be changed in the near future.
Filesystems
Virtual Filesystems

VFS

Disk Filesystems
CD/DVD Filesystems
Network Filesystems
Flash Filesystems

Note: if you find a grammatical error in the article, please correct it (the author does not know English well, so there may be errors).
PureFS is a disk file system designed to simplify the interaction between the operating system and disks.

PureFS V1.2.0

Better than the previous version in terms of speed, but a bit more complicated.
PureFS V1.2.0 has a total of 6 main structures:

  1. PureFsHeader
  2. PureFsVolumeHeader
  3. PureFsFileMap
  4. PureFsDataMap
  5. PureFsFileTable
  6. PureFsDataTable

Advantages(+):

  1. Easy to implement.
  2. Easy to understand.
  3. Supports nested directories.
  4. Maximum available 2^64 - 1 sectors.

Disadvantages(-):

  1. It can be journalable, provided that the OS takes care of this task itself.
  2. The maximum length of the file name is 255 characters.
  3. The maximum number of volumes is 40.
  4. Does not support Unicode names.
  5. Takes up a lot of space.

Example Of Disk Space Allocation

Note: sector #1 is not the first sector on the disk, but the first sector of PureFS.
Partition with a single volume:

Sector # Structure
1 PureFS header
2 PureFS volume header
3 PureFS file map
3+blocks/map PureFS data map
3+blocks/map*2 PureFS file table
3+blocks/map*2+32*blocks/map PureFS data table

Structures

PureFsHeader

Contains information about the file system.

Offset Size Type Name Value
0x00 0x08 char[8] Signature `->PureFS`
0x08 0x04 u32 Version PureFS version number(1.2.0 = 0x010200)
0x0C 0x08 u64 NumVolumes Number of PureFS volumes
0x14 0x01 u8 Checksum Complements byte sum of fields above to 0
0x15 0x0B u8[11] Reserved Reserved for future use
0x20 0x28*0x0C PureFsVolumePtr[40] Volumes Pointers to PureFS volumes

PureFsVolumePtr:

Offset Size Type Name Value
0x00 0x08 u64 Offset Offset to PureFS volume (in sectors)
0x08 0x04 u32 NameHash Murmur v3 32-bit volume name hash

PureFsVolumeHeader

Contains information about the PureFS volume.

Offset Size Type Name Value
0x00 0x37+0x01 char[55+1] Name PureFS volume name (zero-terminated)
0x38 0x08 u64 Attributes PureFS volume attributes
0x40 0x08 u64 BlocksPerMap Maximum number of blocks(sectors) per map(FileMap/DataMap)
0x48 0x08 u64 NumFiles Current number of files
0x50 0x08 u64 NumData Current number of data blocks(sectors)
0x58 0x1A8 u8[424] Reserved Reserved for future use

Attributes:

  • BOOTABLE(0x01) - marks that there is a program (OS kernel, for example) on the partition that bootloader should load.
  • READABLE(0x02)
  • WRITEABLE(0x04)

PureFsFileMap

Consists of PureFsVolumeHeader::BlocksPerMap sectors. There are 32 PureFsFileMapEntry entries in each sector.
PureFsFileMapEntry:

Offset Size Type Name Value
0x00 0x08 u64 FileIndex PureFsFile block(sector) index in the file table
0x08 0x04 u32 PathHash
Murmur v3 32-bit hash of file path on partition (without partition name!)
0x0C 0x04 u32 ParentHash Murmur v3 32-bit hash of the path to the parent directory on the partition (without partition name!)

PureFsDataMap

Consists of PureFsVolumeHeader::BlocksPerMap sectors. There are 32 PureFsDataMapEntry entries in each sector.
PureFsDataMapEntry:

Offset Size Type Name Value
0x00 0x08 u64 FileIndex PureFsData block(sector) index in the data table
0x08 0x08 u8[8] Reserved Reserved for future use

PureFsFileTable

Contains PureFsFile blocks.
PureFsFile:

Offset Size Type Name Value
0x00 0x100 char[255+1] Name File name (ASCII) (zero-terminated)
0x100 0x08 u64 Size Original file size
0x108 0x04 u32 Attributes File attributes
0x10C 0x08 u64 ParentIndex Index of the PureFsFile block(sector) of the parent directory in the file table
0x114 0x08 u64 DataIndex Index of the PureFsData block(sector) in the data table
0x11C 0xE4 u8[228] Reserved Reserved for future use

Attributes:

  • EXECUTABLE(0x01) - marks the file as a program that can be executed by the OS.
  • READABLE(0x02)
  • WRITEABLE(0x04)

PureFsDataTable

Contains PureFsData blocks.
PureFsData:

Offset Size Type Name Value
0x00 0x1F8 u8[504] Data Part of the file data
0x1F8 0x08 u64 NextIndex Index of the next data block(sector) (0 if last)

FAQ

  • How are directories stored? - Directories are the same as files, except that the PUREFS_FILE_ATR_DIRECTORY bit is set in PureFsFile::Attributes, and the data blocks(sectors) (PureFsData) contain the indexes of the files they contain.
  • How are symbolic links stored? - Symbolic links differ from regular files only in that they have no data blocks, and the PureFsFile::DataIndex field contains the index of the file/directory in the PureFsFileTable table.
  • How are hash collisions handled? - For this purpose, the PathHash and ParentHash fields are provided in the PureFsFileMapEntry structure to minimize the risk of finding the wrong file. When the OS reads the PureFsFile structure, it must check that the file name matches the file being searched for.

See Also

PureFS V1.1.0
Murmur v3 32-bit hash