stpdfs.inc

Summary
stpdfs.inc
Stupid Filesystem
Constants and Enumerations
STPDFS_SB_MAGICSuperblock magic number, MUST BE `0x44505453` (STPD)
STPDFS_SB_REVStupidFS revision, currently `0x1`
STPDFS_BSIZEStupidFS block size (512)
STPDFS_BADINOStupidFS bad inode
STPDFS_ROOTINOStupidFS root inode number
STPDFS_NDIRECTNumber of direct block (7)
STPDFS_INDIRECT_PER_BLOCK
STPDFS_NAME_MAXMax file name length (28)
StupidFS State
StupidFS i-node flags
STPDFS_INODE_PER_BLOCKI-node per block
STPDFS_DIRENT_PER_BLOCKDirectory entry per block
Structs
StpdFS_FreeList
StpdFS_Sb
StpdFS_InodeStupidFS on disk i-node
StpdFS_DirentStupidFS directory entry
Implementation

Stupid Filesystem

┌──────────┬───────────┬──────┬───┬──────┬────┬───┬────┐
│Boot block│Super block│Inodes│...│Inodes│Data│...│Data│
└──────────┴───────────┴──────┴───┴──────┴────┴───┴────┘
Summary
Constants and Enumerations
STPDFS_SB_MAGICSuperblock magic number, MUST BE `0x44505453` (STPD)
STPDFS_SB_REVStupidFS revision, currently `0x1`
STPDFS_BSIZEStupidFS block size (512)
STPDFS_BADINOStupidFS bad inode
STPDFS_ROOTINOStupidFS root inode number
STPDFS_NDIRECTNumber of direct block (7)
STPDFS_INDIRECT_PER_BLOCK
STPDFS_NAME_MAXMax file name length (28)
StupidFS State
StupidFS i-node flags
STPDFS_INODE_PER_BLOCKI-node per block
STPDFS_DIRENT_PER_BLOCKDirectory entry per block
Structs
StpdFS_FreeList
StpdFS_Sb
StpdFS_InodeStupidFS on disk i-node
StpdFS_DirentStupidFS directory entry

Constants and Enumerations

STPDFS_SB_MAGIC

Superblock magic number, MUST BE `0x44505453` (STPD)

STPDFS_SB_REV

StupidFS revision, currently `0x1`

STPDFS_BSIZE

StupidFS block size (512)

STPDFS_BADINO

StupidFS bad inode

STPDFS_ROOTINO

StupidFS root inode number

STPDFS_NDIRECT

Number of direct block (7)

STPDFS_INDIRECT_PER_BLOCK

STPDFS_NAME_MAX

Max file name length (28)

StupidFS State

STPDFS_CLEANLY_UNMOUNTED0
STPDFS_ERROR1
STPDFS_DIRTY1

StupidFS i-node flags

STPDFS_INO_FLAG_ALOCI-node is allocated
STPDFS_INO_FLAG_LZPI-node data is compressed using LZP algorithm (see lzp.asm)
STPDFS_INO_FLAG_ENCI-node data is encrypted with XChaCha12 (see xchacha.asm)

STPDFS_INODE_PER_BLOCK

I-node per block

STPDFS_DIRENT_PER_BLOCK

Directory entry per block

Structs

StpdFS_FreeList

.freeList of free block (0-99), index 0 point to next freelist
.nfreeIndex
┌──────────┐
│ block 99 │
├──────────┤
│ block 98 │
├──────────┤
│ ...      │
├──────────┤
│ block 2  │
├──────────┤
│ block 1  │
├──────────┤    ┌──────────┐
│ block 0  ├───►│ block 99 │
└──────────┘    ├──────────┤
                │ ...      │
                ├──────────┤    ┌──────────┐
                │ block 0  ├───►│ block 99 │
                └──────────┘    ├──────────┤
                                │ ...      │
                                ├──────────┤
                                │ block 0  │
                                └──────────┘

StpdFS_Sb

.magicSee STPDFS_SB_MAGIC
.isizeSize in block of the i-node list
.fsizeSize in block of the entire volume
.freelistSee StpdFS_FreeList
.revSee STPDFS_SB_REV
.stateSee StupidFS State
.timeLast mod time (64bit UNIX timestamp)

StpdFS_Inode

StupidFS on disk i-node

.modeFile mode
.nlinkLinks count
.uidOwner Uid
.gidGroup Id
.flagsFile flags, see StupidFS i-node flags
.sizeData size in byte
.zoneSee bellow
.actimeAccess time (64-bit UNIX timestamp)
.modtimeModification time (64-bit UNIX timestamp)

Zone 0-6 are direct, zone 7 indirect, zone 8 double indirect, zone 9 triple indirect

                        ┌────────┐
                        │        │
               ┌───────►│Data    │
               │        │        │
┌──────┐ Direct│        └────────┘
│zone 0├───────┘
├──────┤
│...   │
├──────┤          ┌────────┐      ┌────────┐
│zone 6│          │        ├─────►│        │
├──────┤ Indirect │        │      │ Data   │
│zone 7├─────────►│        │      │        │
├──────┤          └────────┘      └────────┘
│zone 8├───────┐
├──────┤       │Double indirect┌────────┐    ┌────────┐    ┌────────┐
│zone 9│       └──────────────►│        ├───►│        ├───►│        │
└──┬───┘                       │        │    │        │    │ Data   │
   │                           │        │    │        │    │        │
   │                           └────────┘    └────────┘    └────────┘
   │ Triple indirect ┌────────┐
   └────────────────►│        │    ┌────────┐      ┌────────┐      ┌────────┐
                     │        ├───►│        │      │        │      │        │
                     │        │    │        ├─────►│        ├─────►│ Data   │
                     └────────┘    │        │      │        │      │        │
                                   └────────┘      └────────┘      └────────┘

StpdFS_Dirent

StupidFS directory entry

.inodeaddress of i-node
.namenull terminated file name (see STPDFS_NAME_MAX)

Implementation

Lempel-Ziv + Prediction (a fast, efficient, and memory-use conservative compression algorithm)
eXtended-nonce ChaCha cipher
Superblock magic number, MUST BE `0x44505453` (STPD)
StupidFS revision, currently `0x1`
Max file name length (28)
Close