X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=yaffs_yaffs1.c;h=b6c43e5ef3571c88c4e8a25b1698fa4efa372bee;hp=cc717461c66c3887590c9efb66189faa14e87a1b;hb=fc8b640f9637823d87b9582c7edcb87adcd0383a;hpb=41573908f821bcb40750e7c069ea8f5178f630e5 diff --git a/yaffs_yaffs1.c b/yaffs_yaffs1.c index cc71746..b6c43e5 100644 --- a/yaffs_yaffs1.c +++ b/yaffs_yaffs1.c @@ -10,54 +10,50 @@ * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ + #include "yaffs_yaffs1.h" #include "yportenv.h" #include "yaffs_trace.h" #include "yaffs_bitmap.h" #include "yaffs_getblockinfo.h" #include "yaffs_nand.h" +#include "yaffs_attribs.h" - -int yaffs1_scan(yaffs_dev_t *dev) +int yaffs1_scan(struct yaffs_dev *dev) { - yaffs_ext_tags tags; + struct yaffs_ext_tags tags; int blk; - int blockIterator; - int startIterator; - int endIterator; int result; int chunk; int c; int deleted; - yaffs_block_state_t state; - yaffs_obj_t *hard_list = NULL; - yaffs_block_info_t *bi; - __u32 seq_number; - yaffs_obj_header *oh; - yaffs_obj_t *in; - yaffs_obj_t *parent; + enum yaffs_block_state state; + struct yaffs_obj *hard_list = NULL; + struct yaffs_block_info *bi; + u32 seq_number; + struct yaffs_obj_hdr *oh; + struct yaffs_obj *in; + struct yaffs_obj *parent; int alloc_failed = 0; - struct yaffs_shadow_fixer_s *shadowFixerList = NULL; - - - __u8 *chunkData; - + struct yaffs_shadow_fixer *shadow_fixers = NULL; + u8 *chunk_data; T(YAFFS_TRACE_SCAN, (TSTR("yaffs1_scan starts intstartblk %d intendblk %d..." TENDSTR), dev->internal_start_block, dev->internal_end_block)); - chunkData = yaffs_get_temp_buffer(dev, __LINE__); + chunk_data = yaffs_get_temp_buffer(dev, __LINE__); dev->seq_number = YAFFS_LOWEST_SEQUENCE_NUMBER; /* Scan all the blocks to determine their state */ bi = dev->block_info; - for (blk = dev->internal_start_block; blk <= dev->internal_end_block; blk++) { + for (blk = dev->internal_start_block; blk <= dev->internal_end_block; + blk++) { yaffs_clear_chunk_bits(dev, blk); bi->pages_in_use = 0; bi->soft_del_pages = 0; @@ -86,36 +82,30 @@ int yaffs1_scan(yaffs_dev_t *dev) bi++; } - startIterator = dev->internal_start_block; - endIterator = dev->internal_end_block; - /* For each block.... */ - for (blockIterator = startIterator; !alloc_failed && blockIterator <= endIterator; - blockIterator++) { + for (blk = dev->internal_start_block; + !alloc_failed && blk <= dev->internal_end_block; blk++) { YYIELD(); - YYIELD(); - - blk = blockIterator; - bi = yaffs_get_block_info(dev, blk); state = bi->block_state; deleted = 0; - /* For each chunk in each block that needs scanning....*/ + /* For each chunk in each block that needs scanning.... */ for (c = 0; !alloc_failed && c < dev->param.chunks_per_block && state == YAFFS_BLOCK_STATE_NEEDS_SCANNING; c++) { /* Read the tags and decide what to do */ chunk = blk * dev->param.chunks_per_block + c; result = yaffs_rd_chunk_tags_nand(dev, chunk, NULL, - &tags); + &tags); /* Let's have a good look at this chunk... */ - if (tags.ecc_result == YAFFS_ECC_RESULT_UNFIXED || tags.is_deleted) { + if (tags.ecc_result == YAFFS_ECC_RESULT_UNFIXED + || tags.is_deleted) { /* YAFFS1 only... * A deleted chunk */ @@ -146,7 +136,8 @@ int yaffs1_scan(yaffs_dev_t *dev) } - dev->n_free_chunks += (dev->param.chunks_per_block - c); + dev->n_free_chunks += + (dev->param.chunks_per_block - c); } else if (tags.chunk_id > 0) { /* chunk_id > 0 so it is a data chunk... */ unsigned int endpos; @@ -155,9 +146,8 @@ int yaffs1_scan(yaffs_dev_t *dev) bi->pages_in_use++; in = yaffs_find_or_create_by_number(dev, - tags. - obj_id, - YAFFS_OBJECT_TYPE_FILE); + tags.obj_id, + YAFFS_OBJECT_TYPE_FILE); /* PutChunkIntoFile checks for a clash (two data chunks with * the same chunk_id). */ @@ -166,24 +156,27 @@ int yaffs1_scan(yaffs_dev_t *dev) alloc_failed = 1; if (in) { - if (!yaffs_put_chunk_in_file(in, tags.chunk_id, chunk, 1)) + if (!yaffs_put_chunk_in_file + (in, tags.chunk_id, chunk, 1)) alloc_failed = 1; } endpos = - (tags.chunk_id - 1) * dev->data_bytes_per_chunk + + (tags.chunk_id - + 1) * dev->data_bytes_per_chunk + tags.n_bytes; - if (in && - in->variant_type == YAFFS_OBJECT_TYPE_FILE + if (in + && in->variant_type == + YAFFS_OBJECT_TYPE_FILE && in->variant.file_variant.scanned_size < endpos) { - in->variant.file_variant. - scanned_size = endpos; + in->variant.file_variant.scanned_size = + endpos; if (!dev->param.use_header_file_size) { - in->variant.file_variant. - file_size = - in->variant.file_variant. - scanned_size; + in->variant. + file_variant.file_size = + in->variant. + file_variant.scanned_size; } } @@ -196,13 +189,12 @@ int yaffs1_scan(yaffs_dev_t *dev) bi->pages_in_use++; result = yaffs_rd_chunk_tags_nand(dev, chunk, - chunkData, - NULL); + chunk_data, + NULL); - oh = (yaffs_obj_header *) chunkData; + oh = (struct yaffs_obj_hdr *)chunk_data; - in = yaffs_find_by_number(dev, - tags.obj_id); + in = yaffs_find_by_number(dev, tags.obj_id); if (in && in->variant_type != oh->type) { /* This should not happen, but somehow * Wev'e ended up with an obj_id that has been reused but not yet @@ -215,26 +207,30 @@ int yaffs1_scan(yaffs_dev_t *dev) } in = yaffs_find_or_create_by_number(dev, - tags. - obj_id, - oh->type); + tags.obj_id, + oh->type); if (!in) alloc_failed = 1; if (in && oh->shadows_obj > 0) { - struct yaffs_shadow_fixer_s *fixer; - fixer = YMALLOC(sizeof(struct yaffs_shadow_fixer_s)); + struct yaffs_shadow_fixer *fixer; + fixer = + YMALLOC(sizeof + (struct + yaffs_shadow_fixer)); if (fixer) { - fixer->next = shadowFixerList; - shadowFixerList = fixer; + fixer->next = shadow_fixers; + shadow_fixers = fixer; fixer->obj_id = tags.obj_id; - fixer->shadowed_id = oh->shadows_obj; + fixer->shadowed_id = + oh->shadows_obj; T(YAFFS_TRACE_SCAN, (TSTR - (" Shadow fixer: %d shadows %d" TENDSTR), - fixer->obj_id, fixer->shadowed_id)); + (" Shadow fixer: %d shadows %d" + TENDSTR), fixer->obj_id, + fixer->shadowed_id)); } @@ -243,45 +239,34 @@ int yaffs1_scan(yaffs_dev_t *dev) if (in && in->valid) { /* We have already filled this one. We have a duplicate and need to resolve it. */ - unsigned existingSerial = in->serial; - unsigned newSerial = tags.serial_number; + unsigned existing_serial = in->serial; + unsigned new_serial = + tags.serial_number; - if (((existingSerial + 1) & 3) == newSerial) { + if (((existing_serial + 1) & 3) == + new_serial) { /* Use new one - destroy the exisiting one */ yaffs_chunk_del(dev, - in->hdr_chunk, - 1, __LINE__); + in->hdr_chunk, + 1, __LINE__); in->valid = 0; } else { /* Use existing - destroy this one. */ yaffs_chunk_del(dev, chunk, 1, - __LINE__); + __LINE__); } } if (in && !in->valid && (tags.obj_id == YAFFS_OBJECTID_ROOT || - tags.obj_id == YAFFS_OBJECTID_LOSTNFOUND)) { + tags.obj_id == + YAFFS_OBJECTID_LOSTNFOUND)) { /* We only load some info, don't fiddle with directory structure */ in->valid = 1; in->variant_type = oh->type; in->yst_mode = oh->yst_mode; -#ifdef CONFIG_YAFFS_WINCE - in->win_atime[0] = oh->win_atime[0]; - in->win_ctime[0] = oh->win_ctime[0]; - in->win_mtime[0] = oh->win_mtime[0]; - in->win_atime[1] = oh->win_atime[1]; - in->win_ctime[1] = oh->win_ctime[1]; - in->win_mtime[1] = oh->win_mtime[1]; -#else - in->yst_uid = oh->yst_uid; - in->yst_gid = oh->yst_gid; - in->yst_atime = oh->yst_atime; - in->yst_mtime = oh->yst_mtime; - in->yst_ctime = oh->yst_ctime; - in->yst_rdev = oh->yst_rdev; -#endif + yaffs_load_attribs(in, oh); in->hdr_chunk = chunk; in->serial = tags.serial_number; @@ -292,21 +277,7 @@ int yaffs1_scan(yaffs_dev_t *dev) in->variant_type = oh->type; in->yst_mode = oh->yst_mode; -#ifdef CONFIG_YAFFS_WINCE - in->win_atime[0] = oh->win_atime[0]; - in->win_ctime[0] = oh->win_ctime[0]; - in->win_mtime[0] = oh->win_mtime[0]; - in->win_atime[1] = oh->win_atime[1]; - in->win_ctime[1] = oh->win_ctime[1]; - in->win_mtime[1] = oh->win_mtime[1]; -#else - in->yst_uid = oh->yst_uid; - in->yst_gid = oh->yst_gid; - in->yst_atime = oh->yst_atime; - in->yst_mtime = oh->yst_mtime; - in->yst_ctime = oh->yst_ctime; - in->yst_rdev = oh->yst_rdev; -#endif + yaffs_load_attribs(in, oh); in->hdr_chunk = chunk; in->serial = tags.serial_number; @@ -327,11 +298,11 @@ int yaffs1_scan(yaffs_dev_t *dev) YAFFS_OBJECT_TYPE_UNKNOWN) { /* Set up as a directory */ parent->variant_type = - YAFFS_OBJECT_TYPE_DIRECTORY; - YINIT_LIST_HEAD(&parent->variant. - dir_variant. - children); - } else if (!parent || parent->variant_type != + YAFFS_OBJECT_TYPE_DIRECTORY; + INIT_LIST_HEAD(&parent-> + variant.dir_variant.children); + } else if (!parent + || parent->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY) { /* Hoosterman, another problem.... * We're trying to use a non-directory as a directory @@ -347,7 +318,8 @@ int yaffs1_scan(yaffs_dev_t *dev) yaffs_add_obj_to_dir(parent, in); if (0 && (parent == dev->del_dir || - parent == dev->unlinked_dir)) { + parent == + dev->unlinked_dir)) { in->deleted = 1; /* If it is unlinked at start up then it wants deleting */ dev->n_deleted_files++; } @@ -363,20 +335,21 @@ int yaffs1_scan(yaffs_dev_t *dev) /* Todo got a problem */ break; case YAFFS_OBJECT_TYPE_FILE: - if (dev->param.use_header_file_size) + if (dev->param. + use_header_file_size) - in->variant.file_variant. - file_size = - oh->file_size; + in->variant. + file_variant.file_size + = oh->file_size; break; case YAFFS_OBJECT_TYPE_HARDLINK: - in->variant.hardlink_variant. - equiv_id = - oh->equiv_id; + in->variant. + hardlink_variant.equiv_id = + oh->equiv_id; in->hard_links.next = - (struct ylist_head *) - hard_list; + (struct list_head *) + hard_list; hard_list = in; break; case YAFFS_OBJECT_TYPE_DIRECTORY: @@ -386,9 +359,11 @@ int yaffs1_scan(yaffs_dev_t *dev) /* Do nothing */ break; case YAFFS_OBJECT_TYPE_SYMLINK: - in->variant.symlink_variant.alias = + in->variant.symlink_variant. + alias = yaffs_clone_str(oh->alias); - if (!in->variant.symlink_variant.alias) + if (!in->variant. + symlink_variant.alias) alloc_failed = 1; break; } @@ -398,12 +373,12 @@ int yaffs1_scan(yaffs_dev_t *dev) } if (state == YAFFS_BLOCK_STATE_NEEDS_SCANNING) { - /* If we got this far while scanning, then the block is fully allocated.*/ + /* If we got this far while scanning, then the block is fully allocated. */ state = YAFFS_BLOCK_STATE_FULL; } if (state == YAFFS_BLOCK_STATE_ALLOCATING) { - /* If the block was partially allocated then treat it as fully allocated.*/ + /* If the block was partially allocated then treat it as fully allocated. */ state = YAFFS_BLOCK_STATE_FULL; dev->alloc_block = -1; } @@ -419,7 +394,6 @@ int yaffs1_scan(yaffs_dev_t *dev) } - /* Ok, we've done all the scanning. * Fix up the hard link chains. * We should now have scanned all the objects, now it's time to add these @@ -430,12 +404,12 @@ int yaffs1_scan(yaffs_dev_t *dev) /* Fix up any shadowed objects */ { - struct yaffs_shadow_fixer_s *fixer; - yaffs_obj_t *obj; + struct yaffs_shadow_fixer *fixer; + struct yaffs_obj *obj; - while (shadowFixerList) { - fixer = shadowFixerList; - shadowFixerList = fixer->next; + while (shadow_fixers) { + fixer = shadow_fixers; + shadow_fixers = fixer->next; /* Complete the rename transaction by deleting the shadowed object * then setting the object header to unshadowed. */ @@ -452,14 +426,12 @@ int yaffs1_scan(yaffs_dev_t *dev) } } - yaffs_release_temp_buffer(dev, chunkData, __LINE__); + yaffs_release_temp_buffer(dev, chunk_data, __LINE__); if (alloc_failed) return YAFFS_FAIL; T(YAFFS_TRACE_SCAN, (TSTR("yaffs1_scan ends" TENDSTR))); - return YAFFS_OK; } -