1 /* 2 * Copyright (c) 2022-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 CLIENT_TRANS_PROXY_FILE_COMMON_H 17 #define CLIENT_TRANS_PROXY_FILE_COMMON_H 18 19 #include <stdint.h> 20 21 #define MAX_FILE_PATH_NAME_LEN 512 22 #define INVALID_FD (-1) 23 24 #define SOFTBUS_F_RDLCK 0 25 #define SOFTBUS_F_WRLCK 1 26 27 #define BYTE_INT_NUM 4 28 #define BIT_INT_NUM 32 29 #define BIT_BYTE_NUM 8 30 31 #define FRAME_NUM_0 0 32 #define FRAME_NUM_1 1 33 #define FRAME_NUM_2 2 34 35 #define OH_TYPE 10 36 #define PATH_SEPARATOR '/' 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 typedef struct { 43 uint8_t *buffer; 44 uint32_t bufferSize; 45 } FileListBuffer; 46 47 bool IsPathValid(char *filePath); 48 int32_t GetAndCheckRealPath(const char *filePath, char *absPath); 49 bool CheckDestFilePathValid(const char *destFile); 50 int32_t FrameIndexToType(uint64_t index, uint64_t frameNumber); 51 52 char *BufferToFileList(uint8_t *buffer, uint32_t bufferSize, int32_t *fileCount); 53 int32_t FileListToBuffer(const char **destFile, uint32_t fileCnt, FileListBuffer *outbufferInfo); 54 55 const char* TransGetFileName(const char* path); 56 57 uint16_t RTU_CRC(const unsigned char *puchMsg, uint16_t usDataLen); 58 59 int32_t FileLock(int32_t fd, int32_t type, bool isBlock); 60 int32_t TryFileLock(int32_t fd, int32_t type, int32_t retryTimes); 61 int32_t FileUnLock(int32_t fd); 62 63 #ifdef __cplusplus 64 } 65 #endif 66 #endif // CLIENT_TRANS_PROXY_FILE_COMMON_H 67