<s>
Yaffs	B-Application
(	O
Yet	O
Another	O
Flash	O
File	B-Application
System	I-Application
)	O
is	O
a	O
file	B-Application
system	I-Application
designed	O
and	O
written	O
by	O
Charles	O
Manning	O
for	O
the	O
company	O
Aleph	O
One	O
.	O
</s>
<s>
Yaffs1	O
was	O
the	O
first	O
version	O
of	O
this	O
file	B-Application
system	I-Application
and	O
was	O
designed	O
for	O
the	O
then-current	O
NAND	O
chips	O
with	O
512	O
byte	B-Application
page	O
size	O
( +	O
16	O
byte	B-Application
spare	O
(	O
OOB	O
;	O
Out-Of-Band	O
)	O
area	O
)	O
.	O
</s>
<s>
YAFFS	B-Application
takes	O
advantage	O
of	O
this	O
:	O
dirty	O
pages	O
are	O
marked	O
by	O
writing	O
to	O
a	O
specific	O
spare	O
area	O
byte	B-Application
.	O
</s>
<s>
Newer	O
NAND	O
flash	O
chips	O
have	O
larger	O
pages	O
,	O
first	O
2K	O
pages	O
( +	O
64	O
bytes	B-Application
OOB	O
)	O
,	O
later	O
4K	O
,	O
with	O
stricter	O
write	O
requirements	O
.	O
</s>
<s>
YAFFS2	B-Application
was	O
designed	O
to	O
accommodate	O
these	O
newer	O
chips	O
.	O
</s>
<s>
It	O
was	O
based	O
on	O
the	O
YAFFS1	O
source	O
code	O
,	O
with	O
the	O
major	O
difference	O
being	O
that	O
internal	O
structures	O
are	O
not	O
fixed	O
to	O
assume	O
512	O
byte	B-Application
sizing	O
,	O
and	O
a	O
block	O
sequence	O
number	O
is	O
placed	O
on	O
each	O
written	O
page	O
.	O
</s>
<s>
YAFFS	B-Application
is	O
a	O
robust	O
log-structured	B-Application
file	I-Application
system	I-Application
that	O
holds	O
data	O
integrity	O
as	O
a	O
high	O
priority	O
.	O
</s>
<s>
A	O
secondary	O
YAFFS	B-Application
goal	O
is	O
high	O
performance	O
.	O
</s>
<s>
YAFFS	B-Application
will	O
typically	O
outperform	O
most	O
alternatives	O
.	O
</s>
<s>
It	O
is	O
also	O
designed	O
to	O
be	O
portable	O
and	O
has	O
been	O
used	O
on	O
Linux	B-Application
,	O
WinCE	B-Operating_System
,	O
pSOS	B-Operating_System
,	O
RTEMS	B-Operating_System
,	O
eCos	B-Operating_System
,	O
ThreadX	B-Operating_System
,	O
and	O
various	O
special-purpose	O
OSes	O
.	O
</s>
<s>
A	O
variant	O
'	O
YAFFS/Direct	O
'	O
is	O
used	O
in	O
situations	O
where	O
there	O
is	O
no	O
OS	O
,	O
embedded	O
OSes	O
or	O
bootloaders	O
:	O
it	O
has	O
the	O
same	O
core	O
filesystem	B-Application
but	O
simpler	O
interfacing	O
to	O
both	O
the	O
higher	O
and	O
lower	O
level	O
code	O
and	O
the	O
NAND	O
flash	O
hardware	O
.	O
</s>
<s>
The	O
YAFFS	B-Application
codebase	O
is	O
licensed	O
both	O
under	O
the	O
GPL	B-License
and	O
under	O
per-product	O
licenses	O
available	O
from	O
Aleph	O
One	O
.	O
</s>
<s>
There	O
is	O
no	O
special	O
procedure	O
to	O
initialize	B-Application
a	O
YAFFS	B-Application
filesystem	B-Application
beyond	O
simply	O
erasing	O
the	O
flash	O
memory	O
.	O
</s>
<s>
When	O
a	O
bad	O
block	O
is	O
encountered	O
,	O
YAFFS	B-Application
follows	O
the	O
smart	O
media	O
scheme	O
of	O
marking	O
the	O
fifth	O
byte	B-Application
of	O
the	O
block	O
's	O
spare	O
area	O
.	O
</s>
<s>
To	O
write	O
file	O
data	O
,	O
YAFFS	B-Application
initially	O
writes	O
a	O
whole	O
page	O
(	O
chunk	O
in	O
YAFFS	B-Application
terminology	O
)	O
that	O
describes	O
the	O
file	O
metadata	O
,	O
such	O
as	O
timestamps	O
,	O
name	O
,	O
path	O
,	O
etc	O
.	O
</s>
<s>
YAFFS	B-Application
maintains	O
a	O
tree	O
structure	O
in	O
RAM	B-Architecture
of	O
the	O
physical	O
location	O
of	O
these	O
chunks	O
.	O
</s>
<s>
When	O
a	O
chunk	O
is	O
no	O
longer	O
valid	O
(	O
the	O
file	O
is	O
deleted	O
,	O
or	O
parts	O
of	O
the	O
file	O
are	O
overwritten	O
)	O
,	O
YAFFS	B-Application
marks	O
a	O
particular	O
byte	B-Application
in	O
the	O
spare	O
area	O
of	O
the	O
chunk	O
as	O
‘	O
dirty’	O
.	O
</s>
<s>
When	O
an	O
entire	O
block	O
(	O
32	O
pages	O
)	O
is	O
marked	O
as	O
dirty	O
,	O
YAFFS	B-Application
can	O
erase	O
the	O
block	O
and	O
reclaim	O
the	O
space	O
.	O
</s>
<s>
When	O
the	O
filesystem	B-Application
's	O
free	O
space	O
is	O
low	O
,	O
YAFFS	B-Application
consolidates	O
a	O
group	O
of	O
good	O
pages	O
onto	O
a	O
new	O
block	O
.	O
</s>
<s>
YAFFS	B-Application
then	O
reclaims	O
the	O
space	O
used	O
by	O
dirty	O
pages	O
within	O
each	O
of	O
the	O
original	O
blocks	O
.	O
</s>
<s>
When	O
a	O
YAFFS	B-Application
system	O
mounts	O
a	O
NAND	O
flash	O
device	O
,	O
it	O
must	O
visit	O
each	O
block	O
to	O
check	O
for	O
valid	O
data	O
by	O
scanning	O
its	O
spare	O
area	O
.	O
</s>
<s>
YAFFS2	B-Application
is	O
similar	O
in	O
concept	O
to	O
YAFFS1	O
,	O
and	O
shares	O
much	O
of	O
the	O
same	O
code	O
;	O
the	O
YAFFS2	B-Application
code	O
base	O
supports	O
YAFFS1	O
data	O
formats	O
through	O
backward	O
compatibility	O
.	O
</s>
<s>
The	O
main	O
difference	O
is	O
that	O
YAFFS2	B-Application
needs	O
to	O
jump	O
through	O
significant	O
hoops	O
to	O
meet	O
the	O
"	O
write	O
once	O
"	O
requirement	O
of	O
modern	O
NAND	O
flash	O
.	O
</s>
<s>
YAFFS2	B-Application
marks	O
every	O
newly	O
written	O
block	O
with	O
a	O
sequence	O
number	O
that	O
is	O
monotonically	O
increasing	O
.	O
</s>
<s>
Thereby	O
when	O
YAFFS2	B-Application
scans	O
the	O
flash	O
and	O
detects	O
multiple	O
chunks	O
that	O
have	O
identical	O
ObjectIDs	O
and	O
ChunkNumbers	O
,	O
it	O
can	O
choose	O
which	O
to	O
use	O
by	O
taking	O
the	O
greatest	O
sequence	O
number	O
.	O
</s>
<s>
For	O
efficiency	O
reasons	O
YAFFS2	B-Application
also	O
introduces	O
the	O
concept	O
of	O
shrink	O
headers	O
.	O
</s>
<s>
For	O
example	O
,	O
when	O
a	O
file	O
is	O
resized	O
to	O
a	O
smaller	O
size	O
,	O
YAFFS1	O
will	O
mark	O
all	O
of	O
the	O
affected	O
chunks	O
as	O
dirty	O
-	O
YAFFS2	B-Application
cannot	O
do	O
this	O
due	O
to	O
the	O
"	O
write	O
once	O
"	O
rule	O
.	O
</s>
<s>
YAFFS2	B-Application
instead	O
writes	O
a	O
"	O
shrink	O
header	O
"	O
,	O
which	O
indicates	O
that	O
a	O
certain	O
number	O
of	O
pages	O
before	O
that	O
point	O
are	O
invalid	O
.	O
</s>
<s>
This	O
lets	O
YAFFS2	B-Application
reconstruct	O
the	O
final	O
state	O
of	O
the	O
filesystem	B-Application
when	O
the	O
system	O
reboots	O
.	O
</s>
<s>
YAFFS2	B-Application
uses	O
a	O
more	O
abstract	O
definition	O
of	O
the	O
NAND	O
flash	O
allowing	O
it	O
to	O
be	O
used	O
with	O
a	O
wider	O
variety	O
of	O
flash	O
parts	O
with	O
different	O
geometries	O
,	O
bad	O
block	O
handling	O
rules	O
etc	O
.	O
</s>
<s>
YAFFS2	B-Application
later	O
added	O
support	O
for	O
checkpointing	B-General_Concept
,	O
which	O
bypasses	O
normal	O
mount	B-Application
scanning	O
,	O
allowing	O
very	O
fast	O
mount	B-Application
times	O
.	O
</s>
<s>
Performance	O
will	O
vary	O
,	O
but	O
mount	B-Application
times	O
of	O
3	O
seconds	O
for	O
2	O
GB	O
have	O
been	O
reported	O
.	O
</s>
