FreeBSD kernel module for mounting BFC (Binary File Container) filesystem images as read-only filesystems.
- Read-only mounting of BFC container files
- Full support for files, directories, and symlinks
- Hardware-accelerated CRC32C verification (optional)
- Zero-copy reads from backing file
- FreeBSD 14.3 or later
- Kernel sources installed at
/usr/src/sys - C compiler (clang)
makeThis will produce bfcfs.ko kernel module.
Before building, ensure you have:
-
Kernel sources installed at
/usr/src/sys:# If kernel sources are not installed, fetch them: fetch https://download.freebsd.org/ftp/releases/amd64/14.3-RELEASE/src.txz doas tar -C / -xzf src.txz -
Clang compiler (usually installed by default):
cc --version
doas kldload ./bfcfs.koCopy the module to the system modules directory:
doas cp bfcfs.ko /boot/modules/Add to /boot/loader.conf:
bfcfs_load="YES"
doas mount -t bfcfs -o ro /path/to/container.bfc /mnt/bfcro- Read-only (required)noverify- Disable CRC32C verification (faster, less safe)
# Mount with CRC verification
doas mount -t bfcfs -o ro /home/user/mysite.bfc /mnt/bfc
# Mount without CRC verification (faster)
doas mount -t bfcfs -o ro,noverify /home/user/mysite.bfc /mnt/bfc
# View mounted files
ls -la /mnt/bfc
cat /mnt/bfc/index.html
# Unmount
doas umount /mnt/bfc- Read-only: No write support (containers are immutable by design)
- No compression: ZSTD-compressed files not yet supported
- No encryption: ChaCha20-Poly1305 encrypted files not yet supported
- Full file reads only: Partial reads of compressed/encrypted files not supported
The module consists of four main components:
VFS operations (mount, unmount, root vnode, statfs)
Vnode operations (lookup, open, read, readdir, getattr, etc.)
BFC format parsing (header, footer, index management)
Low-level I/O routines (pread, object reading, CRC verification)
bfcfs-freebsd/
├── .github/
│ └── workflows/
│ └── freebsd-build.yml # GitHub Actions CI with tests
├── .gitignore # Git ignore rules
├── LICENSE # BSD 3-Clause License
├── Makefile # Build configuration
├── README.md # This file
├── bfcfs.h # Main header with data structures
├── bfcfs_vfs.c # VFS operations
├── bfcfs_vnops.c # Vnode operations
├── bfc_format.c # BFC format parsing
├── bfc_io.c # I/O routines
└── tests/ # ATF test suite
├── Kyuafile # Test configuration
├── h_funcs.subr # Test helper functions
├── mount_test # Mount/unmount tests
├── read_test # Read operation tests
├── readdir_test # Directory listing tests
├── symlink_test # Symlink tests
└── fixtures/ # Test BFC containers
└── README.md # Fixture documentation
Enable debug output by building with the DEBUG flag:
# Build with debug output enabled
make DEBUG=1
# Build without debug output (default)
makeView kernel messages:
doas dmesg | grep bfcfs- Uses FreeBSD's hardware-accelerated CRC32C (SSE 4.2 on x86_64)
- Direct VOP_READ from backing file (zero-copy when possible)
- Read statistics available via mount structure
kldload: can't load ./bfcfs.ko: Operation not permitted
Solution: Use doas or su root - kernel modules require root privileges.
bfcfs: invalid magic: expected 'BFCFv1', got '...'
Solution: Ensure the file is a valid BFC container. Check with:
hexdump -C container.bfc | head -1
# Should show: 00000000 42 46 43 46 76 31 00 00 ...bfcfs: CRC mismatch for file.txt: expected 0x..., got 0x...
Solution: Container may be corrupted. Try mounting with noverify option to bypass CRC checks, or regenerate the container.
Solution: This should not happen in the current version. If it does:
- Check
doas dmesgfor backtrace - Ensure you're using the latest module version
- Report the issue with the crash dump from
/var/crash/
make clean
make
doas kldunload bfcfs
doas kldload ./bfcfs.koThe module includes an ATF-based test suite using Kyua:
# Install test dependencies
doas pkg install kyua
# Load the module
doas kldload ./bfcfs.ko
# Run the test suite
cd tests
doas kyua test
# View test results
kyua report
# Detailed report
kyua report --verbose# Create a test mount point
doas mkdir -p /mnt/bfc
# Mount test container
doas mount -t bfcfs -o ro /path/to/test.bfc /mnt/bfc
# Run manual tests
ls -la /mnt/bfc
cat /mnt/bfc/somefile.txt
find /mnt/bfc -type f
# Unmount
doas umount /mnt/bfctests/
├── Kyuafile # Test configuration
├── h_funcs.subr # Helper functions
├── mount_test # Mount/unmount tests
├── read_test # Read operations tests
├── readdir_test # Directory listing tests
├── symlink_test # Symlink support tests
└── fixtures/
├── README.md # Fixture documentation
└── test.bfc # Test BFC container
BSD 3-Clause License - See LICENSE file for details
BFC (Binary File Container) is a modern container format designed for embedding and serving static assets. Key features include:
- Immutable: Read-only by design, perfect for distributing static content
- Efficient: Zero-copy reads, hardware-accelerated checksums
- Flexible: Optional compression (ZSTD) and encryption (ChaCha20-Poly1305)
- Cross-platform: Containers work identically on Linux and FreeBSD
- Simple: Single-file containers with embedded index
- Static Website Serving: Embed entire websites in a single
.bfcfile - Application Assets: Bundle application resources (images, configs, data)
- Software Distribution: Immutable, verifiable software packages
- Embedded Systems: Compact, read-only filesystem for embedded devices
A BFC container consists of:
- Header (4096 bytes): Magic signature, features, UUID, encryption salt
- Objects: File and directory data with individual headers
- Index: Fast lookup table mapping paths to object offsets
- Footer (56 bytes): Index location and container checksums
Each object includes:
- Object type (file/directory/symlink)
- Compression and encryption metadata
- POSIX mode bits and timestamps
- CRC32C checksum for integrity
- Variable-length name and content
While this module is for mounting containers, you can create them using:
# Install bfc tool (example)
pkg install bfc-container # or build from source
# Create uncompressed container
bfc create mysite.bfc /var/www/html/
# Create with compression
bfc create -c zstd mysite.bfc /var/www/html/
# Create with encryption
bfc create -e chacha20-poly1305 -k mykey secure.bfc /data/# Create BFC container from website
bfc create website.bfc /var/www/mysite/
# Copy to server
scp website.bfc server:/var/containers/
# On server: load module
doas kldload bfcfs
# Mount and serve
doas mount -t bfcfs -o ro /var/containers/website.bfc /var/www/html
# Configure web server to serve from /var/www/html
# (nginx, apache, etc. will serve files from the mounted BFC)| Feature | BFCFS | SquashFS | ISO9660 | FUSE |
|---|---|---|---|---|
| Read-only | [x] | [x] | [x] | [-] |
| Kernel module | [x] | [x] | [x] | [-] |
| Compression | [ ] | [x] | [-] | Varies |
| Encryption | [ ] | [-] | [-] | Varies |
| CRC integrity | [x] | [x] | [-] | Varies |
| Cross-platform | [x] | [x] | [x] | [x] |
| Performance | High | High | High | Medium |
Current Version: 1.0.0 (Stable)
- Mount/unmount operations
- Directory listing and navigation
- File reading (uncompressed)
- Symlink support
- CRC32C verification
- Hardware-accelerated checksums
- ZSTD decompression support
- ChaCha20-Poly1305 decryption support
- Extended attributes
- Advanced mount options
- Performance optimizations
Contributions are welcome! Please:
- Fork the repository and create a feature branch
- Follow FreeBSD style(9) coding standards
- Test thoroughly on FreeBSD 14.3+
- Update documentation as needed
- Submit a pull request with clear description
- Follow FreeBSD style(9)
- Use tabs for indentation (not spaces)
- Keep lines under 80 characters
- Add comments for complex logic
- Test with different container types
Please report bugs and feature requests via GitHub Issues.
Include:
- FreeBSD version (
freebsd-version) - Kernel version (
uname -a) - Steps to reproduce
- Error messages from
dmesg - Sample BFC container (if applicable)
- FreeBSD kernel developers for excellent VFS documentation
- BFC format specification contributors
- Early testers and adopters
- Documentation: This README and inline code comments
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Taras Havryliak (zombocoder) - Initial implementation
- Contributors - See CONTRIBUTORS file