OP-TEE Storage File System Layers - Architectural Analysis
Overview
This document analyzes the layered architecture of OP-TEE’s storage file system, covering the hash tree implementation (fs_htree), directory file management (fs_dirfile), and object lifecycle management across the storage stack.Hash Tree File System (fs_htree) Implementation
Core Architecture
- Location:
/home/dzb/optee/optee_os/core/tee/fs_htree.c - Purpose: Provides integrity and confidentiality for block-level storage
- Structure: Binary tree with cryptographic hashes for integrity verification
Hash Tree Node Structure
File Layout Organization
Binary Tree Navigation
Integrity Verification Mechanism
Directory File Management (fs_dirfile)
Directory Structure
- Location:
/home/dzb/optee/optee_os/core/tee/fs_dirfile.c - Purpose: Maps object IDs to file numbers and manages directory metadata
- Storage: Single file containing array of directory entries
Directory Entry Format
File Number Management
Object Lifecycle Operations
File Creation Flow
File Lookup Process
REE File System Integration
Storage Backend Architecture
- Location:
/home/dzb/optee/optee_os/core/tee/tee_ree_fs.c - Purpose: Integrates hash tree with REE (Rich Execution Environment) file system
- Block Management: 4KB blocks with out-of-place write operations
File Descriptor Structure
Out-of-Place Write Implementation
Object Lifecycle Management
Creation Workflow
- Directory Setup: Open/create directory file using
tee_fs_dirfile_open() - File Number: Allocate unique file number via
tee_fs_dirfile_get_tmp() - Hash Tree: Create new hash tree with
tee_fs_htree_open(create=true) - Encryption: Generate FEK and initialize encryption context
- Metadata: Store object metadata in directory entry
Access Control Integration
Deletion and Cleanup
Layer Interaction and Data Flow
Read Operation Flow
- Lookup:
tee_fs_dirfile_find()locates file by UUID/OID - Open:
tee_fs_htree_open()initializes hash tree with root hash - Verification: Hash tree verifies integrity during read
- Decryption: Block-level decryption using stored FEK
- Return: Decrypted data returned to caller
Write Operation Flow
- Acquire: Get directory handle with reference counting
- Modify: Out-of-place write updates blocks in hash tree
- Sync:
tee_fs_htree_sync_to_storage()commits changes - Update: Directory entry updated with new root hash
- Commit: Directory changes committed to storage
Performance Optimizations
Memory Management
- Block Pooling: Temporary blocks allocated from memory pools
- Reference Counting: Directory handles shared across operations
- Lazy Sync: Changes batched and committed atomically
I/O Optimization
- Block Alignment: All operations aligned to block boundaries
- Minimal Reads: Only read blocks that need modification
- Batch Operations: Multiple changes committed in single transaction