What is CHFS?

CHFS is an open-source flash filesystem for NetBSD designed for raw flash devices (especially for NAND).

Where can I find the source?

The source is part of the NetBSD under src/sys/ufs/chfs directory. You can check it out from the homepage of NetBSD or browse here.

How can I try it?

You could use a real NAND chip (for example on a board), or the NAND emulator.

  1. CHFS should be defined in your kernel config, if you don't want to use it as a kernel module
    file-system CHFS

  2. If you have a real NAND chip, there is an example config:
    # NAND controller
    omapnand0 at gpmc? addr 0x30000000

    # NAND layer
    nand0 at nandbus?

    # use the bad block table
    options NAND_BBT

    # Define flash partitions for board
    # size 0 means here the partition will fill the left space
    flash0 at nand0 offset 0x000000 size 0x080000 readonly 1
    flash1 at nand0 offset 0x080000 size 0

  3. You can also use the NAND emulator. In this case:
    # NAND emulator
    pseudo-device nandemulator

    nand0 at nandemulator0
    flash0 at nand0

After these steps when you boot the new kernel, you'll find the device(s) under /dev directory, like /dev/flash0.

How can I build the filesystem?

CHFS is automatically build itself during the first mount.

How can I mount / unmount the filesystem?

mount -t chfs /dev/flash0 /mnt
umount /mnt

How can I make a CHFS image from a directory?

makefs -t chfs [image] [directory]

There is no FSCK. Why?

Every time you mount CHFS, it does a self-check.

What's about the fragmentation?

CHFS has a built-in garbage collector that works like an online defragmenter.


Physical eraseblock. Eraseblocks of the device.


Logical eraseblock. PEBs are mapped to LEBs, CHFS can only see these.


Eraseblock-handler. This layer (between the device and the filesystem) maps PEBs to LEBs and handles that the filesystem shouldn't erase the same eraseblock every time.