diff --git a/rpatch.c b/rpatch.c index 523c19b..bbe4485 100644 --- a/rpatch.c +++ b/rpatch.c @@ -1,14 +1,14 @@ #include "io_funcs.h" #include "rpatch.h" -int +lp_UMDiffFile lp_PatchSet_open(const char *path) { } int -lp_PatchSet_covered(lp_PatchSet *ps, u32 offset) +lp_PatchSet_covered(lp_UMDiffCommand *ps, u32 offset) { } diff --git a/rpatch.h b/rpatch.h index e724731..864b971 100644 --- a/rpatch.h +++ b/rpatch.h @@ -1,20 +1,6 @@ #ifndef __RPATCH_H #define __RPATCH_H - -typedef struct { - long sector_start; - long sector_count; - - /* If zero, block is unchanged */ - long patch_start; - - /* If smaller than sector_count, repeating data */ - long patch_len; -} lp_Patch; - -typedef struct { - -} lp_PatchSet; +#include "umdiff/umdiff.h" #endif //__RPATCH_H diff --git a/umdiff/Makefile b/umdiff/Makefile index e69de29..39973c1 100644 --- a/umdiff/Makefile +++ b/umdiff/Makefile @@ -0,0 +1,27 @@ +TARGET = umdiff +C_OBJS = main.o rdiff.o +OBJS = $(C_OBJS) + +CMAKE := cmake + +LIBRSYNC_SOURCE := librsync + +ifeq (,$(wildcard /usr/lib*/librsync.*)) + CFLAGS += -I$(LIBRSYNC_SOURCE)/src + OBJS += librsync.a +else + LIBS += -lrsync +endif + +$(TARGET): $(OBJS) + $(CC) -o $@ $^ $(CFLAGS) $(LIBS) + +librsync: + git clone https://github.com/librsync/librsync + +librsync.a: $(LIBRSYNC_SOURCE) + mkdir -p librsync.build + cd librsync.build && $(CMAKE) -DBUILD_SHARED_LIBS=0 $(shell realpath $(LIBRSYNC_SOURCE)) && make + mv librsync.build/librsync.a . + rm -rf librsync.build + diff --git a/umdiff/main.c b/umdiff/main.c new file mode 100644 index 0000000..8677c17 --- /dev/null +++ b/umdiff/main.c @@ -0,0 +1,4 @@ +int main(int argc, char *argv[]) +{ + +} diff --git a/umdiff/rdiff.c b/umdiff/rdiff.c new file mode 100644 index 0000000..e69de29 diff --git a/umdiff/umdiff.h b/umdiff/umdiff.h new file mode 100644 index 0000000..eee5ed6 --- /dev/null +++ b/umdiff/umdiff.h @@ -0,0 +1,77 @@ +#ifndef __UMDIFF_H +#define __UMDIFF_H + +/** + * @file umdiff.h + * @author Karim Vergnes + * @copyright GPLv2 + * @brief Definitions for UMDiff file format + * + * This file contains all required types to read and parse a UMDiff file. + */ + +#define UMDIFF_VERSION 0x00 + +/** + * @brief Index of commands at 1024 sector interval. + * + * This list contains the offset of the first command for every 1024 sector + * block. + * + * The value represents an offset to read the file from, in the command list. + * If a command exists across a 1024-sector boundary, the offset shall point + * to the start of that command. + * + * Pointers spanning past the end of the disc are undefined and shall not be + * used. + */ +typedef long lp_UMDiffIndex[2048]; + +typedef struct +__attribute__((packed)) { + char magic[7]; /* = 0x7f 'UMDiff' */ + char version; + long cmd_len; + long data_start; + lp_UMDiffIndex index; +} lp_UMDiffHeader; + +/** + * @brief Definition for a single patch command. + * + * This is the format for a unit 'patch command'. A patch command is comprised + * of five parameters: + * + * - sector_start: Where on the original disc the patch command takes + * effect, in sectors. + * - sector_count: How many sectors on the original disc the patch + * command spans. + * - patch_start: Where in the patch source the substitute data is + * found, in sectors. + * - patch_sector_count: How many sectors on the patch source the + * substitute data occupies. If smaller than sector_count, then + * the substitute is a repeating pattern of that length. + * - data_source: 1 if the substitute data is on the original disc, + * 0 if it is in the UMDiff file's data area. + */ +typedef struct { + long sector_start; + long sector_count; + + long patch_start; + long patch_sector_count; /* if < sector_count, repeat */ + + long data_source; /* 0 = patchfile, 1 = source */ +} lp_UMDiffCommand; + +// Commands shall start immediately after the full header +#define UMDIFF_COMMANDS_START (sizeof lp_UMDiffHeader) + +typedef struct { + lp_UMDiffHeader *hdr; + lp_UMDiffCommand *commands; +} lp_UMDiffFile; + +#endif //__UMDIFF_H + +// vim: ft=c.doxygen