360: Try to fix crash from I/O

This commit is contained in:
UnknownShadow200 2024-09-26 17:05:59 +10:00
parent 39ff1db4ff
commit 2cc17f04c1
2 changed files with 43 additions and 1 deletions

View file

@ -43,7 +43,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,--gc-sections -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lxenon -lm
LIBS := -lxenon -lm -lfat
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing

View file

@ -21,6 +21,7 @@
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <libfat/fat.h>
#include "_PlatformConsole.h"
const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */
@ -80,6 +81,7 @@ cc_uint64 Stopwatch_Measure(void) {
*#########################################################################################################################*/
static char root_buffer[NATIVE_STR_LEN];
static cc_string root_path = String_FromArray(root_buffer);
static bool fat_available;
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
char* str = dst->buffer;
@ -89,15 +91,21 @@ void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
}
cc_result Directory_Create(const cc_filepath* path) {
if (!fat_available) return ENOSYS;
return mkdir(path->buffer, 0) == -1 ? errno : 0;
}
int File_Exists(const cc_filepath* path) {
if (!fat_available) return 0;
struct stat sb;
return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {
if (!fat_available) return ENOSYS;
cc_string path; char pathBuffer[FILENAME_SIZE];
cc_filepath str;
struct dirent* entry;
@ -141,12 +149,17 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
}
cc_result File_Open(cc_file* file, const cc_filepath* path) {
if (!fat_available) return ReturnCode_FileNotFound;
return File_Do(file, path->buffer, O_RDONLY);
}
cc_result File_Create(cc_file* file, const cc_filepath* path) {
if (!fat_available) return ENOTSUP;
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC);
}
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
if (!fat_available) return ENOTSUP;
return File_Do(file, path->buffer, O_RDWR | O_CREAT);
}
@ -264,10 +277,39 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) {
/*########################################################################################################################*
*--------------------------------------------------------Platform---------------------------------------------------------*
*#########################################################################################################################*/
extern int bdev_enum(int handle, const char** name);
static void FindRootDirectory(void) {
const char* dev = NULL;
int handle = bdev_enum(-1, &dev);
if (handle < 0) { fat_available = false; return; }
root_path.length = 0;
String_Format1(&root_path, "%c:/ClassiCube", dev);
}
static void CreateRootDirectory(void) {
if (!fat_available) return;
root_buffer[root_path.length] = '\0';
int res = mkdir(root_buffer, 0);
int err = res == -1 ? errno : 0;
Platform_Log1("Created root directory: %i", &err);
}
void Platform_Init(void) {
xenos_init(VIDEO_MODE_AUTO);
console_init();
//network_init();
xenon_ata_init();
xenon_atapi_init();
fat_available = fatInitDefault();
Platform_ReadonlyFilesystem = !fat_available;
FindRootDirectory();
CreateRootDirectory();
}
void Platform_Free(void) {