xref: /nrf52832-nimble/rt-thread/components/dfs/filesystems/uffs/src/inc/uffs/uffs_blockinfo.h (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2   This file is part of UFFS, the Ultra-low-cost Flash File System.
3 
4   Copyright (C) 2005-2009 Ricky Zheng <[email protected]>
5 
6   UFFS is free software; you can redistribute it and/or modify it under
7   the GNU Library General Public License as published by the Free Software
8   Foundation; either version 2 of the License, or (at your option) any
9   later version.
10 
11   UFFS is distributed in the hope that it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   or GNU Library General Public License, as applicable, for more details.
15 
16   You should have received a copy of the GNU General Public License
17   and GNU Library General Public License along with UFFS; if not, write
18   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19   Boston, MA  02110-1301, USA.
20 
21   As a special exception, if other files instantiate templates or use
22   macros or inline functions from this file, or you compile this file
23   and link it with other works to produce a work based on this file,
24   this file does not by itself cause the resulting work to be covered
25   by the GNU General Public License. However the source code for this
26   file must still be made available in accordance with section (3) of
27   the GNU General Public License v2.
28 
29   This exception does not invalidate any other reasons why a work based
30   on this file might be covered by the GNU General Public License.
31 */
32 /**
33  * \file uffs_blockinfo.h
34  * \brief data structure for operating block information
35  * \author Ricky Zheng
36  */
37 
38 #ifndef _UFFS_BLOCKINFO_H_
39 #define _UFFS_BLOCKINFO_H_
40 
41 #include "uffs/uffs_types.h"
42 #include "uffs/uffs_public.h"
43 #include "uffs/uffs_core.h"
44 
45 #ifdef __cplusplus
46 extern "C"{
47 #endif
48 /**
49  * \struct uffs_PageSpareSt
50  * \brief this structure is for storing uffs tag and more.
51  */
52 struct uffs_PageSpareSt {
53 	uffs_Tags tag;			//!< page tag
54 	int expired:1;
55 };
56 
57 /**
58  * \struct uffs_BlockInfoSt
59  * \brief block information data. Block info is frequently accessed,
60           UFFS use a cache system to speed up block info access.
61  */
62 struct uffs_BlockInfoSt {
63 	struct uffs_BlockInfoSt *next;
64 	struct uffs_BlockInfoSt *prev;
65 	u16 block;							//!< block number
66 	struct uffs_PageSpareSt *spares;	//!< page spare info array
67 	int expired_count;					//!< how many pages expired in this block ?
68 	int ref_count;						//!< reference counter, it's safe to reuse this block memory when the counter is 0.
69 };
70 
71 /** get tag from block info */
72 #define GET_TAG(bc, page) (&(bc)->spares[page].tag)
73 
74 
75 /** initialize block info caches */
76 URET uffs_BlockInfoInitCache(uffs_Device *dev, int maxCachedBlocks);
77 
78 /** release block info caches */
79 URET uffs_BlockInfoReleaseCache(uffs_Device *dev);
80 
81 /** load page spare to block info cache */
82 URET uffs_BlockInfoLoad(uffs_Device *dev, uffs_BlockInfo *work, int page);
83 
84 /** find block info cache */
85 uffs_BlockInfo * uffs_BlockInfoFindInCache(uffs_Device *dev, int block);
86 
87 /** get block info cache, load it on demand */
88 uffs_BlockInfo * uffs_BlockInfoGet(uffs_Device *dev, int block);
89 
90 /** put info cache back to pool, should be called with #uffs_BlockInfoGet in pairs. */
91 void uffs_BlockInfoPut(uffs_Device *dev, uffs_BlockInfo *p);
92 
93 /** explicitly expire a block info cache */
94 void uffs_BlockInfoExpire(uffs_Device *dev, uffs_BlockInfo *p, int page);
95 
96 /** no one hold any block info cache ? safe to release block info caches */
97 UBOOL uffs_BlockInfoIsAllFree(uffs_Device *dev);
98 
99 /** explicitly expire all block info caches */
100 void uffs_BlockInfoExpireAll(uffs_Device *dev);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 
107 #endif
108