* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HDC_HEADER_H
#define HDC_HEADER_H
#include <cstdint>
#include <string>
#include "common.h"
namespace Hdc {
#define HEADER_LEN 512
#define HEADER_NAME_LEN 100
#define HEADER_MODE_LEN 8
#define HEADER_UID_LEN 8
#define HEADER_GID_LEN 8
#define HEADER_SIZE_LEN 12
#define HEADER_MTIME_LEN 12
#define HEADER_CHKSUM_LEN 8
#define HEADER_TYPEFLAGE_LEN 1
#define HEADER_LINKNAME_LEN 100
#define HEADER_MAGIC_LEN 6
#define HEADER_VERSION_LEN 2
#define HEADER_UNAME_LEN 32
#define HEADER_GNAME_LEN 32
#define HEADER_DEVMAJOR_LEN 8
#define HEADER_DEVMINOR_LEN 8
#define HEADER_PREFIX_LEN 155
#define HEADER_PAD_LEN 12
#define HEADER_MAX_FILE_LEN 255
typedef enum : uint8_t {
INVALID = 0,
ORDINARYFILE = '0',
HARDLINK = '1',
SOFTLINK = '2',
CHARACTERDEVICE = '3',
BLOCKDEVICE = '4',
DIRECTORY = '5',
FIFO = '6',
RESERVE = '7',
} TypeFlage;
struct Header {
uint8_t name[100] = { 0 };
uint8_t mode[8] = { 0 };
uint8_t uid[8] = { 0 };
uint8_t gid[8] = { 0 };
uint8_t size[12] = { 0 };
uint8_t mtime[12] = { 0 };
uint8_t chksum[8] = { 0 };
uint8_t typeflage[1] = { 0 };
uint8_t linkname[100] = { 0 };
uint8_t magic[6] = { 0 };
uint8_t version[2] = { 0 };
uint8_t uname[32] = { 0 };
uint8_t gname[32] = { 0 };
uint8_t devmajor[8] = { 0 };
uint8_t devminor[8] = { 0 };
uint8_t prefix[155] = { 0 };
uint8_t pad[12] = { 0 };
Header();
explicit Header(uint8_t data[512], int dataLen);
std::string Name();
bool UpdataName(std::string fileName);
uint64_t Size();
void UpdataSize(size_t fileLen);
TypeFlage FileType();
void UpdataFileType(TypeFlage fileType);
bool IsInvalid();
void UpdataCheckSum();
void GetBytes(uint8_t data[512], int dataLen);
};
}
#endif