• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TAR_UTIL_H
17 #define TAR_UTIL_H
18 
19 #include <cstdint>
20 
21 class TarUtil {
22 public:
23     static const int32_t MODE_MASK = 07777;
24     static const int32_t NAME_LEN = 100;
25     static const int32_t MODE_LEN = 8;
26     static const int32_t SIZE_LEN = 12;
27     static const int32_t CHKSUM_LEN = 8;
28     static const int32_t BLOCK_LEN = 512;
29     static const int32_t MAX_PATH_LEN = 4096; // Linux系统中的文件路径长度上限为4096个字符
30     static const int32_t RENAME_START_CNT = 1;
31     static const int32_t CHKSUM_ASCII_VALUE = 256;
32     static const char GNUTYPE_LONGNAME = 'L';
33 };
34 
35 enum RESULT {
36     OK = 0,
37     ERROR = -1,
38     NULL_POINTER = -2,
39     LIST_EMPTY = -3,
40     PATH_EMPTY = -4,
41     OPEN_FILE_FAIL = -5,
42     FILE_NOT_EXIST = -6,
43     FILE_UNREADABLE = -7,
44     READ_INCOMPLETE = -8,
45     WRITE_INCOMPLETE = -9,
46     FILE_REMOVE_FAIL = -10,
47     MAKE_DIR_FAIL = -11,
48 };
49 
50 typedef struct {        /* byte offset */
51     char name[100];     /*   0 */
52     char mode[8];       /* 100 */
53     char uid[8];        /* 108 */
54     char gid[8];        /* 116 */
55     char size[12];      /* 124 */
56     char mtime[12];     /* 136 */
57     char chksum[8];     /* 148 */
58     char typeflag;      /* 156 */
59     char linkname[100]; /* 157 */
60     char magic[6];      /* 257 */
61     char version[2];    /* 263 */
62     char uname[32];     /* 265 */
63     char gname[32];     /* 297 */
64     char devmajor[8];   /* 329 */
65     char devminor[8];   /* 337 */
66     char prefix[155];   /* 345 */
67     char paddings[12];  /* 500 */
68 } TarHeader;
69 
70 #endif // TAR_UTIL_H