started work on UMDiff tool

This commit is contained in:
TheSola10 2025-04-04 14:07:11 +02:00
parent f4d366ce01
commit 8cb83ec37e
Signed by: thesola10
GPG Key ID: 89245619BEBB95BA
6 changed files with 111 additions and 17 deletions

View File

@ -1,14 +1,14 @@
#include "io_funcs.h" #include "io_funcs.h"
#include "rpatch.h" #include "rpatch.h"
int lp_UMDiffFile
lp_PatchSet_open(const char *path) lp_PatchSet_open(const char *path)
{ {
} }
int int
lp_PatchSet_covered(lp_PatchSet *ps, u32 offset) lp_PatchSet_covered(lp_UMDiffCommand *ps, u32 offset)
{ {
} }

View File

@ -1,20 +1,6 @@
#ifndef __RPATCH_H #ifndef __RPATCH_H
#define __RPATCH_H #define __RPATCH_H
#include "umdiff/umdiff.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;
#endif //__RPATCH_H #endif //__RPATCH_H

View File

@ -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

4
umdiff/main.c Normal file
View File

@ -0,0 +1,4 @@
int main(int argc, char *argv[])
{
}

0
umdiff/rdiff.c Normal file
View File

77
umdiff/umdiff.h Normal file
View File

@ -0,0 +1,77 @@
#ifndef __UMDIFF_H
#define __UMDIFF_H
/**
* @file umdiff.h
* @author Karim Vergnes <me@thesola.io>
* @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:
*
* - <tt>sector_start</tt>: Where on the original disc the patch command takes
* effect, in sectors.
* - <tt>sector_count</tt>: How many sectors on the original disc the patch
* command spans.
* - <tt>patch_start</tt>: Where in the patch source the substitute data is
* found, in sectors.
* - <tt>patch_sector_count</tt>: How many sectors on the patch source the
* substitute data occupies. If smaller than <tt>sector_count</tt>, then
* the substitute is a repeating pattern of that length.
* - <tt>data_source</tt>: 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