Now we can generate a fairly basic FS.

Added some test material
This commit is contained in:
Godzil
2022-05-26 12:02:47 +01:00
parent d9b7996c8e
commit 8fd7ab33fc
11 changed files with 296 additions and 40 deletions

View File

@@ -5,3 +5,61 @@
* Copyright (c) 2008-2022 986-Studio. All rights reserved.
*
******************************************************************************/
#ifdef _WIN32
#include <stdio.h>
#include <stdlib.h>
#else
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#endif
#define __miniffs_internal
#include <miniffs.h>
size_t host_map_file(char *filename, char **dest)
{
char *ret_ptr;
size_t fileSize;
#ifdef _WIN32
/* As windows do not provide an easy to use mmap equivalent, let's use the fallback
* of opening the file, allocating memory and read the file in the said memory
*/
FILE *fp;
fp = fopen(filename, "rb");
fseek(fp, 0, SEEK_END);
fileSize = ftell(fp);
fseek(fp, 0, SEEK_SET);
ret_ptr = (char *)calloc(1, fileSize);
fread(ret_ptr, 1, fileSize, fp);
fclose(fp);
#else
int fd;
struct stat FileStat;
fd = open(filename, O_RDWR);
fstat(fd, &FileStat);
ret_ptr = (char *)mmap(NULL, FileStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
close(fd);
fileSize = FileStat.st_size
if (ret_ptr == MAP_FAILED)
{
ret_ptr = NULL;
}
#endif
*dest = ret_ptr;
return fileSize;
}
void host_unmap_file(char **dest, size_t length)
{
#ifdef _WIN32
/* As for windows we don't mmap, let's just free! */
free(*dest);
#else
munmap(*dest, length);
#endif
*dest = NULL;
}

View File

@@ -5,3 +5,6 @@
* Copyright (c) 2008-2022 986-Studio. All rights reserved.
*
******************************************************************************/
#define __miniffs_internal
#include <miniffs.h>