xemu/ui/thirdparty/fatx/fatx.c
Fred Hallock 03f40b1d8e
ui: Support controller peripherals and XMU devices (#1315)
* Added XMU Settings to the Input Screen

* Added Peripherals to config

* Prevent overwriting existing XMUs

* Added blockdev.h to try to fix the MacOS build

* Fixed some issues that antangelo pointed out

* Moved the peripheralType and param vars into the loop

* Moved fatx.h and fatx.c to ui\thirdparty\fatx

* Added Validation for Peripheral Settings

* Fixed some nits that were pointed out

* don't pass NULL into xemu_settings_set_string

* Changes following Matt's recommendations

* Changes to XMU FilePicker

* XMU image auto-bind logic refactor

* renamed peripheralType to peripheral_type

* removed unnecessary calls to g_strdup_printf and g_free

* Cleaned up some comments, removed an unnecessary variable

* handle overwrite prompt in Windows

* Fixed some code format and style inconsistencies

* More formatting fixes

* Fixed a few memory leaks

* qemu_access: check for Read and Write access

* Run clang-format

* Remove unused xemu_new_xmu declaration

* Fix use after free in rebind code
2023-12-18 01:04:14 -05:00

52 lines
1.2 KiB
C

#include "fatx.h"
#include "qemu/bswap.h"
#define FATX_SIGNATURE 0x58544146
// This is from libfatx
#pragma pack(1)
struct fatx_superblock {
uint32_t signature;
uint32_t volume_id;
uint32_t sectors_per_cluster;
uint32_t root_cluster;
uint16_t unknown1;
uint8_t padding[4078];
};
#pragma pack()
bool create_fatx_image(const char *filename, unsigned int size)
{
unsigned int empty_fat = cpu_to_le32(0xfffffff8);
unsigned char zero = 0;
FILE *fp = qemu_fopen(filename, "wb");
if (fp != NULL) {
struct fatx_superblock superblock;
memset(&superblock, 0xff, sizeof(struct fatx_superblock));
superblock.signature = cpu_to_le32(FATX_SIGNATURE);
superblock.sectors_per_cluster = cpu_to_le32(4);
superblock.volume_id = (uint32_t)rand();
superblock.root_cluster = cpu_to_le32(1);
superblock.unknown1 = 0;
// Write the fatx superblock.
fwrite(&superblock, sizeof(superblock), 1, fp);
// Write the FAT
fwrite(&empty_fat, sizeof(empty_fat), 1, fp);
fseek(fp, size - sizeof(unsigned char), SEEK_SET);
fwrite(&zero, sizeof(unsigned char), 1, fp);
fflush(fp);
fclose(fp);
return true;
}
return false;
}