-
Notifications
You must be signed in to change notification settings - Fork 0
/
brn2.h
122 lines (105 loc) · 3.16 KB
/
brn2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright (C) 2022 Patel, Nimai <[email protected]>
* Author: Patel, Nimai <[email protected]>
* Copyright (C) 2023-2024 Mior, Lucas; <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BRN2_H
#define BRN2_H
#ifdef __linux__
#define _GNU_SOURCE
#endif
#include <assert.h>
#include <dirent.h>
#include <fcntl.h>
#include <getopt.h>
#include <linux/limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <threads.h>
#include <unistd.h>
#include "hash.h"
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define RESET "\x1b[0m"
#define USE_HASH_MAP_THRESHOLD 128
#define USE_THREADS_THRESHOLD 524288
#define MAX_THREADS 64
#define MEMCHR_BYTES 16
#define MIN(a,b) (a) < (b) ? (a) : (b)
#define MAX(a,b) (a) > (b) ? (a) : (b)
#ifndef BRN2_DEBUG
#define BRN2_DEBUG 0
#endif
#define STRUCT_ARRAY_SIZE(struct_object, ArrayType, array_length) \
(sizeof (*struct_object) + (usize)(array_length) * sizeof (ArrayType))
#define SWAP(x, y) do { __typeof__(x) SWAP = x; x = y; y = SWAP; } while (0)
#define ARRAY_LENGTH(ARRAY_LENGTH) \
(sizeof(ARRAY_LENGTH) / sizeof(*ARRAY_LENGTH))
#ifndef INTEGERS
#define INTEGERS
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef size_t usize;
typedef ssize_t isize;
#endif
typedef struct File {
char name[PATH_MAX-12];
int fd;
FILE *stream;
} File;
typedef struct FileName {
char *name;
uint32 length;
uint32 hash;
} FileName;
typedef struct FileList {
char *map;
uint32 map_size;
uint32 length;
FileName files[];
} FileList;
typedef struct Hash {
uint32 mod;
} Hash;
extern char *program;
extern bool brn2_fatal;
extern bool brn2_implict;
extern uint32 nthreads;
int brn2_compare(const void *, const void *);
FileList *brn2_list_from_dir(char *);
FileList *brn2_list_from_lines(char *, uint32);
FileList *brn2_list_from_args(int, char **);
void brn2_normalize_names(FileList *);
Hash *brn2_create_hashes(FileList *, uint32);
bool brn2_verify(FileList *, FileList *, HashMap *, Hash *);
uint32 brn2_get_number_changes(FileList *, FileList *);
uint32 brn2_execute(FileList *, FileList *, HashMap *, Hash *, Hash *, bool);
void brn2_free_lines_list(FileList *);
void brn2_free_dir_list(FileList *);
void brn2_usage(FILE *) __attribute__((noreturn));
void error(char *, ...);
#endif