uffs_device.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. This file is part of UFFS, the Ultra-low-cost Flash File System.
  3. Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
  4. UFFS is free software; you can redistribute it and/or modify it under
  5. the GNU Library General Public License as published by the Free Software
  6. Foundation; either version 2 of the License, or (at your option) any
  7. later version.
  8. UFFS is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. or GNU Library General Public License, as applicable, for more details.
  12. You should have received a copy of the GNU General Public License
  13. and GNU Library General Public License along with UFFS; if not, write
  14. to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. As a special exception, if other files instantiate templates or use
  17. macros or inline functions from this file, or you compile this file
  18. and link it with other works to produce a work based on this file,
  19. this file does not by itself cause the resulting work to be covered
  20. by the GNU General Public License. However the source code for this
  21. file must still be made available in accordance with section (3) of
  22. the GNU General Public License v2.
  23. This exception does not invalidate any other reasons why a work based
  24. on this file might be covered by the GNU General Public License.
  25. */
  26. /**
  27. * \file uffs_device.h
  28. * \brief uffs device structures definition
  29. * \author Ricky Zheng
  30. */
  31. #ifndef UFFS_DEVICE_H
  32. #define UFFS_DEVICE_H
  33. #include "uffs/uffs_types.h"
  34. #include "uffs/uffs_config.h"
  35. #include "uffs/uffs_buf.h"
  36. #include "uffs/uffs_blockinfo.h"
  37. #include "uffs/uffs_pool.h"
  38. #include "uffs/uffs_tree.h"
  39. #include "uffs/uffs_mem.h"
  40. #include "uffs/uffs_core.h"
  41. #include "uffs/uffs_flash.h"
  42. #ifdef __cplusplus
  43. extern "C"{
  44. #endif
  45. /**
  46. * \struct uffs_BlockInfoCacheSt
  47. * \brief block information structure, used to manager block information caches
  48. */
  49. struct uffs_BlockInfoCacheSt {
  50. uffs_BlockInfo *head; //!< buffer head of block info(spares)
  51. uffs_BlockInfo *tail; //!< buffer tail
  52. void *mem_pool; //!< internal memory pool, used for release whole buffer
  53. };
  54. /**
  55. * \struct uffs_PartitionSt
  56. * \brief partition basic information
  57. */
  58. struct uffs_PartitionSt {
  59. u16 start; //!< start block number of partition
  60. u16 end; //!< end block number of partiton
  61. };
  62. /**
  63. * \struct uffs_LockSt
  64. * \brief lock stuffs
  65. */
  66. struct uffs_LockSt {
  67. int sem;
  68. int task_id;
  69. int counter;
  70. };
  71. /**
  72. * \struct uffs_DirtyGroupSt
  73. * \brief manager dirty page buffers
  74. */
  75. struct uffs_DirtyGroupSt {
  76. int count; //!< dirty buffers count
  77. int lock; //!< dirty group lock (0: unlocked, >0: locked)
  78. uffs_Buf *dirty; //!< dirty buffer list
  79. };
  80. /**
  81. * \struct uffs_PageBufDescSt
  82. * \brief uffs page buffers descriptor
  83. */
  84. struct uffs_PageBufDescSt {
  85. uffs_Buf *head; //!< head of buffers
  86. uffs_Buf *tail; //!< tail of buffers
  87. struct uffs_DirtyGroupSt dirtyGroup[MAX_DIRTY_BUF_GROUPS]; //!< dirty buffer groups
  88. int buf_max; //!< maximum buffers
  89. int dirty_buf_max; //!< maximum dirty buffer allowed
  90. void *pool; //!< memory pool for buffers
  91. };
  92. /**
  93. * \struct uffs_PageCommInfoSt
  94. * \brief common data for device, should be initialized at early
  95. * \note it is possible that pg_size is smaller than physical page size, but normally they are the same.
  96. * \note page data layout: [HEADER] + [DATA]
  97. */
  98. struct uffs_PageCommInfoSt {
  99. u16 pg_data_size; //!< page data size
  100. u16 header_size; //!< header size
  101. u16 pg_size; //!< page size
  102. };
  103. /**
  104. * \struct uffs_NewBadBlockSt
  105. * \brief holding new discovered bad block
  106. */
  107. struct uffs_NewBadBlockSt {
  108. u16 block; //!< bad block, FIX ME to process more than one bad block
  109. };
  110. /**
  111. * \struct uffs_FlashStatSt
  112. * \typedef uffs_FlashStat
  113. * \brief statistic data of flash read/write/erase activities
  114. */
  115. typedef struct uffs_FlashStatSt {
  116. int block_erase_count;
  117. int page_write_count;
  118. int page_read_count;
  119. int page_header_read_count;
  120. int spare_write_count;
  121. int spare_read_count;
  122. } uffs_FlashStat;
  123. /**
  124. * \struct uffs_DeviceSt
  125. * \brief The core data structure of UFFS, all information needed by manipulate UFFS object
  126. * \note one partition corresponding one uffs device.
  127. */
  128. struct uffs_DeviceSt {
  129. URET (*Init)(uffs_Device *dev); //!< low level initialization
  130. URET (*Release)(uffs_Device *dev); //!< low level release
  131. void *_private; //!< private data for device
  132. struct uffs_StorageAttrSt *attr; //!< storage attribute
  133. struct uffs_PartitionSt par; //!< partition information
  134. struct uffs_FlashOpsSt *ops; //!< flash operations
  135. struct uffs_BlockInfoCacheSt bc; //!< block info cache
  136. struct uffs_LockSt lock; //!< lock data structure
  137. struct uffs_PageBufDescSt buf; //!< page buffers
  138. struct uffs_PageCommInfoSt com; //!< common information
  139. struct uffs_TreeSt tree; //!< tree list of block
  140. struct uffs_NewBadBlockSt bad; //!< new discovered bad block
  141. struct uffs_FlashStatSt st; //!< statistic (counters)
  142. struct uffs_memAllocatorSt mem; //!< uffs native memory allocator
  143. u32 ref_count; //!< device reference count
  144. int dev_num; //!< device number (partition number)
  145. };
  146. /** create the lock for uffs device */
  147. URET uffs_DeviceInitLock(uffs_Device *dev);
  148. /** delete the lock of uffs device */
  149. URET uffs_DeviceReleaseLock(uffs_Device *dev);
  150. /** lock uffs device */
  151. URET uffs_DeviceLock(uffs_Device *dev);
  152. /** unlock uffs device */
  153. URET uffs_DeviceUnLock(uffs_Device *dev);
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif