1 /* 2 * Copyright (c) 2025 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 PHONECLONE_INSTALLDTARUTILS_H 17 #define PHONECLONE_INSTALLDTARUTILS_H 18 #include <sys/types.h> 19 #include <string> 20 #include "securec.h" 21 #include "log.h" 22 23 namespace installd { 24 #define UID_GID_OFFSET 10000 25 #define APP_ID_START 10000 26 #define EOVERLAP_AND_RESET 182 27 #define TMAGIC "ustar" /* ustar and a null */ 28 #define TMAGIC_LEN 6 29 30 #define TMODE_BASE 100 31 #define TMODE_LEN 8 32 #define TUID_BASE 108 33 #define TUID_LEN 8 34 #define TGID_BASE 116 35 #define TGID_LEN 8 36 #define TSIZE_BASE 124 37 #define TSIZE_LEN 12 38 39 #define CHKSUM_BASE 148 40 41 #define BLOCK_SIZE 512 42 #define BLANK_SPACE 0x20 43 44 #define PATH_MAX_LEN 2048 45 #define READ_BUFF_SIZE (512 * 1024) 46 const int MB_TO_BYTE = (1024 * 1024); 47 48 #define ERR_PARAM (-1) 49 #define ERR_NOEXIST (-2) 50 #define ERR_FORMAT (-3) 51 #define ERR_MALLOC (-4) 52 #define ERR_IO (-5) 53 54 #define REGTYPE '0' /* regular file */ 55 #define AREGTYPE '\0' /* regular file */ 56 #define SYMTYPE '2' /* reserved */ 57 #define DIRTYPE '5' /* directory */ 58 #define SPLIT_START_TYPE '8' 59 #define SPLIT_CONTINUE_TYPE '9' 60 #define SPLIT_END_TYPE 'A' 61 62 #define GNUTYPE_LONGLINK 'K' 63 64 #define PERMISSION_MASK 07777 65 #define MAX_FILESIZE 0777777777777LL 66 const int SIZE_OF_LONG_IN_32_SYSTEM = 4; 67 68 #define OCTSTRING_LENGTH (sizeof(off_t) * 3 + 1) 69 70 #define LONG_LINK_SYMBOL "././@LongLink" 71 #define VERSION "00" 72 #define SPACE ' ' 73 #define SLASH '/' 74 75 #define DO_ERROR (-1) 76 #define DO_CONTINUE 0 77 #define DO_IGNORETHIS 1 78 #define DO_TRAVERSAL 2 79 #define DO_EXIT 3 80 #define SPLIT_SIZE (1024 * 1024 * 500) // 500M 81 #define FILTER_SIZE (1024 * 1024 * 100) // 100M 82 83 // callback 84 class TarCallBack { 85 public: ~TarCallBack()86 virtual ~TarCallBack() {} 87 88 public: 89 virtual bool IsAborted() = 0; 90 virtual void OnTaskProgress(size_t szProcessed) = 0; 91 virtual void OnPackagedUseBriefGenTar(long szProcessed) = 0; 92 virtual void OnPackagedOneSplitTar(const char *name) = 0; 93 virtual void WaitTaskLocked() = 0; 94 }; 95 96 const int PATH_LENTH = 2048; 97 struct File_info { 98 char path[PATH_LENTH]; 99 int mode; 100 int type; 101 long size; 102 time_t modified_time; 103 }; 104 } // namespace installd 105 #endif // PHONECLONE_INSTALLDTARUTILS_H