Skip to content

Commit 19f44ba

Browse files
committed
decompress: change length arguments to long
In order to support decompression of files > 2GiB Linux has changed the prototypes of decompression functions from int uncompress(unsigned char *inbuf, int len, int(*fill)(void*, unsigned int), int(*flush)(void*, unsigned int), unsigned char *output, int *pos, void(*error_fn)(char *x)); to int uncompress(unsigned char *inbuf, long len, long(*fill)(void*, unsigned long), long(*flush)(void*, unsigned long), unsigned char *output, long *pos, void(*error_fn)(char *x)); Do likewise in barebox for easier code sharing with Linux. Link: https://lore.barebox.org/[email protected] Signed-off-by: Sascha Hauer <[email protected]>
1 parent ddf44a1 commit 19f44ba

15 files changed

+81
-81
lines changed

commands/uimage.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
static int uimage_fd;
1515

16-
static int uimage_flush(void *buf, unsigned int len)
16+
static long uimage_flush(void *buf, unsigned long len)
1717
{
1818
return write_full(uimage_fd, buf, len);
1919
}

common/uimage.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,23 @@ EXPORT_SYMBOL(uimage_close);
218218

219219
static int uimage_fd;
220220

221-
static int uimage_fill(void *buf, unsigned int len)
221+
static long uimage_fill(void *buf, unsigned long len)
222222
{
223223
return read_full(uimage_fd, buf, len);
224224
}
225225

226-
static int uncompress_copy(unsigned char *inbuf_unused, int len,
227-
int(*fill)(void*, unsigned int),
228-
int(*flush)(void*, unsigned int),
226+
static int uncompress_copy(unsigned char *inbuf_unused, long len,
227+
long(*fill)(void*, unsigned long),
228+
long(*flush)(void*, unsigned long),
229229
unsigned char *outbuf_unused,
230-
int *pos,
230+
long *pos,
231231
void(*error_fn)(char *x))
232232
{
233233
int ret;
234234
void *buf = xmalloc(PAGE_SIZE);
235235

236236
while (len) {
237-
int now = min(len, PAGE_SIZE);
237+
int now = min_t(long, len, PAGE_SIZE);
238238
ret = fill(buf, now);
239239
if (ret < 0)
240240
goto err;
@@ -295,17 +295,17 @@ EXPORT_SYMBOL(uimage_verify);
295295
* Load a uimage, flushing output to flush function
296296
*/
297297
int uimage_load(struct uimage_handle *handle, unsigned int image_no,
298-
int(*flush)(void*, unsigned int))
298+
long(*flush)(void*, unsigned long))
299299
{
300300
image_header_t *hdr = &handle->header;
301301
struct uimage_handle_data *iha;
302302
int ret;
303303
loff_t off;
304-
int (*uncompress_fn)(unsigned char *inbuf, int len,
305-
int(*fill)(void*, unsigned int),
306-
int(*flush)(void*, unsigned int),
304+
int (*uncompress_fn)(unsigned char *inbuf, long len,
305+
long(*fill)(void*, unsigned long),
306+
long(*flush)(void*, unsigned long),
307307
unsigned char *output,
308-
int *pos,
308+
long *pos,
309309
void(*error)(char *x));
310310

311311
if (image_no >= handle->nb_data_entries)
@@ -336,7 +336,7 @@ static void *uimage_buf;
336336
static size_t uimage_size;
337337
static struct resource *uimage_resource;
338338

339-
static int uimage_sdram_flush(void *buf, unsigned int len)
339+
static long uimage_sdram_flush(void *buf, unsigned long len)
340340
{
341341
if (uimage_size + len > resource_size(uimage_resource)) {
342342
resource_size_t start = uimage_resource->start;

include/bunzip2.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#ifndef DECOMPRESS_BUNZIP2_H
33
#define DECOMPRESS_BUNZIP2_H
44

5-
int bunzip2(unsigned char *inbuf, int len,
6-
int(*fill)(void*, unsigned int),
7-
int(*flush)(void*, unsigned int),
5+
int bunzip2(unsigned char *inbuf, long len,
6+
long(*fill)(void*, unsigned long),
7+
long(*flush)(void*, unsigned long),
88
unsigned char *output,
9-
int *pos,
9+
long *pos,
1010
void(*error)(char *x));
1111
#endif

include/gunzip.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#ifndef GUNZIP_H
33
#define GUNZIP_H
44

5-
int gunzip(unsigned char *inbuf, int len,
6-
int(*fill)(void*, unsigned int),
7-
int(*flush)(void*, unsigned int),
5+
int gunzip(unsigned char *inbuf, long len,
6+
long(*fill)(void*, unsigned long),
7+
long(*flush)(void*, unsigned long),
88
unsigned char *output,
9-
int *pos,
9+
long *pos,
1010
void(*error_fn)(char *x));
1111
#endif

include/image.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ struct uimage_handle *uimage_open(const char *filename);
300300
void uimage_close(struct uimage_handle *handle);
301301
int uimage_verify(struct uimage_handle *handle);
302302
int uimage_load(struct uimage_handle *handle, unsigned int image_no,
303-
int(*flush)(void*, unsigned int));
303+
long(*flush)(void*, unsigned long));
304304
void uimage_print_contents(struct uimage_handle *handle);
305305
ssize_t uimage_get_size(struct uimage_handle *handle, unsigned int image_no);
306306
struct resource *uimage_load_to_sdram(struct uimage_handle *handle,

include/linux/decompress/unlz4.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#ifndef DECOMPRESS_UNLZ4_H
44
#define DECOMPRESS_UNLZ4_H
55

6-
int decompress_unlz4(unsigned char *inbuf, int len,
7-
int(*fill)(void*, unsigned int),
8-
int(*flush)(void*, unsigned int),
6+
int decompress_unlz4(unsigned char *inbuf, long len,
7+
long(*fill)(void*, unsigned long),
8+
long(*flush)(void*, unsigned long),
99
unsigned char *output,
10-
int *pos,
10+
long *pos,
1111
void(*error)(char *x));
1212
#endif

include/linux/xz.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,10 @@ XZ_EXTERN void xz_crc32_init(void);
264264
XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc);
265265
#endif
266266

267-
STATIC int decompress_unxz(unsigned char *in, int in_size,
268-
int (*fill)(void *dest, unsigned int size),
269-
int (*flush)(void *src, unsigned int size),
270-
unsigned char *out, int *in_used,
267+
STATIC int decompress_unxz(unsigned char *in, long in_size,
268+
long (*fill)(void *dest, unsigned long size),
269+
long (*flush)(void *src, unsigned long size),
270+
unsigned char *out, long *in_used,
271271
void (*error)(char *x));
272272

273273
#endif

include/lzo.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ STATIC int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
4747
#define LZO_E_NOT_YET_IMPLEMENTED (-9)
4848
#define LZO_E_INVALID_ARGUMENT (-10)
4949

50-
STATIC int decompress_unlzo(u8 *input, int in_len,
51-
int (*fill) (void *, unsigned int),
52-
int (*flush) (void *, unsigned int),
53-
u8 *output, int *posp,
50+
STATIC int decompress_unlzo(u8 *input, long in_len,
51+
long (*fill) (void *, unsigned long),
52+
long (*flush) (void *, unsigned long),
53+
u8 *output, long *posp,
5454
void (*error) (char *x));
5555

5656
#endif

include/uncompress.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#ifndef __UNCOMPRESS_H
33
#define __UNCOMPRESS_H
44

5-
int uncompress(unsigned char *inbuf, int len,
6-
int(*fill)(void*, unsigned int),
7-
int(*flush)(void*, unsigned int),
5+
int uncompress(unsigned char *inbuf, long len,
6+
long(*fill)(void*, unsigned long),
7+
long(*flush)(void*, unsigned long),
88
unsigned char *output,
9-
int *pos,
9+
long *pos,
1010
void(*error_fn)(char *x));
1111

1212
int uncompress_fd_to_fd(int infd, int outfd,

lib/decompress_bunzip2.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct bunzip_data {
8989
/* State for interrupting output loop */
9090
int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent;
9191
/* I/O tracking data (file handles, buffers, positions, etc.) */
92-
int (*fill)(void*, unsigned int);
92+
long (*fill)(void*, unsigned long);
9393
int inbufCount, inbufPos /*, outbufPos*/;
9494
unsigned char *inbuf /*,*outbuf*/;
9595
unsigned int inbufBitCount, inbufBits;
@@ -614,16 +614,16 @@ static int read_bunzip(struct bunzip_data *bd, char *outbuf, int len)
614614
goto decode_next_byte;
615615
}
616616

617-
static int nofill(void *buf, unsigned int len)
617+
static long nofill(void *buf, unsigned long len)
618618
{
619619
return -1;
620620
}
621621

622622
/* Allocate the structure, read file header. If in_fd ==-1, inbuf must contain
623623
a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
624624
ignored, and data is read from file handle into temporary buffer. */
625-
static int start_bunzip(struct bunzip_data **bdp, void *inbuf, int len,
626-
int (*fill)(void*, unsigned int))
625+
static int start_bunzip(struct bunzip_data **bdp, void *inbuf, long len,
626+
long (*fill)(void*, unsigned long))
627627
{
628628
struct bunzip_data *bd;
629629
unsigned int i, j, c;
@@ -672,11 +672,11 @@ static int start_bunzip(struct bunzip_data **bdp, void *inbuf, int len,
672672

673673
/* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip2 data,
674674
not end of file.) */
675-
int bunzip2(unsigned char *buf, int len,
676-
int(*fill)(void*, unsigned int),
677-
int(*flush)(void*, unsigned int),
675+
int bunzip2(unsigned char *buf, long len,
676+
long(*fill)(void*, unsigned long),
677+
long(*flush)(void*, unsigned long),
678678
unsigned char *outbuf,
679-
int *pos,
679+
long *pos,
680680
void(*error)(char *x))
681681
{
682682
struct bunzip_data *bd;

lib/decompress_inflate.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232

3333
#define GZIP_IOBUF_SIZE (16*1024)
3434

35-
static int nofill(void *buffer, unsigned int len)
35+
static long nofill(void *buffer, unsigned long len)
3636
{
3737
return -1;
3838
}
3939

4040
/* Included from initramfs et al code */
41-
int gunzip(unsigned char *buf, int len,
42-
int(*fill)(void*, unsigned int),
43-
int(*flush)(void*, unsigned int),
41+
int gunzip(unsigned char *buf, long len,
42+
long(*fill)(void*, unsigned long),
43+
long(*flush)(void*, unsigned long),
4444
unsigned char *out_buf,
45-
int *pos,
45+
long *pos,
4646
void(*error)(char *x)) {
4747
u8 *zbuf;
4848
struct z_stream_s *strm;

lib/decompress_unlz4.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
#define LZ4_DEFAULT_UNCOMPRESSED_CHUNK_SIZE (8 << 20)
3939
#define ARCHIVE_MAGICNUMBER 0x184C2102
4040

41-
static inline int unlz4(u8 *input, int in_len,
42-
int (*fill) (void *, unsigned int),
43-
int (*flush) (void *, unsigned int),
44-
u8 *output, int *posp,
41+
static inline int unlz4(u8 *input, long in_len,
42+
long (*fill) (void *, unsigned long),
43+
long (*flush) (void *, unsigned long),
44+
u8 *output, long *posp,
4545
void (*error) (char *x))
4646
{
4747
int ret = -1;
@@ -180,11 +180,11 @@ static inline int unlz4(u8 *input, int in_len,
180180
return ret;
181181
}
182182

183-
STATIC int decompress_unlz4(unsigned char *buf, int in_len,
184-
int(*fill)(void*, unsigned int),
185-
int(*flush)(void*, unsigned int),
183+
STATIC int decompress_unlz4(unsigned char *buf, long in_len,
184+
long(*fill)(void*, unsigned long),
185+
long(*flush)(void*, unsigned long),
186186
unsigned char *output,
187-
int *posp,
187+
long *posp,
188188
void(*error)(char *x)
189189
)
190190
{

lib/decompress_unlzo.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ static inline int parse_header(u8 *input, int *skip, int in_len)
109109
return 1;
110110
}
111111

112-
int decompress_unlzo(u8 *input, int in_len,
113-
int (*fill) (void *, unsigned int),
114-
int (*flush) (void *, unsigned int),
115-
u8 *output, int *posp,
112+
int decompress_unlzo(u8 *input, long in_len,
113+
long (*fill) (void *, unsigned long),
114+
long (*flush) (void *, unsigned long),
115+
u8 *output, long *posp,
116116
void (*error) (char *x))
117117
{
118118
u8 r = 0;

lib/decompress_unxz.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ static void memzero(void *buf, size_t size)
235235
* both input and output buffers are available as a single chunk, i.e. when
236236
* fill() and flush() won't be used.
237237
*/
238-
STATIC int decompress_unxz(unsigned char *in, int in_size,
239-
int (*fill)(void *dest, unsigned int size),
240-
int (*flush)(void *src, unsigned int size),
241-
unsigned char *out, int *in_used,
238+
STATIC int decompress_unxz(unsigned char *in, long in_size,
239+
long (*fill)(void *dest, unsigned long size),
240+
long (*flush)(void *src, unsigned long size),
241+
unsigned char *out, long *in_used,
242242
void (*error)(char *x))
243243
{
244244
struct xz_buf b;

lib/uncompress.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
#include <libfile.h>
2828

2929
static void *uncompress_buf;
30-
static unsigned int uncompress_size;
30+
static unsigned long uncompress_size;
3131

3232
void uncompress_err_stdout(char *x)
3333
{
3434
printf("%s\n", x);
3535
}
3636

37-
static int (*uncompress_fill_fn)(void*, unsigned int);
37+
static long (*uncompress_fill_fn)(void*, unsigned long);
3838

39-
static int uncompress_fill(void *buf, unsigned int len)
39+
static long uncompress_fill(void *buf, unsigned long len)
4040
{
41-
int total = 0;
41+
long total = 0;
4242

4343
if (uncompress_size) {
4444
int now = min(len, uncompress_size);
@@ -60,19 +60,19 @@ static int uncompress_fill(void *buf, unsigned int len)
6060
return total;
6161
}
6262

63-
int uncompress(unsigned char *inbuf, int len,
64-
int(*fill)(void*, unsigned int),
65-
int(*flush)(void*, unsigned int),
63+
int uncompress(unsigned char *inbuf, long len,
64+
long(*fill)(void*, unsigned long),
65+
long(*flush)(void*, unsigned long),
6666
unsigned char *output,
67-
int *pos,
67+
long *pos,
6868
void(*error_fn)(char *x))
6969
{
7070
enum filetype ft;
71-
int (*compfn)(unsigned char *inbuf, int len,
72-
int(*fill)(void*, unsigned int),
73-
int(*flush)(void*, unsigned int),
71+
int (*compfn)(unsigned char *inbuf, long len,
72+
long(*fill)(void*, unsigned long),
73+
long(*flush)(void*, unsigned long),
7474
unsigned char *output,
75-
int *pos,
75+
long *pos,
7676
void(*error)(char *x));
7777
int ret;
7878
char *err;
@@ -141,12 +141,12 @@ int uncompress(unsigned char *inbuf, int len,
141141

142142
static int uncompress_infd, uncompress_outfd;
143143

144-
static int fill_fd(void *buf, unsigned int len)
144+
static long fill_fd(void *buf, unsigned long len)
145145
{
146146
return read_full(uncompress_infd, buf, len);
147147
}
148148

149-
static int flush_fd(void *buf, unsigned int len)
149+
static long flush_fd(void *buf, unsigned long len)
150150
{
151151
return write(uncompress_outfd, buf, len);
152152
}

0 commit comments

Comments
 (0)