From ce9008874a492de45c7257f50fafa8c10d2c1eab Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 30 Apr 2023 05:04:46 -0400 Subject: ustar: Set magic+version+chksum in written header --- (limited to 'src') 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; -- cgit v0.9.1