Skip to content

Commit

Permalink
include/fileeq: add functions to compare files content
Browse files Browse the repository at this point in the history
Signed-off-by: Karel Zak <kzak@redhat.com>
  • Loading branch information
karelzak committed Oct 29, 2021
1 parent ee4c324 commit ee2d371
Show file tree
Hide file tree
Showing 4 changed files with 695 additions and 1 deletion.
1 change: 0 additions & 1 deletion include/all-io.h
Expand Up @@ -111,5 +111,4 @@ static inline ssize_t sendfile_all(int out, int in, off_t *off, size_t count)
return -1;
#endif
}

#endif /* UTIL_LINUX_ALL_IO_H */
53 changes: 53 additions & 0 deletions include/fileeq.h
@@ -0,0 +1,53 @@
#ifndef UTIL_LINUX_FILEEQ
#define UTIL_LINUX_FILEEQ

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>

/* Number of bytes from the beginnning of the file we always
* compare by memcmp() */
#define UL_FILEEQ_INTROSIZ 32

struct ul_fileeq_data {
unsigned char intro[UL_FILEEQ_INTROSIZ];
unsigned char *blocks;
size_t nblocks;
size_t maxblocks;
int fd;
const char *name;
bool is_eof;
};

struct ul_fileeq {
int fd_api; /* Crypto socket */
int fd_cip; /* Cipher handler */

size_t readsiz;
uint64_t filesiz;
uint64_t blocksmax;
const struct ul_fileeq_method *method;

/* UL_FILEEQ_MEMCMP buffers */
unsigned char *buf_a;
unsigned char *buf_b;
unsigned char *buf_last;
};

extern int ul_fileeq_init(struct ul_fileeq *eq, const char *method);
extern void ul_fileeq_deinit(struct ul_fileeq *eq);


extern int ul_fileeq_data_associated(struct ul_fileeq_data *data);
extern void ul_fileeq_data_close_file(struct ul_fileeq_data *data);
extern void ul_fileeq_data_init(struct ul_fileeq_data *data);
extern void ul_fileeq_data_deinit(struct ul_fileeq_data *data);
extern void ul_fileeq_data_set_file(struct ul_fileeq_data *data,
const char *name);
extern size_t ul_fileeq_set_size(struct ul_fileeq *eq, uint64_t filesiz,
size_t readsiz, size_t memsiz);

extern int ul_fileeq(struct ul_fileeq *eq,
struct ul_fileeq_data *a, struct ul_fileeq_data *b);

#endif /* UTIL_LINUX_FILEEQ */
4 changes: 4 additions & 0 deletions lib/Makemodule.am
Expand Up @@ -84,6 +84,7 @@ check_PROGRAMS += \
test_buffer \
test_canonicalize \
test_colors \
test_fileeq \
test_fileutils \
test_ismounted \
test_pwdutils \
Expand Down Expand Up @@ -188,6 +189,9 @@ test_linux_version_SOURCES = lib/linux_version.c
test_linux_version_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM_LINUXVERSION
endif

test_fileeq_SOURCES = lib/fileeq.c
test_fileeq_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM_FILEEQ

test_fileutils_SOURCES = lib/fileutils.c
test_fileutils_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM_FILEUTILS

Expand Down

0 comments on commit ee2d371

Please sign in to comment.