X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=yaffs_guts.h;h=b6cbb8bc5c34052e54d611ec3b178c0a78aff730;hb=70c6bf2ff57c8a2fb778accdd5b4227abf273674;hp=3bae979134dfcd3fc7bb66f12d4bb6c78f65c39f;hpb=9dc68bf9810613883954fc50d26ed6f9c2c87ac0;p=yaffs2.git diff --git a/yaffs_guts.h b/yaffs_guts.h index 3bae979..b6cbb8b 100644 --- a/yaffs_guts.h +++ b/yaffs_guts.h @@ -1,7 +1,7 @@ /* * YAFFS: Yet another Flash File System . A NAND-flash specific file system. * - * Copyright (C) 2002-2007 Aleph One Ltd. + * Copyright (C) 2002-2010 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering * * Created by Charles Manning @@ -16,8 +16,9 @@ #ifndef __YAFFS_GUTS_H__ #define __YAFFS_GUTS_H__ -#include "devextras.h" #include "yportenv.h" +#include "devextras.h" +#include "yaffs_list.h" #define YAFFS_OK 1 #define YAFFS_FAIL 0 @@ -52,7 +53,6 @@ #define YAFFS_MAX_CHUNK_ID 0x000FFFFF -#define YAFFS_UNUSED_OBJECT_ID 0x0003FFFF #define YAFFS_ALLOCATION_NOBJECTS 100 #define YAFFS_ALLOCATION_NTNODES 100 @@ -62,6 +62,7 @@ #define YAFFS_OBJECT_SPACE 0x40000 +#define YAFFS_MAX_OBJECT_ID (YAFFS_OBJECT_SPACE -1) #define YAFFS_CHECKPOINT_VERSION 4 @@ -141,7 +142,7 @@ typedef struct { typedef union { yaffs_Tags asTags; __u8 asBytes[8]; -} yaffs_TagsUnion; +} yaffs_tags_union_t; #endif @@ -202,17 +203,17 @@ typedef struct { /* Spare structure for YAFFS1 */ typedef struct { - __u8 tagByte0; - __u8 tagByte1; - __u8 tagByte2; - __u8 tagByte3; + __u8 tb0; + __u8 tb1; + __u8 tb2; + __u8 tb3; __u8 pageStatus; /* set to 0 to delete the chunk */ __u8 blockStatus; - __u8 tagByte4; - __u8 tagByte5; + __u8 tb4; + __u8 tb5; __u8 ecc1[3]; - __u8 tagByte6; - __u8 tagByte7; + __u8 tb6; + __u8 tb7; __u8 ecc2[3]; } yaffs_Spare; @@ -349,24 +350,13 @@ typedef struct { /*--------------------------- Tnode -------------------------- */ -union yaffs_Tnode_union { -#ifdef CONFIG_YAFFS_TNODE_LIST_DEBUG - union yaffs_Tnode_union *internal[YAFFS_NTNODES_INTERNAL + 1]; -#else - union yaffs_Tnode_union *internal[YAFFS_NTNODES_INTERNAL]; -#endif -/* __u16 level0[YAFFS_NTNODES_LEVEL0]; */ +union yaffs_tnode_union { + union yaffs_tnode_union *internal[YAFFS_NTNODES_INTERNAL]; }; -typedef union yaffs_Tnode_union yaffs_Tnode; +typedef union yaffs_tnode_union yaffs_tnode_t; -struct yaffs_TnodeList_struct { - struct yaffs_TnodeList_struct *next; - yaffs_Tnode *tnodes; -}; - -typedef struct yaffs_TnodeList_struct yaffs_TnodeList; /*------------------------ Object -----------------------------*/ /* An object can be one of: @@ -381,11 +371,12 @@ typedef struct { __u32 scannedFileSize; __u32 shrinkSize; int topLevel; - yaffs_Tnode *top; + yaffs_tnode_t *top; } yaffs_FileStructure; typedef struct { struct ylist_head children; /* list of child links */ + struct ylist_head dirty; /* Entry for list of dirty directories */ } yaffs_DirectoryStructure; typedef struct { @@ -427,6 +418,9 @@ struct yaffs_ObjectStruct { __u8 beingCreated:1; /* This object is still being created so skip some checks. */ __u8 isShadowed:1; /* This object is shadowed on the way to being renamed. */ + __u8 xattrKnown:1; /* We know if this has object has xattribs or not. */ + __u8 hasXattr:1; /* This object has xattribs. Valid if xattrKnown. */ + __u8 serial; /* serial number of chunk in NAND. Cached here */ __u16 sum; /* sum of the name to speed searching */ @@ -478,13 +472,6 @@ struct yaffs_ObjectStruct { typedef struct yaffs_ObjectStruct yaffs_Object; -struct yaffs_ObjectList_struct { - yaffs_Object *objects; - struct yaffs_ObjectList_struct *next; -}; - -typedef struct yaffs_ObjectList_struct yaffs_ObjectList; - typedef struct { struct ylist_head list; int count; @@ -522,13 +509,13 @@ typedef struct { __u8 *buffer; int line; /* track from whence this buffer was allocated */ int maxLine; -} yaffs_TempBuffer; +} yaffs_buffer_t; /*----------------- Device ---------------------------------*/ struct yaffs_DeviceParamStruct { - const char *name; + const YCHAR *name; /* * Entry parameters set up way early. Yaffs sets up the rest. @@ -563,6 +550,8 @@ struct yaffs_DeviceParamStruct { __u8 skipCheckpointRead; __u8 skipCheckpointWrite; + int enableXattr; /* Enable xattribs */ + /* NAND access functions (Must be set before calling YAFFS)*/ int (*writeChunkToNAND) (struct yaffs_DeviceStruct *dev, @@ -597,13 +586,22 @@ struct yaffs_DeviceParamStruct { /* Callback to mark the superblock dirty */ void (*markSuperBlockDirty)(struct yaffs_DeviceStruct *dev); + + /* Callback to control garbage collection. */ + unsigned (*gcControl)(struct yaffs_DeviceStruct *dev); /* Debug control flags. Don't use unless you know what you're doing */ int useHeaderFileSize; /* Flag to determine if we should use file sizes from the header */ int disableLazyLoad; /* Disable lazy loading on this device */ int wideTnodesDisabled; /* Set to disable wide tnodes */ + int disableSoftDelete; /* yaffs 1 only: Set to disable the use of softdeletion. */ + + int deferDirectoryUpdate; /* Set to defer directory updates */ - /* End of stuff that must be set before initialisation. */ +#ifdef CONFIG_YAFFS_AUTO_UNICODE + int autoUnicode; +#endif + int alwaysCheckErased; /* Force chunk erased check always on */ }; typedef struct yaffs_DeviceParamStruct yaffs_DeviceParam; @@ -613,7 +611,10 @@ struct yaffs_DeviceStruct { /* Context storage. Holds extra OS specific data for this device */ - void *context; + void *osContext; + void *driverContext; + + struct ylist_head devList; /* Runtime parameters. Set up by YAFFS. */ int nDataBytesPerChunk; @@ -627,6 +628,7 @@ struct yaffs_DeviceStruct { /* Stuff to support wide tnodes */ __u32 tnodeWidth; __u32 tnodeMask; + __u32 tnodeSize; /* Stuff for figuring out file offset to chunk conversions */ __u32 chunkShift; /* Shift value */ @@ -678,34 +680,31 @@ struct yaffs_DeviceStruct { __u32 allocationPage; int allocationBlockFinder; /* Used to search for next allocation block */ - int nTnodesCreated; - yaffs_Tnode *freeTnodes; - int nFreeTnodes; - yaffs_TnodeList *allocatedTnodeList; - - int isDoingGC; - int gcBlock; - int gcChunk; - - int nObjectsCreated; - yaffs_Object *freeObjects; - int nFreeObjects; + /* Object and Tnode memory management */ + void *allocator; + int nObjects; + int nTnodes; int nHardLinks; - yaffs_ObjectList *allocatedObjectList; - yaffs_ObjectBucket objectBucket[YAFFS_NOBJECT_BUCKETS]; __u32 bucketFinder; int nFreeChunks; - int currentDirtyChecker; /* Used to find current dirtiest block */ - + /* Garbage collection control */ __u32 *gcCleanupList; /* objects to delete at the end of a GC. */ - int nonAggressiveSkip; /* GC state/mode */ - - int hasPendingPrioritisedGCs; /* We think this device might have pending prioritised gcs */ + __u32 nCleanups; + + unsigned hasPendingPrioritisedGCs; /* We think this device might have pending prioritised gcs */ + unsigned gcDisable; + unsigned gcBlockFinder; + unsigned gcDirtiest; + unsigned gcPagesInUse; + unsigned gcNotDone; + unsigned gcBlock; + unsigned gcChunk; + unsigned gcSkip; /* Special directories */ yaffs_Object *rootDir; @@ -731,7 +730,7 @@ struct yaffs_DeviceStruct { int nBackgroundDeletions; /* Count of background deletions. */ /* Temporary buffer management */ - yaffs_TempBuffer tempBuffer[YAFFS_N_TEMP_BUFFERS]; + yaffs_buffer_t tempBuffer[YAFFS_N_TEMP_BUFFERS]; int maxTemp; int tempInUse; int unmanagedTempAllocations; @@ -740,28 +739,36 @@ struct yaffs_DeviceStruct { /* yaffs2 runtime stuff */ unsigned sequenceNumber; /* Sequence number of currently allocating block */ unsigned oldestDirtySequence; + unsigned oldestDirtyBlock; /* Block refreshing */ int refreshSkip; /* A skip down counter. Refresh happens when this gets to zero. */ + /* Dirty directory handling */ + struct ylist_head dirtyDirectories; /* List of dirty directories */ + + /* Statistcs */ - int nPageWrites; - int nPageReads; - int nBlockErasures; - int nErasureFailures; - int nGCCopies; - int garbageCollections; - int passiveGarbageCollections; - int nRetriedWrites; - int nRetiredBlocks; - int eccFixed; - int eccUnfixed; - int tagsEccFixed; - int tagsEccUnfixed; - int nDeletions; - int nUnmarkedDeletions; - int refreshCount; - int cacheHits; + __u32 nPageWrites; + __u32 nPageReads; + __u32 nBlockErasures; + __u32 nErasureFailures; + __u32 nGCCopies; + __u32 allGCs; + __u32 passiveGCs; + __u32 oldestDirtyGCs; + __u32 nGCBlocks; + __u32 backgroundGCs; + __u32 nRetriedWrites; + __u32 nRetiredBlocks; + __u32 eccFixed; + __u32 eccUnfixed; + __u32 tagsEccFixed; + __u32 tagsEccUnfixed; + __u32 nDeletions; + __u32 nUnmarkedDeletions; + __u32 refreshCount; + __u32 cacheHits; }; @@ -806,94 +813,157 @@ typedef struct { } yaffs_CheckpointValidity; +struct yaffs_ShadowFixerStruct { + int objectId; + int shadowedId; + struct yaffs_ShadowFixerStruct *next; +}; + +/* Structure for doing xattr modifications */ +typedef struct { + int set; /* If 0 then this is a deletion */ + const YCHAR *name; + const void *data; + int size; + int flags; + int result; +}yaffs_xattr_mod; + + /*----------------------- YAFFS Functions -----------------------*/ -int yaffs_GutsInitialise(yaffs_Device *dev); -void yaffs_Deinitialise(yaffs_Device *dev); +int yaffs_guts_initialise(yaffs_Device *dev); +void yaffs_deinitialise(yaffs_Device *dev); -int yaffs_GetNumberOfFreeChunks(yaffs_Device *dev); +int yaffs_get_n_free_chunks(yaffs_Device *dev); -int yaffs_RenameObject(yaffs_Object *oldDir, const YCHAR *oldName, +int yaffs_rename_obj(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_unlinker(yaffs_Object *dir, const YCHAR *name); +int yaffs_del_obj(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_get_obj_name(yaffs_Object *obj, YCHAR *name, int buffSize); +int yaffs_get_obj_length(yaffs_Object *obj); +int yaffs_get_obj_inode(yaffs_Object *obj); +unsigned yaffs_get_obj_type(yaffs_Object *obj); +int yaffs_get_obj_link_count(yaffs_Object *obj); -int yaffs_SetAttributes(yaffs_Object *obj, struct iattr *attr); -int yaffs_GetAttributes(yaffs_Object *obj, struct iattr *attr); +int yaffs_set_attribs(yaffs_Object *obj, struct iattr *attr); +int yaffs_get_attribs(yaffs_Object *obj, struct iattr *attr); /* File operations */ -int yaffs_ReadDataFromFile(yaffs_Object *obj, __u8 *buffer, loff_t offset, +int yaffs_file_rd(yaffs_Object *obj, __u8 *buffer, loff_t offset, int nBytes); -int yaffs_WriteDataToFile(yaffs_Object *obj, const __u8 *buffer, loff_t offset, +int yaffs_wr_file(yaffs_Object *obj, const __u8 *buffer, loff_t offset, int nBytes, int writeThrough); -int yaffs_ResizeFile(yaffs_Object *obj, loff_t newSize); +int yaffs_resize_file(yaffs_Object *obj, loff_t newSize); -yaffs_Object *yaffs_MknodFile(yaffs_Object *parent, const YCHAR *name, +yaffs_Object *yaffs_create_file(yaffs_Object *parent, const YCHAR *name, __u32 mode, __u32 uid, __u32 gid); -int yaffs_FlushFile(yaffs_Object *obj, int updateTime, int dataSync); +int yaffs_flush_file(yaffs_Object *obj, int updateTime, int dataSync); /* Flushing and checkpointing */ -void yaffs_FlushEntireDeviceCache(yaffs_Device *dev); +void yaffs_flush_whole_cache(yaffs_Device *dev); -int yaffs_CheckpointSave(yaffs_Device *dev); -int yaffs_CheckpointRestore(yaffs_Device *dev); +int yaffs_checkpoint_save(yaffs_Device *dev); +int yaffs_checkpoint_restore(yaffs_Device *dev); /* Directory operations */ -yaffs_Object *yaffs_MknodDirectory(yaffs_Object *parent, const YCHAR *name, +yaffs_Object *yaffs_create_dir(yaffs_Object *parent, const YCHAR *name, __u32 mode, __u32 uid, __u32 gid); -yaffs_Object *yaffs_FindObjectByName(yaffs_Object *theDir, const YCHAR *name); +yaffs_Object *yaffs_find_by_name(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_find_by_number(yaffs_Device *dev, __u32 number); /* Link operations */ yaffs_Object *yaffs_Link(yaffs_Object *parent, const YCHAR *name, yaffs_Object *equivalentObject); -yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object *obj); +yaffs_Object *yaffs_get_equivalent_obj(yaffs_Object *obj); /* Symlink operations */ -yaffs_Object *yaffs_MknodSymLink(yaffs_Object *parent, const YCHAR *name, +yaffs_Object *yaffs_create_symlink(yaffs_Object *parent, const YCHAR *name, __u32 mode, __u32 uid, __u32 gid, const YCHAR *alias); -YCHAR *yaffs_GetSymlinkAlias(yaffs_Object *obj); +YCHAR *yaffs_get_symlink_alias(yaffs_Object *obj); /* Special inodes (fifos, sockets and devices) */ -yaffs_Object *yaffs_MknodSpecial(yaffs_Object *parent, const YCHAR *name, +yaffs_Object *yaffs_create_special(yaffs_Object *parent, const YCHAR *name, __u32 mode, __u32 uid, __u32 gid, __u32 rdev); + +int yaffs_set_xattrib(yaffs_Object *obj, const YCHAR *name, const void * value, int size, int flags); +int yaffs_get_xattrib(yaffs_Object *obj, const YCHAR *name, void *value, int size); +int yaffs_list_xattrib(yaffs_Object *obj, char *buffer, int size); +int yaffs_remove_xattrib(yaffs_Object *obj, const YCHAR *name); + /* Special directories */ yaffs_Object *yaffs_Root(yaffs_Device *dev); yaffs_Object *yaffs_LostNFound(yaffs_Device *dev); #ifdef CONFIG_YAFFS_WINCE /* CONFIG_YAFFS_WINCE special stuff */ -void yfsd_WinFileTimeNow(__u32 target[2]); +void yfsd_win_file_time_now(__u32 target[2]); #endif -void yaffs_HandleDeferedFree(yaffs_Object *obj); +void yaffs_handle_defered_free(yaffs_Object *obj); -/* Debug dump */ -int yaffs_DumpObject(yaffs_Object *obj); - -void yaffs_GutsTest(yaffs_Device *dev); +void yaffs_update_dirty_dirs(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_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi); +int yaffs_bg_gc(yaffs_Device *dev, unsigned urgency); -__u8 *yaffs_GetTempBuffer(yaffs_Device *dev, int lineNo); -void yaffs_ReleaseTempBuffer(yaffs_Device *dev, __u8 *buffer, int lineNo); +/* Debug dump */ +int yaffs_dump_obj(yaffs_Object *obj); + +void yaffs_guts_test(yaffs_Device *dev); + +/* A few useful functions to be used within the core files*/ +void yaffs_chunk_del(yaffs_Device *dev, int chunkId, int markNAND, int lyn); +int yaffs_check_ff(__u8 *buffer, int nBytes); +void yaffs_handle_chunk_error(yaffs_Device *dev, yaffs_BlockInfo *bi); + +__u8 *yaffs_get_temp_buffer(yaffs_Device *dev, int lineNo); +void yaffs_release_temp_buffer(yaffs_Device *dev, __u8 *buffer, int lineNo); + +yaffs_Object *yaffs_find_or_create_by_number(yaffs_Device *dev, + int number, + yaffs_ObjectType type); +int yaffs_put_chunk_in_file(yaffs_Object *in, int chunkInInode, + int chunkInNAND, int inScan); +void yaffs_set_obj_name(yaffs_Object *obj, const YCHAR *name); +void yaffs_set_obj_name_from_oh(yaffs_Object *obj, const yaffs_ObjectHeader *oh); +void yaffs_add_obj_to_dir(yaffs_Object *directory, + yaffs_Object *obj); +YCHAR *yaffs_clone_str(const YCHAR *str); +void yaffs_link_fixup(yaffs_Device *dev, yaffs_Object *hardList); +void yaffs_block_became_dirty(yaffs_Device *dev, int blockNo); +int yaffs_update_oh(yaffs_Object *in, const YCHAR *name, + int force, int isShrink, int shadows, + yaffs_xattr_mod *xop); +void yaffs_handle_shadowed_obj(yaffs_Device *dev, int objId, + int backwardScanning); +int yaffs_check_alloc_available(yaffs_Device *dev, int nChunks); +yaffs_tnode_t *yaffs_get_tnode(yaffs_Device *dev); +yaffs_tnode_t *yaffs_add_find_tnode_0(yaffs_Device *dev, + yaffs_FileStructure *fStruct, + __u32 chunkId, + yaffs_tnode_t *passedTn); + +int yaffs_do_file_wr(yaffs_Object *in, const __u8 *buffer, loff_t offset, + int nBytes, int writeThrough); +void yaffs_resize_file_down( yaffs_Object *obj, loff_t newSize); +void yaffs_skip_rest_of_block(yaffs_Device *dev); + +int yaffs_count_free_chunks(yaffs_Device *dev); + +yaffs_tnode_t *yaffs_find_tnode_0(yaffs_Device *dev, + yaffs_FileStructure *fStruct, + __u32 chunkId); + +__u32 yaffs_get_group_base(yaffs_Device *dev, yaffs_tnode_t *tn, unsigned pos); #endif