資源簡介
2017年5月更新的yaff2源碼
代碼片段和文件信息
/*
?*?YAFFS:?Yet?Another?Flash?File?System.?A?NAND-flash?specific?file?system.
?*
?*?Copyright?(C)?2002-2011?Aleph?One?Ltd.
?*???for?Toby?Churchill?Ltd?and?Brightstar?Engineering
?*
?*?Created?by?Charles?Manning?
?*
?*?This?program?is?free?software;?you?can?redistribute?it?and/or?modify
?*?it?under?the?terms?of?the?GNU?General?Public?License?version?2?as
?*?published?by?the?Free?Software?Foundation.
?*/
#include?“yaffs_allocator.h“
#include?“yaffs_guts.h“
#include?“yaffs_trace.h“
#include?“yportenv.h“
/*
?*?Each?entry?in?yaffs_tnode_list?and?yaffs_obj_list?hold?blocks
?*?of?approx?100?objects?that?are?themn?allocated?singly.
?*?This?is?basically?a?simplified?slab?allocator.
?*
?*?We?don‘t?use?the?Linux?slab?allocator?because?slab?does?not?allow
?*?us?to?dump?all?the?objects?in?one?hit?when?we?do?a?umount?and?tear
?*?down??all?the?tnodes?and?objects.?slab?requires?that?we?first?free
?*?the?individual?objects.
?*
?*?Once?yaffs?has?been?mainlined?I?shall?try?to?motivate?for?a?change
?*?to?slab?to?provide?the?extra?features?we?need?here.
?*/
struct?yaffs_tnode_list?{
struct?yaffs_tnode_list?*next;
struct?yaffs_tnode?*tnodes;
};
struct?yaffs_obj_list?{
struct?yaffs_obj_list?*next;
struct?yaffs_obj?*objects;
};
struct?yaffs_allocator?{
int?n_tnodes_created;
struct?yaffs_tnode?*free_tnodes;
int?n_free_tnodes;
struct?yaffs_tnode_list?*alloc_tnode_list;
int?n_obj_created;
struct?list_head?free_objs;
int?n_free_objects;
struct?yaffs_obj_list?*allocated_obj_list;
};
static?void?yaffs_deinit_raw_tnodes(struct?yaffs_dev?*dev)
{
struct?yaffs_allocator?*allocator?=
????(struct?yaffs_allocator?*)dev->allocator;
struct?yaffs_tnode_list?*tmp;
if?(!allocator)?{
BUG();
return;
}
while?(allocator->alloc_tnode_list)?{
tmp?=?allocator->alloc_tnode_list->next;
kfree(allocator->alloc_tnode_list->tnodes);
kfree(allocator->alloc_tnode_list);
allocator->alloc_tnode_list?=?tmp;
}
allocator->free_tnodes?=?NULL;
allocator->n_free_tnodes?=?0;
allocator->n_tnodes_created?=?0;
}
static?void?yaffs_init_raw_tnodes(struct?yaffs_dev?*dev)
{
struct?yaffs_allocator?*allocator?=?dev->allocator;
if?(!allocator)?{
BUG();
return;
}
allocator->alloc_tnode_list?=?NULL;
allocator->free_tnodes?=?NULL;
allocator->n_free_tnodes?=?0;
allocator->n_tnodes_created?=?0;
}
static?int?yaffs_create_tnodes(struct?yaffs_dev?*dev?int?n_tnodes)
{
struct?yaffs_allocator?*allocator?=
????(struct?yaffs_allocator?*)dev->allocator;
int?i;
struct?yaffs_tnode?*new_tnodes;
u8?*mem;
struct?yaffs_tnode?*curr;
struct?yaffs_tnode?*next;
struct?yaffs_tnode_list?*tnl;
if?(!allocator)?{
BUG();
return?YAFFS_FAIL;
}
if?(n_tnodes?1)
return?YAFFS_OK;
/*?make?these?things?*/
new_tnodes?=?kmalloc(n_tnodes?*?dev->tnode_size?GFP_NOFS);
mem?=?(u8?*)?new_tnodes;
if?(!new_tnodes)?{
yaffs_trace(YAFFS_TRACE_ERROR
“yaffs:?Could?not?allocate?Tnodes“);
return?YAFFS_FAIL;
}
/*?New?hookup?for?wide?tnodes?*/
for?(i?=?0
評論
共有 條評論