From: Richard W.M. Jones <"Richard W.M. Jones "> Date: Sat, 2 Feb 2008 16:09:45 +0000 (+0000) Subject: Change the attachment format so that it contains offsets, not absolute locations. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=dafc5348594b5ddf9ac7c9634b67dbe6c64a3fbe;p=virt-p2v.git Change the attachment format so that it contains offsets, not absolute locations. --- diff --git a/iso-attach b/iso-attach index 55bcd3e..107b63e 100755 --- a/iso-attach +++ b/iso-attach @@ -50,7 +50,7 @@ open Unix * stuff them into a tarball or ZIP file and attach that. *) -let magic = "ISOATTACHMENT002" +let magic = "ISOATTACHMENT003" let magiclen = String.length magic (* = 16 bytes *) let trailerlen = magiclen + 8 + 8 (* magic + file start + true size *) @@ -169,7 +169,8 @@ and do_add isoname attachment = let size = file_size + trailerlen in let over = size land 2047 in if over > 0 then 2048-over else 0 in - assert ((padding_size + file_size + trailerlen) land 2047 = 0); + let attachment_size = padding_size + file_size + trailerlen in + assert (attachment_size land 2047 = 0); (* Write the padding. *) ignore (write fd (String.make padding_size 'x') 0 padding_size); @@ -177,8 +178,8 @@ and do_add isoname attachment = (* Write the magic. *) ignore (write fd magic 0 magiclen); - (* Write the file start and true size. *) - let buffer = string_of_int64 iso_size in + (* Write the attachment size and true file size. *) + let buffer = string_of_int64 (Int64.of_int attachment_size) in ignore (write fd buffer 0 8); let buffer = string_of_int64 (Int64.of_int file_size) in ignore (write fd buffer 0 8); @@ -192,14 +193,16 @@ and do_delete isoname = if read fd buf 0 magiclen <> magiclen || buf <> magic then failwith "no attachment found"; - (* Read the start offset of the file. *) + (* Read the size of the attachment *) let buf = String.create 8 in if read fd buf 0 8 <> 8 then failwith "cannot read attachment size"; - let offset = int64_of_string buf in + let attachment_size = int64_of_string buf in + + let orig_size = LargeFile.lseek fd (Int64.neg attachment_size) SEEK_END in (* Truncate to start of the file. *) - LargeFile.ftruncate fd offset; + LargeFile.ftruncate fd orig_size; close fd @@ -210,18 +213,18 @@ and do_get isoname output = if read fd buf 0 magiclen <> magiclen || buf <> magic then failwith "no attachment found"; - (* Read the start and size. *) + (* Read the attachment size and true size. *) let buf = String.create 8 in if read fd buf 0 8 <> 8 then - failwith "cannot read attachment offset"; - let offset = int64_of_string buf in + failwith "cannot read attachment size"; + let attachment_size = int64_of_string buf in let buf = String.create 8 in if read fd buf 0 8 <> 8 then - failwith "cannot read attachment size"; + failwith "cannot read file true size"; let size = Int64.to_int (int64_of_string buf) in (* Seek to beginning of the attachment. *) - ignore (LargeFile.lseek fd offset SEEK_SET); + ignore (LargeFile.lseek fd (Int64.neg attachment_size) SEEK_END); (* Copy out the attachment. *) let fd2 = openfile output [O_WRONLY; O_CREAT; O_TRUNC] 0o644 in