1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef STARTUP_LIBFS_HVB_H 17 #define STARTUP_LIBFS_HVB_H 18 19 #include <stdbool.h> 20 #include <stdio.h> 21 #include <stdint.h> 22 #include <hvb.h> 23 #include <hvb_cert.h> 24 #include "fs_dm.h" 25 #include "fs_manager.h" 26 #include "ext4_super_block.h" 27 #include "erofs_super_block.h" 28 29 #ifdef __cplusplus 30 #if __cplusplus 31 extern "C" { 32 #endif 33 #endif 34 35 #define USE_FEC_FROM_DEVICE "use_fec_from_device" 36 #define FEC_ROOTS "fec_roots" 37 #define FEC_BLOCKS "fec_blocks" 38 #define FEC_START "fec_start" 39 #define BLOCK_SIZE_UINT 4096 40 #define EXTHDR_MAGIC 0xFEEDBEEF 41 #define EXTHDR_BLKSIZ 4096 42 #define SZ_1KB (0x1 << 10) 43 #define SZ_1MB (0x1 << 20) 44 #define SZ_1GB (0x1 << 30) 45 46 #define SZ_2KB (2 * SZ_1KB) 47 #define SZ_4KB (4 * SZ_1KB) 48 49 typedef struct { 50 uint32_t magicNumber; 51 uint16_t exthdrSize; 52 uint16_t bcc16; 53 uint64_t partSize; 54 } ExtheaderV1; 55 56 int FsHvbInit(void); 57 int FsHvbSetupHashtree(FstabItem *fsItem); 58 int FsHvbFinal(void); 59 struct hvb_ops *FsHvbGetOps(void); 60 int FsHvbGetValueFromCmdLine(char *val, size_t size, const char *key); 61 int FsHvbConstructVerityTarget(DmVerityTarget *target, const char *devName, struct hvb_cert *cert); 62 void FsHvbDestoryVerityTarget(DmVerityTarget *target); 63 64 bool CheckAndGetExt4Size(const char *headerBuf, uint64_t *imageSize, const char* image); 65 bool CheckAndGetErofsSize(const char *headerBuf, uint64_t *imageSize, const char* image); 66 bool CheckAndGetExtheaderSize(const int fd, uint64_t offset, uint64_t *imageSize, const char* image); 67 68 #ifdef __cplusplus 69 #if __cplusplus 70 } 71 #endif 72 #endif 73 74 #endif // STARTUP_LIBFS_HVB_H 75