mirror of
https://git.planet-casio.com/Lephenixnoir/gint.git
synced 2025-07-04 03:26:37 +02:00
fugue: manually handle world-switch
This commit is contained in:
parent
4442d27b62
commit
968588bac3
9 changed files with 72 additions and 19 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include <gint/bfile.h>
|
#include <gint/bfile.h>
|
||||||
|
#include <gint/gint.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
int BFile_Ext_Stat(uint16_t const *path, int *type, int *size)
|
int BFile_Ext_Stat(uint16_t const *path, int *type, int *size)
|
||||||
|
@ -7,6 +8,7 @@ int BFile_Ext_Stat(uint16_t const *path, int *type, int *size)
|
||||||
uint16_t found_file[256];
|
uint16_t found_file[256];
|
||||||
struct BFile_FileInfo fileinfo;
|
struct BFile_FileInfo fileinfo;
|
||||||
|
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
rc = BFile_FindFirst(path, &search_handle, found_file, &fileinfo);
|
rc = BFile_FindFirst(path, &search_handle, found_file, &fileinfo);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
if(type) *type = -1;
|
if(type) *type = -1;
|
||||||
|
@ -20,5 +22,6 @@ int BFile_Ext_Stat(uint16_t const *path, int *type, int *size)
|
||||||
}
|
}
|
||||||
|
|
||||||
BFile_FindClose(search_handle);
|
BFile_FindClose(search_handle);
|
||||||
|
gint_world_leave();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <gint/hardware.h>
|
#include <gint/hardware.h>
|
||||||
#include <gint/bfile.h>
|
#include <gint/bfile.h>
|
||||||
#include <gint/mmu.h>
|
#include <gint/mmu.h>
|
||||||
|
#include <gint/gint.h>
|
||||||
#include <gint/defs/util.h>
|
#include <gint/defs/util.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -11,6 +12,8 @@
|
||||||
|
|
||||||
ssize_t fugue_read(void *data0, void *buf, size_t size)
|
ssize_t fugue_read(void *data0, void *buf, size_t size)
|
||||||
{
|
{
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
|
|
||||||
fugue_fd_t *data = data0;
|
fugue_fd_t *data = data0;
|
||||||
int fugue_fd = data->fd;
|
int fugue_fd = data->fd;
|
||||||
|
|
||||||
|
@ -22,9 +25,12 @@ ssize_t fugue_read(void *data0, void *buf, size_t size)
|
||||||
int rc = BFile_Read(fugue_fd, buf, size, -1);
|
int rc = BFile_Read(fugue_fd, buf, size, -1);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
errno = bfile_error_to_errno(rc);
|
errno = bfile_error_to_errno(rc);
|
||||||
return -1;
|
size = -1;
|
||||||
}
|
} else {
|
||||||
data->pos += rc;
|
data->pos += rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
gint_world_leave();
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +68,7 @@ ssize_t fugue_write(void *data0, const void *buf, size_t size)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
while(written < size) {
|
while(written < size) {
|
||||||
size_t block_size = min(size - written, alloc_size);
|
size_t block_size = min(size - written, alloc_size);
|
||||||
memcpy(ram, buf + written, block_size);
|
memcpy(ram, buf + written, block_size);
|
||||||
|
@ -79,24 +86,31 @@ ssize_t fugue_write(void *data0, const void *buf, size_t size)
|
||||||
/* Partial write */
|
/* Partial write */
|
||||||
if(rc < (int)block_size) break;
|
if(rc < (int)block_size) break;
|
||||||
}
|
}
|
||||||
|
gint_world_leave();
|
||||||
|
|
||||||
free(ram);
|
free(ram);
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
/* Otherwise, we can write normally */
|
/* Otherwise, we can write normally */
|
||||||
else {
|
else {
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
int rc = BFile_Write(fugue_fd, buf, size);
|
int rc = BFile_Write(fugue_fd, buf, size);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
errno = bfile_error_to_errno(rc);
|
errno = bfile_error_to_errno(rc);
|
||||||
return -1;
|
rc = -1;
|
||||||
}
|
} else {
|
||||||
data->pos += rc;
|
data->pos += rc;
|
||||||
|
rc = 0;
|
||||||
|
}
|
||||||
|
gint_world_leave();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t fugue_lseek(void *data0, off_t offset, int whence)
|
off_t fugue_lseek(void *data0, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
|
|
||||||
fugue_fd_t *data = data0;
|
fugue_fd_t *data = data0;
|
||||||
int fugue_fd = data->fd;
|
int fugue_fd = data->fd;
|
||||||
|
|
||||||
|
@ -114,9 +128,12 @@ off_t fugue_lseek(void *data0, off_t offset, int whence)
|
||||||
int rc = BFile_Seek(fugue_fd, offset);
|
int rc = BFile_Seek(fugue_fd, offset);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
errno = bfile_error_to_errno(rc);
|
errno = bfile_error_to_errno(rc);
|
||||||
return -1;
|
offset = -1;
|
||||||
}
|
} else {
|
||||||
data->pos = offset;
|
data->pos = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
gint_world_leave();
|
||||||
|
|
||||||
/* rc is the amount of space left in the file (including pre-allocated
|
/* rc is the amount of space left in the file (including pre-allocated
|
||||||
space), so instead just return offset directly */
|
space), so instead just return offset directly */
|
||||||
|
@ -125,16 +142,21 @@ off_t fugue_lseek(void *data0, off_t offset, int whence)
|
||||||
|
|
||||||
int fugue_close(void *data0)
|
int fugue_close(void *data0)
|
||||||
{
|
{
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
|
|
||||||
fugue_fd_t *data = data0;
|
fugue_fd_t *data = data0;
|
||||||
int fugue_fd = data->fd;
|
int fugue_fd = data->fd;
|
||||||
|
|
||||||
int rc = BFile_Close(fugue_fd);
|
int rc = BFile_Close(fugue_fd);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
errno = bfile_error_to_errno(rc);
|
errno = bfile_error_to_errno(rc);
|
||||||
return -1;
|
rc = -1;
|
||||||
}
|
} else {
|
||||||
|
rc = 0;
|
||||||
|
}
|
||||||
|
gint_world_leave();
|
||||||
free(data);
|
free(data);
|
||||||
return 0;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fs_descriptor_type_t fugue_descriptor_type = {
|
const fs_descriptor_type_t fugue_descriptor_type = {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <gint/fs.h>
|
#include <gint/fs.h>
|
||||||
#include <gint/hardware.h>
|
#include <gint/hardware.h>
|
||||||
#include <gint/bfile.h>
|
#include <gint/bfile.h>
|
||||||
|
#include <gint/gint.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -96,6 +97,8 @@ void *fugue_dir_explore(char const *path)
|
||||||
/* We allocate by batches of 8 */
|
/* We allocate by batches of 8 */
|
||||||
int sd=-1, rc, allocated=0;
|
int sd=-1, rc, allocated=0;
|
||||||
|
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
|
|
||||||
dir_t *dp = malloc(sizeof *dp);
|
dir_t *dp = malloc(sizeof *dp);
|
||||||
if(!dp) goto alloc_failure;
|
if(!dp) goto alloc_failure;
|
||||||
|
|
||||||
|
@ -157,5 +160,6 @@ end:
|
||||||
free(fc_path);
|
free(fc_path);
|
||||||
if(sd >= 0)
|
if(sd >= 0)
|
||||||
BFile_FindClose(sd);
|
BFile_FindClose(sd);
|
||||||
|
gint_world_leave();
|
||||||
return dp;
|
return dp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <gint/hardware.h>
|
#include <gint/hardware.h>
|
||||||
#include <gint/bfile.h>
|
#include <gint/bfile.h>
|
||||||
|
#include <gint/gint.h>
|
||||||
#include <gint/fs.h>
|
#include <gint/fs.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -14,13 +15,17 @@ int fugue_mkdir(char const *path, GUNUSED mode_t mode)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
int rc = BFile_Create(fcpath, BFile_Folder, NULL);
|
int rc = BFile_Create(fcpath, BFile_Folder, NULL);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
errno = bfile_error_to_errno(rc);
|
errno = bfile_error_to_errno(rc);
|
||||||
free(fcpath);
|
free(fcpath);
|
||||||
return -1;
|
rc = -1;
|
||||||
}
|
} else {
|
||||||
|
rc = 0;
|
||||||
|
}
|
||||||
|
gint_world_leave();
|
||||||
|
|
||||||
free(fcpath);
|
free(fcpath);
|
||||||
return 0;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <gint/fs.h>
|
#include <gint/fs.h>
|
||||||
#include <gint/bfile.h>
|
#include <gint/bfile.h>
|
||||||
|
#include <gint/gint.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -32,6 +33,8 @@ int fugue_open(char const *path, int flags, GUNUSED mode_t mode)
|
||||||
/* Truncation requires the file to be removed/recreated */
|
/* Truncation requires the file to be removed/recreated */
|
||||||
bool trunc = (flags & O_TRUNC) && (flags & O_CREAT);
|
bool trunc = (flags & O_TRUNC) && (flags & O_CREAT);
|
||||||
|
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
|
|
||||||
/* Stat the entry. A special case is needed for the root, which doesn't
|
/* Stat the entry. A special case is needed for the root, which doesn't
|
||||||
respond well. fs_path_normalize_fc() normalizes the path so we just
|
respond well. fs_path_normalize_fc() normalizes the path so we just
|
||||||
have to check for the fixed string "\\fls0\". */
|
have to check for the fixed string "\\fls0\". */
|
||||||
|
@ -142,6 +145,7 @@ int fugue_open(char const *path, int flags, GUNUSED mode_t mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
gint_world_leave();
|
||||||
free(fcpath);
|
free(fcpath);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <gint/hardware.h>
|
#include <gint/hardware.h>
|
||||||
#include <gint/bfile.h>
|
#include <gint/bfile.h>
|
||||||
#include <gint/fs.h>
|
#include <gint/fs.h>
|
||||||
|
#include <gint/gint.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -24,12 +25,15 @@ int fugue_rename(char const *oldpath, char const *newpath)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
rc = BFile_Rename(fcpath_1, fcpath_2);
|
rc = BFile_Rename(fcpath_1, fcpath_2);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
errno = bfile_error_to_errno(rc);
|
errno = bfile_error_to_errno(rc);
|
||||||
rc = -1;
|
rc = -1;
|
||||||
}
|
} else {
|
||||||
else rc = 0;
|
rc = 0;
|
||||||
|
}
|
||||||
|
gint_world_leave();
|
||||||
|
|
||||||
end:
|
end:
|
||||||
free(fcpath_1);
|
free(fcpath_1);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <gint/hardware.h>
|
#include <gint/hardware.h>
|
||||||
#include <gint/bfile.h>
|
#include <gint/bfile.h>
|
||||||
#include <gint/fs.h>
|
#include <gint/fs.h>
|
||||||
|
#include <gint/gint.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -39,12 +40,15 @@ int fugue_rmdir(char const *path)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
int rc = BFile_Remove(fcpath);
|
int rc = BFile_Remove(fcpath);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
errno = bfile_error_to_errno(rc);
|
errno = bfile_error_to_errno(rc);
|
||||||
rc = -1;
|
rc = -1;
|
||||||
}
|
} else {
|
||||||
else rc = 0;
|
rc = 0;
|
||||||
|
}
|
||||||
|
gint_world_leave();
|
||||||
|
|
||||||
free(fcpath);
|
free(fcpath);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <gint/fs.h>
|
#include <gint/fs.h>
|
||||||
|
#include <gint/gint.h>
|
||||||
#include <gint/bfile.h>
|
#include <gint/bfile.h>
|
||||||
#include "fugue.h"
|
#include "fugue.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -17,7 +18,9 @@ int fugue_stat(char const * restrict path, struct stat * restrict statbuf)
|
||||||
}
|
}
|
||||||
|
|
||||||
int type, size, rc;
|
int type, size, rc;
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
rc = BFile_Ext_Stat(fcpath, &type, &size);
|
rc = BFile_Ext_Stat(fcpath, &type, &size);
|
||||||
|
gint_world_leave();
|
||||||
free(fcpath);
|
free(fcpath);
|
||||||
|
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <gint/hardware.h>
|
#include <gint/hardware.h>
|
||||||
#include <gint/bfile.h>
|
#include <gint/bfile.h>
|
||||||
#include <gint/fs.h>
|
#include <gint/fs.h>
|
||||||
|
#include <gint/gint.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -15,6 +16,8 @@ int fugue_unlink(char const *path)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint_world_enter(GINT_WORLD_OS);
|
||||||
|
|
||||||
int type, size, rc;
|
int type, size, rc;
|
||||||
rc = BFile_Ext_Stat(fcpath, &type, &size);
|
rc = BFile_Ext_Stat(fcpath, &type, &size);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
|
@ -36,6 +39,7 @@ int fugue_unlink(char const *path)
|
||||||
else rc = 0;
|
else rc = 0;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
gint_world_leave();
|
||||||
free(fcpath);
|
free(fcpath);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue