xref: /nrf52832-nimble/rt-thread/components/dfs/filesystems/uffs/src/inc/uffs/uffs_mem.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 #ifndef _UFFS_MEM_H_
34 #define _UFFS_MEM_H_
35 
36 #include "uffs/uffs_device.h"
37 
38 #ifdef __cplusplus
39 extern "C"{
40 #endif
41 
42 /** uffs memory allocator */
43 typedef struct uffs_memAllocatorSt {
44 	URET (*init)(struct uffs_DeviceSt *dev);			//!< init memory allocator, setup buffer sizes
45 	URET (*release)(struct uffs_DeviceSt *dev);			//!< release memory allocator (for dynamic memory allocation)
46 
47 	void * (*malloc)(struct uffs_DeviceSt *dev, unsigned int size); //!< allocate memory (for dynamic memory allocation)
48 	URET (*free)(struct uffs_DeviceSt *dev, void *p);   //!< free memory (for dynamic memory allocation)
49 
50 	void * blockinfo_pool_buf;			//!< block info cache buffers
51 	void * pagebuf_pool_buf;			//!< page buffers
52 	void * tree_nodes_pool_buf;			//!< tree nodes buffer
53 	void * spare_pool_buf;				//!< spare buffers
54 
55 	int blockinfo_pool_size;			//!< block info cache buffers size
56 	int pagebuf_pool_size;				//!< page buffers size
57 	int tree_nodes_pool_size;			//!< tree nodes buffer size
58 	int spare_pool_size;				//!< spare buffer pool size
59 
60 	uffs_Pool tree_pool;
61 	uffs_Pool spare_pool;
62 
63 	int spare_data_size;				//!< spare size consumed by UFFS,
64 										//!< calculated by UFFS according to the layout information.
65 
66 	/* for static memory allocator */
67 	char *buf_start;
68 	int buf_size;
69 	int pos;
70 
71 
72 } uffs_MemAllocator;
73 
74 void uffs_MemSetupSystemAllocator(uffs_MemAllocator *allocator);
75 void uffs_MemSetupStaticAllocator(uffs_MemAllocator *allocator, void *pool, int size);
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 
82 #endif
83 
84