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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/*
* Copyright (c) 2013 Stefan Bolte <portix@gmx.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* Pack/Unpack files/directories to dwb-extension archive. Only directories and
* regular files are supported. Unlike tar exar doesn't preserve symbolic links,
* instead a copy is packed into the archive and an extension archive doesn't
* preserve any ownership or permissions, so an extension archive cannot contain
* any executables.
*
* File format:
*
* [file header][file][file header][file][file he...
*
* file header : - file info 22 bytes
* - 7 bytes version header, null terminated (char)
* - 1 byte filetype flag (d|f) (char)
* - 14 byte file size, null terminated (char, hex)
* - file name, null terminated, maximum 4096 bytes
* file : saved as unsigned char
* */
#ifndef __EXAR_H__
#define __EXAR_H__
#include <sys/types.h>
enum {
EXAR_VERBOSE_L1 = 1<<0,
EXAR_VERBOSE_L2 = 1<<1,
EXAR_VERBOSE_L3 = 1<<2,
};
#define EXAR_VERBOSE_MASK (0x7)
/*
* Packs a file or directory
* @path: Path to the file or directory to pack
*
* @returns 0 on success and -1 on error
* */
int
exar_pack(const char *path);
/*
* Appends a file or directory to the archive
* @archive The archive
* @path The file or directory to append
*
* @returns 0 on success
*/
int
exar_append(const char *archive, const char *path);
/*
* Unpacks an archive
* @path: Path to the extension archive
* @dest: Destination directory or NULL for current directory
*
* @returns 0 on success and -1 on error
* */
int
exar_unpack(const char *path, const char *dest);
/*
* Extracts a file from an extension archive
* @archive The archive
* @file The path of the file in the archive
* @size Return location for the size, if an error occurs size will be set to -1
*
* @returns A newly allocated char buffer with the file content or NULL if an error
* occured or the file was not found in the archive
* */
unsigned char *
exar_extract(const char *archive, const char *file, off_t *size);
/*
* Searches for a file and extracts the content from the archive.
*
* @archive The archive
* @search The search term. The search term must either match the full path or
* the filename
* @size Return location for the size, if an error occurs size will be set to -1
*
* @returns A newly allocated char buffer with the file content or NULL if an error
* occured or the file was not found in the archive
* */
unsigned char *
exar_search_extract(const char *archive, const char *search, off_t *size);
/*
* Deletes a file from the archive, if it is a directory it is removed
* recursively.
*
* @archive The archive
* @file The file to delete
*
* @returns 0 on success and -1 on error
*/
int
exar_delete(const char *archive, const char *file);
/*
* Checks if the file is an archive file with compatible version number
*
* @archive The archive
* @verbose Whether to print error messages to stderr
*
* @returns 0 on success and -1 on error
*/
int
exar_check_version(const char *archive);
/*
* Print info about the archive to stdout.
*
* @archive The archive
* */
void
exar_info(const char *archive);
/*
* Checks if an archive contains a file
*
* @archive The archive
* @path The path of the file in the archive
*
* @returns 0 if the file was found, -1 otherwise
* */
int
exar_contains(const char *archive, const char *path);
/*
* Checks if an archive contains a file
*
* @archive The archive
* @search The search term. The search term must either match the full path or
* the filename
*
* @returns 0 if the file was found, -1 otherwise
* */
int
exar_search_contains(const char *archive, const char *search);
/*
* Set verbosity flags, exar will be most verbose if all flags are set, log
* messages are printed to stderr.
* @v_flags
*/
void
exar_verbose(unsigned char v_flags);
#endif
|