You are on page 1of 53

1 ........................................................................................................................................................

1
2 ............................................................................................................................................... 3
2.1

(Flash Memory) .............................................................................................. 3


2.1.1 ........................................................................................................... 5
2.1.2 ........................................................................................................... 5

2.2

(File System)........................................................................................................... 6

2.3

FTL(Flash Translation Layer) ..................................................................................................... 7


2.3.1 (BAST) ....................................................................................................... 9
2.3.2 (FAST) .................................................................................................... 10

2.4

YAFFS(Yet Another Flash File System).............................................................................. 11

2.5

JFFS(Journalling Flash File System) .................................................................................... 12


2.5.1 JFFS .............................................................................................................................. 12
2.5.2 JFFS .............................................................................................................................. 13
2.5.3 JFFS .............................................................................................................................. 15
2.5.4 JFFS .............................................................................................................................. 16
- I

3 ..................................................................................................................................................... 17
3.1

JFFS2 .................................................................................................................................... 17

3.2

JFFS2 .................................................................................................................................... 17
3.2.1 ........................................................................................ 17
3.2.2 ........................................................................................ 20

3.3

JFFS2 .................................................................................................................................... 27
3.3.1 Mount ..................................................................................................................................... 27
3.3.2 Read ........................................................................................................................................ 31
3.3.3 Write ....................................................................................................................................... 33
3.3.4 Delete ..................................................................................................................................... 38
3.3.5 Garbage Collection ........................................................................................................... 39

3.4

JFFS2 .................................................................................................................................... 41

4 .......................................................................................................................... 46
5 ............................................................................................................................................ 47

- II


[ 2-1 ] NAND ............................................................................................................. 5
[ 2-2 ] ....................................................................................................... 7
[ 2-3 ] (BAST) ............................................................................................................ 9
[ 2-4 ] (FAST) .......................................................................................................... 10
[ 2-5 ] JFFS ................................................................................................................................... 13
[ 2-6 ] JFFS .............................................................................................................................................. 13
[ 2-7 ] JFFS_RAW_INODE ........................................................................................................................ 14
[ 3-1 ] JFFS2_UNKNOWN_NODE ....................................................................................................... 18
[ 3-2 ] JFFS2_RAW_DIRENT ................................................................................................................ 18
[ 3-3 ] JFFS2_RAW_INODE ................................................................................................................. 19
[ 3-4 ] JFFS2_RAW_NODE_REF .......................................................................................................... 20
[ 3-5 ] JFFS2_INODE_CACHE .............................................................................................................. 21
[ 3-6 ] JFFS2_FULL_DNODE ................................................................................................................ 22
[ 3-7 ] JFFS2_FULL_DIRENT ................................................................................................................ 22
[ 3-8 ] JFFS2_ERASEBLOCK ................................................................................................................. 23
[ 3-9 ] JFFS2_INODE_INFO ................................................................................................................. 24
[ 3-10 ] JFFS2_SB_INFO ..................................................................................................................... 27
[ 3-11 ] INODE CACHE MACRO ........................................................................................... 28
[ 3-12 ] MOUNT FLOW CHART ........................................................................................................................ 29
[ 3-13 ] READ FLOW CHART ............................................................................................................................. 31
[ 3-14 ] CREATE AN EMPTY FILE FLOW CHART .............................................................................................. 35
[ 3-15 ] CREATE A NON EMPTY FILE FLOW CHART ....................................................................................... 36

- III -

[ 3-16 ] MODIFY A FILE FLOW CHART ............................................................................................................ 37


[ 3-17 ] DELETE A FILE FLOW CHART .............................................................................................................. 39
[ 3-18 ] GC FLOW CHART ................................................................................................................................ 40
[ 3-19 ] VMWARE WORKSTATION UBUNTU 9.10 ........................................................ 42
[ 3-20 ] 1 ........................................................................................................................................ 43
[ 3-21 ] 2 ........................................................................................................................................ 43
[ 3-22 ] 3 ........................................................................................................................................ 43
[ 3-23 ] 4 ........................................................................................................................................ 44
[ 3-24 ] 5 ........................................................................................................................................ 45
[ 3-25 ] 6 ........................................................................................................................................ 45

- IV -


< 2-1 > ........................................................................................... 6
< 2-2 > FTL .................................................................................................................... 8
< 3-1 > MOUNT FUNCTION CALL ................................................................................................. 30
< 3-2 > NODETYPE ................................................................................................................................. 33
< 3-3 > ......................................................................................................................................... 41

- V

1
, MP3 ,
.
, , , ,
.


.


. (Flash FileSystem)
.
.
(Block) ,
.

64~128KB

(overwrite) .
(erase-before-write) .
. 10,000~100,000
. .
- 1 -


(wear leveling) .
.
JFFS2(Journalling Flash File System, version 2) .
. 2 ,
, FTL(Flash Translation Layer) YAFFS,
JFFS . 3 JFFS2 4
.

- 2 -

2
2.1 (Flash Memory)

.
, .

EEPROM(Electrically

Erasable

Programmable

Read-Only

Memory) .
EEPROM ,
.
EEPROM .
, MP3 , .

USB . EEPROM
.
NOR NAND CPU
. NOR
EPROM
. NOR
.
- 3 -

. NAND NOR
XIP(Execute-In-Place). XIP
RAM .
NAND
, . (4MB)
.
NAND NOR
64KB 8KB .
, NOR 1B 64KB
. 64KB 8KB
.
NAND
. NAND
NOR . NAND NOR 40%
.

- 4 -

2.1.1
Flash Memory
page

block
[ 2-1 ] NAND
[ 2-1] NAND .
. NAND
(small block) (large block) ,
32 528B(512 bytes for data + 16 bytes
for spare area) . 64
2,112B(2048 bytes for data + 64 bytes for spare area) .

2.1.2
(read), (write), (erase) 3
. , / .
- 5 -

, < 2-1> // 3
.

(overwrite) . ,
( 10 ) .

DRAM
NOR flash memory
NAND flash memory
DISK

Read

Write

60ns (2B)

60ns (2B)

2.56us (512B)

2.56us (512B)

150ns (1B)

211us (1B)

14.4us (512B)

3.53ms (512B)

10.2us (1B)

201us (1B)

35.9us (512B)

226us (512B)

12.4ms (512B)

12.4ms (512B)

(average)

(average)

Erase
N/A

1.2s (128KB)

2ms (16KB)

N/A

< 2-1 >

2.2 (File System)



. CD-ROM, Flash
Memory
(NFS, SMB, 9P )

- 6 -

(procfs

2.3 FTL(Flash Translation Layer)

[ 2-2 ]
[ 2-2] . FTL(Flash Translation Layer)

. FTL
(address mapping)
(logical address)

(physical

address)

- 7 -

(address remapping) . FTL


, ,
. FTL
.
FTL 4 . M-System

Mitsubishi ,
, . < 2-2> 4
.

FMAX

Mitsubishi

BAST

FAST

1:1

&

< 2-2 > FTL


JFFS2 .
.

- 8 -

2.3.1 (BAST)

[ 2-3 ] (BAST)
(BAST) . [ 2-3]
, .
< 2-2> ,
, .
, .

. ,

,
.
(victim block) .
.

- 9 -

2.3.2 (FAST)

[ 2-4 ] (FAST)

(FAST)

2-4]

.
,
.
.

,
.
.

. .

,
.

- 10 -

.
FIFO .

.

2.4 YAFFS(Yet Another Flash File System)


NAND .
,
NAND
. YAFFS journaling,
error , NAND .
NAND ,
. YAFFS , Embedded Linux,
uLinux, Windows ce . YAFFS .
YAFFS . garbge collection
, garbage collection
. YAFFS
. , ,
. OS
.

- 11 -

2.5 JFFS(Journalling Flash File System)


2.5.1 JFFS
1999 (Axis Communications)

2.0

JFFS(Journalling Flash File System) , 2.2 2.3


. JFFS NOR
.
. ,
(wear leveling ) .
. ,
. JFFS
, .( )
JFFS Data Metadata
. .
offset .
.

- 12 -

2.5.2 JFFS

[ 2-5 ] JFFS
[ 2-5] JFFS . JFFS2 . JFFS
(VFS)
. Buffer Cache
.

[ 2-6 ] JFFS
- 13 -

[ 2-6] JFFS . inode map inode


. inode directory node inode
file node inode .
node .
Garbage Collection .

[ 2-7 ] jffs_raw_inode
[ 2-7] jffs_raw_inode . inode
node version(32bits) .
inode node node version .
inode node
. inode 4G node
. inode version 32bits inode
- 14 -

. Raw node inode (uid, gid, mtime, atime )


inode inode inode .

2.5.3 JFFS
JFFS node .
, .
node ,
node . inode node
node dirty space
node . Inode inode deleted flag
inode , dirty space .
node
. raw node
inode map
. JFFS Buffer Cache
.
node
. , node
node .
Garbage Collection JFFS code jffs_raw_inode
dirty space .
Log node head . Log head
- 15 -

Garbage Collection
. node Log tail . Garbage Collection
tail , Garbage Collection
. dirty space Kernel Thread sleep ,
User Process ENOSPC Error . Garbage Collection
.
4 Garbage Collection
.

2.5.4 JFFS
JFFS . , JFFS NOR
NAND . , NOR
. , JFFS inode

. JFFS . ,
(re-written)

(erase)

. Garbage Collection Log


Garbage Collection .
JFFS2 . JFFS2
.

- 16 -

3
JFFS2(Journalling Flash File System, version 2) JFFS NOR
NAND . JFFS2 2.4,
2.6 . JFFS2 JFFS
. JFFS
JFFS .

3.1 JFFS2
JFFS2 node Sigle circular
log format , Directory entries inodes 3
. JFFS2 wear leveling Garbage
Collection .

3.2 JFFS2
3.2.1

3.2.1.1

jffs2_unknown_node
- 17 -

struct jffs2_unknown_node
{
jint16_t magic;

/* A constant magic number. */

jint16_t nodetype;
jint32_t totlen;

/* Total length of this node (inc data, etc.) */

jint32_t hdr_crc;

/* Crc checksum */

};

[ 3-1 ] jffs2_unknown_node
[ 3-1] jffs2_unknown_node .
node header . magic number
JFFS2 node . nodetype node type
. totlen node header . hdr_crc
header CRC .

3.2.1.2

jffs2_raw_dirent

struct jffs2_raw_dirent
{
jint16_t magic;

/* A constant magic number. */

jint16_t nodetype;

/* == JFFS_NODETYPE_DIRENT */

jint32_t totlen;

/* Total length of this node (inc data, etc.) */

jint32_t hdr_crc;

/* CRC checksum */

jint32_t pino;
jint32_t version;
jint32_t ino;
jint32_t mctime;
uint8_t nsize;
uint8_t type;
uint8_t unused[2];
jint32_t node_crc;
jint32_t name_crc;
uint8_t name[0];
};

[ 3-2 ] jffs2_raw_dirent
[ 3-2] jffs2_raw_dirent . directory
entry . pino node inode number . dirent
- 18 -

node version . ino dirent inode


number . mctime node , nsize dirent , type
dirent type . *.crc . name dirent
.

3.2.1.3

jffs2_raw_inode

struct jffs2_raw_inode
{
jint16_t magic;

/* A constant magic number. */

jint16_t nodetype;

/* == JFFS_NODETYPE_INODE */

jint32_t totlen;

/* Total length of this node (inc data, etc.) */

jint32_t hdr_crc;

/* Crc checksum */

jint32_t ino;

/* Inode number.

jint32_t version;

/* Version number. */

jmode_t mode;
jint16_t uid;
jint16_t gid;
jint32_t isize;
jint32_t atime;
jint32_t mtime;
jint32_t ctime;

*/

/* The file's type or mode.


/* The file's owner.

*/

/* The file's group.

*/

*/

/* Total resultant size of this inode (used for truncations) */


/* Last access time.

*/

/* Last modification time.

*/

/* Change time. */

jint32_t offset;

/* Where to begin to write. */

jint32_t csize;

/* (Compressed) data size */

jint32_t dsize;

/* Size of the node's data. (after decompression) */

uint8_t compr;
uint8_t usercompr;

/* Compression algorithm used */


/* Compression algorithm requested by the user */

jint16_t flags;

/* See JFFS2_INO_FLAG_* */

jint32_t data_crc;

/* CRC for the (compressed) data. */

jint32_t node_crc;

/* CRC for the raw inode (excluding data) */

uint8_t data[0];
};

[ 3-3 ] jffs2_raw_inode
[ 3-3] jffs2_raw_inode . JFFS2
. .
.
- 19 -

3.2.2
3.2.2.1

jffs2_raw_node_ref

struct jffs2_raw_node_ref
{
struct jffs2_raw_node_ref *next_in_ino; /* Points to the next raw_node_ref
for this inode. If this is the last, it points to the inode_cache
for this inode instead. The inode_cache will have NULL in the first
word so you know when you've got there :) */
struct jffs2_raw_node_ref *next_phys;
uint32_t flash_offset;
uint32_t __totlen; /* This may die; use ref_totlen(c, jeb, ) below */
};

[ 3-4 ] jffs2_raw_node_ref
[

3-4]

jffs2_raw_node_ref

node . node 2 *next_in_ino


, *next_phys node
. node
node . JFFS2 raw node
node .

3.2.2.2

jffs2_inode_cache

struct jffs2_inode_cache {
struct jffs2_full_dirent *scan_dents; /* Used during scan to hold
temporary lists of dirents, and later must be set to

- 20 -

NULL to mark the end of the raw_node_ref->next_in_ino


chain. */
struct jffs2_inode_cache *next;
struct jffs2_raw_node_ref *nodes;
uint32_t ino;
int nlink;
int state;
};

[ 3-5 ] jffs2_inode_cache
[ 3-5] jffs2_inode_cache . node
jffs2_raw_node_refs . inode
jffs2_inode_cache . inode *scan_dents
directory linked list .
list directory subdirectories .
NULL . *next list . inode
jffs2_raw_inode . node
list *nodes .
ino jffs2_inode_cache inode number . jffs2_inode_cache
nlink inode . inode cache inode
. inode
.

3.2.2.3

jffs2_full_dnode

struct jffs2_full_dnode

- 21 -

{
struct jffs2_raw_node_ref *raw;
uint32_t ofs; /* The offset to which the data of this node belongs */
uint32_t size;
uint32_t frags; /* Number of fragments which currently refer
to this node. When this reaches zero,
the node is obsolete. */
};

[ 3-6 ] jffs2_full_dnode
jffs2_raw_node_ref raw node
[ 3-6] jffs2_full_dnode
. ofs offset . size data
fragment . frags node fragment .
dnode . frags JFFS2
.

3.2.2.4

jffs2_full_dirent

struct jffs2_full_dirent
{
struct jffs2_raw_node_ref *raw;
struct jffs2_full_dirent *next;
uint32_t version;
uint32_t ino; /* == zero for unlink */
unsigned int nhash;
unsigned char type;
unsigned char name[0];
};

[ 3-7 ] jffs2_full_dirent
[ 3-7] jffs2_full_dirent jffs2_raw_node_ref directory
entry . version directory entry version . ino directory
entry inode , nhash directory entry

- 22 -

. type directory entry type , name directory


entry .

3.2.2.5

jffs2_eraseblock

struct jffs2_eraseblock
{
struct list_head list;
int bad_count;
uint32_t offset; /* of this block in the MTD */
uint32_t unchecked_size;
uint32_t used_size;
uint32_t dirty_size;
uint32_t wasted_size;
uint32_t free_size; /* Note that sector_size - free_size
is the address of the first free space */
struct jffs2_raw_node_ref *first_node;
struct jffs2_raw_node_ref *last_node;
struct jffs2_raw_node_ref *gc_node; /* Next node to be garbage collected */
};

[ 3-8 ] jffs2_eraseblock
[ 3-8] jffs2_eraseblock . eraseblock
. eraseblock list . block
bad_count 1 . 3
eraseblock bad block NAND . offset eraseblock

. eraseblock

node unchecked_size . eraseblock


. used_size eraseblock node ,
dirty_size node . wasted_size node
, free_size eraseblock .

- 23 -

3.2.2.6

jffs2_inode_info, jffs2_sb_info

[ 3-9] [ 3-10] JFFS2


.
struct jffs2_inode_info {
/* We need an internal semaphore similar to inode->i_sem.
Unfortunately, we can't used the existing one, because
either the GC would deadlock, or we'd have to release it
before letting GC proceed. Or we'd have to put ugliness
into the GC code so it didn't attempt to obtain the i_sem
for the inode(s) which are already locked */
struct semaphore sem;
/* The highest (datanode) version number used for this ino */
uint32_t highest_version;
/* List of data fragments which make up the file */
struct rb_root fragtree;
/* There may be one datanode which isn't referenced by any of the
above fragments, if it contains a metadata update but no actual
data - or if this is a directory inode */
/* This also holds the _only_ dnode for symlinks/device nodes,
etc. */
struct jffs2_full_dnode *metadata;
/* Directory entries */
struct jffs2_full_dirent *dents;
/* The target path if this is the inode of a symlink */
unsigned char *target;
/* Some stuff we just have to keep in-core at all times, for each inode. */
struct jffs2_inode_cache *inocache;
uint16_t flags;
uint8_t usercompr;
#if !defined (__ECOS)
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,2)
struct inode vfs_inode;
#endif
#endif};

[ 3-9 ] jffs2_inode_info
- 24 -

struct jffs2_sb_info {
struct mtd_info *mtd;
uint32_t highest_ino;
uint32_t checked_ino;
unsigned int flags;
struct task_struct *gc_task;

/* GC task struct */

struct completion gc_thread_start; /* GC thread start completion */


struct completion gc_thread_exit; /* GC thread exit completion port */
struct semaphore alloc_sem;

/* Used to protect all the following


fields, and also to protect against
out-of-order writing of nodes. And GC. */

uint32_t cleanmarker_size;

/* Size of an _inline_ CLEANMARKER


(i.e. zero for OOB CLEANMARKER */

uint32_t flash_size;
uint32_t used_size;
uint32_t dirty_size;
uint32_t wasted_size;
uint32_t free_size;
uint32_t erasing_size;
uint32_t bad_size;
uint32_t sector_size;
uint32_t unchecked_size;
uint32_t nr_free_blocks;
uint32_t nr_erasing_blocks;
/* Number of free blocks there must be before we... */
uint8_t resv_blocks_write;

/* ... allow a normal filesystem write */

uint8_t resv_blocks_deletion; /* ... allow a normal filesystem deletion */


uint8_t resv_blocks_gctrigger; /* ... wake up the GC thread */
uint8_t resv_blocks_gcbad;

/* ... pick a block from the bad_list to GC */

uint8_t resv_blocks_gcmerge;

/* ... merge pages when garbage collecting */

uint32_t nospc_dirty_size;
uint32_t nr_blocks;
struct jffs2_eraseblock *blocks;

/* The whole array of blocks. Used for getting blocks


* from the offset (blocks[ofs / sector_size]) */

struct jffs2_eraseblock *nextblock; /* The block we're currently filling */

- 25 -

struct jffs2_eraseblock *gcblock; /* The block we're currently garbage-collecting */


struct list_head clean_list;

/* Blocks 100% full of clean data */

struct list_head very_dirty_list; /* Blocks with lots of dirty space */


struct list_head dirty_list;

/* Blocks with some dirty space */

struct list_head erasable_list; /* Blocks which are completely dirty, and need erasing */
struct list_head erasable_pending_wbuf_list; /* Blocks which need erasing but only
after the current wbuf is flushed */
struct list_head erasing_list;

/* Blocks which are currently erasing */

struct list_head erase_pending_list; /* Blocks which need erasing now */


struct list_head erase_complete_list; /* Blocks which are erased and need
the clean marker written to them */
struct list_head free_list;

/* Blocks which are free and ready to be used */

struct list_head bad_list;

/* Bad blocks. */

struct list_head bad_used_list;

/* Bad blocks with valid data in. */

spinlock_t erase_completion_lock;

/* Protect free_list and erasing_list


against erase completion handler */

wait_queue_head_t erase_wait;

/* For waiting for erases to complete */

wait_queue_head_t inocache_wq;
struct jffs2_inode_cache **inocache_list;
spinlock_t inocache_lock;
/* Sem to allow jffs2_garbage_collect_deletion_dirent to
drop the erase_completion_lock while it's holding a pointer
to an obsoleted node. I don't like this. Alternatives welcomed. */
struct semaphore erase_free_sem;
#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
/* Write-behind buffer for NAND flash */
unsigned char *wbuf;
uint32_t wbuf_ofs;
uint32_t wbuf_len;
uint32_t wbuf_pagesize;
struct jffs2_inodirty *wbuf_inodes;
struct rw_semaphore wbuf_sem;

/* Protects the write buffer */

/* Information about out-of-band area usage... */


struct nand_oobinfo *oobinfo;
uint32_t badblock_pos;
uint32_t fsdata_pos;
uint32_t fsdata_len;
#endif

- 26 -

struct jffs2_summary *summary;

/* Summary information */

#ifdef CONFIG_JFFS2_CENT_SUM
struct cent_sum *cs_struct;

/* Centralized summary */

#endif
/* OS-private pointer for getting back to master superblock info */
void *os_priv;
};

[ 3-10 ] jffs2_sb_info

3.3 JFFS2
3.3.1 Mount
JFFS2 Mount . JFFS2 jffs2_sb_info
. . JFFS2
inode memory . inode cache .
Inode cache jffs2_inode_cache .
INOCACHE_HASHSIZE macro
. macro 128 . [ 3-11] Inode cache
macro

JFFS2

eraseblock

jffs2_eraseblock . JFFS2 jffs2_eraseblock


. c->blocks .

- 27 -

[ 3-11 ] Inode cache macro


JFFS2 JFFS . JFFS2
type node . free_list
. free_list threshold Garbage Collection
. . JFFS2
inode core memory full map
memory .
.

- 28 -

Start

Scan directory
tree

dirent
nlink++

No

Scan inodes

nlink == 0
End

Yes

inode

No

Yes

Remove inode

No

Directory inode
?
Yes
children
inodes
nlink--

[ 3-12 ] Mount Flow chart


[ 3-12] JFFS2 Mount Flow chart .
Mount directory tree . dirent nlink
. directory tree inode . inode
nlink 0 inode directory inode
inode nlink . inode
. < 3-1>
.

- 29 -

Function call

Scan directory tree

jffs2_inode_cache {
struct jffs2_full_dirent *scan_dents;}
struct jffs2_full_dirent *scan_dents;
->
void jffs2_add_fd_to_list(c, fd, &ic->scan_dents);

Dirent nlink++

->
static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct
jffs2_eraseblock *jeb, struct jffs2_raw_dirent *rd, uint32_t ofs, struct
jffs2_summary *s) {
if (jffs2_sum_active()) {
jffs2_sum_add_dirent_mem(s, rd, ofs - jeb->offset);};};

Scan inodes

jffs2_inode_cache {
struct jffs2_inode_cache *next;};
struct jffs2_raw_node_ref *nodes;
->
void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c) {

Remove inode

if (ic) {
ref->next_in_ino = ic->nodes;
ic->nodes = ref;
}; else {
ref->next_in_ino = NULL;};

dirent free

static void jffs2_free_full_dirent_list(struct jffs2_full_dirent *fd)

< 3-1 > Mount Function call

- 30 -

3.3.2 Read
Start

inode

inode info,
sb info

inodecache
No

CRC check

No

Yes

inode
fd_list
?

Yes

End

[ 3-13 ] Read Flow chart


JFFS2 read . JFFS2 jffs2_lookup()
inode number . jffs2_lookup() inode
iget() . iget() jffs2_read_inode()
inode .

- 31 -

inode

jffs2_do_read_inode()

jffs2_do_read_inode()

jffs2_get_ino_cacahe() inode inode cache .


inode cacahe 3 .
, INO_STATE_UNCHECKED, INO_STATE_CHECKEDABSENT

node

INO_STATE_READING .
, INO_STATE_CHECKING, INO_STATE_GC node
, lock . node
lock .

INO_STATE_READING,

INO_STATE_PRESENT

read .
inode_info inocache NULL .
read inode cache root node
node cache inode (ino, state) .
inode cache inode cache . inocache
. jffs2_do_read_inode_internal()
. jffs2_do_read_inode_internal() call
inode node .
jffs2_get_inode_nodes() node buffer

node

. next_in_ino . node
type < 3-2> .
- 32 -

NODETYPE

read_direntry()

JFFS2_NODETYPE_DRIENT

full_dirent

, (raw, version, ino, type, nhash, next,


name) . full_dirent fd
. (mctime_ver )
(latest_mctime) , .
read_dnode()

JFFS2_NODETYPE_INODE

node

tmp_dnode_info(tn) , node data CRC .


full_dnode(fd) tn->
fn , tn, fn
.

NODETYPE

read_unknown() . node header CRC


. CRC node

< 3-2 > NODETYPE


jffs2_get_inode_nodes() , node data node
inode info inode fragtree jffs2_tmp_dnode_info
. dents fd_list . fd_list
jffs2_get_inode_node() . node directory inode
fd_list . node CRC
. read .

3.3.3 Write
3 . ,
, .
,
VFS(Virtual File System)
. vfs_create dir inode directory
- 33 -

. vfs_create dir->
i_op->create()

JFFS2

jffs2_dir_inode_operations(i_op)

jffs2_create() .
node jffs2_raw_inode jffs2_new_inode()
. jffs2_new_inode() inode
. jffs2_init_inode_info() jffs2_inode_info

inode_cache

jffs2_do_new_inode . inode info


inode cache inode cache . jffs2_new_inode()
raw_inode . , jffs2_new_inode() OS
. jffs_create() inode , inode

jffs2_do_create() . jffs2_do_create() raw_inode


. inode directory entry inode
raw_dirent .
dirent , dirent write dirent
jffs2_full_dirent .
raw_dirent inode info directory entry full_dirent .
jffs2_do_create()
. [ 3-14] Flow chart .

- 34 -

inode_cache
inode cache inode info
inode cache list

Start

jffs2_dir_inode_operation(i_op)
raw_inode

jffs2_create()
OS

node
jffs2_raw_inode
, inode, inode

inode
write

jffs2_inode_info
End

[ 3-14 ] Create an empty file Flow chart



. jffs2_create()
. page page_cache . VFS page
jffs2_commit_write . jffs2_commit_write raw_inode

jffs2_write_inode_range()

jffs2_write_inode_range() , page . inode


cache dnode write inode info .
fragtree fragment .
- 35 -

jffs2_write_inode_range() .
jffs2_commit_write jffs2_raw_inode . [ 3-15]
Flow chart .

Start

inode cache
dnode,
write
inode info

data

page_cache
fragtree

VFS

page

data

jffs2_raw_inode free

raw_inode

fragment

End

erase

block
page

[ 3-15 ] Create a non empty file Flow chart


,
JFFS2 . jffs2_lookup()
inode number . jffs2_lookup() nhash,
directory .
inode iget() inode .
- 36 -

jffs2_prepaire_write() page offset EOF


page EOF offset hole
fragment . generic_file_buffered_write()
(VFS)

page

page

jffs2_commit_write() page write . [ 316] Flow chart .

Start

>

page offset
EOF

Yes
filename

file
page
fragment
offset

hole
EOF

inode number
VFS

page

nhash,

flash

inode
End

inode

[ 3-16 ] Modify a file Flow chart

- 37 -

No

3.3.4 Delete
VFS vfs_unlink() jffs2_unlink()
. jffs2_do_unlink() .
raw_dirent( dirent)
. dirent . dirent dirent
ino 0 version
number . raw_dirent
raw_dirent . node dents list
full_dirent fd . [ 3-17]
Flow chart .

- 38 -

Start

raw_dirent

node
raw_dirent

dents list
full_dirent

old fd
dirent

End
raw_dirent

raw_dirent

[ 3-17 ] Delete a file Flow chart

3.3.5 Garbage Collection


JFFS2 Garbage Collector(GC) . GC JFFS2
GC .

GC . GC
Mount . GC GC
. GC unchecked node dirty
GC . GC jeb(gcblock)
- 39 -

garbage collect . GC unchecked node


GC node . jeb node
jeb(c->nextblock) . node
. GC gcblock node
erase_pending_list list jeb gcblock NULL
. GC GC node . [ 318] GC Flow chart .

Start

jeb(gcblock)

raw_dirent

node

Yes

unchecked node
?

jeb

No

node
jeb

Yes
node

node

No

erase_pending_list
jeb

gcblock

NULL

End

[ 3-18 ] GC Flow chart

- 40 -

list

3.4 JFFS2
2.6 nandsim NAND .
JFFS2 . .

Windows XP Professional Version 2002, Service Pack 3

VMware Workstation 6.5.2 build-156735

Ubuntu 9.10

Linux version 2.6.31-14

#modprobe mtdblock
#modprobe mtdchar
#modprobe

nandsim

first_id_byte=0x20

second_id_byte=0xac

third_id_byte=0x00

fourth_id_byte=0x15
#mkdir /mnt/jffs2
#mkfs.jffs2 -p 512 -s 512 -e 16384 -d jffs2 -o jffs2.img
#flash_eraseall /dev/mtd0
#nandwrite /dev/mtd0 jffs2.img
#mount /dev/mtdblock0 /mnt/ -t jffs2

< 3-3 >


< 3-3> . modprobe
MTD . mnt
jffs2 nandsim nandsim 512MB,
2048 bytes page . mkfs.jffs2 jffs2.img, JFFS2 file
system image . flash_eraseall /dev/mtd0
MTD nandwrite /dev/mtd0 jffs2.img jffs2
- 41 -

. mount /dev/mtdblock0 /mnt/jffs2/ -t jffs2


jffs2 file system mount nandsim
jffs2 file system .

[ 3-19 ] VMware Workstation Ubuntu 9.10


[ 3-19] VMware Worstation Ubuntu 9.10 .
-> -> . [ 3-20]
nandsim .
ls /dev | grep mtd .
.

- 42 -

[ 3-20 ] 1

[ 3-21 ] 2
[ 3-21] jffs2 /mnt mkfs.jffs2
jffs2.img, jffs2 file system .

[ 3-22 ] 3

- 43 -

[ 3-22] flash_eraseall mtd nandwrite


jffs2 mtd . jffs2
/mnt/jffs2 .

[ 3-23 ] 4
[ 3-23] lsmod jffs2 file system
. jffs2 file system
. [ 3-24] .
[ 3-25] mp3 jffs2 .
df
.

- 44 -

[ 3-24 ] 5

[ 3-25 ] 6
- 45 -

4
,
.
, (wear leveling)
. , . , FTL
MTD API . 1999
(Axis Communications) 2.0 3
JFFS , 2.2 2.3 . JFFS
NOR , JFFS2
. JFFS2 2.4 , JFFS
.
JFFS2 . wear
leveling
. Garbage Collection
. JFFS JFFS2 Garbage
Collection . JFFS2
,
.
JFFS2 YAFFS
NAND .

- 46 -

5
1. Tae-Sun Chung, Dong-Joo Park, Sangwon Park, Dong-Ho Lee, Sang-Won Lee, and
Ha-Joo Song. System Software for Flash Memory: A Survey, Submitted for
publication, 2004.
2. Won-Joo Park, Hyun-Seok Yoo, Sung-Hwan Park, Do-Yun Kim, Sangwon Park.
Performance Analysis of FTL Algorithms in Flash Memory for Windows File
Systems,
3. Sung-Hwan Park, Hyun-Seok Yoo, Do Yun Kim, Won-Joo Park, Kisun Oh, Sang-Won
Lee, Sangwon Park. Development of Performance Analysis Tool for Flash Disk on
Windows Platform,
4. Flash-Memory Storage Systems. RTCSA, 2003.
5. David Woodhouse. JFFS - The Journalling Flash File System, Red Hat, Inc. 2004.
6. P., , , .Embedded Linux System
Design And Development, ITC. 2007.
7. , . , IT EXPERT.
2006.
8. , , . , IT EXPERT. 2006.
9. ,

2009

36 1 (B), 2009.

- 47 -

10. , , . NAND
, 2006 (A), 2006.
11. , , . ,
2003 30 2 (I), 2003.
12. , , . ,
2005 6 2 , 2005.
13. , , , . JFFS2 Garbage Collector ,
2005 (I) 32 2 , 2005.
14. , , , . JFFS2 Garbage Collector
, 2004 31 2 (I), 2004.
15. , . NAND

34

11,12 , 2007.
16. ,

NAND

-SD 46 SD 3 , 2009.

- 48 -

You might also like