diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-30 05:04:46 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-30 05:17:21 (EDT) |
commit | ce9008874a492de45c7257f50fafa8c10d2c1eab (patch) | |
tree | 61f4d3895ba7ef9508fe1de9846cd0ec21da1576 | |
parent | 5fc9fd125430db57f352f978867ac1dfb63bc1d0 (diff) |
ustar: Set magic+version+chksum in written header
-rw-r--r-- | src/ustar.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/ustar.c b/src/ustar.c index 3c57ba5..0ecf36a 100644 --- a/src/ustar.c +++ b/src/ustar.c @@ -271,7 +271,10 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar, uid_t uid, const char *uname, gid_t gid, const char *gname, uint64_t size, char type, const char *linkname) { - size_t linkname_len; + size_t linkname_len; + uint32_t chksum; + size_t i; + char *header_uc; if (opkg_opk_dirent_name_prefix(dirent, ustar->header.name, @@ -316,6 +319,19 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar, } memset(ustar->header.linkname, 0, sizeof(ustar->header.linkname) - linkname_len); + + strcpy(ustar->header.magic, "ustar"); + memcpy(ustar->header.version, "00", 2); + chksum = 0; + for (i = 0; i < sizeof(ustar->header.chksum); ++i) { + ustar->header.chksum[i] = ' '; + } + header_uc = (char *) &ustar->header; + for (i = 0; i < OPKG_OPK_USTAR_RECORD_SIZE; ++i) { + chksum += header_uc[i]; + } + sprintf(ustar->header.chksum, "%o", chksum); + if (opkg_opk_gzip_write(ustar->gzip, &ustar->header, OPKG_OPK_USTAR_RECORD_SIZE, 0) != OPKG_OPK_OK) { return OPKG_OPK_ERROR; |