From 9bcb789360472ad4cbcb2765f5a34af6b9e7a888 Mon Sep 17 00:00:00 2001 From: Spencer Williams Date: Thu, 30 Nov 2017 13:59:53 -0800 Subject: [PATCH 1/2] write crc magic and check --- svr4.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/svr4.go b/svr4.go index 2ad6752..5f1dc2e 100644 --- a/svr4.go +++ b/svr4.go @@ -13,7 +13,7 @@ const ( svr4MaxFileSize = 4294967295 ) -var svr4Magic = []byte{0x30, 0x37, 0x30, 0x37, 0x30, 0x31} // 07070 +var svr4Magic = []byte{0x30, 0x37, 0x30, 0x37, 0x30, 0x31} // 07071 func readHex(s string) int64 { // errors are ignored and 0 returned @@ -108,7 +108,11 @@ func writeSVR4Header(w io.Writer, hdr *Header) (pad int64, err error) { for i := 0; i < len(hdrBuf); i++ { hdrBuf[i] = '0' } - copy(hdrBuf[:], svr4Magic) + magic := svr4Magic + if hdr.Checksum != 0 { + magic[5] = 0x32 + } + copy(hdrBuf[:], magic) writeHex(hdrBuf[6:14], hdr.Inode) writeHex(hdrBuf[14:22], int64(hdr.Mode)) writeHex(hdrBuf[22:30], int64(hdr.UID)) @@ -119,6 +123,9 @@ func writeSVR4Header(w io.Writer, hdr *Header) (pad int64, err error) { } writeHex(hdrBuf[54:62], hdr.Size) writeHex(hdrBuf[94:102], int64(len(hdr.Name)+1)) + if hdr.Checksum != 0 { + writeHex(hdrBuf[102:110], int64(hdr.Checksum)) + } // write header _, err = w.Write(hdrBuf[:]) From 8cfca68504f5e2af99d423a15525d3c0514db518 Mon Sep 17 00:00:00 2001 From: Spencer Williams Date: Fri, 1 Dec 2017 17:09:34 -0800 Subject: [PATCH 2/2] typo --- svr4.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svr4.go b/svr4.go index 5f1dc2e..f965554 100644 --- a/svr4.go +++ b/svr4.go @@ -13,7 +13,7 @@ const ( svr4MaxFileSize = 4294967295 ) -var svr4Magic = []byte{0x30, 0x37, 0x30, 0x37, 0x30, 0x31} // 07071 +var svr4Magic = []byte{0x30, 0x37, 0x30, 0x37, 0x30, 0x31} // 070701 func readHex(s string) int64 { // errors are ignored and 0 returned