Specifications
If the flash device is erased, we can simply mount it, and the creation of the JFFS filesystem is performed
automagically.
Note: For simple accesses like direct read or write operations or erasing you use the character device
interface (/dev/mtd*) of the MTD layer, while for filesystem operations like mounting we must use the block
device interface (/dev/mtdblock*).
# eraseall /dev/mtd2
Erased 4096 Kibyte @ 0 -- 100% complete.
# mount -t jffs /dev/mtdblock2 /mnt
# mount
/dev/root on / type nfs (rw,v2,rsize=4096,wsize=4096,hard,udp,nolock,addr=10.0.0.2)
proc on /proc type proc (rw)
devpts on /dev/pts type devpts (rw)
/dev/mtdblock2 on /mnt type jffs (rw)
# df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/root 2087212 1232060 855152 60% /
/dev/mtdblock2 3584 0 3584 0% /mnt
Now you can access the files in the JFFS filesystem in the /mnt directory.
9.1.3. Second Version of JFFS
Probably even more interesting for embedded systems is the second version of JFFS, JFFS2, since it not only
fixes a few design issues with JFFS, but also adds transparent compression, so that you can save a lot of
precious flash memory.
The mkfs.jffs2 tool is used to create a JFFS2 filesystem image; it populates the image with files from a
given directory. For instance, to create a JFFS2 image for a flash partition of 3 MB total size and to populate it
with the files from the /tmp/flashtools directory you would use:
# mkfs.jffs2 --pad=3145728 --eraseblock=262144 \
--root=/tmp/flashtools/ --output image.jffs2
# eraseall /dev/mtd4
Erased 3072 Kibyte @ 0 -- 100% complete.
\# dd if=image.jffs2 of=/dev/mtd4 bs=256k
12+0 records in
12+0 records out
# mount -t jffs2 /dev/mtdblock4 /mnt
# df /mnt
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/mtdblock4 3072 2488 584 81% /mnt
Note: Especially when you are running time-critical applications on your system you should carefully
study if the behaviour of the flash filesystem might have any negative impact on your application. After all, a
flash device is not a normal harddisk. This is especially important when your flash filesystem gets full; JFFS2
acts a bit weird then:
You will note that an increasing amount of CPU time is spent by the filesystem's garbage collection
kernel thread.
•
Access times to the files on the flash filesystem may increase drastically.•
Attempts to truncate a file (to free space) or to rename it may fail:
...
# cp /bin/bash file
cp: writing `file': No space left on device
•
9.1.3. Second Version of JFFS 99