狗拿耗子
1
YAFFS2
———狗拿耗子第三篇
1、YAFFS2 的背景
YAFFS2 是 Charles Manning 开发的 NAND Flash 文件系统。可以从 www.yaffs.net 获得详细
的描述和最新的版本。关于 Nand Flash 与 Nor Flash 的不同之处,网上有很多文章叙述,这
里不再罗嗦。反正是在嵌入式系统中,一般是 Nor Flash 存放在 Boot 程序,Nand Flash 作为
正式的存储设备使用。
YAFFS (Yet Another Flash File System) was designed and written by Charles Manning, of
Whitecliffs, New Zealand, for the company Aleph One. YAFFS is the first file system that was
designed specifically for NAND flash.
Yaffs1 is the first version of this file system and works on NAND chips that have 512 byte pages +
16 byte spare (OOB;Out-Of-Band) areas. These older chips also generally allow 2 or 3 write
cycles per page, which YAFFS takes advantage of - i.e. dirty pages are marked by writing to a
specific spare area byte.
Newer NAND flash chips have larger pages, 2048 bytes + 64 bytes spare areas, and stricter write
requirements. Each page within a block must be written to in sequential order, and each page must
be written only once. YAFFS2 was designed to accommodate these newer chips. YAFFS2 is based
on the YAFFS1 source code, with the major difference being that internal structures are not fixed
to assume 512 byte sizing, and a block sequence number is placed on each written page. In this
way older pages can be logically overwritten without violating the "write once" rule.
YAFFS is a robust log-structured file system that holds data integrity as a high priority. A
secondary YAFFS goal is high performance. YAFFS will typically outperform most alternatives. It
is also designed to be portable and has been used on Linux, WinCE, pSOS, eCOS, ThreadX and
various special-purpose OSes. A variant 'YAFFS/Direct' is used in situations where there is no OS,
embedded OSes and bootloaders: it has the same core filesystem but simpler interfacing to the OS
and NAND flash hardware.
The filesystem is licensed both under the GPL and under per-product licences available from
Aleph One.
YAFFS1
YAFFS has no inherent formatting, an erased flash chip is formatted. It follows the smart media
scheme of marking the 5th byte of the spare area for bad blocks, and ignores any blocks where the
spare area byte 5 is not 0xFF.
To write file data, YAFFS initially writes a whole page (chunk in YAFFS terminology) that
describes the file metadata, such as timestamps, name, path, etc. The new file is assigned a unique
object ID number; every data chunk within the file will contain this unique object ID within the
spare area. YAFFS maintains a tree structure in RAM memory of the physical location of these