Skip to content

Commit

Permalink
[ADB] Update ADB API to use uint64_t and uint32_t instead of size_t. …
Browse files Browse the repository at this point in the history
…This reflects the underlying datasizes, while size_t was ABI dependent.
  • Loading branch information
mywave82 committed Dec 4, 2024
1 parent 4d334ac commit 20ad591
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 69 deletions.
4 changes: 2 additions & 2 deletions filesel/adbmeta-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ const struct adbMetaEntry_t test_many_insert[7] = {
for (i=0; i < 7; i++)
{
unsigned char *data = (unsigned char *)"b";
size_t datasize = 1;
uint32_t datasize = 1;
adbMetaGet (test_many_insert[i].filename,
test_many_insert[i].filesize,
test_many_insert[i].SIG,
Expand All @@ -758,7 +758,7 @@ const struct adbMetaEntry_t test_many_insert[7] = {

{
unsigned char *data = (unsigned char *)"a";
size_t datasize = 1;
uint32_t datasize = 1;
adbMetaGet (test_many_insert[0].filename,
14,
test_many_insert[0].SIG,
Expand Down
24 changes: 12 additions & 12 deletions filesel/adbmeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ static int adbMetaInit_ParseFd (osfile *f)
((uint_fast64_t)data[offset+6] << 8) |
((uint_fast64_t)data[offset+7]);
offset += 8;
datasize = ((uint_fast64_t)data[offset+0] << 24) |
((uint_fast64_t)data[offset+1] << 16) |
((uint_fast64_t)data[offset+2] << 8) |
((uint_fast64_t)data[offset+3]);
datasize = ((uint_fast32_t)data[offset+0] << 24) |
((uint_fast32_t)data[offset+1] << 16) |
((uint_fast32_t)data[offset+2] << 8) |
((uint_fast32_t)data[offset+3]);
offset += 4;

if (offset + datasize > fill)
Expand Down Expand Up @@ -400,7 +400,7 @@ void adbMetaClose (void)
}
}

static uint32_t adbMetaBinarySearchFilesize (const size_t filesize)
static uint32_t adbMetaBinarySearchFilesize (const uint32_t filesize)
{
uint_fast32_t searchbase = 0, searchlen = adbMetaCount;

Expand Down Expand Up @@ -459,14 +459,14 @@ static uint32_t adbMetaBinarySearchFilesize (const size_t filesize)
return searchbase;
}

int adbMetaAdd (const char *filename, const size_t filesize, const char *SIG, const unsigned char *data, const size_t datasize)
int adbMetaAdd (const char *filename, const uint64_t filesize, const char *SIG, const unsigned char *data, const uint32_t datasize)
{
uint_fast32_t searchindex = adbMetaBinarySearchFilesize (filesize);
int_fast32_t search;
struct adbMetaEntry_t *temp;

#ifdef ADBMETA_DEBUG
fprintf (stderr, "adbMetaAdd (\"%s\", %"PRId64", \"%s\", %p, %ld)\n", filename, filesize, SIG, data, datasize);
fprintf (stderr, "adbMetaAdd (\"%s\", %"PRIu64", \"%s\", 0x%p, %"PRIu32")\n", filename, filesize, SIG, data, datasize);
#endif

if (searchindex == adbMetaCount)
Expand Down Expand Up @@ -545,13 +545,13 @@ int adbMetaAdd (const char *filename, const size_t filesize, const char *SIG, co
return 0;
}

int adbMetaRemove (const char *filename, const size_t filesize, const char *SIG)
int adbMetaRemove (const char *filename, const uint64_t filesize, const char *SIG)
{
uint_fast32_t searchindex = adbMetaBinarySearchFilesize (filesize);
int_fast32_t search;

#ifdef ADBMETA_DEBUG
fprintf (stderr, "adbMetaRemove (\"%s\", %ld, \"%s\")\n", filename, filesize, SIG);
fprintf (stderr, "adbMetaRemove (\"%s\", %"PRIu64", \"%s\")\n", filename, filesize, SIG);
#endif

if (searchindex == adbMetaCount)
Expand Down Expand Up @@ -591,13 +591,13 @@ int adbMetaRemove (const char *filename, const size_t filesize, const char *SIG)
return 1; /* not found */
}

int adbMetaGet (const char *filename, const size_t filesize, const char *SIG, unsigned char **data, size_t *datasize)
int adbMetaGet (const char *filename, const uint64_t filesize, const char *SIG, unsigned char **data, uint32_t *datasize)
{
uint_fast32_t searchindex = adbMetaBinarySearchFilesize (filesize);
int_fast32_t search;

#ifdef ADBMETA_DEBUG
fprintf (stderr, "adbMetaGet (\"%s\", %"PRId64", \"%s\") ", filename, filesize, SIG);
fprintf (stderr, "adbMetaGet (\"%s\", %"PRIu64", \"%s\") ", filename, filesize, SIG);
#endif

*data = 0;
Expand Down Expand Up @@ -649,7 +649,7 @@ int adbMetaGet (const char *filename, const size_t filesize, const char *SIG, un
*datasize = adbMetaEntries[search]->datasize;

#ifdef ADBMETA_DEBUG
fprintf (stderr, " => %p %ld\n", *data, *datasize);
fprintf (stderr, " => %p %"PRIu32"\n", *data, *datasize);
#endif
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions filesel/adbmeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ int adbMetaInit (const struct configAPI_t *configAPI);
void adbMetaCommit (void);
void adbMetaClose (void);
// ZIP, GZ, BZ2, etc - who owns this meta-data
int adbMetaAdd (const char *filename, const size_t filesize, const char *SIG, const unsigned char *data, const size_t datasize); // Replaces too
int adbMetaRemove (const char *filename, const size_t filesize, const char *SIG);
int adbMetaAdd (const char *filename, const uint64_t filesize, const char *SIG, const unsigned char *data, const uint32_t datasize); // Replaces too
int adbMetaRemove (const char *filename, const uint64_t filesize, const char *SIG);

// when done, use free()
int adbMetaGet (const char *filename, const size_t filesize, const char *SIG, unsigned char **data, size_t *datasize);
int adbMetaGet (const char *filename, const uint64_t filesize, const char *SIG, unsigned char **data, uint32_t *datasize);

#endif
4 changes: 2 additions & 2 deletions filesel/filesystem-bzip2-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ void register_dirdecompressor (const struct ocpdirdecompressor_t *ofd)
{
}

int adbMetaAdd (const char *filename, const size_t filesize, const char *SIG, const unsigned char *data, const size_t datasize)
int adbMetaAdd (const char *filename, const uint64_t filesize, const char *SIG, const unsigned char *data, const uint32_t datasize)
{
return 0;
}

int adbMetaGet (const char *filename, const size_t filesize, const char *SIG, unsigned char **data, size_t *datasize)
int adbMetaGet (const char *filename, const uint64_t filesize, const char *SIG, unsigned char **data, uint32_t *datasize)
{
return -1;
}
Expand Down
29 changes: 23 additions & 6 deletions filesel/filesystem-bzip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ static int bzip2_ocpfilehandle_compressInit (struct bzip2_ocpfilehandle_t *s)
{
int retval;

DEBUG_PRINT ("bzip2_ocpfilehandle_compressInit (s->need_deinit=%d)\n", s->need_deinit);

if (s->need_deinit)
{
BZ2_bzDecompressEnd (&s->strm);
Expand Down Expand Up @@ -155,6 +157,8 @@ static void bzip2_ocpfilehandle_unref (struct ocpfilehandle_t *_s)
return;
}

DEBUG_PRINT("bzip2_ocpfilehandle_unref, last instance, s->need_deinit=%d\n", s->need_deinit);

if (s->need_deinit)
{
BZ2_bzDecompressEnd (&s->strm);
Expand Down Expand Up @@ -183,6 +187,8 @@ static int bzip2_ocpfilehandle_seek_set (struct ocpfilehandle_t *_s, int64_t pos

if (pos < 0) return -1;

DEBUG_PRINT ("bzip2_ocpfilehandle_seek_set pos=%"PRId64" oldpos=%"PRId64" realpos=%"PRId64" s->owner->filesize_pending=%d \n", pos, s->pos, s->realpos, s->owner->filesize_pending);

if (s->owner->filesize_pending)
{
if (pos > s->pos)
Expand All @@ -207,13 +213,17 @@ static uint64_t bzip2_ocpfilehandle_getpos (struct ocpfilehandle_t *_s)
{
struct bzip2_ocpfilehandle_t *s = (struct bzip2_ocpfilehandle_t *)_s;

DEBUG_PRINT ("bzip2_ocpfilehandle_getpos pos=%"PRId64"\n", s->pos);

return s->pos;
}

static int bzip2_ocpfilehandle_eof (struct ocpfilehandle_t *_s)
{
struct bzip2_ocpfilehandle_t *s = (struct bzip2_ocpfilehandle_t *)_s;

DEBUG_PRINT ("bzip2_ocpfilehandle_eof\n");

if (!s->owner->filesize_pending)
{
if (_s->filesize (_s) == FILESIZE_ERROR) /* force the size to be calculated */
Expand All @@ -229,6 +239,8 @@ static int bzip2_ocpfilehandle_error (struct ocpfilehandle_t *_s)
{
struct bzip2_ocpfilehandle_t *s = (struct bzip2_ocpfilehandle_t *)_s;

DEBUG_PRINT ("bzip2_ocpfilehandle_error\n");

return s->error;
}

Expand All @@ -238,6 +250,8 @@ static int bzip2_ocpfilehandle_read (struct ocpfilehandle_t *_s, void *dst, int
int retval = 0;
int recall = 0;

DEBUG_PRINT ("bzip2_ocpfilehandle_read len=%d pos=%"PRId64" realpos=%"PRId64"\n", len, s->pos, s->realpos);

/* do we need to reverse? */
if ((s->pos < s->realpos) || (!s->need_deinit))
{
Expand Down Expand Up @@ -411,7 +425,7 @@ static int bzip2_ocpfilehandle_read (struct ocpfilehandle_t *_s, void *dst, int

dirdbGetName_internalstr (s->compressedfilehandle->dirdb_ref, &filename);

DEBUG_PRINT ("[BZIP2 filehandle_read EOF] adbMetaAdd(%s, %"PRId64", BZIP2, [%02x %02x %02x %02x %02x %02x %02x %02x] (%"PRIu64" + %d => %"PRIu64")\n", filename, compressedfile_size, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], s->realpos, s->outputbuffer_fill, filesize);
DEBUG_PRINT ("[BZIP2 filehandle_read EOF] adbMetaAdd(%s, %"PRIu64", BZIP2, [%02x %02x %02x %02x %02x %02x %02x %02x] (%"PRIu64" + %d => %"PRIu64")\n", filename, compressedfile_size, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], s->realpos, s->outputbuffer_fill, filesize);
adbMetaAdd (filename, compressedfile_size, "BZIP2", buffer, 8);
}

Expand Down Expand Up @@ -520,7 +534,7 @@ static uint64_t bzip2_ocpfile_filesize (struct ocpfile_t *_s)
compressedfile_size = s->compressedfile->filesize (s->compressedfile);

uint8_t *metadata = 0;
size_t metadatasize = 0;
uint32_t metadatasize = 0;

if ((compressedfile_size < 12) || (compressedfile_size == FILESIZE_ERROR) || (compressedfile_size == FILESIZE_STREAM))
{
Expand All @@ -544,9 +558,11 @@ static uint64_t bzip2_ocpfile_filesize (struct ocpfile_t *_s)
((uint64_t)(metadata[0]));
free (metadata);

DEBUG_PRINT ("[BZIP2 ocpfile_filesize]: got metadatasize=0x%08lx %02x %02x %02x %02x %02x %02x %02x %02x => %"PRIu64"\n", metadatasize, metadata[0], metadata[1], metadata[2], metadata[3], metadata[4], metadata[5], metadata[6], metadata[7], s->uncompressed_filesize);
DEBUG_PRINT ("[BZIP2 ocpfile_filesize]: got metadatasize=0x%08"PRIu32" %02x %02x %02x %02x %02x %02x %02x %02x => %"PRIu64"\n", metadatasize, metadata[0], metadata[1], metadata[2], metadata[3], metadata[4], metadata[5], metadata[6], metadata[7], s->uncompressed_filesize);

return s->uncompressed_filesize;
} else {
DEBUG_PRINT ("[BZIP2 ocpfile_filesize]: got metadatasize=0x%08"PRIu32", unexpected size\n", metadatasize);
}
free (metadata); /* wrong size???... */
metadata = 0;
Expand Down Expand Up @@ -808,7 +824,7 @@ static struct ocpdir_t *bzip2_check_steal (struct ocpfile_t *s, const uint32_t d
if (s->filesize_ready (s))
{
unsigned char *metadata = 0;
size_t metadatasize = 0;
uint32_t metadatasize = 0;
const char *filename = 0;

dirdbGetName_internalstr (retval->child.compressedfile->dirdb_ref, &filename);
Expand All @@ -827,8 +843,9 @@ static struct ocpdir_t *bzip2_check_steal (struct ocpfile_t *s, const uint32_t d
((uint64_t)(metadata[1]) << 8) |
((uint64_t)(metadata[0]));

DEBUG_PRINT ("[BZIP2 bzip2_check_steal]: got metadatasize=0x%08lx %02x %02x %02x %02x %02x %02x %02x %02x => %"PRIu64"\n", metadatasize, metadata[0], metadata[1], metadata[2], metadata[3], metadata[4], metadata[5], metadata[6], metadata[7], retval->child.uncompressed_filesize);

DEBUG_PRINT ("[BZIP2 bzip2_check_steal]: got metadatasize=0x%08"PRIu32" %02x %02x %02x %02x %02x %02x %02x %02x => %"PRIu64"\n", metadatasize, metadata[0], metadata[1], metadata[2], metadata[3], metadata[4], metadata[5], metadata[6], metadata[7], retval->child.uncompressed_filesize);
} else {
DEBUG_PRINT ("[BZIP2 bzip2_check_steal]: got metadatasize=0x%08"PRIu32", an unexpected size\n", metadatasize);
}
free (metadata);
metadata = 0;
Expand Down
4 changes: 2 additions & 2 deletions filesel/filesystem-gzip-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ void register_dirdecompressor (const struct ocpdirdecompressor_t *ofd)
{
}

int adbMetaAdd (const char *filename, const size_t filesize, const char *SIG, const unsigned char *data, const size_t datasize)
int adbMetaAdd (const char *filename, const uint64_t filesize, const char *SIG, const unsigned char *data, const uint32_t datasize)
{
return 0;
}

int adbMetaGet (const char *filename, const size_t filesize, const char *SIG, unsigned char **data, size_t *datasize)
int adbMetaGet (const char *filename, const uint64_t filesize, const char *SIG, unsigned char **data, uint32_t *datasize)
{
return -1;
}
Expand Down
15 changes: 9 additions & 6 deletions filesel/filesystem-gzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static int gzip_ocpfilehandle_read (struct ocpfilehandle_t *_s, void *dst, int l

dirdbGetName_internalstr (s->compressedfilehandle->dirdb_ref, &filename);

DEBUG_PRINT ("[GZIP filehandle_read EOF] adbMetaAdd(%s, %"PRId64", GZIP, [%02x %02x %02x %02x %02x %02x %02x %02x] (%"PRIu64" + %d => %"PRIu64")\n", filename, compressedfile_size, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], s->realpos, s->outputbuffer_fill, filesize);
DEBUG_PRINT ("[GZIP filehandle_read EOF] adbMetaAdd(%s, %"PRIu64", GZIP, [%02x %02x %02x %02x %02x %02x %02x %02x] (%"PRIu64" + %d => %"PRIu64")\n", filename, compressedfile_size, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], s->realpos, s->outputbuffer_fill, filesize);
adbMetaAdd (filename, compressedfile_size, "GZIP", buffer, 8);
}

Expand Down Expand Up @@ -521,7 +521,7 @@ static uint64_t gzip_ocpfile_filesize (struct ocpfile_t *_s)
compressedfile_size = s->compressedfile->filesize (s->compressedfile);

uint8_t *metadata = 0;
size_t metadatasize = 0;
uint32_t metadatasize = 0;

if ((compressedfile_size < 12) || (compressedfile_size == FILESIZE_ERROR) || (compressedfile_size == FILESIZE_STREAM))
{
Expand All @@ -545,9 +545,11 @@ static uint64_t gzip_ocpfile_filesize (struct ocpfile_t *_s)
((uint64_t)(metadata[0]));
free (metadata);

DEBUG_PRINT ("[GZIP ocpfile_filesize]: got metadatasize=0x%08lx %02x %02x %02x %02x %02x %02x %02x %02x => %"PRIu64"\n", metadatasize, metadata[0], metadata[1], metadata[2], metadata[3], metadata[4], metadata[5], metadata[6], metadata[7], s->uncompressed_filesize);
DEBUG_PRINT ("[GZIP ocpfile_filesize]: got metadatasize=0x%08"PRIu32" %02x %02x %02x %02x %02x %02x %02x %02x => %"PRIu64"\n", metadatasize, metadata[0], metadata[1], metadata[2], metadata[3], metadata[4], metadata[5], metadata[6], metadata[7], s->uncompressed_filesize);

return s->uncompressed_filesize;
} else {
DEBUG_PRINT ("[GZIP ocpfile_filesize]: got metadatasize=0x%08"PRIu32", unexpected size\n", metadatasize);
}
free (metadata); /* wrong size???... */
metadata = 0;
Expand Down Expand Up @@ -865,7 +867,7 @@ static struct ocpdir_t *gzip_check_steal (struct ocpfile_t *s, const uint32_t di
if (s->filesize_ready (s))
{
unsigned char *metadata = 0;
size_t metadatasize = 0;
uint32_t metadatasize = 0;
const char *filename = 0;

dirdbGetName_internalstr (retval->child.compressedfile->dirdb_ref, &filename);
Expand All @@ -884,8 +886,9 @@ static struct ocpdir_t *gzip_check_steal (struct ocpfile_t *s, const uint32_t di
((uint64_t)(metadata[1]) << 8) |
((uint64_t)(metadata[0]));

DEBUG_PRINT ("[GZIP gzip_check_steal]: got metadatasize=0x%08lx %02x %02x %02x %02x %02x %02x %02x %02x => %"PRIu64"\n", metadatasize, metadata[0], metadata[1], metadata[2], metadata[3], metadata[4], metadata[5], metadata[6], metadata[7], retval->child.uncompressed_filesize);

DEBUG_PRINT ("[GZIP gzip_check_steal]: got metadatasize=0x%08"PRIu32" %02x %02x %02x %02x %02x %02x %02x %02x => %"PRIu64"\n", metadatasize, metadata[0], metadata[1], metadata[2], metadata[3], metadata[4], metadata[5], metadata[6], metadata[7], retval->child.uncompressed_filesize);
} else {
DEBUG_PRINT ("[GZIP gzip_check_steal]: got metadatasize=0x%08"PRIu32", unexpected size\n", metadatasize);
}
free (metadata);
metadata = 0;
Expand Down
14 changes: 7 additions & 7 deletions filesel/filesystem-pak.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static uint32_t pak_instance_add (struct pak_instance_t *self,
const uint32_t fileoffset);

/* in the blob, we will switch / into \0 temporary as we parse them */
static void pak_instance_decode_blob (struct pak_instance_t *self, uint8_t *blob, size_t blobsize)
static void pak_instance_decode_blob (struct pak_instance_t *self, uint8_t *blob, uint32_t blobsize)
{

uint8_t *eos;
Expand Down Expand Up @@ -218,7 +218,7 @@ static void pak_instance_decode_blob (struct pak_instance_t *self, uint8_t *blob
#endif
}

static void pak_instance_encode_blob (struct pak_instance_t *self, uint8_t **blob, size_t *blobfill)
static void pak_instance_encode_blob (struct pak_instance_t *self, uint8_t **blob, uint32_t *blobfill)
{
uint32_t counter;
uint32_t blobsize = 0;
Expand Down Expand Up @@ -607,7 +607,7 @@ struct ocpdir_t *pak_check (const struct ocpdirdecompressor_t *self, struct ocpf
{
const char *filename = 0;
uint8_t *metadata = 0;
size_t metadatasize = 0;
uint32_t metadatasize = 0;

dirdbGetName_internalstr (iter->archive_file->dirdb_ref, &filename);
if (!adbMetaGet (filename, iter->archive_file->filesize (iter->archive_file), "PAK", &metadata, &metadatasize))
Expand All @@ -632,7 +632,7 @@ struct ocpdir_t *pak_check (const struct ocpdirdecompressor_t *self, struct ocpf
if (iter->file_fill)
{
uint8_t *metadata = 0;
size_t metadatasize = 0;
uint32_t metadatasize = 0;
const char *filename = 0;

pak_instance_encode_blob (iter, &metadata, &metadatasize);
Expand Down Expand Up @@ -1177,10 +1177,10 @@ static void pak_translate_complete (struct pak_instance_t *self)
static void pak_translate (struct pak_instance_t *self, char *src, char **buffer, int *buffersize)
{
char *temp;
size_t srclen;
uint32_t srclen;

char *dst = *buffer;
size_t dstlen = *buffersize;
uint32_t dstlen = *buffersize;

DEBUG_PRINT ("pak_translate %s =>", src);

Expand Down Expand Up @@ -1278,7 +1278,7 @@ static void pak_set_byuser_string (struct ocpdir_t *_self, const char *byuser)
/* update adbMeta */
{
uint8_t *metadata = 0;
size_t metadatasize = 0;
uint32_t metadatasize = 0;
const char *filename = 0;

pak_instance_encode_blob (self->owner, &metadata, &metadatasize);
Expand Down
Loading

0 comments on commit 20ad591

Please sign in to comment.