diff --git a/frameworks/native/backup_ext/include/tar_file.h b/frameworks/native/backup_ext/include/tar_file.h index 5b9dbd3d11a0ad16f70b71992d0e13a523ee76fe..4e1a8a28e10653eb300c3027d7c6d4bdae1f0328 100644 --- a/frameworks/native/backup_ext/include/tar_file.h +++ b/frameworks/native/backup_ext/include/tar_file.h @@ -47,7 +47,7 @@ const uint32_t TSIZE_BASE = 124; const uint32_t TMTIME_BASE = 136; const uint32_t CHKSUM_BASE = 148; const uint32_t BLOCK_SIZE = 512; -const uint64_t READ_BUFF_SIZE = 512 * 1024; +const off_t READ_BUFF_SIZE = 512 * 1024; const uint8_t BLANK_SPACE = 0x20; const uint64_t MB_TO_BYTE = 1024 * 1024; const std::string TMAGIC = "ustar"; @@ -56,7 +56,7 @@ const char AREGTYPE = '\0'; // regular file const char SYMTYPE = '2'; // reserved const char DIRTYPE = '5'; // directory const char GNUTYPE_LONGNAME = 'L'; -} +} // namespace // 512 bytes using TarHeader = struct { @@ -127,7 +127,7 @@ private: * @param read 读取文件 * @param isFilled 是否写完 */ - int SplitWriteAll(const std::vector &ioBuffer, int read, bool &isFilled); + off_t SplitWriteAll(const std::vector &ioBuffer, off_t read, bool &isFilled); /** * @brief creaat split tarfile @@ -176,7 +176,7 @@ private: * @param iobuffer 文件信息数组 * @param size 文件大小 */ - int ReadAll(int fd, std::vector &ioBuffer, off_t size); + off_t ReadAll(int fd, std::vector &ioBuffer, off_t size); /** * @brief write files diff --git a/frameworks/native/backup_ext/src/tar_file.cpp b/frameworks/native/backup_ext/src/tar_file.cpp index aa1ebee0d791db60bebe4ff751123d2d3e011507..bbb135e3f34c5dd8a0381ee70dd4f319e7746302 100644 --- a/frameworks/native/backup_ext/src/tar_file.cpp +++ b/frameworks/native/backup_ext/src/tar_file.cpp @@ -208,8 +208,8 @@ bool TarFile::WriteFileContent(const string &fileName, off_t size) bool isFilled = false; while (remain > 0) { - size_t read = ioBuffer_.size(); - if (size < ioBuffer_.size()) { + off_t read = ioBuffer_.size(); + if (size < static_cast(ioBuffer_.size())) { read = size; } else { if (read > remain) { @@ -241,13 +241,13 @@ bool TarFile::WriteFileContent(const string &fileName, off_t size) return false; } -int TarFile::SplitWriteAll(const vector &ioBuffer, int read, bool &isFilled) +off_t TarFile::SplitWriteAll(const vector &ioBuffer, off_t read, bool &isFilled) { - size_t len = ioBuffer.size(); + off_t len = ioBuffer.size(); if (len > read) { len = read; } - size_t count = 0; + off_t count = 0; while (count < len) { auto writeBytes = fwrite(&ioBuffer[count], sizeof(uint8_t), len - count, currentTarFile_); if (writeBytes < 1) { @@ -322,10 +322,10 @@ bool TarFile::FillSplitTailBlocks() void TarFile::SetCheckSum(TarHeader &hdr) { int sum = 0; - vector buffer {}; + vector buffer {}; buffer.resize(sizeof(hdr)); buffer.assign(reinterpret_cast(&hdr), reinterpret_cast(&hdr) + sizeof(hdr)); - for (int index = 0; index < BLOCK_SIZE; index++) { + for (uint32_t index = 0; index < BLOCK_SIZE; index++) { if (index < CHKSUM_BASE || index > CHKSUM_BASE + CHKSUM_LEN - 1) { sum += (buffer[index] & 0xFF); } else { @@ -339,7 +339,7 @@ void TarFile::FillOwnerName(TarHeader &hdr, const struct stat &st) { struct passwd *pw = getpwuid(st.st_uid); if (pw != nullptr) { - int ret = snprintf_s(hdr.uname, sizeof(hdr.uname), sizeof(hdr.uname) - 1, "%s", pw->pw_name); + size_t ret = snprintf_s(hdr.uname, sizeof(hdr.uname), sizeof(hdr.uname) - 1, "%s", pw->pw_name); if (ret < 0 || ret >= sizeof(hdr.uname)) { HILOGE("Fill pw_name failed, err = %{public}d", errno); } @@ -364,10 +364,10 @@ void TarFile::FillOwnerName(TarHeader &hdr, const struct stat &st) } } -int TarFile::ReadAll(int fd, vector &ioBuffer, off_t size) +off_t TarFile::ReadAll(int fd, vector &ioBuffer, off_t size) { - size_t count = 0; - size_t len = ioBuffer.size(); + off_t count = 0; + off_t len = ioBuffer.size(); if (len > size) { len = size; }