Mercurial > yaffs-ecoscentric-gpl
comparison packages/fs/yaffs/current/src/yaffs_guts.c @ 428:a386ed10401a ecos
Drop in eCos bridge work
| author | Ross Younger <wry@ecoscentric.com> |
|---|---|
| date | Fri, 14 May 2010 17:01:32 +0100 |
| parents | dea4d7d250ad |
| children |
comparison
equal
deleted
inserted
replaced
| 427:d52e3cced121 | 428:a386ed10401a |
|---|---|
| 46 | 46 |
| 47 #include "yaffs_ecc.h" | 47 #include "yaffs_ecc.h" |
| 48 | 48 |
| 49 | 49 |
| 50 /* Robustification (if it ever comes about...) */ | 50 /* Robustification (if it ever comes about...) */ |
| 51 /* eCos note: I have discussed the existence of robustification hooks | |
| 52 * with Charles Manning. He put them in as stubs, but then concluded | |
| 53 * that there was no value in filling them in. | |
| 54 * - wry, 2009-06-19 */ | |
| 51 static void yaffs_RetireBlock(yaffs_Device *dev, int blockInNAND); | 55 static void yaffs_RetireBlock(yaffs_Device *dev, int blockInNAND); |
| 52 static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND, | 56 static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND, |
| 53 int erasedOk); | 57 int erasedOk); |
| 54 static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND, | 58 static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND, |
| 55 const __u8 *data, | 59 const __u8 *data, |
| 563 if (obj && yaffs_SkipVerification(obj->myDev)) | 567 if (obj && yaffs_SkipVerification(obj->myDev)) |
| 564 return; | 568 return; |
| 565 | 569 |
| 566 if (!(tags && obj && oh)) { | 570 if (!(tags && obj && oh)) { |
| 567 T(YAFFS_TRACE_VERIFY, | 571 T(YAFFS_TRACE_VERIFY, |
| 568 (TSTR("Verifying object header tags %p obj %p oh %p"TENDSTR), | 572 (TSTR("Verifying object header tags %x obj %x oh %x"TENDSTR), |
| 569 tags, obj, oh)); | 573 (__u32)tags, (__u32)obj, (__u32)oh)); |
| 570 return; | 574 return; |
| 571 } | 575 } |
| 572 | 576 |
| 573 if (oh->type <= YAFFS_OBJECT_TYPE_UNKNOWN || | 577 if (oh->type <= YAFFS_OBJECT_TYPE_UNKNOWN || |
| 574 oh->type > YAFFS_OBJECT_TYPE_MAX) | 578 oh->type > YAFFS_OBJECT_TYPE_MAX) |
| 4472 } | 4476 } |
| 4473 } | 4477 } |
| 4474 | 4478 |
| 4475 /*--------------------- Checkpointing --------------------*/ | 4479 /*--------------------- Checkpointing --------------------*/ |
| 4476 | 4480 |
| 4477 | 4481 #ifdef CYGSEM_FS_YAFFS_OMIT_YAFFS2_CODE |
| 4482 #else | |
| 4478 static int yaffs_WriteCheckpointValidityMarker(yaffs_Device *dev, int head) | 4483 static int yaffs_WriteCheckpointValidityMarker(yaffs_Device *dev, int head) |
| 4479 { | 4484 { |
| 4480 yaffs_CheckpointValidity cp; | 4485 yaffs_CheckpointValidity cp; |
| 4481 | 4486 |
| 4482 memset(&cp, 0, sizeof(cp)); | 4487 memset(&cp, 0, sizeof(cp)); |
| 4977 dev->isCheckpointed = 0; | 4982 dev->isCheckpointed = 0; |
| 4978 | 4983 |
| 4979 return ok ? 1 : 0; | 4984 return ok ? 1 : 0; |
| 4980 | 4985 |
| 4981 } | 4986 } |
| 4987 #endif // !OMIT_YAFFS2_CODE | |
| 4982 | 4988 |
| 4983 static void yaffs_InvalidateCheckpoint(yaffs_Device *dev) | 4989 static void yaffs_InvalidateCheckpoint(yaffs_Device *dev) |
| 4984 { | 4990 { |
| 4985 if (dev->isCheckpointed || | 4991 if (dev->isCheckpointed || |
| 4986 dev->blocksInCheckpoint > 0) { | 4992 dev->blocksInCheckpoint > 0) { |
| 5001 yaffs_VerifyBlocks(dev); | 5007 yaffs_VerifyBlocks(dev); |
| 5002 yaffs_VerifyFreeChunks(dev); | 5008 yaffs_VerifyFreeChunks(dev); |
| 5003 | 5009 |
| 5004 if (!dev->isCheckpointed) { | 5010 if (!dev->isCheckpointed) { |
| 5005 yaffs_InvalidateCheckpoint(dev); | 5011 yaffs_InvalidateCheckpoint(dev); |
| 5012 #ifdef CYGSEM_FS_YAFFS_OMIT_YAFFS2_CODE | |
| 5013 #else | |
| 5006 yaffs_WriteCheckpointData(dev); | 5014 yaffs_WriteCheckpointData(dev); |
| 5015 #endif | |
| 5007 } | 5016 } |
| 5008 | 5017 |
| 5009 T(YAFFS_TRACE_ALWAYS, (TSTR("save exit: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); | 5018 T(YAFFS_TRACE_ALWAYS, (TSTR("save exit: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); |
| 5010 | 5019 |
| 5011 return dev->isCheckpointed; | 5020 return dev->isCheckpointed; |
| 5012 } | 5021 } |
| 5013 | 5022 |
| 5023 #ifdef CYGSEM_FS_YAFFS_OMIT_YAFFS2_CODE | |
| 5024 #else | |
| 5014 int yaffs_CheckpointRestore(yaffs_Device *dev) | 5025 int yaffs_CheckpointRestore(yaffs_Device *dev) |
| 5015 { | 5026 { |
| 5016 int retval; | 5027 int retval; |
| 5017 T(YAFFS_TRACE_CHECKPOINT, (TSTR("restore entry: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); | 5028 T(YAFFS_TRACE_CHECKPOINT, (TSTR("restore entry: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); |
| 5018 | 5029 |
| 5026 | 5037 |
| 5027 T(YAFFS_TRACE_CHECKPOINT, (TSTR("restore exit: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); | 5038 T(YAFFS_TRACE_CHECKPOINT, (TSTR("restore exit: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); |
| 5028 | 5039 |
| 5029 return retval; | 5040 return retval; |
| 5030 } | 5041 } |
| 5042 #endif | |
| 5031 | 5043 |
| 5032 /*--------------------- File read/write ------------------------ | 5044 /*--------------------- File read/write ------------------------ |
| 5033 * Read and write have very similar structures. | 5045 * Read and write have very similar structures. |
| 5034 * In general the read/write has three parts to it | 5046 * In general the read/write has three parts to it |
| 5035 * An incomplete chunk to start with (if the read/write is not chunk-aligned) | 5047 * An incomplete chunk to start with (if the read/write is not chunk-aligned) |
| 5814 return yaffs_UnlinkObject(obj); | 5826 return yaffs_UnlinkObject(obj); |
| 5815 } | 5827 } |
| 5816 | 5828 |
| 5817 /*----------------------- Initialisation Scanning ---------------------- */ | 5829 /*----------------------- Initialisation Scanning ---------------------- */ |
| 5818 | 5830 |
| 5831 #ifdef CYGSEM_FS_YAFFS_OMIT_YAFFS2_CODE | |
| 5832 #else | |
| 5819 static void yaffs_HandleShadowedObject(yaffs_Device *dev, int objId, | 5833 static void yaffs_HandleShadowedObject(yaffs_Device *dev, int objId, |
| 5820 int backwardScanning) | 5834 int backwardScanning) |
| 5821 { | 5835 { |
| 5822 yaffs_Object *obj; | 5836 yaffs_Object *obj; |
| 5823 | 5837 |
| 5847 yaffs_AddObjectToDirectory(dev->unlinkedDir, obj); | 5861 yaffs_AddObjectToDirectory(dev->unlinkedDir, obj); |
| 5848 obj->variant.fileVariant.shrinkSize = 0; | 5862 obj->variant.fileVariant.shrinkSize = 0; |
| 5849 obj->valid = 1; /* So that we don't read any other info for this file */ | 5863 obj->valid = 1; /* So that we don't read any other info for this file */ |
| 5850 | 5864 |
| 5851 } | 5865 } |
| 5866 #endif | |
| 5852 | 5867 |
| 5853 typedef struct { | 5868 typedef struct { |
| 5854 int seq; | 5869 int seq; |
| 5855 int block; | 5870 int block; |
| 5856 } yaffs_BlockIndex; | 5871 } yaffs_BlockIndex; |
| 5886 | 5901 |
| 5887 | 5902 |
| 5888 | 5903 |
| 5889 | 5904 |
| 5890 | 5905 |
| 5906 #ifdef CYGSEM_FS_YAFFS_OMIT_YAFFS2_CODE | |
| 5907 #else | |
| 5891 static int ybicmp(const void *a, const void *b) | 5908 static int ybicmp(const void *a, const void *b) |
| 5892 { | 5909 { |
| 5893 register int aseq = ((yaffs_BlockIndex *)a)->seq; | 5910 register int aseq = ((yaffs_BlockIndex *)a)->seq; |
| 5894 register int bseq = ((yaffs_BlockIndex *)b)->seq; | 5911 register int bseq = ((yaffs_BlockIndex *)b)->seq; |
| 5895 register int ablock = ((yaffs_BlockIndex *)a)->block; | 5912 register int ablock = ((yaffs_BlockIndex *)a)->block; |
| 5897 if (aseq == bseq) | 5914 if (aseq == bseq) |
| 5898 return ablock - bblock; | 5915 return ablock - bblock; |
| 5899 else | 5916 else |
| 5900 return aseq - bseq; | 5917 return aseq - bseq; |
| 5901 } | 5918 } |
| 5902 | 5919 #endif |
| 5903 | 5920 |
| 5904 struct yaffs_ShadowFixerStruct { | 5921 struct yaffs_ShadowFixerStruct { |
| 5905 int objectId; | 5922 int objectId; |
| 5906 int shadowedId; | 5923 int shadowedId; |
| 5907 struct yaffs_ShadowFixerStruct *next; | 5924 struct yaffs_ShadowFixerStruct *next; |
| 6053 static void yaffs_EmptyLostAndFound(yaffs_Device *dev) | 6070 static void yaffs_EmptyLostAndFound(yaffs_Device *dev) |
| 6054 { | 6071 { |
| 6055 yaffs_DeleteDirectoryContents(dev->lostNFoundDir); | 6072 yaffs_DeleteDirectoryContents(dev->lostNFoundDir); |
| 6056 } | 6073 } |
| 6057 | 6074 |
| 6075 | |
| 6058 static int yaffs_Scan(yaffs_Device *dev) | 6076 static int yaffs_Scan(yaffs_Device *dev) |
| 6059 { | 6077 { |
| 6078 #ifdef CONFIG_YAFFS_NO_YAFFS1 | |
| 6079 return YAFFS_FAIL; | |
| 6080 #else | |
| 6060 yaffs_ExtendedTags tags; | 6081 yaffs_ExtendedTags tags; |
| 6061 int blk; | 6082 int blk; |
| 6062 int blockIterator; | 6083 int blockIterator; |
| 6063 int startIterator; | 6084 int startIterator; |
| 6064 int endIterator; | 6085 int endIterator; |
| 6484 } | 6505 } |
| 6485 } | 6506 } |
| 6486 | 6507 |
| 6487 yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__); | 6508 yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__); |
| 6488 | 6509 |
| 6489 if (alloc_failed) | 6510 if (alloc_failed) { |
| 6511 T(YAFFS_TRACE_ERROR, (TSTR("malloc failed in yaffs_ScanBackwards" TENDSTR))); | |
| 6490 return YAFFS_FAIL; | 6512 return YAFFS_FAIL; |
| 6513 } | |
| 6491 | 6514 |
| 6492 T(YAFFS_TRACE_SCAN, (TSTR("yaffs_Scan ends" TENDSTR))); | 6515 T(YAFFS_TRACE_SCAN, (TSTR("yaffs_Scan ends" TENDSTR))); |
| 6493 | 6516 |
| 6494 | 6517 |
| 6495 return YAFFS_OK; | 6518 return YAFFS_OK; |
| 6496 } | 6519 #endif //CONFIG_YAFFS_NO_YAFFS1 |
| 6520 } | |
| 6521 | |
| 6497 | 6522 |
| 6498 static void yaffs_CheckObjectDetailsLoaded(yaffs_Object *in) | 6523 static void yaffs_CheckObjectDetailsLoaded(yaffs_Object *in) |
| 6499 { | 6524 { |
| 6500 __u8 *chunkData; | 6525 __u8 *chunkData; |
| 6501 yaffs_ObjectHeader *oh; | 6526 yaffs_ObjectHeader *oh; |
| 6550 | 6575 |
| 6551 yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__); | 6576 yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__); |
| 6552 } | 6577 } |
| 6553 } | 6578 } |
| 6554 | 6579 |
| 6580 #ifdef CYGSEM_FS_YAFFS_OMIT_YAFFS2_CODE | |
| 6581 #else | |
| 6555 static int yaffs_ScanBackwards(yaffs_Device *dev) | 6582 static int yaffs_ScanBackwards(yaffs_Device *dev) |
| 6556 { | 6583 { |
| 6557 yaffs_ExtendedTags tags; | 6584 yaffs_ExtendedTags tags; |
| 6558 int blk; | 6585 int blk; |
| 6559 int blockIterator; | 6586 int blockIterator; |
| 7197 | 7224 |
| 7198 T(YAFFS_TRACE_SCAN, (TSTR("yaffs_ScanBackwards ends" TENDSTR))); | 7225 T(YAFFS_TRACE_SCAN, (TSTR("yaffs_ScanBackwards ends" TENDSTR))); |
| 7199 | 7226 |
| 7200 return YAFFS_OK; | 7227 return YAFFS_OK; |
| 7201 } | 7228 } |
| 7229 #endif // !CYGSEM_FS_YAFFS_OMIT_YAFFS2_CODE | |
| 7202 | 7230 |
| 7203 /*------------------------------ Directory Functions ----------------------------- */ | 7231 /*------------------------------ Directory Functions ----------------------------- */ |
| 7204 | 7232 |
| 7205 static void yaffs_VerifyObjectInDirectory(yaffs_Object *obj) | 7233 static void yaffs_VerifyObjectInDirectory(yaffs_Object *obj) |
| 7206 { | 7234 { |
| 8011 | 8039 |
| 8012 | 8040 |
| 8013 if (!init_failed) { | 8041 if (!init_failed) { |
| 8014 /* Now scan the flash. */ | 8042 /* Now scan the flash. */ |
| 8015 if (dev->param.isYaffs2) { | 8043 if (dev->param.isYaffs2) { |
| 8044 #ifdef CYGSEM_FS_YAFFS_OMIT_YAFFS2_CODE | |
| 8045 init_failed = 1; | |
| 8046 #else | |
| 8016 if (yaffs_CheckpointRestore(dev)) { | 8047 if (yaffs_CheckpointRestore(dev)) { |
| 8017 yaffs_CheckObjectDetailsLoaded(dev->rootDir); | 8048 yaffs_CheckObjectDetailsLoaded(dev->rootDir); |
| 8018 T(YAFFS_TRACE_ALWAYS, | 8049 T(YAFFS_TRACE_ALWAYS, |
| 8019 (TSTR("yaffs: restored from checkpoint" TENDSTR))); | 8050 (TSTR("yaffs: restored from checkpoint" TENDSTR))); |
| 8020 } else { | 8051 } else { |
| 8045 init_failed = 1; | 8076 init_failed = 1; |
| 8046 | 8077 |
| 8047 if (!init_failed && !yaffs_ScanBackwards(dev)) | 8078 if (!init_failed && !yaffs_ScanBackwards(dev)) |
| 8048 init_failed = 1; | 8079 init_failed = 1; |
| 8049 } | 8080 } |
| 8050 } else if (!yaffs_Scan(dev)) | 8081 #endif // !CYGSEM_FS_YAFFS_OMIT_YAFFS2_CODE |
| 8051 init_failed = 1; | 8082 } else if (!yaffs_Scan(dev)) |
| 8083 init_failed = 1; | |
| 8052 | 8084 |
| 8053 yaffs_StripDeletedObjects(dev); | 8085 yaffs_StripDeletedObjects(dev); |
| 8054 yaffs_FixHangingObjects(dev); | 8086 yaffs_FixHangingObjects(dev); |
| 8055 if(dev->param.emptyLostAndFound) | 8087 if(dev->param.emptyLostAndFound) |
| 8056 yaffs_EmptyLostAndFound(dev); | 8088 yaffs_EmptyLostAndFound(dev); |
