From 3e5718ec7f0df7b76837d10583419b745cb27474 Mon Sep 17 00:00:00 2001 From: wookey Date: Fri, 6 Mar 2009 17:20:49 +0000 Subject: [PATCH] Major whitespace/style changes to match Linux checkpatch.pl code style --- devextras.h | 82 +- moduleconfig.h | 6 +- yaffs_checkptrw.c | 195 ++- yaffs_checkptrw.h | 4 +- yaffs_ecc.c | 25 +- yaffs_ecc.h | 26 +- yaffs_fs.c | 866 ++++++------ yaffs_getblockinfo.h | 2 +- yaffs_guts.c | 3184 ++++++++++++++++++++---------------------- yaffs_guts.h | 320 +++-- yaffs_mtdif.c | 30 +- yaffs_mtdif.h | 14 +- yaffs_mtdif1.c | 35 +- yaffs_mtdif1.h | 10 +- yaffs_mtdif2.c | 78 +- yaffs_mtdif2.h | 12 +- yaffs_nand.c | 28 +- yaffs_nand.h | 24 +- yaffs_nandemul2k.h | 10 +- yaffs_packedtags1.c | 5 +- yaffs_packedtags1.h | 4 +- yaffs_packedtags2.c | 48 +- yaffs_packedtags2.h | 8 +- yaffs_qsort.c | 43 +- yaffs_qsort.h | 4 +- yaffs_tagscompat.c | 109 +- yaffs_tagscompat.h | 24 +- yaffs_tagsvalidity.c | 4 +- yaffs_tagsvalidity.h | 4 +- yportenv.h | 52 +- 30 files changed, 2547 insertions(+), 2709 deletions(-) diff --git a/devextras.h b/devextras.h index a9366fd..35c3446 100644 --- a/devextras.h +++ b/devextras.h @@ -1,5 +1,5 @@ /* - * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. * * Copyright (C) 2002-2007 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering @@ -24,7 +24,7 @@ #define __EXTRAS_H__ -#if !(defined __KERNEL__) +#if !(defined __KERNEL__) /* Definition of types */ typedef unsigned char __u8; @@ -34,7 +34,7 @@ typedef unsigned __u32; #endif /* - * This is a simple doubly linked list implementation that matches the + * This is a simple doubly linked list implementation that matches the * way the Linux kernel doubly linked list implementation works. */ @@ -46,7 +46,7 @@ struct ylist_head { /* Initialise a static list */ #define YLIST_HEAD(name) \ -struct ylist_head name = { &(name),&(name)} +struct ylist_head name = { &(name), &(name)} @@ -55,32 +55,32 @@ struct ylist_head name = { &(name),&(name)} do { \ (p)->next = (p);\ (p)->prev = (p); \ -} while(0) +} while (0) /* Add an element to a list */ -static __inline__ void ylist_add(struct ylist_head *newEntry, - struct ylist_head *list) +static __inline__ void ylist_add(struct ylist_head *newEntry, + struct ylist_head *list) { - struct ylist_head *listNext = list->next; - - list->next = newEntry; - newEntry->prev = list; + struct ylist_head *listNext = list->next; + + list->next = newEntry; + newEntry->prev = list; newEntry->next = listNext; listNext->prev = newEntry; - + } -static __inline__ void ylist_add_tail(struct ylist_head *newEntry, +static __inline__ void ylist_add_tail(struct ylist_head *newEntry, struct ylist_head *list) { struct ylist_head *listPrev = list->prev; - + list->prev = newEntry; newEntry->next = list; newEntry->prev = listPrev; listPrev->next = newEntry; - + } @@ -88,35 +88,35 @@ static __inline__ void ylist_add_tail(struct ylist_head *newEntry, * reinitialising the links.of the entry*/ static __inline__ void ylist_del(struct ylist_head *entry) { - struct ylist_head *listNext = entry->next; - struct ylist_head *listPrev = entry->prev; - - listNext->prev = listPrev; - listPrev->next = listNext; - + struct ylist_head *listNext = entry->next; + struct ylist_head *listPrev = entry->prev; + + listNext->prev = listPrev; + listPrev->next = listNext; + } static __inline__ void ylist_del_init(struct ylist_head *entry) { - ylist_del(entry); - entry->next = entry->prev = entry; + ylist_del(entry); + entry->next = entry->prev = entry; } /* Test if the list is empty */ static __inline__ int ylist_empty(struct ylist_head *entry) { - return (entry->next == entry); + return (entry->next == entry); } /* ylist_entry takes a pointer to a list entry and offsets it to that * we can find a pointer to the object it is embedded in. */ - - + + #define ylist_entry(entry, type, member) \ - ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member))) + ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member))) /* ylist_for_each and list_for_each_safe iterate over lists. @@ -124,11 +124,11 @@ static __inline__ int ylist_empty(struct ylist_head *entry) */ #define ylist_for_each(itervar, list) \ - for (itervar = (list)->next; itervar != (list); itervar = itervar->next ) + for (itervar = (list)->next; itervar != (list); itervar = itervar->next) -#define ylist_for_each_safe(itervar,saveVar, list) \ - for (itervar = (list)->next, saveVar = (list)->next->next; itervar != (list); \ - itervar = saveVar, saveVar = saveVar->next) +#define ylist_for_each_safe(itervar, saveVar, list) \ + for (itervar = (list)->next, saveVar = (list)->next->next; \ + itervar != (list); itervar = saveVar, saveVar = saveVar->next) #if !(defined __KERNEL__) @@ -143,15 +143,15 @@ static __inline__ int ylist_empty(struct ylist_head *entry) /* File types */ -#define DT_UNKNOWN 0 -#define DT_FIFO 1 -#define DT_CHR 2 +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 #define DT_DIR 4 #define DT_BLK 6 -#define DT_REG 8 -#define DT_LNK 10 -#define DT_SOCK 12 -#define DT_WHT 14 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 +#define DT_WHT 14 #ifndef WIN32 @@ -162,8 +162,8 @@ static __inline__ int ylist_empty(struct ylist_head *entry) * Attribute flags. These should be or-ed together to figure out what * has been changed! */ -#define ATTR_MODE 1 -#define ATTR_UID 2 +#define ATTR_MODE 1 +#define ATTR_UID 2 #define ATTR_GID 4 #define ATTR_SIZE 8 #define ATTR_ATIME 16 @@ -179,7 +179,7 @@ struct iattr { unsigned ia_atime; unsigned ia_mtime; unsigned ia_ctime; - unsigned int ia_attr_flags; + unsigned int ia_attr_flags; }; #endif diff --git a/moduleconfig.h b/moduleconfig.h index ac5af6f..a344baf 100644 --- a/moduleconfig.h +++ b/moduleconfig.h @@ -27,12 +27,12 @@ /* Default: Not selected */ /* Meaning: Yaffs does its own ECC, rather than using MTD ECC */ -//#define CONFIG_YAFFS_DOES_ECC +/* #define CONFIG_YAFFS_DOES_ECC */ /* Default: Not selected */ /* Meaning: ECC byte order is 'wrong'. Only meaningful if */ /* CONFIG_YAFFS_DOES_ECC is set */ -//#define CONFIG_YAFFS_ECC_WRONG_ORDER +/* #define CONFIG_YAFFS_ECC_WRONG_ORDER */ /* Default: Selected */ /* Meaning: Disables testing whether chunks are erased before writing to them*/ @@ -58,7 +58,7 @@ MTD versions in yaffs_mtdif1.c. */ /* Default: Not selected */ /* Meaning: Use older-style on-NAND data format with pageStatus byte */ -//#define CONFIG_YAFFS_9BYTE_TAGS +/* #define CONFIG_YAFFS_9BYTE_TAGS */ #endif /* YAFFS_OUT_OF_TREE */ diff --git a/yaffs_checkptrw.c b/yaffs_checkptrw.c index 7ed37a0..40d7923 100644 --- a/yaffs_checkptrw.c +++ b/yaffs_checkptrw.c @@ -12,7 +12,7 @@ */ const char *yaffs_checkptrw_c_version = - "$Id: yaffs_checkptrw.c,v 1.17 2008-08-12 22:51:57 charles Exp $"; + "$Id: yaffs_checkptrw.c,v 1.18 2009-03-06 17:20:49 wookey Exp $"; #include "yaffs_checkptrw.h" @@ -20,40 +20,35 @@ const char *yaffs_checkptrw_c_version = static int yaffs_CheckpointSpaceOk(yaffs_Device *dev) { - int blocksAvailable = dev->nErasedBlocks - dev->nReservedBlocks; T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpt blocks available = %d" TENDSTR), blocksAvailable)); - return (blocksAvailable <= 0) ? 0 : 1; } static int yaffs_CheckpointErase(yaffs_Device *dev) { - int i; - - if(!dev->eraseBlockInNAND) + if (!dev->eraseBlockInNAND) return 0; - T(YAFFS_TRACE_CHECKPOINT,(TSTR("checking blocks %d to %d"TENDSTR), - dev->internalStartBlock,dev->internalEndBlock)); - - for(i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) { - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,i); - if(bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("erasing checkpt block %d"TENDSTR),i)); - if(dev->eraseBlockInNAND(dev,i- dev->blockOffset /* realign */)){ + T(YAFFS_TRACE_CHECKPOINT, (TSTR("checking blocks %d to %d"TENDSTR), + dev->internalStartBlock, dev->internalEndBlock)); + + for (i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) { + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i); + if (bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("erasing checkpt block %d"TENDSTR), i)); + if (dev->eraseBlockInNAND(dev, i - dev->blockOffset /* realign */)) { bi->blockState = YAFFS_BLOCK_STATE_EMPTY; dev->nErasedBlocks++; dev->nFreeChunks += dev->nChunksPerBlock; - } - else { - dev->markNANDBlockBad(dev,i); + } else { + dev->markNANDBlockBad(dev, i); bi->blockState = YAFFS_BLOCK_STATE_DEAD; } } @@ -71,23 +66,23 @@ static void yaffs_CheckpointFindNextErasedBlock(yaffs_Device *dev) int blocksAvailable = dev->nErasedBlocks - dev->nReservedBlocks; T(YAFFS_TRACE_CHECKPOINT, (TSTR("allocating checkpt block: erased %d reserved %d avail %d next %d "TENDSTR), - dev->nErasedBlocks,dev->nReservedBlocks,blocksAvailable,dev->checkpointNextBlock)); + dev->nErasedBlocks, dev->nReservedBlocks, blocksAvailable, dev->checkpointNextBlock)); - if(dev->checkpointNextBlock >= 0 && - dev->checkpointNextBlock <= dev->internalEndBlock && - blocksAvailable > 0){ + if (dev->checkpointNextBlock >= 0 && + dev->checkpointNextBlock <= dev->internalEndBlock && + blocksAvailable > 0) { - for(i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++){ - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,i); - if(bi->blockState == YAFFS_BLOCK_STATE_EMPTY){ + for (i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++) { + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i); + if (bi->blockState == YAFFS_BLOCK_STATE_EMPTY) { dev->checkpointNextBlock = i + 1; dev->checkpointCurrentBlock = i; - T(YAFFS_TRACE_CHECKPOINT,(TSTR("allocating checkpt block %d"TENDSTR),i)); + T(YAFFS_TRACE_CHECKPOINT, (TSTR("allocating checkpt block %d"TENDSTR), i)); return; } } } - T(YAFFS_TRACE_CHECKPOINT,(TSTR("out of checkpt blocks"TENDSTR))); + T(YAFFS_TRACE_CHECKPOINT, (TSTR("out of checkpt blocks"TENDSTR))); dev->checkpointNextBlock = -1; dev->checkpointCurrentBlock = -1; @@ -98,30 +93,31 @@ static void yaffs_CheckpointFindNextCheckpointBlock(yaffs_Device *dev) int i; yaffs_ExtendedTags tags; - T(YAFFS_TRACE_CHECKPOINT,(TSTR("find next checkpt block: start: blocks %d next %d" TENDSTR), + T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: start: blocks %d next %d" TENDSTR), dev->blocksInCheckpoint, dev->checkpointNextBlock)); - if(dev->blocksInCheckpoint < dev->checkpointMaxBlocks) - for(i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++){ + if (dev->blocksInCheckpoint < dev->checkpointMaxBlocks) + for (i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++) { int chunk = i * dev->nChunksPerBlock; int realignedChunk = chunk - dev->chunkOffset; - dev->readChunkWithTagsFromNAND(dev,realignedChunk,NULL,&tags); - T(YAFFS_TRACE_CHECKPOINT,(TSTR("find next checkpt block: search: block %d oid %d seq %d eccr %d" TENDSTR), - i, tags.objectId,tags.sequenceNumber,tags.eccResult)); + dev->readChunkWithTagsFromNAND(dev, realignedChunk, + NULL, &tags); + T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: search: block %d oid %d seq %d eccr %d" TENDSTR), + i, tags.objectId, tags.sequenceNumber, tags.eccResult)); - if(tags.sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA){ + if (tags.sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA) { /* Right kind of block */ dev->checkpointNextBlock = tags.objectId; dev->checkpointCurrentBlock = i; dev->checkpointBlockList[dev->blocksInCheckpoint] = i; dev->blocksInCheckpoint++; - T(YAFFS_TRACE_CHECKPOINT,(TSTR("found checkpt block %d"TENDSTR),i)); + T(YAFFS_TRACE_CHECKPOINT, (TSTR("found checkpt block %d"TENDSTR), i)); return; } } - T(YAFFS_TRACE_CHECKPOINT,(TSTR("found no more checkpt blocks"TENDSTR))); + T(YAFFS_TRACE_CHECKPOINT, (TSTR("found no more checkpt blocks"TENDSTR))); dev->checkpointNextBlock = -1; dev->checkpointCurrentBlock = -1; @@ -133,17 +129,17 @@ int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting) /* Got the functions we need? */ if (!dev->writeChunkWithTagsToNAND || - !dev->readChunkWithTagsFromNAND || - !dev->eraseBlockInNAND || - !dev->markNANDBlockBad) + !dev->readChunkWithTagsFromNAND || + !dev->eraseBlockInNAND || + !dev->markNANDBlockBad) return 0; - if(forWriting && !yaffs_CheckpointSpaceOk(dev)) + if (forWriting && !yaffs_CheckpointSpaceOk(dev)) return 0; - if(!dev->checkpointBuffer) + if (!dev->checkpointBuffer) dev->checkpointBuffer = YMALLOC_DMA(dev->totalBytesPerChunk); - if(!dev->checkpointBuffer) + if (!dev->checkpointBuffer) return 0; @@ -159,12 +155,10 @@ int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting) dev->checkpointNextBlock = dev->internalStartBlock; /* Erase all the blocks in the checkpoint area */ - if(forWriting){ - memset(dev->checkpointBuffer,0,dev->nDataBytesPerChunk); + if (forWriting) { + memset(dev->checkpointBuffer, 0, dev->nDataBytesPerChunk); dev->checkpointByteOffset = 0; return yaffs_CheckpointErase(dev); - - } else { int i; /* Set to a value that will kick off a read */ @@ -174,7 +168,7 @@ int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting) dev->blocksInCheckpoint = 0; dev->checkpointMaxBlocks = (dev->internalEndBlock - dev->internalStartBlock)/16 + 2; dev->checkpointBlockList = YMALLOC(sizeof(int) * dev->checkpointMaxBlocks); - for(i = 0; i < dev->checkpointMaxBlocks; i++) + for (i = 0; i < dev->checkpointMaxBlocks; i++) dev->checkpointBlockList[i] = -1; } @@ -191,18 +185,17 @@ int yaffs_GetCheckpointSum(yaffs_Device *dev, __u32 *sum) static int yaffs_CheckpointFlushBuffer(yaffs_Device *dev) { - int chunk; int realignedChunk; yaffs_ExtendedTags tags; - if(dev->checkpointCurrentBlock < 0){ + if (dev->checkpointCurrentBlock < 0) { yaffs_CheckpointFindNextErasedBlock(dev); dev->checkpointCurrentChunk = 0; } - if(dev->checkpointCurrentBlock < 0) + if (dev->checkpointCurrentBlock < 0) return 0; tags.chunkDeleted = 0; @@ -210,10 +203,10 @@ static int yaffs_CheckpointFlushBuffer(yaffs_Device *dev) tags.chunkId = dev->checkpointPageSequence + 1; tags.sequenceNumber = YAFFS_SEQUENCE_CHECKPOINT_DATA; tags.byteCount = dev->nDataBytesPerChunk; - if(dev->checkpointCurrentChunk == 0){ + if (dev->checkpointCurrentChunk == 0) { /* First chunk we write for the block? Set block state to checkpoint */ - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,dev->checkpointCurrentBlock); + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, dev->checkpointCurrentBlock); bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT; dev->blocksInCheckpoint++; } @@ -221,28 +214,29 @@ static int yaffs_CheckpointFlushBuffer(yaffs_Device *dev) chunk = dev->checkpointCurrentBlock * dev->nChunksPerBlock + dev->checkpointCurrentChunk; - T(YAFFS_TRACE_CHECKPOINT,(TSTR("checkpoint wite buffer nand %d(%d:%d) objid %d chId %d" TENDSTR), - chunk, dev->checkpointCurrentBlock, dev->checkpointCurrentChunk,tags.objectId,tags.chunkId)); + T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint wite buffer nand %d(%d:%d) objid %d chId %d" TENDSTR), + chunk, dev->checkpointCurrentBlock, dev->checkpointCurrentChunk, tags.objectId, tags.chunkId)); realignedChunk = chunk - dev->chunkOffset; - dev->writeChunkWithTagsToNAND(dev,realignedChunk,dev->checkpointBuffer,&tags); + dev->writeChunkWithTagsToNAND(dev, realignedChunk, + dev->checkpointBuffer, &tags); dev->checkpointByteOffset = 0; dev->checkpointPageSequence++; dev->checkpointCurrentChunk++; - if(dev->checkpointCurrentChunk >= dev->nChunksPerBlock){ + if (dev->checkpointCurrentChunk >= dev->nChunksPerBlock) { dev->checkpointCurrentChunk = 0; dev->checkpointCurrentBlock = -1; } - memset(dev->checkpointBuffer,0,dev->nDataBytesPerChunk); + memset(dev->checkpointBuffer, 0, dev->nDataBytesPerChunk); return 1; } -int yaffs_CheckpointWrite(yaffs_Device *dev,const void *data, int nBytes) +int yaffs_CheckpointWrite(yaffs_Device *dev, const void *data, int nBytes) { - int i=0; + int i = 0; int ok = 1; @@ -250,17 +244,14 @@ int yaffs_CheckpointWrite(yaffs_Device *dev,const void *data, int nBytes) - if(!dev->checkpointBuffer) + if (!dev->checkpointBuffer) return 0; - if(!dev->checkpointOpenForWrite) + if (!dev->checkpointOpenForWrite) return -1; - while(i < nBytes && ok) { - - - - dev->checkpointBuffer[dev->checkpointByteOffset] = *dataBytes ; + while (i < nBytes && ok) { + dev->checkpointBuffer[dev->checkpointByteOffset] = *dataBytes; dev->checkpointSum += *dataBytes; dev->checkpointXor ^= *dataBytes; @@ -270,18 +261,17 @@ int yaffs_CheckpointWrite(yaffs_Device *dev,const void *data, int nBytes) dev->checkpointByteCount++; - if(dev->checkpointByteOffset < 0 || + if (dev->checkpointByteOffset < 0 || dev->checkpointByteOffset >= dev->nDataBytesPerChunk) ok = yaffs_CheckpointFlushBuffer(dev); - } - return i; + return i; } int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes) { - int i=0; + int i = 0; int ok = 1; yaffs_ExtendedTags tags; @@ -291,53 +281,54 @@ int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes) __u8 *dataBytes = (__u8 *)data; - if(!dev->checkpointBuffer) + if (!dev->checkpointBuffer) return 0; - if(dev->checkpointOpenForWrite) + if (dev->checkpointOpenForWrite) return -1; - while(i < nBytes && ok) { + while (i < nBytes && ok) { - if(dev->checkpointByteOffset < 0 || - dev->checkpointByteOffset >= dev->nDataBytesPerChunk) { + if (dev->checkpointByteOffset < 0 || + dev->checkpointByteOffset >= dev->nDataBytesPerChunk) { - if(dev->checkpointCurrentBlock < 0){ + if (dev->checkpointCurrentBlock < 0) { yaffs_CheckpointFindNextCheckpointBlock(dev); dev->checkpointCurrentChunk = 0; } - if(dev->checkpointCurrentBlock < 0) + if (dev->checkpointCurrentBlock < 0) ok = 0; else { - - chunk = dev->checkpointCurrentBlock * dev->nChunksPerBlock + - dev->checkpointCurrentChunk; + chunk = dev->checkpointCurrentBlock * + dev->nChunksPerBlock + + dev->checkpointCurrentChunk; realignedChunk = chunk - dev->chunkOffset; - /* read in the next chunk */ - /* printf("read checkpoint page %d\n",dev->checkpointPage); */ - dev->readChunkWithTagsFromNAND(dev, realignedChunk, - dev->checkpointBuffer, - &tags); + /* read in the next chunk */ + /* printf("read checkpoint page %d\n",dev->checkpointPage); */ + dev->readChunkWithTagsFromNAND(dev, + realignedChunk, + dev->checkpointBuffer, + &tags); - if(tags.chunkId != (dev->checkpointPageSequence + 1) || - tags.eccResult > YAFFS_ECC_RESULT_FIXED || - tags.sequenceNumber != YAFFS_SEQUENCE_CHECKPOINT_DATA) - ok = 0; + if (tags.chunkId != (dev->checkpointPageSequence + 1) || + tags.eccResult > YAFFS_ECC_RESULT_FIXED || + tags.sequenceNumber != YAFFS_SEQUENCE_CHECKPOINT_DATA) + ok = 0; dev->checkpointByteOffset = 0; dev->checkpointPageSequence++; dev->checkpointCurrentChunk++; - if(dev->checkpointCurrentChunk >= dev->nChunksPerBlock) + if (dev->checkpointCurrentChunk >= dev->nChunksPerBlock) dev->checkpointCurrentBlock = -1; } } - if(ok){ + if (ok) { *dataBytes = dev->checkpointBuffer[dev->checkpointByteOffset]; dev->checkpointSum += *dataBytes; dev->checkpointXor ^= *dataBytes; @@ -354,17 +345,17 @@ int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes) int yaffs_CheckpointClose(yaffs_Device *dev) { - if(dev->checkpointOpenForWrite){ - if(dev->checkpointByteOffset != 0) + if (dev->checkpointOpenForWrite) { + if (dev->checkpointByteOffset != 0) yaffs_CheckpointFlushBuffer(dev); } else { int i; - for(i = 0; i < dev->blocksInCheckpoint && dev->checkpointBlockList[i] >= 0; i++){ - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,dev->checkpointBlockList[i]); - if(bi->blockState == YAFFS_BLOCK_STATE_EMPTY) + for (i = 0; i < dev->blocksInCheckpoint && dev->checkpointBlockList[i] >= 0; i++) { + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, dev->checkpointBlockList[i]); + if (bi->blockState == YAFFS_BLOCK_STATE_EMPTY) bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT; else { - // Todo this looks odd... + /* Todo this looks odd... */ } } YFREE(dev->checkpointBlockList); @@ -375,27 +366,25 @@ int yaffs_CheckpointClose(yaffs_Device *dev) dev->nErasedBlocks -= dev->blocksInCheckpoint; - T(YAFFS_TRACE_CHECKPOINT,(TSTR("checkpoint byte count %d" TENDSTR), + T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint byte count %d" TENDSTR), dev->checkpointByteCount)); - if(dev->checkpointBuffer){ + if (dev->checkpointBuffer) { /* free the buffer */ YFREE(dev->checkpointBuffer); dev->checkpointBuffer = NULL; return 1; - } - else + } else return 0; - } int yaffs_CheckpointInvalidateStream(yaffs_Device *dev) { /* Erase the first checksum block */ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("checkpoint invalidate"TENDSTR))); + T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint invalidate"TENDSTR))); - if(!yaffs_CheckpointSpaceOk(dev)) + if (!yaffs_CheckpointSpaceOk(dev)) return 0; return yaffs_CheckpointErase(dev); diff --git a/yaffs_checkptrw.h b/yaffs_checkptrw.h index d3ff174..5d426ea 100644 --- a/yaffs_checkptrw.h +++ b/yaffs_checkptrw.h @@ -20,9 +20,9 @@ int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting); -int yaffs_CheckpointWrite(yaffs_Device *dev,const void *data, int nBytes); +int yaffs_CheckpointWrite(yaffs_Device *dev, const void *data, int nBytes); -int yaffs_CheckpointRead(yaffs_Device *dev,void *data, int nBytes); +int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes); int yaffs_GetCheckpointSum(yaffs_Device *dev, __u32 *sum); diff --git a/yaffs_ecc.c b/yaffs_ecc.c index 9f5973a..d037e90 100644 --- a/yaffs_ecc.c +++ b/yaffs_ecc.c @@ -29,7 +29,7 @@ */ const char *yaffs_ecc_c_version = - "$Id: yaffs_ecc.c,v 1.10 2007-12-13 15:35:17 wookey Exp $"; + "$Id: yaffs_ecc.c,v 1.11 2009-03-06 17:20:50 wookey Exp $"; #include "yportenv.h" @@ -109,12 +109,10 @@ void yaffs_ECCCalculate(const unsigned char *data, unsigned char *ecc) b = column_parity_table[*data++]; col_parity ^= b; - if (b & 0x01) // odd number of bits in the byte - { + if (b & 0x01) { /* odd number of bits in the byte */ line_parity ^= i; line_parity_prime ^= ~i; } - } ecc[2] = (~col_parity) | 0x03; @@ -158,7 +156,7 @@ void yaffs_ECCCalculate(const unsigned char *data, unsigned char *ecc) ecc[0] = ~t; #ifdef CONFIG_YAFFS_ECC_WRONG_ORDER - // Swap the bytes into the wrong order + /* Swap the bytes into the wrong order */ t = ecc[0]; ecc[0] = ecc[1]; ecc[1] = t; @@ -189,7 +187,7 @@ int yaffs_ECCCorrect(unsigned char *data, unsigned char *read_ecc, unsigned bit; #ifdef CONFIG_YAFFS_ECC_WRONG_ORDER - // swap the bytes to correct for the wrong order + /* swap the bytes to correct for the wrong order */ unsigned char t; t = d0; @@ -251,7 +249,7 @@ int yaffs_ECCCorrect(unsigned char *data, unsigned char *read_ecc, * ECCxxxOther does ECC calcs on arbitrary n bytes of data */ void yaffs_ECCCalculateOther(const unsigned char *data, unsigned nBytes, - yaffs_ECCOther * eccOther) + yaffs_ECCOther *eccOther) { unsigned int i; @@ -278,8 +276,8 @@ void yaffs_ECCCalculateOther(const unsigned char *data, unsigned nBytes, } int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes, - yaffs_ECCOther * read_ecc, - const yaffs_ECCOther * test_ecc) + yaffs_ECCOther *read_ecc, + const yaffs_ECCOther *test_ecc) { unsigned char cDelta; /* column parity delta */ unsigned lDelta; /* line parity delta */ @@ -294,8 +292,7 @@ int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes, return 0; /* no error */ if (lDelta == ~lDeltaPrime && - (((cDelta ^ (cDelta >> 1)) & 0x15) == 0x15)) - { + (((cDelta ^ (cDelta >> 1)) & 0x15) == 0x15)) { /* Single bit (recoverable) error in data */ bit = 0; @@ -307,7 +304,7 @@ int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes, if (cDelta & 0x02) bit |= 0x01; - if(lDelta >= nBytes) + if (lDelta >= nBytes) return -1; data[lDelta] ^= (1 << bit); @@ -316,7 +313,7 @@ int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes, } if ((yaffs_CountBits32(lDelta) + yaffs_CountBits32(lDeltaPrime) + - yaffs_CountBits(cDelta)) == 1) { + yaffs_CountBits(cDelta)) == 1) { /* Reccoverable error in ecc */ *read_ecc = *test_ecc; @@ -326,6 +323,4 @@ int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes, /* Unrecoverable error */ return -1; - } - diff --git a/yaffs_ecc.h b/yaffs_ecc.h index 79bc3d1..6076517 100644 --- a/yaffs_ecc.h +++ b/yaffs_ecc.h @@ -13,15 +13,15 @@ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. */ - /* - * This code implements the ECC algorithm used in SmartMedia. - * - * The ECC comprises 22 bits of parity information and is stuffed into 3 bytes. - * The two unused bit are set to 1. - * The ECC can correct single bit errors in a 256-byte page of data. Thus, two such ECC - * blocks are used on a 512-byte NAND page. - * - */ +/* + * This code implements the ECC algorithm used in SmartMedia. + * + * The ECC comprises 22 bits of parity information and is stuffed into 3 bytes. + * The two unused bit are set to 1. + * The ECC can correct single bit errors in a 256-byte page of data. Thus, two such ECC + * blocks are used on a 512-byte NAND page. + * + */ #ifndef __YAFFS_ECC_H__ #define __YAFFS_ECC_H__ @@ -34,11 +34,11 @@ typedef struct { void yaffs_ECCCalculate(const unsigned char *data, unsigned char *ecc); int yaffs_ECCCorrect(unsigned char *data, unsigned char *read_ecc, - const unsigned char *test_ecc); + const unsigned char *test_ecc); void yaffs_ECCCalculateOther(const unsigned char *data, unsigned nBytes, - yaffs_ECCOther * ecc); + yaffs_ECCOther *ecc); int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes, - yaffs_ECCOther * read_ecc, - const yaffs_ECCOther * test_ecc); + yaffs_ECCOther *read_ecc, + const yaffs_ECCOther *test_ecc); #endif diff --git a/yaffs_fs.c b/yaffs_fs.c index 5f0c7b2..376dbdf 100644 --- a/yaffs_fs.c +++ b/yaffs_fs.c @@ -32,11 +32,11 @@ */ const char *yaffs_fs_c_version = - "$Id: yaffs_fs.c,v 1.75 2009-03-05 01:45:28 charles Exp $"; + "$Id: yaffs_fs.c,v 1.76 2009-03-06 17:20:51 wookey Exp $"; extern const char *yaffs_guts_c_version; #include -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)) #include #endif #include @@ -54,7 +54,7 @@ extern const char *yaffs_guts_c_version; #include "asm/div64.h" -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) #include /* Added NCB 15-8-2003 */ #include @@ -70,42 +70,42 @@ extern const char *yaffs_guts_c_version; #define BDEVNAME_SIZE 0 #define yaffs_devname(sb, buf) kdevname(sb->s_dev) -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)) /* added NCB 26/5/2006 for 2.4.25-vrs2-tcl1 kernel */ #define __user #endif #endif -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)) -#define YPROC_ROOT &proc_root +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)) +#define YPROC_ROOT (&proc_root) #else #define YPROC_ROOT NULL #endif -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) #define WRITE_SIZE_STR "writesize" -#define WRITE_SIZE(mtd) (mtd)->writesize +#define WRITE_SIZE(mtd) ((mtd)->writesize) #else #define WRITE_SIZE_STR "oobblock" -#define WRITE_SIZE(mtd) (mtd)->oobblock +#define WRITE_SIZE(mtd) ((mtd)->oobblock) #endif -#if(LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 27)) #define YAFFS_USE_WRITE_BEGIN_END 1 #else #define YAFFS_USE_WRITE_BEGIN_END 0 #endif -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,28)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 28)) static uint32_t YCALCBLOCKS(uint64_t partition_size, uint32_t block_size) { uint64_t result = partition_size; - do_div(result,block_size); + do_div(result, block_size); return (uint32_t)result; } #else -#define YCALCBLOCKS(s,b) ((s)/(b)) +#define YCALCBLOCKS(s, b) ((s)/(b)) #endif #include @@ -123,41 +123,41 @@ unsigned int yaffs_wr_attempts = YAFFS_WR_ATTEMPTS; unsigned int yaffs_auto_checkpoint = 1; /* Module Parameters */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) -module_param(yaffs_traceMask,uint,0644); -module_param(yaffs_wr_attempts,uint,0644); -module_param(yaffs_auto_checkpoint,uint,0644); +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) +module_param(yaffs_traceMask, uint, 0644); +module_param(yaffs_wr_attempts, uint, 0644); +module_param(yaffs_auto_checkpoint, uint, 0644); #else -MODULE_PARM(yaffs_traceMask,"i"); -MODULE_PARM(yaffs_wr_attempts,"i"); -MODULE_PARM(yaffs_auto_checkpoint,"i"); +MODULE_PARM(yaffs_traceMask, "i"); +MODULE_PARM(yaffs_wr_attempts, "i"); +MODULE_PARM(yaffs_auto_checkpoint, "i"); #endif -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)) /* use iget and read_inode */ -#define Y_IGET(sb,inum) iget((sb),(inum)) +#define Y_IGET(sb, inum) iget((sb), (inum)) static void yaffs_read_inode(struct inode *inode); #else /* Call local equivalent */ #define YAFFS_USE_OWN_IGET -#define Y_IGET(sb,inum) yaffs_iget((sb),(inum)) +#define Y_IGET(sb, inum) yaffs_iget((sb), (inum)) -static struct inode * yaffs_iget(struct super_block *sb, unsigned long ino); +static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino); #endif /*#define T(x) printk x */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)) -#define yaffs_InodeToObjectLV(iptr) (iptr)->i_private +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)) +#define yaffs_InodeToObjectLV(iptr) ((iptr)->i_private) #else -#define yaffs_InodeToObjectLV(iptr) (iptr)->u.generic_ip +#define yaffs_InodeToObjectLV(iptr) ((iptr)->u.generic_ip) #endif #define yaffs_InodeToObject(iptr) ((yaffs_Object *)(yaffs_InodeToObjectLV(iptr))) #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode) -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info) #else #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp) @@ -166,49 +166,49 @@ static struct inode * yaffs_iget(struct super_block *sb, unsigned long ino); static void yaffs_put_super(struct super_block *sb); static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, - loff_t * pos); + loff_t *pos); static ssize_t yaffs_hold_space(struct file *f); static void yaffs_release_space(struct file *f); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) static int yaffs_file_flush(struct file *file, fl_owner_t id); #else static int yaffs_file_flush(struct file *file); #endif static int yaffs_sync_object(struct file *file, struct dentry *dentry, - int datasync); + int datasync); static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n); static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry, - struct nameidata *n); + struct nameidata *n); #else static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode); static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry); #endif static int yaffs_link(struct dentry *old_dentry, struct inode *dir, - struct dentry *dentry); + struct dentry *dentry); static int yaffs_unlink(struct inode *dir, struct dentry *dentry); static int yaffs_symlink(struct inode *dir, struct dentry *dentry, - const char *symname); + const char *symname); static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, - dev_t dev); + dev_t dev); #else static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, - int dev); + int dev); #endif static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry); static int yaffs_setattr(struct dentry *dentry, struct iattr *attr); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) static int yaffs_sync_fs(struct super_block *sb, int wait); static void yaffs_write_super(struct super_block *sb); #else @@ -216,9 +216,9 @@ static int yaffs_sync_fs(struct super_block *sb); static int yaffs_write_super(struct super_block *sb); #endif -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf); -#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf); #else static int yaffs_statfs(struct super_block *sb, struct statfs *buf); @@ -232,7 +232,7 @@ static void yaffs_delete_inode(struct inode *); static void yaffs_clear_inode(struct inode *); static int yaffs_readpage(struct file *file, struct page *page); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs_writepage(struct page *page, struct writeback_control *wbc); #else static int yaffs_writepage(struct page *page); @@ -241,22 +241,22 @@ static int yaffs_writepage(struct page *page); #if (YAFFS_USE_WRITE_BEGIN_END != 0) static int yaffs_write_begin(struct file *filp, struct address_space *mapping, - loff_t pos, unsigned len, unsigned flags, - struct page **pagep, void **fsdata); + loff_t pos, unsigned len, unsigned flags, + struct page **pagep, void **fsdata); static int yaffs_write_end(struct file *filp, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, - struct page *pg, void *fsdadata); + loff_t pos, unsigned len, unsigned copied, + struct page *pg, void *fsdadata); #else static int yaffs_prepare_write(struct file *f, struct page *pg, - unsigned offset, unsigned to); + unsigned offset, unsigned to); static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, - unsigned to); - + unsigned to); + #endif -static int yaffs_readlink(struct dentry *dentry, char __user * buffer, - int buflen); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)) +static int yaffs_readlink(struct dentry *dentry, char __user *buffer, + int buflen); +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13)) static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd); #else static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd); @@ -274,7 +274,7 @@ static struct address_space_operations yaffs_file_address_operations = { #endif }; -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22)) static struct file_operations yaffs_file_operations = { .read = do_sync_read, .write = do_sync_write, @@ -288,7 +288,7 @@ static struct file_operations yaffs_file_operations = { .llseek = generic_file_llseek, }; -#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)) +#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)) static struct file_operations yaffs_file_operations = { .read = do_sync_read, @@ -309,7 +309,7 @@ static struct file_operations yaffs_file_operations = { .mmap = generic_file_mmap, .flush = yaffs_file_flush, .fsync = yaffs_sync_object, -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) .sendfile = generic_file_sendfile, #endif }; @@ -360,24 +360,21 @@ static struct super_operations yaffs_super_ops = { .write_super = yaffs_write_super, }; -static void yaffs_GrossLock(yaffs_Device * dev) +static void yaffs_GrossLock(yaffs_Device *dev) { - T(YAFFS_TRACE_OS, ( "yaffs locking %p\n",current)); - + T(YAFFS_TRACE_OS, ("yaffs locking %p\n", current)); down(&dev->grossLock); - T(YAFFS_TRACE_OS, ( "yaffs locked %p\n",current)); - + T(YAFFS_TRACE_OS, ("yaffs locked %p\n", current)); } -static void yaffs_GrossUnlock(yaffs_Device * dev) +static void yaffs_GrossUnlock(yaffs_Device *dev) { - T(YAFFS_TRACE_OS, ( "yaffs unlocking %p\n",current)); + T(YAFFS_TRACE_OS, ("yaffs unlocking %p\n", current)); up(&dev->grossLock); - } -static int yaffs_readlink(struct dentry *dentry, char __user * buffer, - int buflen) +static int yaffs_readlink(struct dentry *dentry, char __user *buffer, + int buflen) { unsigned char *alias; int ret; @@ -398,7 +395,7 @@ static int yaffs_readlink(struct dentry *dentry, char __user * buffer, return ret; } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13)) static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd) #else static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd) @@ -414,16 +411,15 @@ static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd) yaffs_GrossUnlock(dev); - if (!alias) - { + if (!alias) { ret = -ENOMEM; goto out; - } + } ret = vfs_follow_link(nd, alias); kfree(alias); out: -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13)) return ERR_PTR (ret); #else return ret; @@ -431,15 +427,15 @@ out: } struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev, - yaffs_Object * obj); + yaffs_Object *obj); /* * Lookup is used to find objects in the fs */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry, - struct nameidata *n) + struct nameidata *n) #else static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry) #endif @@ -452,12 +448,11 @@ static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry) yaffs_GrossLock(dev); T(YAFFS_TRACE_OS, - ( "yaffs_lookup for %d:%s\n", - yaffs_InodeToObject(dir)->objectId, dentry->d_name.name)); + ("yaffs_lookup for %d:%s\n", + yaffs_InodeToObject(dir)->objectId, dentry->d_name.name)); - obj = - yaffs_FindObjectByName(yaffs_InodeToObject(dir), - dentry->d_name.name); + obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir), + dentry->d_name.name); obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */ @@ -466,13 +461,13 @@ static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry) if (obj) { T(YAFFS_TRACE_OS, - ( "yaffs_lookup found %d\n", obj->objectId)); + ("yaffs_lookup found %d\n", obj->objectId)); inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj); if (inode) { T(YAFFS_TRACE_OS, - ( "yaffs_loookup dentry \n")); + ("yaffs_loookup dentry \n")); /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to * d_add even if NULL inode */ #if 0 @@ -485,7 +480,7 @@ static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry) } } else { - T(YAFFS_TRACE_OS, ( "yaffs_lookup not found\n")); + T(YAFFS_TRACE_OS, ("yaffs_lookup not found\n")); } @@ -507,8 +502,8 @@ static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry) static void yaffs_put_inode(struct inode *inode) { T(YAFFS_TRACE_OS, - ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino, - atomic_read(&inode->i_count))); + ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino, + atomic_read(&inode->i_count))); } #endif @@ -522,9 +517,9 @@ static void yaffs_clear_inode(struct inode *inode) obj = yaffs_InodeToObject(inode); T(YAFFS_TRACE_OS, - ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino, - atomic_read(&inode->i_count), - obj ? "object exists" : "null object")); + ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino, + atomic_read(&inode->i_count), + obj ? "object exists" : "null object")); if (obj) { dev = obj->myDev; @@ -559,9 +554,9 @@ static void yaffs_delete_inode(struct inode *inode) yaffs_Device *dev; T(YAFFS_TRACE_OS, - ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino, - atomic_read(&inode->i_count), - obj ? "object exists" : "null object")); + ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino, + atomic_read(&inode->i_count), + obj ? "object exists" : "null object")); if (obj) { dev = obj->myDev; @@ -569,13 +564,13 @@ static void yaffs_delete_inode(struct inode *inode) yaffs_DeleteObject(obj); yaffs_GrossUnlock(dev); } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)) - truncate_inode_pages (&inode->i_data, 0); +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13)) + truncate_inode_pages (&inode->i_data, 0); #endif clear_inode(inode); } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) static int yaffs_file_flush(struct file *file, fl_owner_t id) #else static int yaffs_file_flush(struct file *file) @@ -586,8 +581,8 @@ static int yaffs_file_flush(struct file *file) yaffs_Device *dev = obj->myDev; T(YAFFS_TRACE_OS, - ( "yaffs_file_flush object %d (%s)\n", obj->objectId, - obj->dirty ? "dirty" : "clean")); + ("yaffs_file_flush object %d (%s)\n", obj->objectId, + obj->dirty ? "dirty" : "clean")); yaffs_GrossLock(dev); @@ -608,15 +603,15 @@ static int yaffs_readpage_nolock(struct file *f, struct page *pg) yaffs_Device *dev; - T(YAFFS_TRACE_OS, ( "yaffs_readpage at %08x, size %08x\n", - (unsigned)(pg->index << PAGE_CACHE_SHIFT), - (unsigned)PAGE_CACHE_SIZE)); + T(YAFFS_TRACE_OS, ("yaffs_readpage at %08x, size %08x\n", + (unsigned)(pg->index << PAGE_CACHE_SHIFT), + (unsigned)PAGE_CACHE_SIZE)); obj = yaffs_DentryToObject(f->f_dentry); dev = obj->myDev; -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) BUG_ON(!PageLocked(pg)); #else if (!PageLocked(pg)) @@ -629,8 +624,9 @@ static int yaffs_readpage_nolock(struct file *f, struct page *pg) yaffs_GrossLock(dev); ret = - yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, - PAGE_CACHE_SIZE); + yaffs_ReadDataFromFile(obj, pg_buf, + pg->index << PAGE_CACHE_SHIFT, + PAGE_CACHE_SIZE); yaffs_GrossUnlock(dev); @@ -648,7 +644,7 @@ static int yaffs_readpage_nolock(struct file *f, struct page *pg) flush_dcache_page(pg); kunmap(pg); - T(YAFFS_TRACE_OS, ( "yaffs_readpage done\n")); + T(YAFFS_TRACE_OS, ("yaffs_readpage done\n")); return ret; } @@ -666,7 +662,7 @@ static int yaffs_readpage(struct file *f, struct page *pg) /* writepage inspired by/stolen from smbfs */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs_writepage(struct page *page, struct writeback_control *wbc) #else static int yaffs_writepage(struct page *page) @@ -689,12 +685,11 @@ static int yaffs_writepage(struct page *page) if (offset > inode->i_size) { T(YAFFS_TRACE_OS, - ( - "yaffs_writepage at %08x, inode size = %08x!!!\n", - (unsigned)(page->index << PAGE_CACHE_SHIFT), - (unsigned)inode->i_size)); + ("yaffs_writepage at %08x, inode size = %08x!!!\n", + (unsigned)(page->index << PAGE_CACHE_SHIFT), + (unsigned)inode->i_size)); T(YAFFS_TRACE_OS, - ( " -> don't care!!\n")); + (" -> don't care!!\n")); unlock_page(page); return 0; } @@ -716,19 +711,18 @@ static int yaffs_writepage(struct page *page) yaffs_GrossLock(obj->myDev); T(YAFFS_TRACE_OS, - ( "yaffs_writepage at %08x, size %08x\n", - (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes)); + ("yaffs_writepage at %08x, size %08x\n", + (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes)); T(YAFFS_TRACE_OS, - ( "writepag0: obj = %05x, ino = %05x\n", - (int)obj->variant.fileVariant.fileSize, (int)inode->i_size)); + ("writepag0: obj = %05x, ino = %05x\n", + (int)obj->variant.fileVariant.fileSize, (int)inode->i_size)); - nWritten = - yaffs_WriteDataToFile(obj, buffer, page->index << PAGE_CACHE_SHIFT, - nBytes, 0); + nWritten = yaffs_WriteDataToFile(obj, buffer, + page->index << PAGE_CACHE_SHIFT, nBytes, 0); T(YAFFS_TRACE_OS, - ( "writepag1: obj = %05x, ino = %05x\n", - (int)obj->variant.fileVariant.fileSize, (int)inode->i_size)); + ("writepag1: obj = %05x, ino = %05x\n", + (int)obj->variant.fileVariant.fileSize, (int)inode->i_size)); yaffs_GrossUnlock(obj->myDev); @@ -743,58 +737,57 @@ static int yaffs_writepage(struct page *page) #if (YAFFS_USE_WRITE_BEGIN_END > 0) static int yaffs_write_begin(struct file *filp, struct address_space *mapping, - loff_t pos, unsigned len, unsigned flags, - struct page **pagep, void **fsdata) - + loff_t pos, unsigned len, unsigned flags, + struct page **pagep, void **fsdata) { struct page *pg = NULL; - pgoff_t index = pos >> PAGE_CACHE_SHIFT; - uint32_t offset = pos & (PAGE_CACHE_SIZE - 1); - uint32_t to = offset + len; - - int ret = 0; - int space_held = 0; - - T(YAFFS_TRACE_OS, ( "start yaffs_write_begin\n")); + pgoff_t index = pos >> PAGE_CACHE_SHIFT; + uint32_t offset = pos & (PAGE_CACHE_SIZE - 1); + uint32_t to = offset + len; + + int ret = 0; + int space_held = 0; + + T(YAFFS_TRACE_OS, ("start yaffs_write_begin\n")); /* Get a page */ -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,28) - pg = grab_cache_page_write_begin(mapping,index,flags); +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 28) + pg = grab_cache_page_write_begin(mapping, index, flags); #else - pg = __grab_cache_page(mapping,index); + pg = __grab_cache_page(mapping, index); #endif - *pagep = pg; - if(!pg){ + *pagep = pg; + if (!pg) { ret = -ENOMEM; goto out; } /* Get fs space */ space_held = yaffs_hold_space(filp); - - if(!space_held){ + + if (!space_held) { ret = -ENOSPC; goto out; } - + /* Update page if required */ - + if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE)) ret = yaffs_readpage_nolock(filp, pg); - - if(ret) + + if (ret) goto out; /* Happy path return */ - T(YAFFS_TRACE_OS, ( "end yaffs_write_begin - ok\n")); - + T(YAFFS_TRACE_OS, ("end yaffs_write_begin - ok\n")); + return 0; - + out: - T(YAFFS_TRACE_OS, ( "end yaffs_write_begin fail returning %d\n",ret)); - if(space_held){ + T(YAFFS_TRACE_OS, ("end yaffs_write_begin fail returning %d\n", ret)); + if (space_held) { yaffs_release_space(filp); } - if(pg) { + if (pg) { unlock_page(pg); page_cache_release(pg); } @@ -804,42 +797,39 @@ out: #else static int yaffs_prepare_write(struct file *f, struct page *pg, - unsigned offset, unsigned to) + unsigned offset, unsigned to) { + T(YAFFS_TRACE_OS, ("yaffs_prepair_write\n")); - T(YAFFS_TRACE_OS, ( "yaffs_prepair_write\n")); if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE)) return yaffs_readpage_nolock(f, pg); return 0; - } #endif #if (YAFFS_USE_WRITE_BEGIN_END > 0) static int yaffs_write_end(struct file *filp, struct address_space *mapping, - loff_t pos, unsigned len, unsigned copied, - struct page *pg, void *fsdadata) + loff_t pos, unsigned len, unsigned copied, + struct page *pg, void *fsdadata) { int ret = 0; void *addr, *kva; - uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE -1); - + uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE - 1); - - kva=kmap(pg); + kva = kmap(pg); addr = kva + offset_into_page; T(YAFFS_TRACE_OS, - ( "yaffs_write_end addr %x pos %x nBytes %d\n", (unsigned) addr, - (int)pos, copied)); + ("yaffs_write_end addr %x pos %x nBytes %d\n", + (unsigned) addr, + (int)pos, copied)); ret = yaffs_file_write(filp, addr, copied, &pos); if (ret != copied) { T(YAFFS_TRACE_OS, - ( - "yaffs_write_end not same size ret %d copied %d\n", - ret, copied )); + ("yaffs_write_end not same size ret %d copied %d\n", + ret, copied)); SetPageError(pg); ClearPageUptodate(pg); } else { @@ -856,34 +846,32 @@ static int yaffs_write_end(struct file *filp, struct address_space *mapping, #else static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, - unsigned to) + unsigned to) { - void *addr, *kva; - + loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset; int nBytes = to - offset; int nWritten; unsigned spos = pos; unsigned saddr; - - kva=kmap(pg); + + kva = kmap(pg); addr = kva + offset; saddr = (unsigned) addr; T(YAFFS_TRACE_OS, - ( "yaffs_commit_write addr %x pos %x nBytes %d\n", saddr, - spos, nBytes)); + ("yaffs_commit_write addr %x pos %x nBytes %d\n", + saddr, spos, nBytes)); nWritten = yaffs_file_write(f, addr, nBytes, &pos); if (nWritten != nBytes) { T(YAFFS_TRACE_OS, - ( - "yaffs_commit_write not same size nWritten %d nBytes %d\n", - nWritten, nBytes)); + ("yaffs_commit_write not same size nWritten %d nBytes %d\n", + nWritten, nBytes)); SetPageError(pg); ClearPageUptodate(pg); } else { @@ -893,62 +881,61 @@ static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, kunmap(pg); T(YAFFS_TRACE_OS, - ( "yaffs_commit_write returning %d\n", - nWritten == nBytes ? 0 : nWritten)); + ("yaffs_commit_write returning %d\n", + nWritten == nBytes ? 0 : nWritten)); return nWritten == nBytes ? 0 : nWritten; - } #endif -static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj) +static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj) { if (inode && obj) { /* Check mode against the variant type and attempt to repair if broken. */ - __u32 mode = obj->yst_mode; - switch( obj->variantType ){ - case YAFFS_OBJECT_TYPE_FILE : - if( ! S_ISREG(mode) ){ - obj->yst_mode &= ~S_IFMT; - obj->yst_mode |= S_IFREG; - } - - break; - case YAFFS_OBJECT_TYPE_SYMLINK : - if( ! S_ISLNK(mode) ){ - obj->yst_mode &= ~S_IFMT; - obj->yst_mode |= S_IFLNK; - } - - break; - case YAFFS_OBJECT_TYPE_DIRECTORY : - if( ! S_ISDIR(mode) ){ - obj->yst_mode &= ~S_IFMT; - obj->yst_mode |= S_IFDIR; - } - - break; - case YAFFS_OBJECT_TYPE_UNKNOWN : - case YAFFS_OBJECT_TYPE_HARDLINK : - case YAFFS_OBJECT_TYPE_SPECIAL : - default: - /* TODO? */ - break; - } - - inode->i_flags |= S_NOATIME; - + __u32 mode = obj->yst_mode; + switch (obj->variantType) { + case YAFFS_OBJECT_TYPE_FILE: + if (!S_ISREG(mode)) { + obj->yst_mode &= ~S_IFMT; + obj->yst_mode |= S_IFREG; + } + + break; + case YAFFS_OBJECT_TYPE_SYMLINK: + if (!S_ISLNK(mode)) { + obj->yst_mode &= ~S_IFMT; + obj->yst_mode |= S_IFLNK; + } + + break; + case YAFFS_OBJECT_TYPE_DIRECTORY: + if (!S_ISDIR(mode)) { + obj->yst_mode &= ~S_IFMT; + obj->yst_mode |= S_IFDIR; + } + + break; + case YAFFS_OBJECT_TYPE_UNKNOWN: + case YAFFS_OBJECT_TYPE_HARDLINK: + case YAFFS_OBJECT_TYPE_SPECIAL: + default: + /* TODO? */ + break; + } + + inode->i_flags |= S_NOATIME; + inode->i_ino = obj->objectId; inode->i_mode = obj->yst_mode; inode->i_uid = obj->yst_uid; inode->i_gid = obj->yst_gid; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)) inode->i_blksize = inode->i_sb->s_blocksize; #endif -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) inode->i_rdev = old_decode_dev(obj->yst_rdev); inode->i_atime.tv_sec = (time_t) (obj->yst_atime); @@ -969,26 +956,25 @@ static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj) inode->i_nlink = yaffs_GetObjectLinkCount(obj); T(YAFFS_TRACE_OS, - ( - "yaffs_FillInode mode %x uid %d gid %d size %d count %d\n", - inode->i_mode, inode->i_uid, inode->i_gid, - (int)inode->i_size, atomic_read(&inode->i_count))); + ("yaffs_FillInode mode %x uid %d gid %d size %d count %d\n", + inode->i_mode, inode->i_uid, inode->i_gid, + (int)inode->i_size, atomic_read(&inode->i_count))); switch (obj->yst_mode & S_IFMT) { default: /* fifo, device or socket */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) init_special_inode(inode, obj->yst_mode, - old_decode_dev(obj->yst_rdev)); + old_decode_dev(obj->yst_rdev)); #else init_special_inode(inode, obj->yst_mode, - (dev_t) (obj->yst_rdev)); + (dev_t) (obj->yst_rdev)); #endif break; case S_IFREG: /* file */ inode->i_op = &yaffs_file_inode_operations; inode->i_fop = &yaffs_file_operations; inode->i_mapping->a_ops = - &yaffs_file_address_operations; + &yaffs_file_address_operations; break; case S_IFDIR: /* directory */ inode->i_op = &yaffs_dir_inode_operations; @@ -1005,36 +991,36 @@ static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj) } else { T(YAFFS_TRACE_OS, - ( "yaffs_FileInode invalid parameters\n")); + ("yaffs_FileInode invalid parameters\n")); } } struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev, - yaffs_Object * obj) + yaffs_Object *obj) { struct inode *inode; if (!sb) { T(YAFFS_TRACE_OS, - ( "yaffs_get_inode for NULL super_block!!\n")); + ("yaffs_get_inode for NULL super_block!!\n")); return NULL; } if (!obj) { T(YAFFS_TRACE_OS, - ( "yaffs_get_inode for NULL object!!\n")); + ("yaffs_get_inode for NULL object!!\n")); return NULL; } T(YAFFS_TRACE_OS, - ( "yaffs_get_inode for object %d\n", obj->objectId)); + ("yaffs_get_inode for object %d\n", obj->objectId)); inode = Y_IGET(sb, obj->objectId); - if(IS_ERR(inode)) - return NULL; + if (IS_ERR(inode)) + return NULL; /* NB Side effect: iget calls back to yaffs_read_inode(). */ /* iget also increments the inode's i_count */ @@ -1044,7 +1030,7 @@ struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev, } static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, - loff_t * pos) + loff_t *pos) { yaffs_Object *obj; int nWritten, ipos; @@ -1067,20 +1053,19 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, if (!obj) { T(YAFFS_TRACE_OS, - ( "yaffs_file_write: hey obj is null!\n")); + ("yaffs_file_write: hey obj is null!\n")); } else { T(YAFFS_TRACE_OS, - ( - "yaffs_file_write about to write writing %zu bytes" - "to object %d at %d\n", - n, obj->objectId, ipos)); + ("yaffs_file_write about to write writing %zu bytes" + "to object %d at %d\n", + n, obj->objectId, ipos)); } nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0); T(YAFFS_TRACE_OS, - ( "yaffs_file_write writing %zu bytes, %d written at %d\n", - n, nWritten, ipos)); + ("yaffs_file_write writing %zu bytes, %d written at %d\n", + n, nWritten, ipos)); if (nWritten > 0) { ipos += nWritten; *pos = ipos; @@ -1089,10 +1074,9 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, inode->i_blocks = (ipos + 511) >> 9; T(YAFFS_TRACE_OS, - ( - "yaffs_file_write size updated to %d bytes, " - "%d blocks\n", - ipos, (int)(inode->i_blocks))); + ("yaffs_file_write size updated to %d bytes, " + "%d blocks\n", + ipos, (int)(inode->i_blocks))); } } @@ -1108,10 +1092,10 @@ static ssize_t yaffs_hold_space(struct file *f) { yaffs_Object *obj; yaffs_Device *dev; - + int nFreeChunks; - + obj = yaffs_DentryToObject(f->f_dentry); dev = obj->myDev; @@ -1119,7 +1103,7 @@ static ssize_t yaffs_hold_space(struct file *f) yaffs_GrossLock(dev); nFreeChunks = yaffs_GetNumberOfFreeChunks(dev); - + yaffs_GrossUnlock(dev); return (nFreeChunks > 20) ? 1 : 0; @@ -1129,17 +1113,16 @@ static void yaffs_release_space(struct file *f) { yaffs_Object *obj; yaffs_Device *dev; - - + + obj = yaffs_DentryToObject(f->f_dentry); dev = obj->myDev; yaffs_GrossLock(dev); - - yaffs_GrossUnlock(dev); + yaffs_GrossUnlock(dev); } static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir) @@ -1164,10 +1147,9 @@ static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir) if (offset == 0) { T(YAFFS_TRACE_OS, - ( "yaffs_readdir: entry . ino %d \n", - (int)inode->i_ino)); - if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) - < 0) { + ("yaffs_readdir: entry . ino %d \n", + (int)inode->i_ino)); + if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) < 0) { goto out; } offset++; @@ -1175,11 +1157,10 @@ static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir) } if (offset == 1) { T(YAFFS_TRACE_OS, - ( "yaffs_readdir: entry .. ino %d \n", - (int)f->f_dentry->d_parent->d_inode->i_ino)); - if (filldir - (dirent, "..", 2, offset, - f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) { + ("yaffs_readdir: entry .. ino %d \n", + (int)f->f_dentry->d_parent->d_inode->i_ino)); + if (filldir(dirent, "..", 2, offset, + f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) { goto out; } offset++; @@ -1205,16 +1186,15 @@ static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir) yaffs_GetObjectName(l, name, YAFFS_MAX_NAME_LENGTH + 1); T(YAFFS_TRACE_OS, - ( "yaffs_readdir: %s inode %d\n", name, + ("yaffs_readdir: %s inode %d\n", name, yaffs_GetObjectInode(l))); if (filldir(dirent, - name, - strlen(name), - offset, - yaffs_GetObjectInode(l), - yaffs_GetObjectType(l)) - < 0) { + name, + strlen(name), + offset, + yaffs_GetObjectInode(l), + yaffs_GetObjectType(l)) < 0) { goto up_and_out; } @@ -1223,9 +1203,8 @@ static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir) } } - up_and_out: - out: - +up_and_out: +out: yaffs_GrossUnlock(dev); return 0; @@ -1234,19 +1213,19 @@ static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir) /* * File creation. Allocate an inode, and we're done.. */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) #define YCRED(x) x #else -#define YCRED(x) x->cred +#define YCRED(x) (x->cred) #endif -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, - dev_t rdev) + dev_t rdev) #else static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, - int rdev) + int rdev) #endif { struct inode *inode; @@ -1260,22 +1239,22 @@ static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, uid_t uid = YCRED(current)->fsuid; gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid; - if((dir->i_mode & S_ISGID) && S_ISDIR(mode)) + if ((dir->i_mode & S_ISGID) && S_ISDIR(mode)) mode |= S_ISGID; if (parent) { T(YAFFS_TRACE_OS, - ( "yaffs_mknod: parent object %d type %d\n", - parent->objectId, parent->variantType)); + ("yaffs_mknod: parent object %d type %d\n", + parent->objectId, parent->variantType)); } else { T(YAFFS_TRACE_OS, - ( "yaffs_mknod: could not get parent object\n")); + ("yaffs_mknod: could not get parent object\n")); return -EPERM; } T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, " - "mode %x dev %x\n", - dentry->d_name.name, mode, rdev)); + "mode %x dev %x\n", + dentry->d_name.name, mode, rdev)); dev = parent->myDev; @@ -1284,33 +1263,28 @@ static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, switch (mode & S_IFMT) { default: /* Special (socket, fifo, device...) */ - T(YAFFS_TRACE_OS, ( - "yaffs_mknod: making special\n")); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) - obj = - yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid, - gid, old_encode_dev(rdev)); + T(YAFFS_TRACE_OS, ("yaffs_mknod: making special\n")); +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) + obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid, + gid, old_encode_dev(rdev)); #else - obj = - yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid, - gid, rdev); + obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid, + gid, rdev); #endif break; case S_IFREG: /* file */ - T(YAFFS_TRACE_OS, ( "yaffs_mknod: making file\n")); - obj = - yaffs_MknodFile(parent, dentry->d_name.name, mode, uid, - gid); + T(YAFFS_TRACE_OS, ("yaffs_mknod: making file\n")); + obj = yaffs_MknodFile(parent, dentry->d_name.name, mode, uid, + gid); break; case S_IFDIR: /* directory */ T(YAFFS_TRACE_OS, - ( "yaffs_mknod: making directory\n")); - obj = - yaffs_MknodDirectory(parent, dentry->d_name.name, mode, - uid, gid); + ("yaffs_mknod: making directory\n")); + obj = yaffs_MknodDirectory(parent, dentry->d_name.name, mode, + uid, gid); break; case S_IFLNK: /* symlink */ - T(YAFFS_TRACE_OS, ( "yaffs_mknod: making symlink\n")); + T(YAFFS_TRACE_OS, ("yaffs_mknod: making symlink\n")); obj = NULL; /* Do we ever get here? */ break; } @@ -1322,12 +1296,12 @@ static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj); d_instantiate(dentry, inode); T(YAFFS_TRACE_OS, - ( "yaffs_mknod created object %d count = %d\n", - obj->objectId, atomic_read(&inode->i_count))); + ("yaffs_mknod created object %d count = %d\n", + obj->objectId, atomic_read(&inode->i_count))); error = 0; } else { T(YAFFS_TRACE_OS, - ( "yaffs_mknod failed making object\n")); + ("yaffs_mknod failed making object\n")); error = -ENOMEM; } @@ -1337,7 +1311,7 @@ static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode) { int retVal; - T(YAFFS_TRACE_OS, ( "yaffs_mkdir\n")); + T(YAFFS_TRACE_OS, ("yaffs_mkdir\n")); retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0); #if 0 /* attempt to fix dir bug - didn't work */ @@ -1348,14 +1322,14 @@ static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode) return retVal; } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n) #else static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode) #endif { - T(YAFFS_TRACE_OS, ( "yaffs_create\n")); + T(YAFFS_TRACE_OS, ("yaffs_create\n")); return yaffs_mknod(dir, dentry, mode | S_IFREG, 0); } @@ -1366,8 +1340,8 @@ static int yaffs_unlink(struct inode *dir, struct dentry *dentry) yaffs_Device *dev; T(YAFFS_TRACE_OS, - ( "yaffs_unlink %d:%s\n", (int)(dir->i_ino), - dentry->d_name.name)); + ("yaffs_unlink %d:%s\n", (int)(dir->i_ino), + dentry->d_name.name)); dev = yaffs_InodeToObject(dir)->myDev; @@ -1390,25 +1364,23 @@ static int yaffs_unlink(struct inode *dir, struct dentry *dentry) * Create a link... */ static int yaffs_link(struct dentry *old_dentry, struct inode *dir, - struct dentry *dentry) + struct dentry *dentry) { struct inode *inode = old_dentry->d_inode; yaffs_Object *obj = NULL; yaffs_Object *link = NULL; yaffs_Device *dev; - T(YAFFS_TRACE_OS, ( "yaffs_link\n")); + T(YAFFS_TRACE_OS, ("yaffs_link\n")); obj = yaffs_InodeToObject(inode); dev = obj->myDev; yaffs_GrossLock(dev); - if (!S_ISDIR(inode->i_mode)) /* Don't link directories */ - { - link = - yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name, - obj); + if (!S_ISDIR(inode->i_mode)) { /* Don't link directories */ + link = yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name, + obj); } if (link) { @@ -1416,16 +1388,14 @@ static int yaffs_link(struct dentry *old_dentry, struct inode *dir, d_instantiate(dentry, old_dentry->d_inode); atomic_inc(&old_dentry->d_inode->i_count); T(YAFFS_TRACE_OS, - ( "yaffs_link link count %d i_count %d\n", - old_dentry->d_inode->i_nlink, - atomic_read(&old_dentry->d_inode->i_count))); - + ("yaffs_link link count %d i_count %d\n", + old_dentry->d_inode->i_nlink, + atomic_read(&old_dentry->d_inode->i_count))); } yaffs_GrossUnlock(dev); if (link) { - return 0; } @@ -1433,39 +1403,37 @@ static int yaffs_link(struct dentry *old_dentry, struct inode *dir, } static int yaffs_symlink(struct inode *dir, struct dentry *dentry, - const char *symname) + const char *symname) { yaffs_Object *obj; yaffs_Device *dev; uid_t uid = YCRED(current)->fsuid; gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid; - T(YAFFS_TRACE_OS, ( "yaffs_symlink\n")); + T(YAFFS_TRACE_OS, ("yaffs_symlink\n")); dev = yaffs_InodeToObject(dir)->myDev; yaffs_GrossLock(dev); obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name, - S_IFLNK | S_IRWXUGO, uid, gid, symname); + S_IFLNK | S_IRWXUGO, uid, gid, symname); yaffs_GrossUnlock(dev); if (obj) { - struct inode *inode; inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj); d_instantiate(dentry, inode); - T(YAFFS_TRACE_OS, ( "symlink created OK\n")); + T(YAFFS_TRACE_OS, ("symlink created OK\n")); return 0; } else { - T(YAFFS_TRACE_OS, ( "symlink not created\n")); - + T(YAFFS_TRACE_OS, ("symlink not created\n")); } return -ENOMEM; } static int yaffs_sync_object(struct file *file, struct dentry *dentry, - int datasync) + int datasync) { yaffs_Object *obj; @@ -1475,7 +1443,7 @@ static int yaffs_sync_object(struct file *file, struct dentry *dentry, dev = obj->myDev; - T(YAFFS_TRACE_OS, ( "yaffs_sync_object\n")); + T(YAFFS_TRACE_OS, ("yaffs_sync_object\n")); yaffs_GrossLock(dev); yaffs_FlushFile(obj, 1); yaffs_GrossUnlock(dev); @@ -1494,41 +1462,36 @@ static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry, int retVal = YAFFS_FAIL; yaffs_Object *target; - T(YAFFS_TRACE_OS, ( "yaffs_rename\n")); + T(YAFFS_TRACE_OS, ("yaffs_rename\n")); dev = yaffs_InodeToObject(old_dir)->myDev; yaffs_GrossLock(dev); /* Check if the target is an existing directory that is not empty. */ - target = - yaffs_FindObjectByName(yaffs_InodeToObject(new_dir), - new_dentry->d_name.name); + target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir), + new_dentry->d_name.name); - if (target && - target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY && - !ylist_empty(&target->variant.directoryVariant.children)) { + if (target && target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY && + !ylist_empty(&target->variant.directoryVariant.children)) { - T(YAFFS_TRACE_OS, ( "target is non-empty dir\n")); + T(YAFFS_TRACE_OS, ("target is non-empty dir\n")); retVal = YAFFS_FAIL; } else { - /* Now does unlinking internally using shadowing mechanism */ - T(YAFFS_TRACE_OS, ( "calling yaffs_RenameObject\n")); - - retVal = - yaffs_RenameObject(yaffs_InodeToObject(old_dir), - old_dentry->d_name.name, - yaffs_InodeToObject(new_dir), - new_dentry->d_name.name); + T(YAFFS_TRACE_OS, ("calling yaffs_RenameObject\n")); + retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir), + old_dentry->d_name.name, + yaffs_InodeToObject(new_dir), + new_dentry->d_name.name); } yaffs_GrossUnlock(dev); if (retVal == YAFFS_OK) { - if(target) { + if (target) { new_dentry->d_inode->i_nlink--; mark_inode_dirty(new_dentry->d_inode); } @@ -1537,7 +1500,6 @@ static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry, } else { return -ENOTEMPTY; } - } static int yaffs_setattr(struct dentry *dentry, struct iattr *attr) @@ -1547,15 +1509,15 @@ static int yaffs_setattr(struct dentry *dentry, struct iattr *attr) yaffs_Device *dev; T(YAFFS_TRACE_OS, - ( "yaffs_setattr of object %d\n", - yaffs_InodeToObject(inode)->objectId)); - - if ((error = inode_change_ok(inode, attr)) == 0) { + ("yaffs_setattr of object %d\n", + yaffs_InodeToObject(inode)->objectId)); + error = inode_change_ok(inode, attr); + if (error == 0) { dev = yaffs_InodeToObject(inode)->myDev; yaffs_GrossLock(dev); if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) == - YAFFS_OK) { + YAFFS_OK) { error = 0; } else { error = -EPERM; @@ -1567,12 +1529,12 @@ static int yaffs_setattr(struct dentry *dentry, struct iattr *attr) return error; } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf) { yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev; struct super_block *sb = dentry->d_sb; -#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf) { yaffs_Device *dev = yaffs_SuperToDevice(sb); @@ -1582,54 +1544,53 @@ static int yaffs_statfs(struct super_block *sb, struct statfs *buf) yaffs_Device *dev = yaffs_SuperToDevice(sb); #endif - T(YAFFS_TRACE_OS, ( "yaffs_statfs\n")); + T(YAFFS_TRACE_OS, ("yaffs_statfs\n")); yaffs_GrossLock(dev); buf->f_type = YAFFS_MAGIC; buf->f_bsize = sb->s_blocksize; buf->f_namelen = 255; - - if(dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)){ + + if (dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)) { /* Do this if chunk size is not a power of 2 */ - + uint64_t bytesInDev; uint64_t bytesFree; - bytesInDev = ((uint64_t)((dev->endBlock - dev->startBlock +1))) * - ((uint64_t)(dev->nChunksPerBlock * dev->nDataBytesPerChunk)); - - do_div(bytesInDev,sb->s_blocksize); /* bytesInDev becomes the number of blocks */ + bytesInDev = ((uint64_t)((dev->endBlock - dev->startBlock + 1))) * + ((uint64_t)(dev->nChunksPerBlock * dev->nDataBytesPerChunk)); + + do_div(bytesInDev, sb->s_blocksize); /* bytesInDev becomes the number of blocks */ buf->f_blocks = bytesInDev; bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) * - ((uint64_t)(dev->nDataBytesPerChunk)); - - do_div(bytesFree,sb->s_blocksize); - + ((uint64_t)(dev->nDataBytesPerChunk)); + + do_div(bytesFree, sb->s_blocksize); + buf->f_bfree = bytesFree; - + } else if (sb->s_blocksize > dev->nDataBytesPerChunk) { - + buf->f_blocks = - (dev->endBlock - dev->startBlock + 1) * - dev->nChunksPerBlock / - (sb->s_blocksize / dev->nDataBytesPerChunk); - buf->f_bfree = - yaffs_GetNumberOfFreeChunks(dev) / - (sb->s_blocksize / dev->nDataBytesPerChunk); + (dev->endBlock - dev->startBlock + 1) * + dev->nChunksPerBlock / + (sb->s_blocksize / dev->nDataBytesPerChunk); + buf->f_bfree = + yaffs_GetNumberOfFreeChunks(dev) / + (sb->s_blocksize / dev->nDataBytesPerChunk); } else { - buf->f_blocks = - (dev->endBlock - dev->startBlock + 1) * - dev->nChunksPerBlock * - (dev->nDataBytesPerChunk / sb->s_blocksize); - - buf->f_bfree = - yaffs_GetNumberOfFreeChunks(dev) * - (dev->nDataBytesPerChunk / sb->s_blocksize); + buf->f_blocks = + (dev->endBlock - dev->startBlock + 1) * + dev->nChunksPerBlock * + (dev->nDataBytesPerChunk / sb->s_blocksize); + + buf->f_bfree = + yaffs_GetNumberOfFreeChunks(dev) * + (dev->nDataBytesPerChunk / sb->s_blocksize); } - - + buf->f_files = 0; buf->f_ffree = 0; buf->f_bavail = buf->f_bfree; @@ -1643,12 +1604,12 @@ static int yaffs_do_sync_fs(struct super_block *sb) { yaffs_Device *dev = yaffs_SuperToDevice(sb); - T(YAFFS_TRACE_OS, ( "yaffs_do_sync_fs\n")); + T(YAFFS_TRACE_OS, ("yaffs_do_sync_fs\n")); - if(sb->s_dirt) { + if (sb->s_dirt) { yaffs_GrossLock(dev); - if(dev){ + if (dev) { yaffs_FlushEntireDeviceCache(dev); yaffs_CheckpointSave(dev); } @@ -1661,48 +1622,46 @@ static int yaffs_do_sync_fs(struct super_block *sb) } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) static void yaffs_write_super(struct super_block *sb) #else static int yaffs_write_super(struct super_block *sb) #endif { - T(YAFFS_TRACE_OS, ( "yaffs_write_super\n")); + T(YAFFS_TRACE_OS, ("yaffs_write_super\n")); if (yaffs_auto_checkpoint >= 2) yaffs_do_sync_fs(sb); -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)) - return 0; +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)) + return 0; #endif } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) static int yaffs_sync_fs(struct super_block *sb, int wait) #else static int yaffs_sync_fs(struct super_block *sb) #endif { - - T(YAFFS_TRACE_OS, ( "yaffs_sync_fs\n")); + T(YAFFS_TRACE_OS, ("yaffs_sync_fs\n")); if (yaffs_auto_checkpoint >= 1) yaffs_do_sync_fs(sb); - - return 0; + return 0; } #ifdef YAFFS_USE_OWN_IGET -static struct inode * yaffs_iget(struct super_block *sb, unsigned long ino) +static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino) { struct inode *inode; yaffs_Object *obj; yaffs_Device *dev = yaffs_SuperToDevice(sb); T(YAFFS_TRACE_OS, - ( "yaffs_iget for %lu\n", ino)); + ("yaffs_iget for %lu\n", ino)); inode = iget_locked(sb, ino); if (!inode) @@ -1710,11 +1669,11 @@ static struct inode * yaffs_iget(struct super_block *sb, unsigned long ino) if (!(inode->i_state & I_NEW)) return inode; - /* NB This is called as a side effect of other functions, but - * we had to release the lock to prevent deadlocks, so - * need to lock again. - */ - + /* NB This is called as a side effect of other functions, but + * we had to release the lock to prevent deadlocks, so + * need to lock again. + */ + yaffs_GrossLock(dev); obj = yaffs_FindObjectByNumber(dev, inode->i_ino); @@ -1722,7 +1681,7 @@ static struct inode * yaffs_iget(struct super_block *sb, unsigned long ino) yaffs_FillInodeFromObject(inode, obj); yaffs_GrossUnlock(dev); - + unlock_new_inode(inode); return inode; } @@ -1740,7 +1699,7 @@ static void yaffs_read_inode(struct inode *inode) yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb); T(YAFFS_TRACE_OS, - ( "yaffs_read_inode for %d\n", (int)inode->i_ino)); + ("yaffs_read_inode for %d\n", (int)inode->i_ino)); yaffs_GrossLock(dev); @@ -1755,16 +1714,16 @@ static void yaffs_read_inode(struct inode *inode) static YLIST_HEAD(yaffs_dev_list); -#if 0 // not used +#if 0 /* not used */ static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data) { yaffs_Device *dev = yaffs_SuperToDevice(sb); - if( *flags & MS_RDONLY ) { + if (*flags & MS_RDONLY) { struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice; T(YAFFS_TRACE_OS, - ( "yaffs_remount_fs: %s: RO\n", dev->name )); + ("yaffs_remount_fs: %s: RO\n", dev->name)); yaffs_GrossLock(dev); @@ -1776,10 +1735,9 @@ static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data) mtd->sync(mtd); yaffs_GrossUnlock(dev); - } - else { + } else { T(YAFFS_TRACE_OS, - ( "yaffs_remount_fs: %s: RW\n", dev->name )); + ("yaffs_remount_fs: %s: RW\n", dev->name)); } return 0; @@ -1790,7 +1748,7 @@ static void yaffs_put_super(struct super_block *sb) { yaffs_Device *dev = yaffs_SuperToDevice(sb); - T(YAFFS_TRACE_OS, ( "yaffs_put_super\n")); + T(YAFFS_TRACE_OS, ("yaffs_put_super\n")); yaffs_GrossLock(dev); @@ -1798,9 +1756,8 @@ static void yaffs_put_super(struct super_block *sb) yaffs_CheckpointSave(dev); - if (dev->putSuperFunc) { + if (dev->putSuperFunc) dev->putSuperFunc(sb); - } yaffs_Deinitialise(dev); @@ -1809,7 +1766,7 @@ static void yaffs_put_super(struct super_block *sb) /* we assume this is protected by lock_kernel() in mount/umount */ ylist_del(&dev->devList); - if(dev->spareBuffer){ + if (dev->spareBuffer) { YFREE(dev->spareBuffer); dev->spareBuffer = NULL; } @@ -1820,12 +1777,10 @@ static void yaffs_put_super(struct super_block *sb) static void yaffs_MTDPutSuper(struct super_block *sb) { - struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice; - if (mtd->sync) { + if (mtd->sync) mtd->sync(mtd); - } put_mtd_device(mtd); } @@ -1835,8 +1790,8 @@ static void yaffs_MarkSuperBlockDirty(void *vsb) { struct super_block *sb = (struct super_block *)vsb; - T(YAFFS_TRACE_OS, ( "yaffs_MarkSuperBlockDirty() sb = %p\n",sb)); - if(sb) + T(YAFFS_TRACE_OS, ("yaffs_MarkSuperBlockDirty() sb = %p\n", sb)); + if (sb) sb->s_dirt = 1; } @@ -1850,48 +1805,48 @@ typedef struct { #define MAX_OPT_LEN 20 static int yaffs_parse_options(yaffs_options *options, const char *options_str) { - char cur_opt[MAX_OPT_LEN+1]; + char cur_opt[MAX_OPT_LEN + 1]; int p; int error = 0; /* Parse through the options which is a comma seperated list */ - while(options_str && *options_str && !error){ - memset(cur_opt,0,MAX_OPT_LEN+1); + while (options_str && *options_str && !error) { + memset(cur_opt, 0, MAX_OPT_LEN + 1); p = 0; - while(*options_str && *options_str != ','){ - if(p < MAX_OPT_LEN){ + while (*options_str && *options_str != ',') { + if (p < MAX_OPT_LEN) { cur_opt[p] = *options_str; p++; } options_str++; } - if(!strcmp(cur_opt,"inband-tags")) + if (!strcmp(cur_opt, "inband-tags")) options->inband_tags = 1; - else if(!strcmp(cur_opt,"no-cache")) + else if (!strcmp(cur_opt, "no-cache")) options->no_cache = 1; - else if(!strcmp(cur_opt,"no-checkpoint-read")) + else if (!strcmp(cur_opt, "no-checkpoint-read")) options->skip_checkpoint_read = 1; - else if(!strcmp(cur_opt,"no-checkpoint-write")) + else if (!strcmp(cur_opt, "no-checkpoint-write")) options->skip_checkpoint_write = 1; - else if(!strcmp(cur_opt,"no-checkpoint")){ + else if (!strcmp(cur_opt, "no-checkpoint")) { options->skip_checkpoint_read = 1; options->skip_checkpoint_write = 1; } else { - printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",cur_opt); + printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n", + cur_opt); error = 1; } - } return error; } static struct super_block *yaffs_internal_read_super(int yaffsVersion, - struct super_block *sb, - void *data, int silent) + struct super_block *sb, + void *data, int silent) { int nBlocks; struct inode *inode = NULL; @@ -1919,14 +1874,14 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, sb->s_dev, yaffs_devname(sb, devname_buf)); - if(!data_str) + if (!data_str) data_str = ""; - printk(KERN_INFO "yaffs: passed flags \"%s\"\n",data_str); + printk(KERN_INFO "yaffs: passed flags \"%s\"\n", data_str); - memset(&options,0,sizeof(options)); + memset(&options, 0, sizeof(options)); - if(yaffs_parse_options(&options,data_str)){ + if (yaffs_parse_options(&options, data_str)) { /* Option parsing failed */ return NULL; } @@ -1978,7 +1933,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, T(YAFFS_TRACE_OS, (" %s %d\n", WRITE_SIZE_STR, WRITE_SIZE(mtd))); T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize)); T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize)); -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) T(YAFFS_TRACE_OS, (" size %u\n", mtd->size)); #else T(YAFFS_TRACE_OS, (" size %lld\n", mtd->size)); @@ -1988,15 +1943,15 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, if (yaffsVersion == 1 && WRITE_SIZE(mtd) >= 2048) { - T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n")); + T(YAFFS_TRACE_ALWAYS, ("yaffs: auto selecting yaffs2\n")); yaffsVersion = 2; } /* Added NCB 26/5/2006 for completeness */ - if (yaffsVersion == 2 && + if (yaffsVersion == 2 && !options.inband_tags && - WRITE_SIZE(mtd) == 512){ - T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs1\n")); + WRITE_SIZE(mtd) == 512) { + T(YAFFS_TRACE_ALWAYS, ("yaffs: auto selecting yaffs1\n")); yaffsVersion = 1; } @@ -2009,7 +1964,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, !mtd->block_markbad || !mtd->read || !mtd->write || -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) !mtd->read_oob || !mtd->write_oob) { #else !mtd->write_ecc || @@ -2034,7 +1989,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, if (!mtd->erase || !mtd->read || !mtd->write || -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) !mtd->read_oob || !mtd->write_oob) { #else !mtd->write_ecc || @@ -2060,7 +2015,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, * Set the yaffs_Device up for mtd */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL); #else sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL); @@ -2079,7 +2034,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, /* Set up the memory size parameters.... */ - nBlocks = YCALCBLOCKS(mtd->size ,(YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK)); + nBlocks = YCALCBLOCKS(mtd->size, (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK)); dev->startBlock = 0; dev->endBlock = nBlocks - 1; @@ -2099,19 +2054,19 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, dev->queryNANDBlock = nandmtd2_QueryNANDBlock; dev->spareBuffer = YMALLOC(mtd->oobsize); dev->isYaffs2 = 1; -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) dev->totalBytesPerChunk = mtd->writesize; dev->nChunksPerBlock = mtd->erasesize / mtd->writesize; #else dev->totalBytesPerChunk = mtd->oobblock; dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock; #endif - nBlocks = YCALCBLOCKS(mtd->size,mtd->erasesize); + nBlocks = YCALCBLOCKS(mtd->size, mtd->erasesize); dev->startBlock = 0; dev->endBlock = nBlocks - 1; } else { -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) /* use the MTD interface in yaffs_mtdif1.c */ dev->writeChunkWithTagsToNAND = nandmtd1_WriteChunkWithTagsToNAND; @@ -2193,14 +2148,14 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data, int silent) { return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL; } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) static int yaffs_read_super(struct file_system_type *fs, int flags, const char *dev_name, void *data, struct vfsmount *mnt) @@ -2241,14 +2196,14 @@ static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, #ifdef CONFIG_YAFFS_YAFFS2 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data, int silent) { return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL; } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) static int yaffs2_read_super(struct file_system_type *fs, int flags, const char *dev_name, void *data, struct vfsmount *mnt) @@ -2421,7 +2376,7 @@ static int yaffs_proc_write(struct file *file, const char *buf, char *end; char *mask_name; const char *x; - char substring[MAX_MASK_NAME_LENGTH+1]; + char substring[MAX_MASK_NAME_LENGTH + 1]; int i; int done = 0; int add, len = 0; @@ -2456,14 +2411,14 @@ static int yaffs_proc_write(struct file *file, const char *buf, pos += len; done = 0; } else { - for(x = buf + pos, i = 0; - (*x == '_' || (*x >='a' && *x <= 'z')) && - i = 'a' && *x <= 'z')) && + i < MAX_MASK_NAME_LENGTH; x++, i++, pos++) + substring[i] = *x; substring[i] = '\0'; for (i = 0; mask_flags[i].mask_name != NULL; i++) { - if(strcmp(substring,mask_flags[i].mask_name) == 0){ + if (strcmp(substring, mask_flags[i].mask_name) == 0) { mask_name = mask_flags[i].mask_name; mask_bitfield = mask_flags[i].mask_bitfield; done = 0; @@ -2474,7 +2429,7 @@ static int yaffs_proc_write(struct file *file, const char *buf, if (mask_name != NULL) { done = 0; - switch(add) { + switch (add) { case '-': rg &= ~mask_bitfield; break; @@ -2493,13 +2448,13 @@ static int yaffs_proc_write(struct file *file, const char *buf, yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS; - printk("new trace = 0x%08X\n",yaffs_traceMask); + printk(KERN_DEBUG "new trace = 0x%08X\n", yaffs_traceMask); if (rg & YAFFS_TRACE_ALWAYS) { for (i = 0; mask_flags[i].mask_name != NULL; i++) { char flag; flag = ((rg & mask_flags[i].mask_bitfield) == mask_flags[i].mask_bitfield) ? '+' : '-'; - printk("%c%s\n", flag, mask_flags[i].mask_name); + printk(KERN_DEBUG "%c%s\n", flag, mask_flags[i].mask_name); } } @@ -2513,12 +2468,8 @@ struct file_system_to_install { }; static struct file_system_to_install fs_to_install[] = { -//#ifdef CONFIG_YAFFS_YAFFS1 {&yaffs_fs_type, 0}, -//#endif -//#ifdef CONFIG_YAFFS_YAFFS2 {&yaffs2_fs_type, 0}, -//#endif {NULL, 0} }; @@ -2590,7 +2541,6 @@ static void __exit exit_yaffs_fs(void) } fsinst++; } - } module_init(init_yaffs_fs) diff --git a/yaffs_getblockinfo.h b/yaffs_getblockinfo.h index b9742ac..5b0a1ac 100644 --- a/yaffs_getblockinfo.h +++ b/yaffs_getblockinfo.h @@ -1,5 +1,5 @@ /* - * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. * * Copyright (C) 2002-2007 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering diff --git a/yaffs_guts.c b/yaffs_guts.c index ea1ffc2..4359db2 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -12,7 +12,7 @@ */ const char *yaffs_guts_c_version = - "$Id: yaffs_guts.c,v 1.80 2009-03-05 21:46:46 charles Exp $"; + "$Id: yaffs_guts.c,v 1.81 2009-03-06 17:20:51 wookey Exp $"; #include "yportenv.h" @@ -22,7 +22,7 @@ const char *yaffs_guts_c_version = #include "yaffs_getblockinfo.h" #include "yaffs_tagscompat.h" -#ifndef CONFIG_YAFFS_USE_OWN_SORT +#ifndef CONFIG_YAFFS_USE_OWN_SORT #include "yaffs_qsort.h" #endif #include "yaffs_nand.h" @@ -39,101 +39,102 @@ const char *yaffs_guts_c_version = /* Robustification (if it ever comes about...) */ -static void yaffs_RetireBlock(yaffs_Device * dev, int blockInNAND); -static void yaffs_HandleWriteChunkError(yaffs_Device * dev, int chunkInNAND, int erasedOk); -static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND, - const __u8 * data, - const yaffs_ExtendedTags * tags); -static void yaffs_HandleUpdateChunk(yaffs_Device * dev, int chunkInNAND, - const yaffs_ExtendedTags * tags); +static void yaffs_RetireBlock(yaffs_Device *dev, int blockInNAND); +static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND, + int erasedOk); +static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND, + const __u8 *data, + const yaffs_ExtendedTags *tags); +static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND, + const yaffs_ExtendedTags *tags); /* Other local prototypes */ -static int yaffs_UnlinkObject( yaffs_Object *obj); +static int yaffs_UnlinkObject(yaffs_Object *obj); static int yaffs_ObjectHasCachedWriteData(yaffs_Object *obj); static void yaffs_HardlinkFixup(yaffs_Device *dev, yaffs_Object *hardList); -static int yaffs_WriteNewChunkWithTagsToNAND(yaffs_Device * dev, - const __u8 * buffer, - yaffs_ExtendedTags * tags, - int useReserve); -static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode, - int chunkInNAND, int inScan); - -static yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, - yaffs_ObjectType type); -static void yaffs_AddObjectToDirectory(yaffs_Object * directory, - yaffs_Object * obj); -static int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, - int force, int isShrink, int shadows); -static void yaffs_RemoveObjectFromDirectory(yaffs_Object * obj); +static int yaffs_WriteNewChunkWithTagsToNAND(yaffs_Device *dev, + const __u8 *buffer, + yaffs_ExtendedTags *tags, + int useReserve); +static int yaffs_PutChunkIntoFile(yaffs_Object *in, int chunkInInode, + int chunkInNAND, int inScan); + +static yaffs_Object *yaffs_CreateNewObject(yaffs_Device *dev, int number, + yaffs_ObjectType type); +static void yaffs_AddObjectToDirectory(yaffs_Object *directory, + yaffs_Object *obj); +static int yaffs_UpdateObjectHeader(yaffs_Object *in, const YCHAR *name, + int force, int isShrink, int shadows); +static void yaffs_RemoveObjectFromDirectory(yaffs_Object *obj); static int yaffs_CheckStructures(void); -static int yaffs_DeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, __u32 level, - int chunkOffset, int *limit); -static int yaffs_DoGenericObjectDeletion(yaffs_Object * in); +static int yaffs_DeleteWorker(yaffs_Object *in, yaffs_Tnode *tn, __u32 level, + int chunkOffset, int *limit); +static int yaffs_DoGenericObjectDeletion(yaffs_Object *in); -static yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blockNo); +static yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device *dev, int blockNo); static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, - int chunkInNAND); + int chunkInNAND); -static int yaffs_UnlinkWorker(yaffs_Object * obj); +static int yaffs_UnlinkWorker(yaffs_Object *obj); -static int yaffs_TagsMatch(const yaffs_ExtendedTags * tags, int objectId, - int chunkInObject); +static int yaffs_TagsMatch(const yaffs_ExtendedTags *tags, int objectId, + int chunkInObject); -loff_t yaffs_GetFileSize(yaffs_Object * obj); +loff_t yaffs_GetFileSize(yaffs_Object *obj); -static int yaffs_AllocateChunk(yaffs_Device * dev, int useReserve, yaffs_BlockInfo **blockUsedPtr); +static int yaffs_AllocateChunk(yaffs_Device *dev, int useReserve, + yaffs_BlockInfo **blockUsedPtr); -static void yaffs_VerifyFreeChunks(yaffs_Device * dev); +static void yaffs_VerifyFreeChunks(yaffs_Device *dev); static void yaffs_CheckObjectDetailsLoaded(yaffs_Object *in); static void yaffs_VerifyDirectory(yaffs_Object *directory); #ifdef YAFFS_PARANOID -static int yaffs_CheckFileSanity(yaffs_Object * in); +static int yaffs_CheckFileSanity(yaffs_Object *in); #else #define yaffs_CheckFileSanity(in) #endif -static void yaffs_InvalidateWholeChunkCache(yaffs_Object * in); -static void yaffs_InvalidateChunkCache(yaffs_Object * object, int chunkId); +static void yaffs_InvalidateWholeChunkCache(yaffs_Object *in); +static void yaffs_InvalidateChunkCache(yaffs_Object *object, int chunkId); static void yaffs_InvalidateCheckpoint(yaffs_Device *dev); -static int yaffs_FindChunkInFile(yaffs_Object * in, int chunkInInode, - yaffs_ExtendedTags * tags); +static int yaffs_FindChunkInFile(yaffs_Object *in, int chunkInInode, + yaffs_ExtendedTags *tags); -static __u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos); -static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device * dev, - yaffs_FileStructure * fStruct, - __u32 chunkId); +static __u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn, + unsigned pos); +static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device *dev, + yaffs_FileStructure *fStruct, + __u32 chunkId); /* Function to calculate chunk and offset */ -static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, int *chunkOut, __u32 *offsetOut) +static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, int *chunkOut, + __u32 *offsetOut) { int chunk; __u32 offset; - + chunk = (__u32)(addr >> dev->chunkShift); - - if(dev->chunkDiv == 1) - { + + if (dev->chunkDiv == 1) { /* easy power of 2 case */ offset = (__u32)(addr & dev->chunkMask); - } - else - { + } else { /* Non power-of-2 case */ - + loff_t chunkBase; - + chunk /= dev->chunkDiv; - + chunkBase = ((loff_t)chunk) * dev->nDataBytesPerChunk; offset = (__u32)(addr - chunkBase); } @@ -142,79 +143,80 @@ static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, int *chunkOut, __u *offsetOut = offset; } -/* Function to return the number of shifts for a power of 2 greater than or equal - * to the given number +/* Function to return the number of shifts for a power of 2 greater than or + * equal to the given number * Note we don't try to cater for all possible numbers and this does not have to * be hellishly efficient. */ - + static __u32 ShiftsGE(__u32 x) { int extraBits; int nShifts; - + nShifts = extraBits = 0; - - while(x>1){ - if(x & 1) extraBits++; - x>>=1; + + while (x > 1) { + if (x & 1) + extraBits++; + x >>= 1; nShifts++; } - if(extraBits) + if (extraBits) nShifts++; - + return nShifts; } /* Function to return the number of shifts to get a 1 in bit 0 */ - + static __u32 Shifts(__u32 x) { int nShifts; - + nShifts = 0; - - if(!x) return 0; - - while( !(x&1)){ - x>>=1; + + if (!x) + return 0; + + while (!(x&1)) { + x >>= 1; nShifts++; } - + return nShifts; } -/* +/* * Temporary buffer manipulations. */ -static int yaffs_InitialiseTempBuffers(yaffs_Device *dev) +static int yaffs_InitialiseTempBuffers(yaffs_Device *dev) { int i; __u8 *buf = (__u8 *)1; - - memset(dev->tempBuffer,0,sizeof(dev->tempBuffer)); - + + memset(dev->tempBuffer, 0, sizeof(dev->tempBuffer)); + for (i = 0; buf && i < YAFFS_N_TEMP_BUFFERS; i++) { dev->tempBuffer[i].line = 0; /* not in use */ dev->tempBuffer[i].buffer = buf = YMALLOC_DMA(dev->totalBytesPerChunk); } - + return buf ? YAFFS_OK : YAFFS_FAIL; - } -__u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) +__u8 *yaffs_GetTempBuffer(yaffs_Device *dev, int lineNo) { int i, j; dev->tempInUse++; - if(dev->tempInUse > dev->maxTemp) + if (dev->tempInUse > dev->maxTemp) dev->maxTemp = dev->tempInUse; for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) { @@ -249,13 +251,13 @@ __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) } -void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, +void yaffs_ReleaseTempBuffer(yaffs_Device *dev, __u8 *buffer, int lineNo) { int i; - + dev->tempInUse--; - + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) { if (dev->tempBuffer[i].buffer == buffer) { dev->tempBuffer[i].line = 0; @@ -277,27 +279,26 @@ void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, /* * Determine if we have a managed buffer. */ -int yaffs_IsManagedTempBuffer(yaffs_Device * dev, const __u8 * buffer) +int yaffs_IsManagedTempBuffer(yaffs_Device *dev, const __u8 *buffer) { int i; + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) { if (dev->tempBuffer[i].buffer == buffer) return 1; - } - for (i = 0; i < dev->nShortOpCaches; i++) { - if( dev->srCache[i].data == buffer ) - return 1; - - } + for (i = 0; i < dev->nShortOpCaches; i++) { + if (dev->srCache[i].data == buffer) + return 1; + } - if (buffer == dev->checkpointBuffer) - return 1; + if (buffer == dev->checkpointBuffer) + return 1; - T(YAFFS_TRACE_ALWAYS, - (TSTR("yaffs: unmaged buffer detected.\n" TENDSTR))); - return 0; + T(YAFFS_TRACE_ALWAYS, + (TSTR("yaffs: unmaged buffer detected.\n" TENDSTR))); + return 0; } @@ -306,62 +307,63 @@ int yaffs_IsManagedTempBuffer(yaffs_Device * dev, const __u8 * buffer) * Chunk bitmap manipulations */ -static Y_INLINE __u8 *yaffs_BlockBits(yaffs_Device * dev, int blk) +static Y_INLINE __u8 *yaffs_BlockBits(yaffs_Device *dev, int blk) { if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) { T(YAFFS_TRACE_ERROR, - (TSTR("**>> yaffs: BlockBits block %d is not valid" TENDSTR), - blk)); + (TSTR("**>> yaffs: BlockBits block %d is not valid" TENDSTR), + blk)); YBUG(); } return dev->chunkBits + - (dev->chunkBitmapStride * (blk - dev->internalStartBlock)); + (dev->chunkBitmapStride * (blk - dev->internalStartBlock)); } static Y_INLINE void yaffs_VerifyChunkBitId(yaffs_Device *dev, int blk, int chunk) { - if(blk < dev->internalStartBlock || blk > dev->internalEndBlock || - chunk < 0 || chunk >= dev->nChunksPerBlock) { - T(YAFFS_TRACE_ERROR, - (TSTR("**>> yaffs: Chunk Id (%d:%d) invalid"TENDSTR),blk,chunk)); - YBUG(); + if (blk < dev->internalStartBlock || blk > dev->internalEndBlock || + chunk < 0 || chunk >= dev->nChunksPerBlock) { + T(YAFFS_TRACE_ERROR, + (TSTR("**>> yaffs: Chunk Id (%d:%d) invalid"TENDSTR), + blk, chunk)); + YBUG(); } } -static Y_INLINE void yaffs_ClearChunkBits(yaffs_Device * dev, int blk) +static Y_INLINE void yaffs_ClearChunkBits(yaffs_Device *dev, int blk) { __u8 *blkBits = yaffs_BlockBits(dev, blk); memset(blkBits, 0, dev->chunkBitmapStride); } -static Y_INLINE void yaffs_ClearChunkBit(yaffs_Device * dev, int blk, int chunk) +static Y_INLINE void yaffs_ClearChunkBit(yaffs_Device *dev, int blk, int chunk) { __u8 *blkBits = yaffs_BlockBits(dev, blk); - yaffs_VerifyChunkBitId(dev,blk,chunk); + yaffs_VerifyChunkBitId(dev, blk, chunk); blkBits[chunk / 8] &= ~(1 << (chunk & 7)); } -static Y_INLINE void yaffs_SetChunkBit(yaffs_Device * dev, int blk, int chunk) +static Y_INLINE void yaffs_SetChunkBit(yaffs_Device *dev, int blk, int chunk) { __u8 *blkBits = yaffs_BlockBits(dev, blk); - - yaffs_VerifyChunkBitId(dev,blk,chunk); + + yaffs_VerifyChunkBitId(dev, blk, chunk); blkBits[chunk / 8] |= (1 << (chunk & 7)); } -static Y_INLINE int yaffs_CheckChunkBit(yaffs_Device * dev, int blk, int chunk) +static Y_INLINE int yaffs_CheckChunkBit(yaffs_Device *dev, int blk, int chunk) { __u8 *blkBits = yaffs_BlockBits(dev, blk); - yaffs_VerifyChunkBitId(dev,blk,chunk); + yaffs_VerifyChunkBitId(dev, blk, chunk); return (blkBits[chunk / 8] & (1 << (chunk & 7))) ? 1 : 0; } -static Y_INLINE int yaffs_StillSomeChunkBits(yaffs_Device * dev, int blk) +static Y_INLINE int yaffs_StillSomeChunkBits(yaffs_Device *dev, int blk) { __u8 *blkBits = yaffs_BlockBits(dev, blk); int i; @@ -373,28 +375,28 @@ static Y_INLINE int yaffs_StillSomeChunkBits(yaffs_Device * dev, int blk) return 0; } -static int yaffs_CountChunkBits(yaffs_Device * dev, int blk) +static int yaffs_CountChunkBits(yaffs_Device *dev, int blk) { __u8 *blkBits = yaffs_BlockBits(dev, blk); int i; int n = 0; for (i = 0; i < dev->chunkBitmapStride; i++) { __u8 x = *blkBits; - while(x){ - if(x & 1) + while (x) { + if (x & 1) n++; - x >>=1; + x >>= 1; } - + blkBits++; } return n; } -/* +/* * Verification code */ - + static int yaffs_SkipVerification(yaffs_Device *dev) { return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY | YAFFS_TRACE_VERIFY_FULL)); @@ -410,7 +412,7 @@ static int yaffs_SkipNANDVerification(yaffs_Device *dev) return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_NAND)); } -static const char * blockStateName[] = { +static const char *blockStateName[] = { "Unknown", "Needs scanning", "Scanning", @@ -423,65 +425,65 @@ static const char * blockStateName[] = { "Dead" }; -static void yaffs_VerifyBlock(yaffs_Device *dev,yaffs_BlockInfo *bi,int n) +static void yaffs_VerifyBlock(yaffs_Device *dev, yaffs_BlockInfo *bi, int n) { int actuallyUsed; int inUse; - - if(yaffs_SkipVerification(dev)) + + if (yaffs_SkipVerification(dev)) return; - + /* Report illegal runtime states */ - if(bi->blockState >= YAFFS_NUMBER_OF_BLOCK_STATES) - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has undefined state %d"TENDSTR),n,bi->blockState)); - - switch(bi->blockState){ - case YAFFS_BLOCK_STATE_UNKNOWN: - case YAFFS_BLOCK_STATE_SCANNING: - case YAFFS_BLOCK_STATE_NEEDS_SCANNING: - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has bad run-state %s"TENDSTR), - n,blockStateName[bi->blockState])); + if (bi->blockState >= YAFFS_NUMBER_OF_BLOCK_STATES) + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has undefined state %d"TENDSTR), n, bi->blockState)); + + switch (bi->blockState) { + case YAFFS_BLOCK_STATE_UNKNOWN: + case YAFFS_BLOCK_STATE_SCANNING: + case YAFFS_BLOCK_STATE_NEEDS_SCANNING: + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has bad run-state %s"TENDSTR), + n, blockStateName[bi->blockState])); } - + /* Check pages in use and soft deletions are legal */ - + actuallyUsed = bi->pagesInUse - bi->softDeletions; - - if(bi->pagesInUse < 0 || bi->pagesInUse > dev->nChunksPerBlock || + + if (bi->pagesInUse < 0 || bi->pagesInUse > dev->nChunksPerBlock || bi->softDeletions < 0 || bi->softDeletions > dev->nChunksPerBlock || actuallyUsed < 0 || actuallyUsed > dev->nChunksPerBlock) - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has illegal values pagesInUsed %d softDeletions %d"TENDSTR), - n,bi->pagesInUse,bi->softDeletions)); - - + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has illegal values pagesInUsed %d softDeletions %d"TENDSTR), + n, bi->pagesInUse, bi->softDeletions)); + + /* Check chunk bitmap legal */ - inUse = yaffs_CountChunkBits(dev,n); - if(inUse != bi->pagesInUse) - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has inconsistent values pagesInUse %d counted chunk bits %d"TENDSTR), - n,bi->pagesInUse,inUse)); - + inUse = yaffs_CountChunkBits(dev, n); + if (inUse != bi->pagesInUse) + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has inconsistent values pagesInUse %d counted chunk bits %d"TENDSTR), + n, bi->pagesInUse, inUse)); + /* Check that the sequence number is valid. - * Ten million is legal, but is very unlikely + * Ten million is legal, but is very unlikely */ - if(dev->isYaffs2 && + if (dev->isYaffs2 && (bi->blockState == YAFFS_BLOCK_STATE_ALLOCATING || bi->blockState == YAFFS_BLOCK_STATE_FULL) && - (bi->sequenceNumber < YAFFS_LOWEST_SEQUENCE_NUMBER || bi->sequenceNumber > 10000000 )) - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has suspect sequence number of %d"TENDSTR), - n,bi->sequenceNumber)); - + (bi->sequenceNumber < YAFFS_LOWEST_SEQUENCE_NUMBER || bi->sequenceNumber > 10000000)) + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has suspect sequence number of %d"TENDSTR), + n, bi->sequenceNumber)); } -static void yaffs_VerifyCollectedBlock(yaffs_Device *dev,yaffs_BlockInfo *bi,int n) +static void yaffs_VerifyCollectedBlock(yaffs_Device *dev, yaffs_BlockInfo *bi, + int n) { - yaffs_VerifyBlock(dev,bi,n); - + yaffs_VerifyBlock(dev, bi, n); + /* After collection the block should be in the erased state */ /* This will need to change if we do partial gc */ - - if(bi->blockState != YAFFS_BLOCK_STATE_COLLECTING && - bi->blockState != YAFFS_BLOCK_STATE_EMPTY){ - T(YAFFS_TRACE_ERROR,(TSTR("Block %d is in state %d after gc, should be erased"TENDSTR), - n,bi->blockState)); + + if (bi->blockState != YAFFS_BLOCK_STATE_COLLECTING && + bi->blockState != YAFFS_BLOCK_STATE_EMPTY) { + T(YAFFS_TRACE_ERROR, (TSTR("Block %d is in state %d after gc, should be erased"TENDSTR), + n, bi->blockState)); } } @@ -490,53 +492,50 @@ static void yaffs_VerifyBlocks(yaffs_Device *dev) int i; int nBlocksPerState[YAFFS_NUMBER_OF_BLOCK_STATES]; int nIllegalBlockStates = 0; - - if(yaffs_SkipVerification(dev)) + if (yaffs_SkipVerification(dev)) return; - memset(nBlocksPerState,0,sizeof(nBlocksPerState)); + memset(nBlocksPerState, 0, sizeof(nBlocksPerState)); - - for(i = dev->internalStartBlock; i <= dev->internalEndBlock; i++){ - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,i); - yaffs_VerifyBlock(dev,bi,i); + for (i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) { + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i); + yaffs_VerifyBlock(dev, bi, i); - if(bi->blockState < YAFFS_NUMBER_OF_BLOCK_STATES) + if (bi->blockState < YAFFS_NUMBER_OF_BLOCK_STATES) nBlocksPerState[bi->blockState]++; else nIllegalBlockStates++; - } - - T(YAFFS_TRACE_VERIFY,(TSTR(""TENDSTR))); - T(YAFFS_TRACE_VERIFY,(TSTR("Block summary"TENDSTR))); - - T(YAFFS_TRACE_VERIFY,(TSTR("%d blocks have illegal states"TENDSTR),nIllegalBlockStates)); - if(nBlocksPerState[YAFFS_BLOCK_STATE_ALLOCATING] > 1) - T(YAFFS_TRACE_VERIFY,(TSTR("Too many allocating blocks"TENDSTR))); - for(i = 0; i < YAFFS_NUMBER_OF_BLOCK_STATES; i++) + T(YAFFS_TRACE_VERIFY, (TSTR(""TENDSTR))); + T(YAFFS_TRACE_VERIFY, (TSTR("Block summary"TENDSTR))); + + T(YAFFS_TRACE_VERIFY, (TSTR("%d blocks have illegal states"TENDSTR), nIllegalBlockStates)); + if (nBlocksPerState[YAFFS_BLOCK_STATE_ALLOCATING] > 1) + T(YAFFS_TRACE_VERIFY, (TSTR("Too many allocating blocks"TENDSTR))); + + for (i = 0; i < YAFFS_NUMBER_OF_BLOCK_STATES; i++) T(YAFFS_TRACE_VERIFY, (TSTR("%s %d blocks"TENDSTR), - blockStateName[i],nBlocksPerState[i])); - - if(dev->blocksInCheckpoint != nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT]) + blockStateName[i], nBlocksPerState[i])); + + if (dev->blocksInCheckpoint != nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT]) T(YAFFS_TRACE_VERIFY, (TSTR("Checkpoint block count wrong dev %d count %d"TENDSTR), dev->blocksInCheckpoint, nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT])); - - if(dev->nErasedBlocks != nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY]) + + if (dev->nErasedBlocks != nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY]) T(YAFFS_TRACE_VERIFY, (TSTR("Erased block count wrong dev %d count %d"TENDSTR), dev->nErasedBlocks, nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY])); - - if(nBlocksPerState[YAFFS_BLOCK_STATE_COLLECTING] > 1) + + if (nBlocksPerState[YAFFS_BLOCK_STATE_COLLECTING] > 1) T(YAFFS_TRACE_VERIFY, (TSTR("Too many collecting blocks %d (max is 1)"TENDSTR), nBlocksPerState[YAFFS_BLOCK_STATE_COLLECTING])); - T(YAFFS_TRACE_VERIFY,(TSTR(""TENDSTR))); + T(YAFFS_TRACE_VERIFY, (TSTR(""TENDSTR))); } @@ -546,64 +545,62 @@ static void yaffs_VerifyBlocks(yaffs_Device *dev) */ static void yaffs_VerifyObjectHeader(yaffs_Object *obj, yaffs_ObjectHeader *oh, yaffs_ExtendedTags *tags, int parentCheck) { - if(obj && yaffs_SkipVerification(obj->myDev)) + if (obj && yaffs_SkipVerification(obj->myDev)) return; - - if(!(tags && obj && oh)){ - T(YAFFS_TRACE_VERIFY, - (TSTR("Verifying object header tags %x obj %x oh %x"TENDSTR), - (__u32)tags,(__u32)obj,(__u32)oh)); + + if (!(tags && obj && oh)) { + T(YAFFS_TRACE_VERIFY, + (TSTR("Verifying object header tags %x obj %x oh %x"TENDSTR), + (__u32)tags, (__u32)obj, (__u32)oh)); return; } - - if(oh->type <= YAFFS_OBJECT_TYPE_UNKNOWN || - oh->type > YAFFS_OBJECT_TYPE_MAX) - T(YAFFS_TRACE_VERIFY, - (TSTR("Obj %d header type is illegal value 0x%x"TENDSTR), - tags->objectId, oh->type)); - if(tags->objectId != obj->objectId) - T(YAFFS_TRACE_VERIFY, - (TSTR("Obj %d header mismatch objectId %d"TENDSTR), - tags->objectId, obj->objectId)); + if (oh->type <= YAFFS_OBJECT_TYPE_UNKNOWN || + oh->type > YAFFS_OBJECT_TYPE_MAX) + T(YAFFS_TRACE_VERIFY, + (TSTR("Obj %d header type is illegal value 0x%x"TENDSTR), + tags->objectId, oh->type)); + + if (tags->objectId != obj->objectId) + T(YAFFS_TRACE_VERIFY, + (TSTR("Obj %d header mismatch objectId %d"TENDSTR), + tags->objectId, obj->objectId)); /* * Check that the object's parent ids match if parentCheck requested. - * + * * Tests do not apply to the root object. */ - - if(parentCheck && tags->objectId > 1 && !obj->parent) - T(YAFFS_TRACE_VERIFY, - (TSTR("Obj %d header mismatch parentId %d obj->parent is NULL"TENDSTR), - tags->objectId, oh->parentObjectId)); - - - if(parentCheck && obj->parent && - oh->parentObjectId != obj->parent->objectId && - (oh->parentObjectId != YAFFS_OBJECTID_UNLINKED || - obj->parent->objectId != YAFFS_OBJECTID_DELETED)) - T(YAFFS_TRACE_VERIFY, - (TSTR("Obj %d header mismatch parentId %d parentObjectId %d"TENDSTR), - tags->objectId, oh->parentObjectId, obj->parent->objectId)); - - - if(tags->objectId > 1 && oh->name[0] == 0) /* Null name */ + + if (parentCheck && tags->objectId > 1 && !obj->parent) + T(YAFFS_TRACE_VERIFY, + (TSTR("Obj %d header mismatch parentId %d obj->parent is NULL"TENDSTR), + tags->objectId, oh->parentObjectId)); + + if (parentCheck && obj->parent && + oh->parentObjectId != obj->parent->objectId && + (oh->parentObjectId != YAFFS_OBJECTID_UNLINKED || + obj->parent->objectId != YAFFS_OBJECTID_DELETED)) + T(YAFFS_TRACE_VERIFY, + (TSTR("Obj %d header mismatch parentId %d parentObjectId %d"TENDSTR), + tags->objectId, oh->parentObjectId, obj->parent->objectId)); + + if (tags->objectId > 1 && oh->name[0] == 0) /* Null name */ T(YAFFS_TRACE_VERIFY, - (TSTR("Obj %d header name is NULL"TENDSTR), - obj->objectId)); + (TSTR("Obj %d header name is NULL"TENDSTR), + obj->objectId)); - if(tags->objectId > 1 && ((__u8)(oh->name[0])) == 0xff) /* Trashed name */ + if (tags->objectId > 1 && ((__u8)(oh->name[0])) == 0xff) /* Trashed name */ T(YAFFS_TRACE_VERIFY, - (TSTR("Obj %d header name is 0xFF"TENDSTR), - obj->objectId)); + (TSTR("Obj %d header name is 0xFF"TENDSTR), + obj->objectId)); } -static int yaffs_VerifyTnodeWorker(yaffs_Object * obj, yaffs_Tnode * tn, - __u32 level, int chunkOffset) +static int yaffs_VerifyTnodeWorker(yaffs_Object *obj, yaffs_Tnode *tn, + __u32 level, int chunkOffset) { int i; yaffs_Device *dev = obj->myDev; @@ -612,7 +609,7 @@ static int yaffs_VerifyTnodeWorker(yaffs_Object * obj, yaffs_Tnode * tn, if (tn) { if (level > 0) { - for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++){ + for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++) { if (tn->internal[i]) { ok = yaffs_VerifyTnodeWorker(obj, tn->internal[i], @@ -623,17 +620,17 @@ static int yaffs_VerifyTnodeWorker(yaffs_Object * obj, yaffs_Tnode * tn, } else if (level == 0) { yaffs_ExtendedTags tags; __u32 objectId = obj->objectId; - + chunkOffset <<= YAFFS_TNODES_LEVEL0_BITS; - - for(i = 0; i < YAFFS_NTNODES_LEVEL0; i++){ - __u32 theChunk = yaffs_GetChunkGroupBase(dev,tn,i); - - if(theChunk > 0){ + + for (i = 0; i < YAFFS_NTNODES_LEVEL0; i++) { + __u32 theChunk = yaffs_GetChunkGroupBase(dev, tn, i); + + if (theChunk > 0) { /* T(~0,(TSTR("verifying (%d:%d) %d"TENDSTR),tags.objectId,tags.chunkId,theChunk)); */ - yaffs_ReadChunkWithTagsFromNAND(dev,theChunk,NULL, &tags); - if(tags.objectId != objectId || tags.chunkId != chunkOffset){ - T(~0,(TSTR("Object %d chunkId %d NAND mismatch chunk %d tags (%d:%d)"TENDSTR), + yaffs_ReadChunkWithTagsFromNAND(dev, theChunk, NULL, &tags); + if (tags.objectId != objectId || tags.chunkId != chunkOffset) { + T(~0, (TSTR("Object %d chunkId %d NAND mismatch chunk %d tags (%d:%d)"TENDSTR), objectId, chunkOffset, theChunk, tags.objectId, tags.chunkId)); } @@ -659,107 +656,105 @@ static void yaffs_VerifyFile(yaffs_Object *obj) yaffs_ExtendedTags tags; yaffs_Tnode *tn; __u32 objectId; - - if(!obj) + + if (!obj) return; - if(yaffs_SkipVerification(obj->myDev)) + if (yaffs_SkipVerification(obj->myDev)) return; - + dev = obj->myDev; objectId = obj->objectId; - + /* Check file size is consistent with tnode depth */ lastChunk = obj->variant.fileVariant.fileSize / dev->nDataBytesPerChunk + 1; x = lastChunk >> YAFFS_TNODES_LEVEL0_BITS; requiredTallness = 0; - while (x> 0) { + while (x > 0) { x >>= YAFFS_TNODES_INTERNAL_BITS; requiredTallness++; } - + actualTallness = obj->variant.fileVariant.topLevel; - - if(requiredTallness > actualTallness ) + + if (requiredTallness > actualTallness) T(YAFFS_TRACE_VERIFY, (TSTR("Obj %d had tnode tallness %d, needs to be %d"TENDSTR), - obj->objectId,actualTallness, requiredTallness)); - - - /* Check that the chunks in the tnode tree are all correct. + obj->objectId, actualTallness, requiredTallness)); + + + /* Check that the chunks in the tnode tree are all correct. * We do this by scanning through the tnode tree and * checking the tags for every chunk match. */ - if(yaffs_SkipNANDVerification(dev)) + if (yaffs_SkipNANDVerification(dev)) return; - - for(i = 1; i <= lastChunk; i++){ - tn = yaffs_FindLevel0Tnode(dev, &obj->variant.fileVariant,i); + + for (i = 1; i <= lastChunk; i++) { + tn = yaffs_FindLevel0Tnode(dev, &obj->variant.fileVariant, i); if (tn) { - __u32 theChunk = yaffs_GetChunkGroupBase(dev,tn,i); - if(theChunk > 0){ + __u32 theChunk = yaffs_GetChunkGroupBase(dev, tn, i); + if (theChunk > 0) { /* T(~0,(TSTR("verifying (%d:%d) %d"TENDSTR),objectId,i,theChunk)); */ - yaffs_ReadChunkWithTagsFromNAND(dev,theChunk,NULL, &tags); - if(tags.objectId != objectId || tags.chunkId != i){ - T(~0,(TSTR("Object %d chunkId %d NAND mismatch chunk %d tags (%d:%d)"TENDSTR), + yaffs_ReadChunkWithTagsFromNAND(dev, theChunk, NULL, &tags); + if (tags.objectId != objectId || tags.chunkId != i) { + T(~0, (TSTR("Object %d chunkId %d NAND mismatch chunk %d tags (%d:%d)"TENDSTR), objectId, i, theChunk, tags.objectId, tags.chunkId)); } } } - } - } static void yaffs_VerifyHardLink(yaffs_Object *obj) { - if(obj && yaffs_SkipVerification(obj->myDev)) + if (obj && yaffs_SkipVerification(obj->myDev)) return; - + /* Verify sane equivalent object */ } static void yaffs_VerifySymlink(yaffs_Object *obj) { - if(obj && yaffs_SkipVerification(obj->myDev)) + if (obj && yaffs_SkipVerification(obj->myDev)) return; - + /* Verify symlink string */ } static void yaffs_VerifySpecial(yaffs_Object *obj) { - if(obj && yaffs_SkipVerification(obj->myDev)) + if (obj && yaffs_SkipVerification(obj->myDev)) return; } static void yaffs_VerifyObject(yaffs_Object *obj) { yaffs_Device *dev; - + __u32 chunkMin; __u32 chunkMax; - + __u32 chunkIdOk; __u32 chunkInRange; __u32 chunkShouldNotBeDeleted; - __u32 chunkValid; - - if(!obj) + __u32 chunkValid; + + if (!obj) return; - - if(obj->beingCreated) + + if (obj->beingCreated) return; - + dev = obj->myDev; - - if(yaffs_SkipVerification(dev)) + + if (yaffs_SkipVerification(dev)) return; - + /* Check sane object header chunk */ chunkMin = dev->internalStartBlock * dev->nChunksPerBlock; @@ -767,51 +762,52 @@ static void yaffs_VerifyObject(yaffs_Object *obj) chunkInRange = (((unsigned)(obj->hdrChunk)) >= chunkMin && ((unsigned)(obj->hdrChunk)) <= chunkMax); chunkIdOk = chunkInRange || obj->hdrChunk == 0; - chunkValid = chunkInRange && + chunkValid = chunkInRange && yaffs_CheckChunkBit(dev, - obj->hdrChunk / dev->nChunksPerBlock, - obj->hdrChunk % dev->nChunksPerBlock); + obj->hdrChunk / dev->nChunksPerBlock, + obj->hdrChunk % dev->nChunksPerBlock); chunkShouldNotBeDeleted = chunkInRange && !chunkValid; - if(!obj->fake && - (!chunkIdOk || chunkShouldNotBeDeleted)) { - T(YAFFS_TRACE_VERIFY, - (TSTR("Obj %d has chunkId %d %s %s"TENDSTR), - obj->objectId,obj->hdrChunk, - chunkIdOk ? "" : ",out of range", - chunkShouldNotBeDeleted ? ",marked as deleted" : "")); + if (!obj->fake && + (!chunkIdOk || chunkShouldNotBeDeleted)) { + T(YAFFS_TRACE_VERIFY, + (TSTR("Obj %d has chunkId %d %s %s"TENDSTR), + obj->objectId, obj->hdrChunk, + chunkIdOk ? "" : ",out of range", + chunkShouldNotBeDeleted ? ",marked as deleted" : "")); } - - if(chunkValid &&!yaffs_SkipNANDVerification(dev)) { + + if (chunkValid && !yaffs_SkipNANDVerification(dev)) { yaffs_ExtendedTags tags; yaffs_ObjectHeader *oh; - __u8 *buffer = yaffs_GetTempBuffer(dev,__LINE__); - + __u8 *buffer = yaffs_GetTempBuffer(dev, __LINE__); + oh = (yaffs_ObjectHeader *)buffer; - yaffs_ReadChunkWithTagsFromNAND(dev, obj->hdrChunk,buffer, &tags); + yaffs_ReadChunkWithTagsFromNAND(dev, obj->hdrChunk, buffer, + &tags); + + yaffs_VerifyObjectHeader(obj, oh, &tags, 1); - yaffs_VerifyObjectHeader(obj,oh,&tags,1); - - yaffs_ReleaseTempBuffer(dev,buffer,__LINE__); + yaffs_ReleaseTempBuffer(dev, buffer, __LINE__); } - + /* Verify it has a parent */ - if(obj && !obj->fake && - (!obj->parent || obj->parent->myDev != dev)){ - T(YAFFS_TRACE_VERIFY, - (TSTR("Obj %d has parent pointer %p which does not look like an object"TENDSTR), - obj->objectId,obj->parent)); + if (obj && !obj->fake && + (!obj->parent || obj->parent->myDev != dev)) { + T(YAFFS_TRACE_VERIFY, + (TSTR("Obj %d has parent pointer %p which does not look like an object"TENDSTR), + obj->objectId, obj->parent)); } - + /* Verify parent is a directory */ - if(obj->parent && obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY){ - T(YAFFS_TRACE_VERIFY, - (TSTR("Obj %d's parent is not a directory (type %d)"TENDSTR), - obj->objectId,obj->parent->variantType)); + if (obj->parent && obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) { + T(YAFFS_TRACE_VERIFY, + (TSTR("Obj %d's parent is not a directory (type %d)"TENDSTR), + obj->objectId, obj->parent->variantType)); } - - switch(obj->variantType){ + + switch (obj->variantType) { case YAFFS_OBJECT_TYPE_FILE: yaffs_VerifyFile(obj); break; @@ -831,57 +827,54 @@ static void yaffs_VerifyObject(yaffs_Object *obj) default: T(YAFFS_TRACE_VERIFY, (TSTR("Obj %d has illegaltype %d"TENDSTR), - obj->objectId,obj->variantType)); + obj->objectId, obj->variantType)); break; } - - } static void yaffs_VerifyObjects(yaffs_Device *dev) { - yaffs_Object *obj; - int i; - struct ylist_head *lh; + yaffs_Object *obj; + int i; + struct ylist_head *lh; - if(yaffs_SkipVerification(dev)) - return; - - /* Iterate through the objects in each hash entry */ - - for(i = 0; i < YAFFS_NOBJECT_BUCKETS; i++){ - ylist_for_each(lh, &dev->objectBucket[i].list) { - if (lh) { - obj = ylist_entry(lh, yaffs_Object, hashLink); - yaffs_VerifyObject(obj); - } - } - } + if (yaffs_SkipVerification(dev)) + return; + + /* Iterate through the objects in each hash entry */ + for (i = 0; i < YAFFS_NOBJECT_BUCKETS; i++) { + ylist_for_each(lh, &dev->objectBucket[i].list) { + if (lh) { + obj = ylist_entry(lh, yaffs_Object, hashLink); + yaffs_VerifyObject(obj); + } + } + } } /* * Simple hash function. Needs to have a reasonable spread */ - + static Y_INLINE int yaffs_HashFunction(int n) { n = abs(n); - return (n % YAFFS_NOBJECT_BUCKETS); + return n % YAFFS_NOBJECT_BUCKETS; } /* * Access functions to useful fake objects. * Note that root might have a presence in NAND if permissions are set. */ - -yaffs_Object *yaffs_Root(yaffs_Device * dev) + +yaffs_Object *yaffs_Root(yaffs_Device *dev) { return dev->rootDir; } -yaffs_Object *yaffs_LostNFound(yaffs_Device * dev) +yaffs_Object *yaffs_LostNFound(yaffs_Device *dev) { return dev->lostNFoundDir; } @@ -890,8 +883,8 @@ yaffs_Object *yaffs_LostNFound(yaffs_Device * dev) /* * Erased NAND checking functions */ - -int yaffs_CheckFF(__u8 * buffer, int nBytes) + +int yaffs_CheckFF(__u8 *buffer, int nBytes) { /* Horrible, slow implementation */ while (nBytes--) { @@ -903,19 +896,17 @@ int yaffs_CheckFF(__u8 * buffer, int nBytes) } static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, - int chunkInNAND) + int chunkInNAND) { - int retval = YAFFS_OK; __u8 *data = yaffs_GetTempBuffer(dev, __LINE__); yaffs_ExtendedTags tags; int result; result = yaffs_ReadChunkWithTagsFromNAND(dev, chunkInNAND, data, &tags); - - if(tags.eccResult > YAFFS_ECC_RESULT_NO_ERROR) + + if (tags.eccResult > YAFFS_ECC_RESULT_NO_ERROR) retval = YAFFS_FAIL; - if (!yaffs_CheckFF(data, dev->nDataBytesPerChunk) || tags.chunkUsed) { T(YAFFS_TRACE_NANDACCESS, @@ -930,9 +921,9 @@ static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, } static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, - const __u8 * data, - yaffs_ExtendedTags * tags, - int useReserve) + const __u8 *data, + yaffs_ExtendedTags *tags, + int useReserve) { int attempts = 0; int writeOk = 0; @@ -1005,10 +996,10 @@ static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, /* Copy the data into the robustification buffer */ yaffs_HandleWriteChunkOk(dev, chunk, data, tags); - } while (writeOk != YAFFS_OK && - (yaffs_wr_attempts <= 0 || attempts <= yaffs_wr_attempts)); - - if(!writeOk) + } while (writeOk != YAFFS_OK && + (yaffs_wr_attempts <= 0 || attempts <= yaffs_wr_attempts)); + + if (!writeOk) chunk = -1; if (attempts > 1) { @@ -1025,20 +1016,19 @@ static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, /* * Block retiring for handling a broken block. */ - -static void yaffs_RetireBlock(yaffs_Device * dev, int blockInNAND) + +static void yaffs_RetireBlock(yaffs_Device *dev, int blockInNAND) { yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockInNAND); yaffs_InvalidateCheckpoint(dev); - + if (yaffs_MarkBlockBad(dev, blockInNAND) != YAFFS_OK) { if (yaffs_EraseBlockInNAND(dev, blockInNAND) != YAFFS_OK) { T(YAFFS_TRACE_ALWAYS, (TSTR( "yaffs: Failed to mark bad and erase block %d" TENDSTR), blockInNAND)); - } - else { + } else { yaffs_ExtendedTags tags; int chunkId = blockInNAND * dev->nChunksPerBlock; @@ -1048,7 +1038,7 @@ static void yaffs_RetireBlock(yaffs_Device * dev, int blockInNAND) yaffs_InitialiseTags(&tags); tags.sequenceNumber = YAFFS_SEQUENCE_BAD_BLOCK; if (dev->writeChunkWithTagsToNAND(dev, chunkId - - dev->chunkOffset, buffer, &tags) != YAFFS_OK) + dev->chunkOffset, buffer, &tags) != YAFFS_OK) T(YAFFS_TRACE_ALWAYS, (TSTR("yaffs: Failed to " TCONT("write bad block marker to block %d") TENDSTR), blockInNAND)); @@ -1068,60 +1058,56 @@ static void yaffs_RetireBlock(yaffs_Device * dev, int blockInNAND) * Functions for robustisizing TODO * */ - -static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND, - const __u8 * data, - const yaffs_ExtendedTags * tags) + +static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND, + const __u8 *data, + const yaffs_ExtendedTags *tags) { } -static void yaffs_HandleUpdateChunk(yaffs_Device * dev, int chunkInNAND, - const yaffs_ExtendedTags * tags) +static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND, + const yaffs_ExtendedTags *tags) { } void yaffs_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi) { - if(!bi->gcPrioritise){ + if (!bi->gcPrioritise) { bi->gcPrioritise = 1; dev->hasPendingPrioritisedGCs = 1; - bi->chunkErrorStrikes ++; - - if(bi->chunkErrorStrikes > 3){ + bi->chunkErrorStrikes++; + + if (bi->chunkErrorStrikes > 3) { bi->needsRetiring = 1; /* Too many stikes, so retire this */ T(YAFFS_TRACE_ALWAYS, (TSTR("yaffs: Block struck out" TENDSTR))); } - } } -static void yaffs_HandleWriteChunkError(yaffs_Device * dev, int chunkInNAND, int erasedOk) +static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND, + int erasedOk) { - int blockInNAND = chunkInNAND / dev->nChunksPerBlock; yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockInNAND); - yaffs_HandleChunkError(dev,bi); - - - if(erasedOk ) { + yaffs_HandleChunkError(dev, bi); + + if (erasedOk) { /* Was an actual write failure, so mark the block for retirement */ bi->needsRetiring = 1; T(YAFFS_TRACE_ERROR | YAFFS_TRACE_BAD_BLOCKS, (TSTR("**>> Block %d needs retiring" TENDSTR), blockInNAND)); - - } - + /* Delete the chunk */ yaffs_DeleteChunk(dev, chunkInNAND, 1, __LINE__); } -/*---------------- Name handling functions ------------*/ +/*---------------- Name handling functions ------------*/ -static __u16 yaffs_CalcNameSum(const YCHAR * name) +static __u16 yaffs_CalcNameSum(const YCHAR *name) { __u16 sum = 0; __u16 i = 1; @@ -1142,10 +1128,10 @@ static __u16 yaffs_CalcNameSum(const YCHAR * name) return sum; } -static void yaffs_SetObjectName(yaffs_Object * obj, const YCHAR * name) +static void yaffs_SetObjectName(yaffs_Object *obj, const YCHAR *name) { #ifdef CONFIG_YAFFS_SHORT_NAMES_IN_RAM - memset(obj->shortName,0,sizeof (YCHAR) * (YAFFS_SHORT_NAME_LENGTH+1)); + memset(obj->shortName, 0, sizeof (YCHAR) * (YAFFS_SHORT_NAME_LENGTH+1)); if (name && yaffs_strlen(name) <= YAFFS_SHORT_NAME_LENGTH) { yaffs_strcpy(obj->shortName, name); } else { @@ -1161,13 +1147,13 @@ static void yaffs_SetObjectName(yaffs_Object * obj, const YCHAR * name) * The list is hooked together using the first pointer * in the tnode. */ - + /* yaffs_CreateTnodes creates a bunch more tnodes and * adds them to the tnode free list. * Don't use this function directly */ -static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes) +static int yaffs_CreateTnodes(yaffs_Device *dev, int nTnodes) { int i; int tnodeSize; @@ -1179,14 +1165,13 @@ static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes) if (nTnodes < 1) return YAFFS_OK; - + /* Calculate the tnode size in bytes for variable width tnode support. * Must be a multiple of 32-bits */ tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; - if(tnodeSize < sizeof(yaffs_Tnode)) + if (tnodeSize < sizeof(yaffs_Tnode)) tnodeSize = sizeof(yaffs_Tnode); - /* make these things */ @@ -1195,7 +1180,7 @@ static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes) if (!newTnodes) { T(YAFFS_TRACE_ERROR, - (TSTR("yaffs: Could not allocate Tnodes" TENDSTR))); + (TSTR("yaffs: Could not allocate Tnodes" TENDSTR))); return YAFFS_FAIL; } @@ -1215,12 +1200,12 @@ static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes) dev->freeTnodes = newTnodes; #else /* New hookup for wide tnodes */ - for(i = 0; i < nTnodes -1; i++) { + for (i = 0; i < nTnodes - 1; i++) { curr = (yaffs_Tnode *) &mem[i * tnodeSize]; next = (yaffs_Tnode *) &mem[(i+1) * tnodeSize]; curr->internal[0] = next; } - + curr = (yaffs_Tnode *) &mem[(nTnodes - 1) * tnodeSize]; curr->internal[0] = dev->freeTnodes; dev->freeTnodes = (yaffs_Tnode *)mem; @@ -1235,14 +1220,13 @@ static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes) * NB If we can't add this to the management list it isn't fatal * but it just means we can't free this bunch of tnodes later. */ - + tnl = YMALLOC(sizeof(yaffs_TnodeList)); if (!tnl) { T(YAFFS_TRACE_ERROR, (TSTR ("yaffs: Could not add tnodes to management list" TENDSTR))); return YAFFS_FAIL; - } else { tnl->tnodes = newTnodes; tnl->next = dev->allocatedTnodeList; @@ -1256,7 +1240,7 @@ static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes) /* GetTnode gets us a clean tnode. Tries to make allocate more if we run out */ -static yaffs_Tnode *yaffs_GetTnodeRaw(yaffs_Device * dev) +static yaffs_Tnode *yaffs_GetTnodeRaw(yaffs_Device *dev) { yaffs_Tnode *tn = NULL; @@ -1283,22 +1267,22 @@ static yaffs_Tnode *yaffs_GetTnodeRaw(yaffs_Device * dev) return tn; } -static yaffs_Tnode *yaffs_GetTnode(yaffs_Device * dev) +static yaffs_Tnode *yaffs_GetTnode(yaffs_Device *dev) { yaffs_Tnode *tn = yaffs_GetTnodeRaw(dev); int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; - if(tnodeSize < sizeof(yaffs_Tnode)) + if (tnodeSize < sizeof(yaffs_Tnode)) tnodeSize = sizeof(yaffs_Tnode); - - if(tn) + + if (tn) memset(tn, 0, tnodeSize); - return tn; + return tn; } /* FreeTnode frees up a tnode and puts it back on the free list */ -static void yaffs_FreeTnode(yaffs_Device * dev, yaffs_Tnode * tn) +static void yaffs_FreeTnode(yaffs_Device *dev, yaffs_Tnode *tn) { if (tn) { #ifdef CONFIG_YAFFS_TNODE_LIST_DEBUG @@ -1314,10 +1298,9 @@ static void yaffs_FreeTnode(yaffs_Device * dev, yaffs_Tnode * tn) dev->nFreeTnodes++; } dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ - } -static void yaffs_DeinitialiseTnodes(yaffs_Device * dev) +static void yaffs_DeinitialiseTnodes(yaffs_Device *dev) { /* Free the list of allocated tnodes */ yaffs_TnodeList *tmp; @@ -1335,71 +1318,72 @@ static void yaffs_DeinitialiseTnodes(yaffs_Device * dev) dev->nFreeTnodes = 0; } -static void yaffs_InitialiseTnodes(yaffs_Device * dev) +static void yaffs_InitialiseTnodes(yaffs_Device *dev) { dev->allocatedTnodeList = NULL; dev->freeTnodes = NULL; dev->nFreeTnodes = 0; dev->nTnodesCreated = 0; +} + + +void yaffs_PutLevel0Tnode(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos, + unsigned val) +{ + __u32 *map = (__u32 *)tn; + __u32 bitInMap; + __u32 bitInWord; + __u32 wordInMap; + __u32 mask; + + pos &= YAFFS_TNODES_LEVEL0_MASK; + val >>= dev->chunkGroupBits; + + bitInMap = pos * dev->tnodeWidth; + wordInMap = bitInMap / 32; + bitInWord = bitInMap & (32 - 1); + mask = dev->tnodeMask << bitInWord; + + map[wordInMap] &= ~mask; + map[wordInMap] |= (mask & (val << bitInWord)); + + if (dev->tnodeWidth > (32 - bitInWord)) { + bitInWord = (32 - bitInWord); + wordInMap++;; + mask = dev->tnodeMask >> (/*dev->tnodeWidth -*/ bitInWord); + map[wordInMap] &= ~mask; + map[wordInMap] |= (mask & (val >> bitInWord)); + } } +static __u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn, + unsigned pos) +{ + __u32 *map = (__u32 *)tn; + __u32 bitInMap; + __u32 bitInWord; + __u32 wordInMap; + __u32 val; + + pos &= YAFFS_TNODES_LEVEL0_MASK; + + bitInMap = pos * dev->tnodeWidth; + wordInMap = bitInMap / 32; + bitInWord = bitInMap & (32 - 1); -void yaffs_PutLevel0Tnode(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos, unsigned val) -{ - __u32 *map = (__u32 *)tn; - __u32 bitInMap; - __u32 bitInWord; - __u32 wordInMap; - __u32 mask; - - pos &= YAFFS_TNODES_LEVEL0_MASK; - val >>= dev->chunkGroupBits; - - bitInMap = pos * dev->tnodeWidth; - wordInMap = bitInMap /32; - bitInWord = bitInMap & (32 -1); - - mask = dev->tnodeMask << bitInWord; - - map[wordInMap] &= ~mask; - map[wordInMap] |= (mask & (val << bitInWord)); - - if(dev->tnodeWidth > (32-bitInWord)) { - bitInWord = (32 - bitInWord); - wordInMap++;; - mask = dev->tnodeMask >> (/*dev->tnodeWidth -*/ bitInWord); - map[wordInMap] &= ~mask; - map[wordInMap] |= (mask & (val >> bitInWord)); - } -} - -static __u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos) -{ - __u32 *map = (__u32 *)tn; - __u32 bitInMap; - __u32 bitInWord; - __u32 wordInMap; - __u32 val; - - pos &= YAFFS_TNODES_LEVEL0_MASK; - - bitInMap = pos * dev->tnodeWidth; - wordInMap = bitInMap /32; - bitInWord = bitInMap & (32 -1); - - val = map[wordInMap] >> bitInWord; - - if(dev->tnodeWidth > (32-bitInWord)) { - bitInWord = (32 - bitInWord); - wordInMap++;; - val |= (map[wordInMap] << bitInWord); - } - - val &= dev->tnodeMask; - val <<= dev->chunkGroupBits; - - return val; + val = map[wordInMap] >> bitInWord; + + if (dev->tnodeWidth > (32 - bitInWord)) { + bitInWord = (32 - bitInWord); + wordInMap++;; + val |= (map[wordInMap] << bitInWord); + } + + val &= dev->tnodeMask; + val <<= dev->chunkGroupBits; + + return val; } /* ------------------- End of individual tnode manipulation -----------------*/ @@ -1410,11 +1394,10 @@ static __u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn, unsigne */ /* FindLevel0Tnode finds the level 0 tnode, if one exists. */ -static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device * dev, - yaffs_FileStructure * fStruct, - __u32 chunkId) +static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device *dev, + yaffs_FileStructure *fStruct, + __u32 chunkId) { - yaffs_Tnode *tn = fStruct->top; __u32 i; int requiredTallness; @@ -1445,15 +1428,12 @@ static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device * dev, /* Traverse down to level 0 */ while (level > 0 && tn) { - tn = tn-> - internal[(chunkId >> - ( YAFFS_TNODES_LEVEL0_BITS + - (level - 1) * - YAFFS_TNODES_INTERNAL_BITS) - ) & - YAFFS_TNODES_INTERNAL_MASK]; + tn = tn->internal[(chunkId >> + (YAFFS_TNODES_LEVEL0_BITS + + (level - 1) * + YAFFS_TNODES_INTERNAL_BITS)) & + YAFFS_TNODES_INTERNAL_MASK]; level--; - } return tn; @@ -1469,13 +1449,12 @@ static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device * dev, * If the tn argument is NULL, then a fresh tnode will be added otherwise the specified tn will * be plugged into the ttree. */ - -static yaffs_Tnode *yaffs_AddOrFindLevel0Tnode(yaffs_Device * dev, - yaffs_FileStructure * fStruct, - __u32 chunkId, - yaffs_Tnode *passedTn) -{ +static yaffs_Tnode *yaffs_AddOrFindLevel0Tnode(yaffs_Device *dev, + yaffs_FileStructure *fStruct, + __u32 chunkId, + yaffs_Tnode *passedTn) +{ int requiredTallness; int i; int l; @@ -1504,9 +1483,9 @@ static yaffs_Tnode *yaffs_AddOrFindLevel0Tnode(yaffs_Device * dev, if (requiredTallness > fStruct->topLevel) { - /* Not tall enough,gotta make the tree taller */ + /* Not tall enough, gotta make the tree taller */ for (i = fStruct->topLevel; i < requiredTallness; i++) { - + tn = yaffs_GetTnode(dev); if (tn) { @@ -1525,63 +1504,61 @@ static yaffs_Tnode *yaffs_AddOrFindLevel0Tnode(yaffs_Device * dev, l = fStruct->topLevel; tn = fStruct->top; - - if(l > 0) { + + if (l > 0) { while (l > 0 && tn) { x = (chunkId >> - ( YAFFS_TNODES_LEVEL0_BITS + + (YAFFS_TNODES_LEVEL0_BITS + (l - 1) * YAFFS_TNODES_INTERNAL_BITS)) & YAFFS_TNODES_INTERNAL_MASK; - if((l>1) && !tn->internal[x]){ + if ((l > 1) && !tn->internal[x]) { /* Add missing non-level-zero tnode */ tn->internal[x] = yaffs_GetTnode(dev); - } else if(l == 1) { + } else if (l == 1) { /* Looking from level 1 at level 0 */ - if (passedTn) { + if (passedTn) { /* If we already have one, then release it.*/ - if(tn->internal[x]) - yaffs_FreeTnode(dev,tn->internal[x]); + if (tn->internal[x]) + yaffs_FreeTnode(dev, tn->internal[x]); tn->internal[x] = passedTn; - - } else if(!tn->internal[x]) { + + } else if (!tn->internal[x]) { /* Don't have one, none passed in */ tn->internal[x] = yaffs_GetTnode(dev); } } - + tn = tn->internal[x]; l--; } } else { /* top is level 0 */ - if(passedTn) { - memcpy(tn,passedTn,(dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8); - yaffs_FreeTnode(dev,passedTn); + if (passedTn) { + memcpy(tn, passedTn, (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8); + yaffs_FreeTnode(dev, passedTn); } } return tn; } -static int yaffs_FindChunkInGroup(yaffs_Device * dev, int theChunk, - yaffs_ExtendedTags * tags, int objectId, - int chunkInInode) +static int yaffs_FindChunkInGroup(yaffs_Device *dev, int theChunk, + yaffs_ExtendedTags *tags, int objectId, + int chunkInInode) { int j; for (j = 0; theChunk && j < dev->chunkGroupSize; j++) { - if (yaffs_CheckChunkBit - (dev, theChunk / dev->nChunksPerBlock, - theChunk % dev->nChunksPerBlock)) { + if (yaffs_CheckChunkBit(dev, theChunk / dev->nChunksPerBlock, + theChunk % dev->nChunksPerBlock)) { yaffs_ReadChunkWithTagsFromNAND(dev, theChunk, NULL, tags); if (yaffs_TagsMatch(tags, objectId, chunkInInode)) { /* found it; */ return theChunk; - } } theChunk++; @@ -1592,11 +1569,11 @@ static int yaffs_FindChunkInGroup(yaffs_Device * dev, int theChunk, /* DeleteWorker scans backwards through the tnode tree and deletes all the * chunks and tnodes in the file - * Returns 1 if the tree was deleted. + * Returns 1 if the tree was deleted. * Returns 0 if it stopped early due to hitting the limit and the delete is incomplete. */ -static int yaffs_DeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, __u32 level, +static int yaffs_DeleteWorker(yaffs_Object *in, yaffs_Tnode *tn, __u32 level, int chunkOffset, int *limit) { int i; @@ -1610,7 +1587,6 @@ static int yaffs_DeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, __u32 level, if (tn) { if (level > 0) { - for (i = YAFFS_NTNODES_INTERNAL - 1; allDone && i >= 0; i--) { if (tn->internal[i]) { @@ -1618,17 +1594,17 @@ static int yaffs_DeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, __u32 level, allDone = 0; } else { allDone = - yaffs_DeleteWorker(in, - tn-> - internal - [i], - level - - 1, - (chunkOffset + yaffs_DeleteWorker(in, + tn-> + internal + [i], + level - + 1, + (chunkOffset << YAFFS_TNODES_INTERNAL_BITS) - + i, - limit); + + i, + limit); } if (allDone) { yaffs_FreeTnode(dev, @@ -1637,27 +1613,25 @@ static int yaffs_DeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, __u32 level, tn->internal[i] = NULL; } } - } return (allDone) ? 1 : 0; } else if (level == 0) { int hitLimit = 0; for (i = YAFFS_NTNODES_LEVEL0 - 1; i >= 0 && !hitLimit; - i--) { - theChunk = yaffs_GetChunkGroupBase(dev,tn,i); + i--) { + theChunk = yaffs_GetChunkGroupBase(dev, tn, i); if (theChunk) { - chunkInInode = - (chunkOffset << - YAFFS_TNODES_LEVEL0_BITS) + i; + chunkInInode = (chunkOffset << + YAFFS_TNODES_LEVEL0_BITS) + i; foundChunk = - yaffs_FindChunkInGroup(dev, - theChunk, - &tags, - in->objectId, - chunkInInode); + yaffs_FindChunkInGroup(dev, + theChunk, + &tags, + in->objectId, + chunkInInode); if (foundChunk > 0) { yaffs_DeleteChunk(dev, @@ -1673,7 +1647,7 @@ static int yaffs_DeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, __u32 level, } - yaffs_PutLevel0Tnode(dev,tn,i,0); + yaffs_PutLevel0Tnode(dev, tn, i, 0); } } @@ -1687,9 +1661,8 @@ static int yaffs_DeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, __u32 level, } -static void yaffs_SoftDeleteChunk(yaffs_Device * dev, int chunk) +static void yaffs_SoftDeleteChunk(yaffs_Device *dev, int chunk) { - yaffs_BlockInfo *theBlock; T(YAFFS_TRACE_DELETION, (TSTR("soft delete chunk %d" TENDSTR), chunk)); @@ -1706,8 +1679,8 @@ static void yaffs_SoftDeleteChunk(yaffs_Device * dev, int chunk) * of the tnode. * Thus, essentially this is the same as DeleteWorker except that the chunks are soft deleted. */ - -static int yaffs_SoftDeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, + +static int yaffs_SoftDeleteWorker(yaffs_Object *in, yaffs_Tnode *tn, __u32 level, int chunkOffset) { int i; @@ -1744,14 +1717,14 @@ static int yaffs_SoftDeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, } else if (level == 0) { for (i = YAFFS_NTNODES_LEVEL0 - 1; i >= 0; i--) { - theChunk = yaffs_GetChunkGroupBase(dev,tn,i); + theChunk = yaffs_GetChunkGroupBase(dev, tn, i); if (theChunk) { /* Note this does not find the real chunk, only the chunk group. - * We make an assumption that a chunk group is not larger than + * We make an assumption that a chunk group is not larger than * a block. */ yaffs_SoftDeleteChunk(dev, theChunk); - yaffs_PutLevel0Tnode(dev,tn,i,0); + yaffs_PutLevel0Tnode(dev, tn, i, 0); } } @@ -1765,7 +1738,7 @@ static int yaffs_SoftDeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, } -static void yaffs_SoftDeleteFile(yaffs_Object * obj) +static void yaffs_SoftDeleteFile(yaffs_Object *obj) { if (obj->deleted && obj->variantType == YAFFS_OBJECT_TYPE_FILE && !obj->softDeleted) { @@ -1799,8 +1772,8 @@ static void yaffs_SoftDeleteFile(yaffs_Object * obj) * by a special case. */ -static yaffs_Tnode *yaffs_PruneWorker(yaffs_Device * dev, yaffs_Tnode * tn, - __u32 level, int del0) +static yaffs_Tnode *yaffs_PruneWorker(yaffs_Device *dev, yaffs_Tnode *tn, + __u32 level, int del0) { int i; int hasData; @@ -1834,8 +1807,8 @@ static yaffs_Tnode *yaffs_PruneWorker(yaffs_Device * dev, yaffs_Tnode * tn, } -static int yaffs_PruneFileStructure(yaffs_Device * dev, - yaffs_FileStructure * fStruct) +static int yaffs_PruneFileStructure(yaffs_Device *dev, + yaffs_FileStructure *fStruct) { int i; int hasData; @@ -1849,7 +1822,7 @@ static int yaffs_PruneFileStructure(yaffs_Device * dev, /* Now we have a tree with all the non-zero branches NULL but the height * is the same as it was. * Let's see if we can trim internal tnodes to shorten the tree. - * We can do this if only the 0th element in the tnode is in use + * We can do this if only the 0th element in the tnode is in use * (ie all the non-zero are NULL) */ @@ -1881,7 +1854,7 @@ static int yaffs_PruneFileStructure(yaffs_Device * dev, /* yaffs_CreateFreeObjects creates a bunch more objects and * adds them to the object free list. */ -static int yaffs_CreateFreeObjects(yaffs_Device * dev, int nObjects) +static int yaffs_CreateFreeObjects(yaffs_Device *dev, int nObjects) { int i; yaffs_Object *newObjects; @@ -1895,22 +1868,22 @@ static int yaffs_CreateFreeObjects(yaffs_Device * dev, int nObjects) list = YMALLOC(sizeof(yaffs_ObjectList)); if (!newObjects || !list) { - if(newObjects) + if (newObjects) YFREE(newObjects); - if(list) + if (list) YFREE(list); T(YAFFS_TRACE_ALLOCATE, (TSTR("yaffs: Could not allocate more objects" TENDSTR))); return YAFFS_FAIL; } - - /* Hook them into the free list */ - for (i = 0; i < nObjects - 1; i++) { - newObjects[i].siblings.next = - (struct ylist_head *)(&newObjects[i + 1]); - } - newObjects[nObjects - 1].siblings.next = (void *)dev->freeObjects; + /* Hook them into the free list */ + for (i = 0; i < nObjects - 1; i++) { + newObjects[i].siblings.next = + (struct ylist_head *)(&newObjects[i + 1]); + } + + newObjects[nObjects - 1].siblings.next = (void *)dev->freeObjects; dev->freeObjects = newObjects; dev->nFreeObjects += nObjects; dev->nObjectsCreated += nObjects; @@ -1926,7 +1899,7 @@ static int yaffs_CreateFreeObjects(yaffs_Device * dev, int nObjects) /* AllocateEmptyObject gets us a clean Object. Tries to make allocate more if we run out */ -static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device * dev) +static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device *dev) { yaffs_Object *tn = NULL; @@ -1941,47 +1914,47 @@ static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device * dev) if (dev->freeObjects) { tn = dev->freeObjects; dev->freeObjects = - (yaffs_Object *) (dev->freeObjects->siblings.next); + (yaffs_Object *) (dev->freeObjects->siblings.next); dev->nFreeObjects--; } #endif - if(tn){ + if (tn) { /* Now sweeten it up... */ memset(tn, 0, sizeof(yaffs_Object)); tn->beingCreated = 1; - + tn->myDev = dev; tn->hdrChunk = 0; tn->variantType = YAFFS_OBJECT_TYPE_UNKNOWN; YINIT_LIST_HEAD(&(tn->hardLinks)); YINIT_LIST_HEAD(&(tn->hashLink)); YINIT_LIST_HEAD(&tn->siblings); - + /* Now make the directory sane */ - if(dev->rootDir){ + if (dev->rootDir) { tn->parent = dev->rootDir; - ylist_add(&(tn->siblings),&dev->rootDir->variant.directoryVariant.children); + ylist_add(&(tn->siblings), &dev->rootDir->variant.directoryVariant.children); } - /* Add it to the lost and found directory. - * NB Can't put root or lostNFound in lostNFound so + /* Add it to the lost and found directory. + * NB Can't put root or lostNFound in lostNFound so * check if lostNFound exists first */ if (dev->lostNFoundDir) { yaffs_AddObjectToDirectory(dev->lostNFoundDir, tn); } - + tn->beingCreated = 0; } - + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ return tn; } -static yaffs_Object *yaffs_CreateFakeDirectory(yaffs_Device * dev, int number, +static yaffs_Object *yaffs_CreateFakeDirectory(yaffs_Device *dev, int number, __u32 mode) { @@ -2002,24 +1975,22 @@ static yaffs_Object *yaffs_CreateFakeDirectory(yaffs_Device * dev, int number, } -static void yaffs_UnhashObject(yaffs_Object * tn) +static void yaffs_UnhashObject(yaffs_Object *tn) { int bucket; - yaffs_Device *dev = tn->myDev; - - /* If it is still linked into the bucket list, free from the list */ - if (!ylist_empty(&tn->hashLink)) { - ylist_del_init(&tn->hashLink); - bucket = yaffs_HashFunction(tn->objectId); - dev->objectBucket[bucket].count--; - } + yaffs_Device *dev = tn->myDev; + /* If it is still linked into the bucket list, free from the list */ + if (!ylist_empty(&tn->hashLink)) { + ylist_del_init(&tn->hashLink); + bucket = yaffs_HashFunction(tn->objectId); + dev->objectBucket[bucket].count--; + } } /* FreeObject frees up a Object and puts it back on the free list */ -static void yaffs_FreeObject(yaffs_Object * tn) +static void yaffs_FreeObject(yaffs_Object *tn) { - yaffs_Device *dev = tn->myDev; #ifdef __KERNEL__ @@ -2028,11 +1999,11 @@ static void yaffs_FreeObject(yaffs_Object * tn) if(tn->parent) YBUG(); - if(!ylist_empty(&tn->siblings)) + if (!ylist_empty(&tn->siblings)) YBUG(); -#ifdef __KERNEL__ +#ifdef __KERNEL__ if (tn->myInode) { /* We're still hooked up to a cached inode. * Don't delete now, but mark for later deletion @@ -2042,23 +2013,22 @@ static void yaffs_FreeObject(yaffs_Object * tn) } #endif - yaffs_UnhashObject(tn); + yaffs_UnhashObject(tn); #ifdef VALGRIND_TEST YFREE(tn); #else - /* Link into the free list. */ - tn->siblings.next = (struct ylist_head *)(dev->freeObjects); - dev->freeObjects = tn; - dev->nFreeObjects++; + /* Link into the free list. */ + tn->siblings.next = (struct ylist_head *)(dev->freeObjects); + dev->freeObjects = tn; + dev->nFreeObjects++; #endif dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ - } #ifdef __KERNEL__ -void yaffs_HandleDeferedFree(yaffs_Object * obj) +void yaffs_HandleDeferedFree(yaffs_Object *obj) { if (obj->deferedFree) { yaffs_FreeObject(obj); @@ -2067,7 +2037,7 @@ void yaffs_HandleDeferedFree(yaffs_Object * obj) #endif -static void yaffs_DeinitialiseObjects(yaffs_Device * dev) +static void yaffs_DeinitialiseObjects(yaffs_Device *dev) { /* Free the list of allocated Objects */ @@ -2085,24 +2055,23 @@ static void yaffs_DeinitialiseObjects(yaffs_Device * dev) dev->nFreeObjects = 0; } -static void yaffs_InitialiseObjects(yaffs_Device * dev) +static void yaffs_InitialiseObjects(yaffs_Device *dev) { int i; dev->allocatedObjectList = NULL; dev->freeObjects = NULL; - dev->nFreeObjects = 0; - - for (i = 0; i < YAFFS_NOBJECT_BUCKETS; i++) { - YINIT_LIST_HEAD(&dev->objectBucket[i].list); - dev->objectBucket[i].count = 0; - } + dev->nFreeObjects = 0; + for (i = 0; i < YAFFS_NOBJECT_BUCKETS; i++) { + YINIT_LIST_HEAD(&dev->objectBucket[i].list); + dev->objectBucket[i].count = 0; + } } -static int yaffs_FindNiceObjectBucket(yaffs_Device * dev) +static int yaffs_FindNiceObjectBucket(yaffs_Device *dev) { - static int x = 0; + static int x; int i; int l = 999; int lowest = 999999; @@ -2136,63 +2105,60 @@ static int yaffs_FindNiceObjectBucket(yaffs_Device * dev) return l; } -static int yaffs_CreateNewObjectNumber(yaffs_Device * dev) +static int yaffs_CreateNewObjectNumber(yaffs_Device *dev) { int bucket = yaffs_FindNiceObjectBucket(dev); /* Now find an object value that has not already been taken * by scanning the list. - */ + */ - int found = 0; - struct ylist_head *i; + int found = 0; + struct ylist_head *i; - __u32 n = (__u32) bucket; + __u32 n = (__u32) bucket; /* yaffs_CheckObjectHashSanity(); */ while (!found) { - found = 1; - n += YAFFS_NOBJECT_BUCKETS; - if (1 || dev->objectBucket[bucket].count > 0) { - ylist_for_each(i, &dev->objectBucket[bucket].list) { - /* If there is already one in the list */ - if (i - && ylist_entry(i, yaffs_Object, - hashLink)->objectId == n) { - found = 0; - } + found = 1; + n += YAFFS_NOBJECT_BUCKETS; + if (1 || dev->objectBucket[bucket].count > 0) { + ylist_for_each(i, &dev->objectBucket[bucket].list) { + /* If there is already one in the list */ + if (i && ylist_entry(i, yaffs_Object, + hashLink)->objectId == n) { + found = 0; + } } } } - return n; } -static void yaffs_HashObject(yaffs_Object * in) +static void yaffs_HashObject(yaffs_Object *in) { - int bucket = yaffs_HashFunction(in->objectId); - yaffs_Device *dev = in->myDev; - - ylist_add(&in->hashLink, &dev->objectBucket[bucket].list); - dev->objectBucket[bucket].count++; + int bucket = yaffs_HashFunction(in->objectId); + yaffs_Device *dev = in->myDev; + ylist_add(&in->hashLink, &dev->objectBucket[bucket].list); + dev->objectBucket[bucket].count++; } -yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number) +yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device *dev, __u32 number) { - int bucket = yaffs_HashFunction(number); - struct ylist_head *i; - yaffs_Object *in; + int bucket = yaffs_HashFunction(number); + struct ylist_head *i; + yaffs_Object *in; - ylist_for_each(i, &dev->objectBucket[bucket].list) { - /* Look if it is in the list */ - if (i) { - in = ylist_entry(i, yaffs_Object, hashLink); - if (in->objectId == number) { + ylist_for_each(i, &dev->objectBucket[bucket].list) { + /* Look if it is in the list */ + if (i) { + in = ylist_entry(i, yaffs_Object, hashLink); + if (in->objectId == number) { #ifdef __KERNEL__ - /* Don't tell the VFS about this one if it is defered free */ + /* Don't tell the VFS about this one if it is defered free */ if (in->deferedFree) return NULL; #endif @@ -2205,10 +2171,9 @@ yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number) return NULL; } -yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, +yaffs_Object *yaffs_CreateNewObject(yaffs_Device *dev, int number, yaffs_ObjectType type) { - yaffs_Object *theObject; yaffs_Tnode *tn = NULL; @@ -2217,18 +2182,16 @@ yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, } theObject = yaffs_AllocateEmptyObject(dev); - if(!theObject) + if (!theObject) return NULL; - - if(type == YAFFS_OBJECT_TYPE_FILE){ + + if (type == YAFFS_OBJECT_TYPE_FILE) { tn = yaffs_GetTnode(dev); - if(!tn){ + if (!tn) { yaffs_FreeObject(theObject); return NULL; } } - - if (theObject) { theObject->fake = 0; @@ -2255,13 +2218,13 @@ yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, theObject->variant.fileVariant.scannedFileSize = 0; theObject->variant.fileVariant.shrinkSize = 0xFFFFFFFF; /* max __u32 */ theObject->variant.fileVariant.topLevel = 0; - theObject->variant.fileVariant.top = tn; - break; - case YAFFS_OBJECT_TYPE_DIRECTORY: - YINIT_LIST_HEAD(&theObject->variant.directoryVariant. - children); - break; - case YAFFS_OBJECT_TYPE_SYMLINK: + theObject->variant.fileVariant.top = tn; + break; + case YAFFS_OBJECT_TYPE_DIRECTORY: + YINIT_LIST_HEAD(&theObject->variant.directoryVariant. + children); + break; + case YAFFS_OBJECT_TYPE_SYMLINK: case YAFFS_OBJECT_TYPE_HARDLINK: case YAFFS_OBJECT_TYPE_SPECIAL: /* No action required */ @@ -2275,7 +2238,7 @@ yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, return theObject; } -static yaffs_Object *yaffs_FindOrCreateObjectByNumber(yaffs_Device * dev, +static yaffs_Object *yaffs_FindOrCreateObjectByNumber(yaffs_Device *dev, int number, yaffs_ObjectType type) { @@ -2292,15 +2255,15 @@ static yaffs_Object *yaffs_FindOrCreateObjectByNumber(yaffs_Device * dev, return theObject; } - -static YCHAR *yaffs_CloneString(const YCHAR * str) + +static YCHAR *yaffs_CloneString(const YCHAR *str) { YCHAR *newStr = NULL; if (str && *str) { newStr = YMALLOC((yaffs_strlen(str) + 1) * sizeof(YCHAR)); - if(newStr) + if (newStr) yaffs_strcpy(newStr, str); } @@ -2314,15 +2277,15 @@ static YCHAR *yaffs_CloneString(const YCHAR * str) * aliasString only has meaning for a sumlink. * rdev only has meaning for devices (a subset of special objects) */ - + static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, - yaffs_Object * parent, - const YCHAR * name, + yaffs_Object *parent, + const YCHAR *name, __u32 mode, __u32 uid, __u32 gid, - yaffs_Object * equivalentObject, - const YCHAR * aliasString, __u32 rdev) + yaffs_Object *equivalentObject, + const YCHAR *aliasString, __u32 rdev) { yaffs_Object *in; YCHAR *str = NULL; @@ -2336,18 +2299,18 @@ static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, in = yaffs_CreateNewObject(dev, -1, type); - if(!in) + if (!in) return YAFFS_FAIL; - - if(type == YAFFS_OBJECT_TYPE_SYMLINK){ + + if (type == YAFFS_OBJECT_TYPE_SYMLINK) { str = yaffs_CloneString(aliasString); - if(!str){ + if (!str) { yaffs_FreeObject(in); return NULL; } } - - + + if (in) { in->hdrChunk = 0; @@ -2383,13 +2346,13 @@ static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, break; case YAFFS_OBJECT_TYPE_HARDLINK: in->variant.hardLinkVariant.equivalentObject = - equivalentObject; - in->variant.hardLinkVariant.equivalentObjectId = - equivalentObject->objectId; - ylist_add(&in->hardLinks, &equivalentObject->hardLinks); - break; - case YAFFS_OBJECT_TYPE_FILE: - case YAFFS_OBJECT_TYPE_DIRECTORY: + equivalentObject; + in->variant.hardLinkVariant.equivalentObjectId = + equivalentObject->objectId; + ylist_add(&in->hardLinks, &equivalentObject->hardLinks); + break; + case YAFFS_OBJECT_TYPE_FILE: + case YAFFS_OBJECT_TYPE_DIRECTORY: case YAFFS_OBJECT_TYPE_SPECIAL: case YAFFS_OBJECT_TYPE_UNKNOWN: /* do nothing */ @@ -2407,38 +2370,38 @@ static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, return in; } -yaffs_Object *yaffs_MknodFile(yaffs_Object * parent, const YCHAR * name, - __u32 mode, __u32 uid, __u32 gid) +yaffs_Object *yaffs_MknodFile(yaffs_Object *parent, const YCHAR *name, + __u32 mode, __u32 uid, __u32 gid) { return yaffs_MknodObject(YAFFS_OBJECT_TYPE_FILE, parent, name, mode, - uid, gid, NULL, NULL, 0); + uid, gid, NULL, NULL, 0); } -yaffs_Object *yaffs_MknodDirectory(yaffs_Object * parent, const YCHAR * name, - __u32 mode, __u32 uid, __u32 gid) +yaffs_Object *yaffs_MknodDirectory(yaffs_Object *parent, const YCHAR *name, + __u32 mode, __u32 uid, __u32 gid) { return yaffs_MknodObject(YAFFS_OBJECT_TYPE_DIRECTORY, parent, name, mode, uid, gid, NULL, NULL, 0); } -yaffs_Object *yaffs_MknodSpecial(yaffs_Object * parent, const YCHAR * name, - __u32 mode, __u32 uid, __u32 gid, __u32 rdev) +yaffs_Object *yaffs_MknodSpecial(yaffs_Object *parent, const YCHAR *name, + __u32 mode, __u32 uid, __u32 gid, __u32 rdev) { return yaffs_MknodObject(YAFFS_OBJECT_TYPE_SPECIAL, parent, name, mode, uid, gid, NULL, NULL, rdev); } -yaffs_Object *yaffs_MknodSymLink(yaffs_Object * parent, const YCHAR * name, - __u32 mode, __u32 uid, __u32 gid, - const YCHAR * alias) +yaffs_Object *yaffs_MknodSymLink(yaffs_Object *parent, const YCHAR *name, + __u32 mode, __u32 uid, __u32 gid, + const YCHAR *alias) { return yaffs_MknodObject(YAFFS_OBJECT_TYPE_SYMLINK, parent, name, mode, - uid, gid, NULL, alias, 0); + uid, gid, NULL, alias, 0); } /* yaffs_Link returns the object id of the equivalent object.*/ -yaffs_Object *yaffs_Link(yaffs_Object * parent, const YCHAR * name, - yaffs_Object * equivalentObject) +yaffs_Object *yaffs_Link(yaffs_Object *parent, const YCHAR *name, + yaffs_Object *equivalentObject) { /* Get the real object in case we were fed a hard link as an equivalent object */ equivalentObject = yaffs_GetEquivalentObject(equivalentObject); @@ -2453,8 +2416,8 @@ yaffs_Object *yaffs_Link(yaffs_Object * parent, const YCHAR * name, } -static int yaffs_ChangeObjectName(yaffs_Object * obj, yaffs_Object * newDir, - const YCHAR * newName, int force, int shadows) +static int yaffs_ChangeObjectName(yaffs_Object *obj, yaffs_Object *newDir, + const YCHAR *newName, int force, int shadows) { int unlinkOp; int deleteOp; @@ -2472,7 +2435,7 @@ static int yaffs_ChangeObjectName(yaffs_Object * obj, yaffs_Object * newDir, TENDSTR))); YBUG(); } - + /* TODO: Do we need this different handling for YAFFS2 and YAFFS1?? */ if (obj->myDev->isYaffs2) { unlinkOp = (newDir == obj->myDev->unlinkedDir); @@ -2485,9 +2448,9 @@ static int yaffs_ChangeObjectName(yaffs_Object * obj, yaffs_Object * newDir, existingTarget = yaffs_FindObjectByName(newDir, newName); - /* If the object is a file going into the unlinked directory, + /* If the object is a file going into the unlinked directory, * then it is OK to just stuff it in since duplicate names are allowed. - * else only proceed if the new name does not exist and if we're putting + * else only proceed if the new name does not exist and if we're putting * it into a directory. */ if ((unlinkOp || @@ -2505,24 +2468,24 @@ static int yaffs_ChangeObjectName(yaffs_Object * obj, yaffs_Object * newDir, obj->unlinked = 1; /* If it is a deletion then we mark it as a shrink for gc purposes. */ - if (yaffs_UpdateObjectHeader(obj, newName, 0, deleteOp, shadows)>= 0) + if (yaffs_UpdateObjectHeader(obj, newName, 0, deleteOp, shadows) >= 0) return YAFFS_OK; } return YAFFS_FAIL; } -int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName, - yaffs_Object * newDir, const YCHAR * newName) +int yaffs_RenameObject(yaffs_Object *oldDir, const YCHAR *oldName, + yaffs_Object *newDir, const YCHAR *newName) { - yaffs_Object *obj=NULL; - yaffs_Object *existingTarget=NULL; + yaffs_Object *obj = NULL; + yaffs_Object *existingTarget = NULL; int force = 0; - - - if(!oldDir || oldDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) + + + if (!oldDir || oldDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) YBUG(); - if(!newDir || newDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) + if (!newDir || newDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) YBUG(); #ifdef CONFIG_YAFFS_CASE_INSENSITIVE @@ -2536,8 +2499,8 @@ int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName, #endif else if (yaffs_strlen(newName) > YAFFS_MAX_NAME_LENGTH) - /* ENAMETOOLONG */ - return YAFFS_FAIL; + /* ENAMETOOLONG */ + return YAFFS_FAIL; obj = yaffs_FindObjectByName(oldDir, oldName); @@ -2545,18 +2508,18 @@ int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName, /* Now do the handling for an existing target, if there is one */ - existingTarget = yaffs_FindObjectByName(newDir, newName); - if (existingTarget && - existingTarget->variantType == YAFFS_OBJECT_TYPE_DIRECTORY && - !ylist_empty(&existingTarget->variant.directoryVariant.children)) { - /* There is a target that is a non-empty directory, so we fail */ - return YAFFS_FAIL; /* EEXIST or ENOTEMPTY */ - } else if (existingTarget && existingTarget != obj) { - /* Nuke the target first, using shadowing, + existingTarget = yaffs_FindObjectByName(newDir, newName); + if (existingTarget && + existingTarget->variantType == YAFFS_OBJECT_TYPE_DIRECTORY && + !ylist_empty(&existingTarget->variant.directoryVariant.children)) { + /* There is a target that is a non-empty directory, so we fail */ + return YAFFS_FAIL; /* EEXIST or ENOTEMPTY */ + } else if (existingTarget && existingTarget != obj) { + /* Nuke the target first, using shadowing, * but only if it isn't the same object */ yaffs_ChangeObjectName(obj, newDir, newName, force, - existingTarget->objectId); + existingTarget->objectId); yaffs_UnlinkObject(existingTarget); } @@ -2567,37 +2530,34 @@ int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName, /*------------------------- Block Management and Page Allocation ----------------*/ -static int yaffs_InitialiseBlocks(yaffs_Device * dev) +static int yaffs_InitialiseBlocks(yaffs_Device *dev) { int nBlocks = dev->internalEndBlock - dev->internalStartBlock + 1; - + dev->blockInfo = NULL; dev->chunkBits = NULL; - + dev->allocationBlock = -1; /* force it to get a new one */ /* If the first allocation strategy fails, thry the alternate one */ dev->blockInfo = YMALLOC(nBlocks * sizeof(yaffs_BlockInfo)); - if(!dev->blockInfo){ + if (!dev->blockInfo) { dev->blockInfo = YMALLOC_ALT(nBlocks * sizeof(yaffs_BlockInfo)); dev->blockInfoAlt = 1; - } - else + } else dev->blockInfoAlt = 0; - - if(dev->blockInfo){ - + + if (dev->blockInfo) { /* Set up dynamic blockinfo stuff. */ dev->chunkBitmapStride = (dev->nChunksPerBlock + 7) / 8; /* round up bytes */ dev->chunkBits = YMALLOC(dev->chunkBitmapStride * nBlocks); - if(!dev->chunkBits){ + if (!dev->chunkBits) { dev->chunkBits = YMALLOC_ALT(dev->chunkBitmapStride * nBlocks); dev->chunkBitsAlt = 1; - } - else + } else dev->chunkBitsAlt = 0; } - + if (dev->blockInfo && dev->chunkBits) { memset(dev->blockInfo, 0, nBlocks * sizeof(yaffs_BlockInfo)); memset(dev->chunkBits, 0, dev->chunkBitmapStride * nBlocks); @@ -2605,30 +2565,29 @@ static int yaffs_InitialiseBlocks(yaffs_Device * dev) } return YAFFS_FAIL; - } -static void yaffs_DeinitialiseBlocks(yaffs_Device * dev) +static void yaffs_DeinitialiseBlocks(yaffs_Device *dev) { - if(dev->blockInfoAlt && dev->blockInfo) + if (dev->blockInfoAlt && dev->blockInfo) YFREE_ALT(dev->blockInfo); - else if(dev->blockInfo) + else if (dev->blockInfo) YFREE(dev->blockInfo); dev->blockInfoAlt = 0; dev->blockInfo = NULL; - - if(dev->chunkBitsAlt && dev->chunkBits) + + if (dev->chunkBitsAlt && dev->chunkBits) YFREE_ALT(dev->chunkBits); - else if(dev->chunkBits) + else if (dev->chunkBits) YFREE(dev->chunkBits); dev->chunkBitsAlt = 0; dev->chunkBits = NULL; } -static int yaffs_BlockNotDisqualifiedFromGC(yaffs_Device * dev, - yaffs_BlockInfo * bi) +static int yaffs_BlockNotDisqualifiedFromGC(yaffs_Device *dev, + yaffs_BlockInfo *bi) { int i; __u32 seq; @@ -2647,7 +2606,7 @@ static int yaffs_BlockNotDisqualifiedFromGC(yaffs_Device * dev, seq = dev->sequenceNumber; for (i = dev->internalStartBlock; i <= dev->internalEndBlock; - i++) { + i++) { b = yaffs_GetBlockInfo(dev, i); if (b->blockState == YAFFS_BLOCK_STATE_FULL && (b->pagesInUse - b->softDeletions) < @@ -2662,38 +2621,36 @@ static int yaffs_BlockNotDisqualifiedFromGC(yaffs_Device * dev, * discarded pages. */ return (bi->sequenceNumber <= dev->oldestDirtySequence); - } /* FindDiretiestBlock is used to select the dirtiest block (or close enough) * for garbage collection. */ -static int yaffs_FindBlockForGarbageCollection(yaffs_Device * dev, - int aggressive) +static int yaffs_FindBlockForGarbageCollection(yaffs_Device *dev, + int aggressive) { - int b = dev->currentDirtyChecker; int i; int iterations; int dirtiest = -1; int pagesInUse = 0; - int prioritised=0; + int prioritised = 0; yaffs_BlockInfo *bi; int pendingPrioritisedExist = 0; - + /* First let's see if we need to grab a prioritised block */ - if(dev->hasPendingPrioritisedGCs){ - for(i = dev->internalStartBlock; i < dev->internalEndBlock && !prioritised; i++){ + if (dev->hasPendingPrioritisedGCs) { + for (i = dev->internalStartBlock; i < dev->internalEndBlock && !prioritised; i++) { bi = yaffs_GetBlockInfo(dev, i); - //yaffs_VerifyBlock(dev,bi,i); - - if(bi->gcPrioritise) { + /* yaffs_VerifyBlock(dev,bi,i); */ + + if (bi->gcPrioritise) { pendingPrioritisedExist = 1; - if(bi->blockState == YAFFS_BLOCK_STATE_FULL && - yaffs_BlockNotDisqualifiedFromGC(dev, bi)){ + if (bi->blockState == YAFFS_BLOCK_STATE_FULL && + yaffs_BlockNotDisqualifiedFromGC(dev, bi)) { pagesInUse = (bi->pagesInUse - bi->softDeletions); dirtiest = i; prioritised = 1; @@ -2701,8 +2658,8 @@ static int yaffs_FindBlockForGarbageCollection(yaffs_Device * dev, } } } - - if(!pendingPrioritisedExist) /* None found, so we can clear this */ + + if (!pendingPrioritisedExist) /* None found, so we can clear this */ dev->hasPendingPrioritisedGCs = 0; } @@ -2718,9 +2675,9 @@ static int yaffs_FindBlockForGarbageCollection(yaffs_Device * dev, return -1; } - if(!prioritised) + if (!prioritised) pagesInUse = - (aggressive) ? dev->nChunksPerBlock : YAFFS_PASSIVE_GC_CHUNKS + 1; + (aggressive) ? dev->nChunksPerBlock : YAFFS_PASSIVE_GC_CHUNKS + 1; if (aggressive) { iterations = @@ -2752,13 +2709,12 @@ static int yaffs_FindBlockForGarbageCollection(yaffs_Device * dev, if (bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT) { dirtiest = b; pagesInUse = 0; - } - else + } else #endif if (bi->blockState == YAFFS_BLOCK_STATE_FULL && - (bi->pagesInUse - bi->softDeletions) < pagesInUse && - yaffs_BlockNotDisqualifiedFromGC(dev, bi)) { + (bi->pagesInUse - bi->softDeletions) < pagesInUse && + yaffs_BlockNotDisqualifiedFromGC(dev, bi)) { dirtiest = b; pagesInUse = (bi->pagesInUse - bi->softDeletions); } @@ -2769,19 +2725,18 @@ static int yaffs_FindBlockForGarbageCollection(yaffs_Device * dev, if (dirtiest > 0) { T(YAFFS_TRACE_GC, (TSTR("GC Selected block %d with %d free, prioritised:%d" TENDSTR), dirtiest, - dev->nChunksPerBlock - pagesInUse,prioritised)); + dev->nChunksPerBlock - pagesInUse, prioritised)); } dev->oldestDirtySequence = 0; - if (dirtiest > 0) { + if (dirtiest > 0) dev->nonAggressiveSkip = 4; - } return dirtiest; } -static void yaffs_BlockBecameDirty(yaffs_Device * dev, int blockNo) +static void yaffs_BlockBecameDirty(yaffs_Device *dev, int blockNo) { yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockNo); @@ -2790,11 +2745,11 @@ static void yaffs_BlockBecameDirty(yaffs_Device * dev, int blockNo) /* If the block is still healthy erase it and mark as clean. * If the block has had a data failure, then retire it. */ - + T(YAFFS_TRACE_GC | YAFFS_TRACE_ERASE, (TSTR("yaffs_BlockBecameDirty block %d state %d %s"TENDSTR), blockNo, bi->blockState, (bi->needsRetiring) ? "needs retiring" : "")); - + bi->blockState = YAFFS_BLOCK_STATE_DIRTY; if (!bi->needsRetiring) { @@ -2807,7 +2762,7 @@ static void yaffs_BlockBecameDirty(yaffs_Device * dev, int blockNo) } } - if (erasedOk && + if (erasedOk && ((yaffs_traceMask & YAFFS_TRACE_ERASE) || !yaffs_SkipVerification(dev))) { int i; for (i = 0; i < dev->nChunksPerBlock; i++) { @@ -2843,7 +2798,7 @@ static void yaffs_BlockBecameDirty(yaffs_Device * dev, int blockNo) } } -static int yaffs_FindBlockForAllocation(yaffs_Device * dev) +static int yaffs_FindBlockForAllocation(yaffs_Device *dev) { int i; @@ -2858,7 +2813,7 @@ static int yaffs_FindBlockForAllocation(yaffs_Device * dev) return -1; } - + /* Find an empty block. */ for (i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) { @@ -2895,8 +2850,8 @@ static int yaffs_FindBlockForAllocation(yaffs_Device * dev) static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev) { - if(!dev->nCheckpointBlocksRequired && - dev->isYaffs2){ + if (!dev->nCheckpointBlocksRequired && + dev->isYaffs2) { /* Not a valid value so recalculate */ int nBytes = 0; int nBlocks; @@ -2905,9 +2860,9 @@ static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev) tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; - if(tnodeSize < sizeof(yaffs_Tnode)) + if (tnodeSize < sizeof(yaffs_Tnode)) tnodeSize = sizeof(yaffs_Tnode); - + nBytes += sizeof(yaffs_CheckpointValidity); nBytes += sizeof(yaffs_CheckpointDevice); nBytes += devBlocks * sizeof(yaffs_BlockInfo); @@ -2916,40 +2871,43 @@ static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev) nBytes += (tnodeSize + sizeof(__u32)) * (dev->nTnodesCreated - dev->nFreeTnodes); nBytes += sizeof(yaffs_CheckpointValidity); nBytes += sizeof(__u32); /* checksum*/ - + /* Round up and add 2 blocks to allow for some bad blocks, so add 3 */ - + nBlocks = (nBytes/(dev->nDataBytesPerChunk * dev->nChunksPerBlock)) + 3; - + dev->nCheckpointBlocksRequired = nBlocks; } return dev->nCheckpointBlocksRequired; } -// Check if there's space to allocate... -// Thinks.... do we need top make this ths same as yaffs_GetFreeChunks()? -static int yaffs_CheckSpaceForAllocation(yaffs_Device * dev) +/* + * Check if there's space to allocate... + * Thinks.... do we need top make this ths same as yaffs_GetFreeChunks()? + */ +static int yaffs_CheckSpaceForAllocation(yaffs_Device *dev) { int reservedChunks; int reservedBlocks = dev->nReservedBlocks; int checkpointBlocks; - - if(dev->isYaffs2){ - checkpointBlocks = yaffs_CalcCheckpointBlocksRequired(dev) - + + if (dev->isYaffs2) { + checkpointBlocks = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; - if(checkpointBlocks < 0) + if (checkpointBlocks < 0) checkpointBlocks = 0; } else { - checkpointBlocks =0; + checkpointBlocks = 0; } - + reservedChunks = ((reservedBlocks + checkpointBlocks) * dev->nChunksPerBlock); - + return (dev->nFreeChunks > reservedChunks); } -static int yaffs_AllocateChunk(yaffs_Device * dev, int useReserve, yaffs_BlockInfo **blockUsedPtr) +static int yaffs_AllocateChunk(yaffs_Device *dev, int useReserve, + yaffs_BlockInfo **blockUsedPtr) { int retVal; yaffs_BlockInfo *bi; @@ -2966,7 +2924,7 @@ static int yaffs_AllocateChunk(yaffs_Device * dev, int useReserve, yaffs_BlockIn } if (dev->nErasedBlocks < dev->nReservedBlocks - && dev->allocationPage == 0) { + && dev->allocationPage == 0) { T(YAFFS_TRACE_ALLOCATE, (TSTR("Allocating reserve" TENDSTR))); } @@ -2975,10 +2933,10 @@ static int yaffs_AllocateChunk(yaffs_Device * dev, int useReserve, yaffs_BlockIn bi = yaffs_GetBlockInfo(dev, dev->allocationBlock); retVal = (dev->allocationBlock * dev->nChunksPerBlock) + - dev->allocationPage; + dev->allocationPage; bi->pagesInUse++; yaffs_SetChunkBit(dev, dev->allocationBlock, - dev->allocationPage); + dev->allocationPage); dev->allocationPage++; @@ -2990,19 +2948,19 @@ static int yaffs_AllocateChunk(yaffs_Device * dev, int useReserve, yaffs_BlockIn dev->allocationBlock = -1; } - if(blockUsedPtr) + if (blockUsedPtr) *blockUsedPtr = bi; - + return retVal; } - + T(YAFFS_TRACE_ERROR, - (TSTR("!!!!!!!!! Allocator out !!!!!!!!!!!!!!!!!" TENDSTR))); + (TSTR("!!!!!!!!! Allocator out !!!!!!!!!!!!!!!!!" TENDSTR))); return -1; } -static int yaffs_GetErasedChunks(yaffs_Device * dev) +static int yaffs_GetErasedChunks(yaffs_Device *dev) { int n; @@ -3016,7 +2974,8 @@ static int yaffs_GetErasedChunks(yaffs_Device * dev) } -static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlock) +static int yaffs_GarbageCollectBlock(yaffs_Device *dev, int block, + int wholeBlock) { int oldChunk; int newChunk; @@ -3038,15 +2997,15 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo yaffs_Object *object; isCheckpointBlock = (bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT); - + bi->blockState = YAFFS_BLOCK_STATE_COLLECTING; T(YAFFS_TRACE_TRACING, - (TSTR("Collecting block %d, in use %d, shrink %d, wholeBlock %d" TENDSTR), - block, - bi->pagesInUse, - bi->hasShrinkHeader, - wholeBlock)); + (TSTR("Collecting block %d, in use %d, shrink %d, wholeBlock %d" TENDSTR), + block, + bi->pagesInUse, + bi->hasShrinkHeader, + wholeBlock)); /*yaffs_VerifyFreeChunks(dev); */ @@ -3060,31 +3019,31 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo dev->isDoingGC = 1; if (isCheckpointBlock || - !yaffs_StillSomeChunkBits(dev, block)) { + !yaffs_StillSomeChunkBits(dev, block)) { T(YAFFS_TRACE_TRACING, - (TSTR - ("Collecting block %d that has no chunks in use" TENDSTR), - block)); + (TSTR + ("Collecting block %d that has no chunks in use" TENDSTR), + block)); yaffs_BlockBecameDirty(dev, block); } else { __u8 *buffer = yaffs_GetTempBuffer(dev, __LINE__); - - yaffs_VerifyBlock(dev,bi,block); + + yaffs_VerifyBlock(dev, bi, block); maxCopies = (wholeBlock) ? dev->nChunksPerBlock : 10; oldChunk = block * dev->nChunksPerBlock + dev->gcChunk; - - for ( /* init already done */; + + for (/* init already done */; retVal == YAFFS_OK && dev->gcChunk < dev->nChunksPerBlock && - (bi->blockState == YAFFS_BLOCK_STATE_COLLECTING)&& + (bi->blockState == YAFFS_BLOCK_STATE_COLLECTING) && maxCopies > 0; dev->gcChunk++, oldChunk++) { if (yaffs_CheckChunkBit(dev, block, dev->gcChunk)) { /* This page is in use and might need to be copied off */ - + maxCopies--; markNAND = 1; @@ -3103,20 +3062,20 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo ("Collecting chunk in block %d, %d %d %d " TENDSTR), dev->gcChunk, tags.objectId, tags.chunkId, tags.byteCount)); - - if(object && !yaffs_SkipVerification(dev)){ - if(tags.chunkId == 0) + + if (object && !yaffs_SkipVerification(dev)) { + if (tags.chunkId == 0) matchingChunk = object->hdrChunk; - else if(object->softDeleted) + else if (object->softDeleted) matchingChunk = oldChunk; /* Defeat the test */ else - matchingChunk = yaffs_FindChunkInFile(object,tags.chunkId,NULL); - - if(oldChunk != matchingChunk) + matchingChunk = yaffs_FindChunkInFile(object, tags.chunkId, NULL); + + if (oldChunk != matchingChunk) T(YAFFS_TRACE_ERROR, (TSTR("gc: page in gc mismatch: %d %d %d %d"TENDSTR), - oldChunk,matchingChunk,tags.objectId, tags.chunkId)); - + oldChunk, matchingChunk, tags.objectId, tags.chunkId)); + } if (!object) { @@ -3127,13 +3086,13 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo tags.objectId, tags.chunkId, tags.byteCount)); } - if (object && + if (object && object->deleted && object->softDeleted && tags.chunkId != 0) { /* Data chunk in a soft deleted file, throw it away * It's a soft deleted data chunk, - * No need to copy this, just forget about it and + * No need to copy this, just forget about it and * fix up the object. */ @@ -3146,9 +3105,8 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo cleanups++; } markNAND = 0; - } else if (0 - /* Todo object && object->deleted && object->nDataChunks == 0 */ - ) { + } else if (0) { + /* Todo object && object->deleted && object->nDataChunks == 0 */ /* Deleted object header with no data chunks. * Can be discarded and the file deleted. */ @@ -3180,8 +3138,8 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo oh = (yaffs_ObjectHeader *)buffer; oh->isShrink = 0; tags.extraIsShrinkHeader = 0; - - yaffs_VerifyObjectHeader(object,oh,&tags,1); + + yaffs_VerifyObjectHeader(object, oh, &tags, 1); } newChunk = @@ -3207,7 +3165,7 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo } } - if(retVal == YAFFS_OK) + if (retVal == YAFFS_OK) yaffs_DeleteChunk(dev, oldChunk, markNAND, __LINE__); } @@ -3239,9 +3197,10 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo } - yaffs_VerifyCollectedBlock(dev,bi,block); - - if (chunksBefore >= (chunksAfter = yaffs_GetErasedChunks(dev))) { + yaffs_VerifyCollectedBlock(dev, bi, block); + + chunksAfter = yaffs_GetErasedChunks(dev); + if (chunksBefore >= chunksAfter) { T(YAFFS_TRACE_GC, (TSTR ("gc did not increase free chunks before %d after %d" @@ -3249,11 +3208,11 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo } /* If the gc completed then clear the current gcBlock so that we find another. */ - if(bi->blockState != YAFFS_BLOCK_STATE_COLLECTING){ + if (bi->blockState != YAFFS_BLOCK_STATE_COLLECTING) { dev->gcBlock = -1; dev->gcChunk = 0; } - + dev->isDoingGC = 0; return retVal; @@ -3268,29 +3227,29 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block, int wholeBlo * The idea is to help clear out space in a more spread-out manner. * Dunno if it really does anything useful. */ -static int yaffs_CheckGarbageCollection(yaffs_Device * dev) +static int yaffs_CheckGarbageCollection(yaffs_Device *dev) { int block; int aggressive; int gcOk = YAFFS_OK; int maxTries = 0; - + int checkpointBlockAdjust; if (dev->isDoingGC) { /* Bail out so we don't get recursive gc */ return YAFFS_OK; } - + /* This loop should pass the first time. * We'll only see looping here if the erase of the collected block fails. */ do { maxTries++; - + checkpointBlockAdjust = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; - if(checkpointBlockAdjust < 0) + if (checkpointBlockAdjust < 0) checkpointBlockAdjust = 0; if (dev->nErasedBlocks < (dev->nReservedBlocks + checkpointBlockAdjust + 2)) { @@ -3301,11 +3260,11 @@ static int yaffs_CheckGarbageCollection(yaffs_Device * dev) aggressive = 0; } - if(dev->gcBlock <= 0){ + if (dev->gcBlock <= 0) { dev->gcBlock = yaffs_FindBlockForGarbageCollection(dev, aggressive); dev->gcChunk = 0; } - + block = dev->gcBlock; if (block > 0) { @@ -3319,7 +3278,7 @@ static int yaffs_CheckGarbageCollection(yaffs_Device * dev) ("yaffs: GC erasedBlocks %d aggressive %d" TENDSTR), dev->nErasedBlocks, aggressive)); - gcOk = yaffs_GarbageCollectBlock(dev,block,aggressive); + gcOk = yaffs_GarbageCollectBlock(dev, block, aggressive); } if (dev->nErasedBlocks < (dev->nReservedBlocks) && block > 0) { @@ -3328,7 +3287,7 @@ static int yaffs_CheckGarbageCollection(yaffs_Device * dev) ("yaffs: GC !!!no reclaim!!! erasedBlocks %d after try %d block %d" TENDSTR), dev->nErasedBlocks, maxTries, block)); } - } while ((dev->nErasedBlocks < dev->nReservedBlocks) && + } while ((dev->nErasedBlocks < dev->nReservedBlocks) && (block > 0) && (maxTries < 2)); @@ -3337,7 +3296,7 @@ static int yaffs_CheckGarbageCollection(yaffs_Device * dev) /*------------------------- TAGS --------------------------------*/ -static int yaffs_TagsMatch(const yaffs_ExtendedTags * tags, int objectId, +static int yaffs_TagsMatch(const yaffs_ExtendedTags *tags, int objectId, int chunkInObject) { return (tags->chunkId == chunkInObject && @@ -3348,8 +3307,8 @@ static int yaffs_TagsMatch(const yaffs_ExtendedTags * tags, int objectId, /*-------------------- Data file manipulation -----------------*/ -static int yaffs_FindChunkInFile(yaffs_Object * in, int chunkInInode, - yaffs_ExtendedTags * tags) +static int yaffs_FindChunkInFile(yaffs_Object *in, int chunkInInode, + yaffs_ExtendedTags *tags) { /*Get the Tnode, then get the level 0 offset chunk offset */ yaffs_Tnode *tn; @@ -3367,7 +3326,7 @@ static int yaffs_FindChunkInFile(yaffs_Object * in, int chunkInInode, tn = yaffs_FindLevel0Tnode(dev, &in->variant.fileVariant, chunkInInode); if (tn) { - theChunk = yaffs_GetChunkGroupBase(dev,tn,chunkInInode); + theChunk = yaffs_GetChunkGroupBase(dev, tn, chunkInInode); retVal = yaffs_FindChunkInGroup(dev, theChunk, tags, in->objectId, @@ -3376,8 +3335,8 @@ static int yaffs_FindChunkInFile(yaffs_Object * in, int chunkInInode, return retVal; } -static int yaffs_FindAndDeleteChunkInFile(yaffs_Object * in, int chunkInInode, - yaffs_ExtendedTags * tags) +static int yaffs_FindAndDeleteChunkInFile(yaffs_Object *in, int chunkInInode, + yaffs_ExtendedTags *tags) { /* Get the Tnode, then get the level 0 offset chunk offset */ yaffs_Tnode *tn; @@ -3396,7 +3355,7 @@ static int yaffs_FindAndDeleteChunkInFile(yaffs_Object * in, int chunkInInode, if (tn) { - theChunk = yaffs_GetChunkGroupBase(dev,tn,chunkInInode); + theChunk = yaffs_GetChunkGroupBase(dev, tn, chunkInInode); retVal = yaffs_FindChunkInGroup(dev, theChunk, tags, in->objectId, @@ -3404,7 +3363,7 @@ static int yaffs_FindAndDeleteChunkInFile(yaffs_Object * in, int chunkInInode, /* Delete the entry in the filestructure (if found) */ if (retVal != -1) { - yaffs_PutLevel0Tnode(dev,tn,chunkInInode,0); + yaffs_PutLevel0Tnode(dev, tn, chunkInInode, 0); } } else { /*T(("No level 0 found for %d\n", chunkInInode)); */ @@ -3418,7 +3377,7 @@ static int yaffs_FindAndDeleteChunkInFile(yaffs_Object * in, int chunkInInode, #ifdef YAFFS_PARANOID -static int yaffs_CheckFileSanity(yaffs_Object * in) +static int yaffs_CheckFileSanity(yaffs_Object *in) { int chunk; int nChunks; @@ -3447,7 +3406,7 @@ static int yaffs_CheckFileSanity(yaffs_Object * in) if (tn) { - theChunk = yaffs_GetChunkGroupBase(dev,tn,chunk); + theChunk = yaffs_GetChunkGroupBase(dev, tn, chunk); if (yaffs_CheckChunkBits (dev, theChunk / dev->nChunksPerBlock, @@ -3476,14 +3435,14 @@ static int yaffs_CheckFileSanity(yaffs_Object * in) #endif -static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode, +static int yaffs_PutChunkIntoFile(yaffs_Object *in, int chunkInInode, int chunkInNAND, int inScan) { - /* NB inScan is zero unless scanning. - * For forward scanning, inScan is > 0; + /* NB inScan is zero unless scanning. + * For forward scanning, inScan is > 0; * for backward scanning inScan is < 0 */ - + yaffs_Tnode *tn; yaffs_Device *dev = in->myDev; int existingChunk; @@ -3507,7 +3466,7 @@ static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode, return YAFFS_OK; } - tn = yaffs_AddOrFindLevel0Tnode(dev, + tn = yaffs_AddOrFindLevel0Tnode(dev, &in->variant.fileVariant, chunkInInode, NULL); @@ -3515,11 +3474,11 @@ static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode, return YAFFS_FAIL; } - existingChunk = yaffs_GetChunkGroupBase(dev,tn,chunkInInode); + existingChunk = yaffs_GetChunkGroupBase(dev, tn, chunkInInode); if (inScan != 0) { /* If we're scanning then we need to test for duplicates - * NB This does not need to be efficient since it should only ever + * NB This does not need to be efficient since it should only ever * happen when the power fails during a write, then only one * chunk should ever be affected. * @@ -3560,11 +3519,11 @@ static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode, } - /* NB The deleted flags should be false, otherwise the chunks will + /* NB The deleted flags should be false, otherwise the chunks will * not be loaded during a scan */ - if(inScan > 0) { + if (inScan > 0) { newSerial = newTags.serialNumber; existingSerial = existingTags.serialNumber; } @@ -3573,7 +3532,7 @@ static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode, (in->myDev->isYaffs2 || existingChunk <= 0 || ((existingSerial + 1) & 3) == newSerial)) { - /* Forward scanning. + /* Forward scanning. * Use new * Delete the old one and drop through to update the tnode */ @@ -3596,31 +3555,31 @@ static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode, in->nDataChunks++; } - yaffs_PutLevel0Tnode(dev,tn,chunkInInode,chunkInNAND); + yaffs_PutLevel0Tnode(dev, tn, chunkInInode, chunkInNAND); return YAFFS_OK; } -static int yaffs_ReadChunkDataFromObject(yaffs_Object * in, int chunkInInode, - __u8 * buffer) +static int yaffs_ReadChunkDataFromObject(yaffs_Object *in, int chunkInInode, + __u8 *buffer) { int chunkInNAND = yaffs_FindChunkInFile(in, chunkInInode, NULL); if (chunkInNAND >= 0) { return yaffs_ReadChunkWithTagsFromNAND(in->myDev, chunkInNAND, - buffer,NULL); + buffer, NULL); } else { T(YAFFS_TRACE_NANDACCESS, (TSTR("Chunk %d not found zero instead" TENDSTR), chunkInNAND)); /* get sane (zero) data if you read a hole */ - memset(buffer, 0, in->myDev->nDataBytesPerChunk); + memset(buffer, 0, in->myDev->nDataBytesPerChunk); return 0; } } -void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn) +void yaffs_DeleteChunk(yaffs_Device *dev, int chunkId, int markNAND, int lyn) { int block; int page; @@ -3629,17 +3588,17 @@ void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn) if (chunkId <= 0) return; - + dev->nDeletions++; block = chunkId / dev->nChunksPerBlock; page = chunkId % dev->nChunksPerBlock; - if(!yaffs_CheckChunkBit(dev,block,page)) + if (!yaffs_CheckChunkBit(dev, block, page)) T(YAFFS_TRACE_VERIFY, - (TSTR("Deleting invalid chunk %d"TENDSTR), - chunkId)); + (TSTR("Deleting invalid chunk %d"TENDSTR), + chunkId)); bi = yaffs_GetBlockInfo(dev, block); @@ -3685,8 +3644,8 @@ void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn) } -static int yaffs_WriteChunkDataToObject(yaffs_Object * in, int chunkInInode, - const __u8 * buffer, int nBytes, +static int yaffs_WriteChunkDataToObject(yaffs_Object *in, int chunkInInode, + const __u8 *buffer, int nBytes, int useReserve) { /* Find old chunk Need to do this to get serial number @@ -3715,14 +3674,12 @@ static int yaffs_WriteChunkDataToObject(yaffs_Object * in, int chunkInInode, newTags.serialNumber = (prevChunkId >= 0) ? prevTags.serialNumber + 1 : 1; newTags.byteCount = nBytes; - - if(nBytes < 1 || nBytes > dev->totalBytesPerChunk){ + + if (nBytes < 1 || nBytes > dev->totalBytesPerChunk) { T(YAFFS_TRACE_ERROR, (TSTR("Writing %d bytes to chunk!!!!!!!!!" TENDSTR), nBytes)); YBUG(); - } - - + } newChunkId = yaffs_WriteNewChunkWithTagsToNAND(dev, buffer, &newTags, @@ -3745,7 +3702,7 @@ static int yaffs_WriteChunkDataToObject(yaffs_Object * in, int chunkInInode, /* UpdateObjectHeader updates the header on NAND for an object. * If name is not NULL, then that new name is used. */ -int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, +int yaffs_UpdateObjectHeader(yaffs_Object *in, const YCHAR *name, int force, int isShrink, int shadows) { @@ -3764,14 +3721,14 @@ int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, __u8 *buffer = NULL; YCHAR oldName[YAFFS_MAX_NAME_LENGTH + 1]; - yaffs_ObjectHeader *oh = NULL; - - yaffs_strcpy(oldName,_Y("silly old name")); + yaffs_ObjectHeader *oh = NULL; + + yaffs_strcpy(oldName, _Y("silly old name")); - if (!in->fake || - in == dev->rootDir || /* The rootDir should also be saved */ - force) { + if (!in->fake || + in == dev->rootDir || /* The rootDir should also be saved */ + force) { yaffs_CheckGarbageCollection(dev); yaffs_CheckObjectDetailsLoaded(in); @@ -3784,9 +3741,9 @@ int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, if (prevChunkId > 0) { result = yaffs_ReadChunkWithTagsFromNAND(dev, prevChunkId, buffer, &oldTags); - - yaffs_VerifyObjectHeader(in,oh,&oldTags,0); - + + yaffs_VerifyObjectHeader(in, oh, &oldTags, 0); + memcpy(oldName, oh->name, sizeof(oh->name)); } @@ -3820,7 +3777,7 @@ int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, if (name && *name) { memset(oh->name, 0, sizeof(oh->name)); yaffs_strncpy(oh->name, name, YAFFS_MAX_NAME_LENGTH); - } else if (prevChunkId>=0) { + } else if (prevChunkId >= 0) { memcpy(oh->name, oldName, sizeof(oh->name)); } else { memset(oh->name, 0, sizeof(oh->name)); @@ -3874,7 +3831,7 @@ int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, newTags.extraShadows = (oh->shadowsObject > 0) ? 1 : 0; newTags.extraObjectType = in->variantType; - yaffs_VerifyObjectHeader(in,oh,&newTags,1); + yaffs_VerifyObjectHeader(in, oh, &newTags, 1); /* Create new chunk in NAND */ newChunkId = @@ -3890,13 +3847,13 @@ int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, __LINE__); } - if(!yaffs_ObjectHasCachedWriteData(in)) + if (!yaffs_ObjectHasCachedWriteData(in)) in->dirty = 0; /* If this was a shrink, then mark the block that the chunk lives on */ if (isShrink) { bi = yaffs_GetBlockInfo(in->myDev, - newChunkId /in->myDev-> nChunksPerBlock); + newChunkId / in->myDev->nChunksPerBlock); bi->hasShrinkHeader = 1; } @@ -3914,11 +3871,11 @@ int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, /*------------------------ Short Operations Cache ---------------------------------------- * In many situations where there is no high level buffering (eg WinCE) a lot of - * reads might be short sequential reads, and a lot of writes may be short + * reads might be short sequential reads, and a lot of writes may be short * sequential writes. eg. scanning/writing a jpeg file. - * In these cases, a short read/write cache can provide a huge perfomance benefit + * In these cases, a short read/write cache can provide a huge perfomance benefit * with dumb-as-a-rock code. - * In Linux, the page cache provides read buffering aand the short op cache provides write + * In Linux, the page cache provides read buffering aand the short op cache provides write * buffering. * * There are a limited number (~10) of cache chunks per device so that we don't @@ -3931,19 +3888,19 @@ static int yaffs_ObjectHasCachedWriteData(yaffs_Object *obj) int i; yaffs_ChunkCache *cache; int nCaches = obj->myDev->nShortOpCaches; - - for(i = 0; i < nCaches; i++){ + + for (i = 0; i < nCaches; i++) { cache = &dev->srCache[i]; if (cache->object == obj && cache->dirty) return 1; } - + return 0; } -static void yaffs_FlushFilesChunkCache(yaffs_Object * obj) +static void yaffs_FlushFilesChunkCache(yaffs_Object *obj) { yaffs_Device *dev = obj->myDev; int lowest = -99; /* Stop compiler whining. */ @@ -4004,38 +3961,38 @@ void yaffs_FlushEntireDeviceCache(yaffs_Device *dev) yaffs_Object *obj; int nCaches = dev->nShortOpCaches; int i; - + /* Find a dirty object in the cache and flush it... * until there are no further dirty objects. */ do { obj = NULL; - for( i = 0; i < nCaches && !obj; i++) { + for (i = 0; i < nCaches && !obj; i++) { if (dev->srCache[i].object && dev->srCache[i].dirty) obj = dev->srCache[i].object; - + } - if(obj) + if (obj) yaffs_FlushFilesChunkCache(obj); - - } while(obj); - + + } while (obj); + } /* Grab us a cache chunk for use. - * First look for an empty one. + * First look for an empty one. * Then look for the least recently used non-dirty one. * Then look for the least recently used dirty one...., flush and look again. */ -static yaffs_ChunkCache *yaffs_GrabChunkCacheWorker(yaffs_Device * dev) +static yaffs_ChunkCache *yaffs_GrabChunkCacheWorker(yaffs_Device *dev) { int i; if (dev->nShortOpCaches > 0) { for (i = 0; i < dev->nShortOpCaches; i++) { - if (!dev->srCache[i].object) + if (!dev->srCache[i].object) return &dev->srCache[i]; } } @@ -4043,7 +4000,7 @@ static yaffs_ChunkCache *yaffs_GrabChunkCacheWorker(yaffs_Device * dev) return NULL; } -static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device * dev) +static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device *dev) { yaffs_ChunkCache *cache; yaffs_Object *theObj; @@ -4073,8 +4030,7 @@ static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device * dev) for (i = 0; i < dev->nShortOpCaches; i++) { if (dev->srCache[i].object && !dev->srCache[i].locked && - (dev->srCache[i].lastUse < usage || !cache)) - { + (dev->srCache[i].lastUse < usage || !cache)) { usage = dev->srCache[i].lastUse; theObj = dev->srCache[i].object; cache = &dev->srCache[i]; @@ -4096,7 +4052,7 @@ static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device * dev) } /* Find a cached chunk */ -static yaffs_ChunkCache *yaffs_FindChunkCache(const yaffs_Object * obj, +static yaffs_ChunkCache *yaffs_FindChunkCache(const yaffs_Object *obj, int chunkId) { yaffs_Device *dev = obj->myDev; @@ -4115,7 +4071,7 @@ static yaffs_ChunkCache *yaffs_FindChunkCache(const yaffs_Object * obj, } /* Mark the chunk for the least recently used algorithym */ -static void yaffs_UseChunkCache(yaffs_Device * dev, yaffs_ChunkCache * cache, +static void yaffs_UseChunkCache(yaffs_Device *dev, yaffs_ChunkCache *cache, int isAWrite) { @@ -4143,7 +4099,7 @@ static void yaffs_UseChunkCache(yaffs_Device * dev, yaffs_ChunkCache * cache, * Do this when a whole page gets written, * ie the short cache for this page is no longer valid. */ -static void yaffs_InvalidateChunkCache(yaffs_Object * object, int chunkId) +static void yaffs_InvalidateChunkCache(yaffs_Object *object, int chunkId) { if (object->myDev->nShortOpCaches > 0) { yaffs_ChunkCache *cache = yaffs_FindChunkCache(object, chunkId); @@ -4157,7 +4113,7 @@ static void yaffs_InvalidateChunkCache(yaffs_Object * object, int chunkId) /* Invalidate all the cache pages associated with this object * Do this whenever ther file is deleted or resized. */ -static void yaffs_InvalidateWholeChunkCache(yaffs_Object * in) +static void yaffs_InvalidateWholeChunkCache(yaffs_Object *in) { int i; yaffs_Device *dev = in->myDev; @@ -4175,18 +4131,18 @@ static void yaffs_InvalidateWholeChunkCache(yaffs_Object * in) /*--------------------- Checkpointing --------------------*/ -static int yaffs_WriteCheckpointValidityMarker(yaffs_Device *dev,int head) +static int yaffs_WriteCheckpointValidityMarker(yaffs_Device *dev, int head) { yaffs_CheckpointValidity cp; - - memset(&cp,0,sizeof(cp)); - + + memset(&cp, 0, sizeof(cp)); + cp.structType = sizeof(cp); cp.magic = YAFFS_MAGIC; cp.version = YAFFS_CHECKPOINT_VERSION; cp.head = (head) ? 1 : 0; - - return (yaffs_CheckpointWrite(dev,&cp,sizeof(cp)) == sizeof(cp))? + + return (yaffs_CheckpointWrite(dev, &cp, sizeof(cp)) == sizeof(cp)) ? 1 : 0; } @@ -4194,10 +4150,10 @@ static int yaffs_ReadCheckpointValidityMarker(yaffs_Device *dev, int head) { yaffs_CheckpointValidity cp; int ok; - - ok = (yaffs_CheckpointRead(dev,&cp,sizeof(cp)) == sizeof(cp)); - - if(ok) + + ok = (yaffs_CheckpointRead(dev, &cp, sizeof(cp)) == sizeof(cp)); + + if (ok) ok = (cp.structType == sizeof(cp)) && (cp.magic == YAFFS_MAGIC) && (cp.version == YAFFS_CHECKPOINT_VERSION) && @@ -4205,20 +4161,20 @@ static int yaffs_ReadCheckpointValidityMarker(yaffs_Device *dev, int head) return ok ? 1 : 0; } -static void yaffs_DeviceToCheckpointDevice(yaffs_CheckpointDevice *cp, +static void yaffs_DeviceToCheckpointDevice(yaffs_CheckpointDevice *cp, yaffs_Device *dev) { cp->nErasedBlocks = dev->nErasedBlocks; cp->allocationBlock = dev->allocationBlock; cp->allocationPage = dev->allocationPage; cp->nFreeChunks = dev->nFreeChunks; - + cp->nDeletedFiles = dev->nDeletedFiles; cp->nUnlinkedFiles = dev->nUnlinkedFiles; cp->nBackgroundDeletions = dev->nBackgroundDeletions; cp->sequenceNumber = dev->sequenceNumber; cp->oldestDirtySequence = dev->oldestDirtySequence; - + } static void yaffs_CheckpointDeviceToDevice(yaffs_Device *dev, @@ -4228,7 +4184,7 @@ static void yaffs_CheckpointDeviceToDevice(yaffs_Device *dev, dev->allocationBlock = cp->allocationBlock; dev->allocationPage = cp->allocationPage; dev->nFreeChunks = cp->nFreeChunks; - + dev->nDeletedFiles = cp->nDeletedFiles; dev->nUnlinkedFiles = cp->nUnlinkedFiles; dev->nBackgroundDeletions = cp->nBackgroundDeletions; @@ -4244,23 +4200,23 @@ static int yaffs_WriteCheckpointDevice(yaffs_Device *dev) __u32 nBlocks = (dev->internalEndBlock - dev->internalStartBlock + 1); int ok; - + /* Write device runtime values*/ - yaffs_DeviceToCheckpointDevice(&cp,dev); + yaffs_DeviceToCheckpointDevice(&cp, dev); cp.structType = sizeof(cp); - - ok = (yaffs_CheckpointWrite(dev,&cp,sizeof(cp)) == sizeof(cp)); - + + ok = (yaffs_CheckpointWrite(dev, &cp, sizeof(cp)) == sizeof(cp)); + /* Write block info */ - if(ok) { + if (ok) { nBytes = nBlocks * sizeof(yaffs_BlockInfo); - ok = (yaffs_CheckpointWrite(dev,dev->blockInfo,nBytes) == nBytes); + ok = (yaffs_CheckpointWrite(dev, dev->blockInfo, nBytes) == nBytes); } - - /* Write chunk bits */ - if(ok) { + + /* Write chunk bits */ + if (ok) { nBytes = nBlocks * dev->chunkBitmapStride; - ok = (yaffs_CheckpointWrite(dev,dev->chunkBits,nBytes) == nBytes); + ok = (yaffs_CheckpointWrite(dev, dev->chunkBits, nBytes) == nBytes); } return ok ? 1 : 0; @@ -4272,28 +4228,28 @@ static int yaffs_ReadCheckpointDevice(yaffs_Device *dev) __u32 nBytes; __u32 nBlocks = (dev->internalEndBlock - dev->internalStartBlock + 1); - int ok; - - ok = (yaffs_CheckpointRead(dev,&cp,sizeof(cp)) == sizeof(cp)); - if(!ok) + int ok; + + ok = (yaffs_CheckpointRead(dev, &cp, sizeof(cp)) == sizeof(cp)); + if (!ok) return 0; - - if(cp.structType != sizeof(cp)) + + if (cp.structType != sizeof(cp)) return 0; - - - yaffs_CheckpointDeviceToDevice(dev,&cp); - + + + yaffs_CheckpointDeviceToDevice(dev, &cp); + nBytes = nBlocks * sizeof(yaffs_BlockInfo); - - ok = (yaffs_CheckpointRead(dev,dev->blockInfo,nBytes) == nBytes); - - if(!ok) + + ok = (yaffs_CheckpointRead(dev, dev->blockInfo, nBytes) == nBytes); + + if (!ok) return 0; nBytes = nBlocks * dev->chunkBitmapStride; - - ok = (yaffs_CheckpointRead(dev,dev->chunkBits,nBytes) == nBytes); - + + ok = (yaffs_CheckpointRead(dev, dev->chunkBits, nBytes) == nBytes); + return ok ? 1 : 0; } @@ -4313,42 +4269,43 @@ static void yaffs_ObjectToCheckpointObject(yaffs_CheckpointObject *cp, cp->unlinkAllowed = obj->unlinkAllowed; cp->serial = obj->serial; cp->nDataChunks = obj->nDataChunks; - - if(obj->variantType == YAFFS_OBJECT_TYPE_FILE) + + if (obj->variantType == YAFFS_OBJECT_TYPE_FILE) cp->fileSizeOrEquivalentObjectId = obj->variant.fileVariant.fileSize; - else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) + else if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) cp->fileSizeOrEquivalentObjectId = obj->variant.hardLinkVariant.equivalentObjectId; } -static int yaffs_CheckpointObjectToObject( yaffs_Object *obj,yaffs_CheckpointObject *cp) +static int yaffs_CheckpointObjectToObject(yaffs_Object *obj, yaffs_CheckpointObject *cp) { yaffs_Object *parent; if (obj->variantType != cp->variantType) { - T(YAFFS_TRACE_ERROR,(TSTR("Checkpoint read object %d type %d " + T(YAFFS_TRACE_ERROR, (TSTR("Checkpoint read object %d type %d " TCONT("chunk %d does not match existing object type %d") TENDSTR), cp->objectId, cp->variantType, cp->hdrChunk, obj->variantType)); return 0; } - + obj->objectId = cp->objectId; - - if(cp->parentId) + + if (cp->parentId) parent = yaffs_FindOrCreateObjectByNumber( obj->myDev, cp->parentId, YAFFS_OBJECT_TYPE_DIRECTORY); else parent = NULL; - - if(parent) { + + if (parent) { if (parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) { - T(YAFFS_TRACE_ALWAYS,(TSTR("Checkpoint read object %d parent %d type %d" + T(YAFFS_TRACE_ALWAYS, (TSTR("Checkpoint read object %d parent %d type %d" TCONT(" chunk %d Parent type, %d, not directory") TENDSTR), - cp->objectId,cp->parentId,cp->variantType,cp->hdrChunk,parent->variantType)); + cp->objectId, cp->parentId, cp->variantType, + cp->hdrChunk, parent->variantType)); return 0; } yaffs_AddObjectToDirectory(parent, obj); @@ -4364,35 +4321,35 @@ static int yaffs_CheckpointObjectToObject( yaffs_Object *obj,yaffs_CheckpointObj obj->unlinkAllowed = cp->unlinkAllowed; obj->serial = cp->serial; obj->nDataChunks = cp->nDataChunks; - - if(obj->variantType == YAFFS_OBJECT_TYPE_FILE) + + if (obj->variantType == YAFFS_OBJECT_TYPE_FILE) obj->variant.fileVariant.fileSize = cp->fileSizeOrEquivalentObjectId; - else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) + else if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) obj->variant.hardLinkVariant.equivalentObjectId = cp->fileSizeOrEquivalentObjectId; - if(obj->hdrChunk > 0) + if (obj->hdrChunk > 0) obj->lazyLoaded = 1; return 1; } -static int yaffs_CheckpointTnodeWorker(yaffs_Object * in, yaffs_Tnode * tn, - __u32 level, int chunkOffset) +static int yaffs_CheckpointTnodeWorker(yaffs_Object *in, yaffs_Tnode *tn, + __u32 level, int chunkOffset) { int i; yaffs_Device *dev = in->myDev; int ok = 1; int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; - if(tnodeSize < sizeof(yaffs_Tnode)) + if (tnodeSize < sizeof(yaffs_Tnode)) tnodeSize = sizeof(yaffs_Tnode); - + if (tn) { if (level > 0) { - for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++){ + for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++) { if (tn->internal[i]) { ok = yaffs_CheckpointTnodeWorker(in, tn->internal[i], @@ -4402,9 +4359,9 @@ static int yaffs_CheckpointTnodeWorker(yaffs_Object * in, yaffs_Tnode * tn, } } else if (level == 0) { __u32 baseOffset = chunkOffset << YAFFS_TNODES_LEVEL0_BITS; - ok = (yaffs_CheckpointWrite(dev,&baseOffset,sizeof(baseOffset)) == sizeof(baseOffset)); - if(ok) - ok = (yaffs_CheckpointWrite(dev,tn,tnodeSize) == tnodeSize); + ok = (yaffs_CheckpointWrite(dev, &baseOffset, sizeof(baseOffset)) == sizeof(baseOffset)); + if (ok) + ok = (yaffs_CheckpointWrite(dev, tn, tnodeSize) == tnodeSize); } } @@ -4416,17 +4373,17 @@ static int yaffs_WriteCheckpointTnodes(yaffs_Object *obj) { __u32 endMarker = ~0; int ok = 1; - - if(obj->variantType == YAFFS_OBJECT_TYPE_FILE){ + + if (obj->variantType == YAFFS_OBJECT_TYPE_FILE) { ok = yaffs_CheckpointTnodeWorker(obj, obj->variant.fileVariant.top, obj->variant.fileVariant.topLevel, 0); - if(ok) - ok = (yaffs_CheckpointWrite(obj->myDev,&endMarker,sizeof(endMarker)) == + if (ok) + ok = (yaffs_CheckpointWrite(obj->myDev, &endMarker, sizeof(endMarker)) == sizeof(endMarker)); } - + return ok ? 1 : 0; } @@ -4440,85 +4397,83 @@ static int yaffs_ReadCheckpointTnodes(yaffs_Object *obj) int nread = 0; int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; - if(tnodeSize < sizeof(yaffs_Tnode)) + if (tnodeSize < sizeof(yaffs_Tnode)) tnodeSize = sizeof(yaffs_Tnode); - ok = (yaffs_CheckpointRead(dev,&baseChunk,sizeof(baseChunk)) == sizeof(baseChunk)); - - while(ok && (~baseChunk)){ + ok = (yaffs_CheckpointRead(dev, &baseChunk, sizeof(baseChunk)) == sizeof(baseChunk)); + + while (ok && (~baseChunk)) { nread++; /* Read level 0 tnode */ - - + + tn = yaffs_GetTnodeRaw(dev); - if(tn) - ok = (yaffs_CheckpointRead(dev,tn,tnodeSize) == tnodeSize); + if (tn) + ok = (yaffs_CheckpointRead(dev, tn, tnodeSize) == tnodeSize); else ok = 0; - - if(tn && ok){ + + if (tn && ok) ok = yaffs_AddOrFindLevel0Tnode(dev, - fileStructPtr, - baseChunk, - tn) ? 1 : 0; - - } - - if(ok) - ok = (yaffs_CheckpointRead(dev,&baseChunk,sizeof(baseChunk)) == sizeof(baseChunk)); - + fileStructPtr, + baseChunk, + tn) ? 1 : 0; + + if (ok) + ok = (yaffs_CheckpointRead(dev, &baseChunk, sizeof(baseChunk)) == sizeof(baseChunk)); + } - T(YAFFS_TRACE_CHECKPOINT,( + T(YAFFS_TRACE_CHECKPOINT, ( TSTR("Checkpoint read tnodes %d records, last %d. ok %d" TENDSTR), - nread,baseChunk,ok)); + nread, baseChunk, ok)); - return ok ? 1 : 0; + return ok ? 1 : 0; } - + static int yaffs_WriteCheckpointObjects(yaffs_Device *dev) { yaffs_Object *obj; - yaffs_CheckpointObject cp; - int i; - int ok = 1; - struct ylist_head *lh; + yaffs_CheckpointObject cp; + int i; + int ok = 1; + struct ylist_head *lh; - - /* Iterate through the objects in each hash entry, + + /* Iterate through the objects in each hash entry, * dumping them to the checkpointing stream. - */ - - for(i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++){ - ylist_for_each(lh, &dev->objectBucket[i].list) { - if (lh) { - obj = ylist_entry(lh, yaffs_Object, hashLink); - if (!obj->deferedFree) { - yaffs_ObjectToCheckpointObject(&cp,obj); - cp.structType = sizeof(cp); - - T(YAFFS_TRACE_CHECKPOINT,( + */ + + for (i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++) { + ylist_for_each(lh, &dev->objectBucket[i].list) { + if (lh) { + obj = ylist_entry(lh, yaffs_Object, hashLink); + if (!obj->deferedFree) { + yaffs_ObjectToCheckpointObject(&cp, obj); + cp.structType = sizeof(cp); + + T(YAFFS_TRACE_CHECKPOINT, ( TSTR("Checkpoint write object %d parent %d type %d chunk %d obj addr %x" TENDSTR), - cp.objectId,cp.parentId,cp.variantType,cp.hdrChunk,(unsigned) obj)); + cp.objectId, cp.parentId, cp.variantType, cp.hdrChunk, (unsigned) obj)); + + ok = (yaffs_CheckpointWrite(dev, &cp, sizeof(cp)) == sizeof(cp)); - ok = (yaffs_CheckpointWrite(dev,&cp,sizeof(cp)) == sizeof(cp)); - - if(ok && obj->variantType == YAFFS_OBJECT_TYPE_FILE){ + if (ok && obj->variantType == YAFFS_OBJECT_TYPE_FILE) { ok = yaffs_WriteCheckpointTnodes(obj); } } } } - } - - /* Dump end of list */ - memset(&cp,0xFF,sizeof(yaffs_CheckpointObject)); + } + + /* Dump end of list */ + memset(&cp, 0xFF, sizeof(yaffs_CheckpointObject)); cp.structType = sizeof(cp); - - if(ok) - ok = (yaffs_CheckpointWrite(dev,&cp,sizeof(cp)) == sizeof(cp)); - + + if (ok) + ok = (yaffs_CheckpointWrite(dev, &cp, sizeof(cp)) == sizeof(cp)); + return ok ? 1 : 0; } @@ -4529,44 +4484,41 @@ static int yaffs_ReadCheckpointObjects(yaffs_Device *dev) int ok = 1; int done = 0; yaffs_Object *hardList = NULL; - - while(ok && !done) { - ok = (yaffs_CheckpointRead(dev,&cp,sizeof(cp)) == sizeof(cp)); - if(cp.structType != sizeof(cp)) { - T(YAFFS_TRACE_CHECKPOINT,(TSTR("struct size %d instead of %d ok %d"TENDSTR), - cp.structType,sizeof(cp),ok)); + + while (ok && !done) { + ok = (yaffs_CheckpointRead(dev, &cp, sizeof(cp)) == sizeof(cp)); + if (cp.structType != sizeof(cp)) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("struct size %d instead of %d ok %d"TENDSTR), + cp.structType, sizeof(cp), ok)); ok = 0; } - - T(YAFFS_TRACE_CHECKPOINT,(TSTR("Checkpoint read object %d parent %d type %d chunk %d " TENDSTR), - cp.objectId,cp.parentId,cp.variantType,cp.hdrChunk)); - if(ok && cp.objectId == ~0) + T(YAFFS_TRACE_CHECKPOINT, (TSTR("Checkpoint read object %d parent %d type %d chunk %d " TENDSTR), + cp.objectId, cp.parentId, cp.variantType, cp.hdrChunk)); + + if (ok && cp.objectId == ~0) done = 1; - else if(ok){ - obj = yaffs_FindOrCreateObjectByNumber(dev,cp.objectId, cp.variantType); - if(obj) { - ok = yaffs_CheckpointObjectToObject(obj,&cp); + else if (ok) { + obj = yaffs_FindOrCreateObjectByNumber(dev, cp.objectId, cp.variantType); + if (obj) { + ok = yaffs_CheckpointObjectToObject(obj, &cp); if (!ok) break; - if(obj->variantType == YAFFS_OBJECT_TYPE_FILE) { - ok = yaffs_ReadCheckpointTnodes(obj); - } else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) { - obj->hardLinks.next = - (struct ylist_head *) - hardList; - hardList = obj; - } - - } - else + if (obj->variantType == YAFFS_OBJECT_TYPE_FILE) { + ok = yaffs_ReadCheckpointTnodes(obj); + } else if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) { + obj->hardLinks.next = + (struct ylist_head *) hardList; + hardList = obj; + } + } else ok = 0; } } - - if(ok) - yaffs_HardlinkFixup(dev,hardList); - + + if (ok) + yaffs_HardlinkFixup(dev, hardList); + return ok ? 1 : 0; } @@ -4574,14 +4526,14 @@ static int yaffs_WriteCheckpointSum(yaffs_Device *dev) { __u32 checkpointSum; int ok; - - yaffs_GetCheckpointSum(dev,&checkpointSum); - - ok = (yaffs_CheckpointWrite(dev,&checkpointSum,sizeof(checkpointSum)) == sizeof(checkpointSum)); - - if(!ok) + + yaffs_GetCheckpointSum(dev, &checkpointSum); + + ok = (yaffs_CheckpointWrite(dev, &checkpointSum, sizeof(checkpointSum)) == sizeof(checkpointSum)); + + if (!ok) return 0; - + return 1; } @@ -4590,63 +4542,62 @@ static int yaffs_ReadCheckpointSum(yaffs_Device *dev) __u32 checkpointSum0; __u32 checkpointSum1; int ok; - - yaffs_GetCheckpointSum(dev,&checkpointSum0); - - ok = (yaffs_CheckpointRead(dev,&checkpointSum1,sizeof(checkpointSum1)) == sizeof(checkpointSum1)); - - if(!ok) + + yaffs_GetCheckpointSum(dev, &checkpointSum0); + + ok = (yaffs_CheckpointRead(dev, &checkpointSum1, sizeof(checkpointSum1)) == sizeof(checkpointSum1)); + + if (!ok) return 0; - - if(checkpointSum0 != checkpointSum1) + + if (checkpointSum0 != checkpointSum1) return 0; - + return 1; } static int yaffs_WriteCheckpointData(yaffs_Device *dev) { - int ok = 1; - - if(dev->skipCheckpointWrite || !dev->isYaffs2){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("skipping checkpoint write" TENDSTR))); + + if (dev->skipCheckpointWrite || !dev->isYaffs2) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("skipping checkpoint write" TENDSTR))); ok = 0; } - - if(ok) - ok = yaffs_CheckpointOpen(dev,1); - - if(ok){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint validity" TENDSTR))); - ok = yaffs_WriteCheckpointValidityMarker(dev,1); + + if (ok) + ok = yaffs_CheckpointOpen(dev, 1); + + if (ok) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("write checkpoint validity" TENDSTR))); + ok = yaffs_WriteCheckpointValidityMarker(dev, 1); } - if(ok){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint device" TENDSTR))); + if (ok) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("write checkpoint device" TENDSTR))); ok = yaffs_WriteCheckpointDevice(dev); } - if(ok){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint objects" TENDSTR))); + if (ok) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("write checkpoint objects" TENDSTR))); ok = yaffs_WriteCheckpointObjects(dev); } - if(ok){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint validity" TENDSTR))); - ok = yaffs_WriteCheckpointValidityMarker(dev,0); + if (ok) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("write checkpoint validity" TENDSTR))); + ok = yaffs_WriteCheckpointValidityMarker(dev, 0); } - - if(ok){ + + if (ok) { ok = yaffs_WriteCheckpointSum(dev); } - - - if(!yaffs_CheckpointClose(dev)) - ok = 0; - - if(ok) - dev->isCheckpointed = 1; - else - dev->isCheckpointed = 0; + + + if (!yaffs_CheckpointClose(dev)) + ok = 0; + + if (ok) + dev->isCheckpointed = 1; + else + dev->isCheckpointed = 0; return dev->isCheckpointed; } @@ -4654,44 +4605,44 @@ static int yaffs_WriteCheckpointData(yaffs_Device *dev) static int yaffs_ReadCheckpointData(yaffs_Device *dev) { int ok = 1; - - if(dev->skipCheckpointRead || !dev->isYaffs2){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("skipping checkpoint read" TENDSTR))); + + if (dev->skipCheckpointRead || !dev->isYaffs2) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("skipping checkpoint read" TENDSTR))); ok = 0; } - - if(ok) - ok = yaffs_CheckpointOpen(dev,0); /* open for read */ - - if(ok){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint validity" TENDSTR))); - ok = yaffs_ReadCheckpointValidityMarker(dev,1); + + if (ok) + ok = yaffs_CheckpointOpen(dev, 0); /* open for read */ + + if (ok) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint validity" TENDSTR))); + ok = yaffs_ReadCheckpointValidityMarker(dev, 1); } - if(ok){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint device" TENDSTR))); + if (ok) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint device" TENDSTR))); ok = yaffs_ReadCheckpointDevice(dev); } - if(ok){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint objects" TENDSTR))); + if (ok) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint objects" TENDSTR))); ok = yaffs_ReadCheckpointObjects(dev); } - if(ok){ - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint validity" TENDSTR))); - ok = yaffs_ReadCheckpointValidityMarker(dev,0); + if (ok) { + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint validity" TENDSTR))); + ok = yaffs_ReadCheckpointValidityMarker(dev, 0); } - - if(ok){ + + if (ok) { ok = yaffs_ReadCheckpointSum(dev); - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint checksum %d" TENDSTR),ok)); + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint checksum %d" TENDSTR), ok)); } - if(!yaffs_CheckpointClose(dev)) + if (!yaffs_CheckpointClose(dev)) ok = 0; - if(ok) - dev->isCheckpointed = 1; - else - dev->isCheckpointed = 0; + if (ok) + dev->isCheckpointed = 1; + else + dev->isCheckpointed = 0; return ok ? 1 : 0; @@ -4699,11 +4650,11 @@ static int yaffs_ReadCheckpointData(yaffs_Device *dev) static void yaffs_InvalidateCheckpoint(yaffs_Device *dev) { - if(dev->isCheckpointed || - dev->blocksInCheckpoint > 0){ + if (dev->isCheckpointed || + dev->blocksInCheckpoint > 0) { dev->isCheckpointed = 0; yaffs_CheckpointInvalidateStream(dev); - if(dev->superBlock && dev->markSuperBlockDirty) + if (dev->superBlock && dev->markSuperBlockDirty) dev->markSuperBlockDirty(dev->superBlock); } } @@ -4712,18 +4663,18 @@ static void yaffs_InvalidateCheckpoint(yaffs_Device *dev) int yaffs_CheckpointSave(yaffs_Device *dev) { - T(YAFFS_TRACE_CHECKPOINT,(TSTR("save entry: isCheckpointed %d"TENDSTR),dev->isCheckpointed)); + T(YAFFS_TRACE_CHECKPOINT, (TSTR("save entry: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); yaffs_VerifyObjects(dev); yaffs_VerifyBlocks(dev); yaffs_VerifyFreeChunks(dev); - if(!dev->isCheckpointed) { + if (!dev->isCheckpointed) { yaffs_InvalidateCheckpoint(dev); yaffs_WriteCheckpointData(dev); } - - T(YAFFS_TRACE_ALWAYS,(TSTR("save exit: isCheckpointed %d"TENDSTR),dev->isCheckpointed)); + + T(YAFFS_TRACE_ALWAYS, (TSTR("save exit: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); return dev->isCheckpointed; } @@ -4731,18 +4682,18 @@ int yaffs_CheckpointSave(yaffs_Device *dev) int yaffs_CheckpointRestore(yaffs_Device *dev) { int retval; - T(YAFFS_TRACE_CHECKPOINT,(TSTR("restore entry: isCheckpointed %d"TENDSTR),dev->isCheckpointed)); - + T(YAFFS_TRACE_CHECKPOINT, (TSTR("restore entry: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); + retval = yaffs_ReadCheckpointData(dev); - if(dev->isCheckpointed){ + if (dev->isCheckpointed) { yaffs_VerifyObjects(dev); yaffs_VerifyBlocks(dev); yaffs_VerifyFreeChunks(dev); } - T(YAFFS_TRACE_CHECKPOINT,(TSTR("restore exit: isCheckpointed %d"TENDSTR),dev->isCheckpointed)); - + T(YAFFS_TRACE_CHECKPOINT, (TSTR("restore exit: isCheckpointed %d"TENDSTR), dev->isCheckpointed)); + return retval; } @@ -4756,8 +4707,8 @@ int yaffs_CheckpointRestore(yaffs_Device *dev) * Curve-balls: the first chunk might also be the last chunk. */ -int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset, - int nBytes) +int yaffs_ReadDataFromFile(yaffs_Object *in, __u8 *buffer, loff_t offset, + int nBytes) { int chunk; @@ -4772,13 +4723,13 @@ int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset, dev = in->myDev; while (n > 0) { - //chunk = offset / dev->nDataBytesPerChunk + 1; - //start = offset % dev->nDataBytesPerChunk; - yaffs_AddrToChunk(dev,offset,&chunk,&start); + /* chunk = offset / dev->nDataBytesPerChunk + 1; */ + /* start = offset % dev->nDataBytesPerChunk; */ + yaffs_AddrToChunk(dev, offset, &chunk, &start); chunk++; /* OK now check for the curveball where the start and end are in - * the same chunk. + * the same chunk. */ if ((start + n) < dev->nDataBytesPerChunk) { nToCopy = n; @@ -4849,36 +4800,36 @@ int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset, return nDone; } -int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, - int nBytes, int writeThrough) +int yaffs_WriteDataToFile(yaffs_Object *in, const __u8 *buffer, loff_t offset, + int nBytes, int writeThrough) { int chunk; __u32 start; int nToCopy; - int n = nBytes; - int nDone = 0; - int nToWriteBack; - int startOfWrite = offset; - int chunkWritten = 0; - __u32 nBytesRead; - __u32 chunkStart; + int n = nBytes; + int nDone = 0; + int nToWriteBack; + int startOfWrite = offset; + int chunkWritten = 0; + __u32 nBytesRead; + __u32 chunkStart; yaffs_Device *dev; dev = in->myDev; while (n > 0 && chunkWritten >= 0) { - //chunk = offset / dev->nDataBytesPerChunk + 1; - //start = offset % dev->nDataBytesPerChunk; - yaffs_AddrToChunk(dev,offset,&chunk,&start); - - if(chunk * dev->nDataBytesPerChunk + start != offset || - start >= dev->nDataBytesPerChunk){ - T(YAFFS_TRACE_ERROR,( + /* chunk = offset / dev->nDataBytesPerChunk + 1; */ + /* start = offset % dev->nDataBytesPerChunk; */ + yaffs_AddrToChunk(dev, offset, &chunk, &start); + + if (chunk * dev->nDataBytesPerChunk + start != offset || + start >= dev->nDataBytesPerChunk) { + T(YAFFS_TRACE_ERROR, ( TSTR("AddrToChunk of offset %d gives chunk %d start %d" TENDSTR), - (int)offset, chunk,start)); + (int)offset, chunk, start)); } chunk++; @@ -4896,7 +4847,7 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, chunkStart = ((chunk - 1) * dev->nDataBytesPerChunk); - if(chunkStart > in->variant.fileVariant.fileSize) + if (chunkStart > in->variant.fileVariant.fileSize) nBytesRead = 0; /* Past end of file */ else nBytesRead = in->variant.fileVariant.fileSize - chunkStart; @@ -4908,8 +4859,8 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, nToWriteBack = (nBytesRead > (start + n)) ? nBytesRead : (start + n); - - if(nToWriteBack < 0 || nToWriteBack > dev->nDataBytesPerChunk) + + if (nToWriteBack < 0 || nToWriteBack > dev->nDataBytesPerChunk) YBUG(); } else { @@ -4918,14 +4869,14 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, } if (nToCopy != dev->nDataBytesPerChunk || dev->inbandTags) { - /* An incomplete start or end chunk (or maybe both start and end chunk), + /* An incomplete start or end chunk (or maybe both start and end chunk), * or we're using inband tags, so we want to use the cache buffers. */ if (dev->nShortOpCaches > 0) { yaffs_ChunkCache *cache; /* If we can't find the data in the cache, then load the cache */ cache = yaffs_FindChunkCache(in, chunk); - + if (!cache && yaffs_CheckSpaceForAllocation(in-> myDev)) { @@ -4937,13 +4888,12 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, yaffs_ReadChunkDataFromObject(in, chunk, cache-> data); - } - else if(cache && - !cache->dirty && - !yaffs_CheckSpaceForAllocation(in->myDev)){ + } else if (cache && + !cache->dirty && + !yaffs_CheckSpaceForAllocation(in->myDev)) { /* Drop the cache if it was a read cache item and * no space check has been made for it. - */ + */ cache = NULL; } @@ -5000,7 +4950,7 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, } else { /* A full chunk. Write directly from the supplied buffer. */ - + chunkWritten = @@ -5035,7 +4985,7 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, /* ---------------------- File resizing stuff ------------------ */ -static void yaffs_PruneResizedChunks(yaffs_Object * in, int newSize) +static void yaffs_PruneResizedChunks(yaffs_Object *in, int newSize) { yaffs_Device *dev = in->myDev; @@ -5076,13 +5026,13 @@ static void yaffs_PruneResizedChunks(yaffs_Object * in, int newSize) } -int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) +int yaffs_ResizeFile(yaffs_Object *in, loff_t newSize) { int oldFileSize = in->variant.fileVariant.fileSize; __u32 newSizeOfPartialChunk; int newFullChunks; - + yaffs_Device *dev = in->myDev; yaffs_AddrToChunk(dev, newSize, &newFullChunks, &newSizeOfPartialChunk); @@ -5090,23 +5040,23 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) yaffs_FlushFilesChunkCache(in); yaffs_InvalidateWholeChunkCache(in); - yaffs_CheckGarbageCollection(dev); + yaffs_CheckGarbageCollection(dev); - if (in->variantType != YAFFS_OBJECT_TYPE_FILE) { - return YAFFS_FAIL; - } + if (in->variantType != YAFFS_OBJECT_TYPE_FILE) { + return YAFFS_FAIL; + } - if (newSize == oldFileSize) { - return YAFFS_OK; - } + if (newSize == oldFileSize) { + return YAFFS_OK; + } - if (newSize < oldFileSize) { + if (newSize < oldFileSize) { yaffs_PruneResizedChunks(in, newSize); if (newSizeOfPartialChunk != 0) { int lastChunk = 1 + newFullChunks; - + __u8 *localBuffer = yaffs_GetTempBuffer(dev, __LINE__); /* Got to read and rewrite the last chunk with its new size and zero pad */ @@ -5130,8 +5080,7 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) in->variant.fileVariant.fileSize = newSize; } - - + /* Write a new object header. * show we've shrunk the file, if need be * Do this only if the file is not in the deleted directories. @@ -5146,7 +5095,7 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) return YAFFS_OK; } -loff_t yaffs_GetFileSize(yaffs_Object * obj) +loff_t yaffs_GetFileSize(yaffs_Object *obj) { obj = yaffs_GetEquivalentObject(obj); @@ -5162,7 +5111,7 @@ loff_t yaffs_GetFileSize(yaffs_Object * obj) -int yaffs_FlushFile(yaffs_Object * in, int updateTime) +int yaffs_FlushFile(yaffs_Object *in, int updateTime) { int retVal; if (in->dirty) { @@ -5177,9 +5126,8 @@ int yaffs_FlushFile(yaffs_Object * in, int updateTime) #endif } - retVal = - (yaffs_UpdateObjectHeader(in, NULL, 0, 0, 0) >= - 0) ? YAFFS_OK : YAFFS_FAIL; + retVal = (yaffs_UpdateObjectHeader(in, NULL, 0, 0, 0) >= + 0) ? YAFFS_OK : YAFFS_FAIL; } else { retVal = YAFFS_OK; } @@ -5188,7 +5136,7 @@ int yaffs_FlushFile(yaffs_Object * in, int updateTime) } -static int yaffs_DoGenericObjectDeletion(yaffs_Object * in) +static int yaffs_DoGenericObjectDeletion(yaffs_Object *in) { /* First off, invalidate the file's data in the cache, without flushing. */ @@ -5196,7 +5144,7 @@ static int yaffs_DoGenericObjectDeletion(yaffs_Object * in) if (in->myDev->isYaffs2 && (in->parent != in->myDev->deletedDir)) { /* Move to the unlinked directory so we have a record that it was deleted. */ - yaffs_ChangeObjectName(in, in->myDev->deletedDir,_Y("deleted"), 0, 0); + yaffs_ChangeObjectName(in, in->myDev->deletedDir, _Y("deleted"), 0, 0); } @@ -5213,7 +5161,7 @@ static int yaffs_DoGenericObjectDeletion(yaffs_Object * in) * and the inode associated with the file. * It does not delete the links associated with the file. */ -static int yaffs_UnlinkFileIfNeeded(yaffs_Object * in) +static int yaffs_UnlinkFileIfNeeded(yaffs_Object *in) { int retVal; @@ -5252,12 +5200,12 @@ static int yaffs_UnlinkFileIfNeeded(yaffs_Object * in) return retVal; } -int yaffs_DeleteFile(yaffs_Object * in) +int yaffs_DeleteFile(yaffs_Object *in) { int retVal = YAFFS_OK; int deleted = in->deleted; - - yaffs_ResizeFile(in,0); + + yaffs_ResizeFile(in, 0); if (in->nDataChunks > 0) { /* Use soft deletion if there is data in the file. @@ -5282,34 +5230,34 @@ int yaffs_DeleteFile(yaffs_Object * in) } } -static int yaffs_DeleteDirectory(yaffs_Object * in) +static int yaffs_DeleteDirectory(yaffs_Object *in) { - /* First check that the directory is empty. */ - if (ylist_empty(&in->variant.directoryVariant.children)) { - return yaffs_DoGenericObjectDeletion(in); - } + /* First check that the directory is empty. */ + if (ylist_empty(&in->variant.directoryVariant.children)) { + return yaffs_DoGenericObjectDeletion(in); + } return YAFFS_FAIL; } -static int yaffs_DeleteSymLink(yaffs_Object * in) +static int yaffs_DeleteSymLink(yaffs_Object *in) { YFREE(in->variant.symLinkVariant.alias); return yaffs_DoGenericObjectDeletion(in); } -static int yaffs_DeleteHardLink(yaffs_Object * in) +static int yaffs_DeleteHardLink(yaffs_Object *in) { - /* remove this hardlink from the list assocaited with the equivalent - * object - */ - ylist_del_init(&in->hardLinks); - return yaffs_DoGenericObjectDeletion(in); + /* remove this hardlink from the list assocaited with the equivalent + * object + */ + ylist_del_init(&in->hardLinks); + return yaffs_DoGenericObjectDeletion(in); } -int yaffs_DeleteObject(yaffs_Object * obj) +int yaffs_DeleteObject(yaffs_Object *obj) { int retVal = -1; switch (obj->variantType) { @@ -5336,7 +5284,7 @@ int retVal = -1; return retVal; } -static int yaffs_UnlinkWorker(yaffs_Object * obj) +static int yaffs_UnlinkWorker(yaffs_Object *obj) { int immediateDeletion = 0; @@ -5369,15 +5317,15 @@ static int yaffs_UnlinkWorker(yaffs_Object * obj) */ yaffs_Object *hl; - int retVal; - YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; + int retVal; + YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; - hl = ylist_entry(obj->hardLinks.next, yaffs_Object, hardLinks); + hl = ylist_entry(obj->hardLinks.next, yaffs_Object, hardLinks); - ylist_del_init(&hl->hardLinks); - ylist_del_init(&hl->siblings); + ylist_del_init(&hl->hardLinks); + ylist_del_init(&hl->siblings); - yaffs_GetObjectName(hl, name, YAFFS_MAX_NAME_LENGTH + 1); + yaffs_GetObjectName(hl, name, YAFFS_MAX_NAME_LENGTH + 1); retVal = yaffs_ChangeObjectName(obj, hl->parent, name, 0, 0); @@ -5412,7 +5360,7 @@ static int yaffs_UnlinkWorker(yaffs_Object * obj) } -static int yaffs_UnlinkObject( yaffs_Object *obj) +static int yaffs_UnlinkObject(yaffs_Object *obj) { if (obj && obj->unlinkAllowed) { @@ -5422,7 +5370,7 @@ static int yaffs_UnlinkObject( yaffs_Object *obj) return YAFFS_FAIL; } -int yaffs_Unlink(yaffs_Object * dir, const YCHAR * name) +int yaffs_Unlink(yaffs_Object *dir, const YCHAR *name) { yaffs_Object *obj; @@ -5432,8 +5380,8 @@ int yaffs_Unlink(yaffs_Object * dir, const YCHAR * name) /*----------------------- Initialisation Scanning ---------------------- */ -static void yaffs_HandleShadowedObject(yaffs_Device * dev, int objId, - int backwardScanning) +static void yaffs_HandleShadowedObject(yaffs_Device *dev, int objId, + int backwardScanning) { yaffs_Object *obj; @@ -5475,7 +5423,7 @@ static void yaffs_HardlinkFixup(yaffs_Device *dev, yaffs_Object *hardList) { yaffs_Object *hl; yaffs_Object *in; - + while (hardList) { hl = hardList; hardList = (yaffs_Object *) (hardList->hardLinks.next); @@ -5484,37 +5432,35 @@ static void yaffs_HardlinkFixup(yaffs_Device *dev, yaffs_Object *hardList) hl->variant.hardLinkVariant. equivalentObjectId); - if (in) { - /* Add the hardlink pointers */ - hl->variant.hardLinkVariant.equivalentObject = in; - ylist_add(&hl->hardLinks, &in->hardLinks); - } else { - /* Todo Need to report/handle this better. - * Got a problem... hardlink to a non-existant object - */ - hl->variant.hardLinkVariant.equivalentObject = NULL; - YINIT_LIST_HEAD(&hl->hardLinks); - - } + if (in) { + /* Add the hardlink pointers */ + hl->variant.hardLinkVariant.equivalentObject = in; + ylist_add(&hl->hardLinks, &in->hardLinks); + } else { + /* Todo Need to report/handle this better. + * Got a problem... hardlink to a non-existant object + */ + hl->variant.hardLinkVariant.equivalentObject = NULL; + YINIT_LIST_HEAD(&hl->hardLinks); + } } - } -static int ybicmp(const void *a, const void *b){ - register int aseq = ((yaffs_BlockIndex *)a)->seq; - register int bseq = ((yaffs_BlockIndex *)b)->seq; - register int ablock = ((yaffs_BlockIndex *)a)->block; - register int bblock = ((yaffs_BlockIndex *)b)->block; - if( aseq == bseq ) - return ablock - bblock; - else - return aseq - bseq; - +static int ybicmp(const void *a, const void *b) +{ + register int aseq = ((yaffs_BlockIndex *)a)->seq; + register int bseq = ((yaffs_BlockIndex *)b)->seq; + register int ablock = ((yaffs_BlockIndex *)a)->block; + register int bblock = ((yaffs_BlockIndex *)b)->block; + if (aseq == bseq) + return ablock - bblock; + else + return aseq - bseq; } @@ -5542,7 +5488,7 @@ static void yaffs_StripDeletedObjects(yaffs_Device *dev) yaffs_DeleteObject(l); } } - + ylist_for_each_safe(i, n, &dev->deletedDir->variant.directoryVariant.children) { if (i) { @@ -5553,7 +5499,7 @@ static void yaffs_StripDeletedObjects(yaffs_Device *dev) } -static int yaffs_Scan(yaffs_Device * dev) +static int yaffs_Scan(yaffs_Device *dev) { yaffs_ExtendedTags tags; int blk; @@ -5572,16 +5518,16 @@ static int yaffs_Scan(yaffs_Device * dev) yaffs_ObjectHeader *oh; yaffs_Object *in; yaffs_Object *parent; - + int alloc_failed = 0; - + struct yaffs_ShadowFixerStruct *shadowFixerList = NULL; - + __u8 *chunkData; - - + + T(YAFFS_TRACE_SCAN, (TSTR("yaffs_Scan starts intstartblk %d intendblk %d..." TENDSTR), dev->internalStartBlock, dev->internalEndBlock)); @@ -5602,7 +5548,7 @@ static int yaffs_Scan(yaffs_Device * dev) bi->blockState = state; bi->sequenceNumber = sequenceNumber; - if(bi->sequenceNumber == YAFFS_SEQUENCE_BAD_BLOCK) + if (bi->sequenceNumber == YAFFS_SEQUENCE_BAD_BLOCK) bi->blockState = state = YAFFS_BLOCK_STATE_DEAD; T(YAFFS_TRACE_SCAN_DEBUG, @@ -5617,7 +5563,7 @@ static int yaffs_Scan(yaffs_Device * dev) (TSTR("Block empty " TENDSTR))); dev->nErasedBlocks++; dev->nFreeChunks += dev->nChunksPerBlock; - } + } } startIterator = dev->internalStartBlock; @@ -5626,11 +5572,11 @@ static int yaffs_Scan(yaffs_Device * dev) /* For each block.... */ for (blockIterator = startIterator; !alloc_failed && blockIterator <= endIterator; blockIterator++) { - + + YYIELD(); + YYIELD(); - YYIELD(); - blk = blockIterator; bi = yaffs_GetBlockInfo(dev, blk); @@ -5658,7 +5604,7 @@ static int yaffs_Scan(yaffs_Device * dev) /*T((" %d %d deleted\n",blk,c)); */ } else if (!tags.chunkUsed) { /* An unassigned chunk in the block - * This means that either the block is empty or + * This means that either the block is empty or * this is the one being allocated from */ @@ -5675,9 +5621,9 @@ static int yaffs_Scan(yaffs_Device * dev) state = YAFFS_BLOCK_STATE_ALLOCATING; dev->allocationBlock = blk; dev->allocationPage = c; - dev->allocationBlockFinder = blk; + dev->allocationBlockFinder = blk; /* Set it to here to encourage the allocator to go forth from here. */ - + } dev->nFreeChunks += (dev->nChunksPerBlock - c); @@ -5695,19 +5641,19 @@ static int yaffs_Scan(yaffs_Device * dev) /* PutChunkIntoFile checks for a clash (two data chunks with * the same chunkId). */ - - if(!in) + + if (!in) alloc_failed = 1; - if(in){ - if(!yaffs_PutChunkIntoFile(in, tags.chunkId, chunk,1)) + if (in) { + if (!yaffs_PutChunkIntoFile(in, tags.chunkId, chunk, 1)) alloc_failed = 1; } - + endpos = (tags.chunkId - 1) * dev->nDataBytesPerChunk + tags.byteCount; - if (in && + if (in && in->variantType == YAFFS_OBJECT_TYPE_FILE && in->variant.fileVariant.scannedFileSize < endpos) { @@ -5739,7 +5685,7 @@ static int yaffs_Scan(yaffs_Device * dev) tags.objectId); if (in && in->variantType != oh->type) { /* This should not happen, but somehow - * Wev'e ended up with an objectId that has been reused but not yet + * Wev'e ended up with an objectId that has been reused but not yet * deleted, and worse still it has changed type. Delete the old object. */ @@ -5753,20 +5699,20 @@ static int yaffs_Scan(yaffs_Device * dev) objectId, oh->type); - if(!in) + if (!in) alloc_failed = 1; - + if (in && oh->shadowsObject > 0) { - + struct yaffs_ShadowFixerStruct *fixer; fixer = YMALLOC(sizeof(struct yaffs_ShadowFixerStruct)); - if(fixer){ - fixer-> next = shadowFixerList; + if (fixer) { + fixer->next = shadowFixerList; shadowFixerList = fixer; fixer->objectId = tags.objectId; fixer->shadowedId = oh->shadowsObject; } - + } if (in && in->valid) { @@ -5850,19 +5796,18 @@ static int yaffs_Scan(yaffs_Device * dev) yaffs_FindOrCreateObjectByNumber (dev, oh->parentObjectId, YAFFS_OBJECT_TYPE_DIRECTORY); - if(!parent) + if (!parent) alloc_failed = 1; if (parent && parent->variantType == YAFFS_OBJECT_TYPE_UNKNOWN) { - /* Set up as a directory */ - parent->variantType = - YAFFS_OBJECT_TYPE_DIRECTORY; - YINIT_LIST_HEAD(&parent->variant. - directoryVariant. - children); - } else if (!parent || parent->variantType != - YAFFS_OBJECT_TYPE_DIRECTORY) - { + /* Set up as a directory */ + parent->variantType = + YAFFS_OBJECT_TYPE_DIRECTORY; + YINIT_LIST_HEAD(&parent->variant. + directoryVariant. + children); + } else if (!parent || parent->variantType != + YAFFS_OBJECT_TYPE_DIRECTORY) { /* Hoosterman, another problem.... * We're trying to use a non-directory as a directory */ @@ -5885,11 +5830,11 @@ static int yaffs_Scan(yaffs_Device * dev) * Since we might scan a hardlink before its equivalent object is scanned * we put them all in a list. * After scanning is complete, we should have all the objects, so we run through this - * list and fix up all the chains. + * list and fix up all the chains. */ switch (in->variantType) { - case YAFFS_OBJECT_TYPE_UNKNOWN: + case YAFFS_OBJECT_TYPE_UNKNOWN: /* Todo got a problem */ break; case YAFFS_OBJECT_TYPE_FILE: @@ -5902,29 +5847,29 @@ static int yaffs_Scan(yaffs_Device * dev) break; case YAFFS_OBJECT_TYPE_HARDLINK: in->variant.hardLinkVariant. - equivalentObjectId = - oh->equivalentObjectId; - in->hardLinks.next = - (struct ylist_head *) - hardList; - hardList = in; - break; + equivalentObjectId = + oh->equivalentObjectId; + in->hardLinks.next = + (struct ylist_head *) + hardList; + hardList = in; + break; case YAFFS_OBJECT_TYPE_DIRECTORY: /* Do nothing */ break; case YAFFS_OBJECT_TYPE_SPECIAL: /* Do nothing */ break; - case YAFFS_OBJECT_TYPE_SYMLINK: + case YAFFS_OBJECT_TYPE_SYMLINK: in->variant.symLinkVariant.alias = yaffs_CloneString(oh->alias); - if(!in->variant.symLinkVariant.alias) + if (!in->variant.symLinkVariant.alias) alloc_failed = 1; break; } /* - if (parent == dev->deletedDir) { + if (parent == dev->deletedDir) { yaffs_DestroyObject(in); bi->hasShrinkHeader = 1; } @@ -5949,47 +5894,47 @@ static int yaffs_Scan(yaffs_Device * 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 + * We should now have scanned all the objects, now it's time to add these * hardlinks. */ - yaffs_HardlinkFixup(dev,hardList); - + yaffs_HardlinkFixup(dev, hardList); + /* Fix up any shadowed objects */ { struct yaffs_ShadowFixerStruct *fixer; yaffs_Object *obj; - - while(shadowFixerList){ + + while (shadowFixerList) { fixer = shadowFixerList; shadowFixerList = fixer->next; /* Complete the rename transaction by deleting the shadowed object * then setting the object header to unshadowed. */ - obj = yaffs_FindObjectByNumber(dev,fixer->shadowedId); + obj = yaffs_FindObjectByNumber(dev, fixer->shadowedId); if(obj) yaffs_DeleteObject(obj); - obj = yaffs_FindObjectByNumber(dev,fixer->objectId); + obj = yaffs_FindObjectByNumber(dev, fixer->objectId); if(obj){ - yaffs_UpdateObjectHeader(obj,NULL,1,0,0); + yaffs_UpdateObjectHeader(obj, NULL, 1, 0, 0); } - + YFREE(fixer); } } yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__); - if(alloc_failed){ + if (alloc_failed) { return YAFFS_FAIL; } - + T(YAFFS_TRACE_SCAN, (TSTR("yaffs_Scan ends" TENDSTR))); - + return YAFFS_OK; } @@ -6003,22 +5948,22 @@ static void yaffs_CheckObjectDetailsLoaded(yaffs_Object *in) int result; int alloc_failed = 0; - if(!in) + if (!in) return; - + dev = in->myDev; - + #if 0 - T(YAFFS_TRACE_SCAN,(TSTR("details for object %d %s loaded" TENDSTR), + T(YAFFS_TRACE_SCAN, (TSTR("details for object %d %s loaded" TENDSTR), in->objectId, in->lazyLoaded ? "not yet" : "already")); #endif - if(in->lazyLoaded && in->hdrChunk > 0){ + if (in->lazyLoaded && in->hdrChunk > 0) { in->lazyLoaded = 0; chunkData = yaffs_GetTempBuffer(dev, __LINE__); - result = yaffs_ReadChunkWithTagsFromNAND(dev,in->hdrChunk,chunkData,&tags); + result = yaffs_ReadChunkWithTagsFromNAND(dev, in->hdrChunk, chunkData, &tags); oh = (yaffs_ObjectHeader *) chunkData; in->yst_mode = oh->yst_mode; @@ -6036,22 +5981,22 @@ static void yaffs_CheckObjectDetailsLoaded(yaffs_Object *in) in->yst_mtime = oh->yst_mtime; in->yst_ctime = oh->yst_ctime; in->yst_rdev = oh->yst_rdev; - + #endif yaffs_SetObjectName(in, oh->name); - - if(in->variantType == YAFFS_OBJECT_TYPE_SYMLINK){ + + if (in->variantType == YAFFS_OBJECT_TYPE_SYMLINK) { in->variant.symLinkVariant.alias = yaffs_CloneString(oh->alias); - if(!in->variant.symLinkVariant.alias) + if (!in->variant.symLinkVariant.alias) alloc_failed = 1; /* Not returned to caller */ } - - yaffs_ReleaseTempBuffer(dev,chunkData, __LINE__); + + yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__); } } -static int yaffs_ScanBackwards(yaffs_Device * dev) +static int yaffs_ScanBackwards(yaffs_Device *dev) { yaffs_ExtendedTags tags; int blk; @@ -6074,13 +6019,13 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) int nBlocks = dev->internalEndBlock - dev->internalStartBlock + 1; int itsUnlinked; __u8 *chunkData; - + int fileSize; int isShrink; int foundChunksInBlock; int equivalentObjectId; int alloc_failed = 0; - + yaffs_BlockIndex *blockIndex = NULL; int altBlockIndex = 0; @@ -6100,20 +6045,20 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) dev->sequenceNumber = YAFFS_LOWEST_SEQUENCE_NUMBER; blockIndex = YMALLOC(nBlocks * sizeof(yaffs_BlockIndex)); - - if(!blockIndex) { + + if (!blockIndex) { blockIndex = YMALLOC_ALT(nBlocks * sizeof(yaffs_BlockIndex)); altBlockIndex = 1; } - - if(!blockIndex) { + + if (!blockIndex) { T(YAFFS_TRACE_SCAN, (TSTR("yaffs_Scan() could not allocate block index!" TENDSTR))); return YAFFS_FAIL; } - + dev->blocksInCheckpoint = 0; - + chunkData = yaffs_GetTempBuffer(dev, __LINE__); /* Scan all the blocks to determine their state */ @@ -6128,19 +6073,19 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) bi->blockState = state; bi->sequenceNumber = sequenceNumber; - if(bi->sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA) + if (bi->sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA) bi->blockState = state = YAFFS_BLOCK_STATE_CHECKPOINT; - if(bi->sequenceNumber == YAFFS_SEQUENCE_BAD_BLOCK) + if (bi->sequenceNumber == YAFFS_SEQUENCE_BAD_BLOCK) bi->blockState = state = YAFFS_BLOCK_STATE_DEAD; - + T(YAFFS_TRACE_SCAN_DEBUG, (TSTR("Block scanning block %d state %d seq %d" TENDSTR), blk, state, sequenceNumber)); - - if(state == YAFFS_BLOCK_STATE_CHECKPOINT){ + + if (state == YAFFS_BLOCK_STATE_CHECKPOINT) { dev->blocksInCheckpoint++; - + } else if (state == YAFFS_BLOCK_STATE_DEAD) { T(YAFFS_TRACE_BAD_BLOCKS, (TSTR("block %d is bad" TENDSTR), blk)); @@ -6189,8 +6134,8 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) } #else { - /* Dungy old bubble sort... */ - + /* Dungy old bubble sort... */ + yaffs_BlockIndex temp; int i; int j; @@ -6207,7 +6152,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) YYIELD(); - T(YAFFS_TRACE_SCAN, (TSTR("...done" TENDSTR))); + T(YAFFS_TRACE_SCAN, (TSTR("...done" TENDSTR))); /* Now scan the blocks looking at the data. */ startIterator = 0; @@ -6217,31 +6162,31 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* For each block.... backwards */ for (blockIterator = endIterator; !alloc_failed && blockIterator >= startIterator; - blockIterator--) { - /* Cooperative multitasking! This loop can run for so + blockIterator--) { + /* Cooperative multitasking! This loop can run for so long that watchdog timers expire. */ - YYIELD(); + YYIELD(); /* get the block to scan in the correct order */ blk = blockIndex[blockIterator].block; bi = yaffs_GetBlockInfo(dev, blk); - - + + state = bi->blockState; deleted = 0; /* For each chunk in each block that needs scanning.... */ foundChunksInBlock = 0; - for (c = dev->nChunksPerBlock - 1; + for (c = dev->nChunksPerBlock - 1; !alloc_failed && c >= 0 && (state == YAFFS_BLOCK_STATE_NEEDS_SCANNING || state == YAFFS_BLOCK_STATE_ALLOCATING); c--) { - /* Scan backwards... + /* Scan backwards... * Read the tags and decide what to do */ - + chunk = blk * dev->nChunksPerBlock + c; result = yaffs_ReadChunkWithTagsFromNAND(dev, chunk, NULL, @@ -6255,14 +6200,12 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) * it is a chunk that was skipped due to failing the erased * check. Just skip it so that it can be deleted. * But, more typically, We get here when this is an unallocated - * chunk and his means that either the block is empty or + * chunk and his means that either the block is empty or * this is the one being allocated from */ - if(foundChunksInBlock) - { + if (foundChunksInBlock) { /* This is a chunk that was skipped due to failing the erased check */ - } else if (c == 0) { /* We're looking at the first chunk in the block so the block is unused */ state = YAFFS_BLOCK_STATE_EMPTY; @@ -6270,9 +6213,9 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) } else { if (state == YAFFS_BLOCK_STATE_NEEDS_SCANNING || state == YAFFS_BLOCK_STATE_ALLOCATING) { - if(dev->sequenceNumber == bi->sequenceNumber) { + if (dev->sequenceNumber == bi->sequenceNumber) { /* this is the block being allocated from */ - + T(YAFFS_TRACE_SCAN, (TSTR (" Allocating from %d %d" @@ -6281,41 +6224,38 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) state = YAFFS_BLOCK_STATE_ALLOCATING; dev->allocationBlock = blk; dev->allocationPage = c; - dev->allocationBlockFinder = blk; - } - else { + dev->allocationBlockFinder = blk; + } else { /* This is a partially written block that is not * the current allocation block. This block must have * had a write failure, so set up for retirement. */ - + /* bi->needsRetiring = 1; ??? TODO */ bi->gcPrioritise = 1; - + T(YAFFS_TRACE_ALWAYS, (TSTR("Partially written block %d detected" TENDSTR), blk)); } - } - } dev->nFreeChunks++; - - } else if (tags.eccResult == YAFFS_ECC_RESULT_UNFIXED){ + + } else if (tags.eccResult == YAFFS_ECC_RESULT_UNFIXED) { T(YAFFS_TRACE_SCAN, (TSTR(" Unfixed ECC in chunk(%d:%d), chunk ignored"TENDSTR), blk, c)); dev->nFreeChunks++; - }else if (tags.chunkId > 0) { + } else if (tags.chunkId > 0) { /* chunkId > 0 so it is a data chunk... */ unsigned int endpos; __u32 chunkBase = (tags.chunkId - 1) * dev->nDataBytesPerChunk; - + foundChunksInBlock = 1; @@ -6326,29 +6266,29 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) tags. objectId, YAFFS_OBJECT_TYPE_FILE); - if(!in){ + if (!in) { /* Out of memory */ alloc_failed = 1; } - + if (in && in->variantType == YAFFS_OBJECT_TYPE_FILE && chunkBase < in->variant.fileVariant.shrinkSize) { /* This has not been invalidated by a resize */ - if(!yaffs_PutChunkIntoFile(in, tags.chunkId, - chunk, -1)){ + if (!yaffs_PutChunkIntoFile(in, tags.chunkId, + chunk, -1)) { alloc_failed = 1; } - /* File size is calculated by looking at the data chunks if we have not + /* File size is calculated by looking at the data chunks if we have not * seen an object header yet. Stop this practice once we find an object header. */ endpos = (tags.chunkId - 1) * dev->nDataBytesPerChunk + tags.byteCount; - + if (!in->valid && /* have not got an object header yet */ in->variant.fileVariant. scannedFileSize < endpos) { @@ -6360,7 +6300,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) scannedFileSize; } - } else if(in) { + } else if (in) { /* This chunk has been invalidated by a resize, so delete */ yaffs_DeleteChunk(dev, chunk, 1, __LINE__); @@ -6392,11 +6332,10 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) tags.extraShadows || (!in->valid && (tags.objectId == YAFFS_OBJECTID_ROOT || - tags.objectId == YAFFS_OBJECTID_LOSTNFOUND)) - ) { + tags.objectId == YAFFS_OBJECTID_LOSTNFOUND))) { /* If we don't have valid info then we need to read the chunk - * TODO In future we can probably defer reading the chunk and + * TODO In future we can probably defer reading the chunk and * living with invalid data until needed. */ @@ -6406,8 +6345,8 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) NULL); oh = (yaffs_ObjectHeader *) chunkData; - - if(dev->inbandTags){ + + if (dev->inbandTags) { /* Fix up the header if they got corrupted by inband tags */ oh->shadowsObject = oh->inbandShadowsObject; oh->isShrink = oh->inbandIsShrink; @@ -6432,16 +6371,15 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) if (in->valid) { /* We have already filled this one. - * We have a duplicate that will be discarded, but + * We have a duplicate that will be discarded, but * we first have to suck out resize info if it is a file. */ - if ((in->variantType == YAFFS_OBJECT_TYPE_FILE) && - ((oh && - oh-> type == YAFFS_OBJECT_TYPE_FILE)|| + if ((in->variantType == YAFFS_OBJECT_TYPE_FILE) && + ((oh && + oh->type == YAFFS_OBJECT_TYPE_FILE) || (tags.extraHeaderInfoAvailable && - tags.extraObjectType == YAFFS_OBJECT_TYPE_FILE)) - ) { + tags.extraObjectType == YAFFS_OBJECT_TYPE_FILE))) { __u32 thisSize = (oh) ? oh->fileSize : tags. extraFileLength; @@ -6449,8 +6387,8 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) (oh) ? oh-> parentObjectId : tags. extraParentObjectId; - - + + isShrink = (oh) ? oh->isShrink : tags. extraIsShrinkHeader; @@ -6501,8 +6439,8 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) YAFFS_OBJECTID_LOSTNFOUND)) { /* We only load some info, don't fiddle with directory structure */ in->valid = 1; - - if(oh) { + + if (oh) { in->variantType = oh->type; in->yst_mode = oh->yst_mode; @@ -6520,7 +6458,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) in->yst_mtime = oh->yst_mtime; in->yst_ctime = oh->yst_ctime; in->yst_rdev = oh->yst_rdev; - + #endif } else { in->variantType = tags.extraObjectType; @@ -6535,7 +6473,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) in->valid = 1; in->hdrChunk = chunk; - if(oh) { + if (oh) { in->variantType = oh->type; in->yst_mode = oh->yst_mode; @@ -6555,30 +6493,29 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) in->yst_rdev = oh->yst_rdev; #endif - if (oh->shadowsObject > 0) + if (oh->shadowsObject > 0) yaffs_HandleShadowedObject(dev, oh-> shadowsObject, 1); - + yaffs_SetObjectName(in, oh->name); parent = yaffs_FindOrCreateObjectByNumber - (dev, oh->parentObjectId, - YAFFS_OBJECT_TYPE_DIRECTORY); + (dev, oh->parentObjectId, + YAFFS_OBJECT_TYPE_DIRECTORY); fileSize = oh->fileSize; - isShrink = oh->isShrink; + isShrink = oh->isShrink; equivalentObjectId = oh->equivalentObjectId; - } - else { + } else { in->variantType = tags.extraObjectType; parent = yaffs_FindOrCreateObjectByNumber - (dev, tags.extraParentObjectId, - YAFFS_OBJECT_TYPE_DIRECTORY); + (dev, tags.extraParentObjectId, + YAFFS_OBJECT_TYPE_DIRECTORY); fileSize = tags.extraFileLength; isShrink = tags.extraIsShrinkHeader; equivalentObjectId = tags.extraEquivalentObjectId; @@ -6596,15 +6533,14 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) if (parent && parent->variantType == YAFFS_OBJECT_TYPE_UNKNOWN) { - /* Set up as a directory */ - parent->variantType = - YAFFS_OBJECT_TYPE_DIRECTORY; - YINIT_LIST_HEAD(&parent->variant. - directoryVariant. - children); - } else if (!parent || parent->variantType != - YAFFS_OBJECT_TYPE_DIRECTORY) - { + /* Set up as a directory */ + parent->variantType = + YAFFS_OBJECT_TYPE_DIRECTORY; + YINIT_LIST_HEAD(&parent->variant. + directoryVariant. + children); + } else if (!parent || parent->variantType != + YAFFS_OBJECT_TYPE_DIRECTORY) { /* Hoosterman, another problem.... * We're trying to use a non-directory as a directory */ @@ -6630,11 +6566,11 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) * Since we might scan a hardlink before its equivalent object is scanned * we put them all in a list. * After scanning is complete, we should have all the objects, so we run - * through this list and fix up all the chains. + * through this list and fix up all the chains. */ switch (in->variantType) { - case YAFFS_OBJECT_TYPE_UNKNOWN: + case YAFFS_OBJECT_TYPE_UNKNOWN: /* Todo got a problem */ break; case YAFFS_OBJECT_TYPE_FILE: @@ -6643,7 +6579,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) scannedFileSize < fileSize) { /* This covers the case where the file size is greater * than where the data is - * This will happen if the file is resized to be larger + * This will happen if the file is resized to be larger * than its current data extents. */ in->variant.fileVariant.fileSize = fileSize; @@ -6658,14 +6594,14 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) break; case YAFFS_OBJECT_TYPE_HARDLINK: - if(!itsUnlinked) { - in->variant.hardLinkVariant.equivalentObjectId = - equivalentObjectId; - in->hardLinks.next = - (struct ylist_head *) hardList; - hardList = in; - } - break; + if (!itsUnlinked) { + in->variant.hardLinkVariant.equivalentObjectId = + equivalentObjectId; + in->hardLinks.next = + (struct ylist_head *) hardList; + hardList = in; + } + break; case YAFFS_OBJECT_TYPE_DIRECTORY: /* Do nothing */ break; @@ -6673,18 +6609,17 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* Do nothing */ break; case YAFFS_OBJECT_TYPE_SYMLINK: - if(oh){ - in->variant.symLinkVariant.alias = - yaffs_CloneString(oh-> - alias); - if(!in->variant.symLinkVariant.alias) - alloc_failed = 1; + if (oh) { + in->variant.symLinkVariant.alias = + yaffs_CloneString(oh->alias); + if (!in->variant.symLinkVariant.alias) + alloc_failed = 1; } break; } } - + } } /* End of scanning for each chunk */ @@ -6705,22 +6640,22 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) } - if (altBlockIndex) + if (altBlockIndex) YFREE_ALT(blockIndex); else YFREE(blockIndex); - + /* 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 + * We should now have scanned all the objects, now it's time to add these * hardlinks. */ - yaffs_HardlinkFixup(dev,hardList); - + yaffs_HardlinkFixup(dev, hardList); + yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__); - - if(alloc_failed){ + + if (alloc_failed) { return YAFFS_FAIL; } @@ -6733,111 +6668,105 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) static void yaffs_VerifyObjectInDirectory(yaffs_Object *obj) { - struct ylist_head *lh; - yaffs_Object *listObj; - - int count = 0; + struct ylist_head *lh; + yaffs_Object *listObj; - if(!obj){ + int count = 0; + + if (!obj) { T(YAFFS_TRACE_ALWAYS, (TSTR("No object to verify" TENDSTR))); YBUG(); return; } - if(yaffs_SkipVerification(obj->myDev)) - return; + if (yaffs_SkipVerification(obj->myDev)) + return; - if(!obj->parent){ + if (!obj->parent) { T(YAFFS_TRACE_ALWAYS, (TSTR("Object does not have parent" TENDSTR))); YBUG(); return; } - - if(obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY){ + + if (obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) { T(YAFFS_TRACE_ALWAYS, (TSTR("Parent is not directory" TENDSTR))); YBUG(); } - - /* Iterate through the objects in each hash entry */ - - ylist_for_each(lh, &obj->parent->variant.directoryVariant.children) { + + /* Iterate through the objects in each hash entry */ + + ylist_for_each(lh, &obj->parent->variant.directoryVariant.children) { if (lh) { - listObj = ylist_entry(lh, yaffs_Object, siblings); + listObj = ylist_entry(lh, yaffs_Object, siblings); yaffs_VerifyObject(listObj); - if(obj == listObj) - count ++; - } + if (obj == listObj) + count++; + } } - - if(count != 1){ - T(YAFFS_TRACE_ALWAYS, (TSTR("Object in directory %d times" TENDSTR),count)); + + if (count != 1) { + T(YAFFS_TRACE_ALWAYS, (TSTR("Object in directory %d times" TENDSTR), count)); YBUG(); } - } static void yaffs_VerifyDirectory(yaffs_Object *directory) { - - struct ylist_head *lh; - yaffs_Object *listObj; + struct ylist_head *lh; + yaffs_Object *listObj; - if(!directory){ + if (!directory) { YBUG(); return; } - if(yaffs_SkipFullVerification(directory->myDev)) - return; + if (yaffs_SkipFullVerification(directory->myDev)) + return; - - if(directory->variantType != YAFFS_OBJECT_TYPE_DIRECTORY){ - T(YAFFS_TRACE_ALWAYS, (TSTR("Directory has wrong type: %d" TENDSTR),directory->variantType)); + if (directory->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) { + T(YAFFS_TRACE_ALWAYS, (TSTR("Directory has wrong type: %d" TENDSTR), directory->variantType)); YBUG(); } - - /* Iterate through the objects in each hash entry */ - - ylist_for_each(lh, &directory->variant.directoryVariant.children) { + + /* Iterate through the objects in each hash entry */ + + ylist_for_each(lh, &directory->variant.directoryVariant.children) { if (lh) { - listObj = ylist_entry(lh, yaffs_Object, siblings); - if(listObj->parent != directory){ - T(YAFFS_TRACE_ALWAYS, (TSTR("Object in directory list has wrong parent %p" TENDSTR),listObj->parent)); + listObj = ylist_entry(lh, yaffs_Object, siblings); + if (listObj->parent != directory) { + T(YAFFS_TRACE_ALWAYS, (TSTR("Object in directory list has wrong parent %p" TENDSTR), listObj->parent)); YBUG(); } yaffs_VerifyObjectInDirectory(listObj); - } - } - + } + } } -static void yaffs_RemoveObjectFromDirectory(yaffs_Object * obj) +static void yaffs_RemoveObjectFromDirectory(yaffs_Object *obj) { yaffs_Device *dev = obj->myDev; yaffs_Object *parent; - - yaffs_VerifyObjectInDirectory(obj); + + yaffs_VerifyObjectInDirectory(obj); parent = obj->parent; - + yaffs_VerifyDirectory(parent); - if(dev && dev->removeObjectCallback) - dev->removeObjectCallback(obj); + if (dev && dev->removeObjectCallback) + dev->removeObjectCallback(obj); - - ylist_del_init(&obj->siblings); - obj->parent = NULL; - yaffs_VerifyDirectory(parent); + ylist_del_init(&obj->siblings); + obj->parent = NULL; + yaffs_VerifyDirectory(parent); } -static void yaffs_AddObjectToDirectory(yaffs_Object * directory, - yaffs_Object * obj) +static void yaffs_AddObjectToDirectory(yaffs_Object *directory, + yaffs_Object *obj) { - if (!directory) { T(YAFFS_TRACE_ALWAYS, (TSTR @@ -6854,43 +6783,41 @@ static void yaffs_AddObjectToDirectory(yaffs_Object * directory, YBUG(); } - if (obj->siblings.prev == NULL) { - /* Not initialised */ - YBUG(); + if (obj->siblings.prev == NULL) { + /* Not initialised */ + YBUG(); + } - } yaffs_VerifyDirectory(directory); yaffs_RemoveObjectFromDirectory(obj); - - - /* Now add it */ - ylist_add(&obj->siblings, &directory->variant.directoryVariant.children); - obj->parent = directory; - if (directory == obj->myDev->unlinkedDir - || directory == obj->myDev->deletedDir) { + + /* Now add it */ + ylist_add(&obj->siblings, &directory->variant.directoryVariant.children); + obj->parent = directory; + + if (directory == obj->myDev->unlinkedDir + || directory == obj->myDev->deletedDir) { obj->unlinked = 1; obj->myDev->nUnlinkedFiles++; obj->renameAllowed = 0; } yaffs_VerifyDirectory(directory); - yaffs_VerifyObjectInDirectory(obj); - - + yaffs_VerifyObjectInDirectory(obj); } -yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, - const YCHAR * name) +yaffs_Object *yaffs_FindObjectByName(yaffs_Object *directory, + const YCHAR *name) { - int sum; + int sum; - struct ylist_head *i; - YCHAR buffer[YAFFS_MAX_NAME_LENGTH + 1]; + struct ylist_head *i; + YCHAR buffer[YAFFS_MAX_NAME_LENGTH + 1]; - yaffs_Object *l; + yaffs_Object *l; if (!name) { return NULL; @@ -6911,32 +6838,31 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, YBUG(); } - sum = yaffs_CalcNameSum(name); + sum = yaffs_CalcNameSum(name); + + ylist_for_each(i, &directory->variant.directoryVariant.children) { + if (i) { + l = ylist_entry(i, yaffs_Object, siblings); + + if (l->parent != directory) + YBUG(); - ylist_for_each(i, &directory->variant.directoryVariant.children) { - if (i) { - l = ylist_entry(i, yaffs_Object, siblings); - - if(l->parent != directory) - YBUG(); - - yaffs_CheckObjectDetailsLoaded(l); + yaffs_CheckObjectDetailsLoaded(l); /* Special case for lost-n-found */ if (l->objectId == YAFFS_OBJECTID_LOSTNFOUND) { if (yaffs_strcmp(name, YAFFS_LOSTNFOUND_NAME) == 0) { return l; } - } else if (yaffs_SumCompare(l->sum, sum) || l->hdrChunk <= 0){ + } else if (yaffs_SumCompare(l->sum, sum) || l->hdrChunk <= 0) { /* LostnFound chunk called Objxxx * Do a real check */ yaffs_GetObjectName(l, buffer, YAFFS_MAX_NAME_LENGTH); - if (yaffs_strncmp(name, buffer,YAFFS_MAX_NAME_LENGTH) == 0) { + if (yaffs_strncmp(name, buffer, YAFFS_MAX_NAME_LENGTH) == 0) { return l; } - } } } @@ -6946,13 +6872,13 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, #if 0 -int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, - int (*fn) (yaffs_Object *)) +int yaffs_ApplyToDirectoryChildren(yaffs_Object *theDir, + int (*fn) (yaffs_Object *)) { - struct ylist_head *i; - yaffs_Object *l; + struct ylist_head *i; + yaffs_Object *l; - if (!theDir) { + if (!theDir) { T(YAFFS_TRACE_ALWAYS, (TSTR ("tragedy: yaffs_FindObjectByName: null pointer directory" @@ -6968,12 +6894,12 @@ int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, return YAFFS_FAIL; } - ylist_for_each(i, &theDir->variant.directoryVariant.children) { - if (i) { - l = ylist_entry(i, yaffs_Object, siblings); - if (l && !fn(l)) { - return YAFFS_FAIL; - } + ylist_for_each(i, &theDir->variant.directoryVariant.children) { + if (i) { + l = ylist_entry(i, yaffs_Object, siblings); + if (l && !fn(l)) { + return YAFFS_FAIL; + } } } @@ -6986,7 +6912,7 @@ int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, * actual object. */ -yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object * obj) +yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object *obj) { if (obj && obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) { /* We want the object id of the equivalent object, not this one */ @@ -6994,13 +6920,12 @@ yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object * obj) yaffs_CheckObjectDetailsLoaded(obj); } return obj; - } -int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize) +int yaffs_GetObjectName(yaffs_Object *obj, YCHAR *name, int buffSize) { memset(name, 0, buffSize * sizeof(YCHAR)); - + yaffs_CheckObjectDetailsLoaded(obj); if (obj->objectId == YAFFS_OBJECTID_LOSTNFOUND) { @@ -7011,14 +6936,14 @@ int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize) YCHAR *x = &numString[19]; unsigned v = obj->objectId; numString[19] = 0; - while(v>0){ + while (v > 0) { x--; *x = '0' + (v % 10); v /= 10; } /* make up a name */ yaffs_strcpy(locName, YAFFS_LOSTNFOUND_PREFIX); - yaffs_strcat(locName,x); + yaffs_strcat(locName, x); yaffs_strncpy(name, locName, buffSize - 1); } @@ -7048,9 +6973,8 @@ int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize) return yaffs_strlen(name); } -int yaffs_GetObjectFileLength(yaffs_Object * obj) +int yaffs_GetObjectFileLength(yaffs_Object *obj) { - /* Dereference any hard linking */ obj = yaffs_GetEquivalentObject(obj); @@ -7065,29 +6989,28 @@ int yaffs_GetObjectFileLength(yaffs_Object * obj) } } -int yaffs_GetObjectLinkCount(yaffs_Object * obj) +int yaffs_GetObjectLinkCount(yaffs_Object *obj) { - int count = 0; - struct ylist_head *i; - - if (!obj->unlinked) { - count++; /* the object itself */ - } - ylist_for_each(i, &obj->hardLinks) { - count++; /* add the hard links; */ - } - return count; + int count = 0; + struct ylist_head *i; + if (!obj->unlinked) { + count++; /* the object itself */ + } + ylist_for_each(i, &obj->hardLinks) { + count++; /* add the hard links; */ + } + return count; } -int yaffs_GetObjectInode(yaffs_Object * obj) +int yaffs_GetObjectInode(yaffs_Object *obj) { obj = yaffs_GetEquivalentObject(obj); return obj->objectId; } -unsigned yaffs_GetObjectType(yaffs_Object * obj) +unsigned yaffs_GetObjectType(yaffs_Object *obj) { obj = yaffs_GetEquivalentObject(obj); @@ -7119,7 +7042,7 @@ unsigned yaffs_GetObjectType(yaffs_Object * obj) } } -YCHAR *yaffs_GetSymlinkAlias(yaffs_Object * obj) +YCHAR *yaffs_GetSymlinkAlias(yaffs_Object *obj) { obj = yaffs_GetEquivalentObject(obj); if (obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK) { @@ -7131,7 +7054,7 @@ YCHAR *yaffs_GetSymlinkAlias(yaffs_Object * obj) #ifndef CONFIG_YAFFS_WINCE -int yaffs_SetAttributes(yaffs_Object * obj, struct iattr *attr) +int yaffs_SetAttributes(yaffs_Object *obj, struct iattr *attr) { unsigned int valid = attr->ia_valid; @@ -7157,7 +7080,7 @@ int yaffs_SetAttributes(yaffs_Object * obj, struct iattr *attr) return YAFFS_OK; } -int yaffs_GetAttributes(yaffs_Object * obj, struct iattr *attr) +int yaffs_GetAttributes(yaffs_Object *obj, struct iattr *attr) { unsigned int valid = 0; @@ -7181,13 +7104,12 @@ int yaffs_GetAttributes(yaffs_Object * obj, struct iattr *attr) attr->ia_valid = valid; return YAFFS_OK; - } #endif #if 0 -int yaffs_DumpObject(yaffs_Object * obj) +int yaffs_DumpObject(yaffs_Object *obj) { YCHAR name[257]; @@ -7207,7 +7129,7 @@ int yaffs_DumpObject(yaffs_Object * obj) /*---------------------------- Initialisation code -------------------------------------- */ -static int yaffs_CheckDevFunctions(const yaffs_Device * dev) +static int yaffs_CheckDevFunctions(const yaffs_Device *dev) { /* Common functions, gotta have */ @@ -7241,13 +7163,13 @@ static int yaffs_CheckDevFunctions(const yaffs_Device * dev) static int yaffs_CreateInitialDirectories(yaffs_Device *dev) { /* Initialise the unlinked, deleted, root and lost and found directories */ - + dev->lostNFoundDir = dev->rootDir = NULL; dev->unlinkedDir = dev->deletedDir = NULL; dev->unlinkedDir = yaffs_CreateFakeDirectory(dev, YAFFS_OBJECTID_UNLINKED, S_IFDIR); - + dev->deletedDir = yaffs_CreateFakeDirectory(dev, YAFFS_OBJECTID_DELETED, S_IFDIR); @@ -7257,16 +7179,16 @@ static int yaffs_CreateInitialDirectories(yaffs_Device *dev) dev->lostNFoundDir = yaffs_CreateFakeDirectory(dev, YAFFS_OBJECTID_LOSTNFOUND, YAFFS_LOSTNFOUND_MODE | S_IFDIR); - - if(dev->lostNFoundDir && dev->rootDir && dev->unlinkedDir && dev->deletedDir){ + + if (dev->lostNFoundDir && dev->rootDir && dev->unlinkedDir && dev->deletedDir) { yaffs_AddObjectToDirectory(dev->rootDir, dev->lostNFoundDir); return YAFFS_OK; } - + return YAFFS_FAIL; } -int yaffs_GutsInitialise(yaffs_Device * dev) +int yaffs_GutsInitialise(yaffs_Device *dev) { int init_failed = 0; unsigned x; @@ -7286,7 +7208,7 @@ int yaffs_GutsInitialise(yaffs_Device * dev) dev->blockOffset = 0; dev->chunkOffset = 0; dev->nFreeChunks = 0; - + dev->gcBlock = -1; if (dev->startBlock == 0) { @@ -7298,15 +7220,14 @@ int yaffs_GutsInitialise(yaffs_Device * dev) /* Check geometry parameters. */ - if ((!dev->inbandTags && dev->isYaffs2 && dev->totalBytesPerChunk < 1024) || - (!dev->isYaffs2 && dev->totalBytesPerChunk < 512) || - (dev->inbandTags && !dev->isYaffs2 ) || - dev->nChunksPerBlock < 2 || - dev->nReservedBlocks < 2 || - dev->internalStartBlock <= 0 || - dev->internalEndBlock <= 0 || - dev->internalEndBlock <= (dev->internalStartBlock + dev->nReservedBlocks + 2) // otherwise it is too small - ) { + if ((!dev->inbandTags && dev->isYaffs2 && dev->totalBytesPerChunk < 1024) || + (!dev->isYaffs2 && dev->totalBytesPerChunk < 512) || + (dev->inbandTags && !dev->isYaffs2) || + dev->nChunksPerBlock < 2 || + dev->nReservedBlocks < 2 || + dev->internalStartBlock <= 0 || + dev->internalEndBlock <= 0 || + dev->internalEndBlock <= (dev->internalStartBlock + dev->nReservedBlocks + 2)) { /* otherwise it is too small */ T(YAFFS_TRACE_ALWAYS, (TSTR ("yaffs: NAND geometry problems: chunk size %d, type is yaffs%s, inbandTags %d " @@ -7319,11 +7240,11 @@ int yaffs_GutsInitialise(yaffs_Device * dev) (TSTR("yaffs: InitialiseNAND failed" TENDSTR))); return YAFFS_FAIL; } - + /* Sort out space for inband tags, if required */ - if(dev->inbandTags) + if (dev->inbandTags) dev->nDataBytesPerChunk = dev->totalBytesPerChunk - sizeof(yaffs_PackedTags2TagsPart); - else + else dev->nDataBytesPerChunk = dev->totalBytesPerChunk; /* Got the right mix of functions? */ @@ -7354,9 +7275,9 @@ int yaffs_GutsInitialise(yaffs_Device * dev) dev->isMounted = 1; /* OK now calculate a few things for the device */ - + /* - * Calculate all the chunk size manipulation numbers: + * Calculate all the chunk size manipulation numbers: */ x = dev->nDataBytesPerChunk; /* We always use dev->chunkShift and dev->chunkDiv */ @@ -7365,42 +7286,41 @@ int yaffs_GutsInitialise(yaffs_Device * dev) dev->chunkDiv = x; /* We only use chunk mask if chunkDiv is 1 */ dev->chunkMask = (1<chunkShift) - 1; - + /* * Calculate chunkGroupBits. * We need to find the next power of 2 > than internalEndBlock */ x = dev->nChunksPerBlock * (dev->internalEndBlock + 1); - + bits = ShiftsGE(x); - + /* Set up tnode width if wide tnodes are enabled. */ - if(!dev->wideTnodesDisabled){ + if (!dev->wideTnodesDisabled) { /* bits must be even so that we end up with 32-bit words */ - if(bits & 1) + if (bits & 1) bits++; - if(bits < 16) + if (bits < 16) dev->tnodeWidth = 16; else dev->tnodeWidth = bits; - } - else + } else dev->tnodeWidth = 16; - + dev->tnodeMask = (1<tnodeWidth)-1; - + /* Level0 Tnodes are 16 bits or wider (if wide tnodes are enabled), * so if the bitwidth of the * chunk range we're using is greater than 16 we need * to figure out chunk shift and chunkGroupSize */ - + if (bits <= dev->tnodeWidth) dev->chunkGroupBits = 0; else dev->chunkGroupBits = bits - dev->tnodeWidth; - + dev->chunkGroupSize = 1 << dev->chunkGroupBits; @@ -7436,13 +7356,13 @@ int yaffs_GutsInitialise(yaffs_Device * dev) dev->hasPendingPrioritisedGCs = 1; /* Assume the worst for now, will get fixed on first GC */ /* Initialise temporary buffers and caches. */ - if(!yaffs_InitialiseTempBuffers(dev)) + if (!yaffs_InitialiseTempBuffers(dev)) init_failed = 1; - + dev->srCache = NULL; dev->gcCleanupList = NULL; - - + + if (!init_failed && dev->nShortOpCaches > 0) { int i; @@ -7454,62 +7374,62 @@ int yaffs_GutsInitialise(yaffs_Device * dev) } dev->srCache = YMALLOC(srCacheBytes); - + buf = (__u8 *) dev->srCache; - - if(dev->srCache) - memset(dev->srCache,0,srCacheBytes); - + + if (dev->srCache) + memset(dev->srCache, 0, srCacheBytes); + for (i = 0; i < dev->nShortOpCaches && buf; i++) { dev->srCache[i].object = NULL; dev->srCache[i].lastUse = 0; dev->srCache[i].dirty = 0; dev->srCache[i].data = buf = YMALLOC_DMA(dev->totalBytesPerChunk); } - if(!buf) + if (!buf) init_failed = 1; - + dev->srLastUse = 0; } dev->cacheHits = 0; - - if(!init_failed){ + + if (!init_failed) { dev->gcCleanupList = YMALLOC(dev->nChunksPerBlock * sizeof(__u32)); - if(!dev->gcCleanupList) + if (!dev->gcCleanupList) init_failed = 1; } if (dev->isYaffs2) { dev->useHeaderFileSize = 1; } - if(!init_failed && !yaffs_InitialiseBlocks(dev)) + if (!init_failed && !yaffs_InitialiseBlocks(dev)) init_failed = 1; - + yaffs_InitialiseTnodes(dev); yaffs_InitialiseObjects(dev); - if(!init_failed && !yaffs_CreateInitialDirectories(dev)) + if (!init_failed && !yaffs_CreateInitialDirectories(dev)) init_failed = 1; - if(!init_failed){ + if (!init_failed) { /* Now scan the flash. */ if (dev->isYaffs2) { - if(yaffs_CheckpointRestore(dev)) { + if (yaffs_CheckpointRestore(dev)) { yaffs_CheckObjectDetailsLoaded(dev->rootDir); T(YAFFS_TRACE_ALWAYS, (TSTR("yaffs: restored from checkpoint" TENDSTR))); } else { - /* Clean up the mess caused by an aborted checkpoint load - * and scan backwards. + /* Clean up the mess caused by an aborted checkpoint load + * and scan backwards. */ yaffs_DeinitialiseBlocks(dev); yaffs_DeinitialiseTnodes(dev); yaffs_DeinitialiseObjects(dev); - - + + dev->nErasedBlocks = 0; dev->nFreeChunks = 0; dev->allocationBlock = -1; @@ -7519,26 +7439,25 @@ int yaffs_GutsInitialise(yaffs_Device * dev) dev->nBackgroundDeletions = 0; dev->oldestDirtySequence = 0; - if(!init_failed && !yaffs_InitialiseBlocks(dev)) + if (!init_failed && !yaffs_InitialiseBlocks(dev)) init_failed = 1; - + yaffs_InitialiseTnodes(dev); yaffs_InitialiseObjects(dev); - if(!init_failed && !yaffs_CreateInitialDirectories(dev)) + if (!init_failed && !yaffs_CreateInitialDirectories(dev)) init_failed = 1; - if(!init_failed && !yaffs_ScanBackwards(dev)) + if (!init_failed && !yaffs_ScanBackwards(dev)) init_failed = 1; } - }else - if(!yaffs_Scan(dev)) + } else if (!yaffs_Scan(dev)) init_failed = 1; yaffs_StripDeletedObjects(dev); } - - if(init_failed){ + + if (init_failed) { /* Clean up the mess */ T(YAFFS_TRACE_TRACING, (TSTR("yaffs: yaffs_GutsInitialise() aborted.\n" TENDSTR))); @@ -7558,7 +7477,7 @@ int yaffs_GutsInitialise(yaffs_Device * dev) yaffs_VerifyFreeChunks(dev); yaffs_VerifyBlocks(dev); - + T(YAFFS_TRACE_TRACING, (TSTR("yaffs: yaffs_GutsInitialise() done.\n" TENDSTR))); @@ -7566,7 +7485,7 @@ int yaffs_GutsInitialise(yaffs_Device * dev) } -void yaffs_Deinitialise(yaffs_Device * dev) +void yaffs_Deinitialise(yaffs_Device *dev) { if (dev->isMounted) { int i; @@ -7578,7 +7497,7 @@ void yaffs_Deinitialise(yaffs_Device * dev) dev->srCache) { for (i = 0; i < dev->nShortOpCaches; i++) { - if(dev->srCache[i].data) + if (dev->srCache[i].data) YFREE(dev->srCache[i].data); dev->srCache[i].data = NULL; } @@ -7595,14 +7514,13 @@ void yaffs_Deinitialise(yaffs_Device * dev) dev->isMounted = 0; - - if(dev->deinitialiseNAND) + + if (dev->deinitialiseNAND) dev->deinitialiseNAND(dev); } - } -static int yaffs_CountFreeChunks(yaffs_Device * dev) +static int yaffs_CountFreeChunks(yaffs_Device *dev) { int nFree; int b; @@ -7610,7 +7528,7 @@ static int yaffs_CountFreeChunks(yaffs_Device * dev) yaffs_BlockInfo *blk; for (nFree = 0, b = dev->internalStartBlock; b <= dev->internalEndBlock; - b++) { + b++) { blk = yaffs_GetBlockInfo(dev, b); switch (blk->blockState) { @@ -7625,13 +7543,12 @@ static int yaffs_CountFreeChunks(yaffs_Device * dev) default: break; } - } return nFree; } -int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev) +int yaffs_GetNumberOfFreeChunks(yaffs_Device *dev) { /* This is what we report to the outside world */ @@ -7646,7 +7563,7 @@ int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev) #endif nFree += dev->nDeletedFiles; - + /* Now count the number of dirty chunks in the cache and subtract those */ { @@ -7660,12 +7577,12 @@ int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev) nFree -= nDirtyCacheChunks; nFree -= ((dev->nReservedBlocks + 1) * dev->nChunksPerBlock); - + /* Now we figure out how much to reserve for the checkpoint and report that... */ blocksForCheckpoint = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; - if(blocksForCheckpoint < 0) + if (blocksForCheckpoint < 0) blocksForCheckpoint = 0; - + nFree -= (blocksForCheckpoint * dev->nChunksPerBlock); if (nFree < 0) @@ -7677,14 +7594,14 @@ int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev) static int yaffs_freeVerificationFailures; -static void yaffs_VerifyFreeChunks(yaffs_Device * dev) +static void yaffs_VerifyFreeChunks(yaffs_Device *dev) { int counted; int difference; - - if(yaffs_SkipVerification(dev)) + + if (yaffs_SkipVerification(dev)) return; - + counted = yaffs_CountFreeChunks(dev); difference = dev->nFreeChunks - counted; @@ -7699,15 +7616,14 @@ static void yaffs_VerifyFreeChunks(yaffs_Device * dev) /*---------------------------------------- YAFFS test code ----------------------*/ -#define yaffs_CheckStruct(structure,syze, name) \ +#define yaffs_CheckStruct(structure, syze, name) \ do { \ - if(sizeof(structure) != syze) \ - { \ - T(YAFFS_TRACE_ALWAYS,(TSTR("%s should be %d but is %d\n" TENDSTR),\ - name,syze,sizeof(structure))); \ - return YAFFS_FAIL; \ + if (sizeof(structure) != syze) { \ + T(YAFFS_TRACE_ALWAYS, (TSTR("%s should be %d but is %d\n" TENDSTR),\ + name, syze, sizeof(structure))); \ + return YAFFS_FAIL; \ } \ - } while(0) + } while (0) static int yaffs_CheckStructures(void) { @@ -7715,10 +7631,10 @@ static int yaffs_CheckStructures(void) /* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion"); */ /* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare"); */ #ifndef CONFIG_YAFFS_TNODE_LIST_DEBUG - yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode"); + yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode"); #endif #ifndef CONFIG_YAFFS_WINCE - yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader"); + yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader"); #endif - return YAFFS_OK; + return YAFFS_OK; } diff --git a/yaffs_guts.h b/yaffs_guts.h index bef284f..a3b1102 100644 --- a/yaffs_guts.h +++ b/yaffs_guts.h @@ -1,5 +1,5 @@ /* - * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. * * Copyright (C) 2002-2007 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering @@ -22,11 +22,11 @@ #define YAFFS_OK 1 #define YAFFS_FAIL 0 -/* Give us a Y=0x59, - * Give us an A=0x41, - * Give us an FF=0xFF +/* Give us a Y=0x59, + * Give us an A=0x41, + * Give us an FF=0xFF * Give us an S=0x53 - * And what have we got... + * And what have we got... */ #define YAFFS_MAGIC 0x5941FF53 @@ -102,7 +102,7 @@ * The range is limited slightly to help distinguish bad numbers from good. * This also allows us to perhaps in the future use special numbers for * special purposes. - * EFFFFF00 allows the allocation of 8 blocks per second (~1Mbytes) for 15 years, + * EFFFFF00 allows the allocation of 8 blocks per second (~1Mbytes) for 15 years, * and is a larger number than the lifetime of a 2GB device. */ #define YAFFS_LOWEST_SEQUENCE_NUMBER 0x00001000 @@ -135,13 +135,12 @@ typedef struct { #ifndef CONFIG_YAFFS_NO_YAFFS1 typedef struct { - unsigned chunkId:20; - unsigned serialNumber:2; - unsigned byteCountLSB:10; - unsigned objectId:18; - unsigned ecc:12; - unsigned byteCountMSB:2; - + unsigned chunkId:20; + unsigned serialNumber:2; + unsigned byteCountLSB:10; + unsigned objectId:18; + unsigned ecc:12; + unsigned byteCountMSB:2; } yaffs_Tags; typedef union { @@ -181,7 +180,7 @@ typedef struct { /* The following stuff only has meaning when we read */ yaffs_ECCResult eccResult; - unsigned blockBad; + unsigned blockBad; /* YAFFS 1 stuff */ unsigned chunkDeleted; /* The chunk is marked deleted */ @@ -247,29 +246,29 @@ typedef enum { /* This block is empty */ YAFFS_BLOCK_STATE_ALLOCATING, - /* This block is partially allocated. + /* This block is partially allocated. * At least one page holds valid data. * This is the one currently being used for page * allocation. Should never be more than one of these */ - YAFFS_BLOCK_STATE_FULL, + YAFFS_BLOCK_STATE_FULL, /* All the pages in this block have been allocated. */ YAFFS_BLOCK_STATE_DIRTY, - /* All pages have been allocated and deleted. + /* All pages have been allocated and deleted. * Erase me, reuse me. */ - YAFFS_BLOCK_STATE_CHECKPOINT, + YAFFS_BLOCK_STATE_CHECKPOINT, /* This block is assigned to holding checkpoint data. */ - YAFFS_BLOCK_STATE_COLLECTING, + YAFFS_BLOCK_STATE_COLLECTING, /* This block is being garbage collected */ - YAFFS_BLOCK_STATE_DEAD + YAFFS_BLOCK_STATE_DEAD /* This block has failed and is not in use */ } yaffs_BlockState; @@ -282,11 +281,11 @@ typedef struct { int pagesInUse:10; /* number of pages in use */ unsigned blockState:4; /* One of the above block states. NB use unsigned because enum is sometimes an int */ __u32 needsRetiring:1; /* Data has failed on this block, need to get valid data off */ - /* and retire the block. */ - __u32 skipErasedCheck: 1; /* If this is set we can skip the erased check on this block */ - __u32 gcPrioritise: 1; /* An ECC check or blank check has failed on this block. + /* and retire the block. */ + __u32 skipErasedCheck:1; /* If this is set we can skip the erased check on this block */ + __u32 gcPrioritise:1; /* An ECC check or blank check has failed on this block. It should be prioritised for GC */ - __u32 chunkErrorStrikes:3; /* How many times we've had ecc etc failures on this block and tried to reuse it */ + __u32 chunkErrorStrikes:3; /* How many times we've had ecc etc failures on this block and tried to reuse it */ #ifdef CONFIG_YAFFS_YAFFS2 __u32 hasShrinkHeader:1; /* This block has at least one shrink object header */ @@ -303,11 +302,11 @@ typedef struct { /* Apply to everything */ int parentObjectId; - __u16 sum__NoLongerUsed; /* checksum of name. No longer used */ - YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; + __u16 sum__NoLongerUsed; /* checksum of name. No longer used */ + YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; - /* The following apply to directories, files, symlinks - not hard links */ - __u32 yst_mode; /* protection */ + /* The following apply to directories, files, symlinks - not hard links */ + __u32 yst_mode; /* protection */ #ifdef CONFIG_YAFFS_WINCE __u32 notForWinCE[5]; @@ -387,7 +386,7 @@ typedef struct { } yaffs_FileStructure; typedef struct { - struct ylist_head children; /* list of child links */ + struct ylist_head children; /* list of child links */ } yaffs_DirectoryStructure; typedef struct { @@ -414,7 +413,7 @@ struct yaffs_ObjectStruct { __u8 renameAllowed:1; /* Some objects are not allowed to be renamed. */ __u8 unlinkAllowed:1; __u8 dirty:1; /* the object needs to be written to flash */ - __u8 valid:1; /* When the file system is being loaded up, this + __u8 valid:1; /* When the file system is being loaded up, this * object might be created before the data * is available (ie. file data records appear before the header). */ @@ -423,22 +422,22 @@ struct yaffs_ObjectStruct { __u8 deferedFree:1; /* For Linux kernel. Object is removed from NAND, but is * still in the inode cache. Free of object is defered. * until the inode is released. - */ - __u8 beingCreated:1; /* This object is still being created so skip some checks. */ + */ + __u8 beingCreated:1; /* This object is still being created so skip some checks. */ __u8 serial; /* serial number of chunk in NAND. Cached here */ __u16 sum; /* sum of the name to speed searching */ - struct yaffs_DeviceStruct *myDev; /* The device I'm on */ + struct yaffs_DeviceStruct *myDev; /* The device I'm on */ - struct ylist_head hashLink; /* list of objects in this hash bucket */ + struct ylist_head hashLink; /* list of objects in this hash bucket */ - struct ylist_head hardLinks; /* all the equivalent hard linked objects */ + struct ylist_head hardLinks; /* all the equivalent hard linked objects */ - /* directory structure stuff */ - /* also used for linking up the free list */ - struct yaffs_ObjectStruct *parent; - struct ylist_head siblings; + /* directory structure stuff */ + /* also used for linking up the free list */ + struct yaffs_ObjectStruct *parent; + struct ylist_head siblings; /* Where's my object header in NAND? */ int hdrChunk; @@ -492,33 +491,32 @@ struct yaffs_ObjectList_struct { typedef struct yaffs_ObjectList_struct yaffs_ObjectList; typedef struct { - struct ylist_head list; - int count; + struct ylist_head list; + int count; } yaffs_ObjectBucket; -/* yaffs_CheckpointObject holds the definition of an object as dumped +/* yaffs_CheckpointObject holds the definition of an object as dumped * by checkpointing. */ typedef struct { - int structType; - __u32 objectId; + int structType; + __u32 objectId; __u32 parentId; int hdrChunk; yaffs_ObjectType variantType:3; - __u8 deleted:1; - __u8 softDeleted:1; - __u8 unlinked:1; - __u8 fake:1; + __u8 deleted:1; + __u8 softDeleted:1; + __u8 unlinked:1; + __u8 fake:1; __u8 renameAllowed:1; __u8 unlinkAllowed:1; - __u8 serial; - - int nDataChunks; - __u32 fileSizeOrEquivalentObjectId; + __u8 serial; -}yaffs_CheckpointObject; + int nDataChunks; + __u32 fileSizeOrEquivalentObjectId; +} yaffs_CheckpointObject; /*--------------------- Temporary buffers ---------------- * @@ -534,25 +532,23 @@ typedef struct { /*----------------- Device ---------------------------------*/ struct yaffs_DeviceStruct { - struct ylist_head devList; - const char *name; - - /* Entry parameters set up way early. Yaffs sets up the rest.*/ - int nDataBytesPerChunk; /* Should be a power of 2 >= 512 */ - int nChunksPerBlock; /* does not need to be a power of 2 */ - int spareBytesPerChunk;/* spare area size */ - int startBlock; /* Start block we're allowed to use */ - int endBlock; /* End block we're allowed to use */ - int nReservedBlocks; /* We want this tuneable so that we can reduce */ + struct ylist_head devList; + const char *name; + + /* Entry parameters set up way early. Yaffs sets up the rest.*/ + int nDataBytesPerChunk; /* Should be a power of 2 >= 512 */ + int nChunksPerBlock; /* does not need to be a power of 2 */ + int spareBytesPerChunk; /* spare area size */ + int startBlock; /* Start block we're allowed to use */ + int endBlock; /* End block we're allowed to use */ + int nReservedBlocks; /* We want this tuneable so that we can reduce */ /* reserved blocks on NOR and RAM. */ - - + + /* Stuff used by the shared space checkpointing mechanism */ /* If this value is zero, then this mechanism is disabled */ - -// int nCheckpointReservedBlocks; /* Blocks to reserve for checkpoint data */ - +/* int nCheckpointReservedBlocks; */ /* Blocks to reserve for checkpoint data */ int nShortOpCaches; /* If <= 0, then short op caching is disabled, else @@ -566,51 +562,51 @@ struct yaffs_DeviceStruct { void *genericDevice; /* Pointer to device context * On an mtd this holds the mtd pointer. */ - void *superBlock; - + void *superBlock; + /* NAND access functions (Must be set before calling YAFFS)*/ - int (*writeChunkToNAND) (struct yaffs_DeviceStruct * dev, - int chunkInNAND, const __u8 * data, - const yaffs_Spare * spare); - int (*readChunkFromNAND) (struct yaffs_DeviceStruct * dev, - int chunkInNAND, __u8 * data, - yaffs_Spare * spare); - int (*eraseBlockInNAND) (struct yaffs_DeviceStruct * dev, - int blockInNAND); - int (*initialiseNAND) (struct yaffs_DeviceStruct * dev); - int (*deinitialiseNAND) (struct yaffs_DeviceStruct * dev); + int (*writeChunkToNAND) (struct yaffs_DeviceStruct *dev, + int chunkInNAND, const __u8 *data, + const yaffs_Spare *spare); + int (*readChunkFromNAND) (struct yaffs_DeviceStruct *dev, + int chunkInNAND, __u8 *data, + yaffs_Spare *spare); + int (*eraseBlockInNAND) (struct yaffs_DeviceStruct *dev, + int blockInNAND); + int (*initialiseNAND) (struct yaffs_DeviceStruct *dev); + int (*deinitialiseNAND) (struct yaffs_DeviceStruct *dev); #ifdef CONFIG_YAFFS_YAFFS2 - int (*writeChunkWithTagsToNAND) (struct yaffs_DeviceStruct * dev, - int chunkInNAND, const __u8 * data, - const yaffs_ExtendedTags * tags); - int (*readChunkWithTagsFromNAND) (struct yaffs_DeviceStruct * dev, - int chunkInNAND, __u8 * data, - yaffs_ExtendedTags * tags); - int (*markNANDBlockBad) (struct yaffs_DeviceStruct * dev, int blockNo); - int (*queryNANDBlock) (struct yaffs_DeviceStruct * dev, int blockNo, - yaffs_BlockState * state, __u32 *sequenceNumber); + int (*writeChunkWithTagsToNAND) (struct yaffs_DeviceStruct *dev, + int chunkInNAND, const __u8 *data, + const yaffs_ExtendedTags *tags); + int (*readChunkWithTagsFromNAND) (struct yaffs_DeviceStruct *dev, + int chunkInNAND, __u8 *data, + yaffs_ExtendedTags *tags); + int (*markNANDBlockBad) (struct yaffs_DeviceStruct *dev, int blockNo); + int (*queryNANDBlock) (struct yaffs_DeviceStruct *dev, int blockNo, + yaffs_BlockState *state, __u32 *sequenceNumber); #endif int isYaffs2; - - /* The removeObjectCallback function must be supplied by OS flavours that + + /* The removeObjectCallback function must be supplied by OS flavours that * need it. The Linux kernel does not use this, but yaffs direct does use * it to implement the faster readdir */ void (*removeObjectCallback)(struct yaffs_ObjectStruct *obj); - + /* Callback to mark the superblock dirsty */ - void (*markSuperBlockDirty)(void * superblock); - + void (*markSuperBlockDirty)(void *superblock); + int wideTnodesDisabled; /* Set to disable wide tnodes */ - + YCHAR *pathDividers; /* String of legal path dividers */ - + /* End of stuff that must be set before initialisation. */ - + /* Checkpoint control. Can be set before or after initialisation */ __u8 skipCheckpointRead; __u8 skipCheckpointWrite; @@ -619,11 +615,11 @@ struct yaffs_DeviceStruct { __u16 chunkGroupBits; /* 0 for devices <= 32MB. else log2(nchunks) - 16 */ __u16 chunkGroupSize; /* == 2^^chunkGroupBits */ - + /* Stuff to support wide tnodes */ __u32 tnodeWidth; __u32 tnodeMask; - + /* Stuff for figuring out file offset to chunk conversions */ __u32 chunkShift; /* Shift value */ __u32 chunkDiv; /* Divisor after shifting: 1 for power-of-2 sizes */ @@ -637,14 +633,14 @@ struct yaffs_DeviceStruct { struct semaphore sem; /* Semaphore for waiting on erasure.*/ struct semaphore grossLock; /* Gross locking semaphore */ - __u8 *spareBuffer; /* For mtdif2 use. Don't know the size of the buffer + __u8 *spareBuffer; /* For mtdif2 use. Don't know the size of the buffer * at compile time so we have to allocate it. */ - void (*putSuperFunc) (struct super_block * sb); + void (*putSuperFunc) (struct super_block *sb); #endif int isMounted; - + int isCheckpointed; @@ -653,7 +649,7 @@ struct yaffs_DeviceStruct { int internalEndBlock; int blockOffset; int chunkOffset; - + /* Runtime checkpointing stuff */ int checkpointPageSequence; /* running sequence number of checkpoint pages */ @@ -669,15 +665,15 @@ struct yaffs_DeviceStruct { int checkpointMaxBlocks; __u32 checkpointSum; __u32 checkpointXor; - + int nCheckpointBlocksRequired; /* Number of blocks needed to store current checkpoint set */ - + /* Block Info */ yaffs_BlockInfo *blockInfo; __u8 *chunkBits; /* bitmap of chunks in use */ unsigned blockInfoAlt:1; /* was allocated using alternative strategy */ unsigned chunkBitsAlt:1; /* was allocated using alternative strategy */ - int chunkBitmapStride; /* Number of bytes of chunkBits per block. + int chunkBitmapStride; /* Number of bytes of chunkBits per block. * Must be consistent with nChunksPerBlock. */ @@ -699,7 +695,7 @@ struct yaffs_DeviceStruct { int nObjectsCreated; yaffs_Object *freeObjects; int nFreeObjects; - + int nHardLinks; yaffs_ObjectList *allocatedObjectList; @@ -729,7 +725,7 @@ struct yaffs_DeviceStruct { int tagsEccUnfixed; int nDeletions; int nUnmarkedDeletions; - + int hasPendingPrioritisedGCs; /* We think this device might have pending prioritised gcs */ /* Special directories */ @@ -740,7 +736,7 @@ struct yaffs_DeviceStruct { * __u8 bufferedData[YAFFS_CHUNKS_PER_BLOCK][YAFFS_BYTES_PER_CHUNK]; * yaffs_Spare bufferedSpare[YAFFS_CHUNKS_PER_BLOCK]; */ - + int bufferedBlock; /* Which block is buffered here? */ int doingBufferedBlockRewrite; @@ -757,7 +753,7 @@ struct yaffs_DeviceStruct { int nUnlinkedFiles; /* Count of unlinked files. */ int nBackgroundDeletions; /* Count of background deletions. */ - + /* Temporary buffer management */ yaffs_TempBuffer tempBuffer[YAFFS_N_TEMP_BUFFERS]; int maxTemp; @@ -775,20 +771,20 @@ typedef struct yaffs_DeviceStruct yaffs_Device; /* The static layout of block usage etc is stored in the super block header */ typedef struct { - int StructType; - int version; + int StructType; + int version; int checkpointStartBlock; int checkpointEndBlock; int startBlock; int endBlock; int rfu[100]; } yaffs_SuperBlockHeader; - + /* The CheckpointDevice structure holds the device information that changes at runtime and * must be preserved over unmount/mount cycles. */ typedef struct { - int structType; + int structType; int nErasedBlocks; int allocationBlock; /* Current block being allocated off */ __u32 allocationPage; @@ -806,45 +802,45 @@ typedef struct { typedef struct { - int structType; - __u32 magic; - __u32 version; - __u32 head; + int structType; + __u32 magic; + __u32 version; + __u32 head; } yaffs_CheckpointValidity; /*----------------------- YAFFS Functions -----------------------*/ -int yaffs_GutsInitialise(yaffs_Device * dev); -void yaffs_Deinitialise(yaffs_Device * dev); +int yaffs_GutsInitialise(yaffs_Device *dev); +void yaffs_Deinitialise(yaffs_Device *dev); -int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev); +int yaffs_GetNumberOfFreeChunks(yaffs_Device *dev); -int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName, - yaffs_Object * newDir, const YCHAR * newName); +int yaffs_RenameObject(yaffs_Object *oldDir, const YCHAR *oldName, + yaffs_Object *newDir, const YCHAR *newName); -int yaffs_Unlink(yaffs_Object * dir, const YCHAR * name); -int yaffs_DeleteObject(yaffs_Object * obj); +int yaffs_Unlink(yaffs_Object *dir, const YCHAR *name); +int yaffs_DeleteObject(yaffs_Object *obj); -int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize); -int yaffs_GetObjectFileLength(yaffs_Object * obj); -int yaffs_GetObjectInode(yaffs_Object * obj); -unsigned yaffs_GetObjectType(yaffs_Object * obj); -int yaffs_GetObjectLinkCount(yaffs_Object * obj); +int yaffs_GetObjectName(yaffs_Object *obj, YCHAR *name, int buffSize); +int yaffs_GetObjectFileLength(yaffs_Object *obj); +int yaffs_GetObjectInode(yaffs_Object *obj); +unsigned yaffs_GetObjectType(yaffs_Object *obj); +int yaffs_GetObjectLinkCount(yaffs_Object *obj); -int yaffs_SetAttributes(yaffs_Object * obj, struct iattr *attr); -int yaffs_GetAttributes(yaffs_Object * obj, struct iattr *attr); +int yaffs_SetAttributes(yaffs_Object *obj, struct iattr *attr); +int yaffs_GetAttributes(yaffs_Object *obj, struct iattr *attr); /* File operations */ -int yaffs_ReadDataFromFile(yaffs_Object * obj, __u8 * buffer, loff_t offset, - int nBytes); -int yaffs_WriteDataToFile(yaffs_Object * obj, const __u8 * buffer, loff_t offset, - int nBytes, int writeThrough); -int yaffs_ResizeFile(yaffs_Object * obj, loff_t newSize); +int yaffs_ReadDataFromFile(yaffs_Object *obj, __u8 *buffer, loff_t offset, + int nBytes); +int yaffs_WriteDataToFile(yaffs_Object *obj, const __u8 *buffer, loff_t offset, + int nBytes, int writeThrough); +int yaffs_ResizeFile(yaffs_Object *obj, loff_t newSize); -yaffs_Object *yaffs_MknodFile(yaffs_Object * parent, const YCHAR * name, - __u32 mode, __u32 uid, __u32 gid); -int yaffs_FlushFile(yaffs_Object * obj, int updateTime); +yaffs_Object *yaffs_MknodFile(yaffs_Object *parent, const YCHAR *name, + __u32 mode, __u32 uid, __u32 gid); +int yaffs_FlushFile(yaffs_Object *obj, int updateTime); /* Flushing and checkpointing */ void yaffs_FlushEntireDeviceCache(yaffs_Device *dev); @@ -853,33 +849,33 @@ int yaffs_CheckpointSave(yaffs_Device *dev); int yaffs_CheckpointRestore(yaffs_Device *dev); /* Directory operations */ -yaffs_Object *yaffs_MknodDirectory(yaffs_Object * parent, const YCHAR * name, - __u32 mode, __u32 uid, __u32 gid); -yaffs_Object *yaffs_FindObjectByName(yaffs_Object * theDir, const YCHAR * name); -int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, +yaffs_Object *yaffs_MknodDirectory(yaffs_Object *parent, const YCHAR *name, + __u32 mode, __u32 uid, __u32 gid); +yaffs_Object *yaffs_FindObjectByName(yaffs_Object *theDir, const YCHAR *name); +int yaffs_ApplyToDirectoryChildren(yaffs_Object *theDir, int (*fn) (yaffs_Object *)); -yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number); +yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device *dev, __u32 number); /* Link operations */ -yaffs_Object *yaffs_Link(yaffs_Object * parent, const YCHAR * name, - yaffs_Object * equivalentObject); +yaffs_Object *yaffs_Link(yaffs_Object *parent, const YCHAR *name, + yaffs_Object *equivalentObject); -yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object * obj); +yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object *obj); /* Symlink operations */ -yaffs_Object *yaffs_MknodSymLink(yaffs_Object * parent, const YCHAR * name, +yaffs_Object *yaffs_MknodSymLink(yaffs_Object *parent, const YCHAR *name, __u32 mode, __u32 uid, __u32 gid, - const YCHAR * alias); -YCHAR *yaffs_GetSymlinkAlias(yaffs_Object * obj); + const YCHAR *alias); +YCHAR *yaffs_GetSymlinkAlias(yaffs_Object *obj); /* Special inodes (fifos, sockets and devices) */ -yaffs_Object *yaffs_MknodSpecial(yaffs_Object * parent, const YCHAR * name, +yaffs_Object *yaffs_MknodSpecial(yaffs_Object *parent, const YCHAR *name, __u32 mode, __u32 uid, __u32 gid, __u32 rdev); /* Special directories */ -yaffs_Object *yaffs_Root(yaffs_Device * dev); -yaffs_Object *yaffs_LostNFound(yaffs_Device * dev); +yaffs_Object *yaffs_Root(yaffs_Device *dev); +yaffs_Object *yaffs_LostNFound(yaffs_Device *dev); #ifdef CONFIG_YAFFS_WINCE /* CONFIG_YAFFS_WINCE special stuff */ @@ -888,21 +884,21 @@ void yfsd_WinFileTimeNow(__u32 target[2]); #ifdef __KERNEL__ -void yaffs_HandleDeferedFree(yaffs_Object * obj); +void yaffs_HandleDeferedFree(yaffs_Object *obj); #endif /* Debug dump */ -int yaffs_DumpObject(yaffs_Object * obj); +int yaffs_DumpObject(yaffs_Object *obj); -void yaffs_GutsTest(yaffs_Device * dev); +void yaffs_GutsTest(yaffs_Device *dev); /* A few useful functions */ -void yaffs_InitialiseTags(yaffs_ExtendedTags * tags); -void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn); -int yaffs_CheckFF(__u8 * buffer, int nBytes); +void yaffs_InitialiseTags(yaffs_ExtendedTags *tags); +void yaffs_DeleteChunk(yaffs_Device *dev, int chunkId, int markNAND, int lyn); +int yaffs_CheckFF(__u8 *buffer, int nBytes); void yaffs_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi); -__u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo); -void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, int lineNo); +__u8 *yaffs_GetTempBuffer(yaffs_Device *dev, int lineNo); +void yaffs_ReleaseTempBuffer(yaffs_Device *dev, __u8 *buffer, int lineNo); #endif diff --git a/yaffs_mtdif.c b/yaffs_mtdif.c index 4888b96..306e188 100644 --- a/yaffs_mtdif.c +++ b/yaffs_mtdif.c @@ -12,7 +12,7 @@ */ const char *yaffs_mtdif_c_version = - "$Id: yaffs_mtdif.c,v 1.21 2007-12-13 15:35:18 wookey Exp $"; + "$Id: yaffs_mtdif.c,v 1.22 2009-03-06 17:20:51 wookey Exp $"; #include "yportenv.h" @@ -24,7 +24,7 @@ const char *yaffs_mtdif_c_version = #include "linux/time.h" #include "linux/mtd/nand.h" -#if (MTD_VERSION_CODE < MTD_VERSION(2,6,18)) +#if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 18)) static struct nand_oobinfo yaffs_oobinfo = { .useecc = 1, .eccbytes = 6, @@ -36,7 +36,7 @@ static struct nand_oobinfo yaffs_noeccinfo = { }; #endif -#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17)) static inline void translate_spare2oob(const yaffs_Spare *spare, __u8 *oob) { oob[0] = spare->tagByte0; @@ -45,8 +45,8 @@ static inline void translate_spare2oob(const yaffs_Spare *spare, __u8 *oob) oob[3] = spare->tagByte3; oob[4] = spare->tagByte4; oob[5] = spare->tagByte5 & 0x3f; - oob[5] |= spare->blockStatus == 'Y' ? 0: 0x80; - oob[5] |= spare->pageStatus == 0 ? 0: 0x40; + oob[5] |= spare->blockStatus == 'Y' ? 0 : 0x80; + oob[5] |= spare->pageStatus == 0 ? 0 : 0x40; oob[6] = spare->tagByte6; oob[7] = spare->tagByte7; } @@ -71,18 +71,18 @@ static inline void translate_oob2spare(yaffs_Spare *spare, __u8 *oob) } #endif -int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, - const __u8 * data, const yaffs_Spare * spare) +int nandmtd_WriteChunkToNAND(yaffs_Device *dev, int chunkInNAND, + const __u8 *data, const yaffs_Spare *spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; -#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17)) __u8 spareAsBytes[8]; /* OOB */ if (data && !spare) @@ -135,18 +135,18 @@ int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, return YAFFS_FAIL; } -int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, - yaffs_Spare * spare) +int nandmtd_ReadChunkFromNAND(yaffs_Device *dev, int chunkInNAND, __u8 *data, + yaffs_Spare *spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; -#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17)) __u8 spareAsBytes[8]; /* OOB */ if (data && !spare) @@ -205,7 +205,7 @@ int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, return YAFFS_FAIL; } -int nandmtd_EraseBlockInNAND(yaffs_Device * dev, int blockNumber) +int nandmtd_EraseBlockInNAND(yaffs_Device *dev, int blockNumber) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); __u32 addr = @@ -234,7 +234,7 @@ int nandmtd_EraseBlockInNAND(yaffs_Device * dev, int blockNumber) return YAFFS_FAIL; } -int nandmtd_InitialiseNAND(yaffs_Device * dev) +int nandmtd_InitialiseNAND(yaffs_Device *dev) { return YAFFS_OK; } diff --git a/yaffs_mtdif.h b/yaffs_mtdif.h index 511b017..e72cfcd 100644 --- a/yaffs_mtdif.h +++ b/yaffs_mtdif.h @@ -18,15 +18,15 @@ #include "yaffs_guts.h" -#if (MTD_VERSION_CODE < MTD_VERSION(2,6,18)) +#if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 18)) extern struct nand_oobinfo yaffs_oobinfo; extern struct nand_oobinfo yaffs_noeccinfo; #endif -int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, - const __u8 * data, const yaffs_Spare * spare); -int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, - yaffs_Spare * spare); -int nandmtd_EraseBlockInNAND(yaffs_Device * dev, int blockNumber); -int nandmtd_InitialiseNAND(yaffs_Device * dev); +int nandmtd_WriteChunkToNAND(yaffs_Device *dev, int chunkInNAND, + const __u8 *data, const yaffs_Spare *spare); +int nandmtd_ReadChunkFromNAND(yaffs_Device *dev, int chunkInNAND, __u8 *data, + yaffs_Spare *spare); +int nandmtd_EraseBlockInNAND(yaffs_Device *dev, int blockNumber); +int nandmtd_InitialiseNAND(yaffs_Device *dev); #endif diff --git a/yaffs_mtdif1.c b/yaffs_mtdif1.c index 2aad44e..f4d35fc 100644 --- a/yaffs_mtdif1.c +++ b/yaffs_mtdif1.c @@ -26,7 +26,7 @@ #include "yportenv.h" #include "yaffs_guts.h" #include "yaffs_packedtags1.h" -#include "yaffs_tagscompat.h" // for yaffs_CalcTagsECC +#include "yaffs_tagscompat.h" /* for yaffs_CalcTagsECC */ #include "linux/kernel.h" #include "linux/version.h" @@ -34,9 +34,9 @@ #include "linux/mtd/mtd.h" /* Don't compile this module if we don't have MTD's mtd_oob_ops interface */ -#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17)) -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.8 2008-07-23 03:35:12 charles Exp $"; +const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.9 2009-03-06 17:20:52 wookey Exp $"; #ifndef CONFIG_YAFFS_9BYTE_TAGS # define YTAG1_SIZE 8 @@ -89,9 +89,9 @@ static struct nand_ecclayout nand_oob_16 = { * Returns YAFFS_OK or YAFFS_FAIL. */ int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, - int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * etags) + int chunkInNAND, const __u8 *data, const yaffs_ExtendedTags *etags) { - struct mtd_info * mtd = dev->genericDevice; + struct mtd_info *mtd = dev->genericDevice; int chunkBytes = dev->nDataBytesPerChunk; loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; struct mtd_oob_ops ops; @@ -146,7 +146,7 @@ int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, /* Return with empty ExtendedTags but add eccResult. */ -static int rettags(yaffs_ExtendedTags * etags, int eccResult, int retval) +static int rettags(yaffs_ExtendedTags *etags, int eccResult, int retval) { if (etags) { memset(etags, 0, sizeof(*etags)); @@ -169,9 +169,9 @@ static int rettags(yaffs_ExtendedTags * etags, int eccResult, int retval) * Returns YAFFS_OK or YAFFS_FAIL. */ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, - int chunkInNAND, __u8 * data, yaffs_ExtendedTags * etags) + int chunkInNAND, __u8 *data, yaffs_ExtendedTags *etags) { - struct mtd_info * mtd = dev->genericDevice; + struct mtd_info *mtd = dev->genericDevice; int chunkBytes = dev->nDataBytesPerChunk; loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; int eccres = YAFFS_ECC_RESULT_NO_ERROR; @@ -189,7 +189,7 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, ops.datbuf = data; ops.oobbuf = (__u8 *)&pt1; -#if (MTD_VERSION_CODE < MTD_VERSION(2,6,20)) +#if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 20)) /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. */ @@ -284,7 +284,7 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, */ int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) { - struct mtd_info * mtd = dev->genericDevice; + struct mtd_info *mtd = dev->genericDevice; int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk; int retval; @@ -298,7 +298,7 @@ int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) * * Returns YAFFS_OK or YAFFS_FAIL. */ -static int nandmtd1_TestPrerequists(struct mtd_info * mtd) +static int nandmtd1_TestPrerequists(struct mtd_info *mtd) { /* 2.6.18 has mtd->ecclayout->oobavail */ /* 2.6.21 has mtd->ecclayout->oobavail and mtd->oobavail */ @@ -323,9 +323,9 @@ static int nandmtd1_TestPrerequists(struct mtd_info * mtd) * Always returns YAFFS_OK. */ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * pState, __u32 *pSequenceNumber) + yaffs_BlockState *pState, __u32 *pSequenceNumber) { - struct mtd_info * mtd = dev->genericDevice; + struct mtd_info *mtd = dev->genericDevice; int chunkNo = blockNo * dev->nChunksPerBlock; loff_t addr = (loff_t)chunkNo * dev->nDataBytesPerChunk; yaffs_ExtendedTags etags; @@ -346,16 +346,13 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "block %d is marked bad\n", blockNo); state = YAFFS_BLOCK_STATE_DEAD; - } - else if (etags.eccResult != YAFFS_ECC_RESULT_NO_ERROR) { + } else if (etags.eccResult != YAFFS_ECC_RESULT_NO_ERROR) { /* bad tags, need to look more closely */ state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; - } - else if (etags.chunkUsed) { + } else if (etags.chunkUsed) { state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; seqnum = etags.sequenceNumber; - } - else { + } else { state = YAFFS_BLOCK_STATE_EMPTY; } diff --git a/yaffs_mtdif1.h b/yaffs_mtdif1.h index 5fa056c..240202c 100644 --- a/yaffs_mtdif1.h +++ b/yaffs_mtdif1.h @@ -14,15 +14,15 @@ #ifndef __YAFFS_MTDIF1_H__ #define __YAFFS_MTDIF1_H__ -int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, - const __u8 * data, const yaffs_ExtendedTags * tags); +int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, int chunkInNAND, + const __u8 *data, const yaffs_ExtendedTags *tags); -int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, - __u8 * data, yaffs_ExtendedTags * tags); +int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, + __u8 *data, yaffs_ExtendedTags *tags); int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * state, __u32 *sequenceNumber); + yaffs_BlockState *state, __u32 *sequenceNumber); #endif diff --git a/yaffs_mtdif2.c b/yaffs_mtdif2.c index 6ed89c2..77504ba 100644 --- a/yaffs_mtdif2.c +++ b/yaffs_mtdif2.c @@ -14,7 +14,7 @@ /* mtd interface for YAFFS2 */ const char *yaffs_mtdif2_c_version = - "$Id: yaffs_mtdif2.c,v 1.22 2008-11-02 22:47:13 charles Exp $"; + "$Id: yaffs_mtdif2.c,v 1.23 2009-03-06 17:20:53 wookey Exp $"; #include "yportenv.h" @@ -31,12 +31,12 @@ const char *yaffs_mtdif2_c_version = * We assume that the data buffer is of size totalBytersPerChunk so that we can also * use it to load the tags. */ -int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, - const __u8 * data, - const yaffs_ExtendedTags * tags) +int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device *dev, int chunkInNAND, + const __u8 *data, + const yaffs_ExtendedTags *tags) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17)) struct mtd_oob_ops ops; #else size_t dummy; @@ -51,25 +51,24 @@ int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, (TSTR ("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p" TENDSTR), chunkInNAND, data, tags)); - + addr = ((loff_t) chunkInNAND) * dev->totalBytesPerChunk; - + /* For yaffs2 writing there must be both data and tags. * If we're using inband tags, then the tags are stuffed into * the end of the data buffer. */ - if(!data || !tags) - BUG(); - else if(dev->inbandTags){ + if (!data || !tags) + BUG(); + else if (dev->inbandTags) { yaffs_PackedTags2TagsPart *pt2tp; pt2tp = (yaffs_PackedTags2TagsPart *)(data + dev->nDataBytesPerChunk); - yaffs_PackTags2TagsPart(pt2tp,tags); - } - else + yaffs_PackTags2TagsPart(pt2tp, tags); + } else yaffs_PackTags2(&pt, tags); - -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) ops.mode = MTD_OOB_AUTO; ops.ooblen = (dev->inbandTags) ? 0 : sizeof(pt); ops.len = dev->totalBytesPerChunk; @@ -82,7 +81,7 @@ int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, if (!dev->inbandTags) { retval = mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, (__u8 *) & pt, NULL); + &dummy, data, (__u8 *) &pt, NULL); } else { retval = mtd->write(mtd, addr, dev->totalBytesPerChunk, &dummy, @@ -96,11 +95,11 @@ int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, return YAFFS_FAIL; } -int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, - __u8 * data, yaffs_ExtendedTags * tags) +int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, + __u8 *data, yaffs_ExtendedTags *tags) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17)) struct mtd_oob_ops ops; #endif size_t dummy; @@ -115,19 +114,19 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, (TSTR ("nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p" TENDSTR), chunkInNAND, data, tags)); - - if(dev->inbandTags){ - - if(!data) { + + if (dev->inbandTags) { + + if (!data) { localData = 1; - data = yaffs_GetTempBuffer(dev,__LINE__); + data = yaffs_GetTempBuffer(dev, __LINE__); } - + } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17)) if (dev->inbandTags || (data && !tags)) retval = mtd->read(mtd, addr, dev->totalBytesPerChunk, &dummy, data); @@ -159,25 +158,24 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, #endif - if(dev->inbandTags){ - if(tags){ - yaffs_PackedTags2TagsPart * pt2tp; - pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk]; - yaffs_UnpackTags2TagsPart(tags,pt2tp); + if (dev->inbandTags) { + if (tags) { + yaffs_PackedTags2TagsPart *pt2tp; + pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk]; + yaffs_UnpackTags2TagsPart(tags, pt2tp); } - } - else { - if (tags){ + } else { + if (tags) { memcpy(&pt, dev->spareBuffer, sizeof(pt)); yaffs_UnpackTags2(tags, &pt); } } - if(localData) - yaffs_ReleaseTempBuffer(dev,data,__LINE__); - - if(tags && retval == -EBADMSG && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR) - tags->eccResult = YAFFS_ECC_RESULT_UNFIXED; + if (localData) + yaffs_ReleaseTempBuffer(dev, data, __LINE__); + + if (tags && retval == -EBADMSG && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR) + tags->eccResult = YAFFS_ECC_RESULT_UNFIXED; if (retval == 0) return YAFFS_OK; else @@ -204,7 +202,7 @@ int nandmtd2_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) } int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * state, __u32 *sequenceNumber) + yaffs_BlockState *state, __u32 *sequenceNumber) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); int retval; diff --git a/yaffs_mtdif2.h b/yaffs_mtdif2.h index 19f63b3..b5ff078 100644 --- a/yaffs_mtdif2.h +++ b/yaffs_mtdif2.h @@ -17,13 +17,13 @@ #define __YAFFS_MTDIF2_H__ #include "yaffs_guts.h" -int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, - const __u8 * data, - const yaffs_ExtendedTags * tags); -int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, - __u8 * data, yaffs_ExtendedTags * tags); +int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device *dev, int chunkInNAND, + const __u8 *data, + const yaffs_ExtendedTags *tags); +int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, + __u8 *data, yaffs_ExtendedTags *tags); int nandmtd2_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * state, __u32 *sequenceNumber); + yaffs_BlockState *state, __u32 *sequenceNumber); #endif diff --git a/yaffs_nand.c b/yaffs_nand.c index af42157..bd815cb 100644 --- a/yaffs_nand.c +++ b/yaffs_nand.c @@ -12,7 +12,7 @@ */ const char *yaffs_nand_c_version = - "$Id: yaffs_nand.c,v 1.9 2008-05-05 07:58:58 charles Exp $"; + "$Id: yaffs_nand.c,v 1.10 2009-03-06 17:20:54 wookey Exp $"; #include "yaffs_nand.h" #include "yaffs_tagscompat.h" @@ -20,9 +20,9 @@ const char *yaffs_nand_c_version = #include "yaffs_getblockinfo.h" -int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, - __u8 * buffer, - yaffs_ExtendedTags * tags) +int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, + __u8 *buffer, + yaffs_ExtendedTags *tags) { int result; yaffs_ExtendedTags localTags; @@ -30,7 +30,7 @@ int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, int realignedChunkInNAND = chunkInNAND - dev->chunkOffset; /* If there are no tags provided, use local tags to get prioritised gc working */ - if(!tags) + if (!tags) tags = &localTags; if (dev->readChunkWithTagsFromNAND) @@ -41,20 +41,20 @@ int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, realignedChunkInNAND, buffer, tags); - if(tags && - tags->eccResult > YAFFS_ECC_RESULT_NO_ERROR){ + if (tags && + tags->eccResult > YAFFS_ECC_RESULT_NO_ERROR) { yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, chunkInNAND/dev->nChunksPerBlock); - yaffs_HandleChunkError(dev,bi); + yaffs_HandleChunkError(dev, bi); } return result; } -int yaffs_WriteChunkWithTagsToNAND(yaffs_Device * dev, +int yaffs_WriteChunkWithTagsToNAND(yaffs_Device *dev, int chunkInNAND, - const __u8 * buffer, - yaffs_ExtendedTags * tags) + const __u8 *buffer, + yaffs_ExtendedTags *tags) { chunkInNAND -= dev->chunkOffset; @@ -85,7 +85,7 @@ int yaffs_WriteChunkWithTagsToNAND(yaffs_Device * dev, tags); } -int yaffs_MarkBlockBad(yaffs_Device * dev, int blockNo) +int yaffs_MarkBlockBad(yaffs_Device *dev, int blockNo) { blockNo -= dev->blockOffset; @@ -96,9 +96,9 @@ int yaffs_MarkBlockBad(yaffs_Device * dev, int blockNo) return yaffs_TagsCompatabilityMarkNANDBlockBad(dev, blockNo); } -int yaffs_QueryInitialBlockState(yaffs_Device * dev, +int yaffs_QueryInitialBlockState(yaffs_Device *dev, int blockNo, - yaffs_BlockState * state, + yaffs_BlockState *state, __u32 *sequenceNumber) { blockNo -= dev->blockOffset; diff --git a/yaffs_nand.h b/yaffs_nand.h index 5fa334b..e013cdc 100644 --- a/yaffs_nand.h +++ b/yaffs_nand.h @@ -19,21 +19,21 @@ -int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, - __u8 * buffer, - yaffs_ExtendedTags * tags); +int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, + __u8 *buffer, + yaffs_ExtendedTags *tags); -int yaffs_WriteChunkWithTagsToNAND(yaffs_Device * dev, - int chunkInNAND, - const __u8 * buffer, - yaffs_ExtendedTags * tags); +int yaffs_WriteChunkWithTagsToNAND(yaffs_Device *dev, + int chunkInNAND, + const __u8 *buffer, + yaffs_ExtendedTags *tags); -int yaffs_MarkBlockBad(yaffs_Device * dev, int blockNo); +int yaffs_MarkBlockBad(yaffs_Device *dev, int blockNo); -int yaffs_QueryInitialBlockState(yaffs_Device * dev, - int blockNo, - yaffs_BlockState * state, - unsigned *sequenceNumber); +int yaffs_QueryInitialBlockState(yaffs_Device *dev, + int blockNo, + yaffs_BlockState *state, + unsigned *sequenceNumber); int yaffs_EraseBlockInNAND(struct yaffs_DeviceStruct *dev, int blockInNAND); diff --git a/yaffs_nandemul2k.h b/yaffs_nandemul2k.h index c8576b3..41bc2b5 100644 --- a/yaffs_nandemul2k.h +++ b/yaffs_nandemul2k.h @@ -21,14 +21,14 @@ #include "yaffs_guts.h" int nandemul2k_WriteChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, - int chunkInNAND, const __u8 * data, - const yaffs_ExtendedTags * tags); + int chunkInNAND, const __u8 *data, + const yaffs_ExtendedTags *tags); int nandemul2k_ReadChunkWithTagsFromNAND(struct yaffs_DeviceStruct *dev, - int chunkInNAND, __u8 * data, - yaffs_ExtendedTags * tags); + int chunkInNAND, __u8 *data, + yaffs_ExtendedTags *tags); int nandemul2k_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int nandemul2k_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * state, __u32 *sequenceNumber); + yaffs_BlockState *state, __u32 *sequenceNumber); int nandemul2k_EraseBlockInNAND(struct yaffs_DeviceStruct *dev, int blockInNAND); int nandemul2k_InitialiseNAND(struct yaffs_DeviceStruct *dev); diff --git a/yaffs_packedtags1.c b/yaffs_packedtags1.c index f480bf1..c910f22 100644 --- a/yaffs_packedtags1.c +++ b/yaffs_packedtags1.c @@ -14,7 +14,7 @@ #include "yaffs_packedtags1.h" #include "yportenv.h" -void yaffs_PackTags1(yaffs_PackedTags1 * pt, const yaffs_ExtendedTags * t) +void yaffs_PackTags1(yaffs_PackedTags1 *pt, const yaffs_ExtendedTags *t) { pt->chunkId = t->chunkId; pt->serialNumber = t->serialNumber; @@ -27,7 +27,7 @@ void yaffs_PackTags1(yaffs_PackedTags1 * pt, const yaffs_ExtendedTags * t) } -void yaffs_UnpackTags1(yaffs_ExtendedTags * t, const yaffs_PackedTags1 * pt) +void yaffs_UnpackTags1(yaffs_ExtendedTags *t, const yaffs_PackedTags1 *pt) { static const __u8 allFF[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -47,6 +47,5 @@ void yaffs_UnpackTags1(yaffs_ExtendedTags * t, const yaffs_PackedTags1 * pt) t->serialNumber = pt->serialNumber; } else { memset(t, 0, sizeof(yaffs_ExtendedTags)); - } } diff --git a/yaffs_packedtags1.h b/yaffs_packedtags1.h index 776c5c2..f8c0471 100644 --- a/yaffs_packedtags1.h +++ b/yaffs_packedtags1.h @@ -32,6 +32,6 @@ typedef struct { } yaffs_PackedTags1; -void yaffs_PackTags1(yaffs_PackedTags1 * pt, const yaffs_ExtendedTags * t); -void yaffs_UnpackTags1(yaffs_ExtendedTags * t, const yaffs_PackedTags1 * pt); +void yaffs_PackTags1(yaffs_PackedTags1 *pt, const yaffs_ExtendedTags *t); +void yaffs_UnpackTags1(yaffs_ExtendedTags *t, const yaffs_PackedTags1 *pt); #endif diff --git a/yaffs_packedtags2.c b/yaffs_packedtags2.c index 3f9a815..da1621f 100644 --- a/yaffs_packedtags2.c +++ b/yaffs_packedtags2.c @@ -38,19 +38,19 @@ #define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT) -static void yaffs_DumpPackedTags2TagsPart(const yaffs_PackedTags2TagsPart * ptt) +static void yaffs_DumpPackedTags2TagsPart(const yaffs_PackedTags2TagsPart *ptt) { T(YAFFS_TRACE_MTD, (TSTR("packed tags obj %d chunk %d byte %d seq %d" TENDSTR), ptt->objectId, ptt->chunkId, ptt->byteCount, ptt->sequenceNumber)); } -static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 * pt) +static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 *pt) { yaffs_DumpPackedTags2TagsPart(&pt->t); } -static void yaffs_DumpTags2(const yaffs_ExtendedTags * t) +static void yaffs_DumpTags2(const yaffs_ExtendedTags *t) { T(YAFFS_TRACE_MTD, (TSTR @@ -61,7 +61,8 @@ static void yaffs_DumpTags2(const yaffs_ExtendedTags * t) } -void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart * ptt, const yaffs_ExtendedTags * t) +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart *ptt, + const yaffs_ExtendedTags *t) { ptt->chunkId = t->chunkId; ptt->sequenceNumber = t->sequenceNumber; @@ -98,9 +99,9 @@ void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart * ptt, const yaffs_Extend } -void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) +void yaffs_PackTags2(yaffs_PackedTags2 *pt, const yaffs_ExtendedTags *t) { - yaffs_PackTags2TagsPart(&pt->t,t); + yaffs_PackTags2TagsPart(&pt->t, t); #ifndef YAFFS_IGNORE_TAGS_ECC { @@ -112,7 +113,8 @@ void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) } -void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags * t, yaffs_PackedTags2TagsPart * ptt) +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags *t, + yaffs_PackedTags2TagsPart *ptt) { memset(t, 0, sizeof(yaffs_ExtendedTags)); @@ -160,11 +162,11 @@ void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags * t, yaffs_PackedTags2TagsPart } -void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) +void yaffs_UnpackTags2(yaffs_ExtendedTags *t, yaffs_PackedTags2 *pt) { yaffs_ECCResult eccResult = YAFFS_ECC_RESULT_NO_ERROR; - + if (pt->t.sequenceNumber != 0xFFFFFFFF) { /* Page is in use */ #ifndef YAFFS_IGNORE_TAGS_ECC @@ -180,25 +182,25 @@ void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) sizeof (yaffs_PackedTags2TagsPart), &pt->ecc, &ecc); - switch(result){ - case 0: - eccResult = YAFFS_ECC_RESULT_NO_ERROR; - break; - case 1: - eccResult = YAFFS_ECC_RESULT_FIXED; - break; - case -1: - eccResult = YAFFS_ECC_RESULT_UNFIXED; - break; - default: - eccResult = YAFFS_ECC_RESULT_UNKNOWN; + switch (result) { + case 0: + eccResult = YAFFS_ECC_RESULT_NO_ERROR; + break; + case 1: + eccResult = YAFFS_ECC_RESULT_FIXED; + break; + case -1: + eccResult = YAFFS_ECC_RESULT_UNFIXED; + break; + default: + eccResult = YAFFS_ECC_RESULT_UNKNOWN; } } #endif } - yaffs_UnpackTags2TagsPart(t,&pt->t); - + yaffs_UnpackTags2TagsPart(t, &pt->t); + t->eccResult = eccResult; yaffs_DumpPackedTags2(pt); diff --git a/yaffs_packedtags2.h b/yaffs_packedtags2.h index 75761d3..ec30f84 100644 --- a/yaffs_packedtags2.h +++ b/yaffs_packedtags2.h @@ -34,10 +34,10 @@ typedef struct { } yaffs_PackedTags2; /* Full packed tags with ECC, used for oob tags */ -void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t); -void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt); +void yaffs_PackTags2(yaffs_PackedTags2 *pt, const yaffs_ExtendedTags *t); +void yaffs_UnpackTags2(yaffs_ExtendedTags *t, yaffs_PackedTags2 *pt); /* Only the tags part (no ECC for use with inband tags */ -void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart * pt, const yaffs_ExtendedTags * t); -void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags * t, yaffs_PackedTags2TagsPart * pt); +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart *pt, const yaffs_ExtendedTags *t); +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags *t, yaffs_PackedTags2TagsPart *pt); #endif diff --git a/yaffs_qsort.c b/yaffs_qsort.c index 474be9c..187519f 100644 --- a/yaffs_qsort.c +++ b/yaffs_qsort.c @@ -28,12 +28,12 @@ */ #include "yportenv.h" -//#include +/* #include */ /* * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". */ -#define swapcode(TYPE, parmi, parmj, n) { \ +#define swapcode(TYPE, parmi, parmj, n) do { \ long i = (n) / sizeof (TYPE); \ register TYPE *pi = (TYPE *) (parmi); \ register TYPE *pj = (TYPE *) (parmj); \ @@ -41,28 +41,29 @@ register TYPE t = *pi; \ *pi++ = *pj; \ *pj++ = t; \ - } while (--i > 0); \ -} + } while (--i > 0); \ +} while (0) #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ - es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; + es % sizeof(long) ? 2 : es == sizeof(long) ? 0 : 1; static __inline void swapfunc(char *a, char *b, int n, int swaptype) { if (swaptype <= 1) - swapcode(long, a, b, n) + swapcode(long, a, b, n); else - swapcode(char, a, b, n) + swapcode(char, a, b, n); } -#define swap(a, b) \ +#define yswap(a, b) do { \ if (swaptype == 0) { \ long t = *(long *)(a); \ *(long *)(a) = *(long *)(b); \ *(long *)(b) = t; \ } else \ - swapfunc(a, b, es, swaptype) + swapfunc(a, b, es, swaptype); \ +} while (0) #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) @@ -70,12 +71,12 @@ static __inline char * med3(char *a, char *b, char *c, int (*cmp)(const void *, const void *)) { return cmp(a, b) < 0 ? - (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) - :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c )); + (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a)) + : (cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c)); } #ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) +#define min(a, b) (((a) < (b)) ? (a) : (b)) #endif void @@ -92,7 +93,7 @@ loop: SWAPINIT(a, es); for (pm = (char *)a + es; pm < (char *) a + n * es; pm += es) for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; pl -= es) - swap(pl, pl - es); + yswap(pl, pl - es); return; } pm = (char *)a + (n / 2) * es; @@ -107,7 +108,7 @@ loop: SWAPINIT(a, es); } pm = med3(pl, pm, pn, cmp); } - swap(a, pm); + yswap(a, pm); pa = pb = (char *)a + es; pc = pd = (char *)a + (n - 1) * es; @@ -115,7 +116,7 @@ loop: SWAPINIT(a, es); while (pb <= pc && (r = cmp(pb, a)) <= 0) { if (r == 0) { swap_cnt = 1; - swap(pa, pb); + yswap(pa, pb); pa += es; } pb += es; @@ -123,14 +124,14 @@ loop: SWAPINIT(a, es); while (pb <= pc && (r = cmp(pc, a)) >= 0) { if (r == 0) { swap_cnt = 1; - swap(pc, pd); + yswap(pc, pd); pd -= es; } pc -= es; } if (pb > pc) break; - swap(pb, pc); + yswap(pb, pc); swap_cnt = 1; pb += es; pc -= es; @@ -139,7 +140,7 @@ loop: SWAPINIT(a, es); for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; pl -= es) - swap(pl, pl - es); + yswap(pl, pl - es); return; } @@ -148,9 +149,11 @@ loop: SWAPINIT(a, es); vecswap(a, pb - r, r); r = min((long)(pd - pc), (long)(pn - pd - es)); vecswap(pb, pn - r, r); - if ((r = pb - pa) > es) + r = pb - pa; + if (r > es) yaffs_qsort(a, r / es, es, cmp); - if ((r = pd - pc) > es) { + r = pd - pc; + if (r > es) { /* Iterate rather than recurse to save stack space */ a = pn - r; n = r / es; diff --git a/yaffs_qsort.h b/yaffs_qsort.h index 610b7ec..941c7a8 100644 --- a/yaffs_qsort.h +++ b/yaffs_qsort.h @@ -17,7 +17,7 @@ #ifndef __YAFFS_QSORT_H__ #define __YAFFS_QSORT_H__ -extern void yaffs_qsort (void *const base, size_t total_elems, size_t size, - int (*cmp)(const void *, const void *)); +extern void yaffs_qsort(void *const base, size_t total_elems, size_t size, + int (*cmp)(const void *, const void *)); #endif diff --git a/yaffs_tagscompat.c b/yaffs_tagscompat.c index f6c4053..1e0a1a1 100644 --- a/yaffs_tagscompat.c +++ b/yaffs_tagscompat.c @@ -16,15 +16,15 @@ #include "yaffs_ecc.h" #include "yaffs_getblockinfo.h" -static void yaffs_HandleReadDataError(yaffs_Device * dev, int chunkInNAND); +static void yaffs_HandleReadDataError(yaffs_Device *dev, int chunkInNAND); #ifdef NOTYET -static void yaffs_CheckWrittenBlock(yaffs_Device * dev, int chunkInNAND); -static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND, - const __u8 * data, - const yaffs_Spare * spare); -static void yaffs_HandleUpdateChunk(yaffs_Device * dev, int chunkInNAND, - const yaffs_Spare * spare); -static void yaffs_HandleWriteChunkError(yaffs_Device * dev, int chunkInNAND); +static void yaffs_CheckWrittenBlock(yaffs_Device *dev, int chunkInNAND); +static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND, + const __u8 *data, + const yaffs_Spare *spare); +static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND, + const yaffs_Spare *spare); +static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND); #endif static const char yaffs_countBitsTable[256] = { @@ -55,13 +55,13 @@ int yaffs_CountBits(__u8 x) /********** Tags ECC calculations *********/ -void yaffs_CalcECC(const __u8 * data, yaffs_Spare * spare) +void yaffs_CalcECC(const __u8 *data, yaffs_Spare *spare) { yaffs_ECCCalculate(data, spare->ecc1); yaffs_ECCCalculate(&data[256], spare->ecc2); } -void yaffs_CalcTagsECC(yaffs_Tags * tags) +void yaffs_CalcTagsECC(yaffs_Tags *tags) { /* Calculate an ecc */ @@ -75,9 +75,8 @@ void yaffs_CalcTagsECC(yaffs_Tags * tags) for (i = 0; i < 8; i++) { for (j = 1; j & 0xff; j <<= 1) { bit++; - if (b[i] & j) { + if (b[i] & j) ecc ^= bit; - } } } @@ -85,7 +84,7 @@ void yaffs_CalcTagsECC(yaffs_Tags * tags) } -int yaffs_CheckECCOnTags(yaffs_Tags * tags) +int yaffs_CheckECCOnTags(yaffs_Tags *tags) { unsigned ecc = tags->ecc; @@ -116,8 +115,8 @@ int yaffs_CheckECCOnTags(yaffs_Tags * tags) /********** Tags **********/ -static void yaffs_LoadTagsIntoSpare(yaffs_Spare * sparePtr, - yaffs_Tags * tagsPtr) +static void yaffs_LoadTagsIntoSpare(yaffs_Spare *sparePtr, + yaffs_Tags *tagsPtr) { yaffs_TagsUnion *tu = (yaffs_TagsUnion *) tagsPtr; @@ -133,8 +132,8 @@ static void yaffs_LoadTagsIntoSpare(yaffs_Spare * sparePtr, sparePtr->tagByte7 = tu->asBytes[7]; } -static void yaffs_GetTagsFromSpare(yaffs_Device * dev, yaffs_Spare * sparePtr, - yaffs_Tags * tagsPtr) +static void yaffs_GetTagsFromSpare(yaffs_Device *dev, yaffs_Spare *sparePtr, + yaffs_Tags *tagsPtr) { yaffs_TagsUnion *tu = (yaffs_TagsUnion *) tagsPtr; int result; @@ -149,21 +148,20 @@ static void yaffs_GetTagsFromSpare(yaffs_Device * dev, yaffs_Spare * sparePtr, tu->asBytes[7] = sparePtr->tagByte7; result = yaffs_CheckECCOnTags(tagsPtr); - if (result > 0) { + if (result > 0) dev->tagsEccFixed++; - } else if (result < 0) { + else if (result < 0) dev->tagsEccUnfixed++; - } } -static void yaffs_SpareInitialise(yaffs_Spare * spare) +static void yaffs_SpareInitialise(yaffs_Spare *spare) { memset(spare, 0xFF, sizeof(yaffs_Spare)); } static int yaffs_WriteChunkToNAND(struct yaffs_DeviceStruct *dev, - int chunkInNAND, const __u8 * data, - yaffs_Spare * spare) + int chunkInNAND, const __u8 *data, + yaffs_Spare *spare) { if (chunkInNAND < dev->startBlock * dev->nChunksPerBlock) { T(YAFFS_TRACE_ERROR, @@ -178,9 +176,9 @@ static int yaffs_WriteChunkToNAND(struct yaffs_DeviceStruct *dev, static int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev, int chunkInNAND, - __u8 * data, - yaffs_Spare * spare, - yaffs_ECCResult * eccResult, + __u8 *data, + yaffs_Spare *spare, + yaffs_ECCResult *eccResult, int doErrorCorrection) { int retVal; @@ -253,12 +251,11 @@ static int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev, /* Must allocate enough memory for spare+2*sizeof(int) */ /* for ecc results from device. */ struct yaffs_NANDSpare nspare; - - memset(&nspare,0,sizeof(nspare)); - - retVal = - dev->readChunkFromNAND(dev, chunkInNAND, data, - (yaffs_Spare *) & nspare); + + memset(&nspare, 0, sizeof(nspare)); + + retVal = dev->readChunkFromNAND(dev, chunkInNAND, data, + (yaffs_Spare *) &nspare); memcpy(spare, &nspare, sizeof(yaffs_Spare)); if (data && doErrorCorrection) { if (nspare.eccres1 > 0) { @@ -306,8 +303,7 @@ static int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev, static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, int chunkInNAND) { - - static int init = 0; + static int init; static __u8 cmpbuf[YAFFS_BYTES_PER_CHUNK]; static __u8 data[YAFFS_BYTES_PER_CHUNK]; /* Might as well always allocate the larger size for */ @@ -335,7 +331,7 @@ static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, * Functions for robustisizing */ -static void yaffs_HandleReadDataError(yaffs_Device * dev, int chunkInNAND) +static void yaffs_HandleReadDataError(yaffs_Device *dev, int chunkInNAND) { int blockInNAND = chunkInNAND / dev->nChunksPerBlock; @@ -352,22 +348,22 @@ static void yaffs_HandleReadDataError(yaffs_Device * dev, int chunkInNAND) } #ifdef NOTYET -static void yaffs_CheckWrittenBlock(yaffs_Device * dev, int chunkInNAND) +static void yaffs_CheckWrittenBlock(yaffs_Device *dev, int chunkInNAND) { } -static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND, - const __u8 * data, - const yaffs_Spare * spare) +static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND, + const __u8 *data, + const yaffs_Spare *spare) { } -static void yaffs_HandleUpdateChunk(yaffs_Device * dev, int chunkInNAND, - const yaffs_Spare * spare) +static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND, + const yaffs_Spare *spare) { } -static void yaffs_HandleWriteChunkError(yaffs_Device * dev, int chunkInNAND) +static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND) { int blockInNAND = chunkInNAND / dev->nChunksPerBlock; @@ -377,8 +373,8 @@ static void yaffs_HandleWriteChunkError(yaffs_Device * dev, int chunkInNAND) yaffs_DeleteChunk(dev, chunkInNAND, 1, __LINE__); } -static int yaffs_VerifyCompare(const __u8 * d0, const __u8 * d1, - const yaffs_Spare * s0, const yaffs_Spare * s1) +static int yaffs_VerifyCompare(const __u8 *d0, const __u8 *d1, + const yaffs_Spare *s0, const yaffs_Spare *s1) { if (memcmp(d0, d1, YAFFS_BYTES_PER_CHUNK) != 0 || @@ -402,11 +398,10 @@ static int yaffs_VerifyCompare(const __u8 * d0, const __u8 * d1, } #endif /* NOTYET */ -int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device * dev, - int chunkInNAND, - const __u8 * data, - const yaffs_ExtendedTags * - eTags) +int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device *dev, + int chunkInNAND, + const __u8 *data, + const yaffs_ExtendedTags *eTags) { yaffs_Spare spare; yaffs_Tags tags; @@ -420,13 +415,13 @@ int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device * dev, tags.chunkId = eTags->chunkId; tags.byteCountLSB = eTags->byteCount & 0x3ff; - - if(dev->nDataBytesPerChunk >= 1024){ + + if (dev->nDataBytesPerChunk >= 1024) { tags.byteCountMSB = (eTags->byteCount >> 10) & 3; } else { tags.byteCountMSB = 3; } - + tags.serialNumber = eTags->serialNumber; @@ -440,10 +435,10 @@ int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device * dev, return yaffs_WriteChunkToNAND(dev, chunkInNAND, data, &spare); } -int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, +int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, - __u8 * data, - yaffs_ExtendedTags * eTags) + __u8 *data, + yaffs_ExtendedTags *eTags) { yaffs_Spare spare; @@ -451,7 +446,7 @@ int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, yaffs_ECCResult eccResult = YAFFS_ECC_RESULT_UNKNOWN; static yaffs_Spare spareFF; - static int init = 0; + static int init; if (!init) { memset(&spareFF, 0xFF, sizeof(spareFF)); @@ -481,7 +476,7 @@ int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, eTags->chunkId = tags.chunkId; eTags->byteCount = tags.byteCountLSB; - if(dev->nDataBytesPerChunk >= 1024) + if (dev->nDataBytesPerChunk >= 1024) eTags->byteCount |= (((unsigned) tags.byteCountMSB) << 10); eTags->serialNumber = tags.serialNumber; diff --git a/yaffs_tagscompat.h b/yaffs_tagscompat.h index 6549398..6f95119 100644 --- a/yaffs_tagscompat.h +++ b/yaffs_tagscompat.h @@ -17,25 +17,23 @@ #define __YAFFS_TAGSCOMPAT_H__ #include "yaffs_guts.h" -int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device * dev, - int chunkInNAND, - const __u8 * data, - const yaffs_ExtendedTags * - tags); -int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, - int chunkInNAND, - __u8 * data, - yaffs_ExtendedTags * - tags); +int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device *dev, + int chunkInNAND, + const __u8 *data, + const yaffs_ExtendedTags *tags); +int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device *dev, + int chunkInNAND, + __u8 *data, + yaffs_ExtendedTags *tags); int yaffs_TagsCompatabilityMarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev, - int blockNo, + int blockNo, yaffs_BlockState *state, __u32 *sequenceNumber); -void yaffs_CalcTagsECC(yaffs_Tags * tags); -int yaffs_CheckECCOnTags(yaffs_Tags * tags); +void yaffs_CalcTagsECC(yaffs_Tags *tags); +int yaffs_CheckECCOnTags(yaffs_Tags *tags); int yaffs_CountBits(__u8 byte); #endif diff --git a/yaffs_tagsvalidity.c b/yaffs_tagsvalidity.c index 9e0bd1c..5233bcb 100644 --- a/yaffs_tagsvalidity.c +++ b/yaffs_tagsvalidity.c @@ -13,14 +13,14 @@ #include "yaffs_tagsvalidity.h" -void yaffs_InitialiseTags(yaffs_ExtendedTags * tags) +void yaffs_InitialiseTags(yaffs_ExtendedTags *tags) { memset(tags, 0, sizeof(yaffs_ExtendedTags)); tags->validMarker0 = 0xAAAAAAAA; tags->validMarker1 = 0x55555555; } -int yaffs_ValidateTags(yaffs_ExtendedTags * tags) +int yaffs_ValidateTags(yaffs_ExtendedTags *tags) { return (tags->validMarker0 == 0xAAAAAAAA && tags->validMarker1 == 0x55555555); diff --git a/yaffs_tagsvalidity.h b/yaffs_tagsvalidity.h index 2fd0c24..cb11884 100644 --- a/yaffs_tagsvalidity.h +++ b/yaffs_tagsvalidity.h @@ -19,6 +19,6 @@ #include "yaffs_guts.h" -void yaffs_InitialiseTags(yaffs_ExtendedTags * tags); -int yaffs_ValidateTags(yaffs_ExtendedTags * tags); +void yaffs_InitialiseTags(yaffs_ExtendedTags *tags); +int yaffs_ValidateTags(yaffs_ExtendedTags *tags); #endif diff --git a/yportenv.h b/yportenv.h index ae2c5b6..28e205b 100644 --- a/yportenv.h +++ b/yportenv.h @@ -23,13 +23,13 @@ * as well as with it. */ -#define MTD_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) +#define MTD_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) #if defined CONFIG_YAFFS_WINCE #include "ywinceenv.h" -#elif defined __KERNEL__ +#elif defined __KERNEL__ #include "moduleconfig.h" @@ -38,7 +38,7 @@ #include #define MTD_VERSION_CODE LINUX_VERSION_CODE -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)) #include #endif #include @@ -51,13 +51,13 @@ #define YCHAR char #define YUCHAR unsigned char #define _Y(x) x -#define yaffs_strcat(a,b) strcat(a,b) -#define yaffs_strcpy(a,b) strcpy(a,b) -#define yaffs_strncpy(a,b,c) strncpy(a,b,c) -#define yaffs_strncmp(a,b,c) strncmp(a,b,c) -#define yaffs_strlen(s) strlen(s) -#define yaffs_sprintf sprintf -#define yaffs_toupper(a) toupper(a) +#define yaffs_strcat(a, b) strcat(a, b) +#define yaffs_strcpy(a, b) strcpy(a, b) +#define yaffs_strncpy(a, b, c) strncpy(a, b, c) +#define yaffs_strncmp(a, b, c) strncmp(a, b, c) +#define yaffs_strlen(s) strlen(s) +#define yaffs_sprintf sprintf +#define yaffs_toupper(a) toupper(a) #define Y_INLINE inline @@ -65,19 +65,19 @@ #define YAFFS_LOSTNFOUND_PREFIX "obj" /* #define YPRINTF(x) printk x */ -#define YMALLOC(x) kmalloc(x,GFP_NOFS) +#define YMALLOC(x) kmalloc(x, GFP_NOFS) #define YFREE(x) kfree(x) #define YMALLOC_ALT(x) vmalloc(x) #define YFREE_ALT(x) vfree(x) #define YMALLOC_DMA(x) YMALLOC(x) -// KR - added for use in scan so processes aren't blocked indefinitely. +/* KR - added for use in scan so processes aren't blocked indefinitely. */ #define YYIELD() schedule() #define YAFFS_ROOT_MODE 0666 #define YAFFS_LOSTNFOUND_MODE 0666 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) #define Y_CURRENT_TIME CURRENT_TIME.tv_sec #define Y_TIME_CONVERT(x) (x).tv_sec #else @@ -85,8 +85,8 @@ #define Y_TIME_CONVERT(x) (x) #endif -#define yaffs_SumCompare(x,y) ((x) == (y)) -#define yaffs_strcmp(a,b) strcmp(a,b) +#define yaffs_SumCompare(x, y) ((x) == (y)) +#define yaffs_strcmp(a, b) strcmp(a, b) #define TENDSTR "\n" #define TSTR(x) KERN_WARNING x @@ -103,7 +103,7 @@ #elif defined CONFIG_YAFFS_DIRECT -#define MTD_VERSION_CODE MTD_VERSION(2,6,22) +#define MTD_VERSION_CODE MTD_VERSION(2, 6, 22) /* Direct interface */ #include "ydirectenv.h" @@ -126,12 +126,12 @@ #define YCHAR char #define YUCHAR unsigned char #define _Y(x) x -#define yaffs_strcat(a,b) strcat(a,b) -#define yaffs_strcpy(a,b) strcpy(a,b) -#define yaffs_strncpy(a,b,c) strncpy(a,b,c) -#define yaffs_strlen(s) strlen(s) -#define yaffs_sprintf sprintf -#define yaffs_toupper(a) toupper(a) +#define yaffs_strcat(a, b) strcat(a, b) +#define yaffs_strcpy(a, b) strcpy(a, b) +#define yaffs_strncpy(a, b, c) strncpy(a, b, c) +#define yaffs_strlen(s) strlen(s) +#define yaffs_sprintf sprintf +#define yaffs_toupper(a) toupper(a) #define Y_INLINE inline @@ -149,8 +149,8 @@ #define YAFFS_ROOT_MODE 0666 #define YAFFS_LOSTNFOUND_MODE 0666 -#define yaffs_SumCompare(x,y) ((x) == (y)) -#define yaffs_strcmp(a,b) strcmp(a,b) +#define yaffs_SumCompare(x, y) ((x) == (y)) +#define yaffs_strcmp(a, b) strcmp(a, b) #else /* Should have specified a configuration type */ @@ -194,10 +194,10 @@ extern unsigned int yaffs_wr_attempts; #define YAFFS_TRACE_ALWAYS 0xF0000000 -#define T(mask,p) do{ if((mask) & (yaffs_traceMask | YAFFS_TRACE_ALWAYS)) TOUT(p);} while(0) +#define T(mask, p) do { if ((mask) & (yaffs_traceMask | YAFFS_TRACE_ALWAYS)) TOUT(p); } while (0) #ifndef YBUG -#define YBUG() do {T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__));} while(0) +#define YBUG() do {T(YAFFS_TRACE_BUG, (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR), __LINE__)); } while (0) #endif #endif -- 2.30.2