tio fixes
This commit is contained in:
parent
54eeb97b24
commit
9b3cc5391b
@ -38,6 +38,7 @@ typedef struct
|
||||
} IFile;
|
||||
|
||||
Result IFile_Open(IFile *file, FS_ArchiveID archiveId, FS_Path archivePath, FS_Path filePath, u32 flags);
|
||||
Result IFile_OpenFromArchive(IFile *file, FS_Archive archive, FS_Path filePath, u32 flags);
|
||||
Result IFile_Close(IFile *file);
|
||||
Result IFile_GetSize(IFile *file, u64 *size);
|
||||
Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len);
|
||||
|
@ -349,8 +349,8 @@ int GDB_SendStreamData(GDBContext *ctx, const char *streamData, u32 offset, u32
|
||||
|
||||
int GDB_SendDebugString(GDBContext *ctx, const char *fmt, ...) // unsecure
|
||||
{
|
||||
if(ctx->state == GDB_STATE_DETACHING || !(ctx->flags & GDB_FLAG_PROCESS_CONTINUING))
|
||||
return 0;
|
||||
/*if(ctx->state == GDB_STATE_DETACHING || !(ctx->flags & GDB_FLAG_PROCESS_CONTINUING))
|
||||
return 0;*/
|
||||
|
||||
char formatted[(GDB_BUF_LEN - 1) / 2 + 1];
|
||||
ctx->buffer[0] = '$';
|
||||
|
@ -181,12 +181,19 @@ static int GDB_TioRegisterFile(GDBContext *ctx, Handle h, int gdbOpenFlags)
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int GDB_MakeUtf16Path(FS_Path *outPath, const char *path)
|
||||
static int GDB_MakeUtf16Path(FS_Path *outPath, const char *pathData)
|
||||
{
|
||||
size_t pathDataLen = strlen(pathData);
|
||||
if (pathDataLen % 2 == 1) return GDBHIO_EINVAL;
|
||||
|
||||
char path[PATH_MAX + 1];
|
||||
u32 count = GDB_DecodeHex(path, pathData, pathDataLen / 2);
|
||||
path[count] = 0;
|
||||
|
||||
u16 *p16 = (u16 *)outPath->data;
|
||||
outPath->type = PATH_UTF16;
|
||||
|
||||
ssize_t units = utf8_to_utf16(p16, (const u8 *) path, PATH_MAX);
|
||||
ssize_t units = utf8_to_utf16(p16, (const u8 *) path, count);
|
||||
if (units < 0) return GDBHIO_EINVAL;
|
||||
else if (units >= PATH_MAX) return GDBHIO_ENAMETOOLONG;
|
||||
|
||||
@ -200,12 +207,22 @@ static inline int GDB_TioReplyErrno(GDBContext *ctx, int err)
|
||||
return GDB_SendFormattedPacket(ctx, "F-1,%lx", (u32)err);
|
||||
}
|
||||
|
||||
GDB_DECLARE_TIO_HANDLER(Open)
|
||||
static inline FS_ArchiveID GDB_TioGetArchiveId(void)
|
||||
{
|
||||
/*
|
||||
s64 out = 1;
|
||||
svcGetSystemInfo(&out, 0x10000, 0x203);
|
||||
bool isSdMode = (bool)out;
|
||||
FS_ArchiveID archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
|
||||
*/
|
||||
|
||||
// Actually, only support SD card for security reasons.
|
||||
return ARCHIVE_SDMC;
|
||||
}
|
||||
|
||||
GDB_DECLARE_TIO_HANDLER(Open)
|
||||
{
|
||||
FS_ArchiveID archiveId = GDB_TioGetArchiveId();
|
||||
u16 fsNameBuf[PATH_MAX + 1];
|
||||
FS_Path fsPath;
|
||||
fsPath.data = fsNameBuf;
|
||||
@ -215,7 +232,7 @@ GDB_DECLARE_TIO_HANDLER(Open)
|
||||
return GDB_ReplyErrno(ctx, EILSEQ);
|
||||
|
||||
*comma = 0;
|
||||
char *fileName = ctx->commandData;
|
||||
char *fileNameData = ctx->commandData;
|
||||
|
||||
u32 args[2] = {0};
|
||||
if (GDB_ParseHexIntegerList(args, comma + 1, 2, 0) == NULL)
|
||||
@ -227,7 +244,7 @@ GDB_DECLARE_TIO_HANDLER(Open)
|
||||
if (ctx->numOpenTioFiles >= MAX_TIO_OPEN_FILE)
|
||||
return GDB_TioReplyErrno(ctx, GDBHIO_EMFILE);
|
||||
|
||||
int err = GDB_MakeUtf16Path(&fsPath, fileName);
|
||||
int err = GDB_MakeUtf16Path(&fsPath, fileNameData);
|
||||
if (err != 0)
|
||||
return GDB_TioReplyErrno(ctx, err);
|
||||
|
||||
@ -254,17 +271,26 @@ GDB_DECLARE_TIO_HANDLER(Open)
|
||||
if (err != 0)
|
||||
return GDB_TioReplyErrno(ctx, err);
|
||||
|
||||
if ((flags & O_CREAT) && (flags & O_EXCL))
|
||||
{
|
||||
err = GDB_TioConvertResult(FSUSER_CreateFile(archiveId, fsPath, 0, 0));
|
||||
if (err != 0)
|
||||
return GDB_TioReplyErrno(ctx, err);
|
||||
}
|
||||
|
||||
err = GDB_TioConvertResult(IFile_Open(&f, archiveId, fsPath, fsMakePath(PATH_EMPTY, ""), fsFlags));
|
||||
FS_Archive ar;
|
||||
err = GDB_TioConvertResult(FSUSER_OpenArchive(&ar, archiveId, fsMakePath(PATH_EMPTY, "")));
|
||||
if (err != 0)
|
||||
return GDB_TioReplyErrno(ctx, err);
|
||||
|
||||
if ((flags & GDBHIO_O_CREAT) && (flags & GDBHIO_O_EXCL))
|
||||
{
|
||||
err = GDB_TioConvertResult(FSUSER_CreateFile(ar, fsPath, 0, 0));
|
||||
if (err != 0)
|
||||
{
|
||||
FSUSER_CloseArchive(ar);
|
||||
return GDB_TioReplyErrno(ctx, err);
|
||||
}
|
||||
}
|
||||
|
||||
err = GDB_TioConvertResult(IFile_OpenFromArchive(&f, ar, fsPath, fsFlags));
|
||||
if (err != 0)
|
||||
__builtin_trap();//return GDB_TioReplyErrno(ctx, err);
|
||||
FSUSER_CloseArchive(ar);
|
||||
|
||||
if((flags & GDBHIO_O_ACCMODE) != GDBHIO_O_RDONLY && (flags & GDBHIO_O_TRUNC))
|
||||
{
|
||||
f.size = 0;
|
||||
@ -365,19 +391,17 @@ GDB_DECLARE_TIO_HANDLER(Write)
|
||||
|
||||
GDB_DECLARE_TIO_HANDLER(Stat)
|
||||
{
|
||||
char *fileName = ctx->commandData;
|
||||
if (*fileName == 0)
|
||||
char *fileNameData = ctx->commandData;
|
||||
if (*fileNameData == 0)
|
||||
return GDB_ReplyErrno(ctx, EILSEQ);
|
||||
|
||||
s64 out = 1;
|
||||
svcGetSystemInfo(&out, 0x10000, 0x203);
|
||||
bool isSdMode = (bool)out;
|
||||
FS_ArchiveID archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
|
||||
FS_ArchiveID archiveId = GDB_TioGetArchiveId();
|
||||
|
||||
u16 fsNameBuf[PATH_MAX + 1];
|
||||
FS_Path fsPath;
|
||||
fsPath.data = fsNameBuf;
|
||||
|
||||
int err = GDB_MakeUtf16Path(&fsPath, fileName);
|
||||
int err = GDB_MakeUtf16Path(&fsPath, fileNameData);
|
||||
if (err != 0)
|
||||
return GDB_TioReplyErrno(ctx, err);
|
||||
|
||||
@ -430,23 +454,27 @@ GDB_DECLARE_TIO_HANDLER(Stat)
|
||||
|
||||
GDB_DECLARE_TIO_HANDLER(Unlink)
|
||||
{
|
||||
char *fileName = ctx->commandData;
|
||||
if (*fileName == 0)
|
||||
char *fileNameData = ctx->commandData;
|
||||
if (*fileNameData == 0)
|
||||
return GDB_ReplyErrno(ctx, EILSEQ);
|
||||
|
||||
s64 out = 1;
|
||||
svcGetSystemInfo(&out, 0x10000, 0x203);
|
||||
bool isSdMode = (bool)out;
|
||||
FS_ArchiveID archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
|
||||
FS_ArchiveID archiveId = GDB_TioGetArchiveId();
|
||||
|
||||
u16 fsNameBuf[PATH_MAX + 1];
|
||||
FS_Path fsPath;
|
||||
fsPath.data = fsNameBuf;
|
||||
|
||||
int err = GDB_MakeUtf16Path(&fsPath, fileName);
|
||||
int err = GDB_MakeUtf16Path(&fsPath, fileNameData);
|
||||
if (err != 0)
|
||||
return GDB_TioReplyErrno(ctx, err);
|
||||
|
||||
err = GDB_TioConvertResult(FSUSER_DeleteFile(archiveId, fsPath));
|
||||
FS_Archive ar;
|
||||
err = GDB_TioConvertResult(FSUSER_OpenArchive(&ar, archiveId, fsMakePath(PATH_EMPTY, "")));
|
||||
if (err != 0)
|
||||
return GDB_TioReplyErrno(ctx, err);
|
||||
|
||||
err = GDB_TioConvertResult(FSUSER_DeleteFile(ar, fsPath));
|
||||
FSUSER_CloseArchive(ar);
|
||||
if (err != 0)
|
||||
return GDB_TioReplyErrno(ctx, err);
|
||||
|
||||
@ -456,8 +484,8 @@ GDB_DECLARE_TIO_HANDLER(Unlink)
|
||||
GDB_DECLARE_TIO_HANDLER(Readlink)
|
||||
{
|
||||
// Not really supported
|
||||
char *fileName = ctx->commandData;
|
||||
if (*fileName == 0)
|
||||
char *fileNameData = ctx->commandData;
|
||||
if (*fileNameData == 0)
|
||||
return GDB_ReplyErrno(ctx, EILSEQ);
|
||||
|
||||
return GDB_SendPacket(ctx, "F0;", 3);
|
||||
|
@ -37,6 +37,16 @@ Result IFile_Open(IFile *file, FS_ArchiveID archiveId, FS_Path archivePath, FS_P
|
||||
return res;
|
||||
}
|
||||
|
||||
Result IFile_OpenFromArchive(IFile *file, FS_Archive archive, FS_Path filePath, u32 flags)
|
||||
{
|
||||
Result res;
|
||||
|
||||
res = FSUSER_OpenFile(&file->handle, archive, filePath, flags, 0);
|
||||
file->pos = 0;
|
||||
file->size = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
Result IFile_Close(IFile *file)
|
||||
{
|
||||
return FSFILE_Close(file->handle);
|
||||
|
Reference in New Issue
Block a user