From: Charles Manning Date: Tue, 21 Jan 2014 23:14:26 +0000 (+1300) Subject: Change the object type if it turns out to be wrong during a scan X-Git-Tag: aleph1-release~46 X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=6014fce5c65757724aef9033f2a710da324f2523;ds=sidebyside Change the object type if it turns out to be wrong during a scan This might result in some files ending up in lost but at least we can get the file system to mount. Signed-off-by: Charles Manning --- diff --git a/yaffs_guts.c b/yaffs_guts.c index 1fd464d..d3e877f 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -3950,6 +3950,70 @@ int yaffs_del_obj(struct yaffs_obj *obj) return ret_val; } + +static void yaffs_empty_dir_to_dir(struct yaffs_obj *from_dir, + struct yaffs_obj *to_dir) +{ + struct yaffs_obj *obj; + struct list_head *lh; + struct list_head *n; + + list_for_each_safe(lh, n, &from_dir->variant.dir_variant.children) { + obj = list_entry(lh, struct yaffs_obj, siblings); + yaffs_add_obj_to_dir(to_dir, obj); + } +} + +struct yaffs_obj *yaffs_retype_obj(struct yaffs_obj *obj, + enum yaffs_obj_type type) +{ + /* Tear down the old variant */ + switch (obj->variant_type) { + case YAFFS_OBJECT_TYPE_FILE: + /* Nuke file data */ + yaffs_resize_file(obj, 0); + yaffs_free_tnode(obj->my_dev, obj->variant.file_variant.top); + obj->variant.file_variant.top = NULL; + break; + case YAFFS_OBJECT_TYPE_DIRECTORY: + /* Put the children in lost and found. */ + yaffs_empty_dir_to_dir(obj, obj->my_dev->lost_n_found); + if (!list_empty(&obj->variant.dir_variant.dirty)) + list_del_init(&obj->variant.dir_variant.dirty); + break; + case YAFFS_OBJECT_TYPE_SYMLINK: + /* Nuke symplink data */ + kfree(obj->variant.symlink_variant.alias); + obj->variant.symlink_variant.alias = NULL; + break; + case YAFFS_OBJECT_TYPE_HARDLINK: + list_del_init(&obj->hard_links); + break; + default: + break; + } + + memset(&obj->variant, 0, sizeof(obj->variant)); + + /*Set up new variant if the memset is not enough. */ + switch (type) { + case YAFFS_OBJECT_TYPE_DIRECTORY: + INIT_LIST_HEAD(&obj->variant.dir_variant.children); + INIT_LIST_HEAD(&obj->variant.dir_variant.dirty); + break; + case YAFFS_OBJECT_TYPE_FILE: + case YAFFS_OBJECT_TYPE_SYMLINK: + case YAFFS_OBJECT_TYPE_HARDLINK: + default: + break; + } + + obj->variant_type = type; + + return obj; + +} + static int yaffs_unlink_worker(struct yaffs_obj *obj) { int del_now = 0; diff --git a/yaffs_guts.h b/yaffs_guts.h index 0578536..d89f8b0 100644 --- a/yaffs_guts.h +++ b/yaffs_guts.h @@ -776,6 +776,7 @@ struct yaffs_dev { u32 n_page_writes; u32 n_page_reads; u32 n_erasures; + u32 n_bad_queries; u32 n_bad_markings; u32 n_erase_failures; u32 n_gc_copies; @@ -854,6 +855,9 @@ int yaffs_rename_obj(struct yaffs_obj *old_dir, const YCHAR * old_name, int yaffs_unlinker(struct yaffs_obj *dir, const YCHAR * name); int yaffs_del_obj(struct yaffs_obj *obj); +struct yaffs_obj *yaffs_retype_obj(struct yaffs_obj *obj, + enum yaffs_obj_type type); + int yaffs_get_obj_name(struct yaffs_obj *obj, YCHAR * name, int buffer_size); loff_t yaffs_get_obj_length(struct yaffs_obj *obj); diff --git a/yaffs_yaffs2.c b/yaffs_yaffs2.c index f1dc972..8c31a66 100644 --- a/yaffs_yaffs2.c +++ b/yaffs_yaffs2.c @@ -1193,12 +1193,14 @@ static inline int yaffs2_scan_chunk(struct yaffs_dev *dev, } if (!in->valid && in->variant_type != - (oh ? oh->type : tags.extra_obj_type)) + (oh ? oh->type : tags.extra_obj_type)) { yaffs_trace(YAFFS_TRACE_ERROR, - "yaffs tragedy: Bad object type, %d != %d, for object %d at chunk %d during scan", + "yaffs tragedy: Bad type, %d != %d, for object %d at chunk %d during scan", oh ? oh->type : tags.extra_obj_type, in->variant_type, tags.obj_id, chunk); + in = yaffs_retype_obj(in, oh ? oh->type : tags.extra_obj_type); + } if (!in->valid && (tags.obj_id == YAFFS_OBJECTID_ROOT || @@ -1439,7 +1441,7 @@ int yaffs2_scan_backwards(struct yaffs_dev *dev) bi++; } - yaffs_trace(YAFFS_TRACE_SCAN, "%d blocks to be sorted...", n_to_scan); + yaffs_trace(YAFFS_TRACE_ALWAYS, "%d blocks to be sorted...", n_to_scan); cond_resched();