]> git.zerfleddert.de Git - rsbs2/blobdiff - src/filesystem.c
firmware: update for 64bit platforms
[rsbs2] / src / filesystem.c
index ef26de4fb3c30d5fde0c8efab5cc1eca23333f35..da3cf76b30ff8a7cdf45345443a62b072e9472b7 100644 (file)
@@ -4,6 +4,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <strings.h>
 #include <string.h>
 #include <unistd.h>
 #include "rsb-lz.h"
 #include "filesystem.h"
 
-struct file_entry* get_next_file(unsigned char *fw, int len)
+struct file_entry* get_next_file(uint8_t *fw, int32_t len)
 {
-       static unsigned char *pos;
-       static unsigned char *start;
-       static unsigned char *end;
+       static uint8_t *pos;
+       static uint8_t *start;
+       static uint8_t *end;
        static struct file_entry fent;
-       int name_length;
+       int32_t name_length;
 
        if (fw != NULL && len != 0) {
                pos = fw + 0x28;
 
 #if 0
-               printf("Start of filesystem: 0x%08x\n", *((unsigned int*)pos));
+               printf("Start of filesystem: 0x%08x\n", *((uint32_t*)pos));
 #endif
                start = fw;
-               pos = fw + *((unsigned int*)pos);
+               pos = fw + *((uint32_t*)pos);
                end = fw + len;
        }
 
@@ -36,8 +37,8 @@ struct file_entry* get_next_file(unsigned char *fw, int len)
 
        if (fent.unknown == 0x00) {
                /* EOF */
-               int fill = (4 - ((pos - start) % 4)) % 4;
-               int i;
+               int32_t fill = (4 - ((pos - start) % 4)) % 4;
+               int32_t i;
 
                for (i = 0; i < fill; i++) {
                        if (*pos != 0xff) {
@@ -56,10 +57,10 @@ struct file_entry* get_next_file(unsigned char *fw, int len)
        }
 
 
-       name_length = *((unsigned int*)pos);
+       name_length = *((uint32_t*)pos);
        pos += 4;
 
-       fent.length = *((unsigned int*)pos);
+       fent.length = *((uint32_t*)pos);
        pos += 4;
 
        if ((fent.length > (end - pos)) ||
@@ -79,7 +80,7 @@ struct file_entry* get_next_file(unsigned char *fw, int len)
        return &fent;
 }
 
-void extract_files(unsigned char *fw, int len)
+void extract_files(uint8_t *fw, int32_t len)
 {
        struct file_entry *fent;
 
@@ -91,10 +92,10 @@ void extract_files(unsigned char *fw, int len)
 
                if (fent->length > 0) {
                        write_file(extracted_file(fent->name), fent->start, fent->length);
-                       if (*((unsigned int*)fent->start) == LZ_MAGIC) {
+                       if (*((uint32_t*)fent->start) == LZ_MAGIC) {
                                char *lzname;
-                               unsigned char *outbuf;
-                               unsigned int outlen;
+                               uint8_t *outbuf;
+                               uint32_t outlen;
 
                                if ((lzname = strdup(fent->name)) == NULL) {
                                        perror("strdup");
@@ -115,18 +116,18 @@ void extract_files(unsigned char *fw, int len)
                                free(outbuf);
                                free(lzname);
                        } else if (!strcmp(fent->name, "firmware")) {
-                               unsigned char *lzpos;
+                               uint8_t *lzpos;
                                char lzname[128];
 
                                bzero(lzname, sizeof(lzname));
                                strcpy(lzname, "firmware.");
 
-                               lzpos = fent->start + *((unsigned int*)(fent->start + 0x20));
+                               lzpos = fent->start + *((uint32_t*)(fent->start + 0x20));
                                memcpy(lzname + strlen(lzname), lzpos - 4, 4);
                                lzpos += 4;
-                               if (*((unsigned int*)(lzpos)) == LZ_MAGIC) {
-                                       unsigned char *outbuf;
-                                       unsigned int outlen;
+                               if (*((uint32_t*)(lzpos)) == LZ_MAGIC) {
+                                       uint8_t *outbuf;
+                                       uint32_t outlen;
 
                                        printf("%s: compressed firmware part found", lzname);
                                        outbuf = extract_lz_file(lzpos, &outlen, 1);
@@ -143,13 +144,13 @@ void extract_files(unsigned char *fw, int len)
        }
 }
 
-void replace_add_file(unsigned char *fw, int len, char *fwname, char *lname)
+void replace_add_file(uint8_t *fw, int32_t len, char *fwname, char *lname)
 {
        fprintf(stderr, "%s: Implement me!\n", __func__);
        exit(1);
 }
 
-void list_files(unsigned char *fw, int len)
+void list_files(uint8_t *fw, int32_t len)
 {
        struct file_entry *fent;
 
@@ -185,12 +186,12 @@ void mkdir_p(char *dir)
        free(parent);
 }
 
-void write_file(char *fname, unsigned char *buf, int len)
+void write_file(char *fname, uint8_t *buf, int32_t len)
 {
        char *filename_c, *dirn;
-       int fd;
-       int remaining;
-       int ret;
+       int32_t fd;
+       int32_t remaining;
+       int32_t ret;
 
        if ((filename_c = strdup(fname)) == NULL) {
                perror("strdup");
Impressum, Datenschutz