WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
bcache.h
浏览该文件的文档.
1/* ----------------------------------------------------------------------------
2 * Copyright (c) Huawei Technologies Co., Ltd. 2015-2019. All rights reserved.
3 * Description: LiteOS Bcache Module Headfile
4 * Author: Huawei LiteOS Team
5 * Create: 2015-01-01
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14 * to endorse or promote products derived from this software without specific prior written
15 * permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * --------------------------------------------------------------------------- */
28#ifndef _BCACHE_H
29#define _BCACHE_H
30
31#include "pthread.h"
32#include "linux/rbtree.h"
33#include "los_list.h"
34#include "los_atomic.h"
35#ifdef LOSCFG_SHELL
36#include "reset_shell.h"
37#endif
38#include "inode/inode.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif /* __cplusplus */
43
44#define ALIGN_LIB(x) (((x) + (HALARC_ALIGNMENT - 1)) & ~(HALARC_ALIGNMENT - 1))
45#define ALIGN_DISP(x) (HALARC_ALIGNMENT - ((x) & (HALARC_ALIGNMENT - 1)))
46#define UNSIGNED_INTEGER_BITS 32
47#define UNINT_MAX_SHIFT_BITS 31
48#define UNINT_LOG2_SHIFT 5
49#define EVEN_JUDGED 2
50#define PERCENTAGE 100
51
52#if CONFIG_FS_FAT_SECTOR_PER_BLOCK < UNSIGNED_INTEGER_BITS
53#error cache too small
54#else
55#define BCACHE_BLOCK_FLAGS (CONFIG_FS_FAT_SECTOR_PER_BLOCK / UNSIGNED_INTEGER_BITS)
56#endif
57
58typedef struct {
59 LOS_DL_LIST listNode; /* list node */
60 struct rb_node rbNode; /* red-black tree node */
61 UINT64 num; /* block number */
62 Atomic status; /* the block status */
63 BOOL readFlag; /* is the block data have read form sd(real data) */
64 UINT64 age; /* the tick value of first fetch block */
65 UINT8 *data; /* block data */
66 UINT32 flag[0];
68
69typedef INT32 (*BcacheReadFun)(struct inode *, /* private data */
70 UINT8 *, /* block buffer */
71 UINT32, /* number of blocks to read */
72 UINT64); /* starting block number */
73
74typedef INT32 (*BcacheWriteFun)(struct inode *, /* private data */
75 const UINT8 *, /* block buffer */
76 UINT32, /* number of blocks to write */
77 UINT64); /* starting block number */
78
79typedef INT32 (*BcacheWritevFun)(struct inode *, /* private data */
80 const struct iovec *, /* segments */
81 UINT32, /* segments size to write */
82 UINT64); /* starting block number */
83
84typedef struct tagOsBcache {
85 VOID *priv; /* private data */
86 LOS_DL_LIST listHead; /* head of block list */
87 struct rb_root rbRoot; /* block red-black tree root */
88 UINT32 blockSize; /* block size in bytes */
89 UINT32 blockSizeLog2; /* block size log2 */
90 UINT64 blockCount; /* block count of the disk */
91 UINT32 sectorSize; /* device sector size in bytes */
92 UINT32 sectorPerBlock; /* sector count per block */
93 UINT8 *memStart; /* memory base */
94 UINT64 curBlockNum; /* current preread block number */
95 LOS_DL_LIST freeListHead; /* list of free blocks */
96 BcacheReadFun breadFun; /* block read function */
97 BcacheWriteFun bwriteFun; /* block write function */
98 BcacheWritevFun bwritevFun; /* block write segments function */
99 UINT8 *rwBuffer; /* buffer for bcache block */
100 UINT32 bcacheMutex; /* mutex for bcache */
101 EVENT_CB_S bcacheEvent; /* event for bcache */
102 Atomic dirtyBlockNums; /* number of dirty blocks */
103#ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD
104 BOOL syncTaskDelete; /* delete notify flag */
105 BOOL syncTaskPend; /* sync task is pending */
106 UINT32 syncTaskId; /* sync task id */
107#endif
109
136 UINT8 *buf,
137 UINT32 *len,
138 UINT64 num,
139 UINT64 pos);
140
167 const UINT8 *buf,
168 UINT32 *len,
169 UINT64 num,
170 UINT64 pos);
171
194
220OsBcache *BlockCacheInit(struct inode *devNode,
221 UINT32 sectorSize,
222 UINT32 sectorPerBlock,
223 UINT32 blockNum,
224 UINT64 blockCount);
225
247
249
250#ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD
251VOID BcacheSyncThreadInit(OsBcache *bc, INT32 id);
252VOID BcacheSyncThreadDeinit(OsBcache *bc);
253#endif
254
255#ifdef __cplusplus
256}
257#endif /* __cplusplus */
258#endif /* _BCACHE_H */
INT32 BlockCacheWrite(OsBcache *bc, const UINT8 *buf, UINT32 *len, UINT64 num, UINT64 pos)
INT32(* BcacheReadFun)(struct inode *, UINT8 *, UINT32, UINT64)
Definition bcache.h:69
VOID BlockCacheDeinit(OsBcache *bc)
INT32(* BcacheWritevFun)(struct inode *, const struct iovec *, UINT32, UINT64)
Definition bcache.h:79
INT32 OsSdSync(INT32 id)
INT32 BlockCacheSync(OsBcache *bc)
OsBcache * BlockCacheInit(struct inode *devNode, UINT32 sectorSize, UINT32 sectorPerBlock, UINT32 blockNum, UINT64 blockCount)
INT32 BlockCacheRead(OsBcache *bc, UINT8 *buf, UINT32 *len, UINT64 num, UINT64 pos)
INT32(* BcacheWriteFun)(struct inode *, const UINT8 *, UINT32, UINT64)
Definition bcache.h:74
struct tagOsBcache OsBcache
signed int INT32
Definition los_typedef.h:55
unsigned long long UINT64
Definition los_typedef.h:72
#define VOID
Definition los_typedef.h:88
volatile INT32 Atomic
Definition los_typedef.h:85
unsigned char UINT8
Definition los_typedef.h:50
unsigned int UINT32
Definition los_typedef.h:52
size_t BOOL
Definition los_typedef.h:83
Definition los_list.h:47
Definition bcache.h:58
UINT64 age
Definition bcache.h:64
Atomic status
Definition bcache.h:62
BOOL readFlag
Definition bcache.h:63
LOS_DL_LIST listNode
Definition bcache.h:59
UINT8 * data
Definition bcache.h:65
UINT64 num
Definition bcache.h:61
Definition los_event.h:164
Definition bcache.h:84
LOS_DL_LIST freeListHead
Definition bcache.h:95
LOS_DL_LIST listHead
Definition bcache.h:86
Atomic dirtyBlockNums
Definition bcache.h:102
UINT8 * memStart
Definition bcache.h:93
BcacheWriteFun bwriteFun
Definition bcache.h:97
UINT32 sectorPerBlock
Definition bcache.h:92
VOID * priv
Definition bcache.h:85
struct rb_root rbRoot
Definition bcache.h:87
UINT8 * rwBuffer
Definition bcache.h:99
BcacheWritevFun bwritevFun
Definition bcache.h:98
UINT64 blockCount
Definition bcache.h:90
UINT32 bcacheMutex
Definition bcache.h:100
UINT32 blockSizeLog2
Definition bcache.h:89
BcacheReadFun breadFun
Definition bcache.h:96
UINT64 curBlockNum
Definition bcache.h:94
UINT32 sectorSize
Definition bcache.h:91
UINT32 blockSize
Definition bcache.h:88
EVENT_CB_S bcacheEvent
Definition bcache.h:101