michael@0: /*- michael@0: * Copyright 2003,2004 Colin Percival michael@0: * All rights reserved michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted providing that the following conditions michael@0: * are met: michael@0: * 1. Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * 2. Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR michael@0: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED michael@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY michael@0: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL michael@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS michael@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, michael@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING michael@0: * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE michael@0: * POSSIBILITY OF SUCH DAMAGE. michael@0: * michael@0: * Changelog: michael@0: * 2005-04-26 - Define the header as a C structure, add a CRC32 checksum to michael@0: * the header, and make all the types 32-bit. michael@0: * --Benjamin Smedberg michael@0: */ michael@0: michael@0: #ifndef bspatch_h__ michael@0: #define bspatch_h__ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: typedef struct MBSPatchHeader_ { michael@0: /* "MBDIFF10" */ michael@0: char tag[8]; michael@0: michael@0: /* Length of the file to be patched */ michael@0: uint32_t slen; michael@0: michael@0: /* CRC32 of the file to be patched */ michael@0: uint32_t scrc32; michael@0: michael@0: /* Length of the result file */ michael@0: uint32_t dlen; michael@0: michael@0: /* Length of the control block in bytes */ michael@0: uint32_t cblen; michael@0: michael@0: /* Length of the diff block in bytes */ michael@0: uint32_t difflen; michael@0: michael@0: /* Length of the extra block in bytes */ michael@0: uint32_t extralen; michael@0: michael@0: /* Control block (MBSPatchTriple[]) */ michael@0: /* Diff block (binary data) */ michael@0: /* Extra block (binary data) */ michael@0: } MBSPatchHeader; michael@0: michael@0: /** michael@0: * Read the header of a patch file into the MBSPatchHeader structure. michael@0: * michael@0: * @param fd Must have been opened for reading, and be at the beginning michael@0: * of the file. michael@0: */ michael@0: int MBS_ReadHeader(FILE* file, MBSPatchHeader *header); michael@0: michael@0: /** michael@0: * Apply a patch. This method does not validate the checksum of the original michael@0: * file: client code should validate the checksum before calling this method. michael@0: * michael@0: * @param patchfd Must have been processed by MBS_ReadHeader michael@0: * @param fbuffer The original file read into a memory buffer of length michael@0: * header->slen. michael@0: * @param filefd Must have been opened for writing. Should be truncated michael@0: * to header->dlen if it is an existing file. The offset michael@0: * should be at the beginning of the file. michael@0: */ michael@0: int MBS_ApplyPatch(const MBSPatchHeader *header, FILE* patchFile, michael@0: unsigned char *fbuffer, FILE* file); michael@0: michael@0: typedef struct MBSPatchTriple_ { michael@0: uint32_t x; /* add x bytes from oldfile to x bytes from the diff block */ michael@0: uint32_t y; /* copy y bytes from the extra block */ michael@0: int32_t z; /* seek forwards in oldfile by z bytes */ michael@0: } MBSPatchTriple; michael@0: michael@0: #endif // bspatch_h__