-
static int write_object_header(int id, enum yaffs_obj_type t, struct stat *s, int parent, const char *name, int equivalentObj, const char * alias)
-
{
-
u8 bytes[chunkSize];
-
-
-
struct yaffs_obj_hdr *oh = (struct yaffs_obj_hdr *)bytes;
-
-
memset(bytes,0xff,sizeof(bytes));
-
-
oh->type = t;
-
-
oh->parent_obj_id = parent;
-
-
if (strlen(name)+1 > sizeof(oh->name))
-
{
-
errno = ENAMETOOLONG;
-
return warn("object name");
-
}
-
memset(oh->name,0,sizeof(oh->name));
-
strcpy(oh->name,name);
-
-
-
if(t != YAFFS_OBJECT_TYPE_HARDLINK)
-
{
-
oh->yst_mode = s->st_mode;
-
oh->yst_uid = s->st_uid;
-
// NCB 12/9/02 oh->yst_gid = s->yst_uid;
-
oh->yst_gid = s->st_gid;
-
oh->yst_atime = s->st_atime;
-
oh->yst_mtime = s->st_mtime;
-
oh->yst_ctime = s->st_ctime;
-
oh->yst_rdev = s->st_rdev;
-
}
-
-
if(t == YAFFS_OBJECT_TYPE_FILE)
-
{
-
oh->file_size_low = s->st_size;
-
oh->file_size_high = (s->st_size >> 32);
-
}
-
-
if(t == YAFFS_OBJECT_TYPE_HARDLINK)
-
{
-
oh->equiv_id = equivalentObj;
-
}
-
-
if(t == YAFFS_OBJECT_TYPE_SYMLINK)
-
{
-
if (strlen(alias)+1 > sizeof(oh->alias))
-
{
-
errno = ENAMETOOLONG;
-
return warn("object alias");
-
}
-
memset(oh->alias,0,sizeof(oh->alias));
-
strcpy(oh->alias,alias);
-
}
-
-
if (convert_endian)
-
{
-
object_header_little_to_big_endian(oh);
-
}
-
-
return write_chunk(bytes,id,0,0xffff);
-
-
}
-
-
-
static int write_chunk(u8 *data, u32 id, u32 chunk_id, u32 n_bytes)
-
{
-
struct yaffs_ext_tags t;
-
struct yaffs_packed_tags2 pt;//28byte
-
char spareData[spareSize];
-
-
if (write(outFile,data,chunkSize) != chunkSize)
-
fatal("write");
-
-
memset(&t, 0, sizeof(t));
-
-
t.chunk_id = chunk_id;
-
// t.serial_number = 0;
-
t.serial_number = 1; // **CHECK**
-
t.n_bytes = n_bytes; // 0xffff=65536
-
t.obj_id = id;
-
-
t.seq_number = YAFFS_LOWEST_SEQUENCE_NUMBER;
-
-
// added NCB **CHECK**
-
t.chunk_used = 1;
-
-
if (convert_endian)
-
{
-
little_to_big_endian(&t);
-
}
-
-
nPages++;
-
-
memset(&pt, 0, sizeof(pt));//28bytes
-
yaffs_pack_tags2(&pt,&t,1);//(struct yaffs_packed_tags2 *pt,
-
//const struct yaffs_ext_tags *t, int tags_ecc)
-
-
memset(spareData, 0xff, sizeof(spareData));//先全部置0xff
-
shuffle_oob(spareData, &pt);//填充28bytes
-
-
if (write(outFile,spareData,sizeof(spareData)) != sizeof(spareData))
-
fatal("write");
-
return 0;
-
}
-
-
-
struct yaffs_ext_tags {
-
unsigned chunk_used; /* Status of the chunk: used or unused */
-
unsigned obj_id; /* If 0 this is not used */
-
unsigned chunk_id; /* If 0 this is a header, else a data chunk */
-
unsigned n_bytes; /* Only valid for data chunks */
-
-
/* The following stuff only has meaning when we read */
-
enum yaffs_ecc_result ecc_result;
-
unsigned block_bad;
-
-
/* YAFFS 1 stuff */
-
unsigned is_deleted; /* The chunk is marked deleted */
-
unsigned serial_number; /* Yaffs1 2-bit serial number */
-
-
/* YAFFS2 stuff */
-
unsigned seq_number; /* The sequence number of this block */
-
-
/* Extra info if this is an object header (YAFFS2 only) */
-
-
unsigned extra_available; /* Extra info available if not zero */
-
unsigned extra_parent_id; /* The parent object */
-
unsigned extra_is_shrink; /* Is it a shrink header? */
-
unsigned extra_shadows; /* Does this shadow another object? */
-
-
enum yaffs_obj_type extra_obj_type; /* What object type? */
-
-
loff_t extra_file_size; /* Length if it is a file */
-
unsigned extra_equiv_id; /* Equivalent object for a hard link */
-
};
-
-
struct yaffs_packed_tags2 {
-
struct yaffs_packed_tags2_tags_only t; //16byte
-
struct yaffs_ecc_other ecc; //12byte
-
};
-
-
struct yaffs_packed_tags2_tags_only {
-
unsigned seq_number;
-
unsigned obj_id;
-
unsigned chunk_id;
-
unsigned n_bytes;
-
};//16 byte
-
-
struct yaffs_ecc_other {
-
unsigned char col_parity;
-
unsigned line_parity;
-
unsigned line_parity_prime;
-
};//3*4 = 12byte
关键是yaffs_packed_tags2这个数据,在write_chunk函数中有shuffle_oob(spareData, &pt)函数,实际上就是向OOB填充了28字节yaffs_packed_tags2,因此yaffs2需要占用28字节的OOB空间。
这里就可以看出yaffs2会造成u-boot提示坏块了,因为OOB前面两个字节被填写了tags的内容,不再是0xff。如果不想uboot提示坏块,可以将shuffle_oob(spareData, &pt);修改为shuffle_oob(spareData + 2, &pt);
更合理的做法是使用MTD_OPS_AUTO_OOB方式写入数据,这样yaffs tags就能正常写入了。
阅读(3212) | 评论(0) | 转发(0) |