WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
disk_pri.h
浏览该文件的文档.
1/* ----------------------------------------------------------------------------
2 * Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved.
3 * Description: LiteOS Disk Module Inside Headfile
4 * Author: Huawei LiteOS Team
5 * Create: 2019-06-12
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
34#ifndef _DISK_PRI_H
35#define _DISK_PRI_H
36
37#include "disk.h"
38#include "los_mux.h"
39
40#ifdef __cplusplus
41extern "C"{
42#endif /* __cplusplus */
43
44#define DISK_MAX_SECTOR_SIZE 512
45
46#define PAR_OFFSET 446 /* MBR: Partition table offset (2) */
47#define BS_SIG55AA 510 /* Signature word (2) */
48#define BS_FILSYSTEMTYPE32 82 /* File system type (1) */
49#define BS_JMPBOOT 0 /* x86 jump instruction (3-byte) */
50#define BS_FILSYSTYPE 0x36 /* File system type (2) */
51#define BS_SIG55AA_VALUE 0xAA55
52
53#define PAR_TYPE_OFFSET 4
54#define PAR_START_OFFSET 8
55#define PAR_COUNT_OFFSET 12
56#define PAR_TABLE_SIZE 16
57#define EXTENDED_PAR 0x0F
58#define EXTENDED_8G 0x05
59
60#define BS_FS_TYPE_MASK 0xFFFFFF
61#define BS_FS_TYPE_VALUE 0x544146
62#define BS_FS_TYPE_FAT 0x0B
63#define BS_FS_TYPE_NTFS 0x07
64
65#define FIRST_BYTE 1
66#define SECOND_BYTE 2
67#define THIRD_BYTE 3
68#define FOURTH_BYTE 4
69
70#define BIT_FOR_BYTE 8
71
72#define LD_WORD_DISK(ptr) (UINT16)(((UINT16)*((UINT8 *)(ptr) + FIRST_BYTE) << (BIT_FOR_BYTE * FIRST_BYTE)) | \
73 (UINT16)*(UINT8 *)(ptr))
74#define LD_DWORD_DISK(ptr) (UINT32)(((UINT32)*((UINT8 *)(ptr) + THIRD_BYTE) << (BIT_FOR_BYTE * THIRD_BYTE)) | \
75 ((UINT32)*((UINT8 *)(ptr) + SECOND_BYTE) << (BIT_FOR_BYTE * SECOND_BYTE)) | \
76 ((UINT16)*((UINT8 *)(ptr) + FIRST_BYTE) << (BIT_FOR_BYTE * FIRST_BYTE)) | \
77 (*(UINT8 *)(ptr)))
78
79#define LD_QWORD_DISK(ptr) ((UINT64)(((UINT64)LD_DWORD_DISK(&(ptr)[FOURTH_BYTE]) << (BIT_FOR_BYTE * FOURTH_BYTE)) | \
80 LD_DWORD_DISK(ptr)))
81
82/* Check VBR string, including FAT, NTFS */
83#define VERIFY_FS(ptr) (((LD_DWORD_DISK(&(ptr)[BS_FILSYSTEMTYPE32]) & BS_FS_TYPE_MASK) == BS_FS_TYPE_VALUE) || \
84 !strncmp(&(ptr)[BS_FILSYSTYPE], "FAT", strlen("FAT")) || \
85 !strncmp(&(ptr)[BS_JMPBOOT], "\xEB\x52\x90" "NTFS ", \
86 strlen("\xEB\x52\x90" "NTFS ")))
87
88#define PARTION_MODE_BTYE (PAR_OFFSET + PAR_TYPE_OFFSET) /* 0xEE: GPT(GUID), else: MBR */
89#define PARTION_MODE_GPT 0xEE /* 0xEE: GPT(GUID), else: MBR */
90#define SIGNATURE_OFFSET 0 /* The offset of GPT partition header signature */
91#define SIGNATURE_LEN 8 /* The length of GPT signature */
92#define HEADER_SIZE_OFFSET 12 /* The offset of GPT header size */
93#define TABLE_SIZE_OFFSET 84 /* The offset of GPT table size */
94#define TABLE_NUM_OFFSET 80 /* The number of GPT table */
95#define TABLE_START_SECTOR 2
96#define TABLE_MAX_NUM 128
97#define TABLE_SIZE 128
98#define GPT_PAR_START_OFFSET 32
99#define GPT_PAR_END_OFFSET 40
100#define PAR_ENTRY_NUM_PER_SECTOR 4
101#define HEADER_SIZE_MASK 0xFFFFFFFF
102#define HEADER_SIZE 0x5C
103#define HARD_DISK_GUID_OFFSET 56
104#define HARD_DISK_GUID_FOR_ESP 0x0020004900460045
105#define HARD_DISK_GUID_FOR_MSP 0x007200630069004D
106#define PAR_VALID_OFFSET0 0
107#define PAR_VALID_OFFSET1 4
108#define PAR_VALID_OFFSET2 8
109#define PAR_VALID_OFFSET3 12
110
111#define VERIFY_GPT(ptr) ((!strncmp(&(ptr)[SIGNATURE_OFFSET], "EFI PART", SIGNATURE_LEN)) && \
112 ((LD_DWORD_DISK(&(ptr)[HEADER_SIZE_OFFSET]) & HEADER_SIZE_MASK) == HEADER_SIZE))
113
114#define VERITY_PAR_VALID(ptr) ((LD_DWORD_DISK(&(ptr)[PAR_VALID_OFFSET0]) + \
115 LD_DWORD_DISK(&(ptr)[PAR_VALID_OFFSET1]) + \
116 LD_DWORD_DISK(&(ptr)[PAR_VALID_OFFSET2]) + \
117 LD_DWORD_DISK(&(ptr)[PAR_VALID_OFFSET3])) != 0)
118
119/* ESP MSP */
120#define VERITY_AVAILABLE_PAR(ptr) ((LD_QWORD_DISK(&(ptr)[HARD_DISK_GUID_OFFSET]) != HARD_DISK_GUID_FOR_ESP) && \
121 (LD_QWORD_DISK(&(ptr)[HARD_DISK_GUID_OFFSET]) != HARD_DISK_GUID_FOR_MSP))
122
123typedef enum _disk_status_ {
127 STAT_ONGOING /* Not a state machine, represents an intermediate state when init and deinit */
129
130#define DISK_LOCK(disk) do { \
131 UINT32 ret_ = LOS_MuxPend((disk)->disk_mutex, LOS_WAIT_FOREVER); \
132 if (ret_ != LOS_OK) { \
133 PRINT_ERR("%s %d, mutex lock failed, ret = 0x%x\n", \
134 __FUNCTION__, __LINE__, ret_); \
135 } \
136} while (0)
137
138#define DISK_UNLOCK(disk) do { \
139 UINT32 ret_ = LOS_MuxPost((disk)->disk_mutex); \
140 if (ret_ != LOS_OK) { \
141 PRINT_ERR("%s %d, mutex unlock failed, ret: 0x%x\n", \
142 __FUNCTION__, __LINE__, ret_); \
143 } \
144} while (0)
145
146#ifdef LOSCFG_FS_FAT_CACHE
147extern UINT32 GetFatBlockNums(VOID);
148extern VOID SetFatBlockNums(UINT32 blockNums);
149extern UINT32 GetFatSectorsPerBlock(VOID);
150extern VOID SetFatSectorsPerBlock(UINT32 sectorsPerBlock);
151#endif
152extern INT32 SetDiskPartName(los_part *part, const CHAR *src);
153extern INT32 EraseDiskByID(UINT32 diskId, size_t startSector, UINT32 sectors);
154extern BOOL IsBlockStatusReady(const struct inode *blkDriver);
156
157#ifdef __cplusplus
158}
159#endif /* __cplusplus */
160
161#endif
VOID OsDiskInit(VOID)
INT32 EraseDiskByID(UINT32 diskId, size_t startSector, UINT32 sectors)
enum _disk_status_ disk_status_e
_disk_status_
Definition disk_pri.h:123
@ STAT_UNUSED
Definition disk_pri.h:124
@ STAT_INUSED
Definition disk_pri.h:125
@ STAT_ONGOING
Definition disk_pri.h:127
@ STAT_UNREADY
Definition disk_pri.h:126
INT32 SetDiskPartName(los_part *part, const CHAR *src)
BOOL IsBlockStatusReady(const struct inode *blkDriver)
signed int INT32
Definition los_typedef.h:55
#define VOID
Definition los_typedef.h:88
unsigned int UINT32
Definition los_typedef.h:52
char CHAR
Definition los_typedef.h:58
size_t BOOL
Definition los_typedef.h:83
Definition disk.h:97