fs.o 100%

This commit is contained in:
Joshua Andrew 2023-07-07 02:09:57 -04:00
parent 0fa753fa4c
commit c6da376897
12 changed files with 975 additions and 65 deletions

View File

@ -1,29 +1,29 @@
Symbol Name, Object File, Library Archive, Matching
ISFS_OpenLib,fs.o,fs.a,true
_isfsFuncCb,fs.o,fs.a,true
ISFS_CreateDir,fs.o,fs.a,false
ISFS_CreateDirAsync,fs.o,fs.a,false
ISFS_ReadDir,fs.o,fs.a,false
ISFS_ReadDirAsync,fs.o,fs.a,false
ISFS_GetAttr,fs.o,fs.a,false
ISFS_GetAttrAsync,fs.o,fs.a,false
ISFS_Delete,fs.o,fs.a,false
ISFS_DeleteAsync,fs.o,fs.a,false
ISFS_Rename,fs.o,fs.a,false
ISFS_RenameAsync,fs.o,fs.a,false
ISFS_GetUsage,fs.o,fs.a,false
ISFS_CreateFile,fs.o,fs.a,false
ISFS_CreateFileAsync,fs.o,fs.a,false
ISFS_Open,fs.o,fs.a,false
ISFS_OpenAsync,fs.o,fs.a,false
ISFS_GetFileStats,fs.o,fs.a,false
ISFS_GetFileStatsAsync,fs.o,fs.a,false
ISFS_Seek,fs.o,fs.a,false
ISFS_SeekAsync,fs.o,fs.a,false
ISFS_CreateDir,fs.o,fs.a,true
ISFS_CreateDirAsync,fs.o,fs.a,true
ISFS_ReadDir,fs.o,fs.a,true
ISFS_ReadDirAsync,fs.o,fs.a,true
ISFS_GetAttr,fs.o,fs.a,true
ISFS_GetAttrAsync,fs.o,fs.a,true
ISFS_Delete,fs.o,fs.a,true
ISFS_DeleteAsync,fs.o,fs.a,true
ISFS_Rename,fs.o,fs.a,true
ISFS_RenameAsync,fs.o,fs.a,true
ISFS_GetUsage,fs.o,fs.a,true
ISFS_CreateFile,fs.o,fs.a,true
ISFS_CreateFileAsync,fs.o,fs.a,true
ISFS_Open,fs.o,fs.a,true
ISFS_OpenAsync,fs.o,fs.a,true
ISFS_GetFileStats,fs.o,fs.a,true
ISFS_GetFileStatsAsync,fs.o,fs.a,true
ISFS_Seek,fs.o,fs.a,true
ISFS_SeekAsync,fs.o,fs.a,true
ISFS_Read,fs.o,fs.a,true
ISFS_ReadAsync,fs.o,fs.a,false
ISFS_Write,fs.o,fs.a,false
ISFS_WriteAsync,fs.o,fs.a,false
ISFS_Close,fs.o,fs.a,false
ISFS_CloseAsync,fs.o,fs.a,false
ISFS_ShutdownAsync,fs.o,fs.a,false
ISFS_ReadAsync,fs.o,fs.a,true
ISFS_Write,fs.o,fs.a,true
ISFS_WriteAsync,fs.o,fs.a,true
ISFS_Close,fs.o,fs.a,true
ISFS_CloseAsync,fs.o,fs.a,true
ISFS_ShutdownAsync,fs.o,fs.a,true

1 Symbol Name Object File Library Archive Matching
2 ISFS_OpenLib fs.o fs.a true
3 _isfsFuncCb fs.o fs.a true
4 ISFS_CreateDir fs.o fs.a false true
5 ISFS_CreateDirAsync fs.o fs.a false true
6 ISFS_ReadDir fs.o fs.a false true
7 ISFS_ReadDirAsync fs.o fs.a false true
8 ISFS_GetAttr fs.o fs.a false true
9 ISFS_GetAttrAsync fs.o fs.a false true
10 ISFS_Delete fs.o fs.a false true
11 ISFS_DeleteAsync fs.o fs.a false true
12 ISFS_Rename fs.o fs.a false true
13 ISFS_RenameAsync fs.o fs.a false true
14 ISFS_GetUsage fs.o fs.a false true
15 ISFS_CreateFile fs.o fs.a false true
16 ISFS_CreateFileAsync fs.o fs.a false true
17 ISFS_Open fs.o fs.a false true
18 ISFS_OpenAsync fs.o fs.a false true
19 ISFS_GetFileStats fs.o fs.a false true
20 ISFS_GetFileStatsAsync fs.o fs.a false true
21 ISFS_Seek fs.o fs.a false true
22 ISFS_SeekAsync fs.o fs.a false true
23 ISFS_Read fs.o fs.a true
24 ISFS_ReadAsync fs.o fs.a false true
25 ISFS_Write fs.o fs.a false true
26 ISFS_WriteAsync fs.o fs.a false true
27 ISFS_Close fs.o fs.a false true
28 ISFS_CloseAsync fs.o fs.a false true
29 ISFS_ShutdownAsync fs.o fs.a false true

View File

@ -40,12 +40,12 @@ NANDCloseAsync,NANDOpenClose.o,nand.a,false
NANDPrivateSafeOpenAsync,NANDOpenClose.o,nand.a,false
nandSafeOpenAsync,NANDOpenClose.o,nand.a,false
nandSafeOpenCallback,NANDOpenClose.o,nand.a,false
nandReadOpenCallback,NANDOpenClose.o,nand.a,false
NANDSafeCloseAsync,NANDOpenClose.o,nand.a,false
nandSafeCloseAsync,NANDOpenClose.o,nand.a,false
nandReadOpenCallback,NANDOpenClose.o,nand.a,true
NANDSafeCloseAsync,NANDOpenClose.o,nand.a,true
nandSafeCloseAsync,NANDOpenClose.o,nand.a,true
nandSafeCloseCallback,NANDOpenClose.o,nand.a,false
nandReadCloseCallback,NANDOpenClose.o,nand.a,false
nandCloseCallback,NANDOpenClose.o,nand.a,false
nandReadCloseCallback,NANDOpenClose.o,nand.a,true
nandCloseCallback,NANDOpenClose.o,nand.a,true
nandRemoveTailToken,NANDCore.o,nand.a,true
nandGetHeadToken,NANDCore.o,nand.a,true
nandGetRelativeName,NANDCore.o,nand.a,true

1 Symbol Name Object File Library Archive Matching
40 NANDPrivateSafeOpenAsync NANDOpenClose.o nand.a false
41 nandSafeOpenAsync NANDOpenClose.o nand.a false
42 nandSafeOpenCallback NANDOpenClose.o nand.a false
43 nandReadOpenCallback NANDOpenClose.o nand.a false true
44 NANDSafeCloseAsync NANDOpenClose.o nand.a false true
45 nandSafeCloseAsync NANDOpenClose.o nand.a false true
46 nandSafeCloseCallback NANDOpenClose.o nand.a false
47 nandReadCloseCallback NANDOpenClose.o nand.a false true
48 nandCloseCallback NANDOpenClose.o nand.a false true
49 nandRemoveTailToken NANDCore.o nand.a true
50 nandGetHeadToken NANDCore.o nand.a true
51 nandGetRelativeName NANDCore.o nand.a true

View File

@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"label": "SDK",
"message": "9.052%",
"message": "9.89%",
"color": "blue"
}

View File

@ -13,13 +13,13 @@
| [esp](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/esp.md) | 100.0% |
| [euart](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/euart.md) | 100.0% |
| [exi](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/exi.md) | 100.0% |
| [fs](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/fs.md) | 12.208504801097392% |
| [fs](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/fs.md) | 100.0% |
| [gd](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/gd.md) | 0.0% |
| [gx](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/gx.md) | 3.3725976441413517% |
| [ipc](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/ipc.md) | 100.0% |
| [mem](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/mem.md) | 9.977827050997783% |
| [mtx](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/mtx.md) | 0.0% |
| [nand](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/nand.md) | 26.01744186046512% |
| [nand](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/nand.md) | 30.348837209302324% |
| [net](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/net.md) | 0.0% |
| [nwc24](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/nwc24.md) | 0.0% |
| [os](https://github.com/shibbo/Petari/tree/master/libs/RVL_SDK/docs/lib/os.md) | 46.44500209117524% |

View File

@ -8,7 +8,7 @@
| Object | Percentage (of Bytes) | Functions Done / Total Functions | Percentage (Functions) | Status
| ------------- | ------------- | ------------- | ------------- | -------------
| fs.o | 12.208504801097392% | 3 / 28 | 10.714285714285714% | :eight_pointed_black_star:
| fs.o | 100.0% | 28 / 28 | 100.0% | :white_check_mark:
# fs.o
@ -16,31 +16,31 @@
| ------------- | ------------- |
| ISFS_OpenLib | :white_check_mark: |
| _isfsFuncCb | :white_check_mark: |
| ISFS_CreateDir | :x: |
| ISFS_CreateDirAsync | :x: |
| ISFS_ReadDir | :x: |
| ISFS_ReadDirAsync | :x: |
| ISFS_GetAttr | :x: |
| ISFS_GetAttrAsync | :x: |
| ISFS_Delete | :x: |
| ISFS_DeleteAsync | :x: |
| ISFS_Rename | :x: |
| ISFS_RenameAsync | :x: |
| ISFS_GetUsage | :x: |
| ISFS_CreateFile | :x: |
| ISFS_CreateFileAsync | :x: |
| ISFS_Open | :x: |
| ISFS_OpenAsync | :x: |
| ISFS_GetFileStats | :x: |
| ISFS_GetFileStatsAsync | :x: |
| ISFS_Seek | :x: |
| ISFS_SeekAsync | :x: |
| ISFS_CreateDir | :white_check_mark: |
| ISFS_CreateDirAsync | :white_check_mark: |
| ISFS_ReadDir | :white_check_mark: |
| ISFS_ReadDirAsync | :white_check_mark: |
| ISFS_GetAttr | :white_check_mark: |
| ISFS_GetAttrAsync | :white_check_mark: |
| ISFS_Delete | :white_check_mark: |
| ISFS_DeleteAsync | :white_check_mark: |
| ISFS_Rename | :white_check_mark: |
| ISFS_RenameAsync | :white_check_mark: |
| ISFS_GetUsage | :white_check_mark: |
| ISFS_CreateFile | :white_check_mark: |
| ISFS_CreateFileAsync | :white_check_mark: |
| ISFS_Open | :white_check_mark: |
| ISFS_OpenAsync | :white_check_mark: |
| ISFS_GetFileStats | :white_check_mark: |
| ISFS_GetFileStatsAsync | :white_check_mark: |
| ISFS_Seek | :white_check_mark: |
| ISFS_SeekAsync | :white_check_mark: |
| ISFS_Read | :white_check_mark: |
| ISFS_ReadAsync | :x: |
| ISFS_Write | :x: |
| ISFS_WriteAsync | :x: |
| ISFS_Close | :x: |
| ISFS_CloseAsync | :x: |
| ISFS_ShutdownAsync | :x: |
| ISFS_ReadAsync | :white_check_mark: |
| ISFS_Write | :white_check_mark: |
| ISFS_WriteAsync | :white_check_mark: |
| ISFS_Close | :white_check_mark: |
| ISFS_CloseAsync | :white_check_mark: |
| ISFS_ShutdownAsync | :white_check_mark: |

View File

@ -9,7 +9,7 @@
| Object | Percentage (of Bytes) | Functions Done / Total Functions | Percentage (Functions) | Status
| ------------- | ------------- | ------------- | ------------- | -------------
| nand.o | 0.0% | 0 / 30 | 0.0% | :x:
| NANDOpenClose.o | 0.0% | 0 / 17 | 0.0% | :x:
| NANDOpenClose.o | 16.464088397790057% | 5 / 17 | 29.411764705882355% | :eight_pointed_black_star:
| NANDCore.o | 100.0% | 21 / 21 | 100.0% | :white_check_mark:
| NANDSecret.o | 0.0% | 0 / 1 | 0.0% | :x:
| NANDCheck.o | 0.0% | 0 / 2 | 0.0% | :x:
@ -65,12 +65,12 @@
| NANDPrivateSafeOpenAsync | :x: |
| nandSafeOpenAsync | :x: |
| nandSafeOpenCallback | :x: |
| nandReadOpenCallback | :x: |
| NANDSafeCloseAsync | :x: |
| nandSafeCloseAsync | :x: |
| nandReadOpenCallback | :white_check_mark: |
| NANDSafeCloseAsync | :white_check_mark: |
| nandSafeCloseAsync | :white_check_mark: |
| nandSafeCloseCallback | :x: |
| nandReadCloseCallback | :x: |
| nandCloseCallback | :x: |
| nandReadCloseCallback | :white_check_mark: |
| nandCloseCallback | :white_check_mark: |
# NANDCore.o

View File

@ -2,6 +2,7 @@
#define FS_H
#include <revolution/types.h>
#include <private/iostypes.h>
#include <private/iosrestypes.h>
#ifdef __cplusplus
@ -58,11 +59,24 @@ typedef struct {
u8 attr;
} ISFSPathAttrArgs;
typedef struct {
u8 path1[64];
u8 path2[64];
} ISFSPathsArgs;
s32 ISFS_Read(s32, u8 *, u32);
s32 ISFS_ShutdownAsync(ISFSCallback, void *);
s32 ISFS_ReadDir(const u8 *, u8 *, u32 *);
s32 ISFS_ReadDirAsync(const u8 *, u8 *, u32 *, ISFSCallback, void *);
s32 ISFS_CloseAsync(IOSFd, ISFSCallback, void *);
s32 ISFS_RenameAsync(const u8 *, const u8 *, ISFSCallback, void *);
s32 ISFS_RenameAsync(const u8 *, const u8 *, ISFSCallback, void *);
s32 ISFS_DeleteAsync(const u8 *, ISFSCallback, void *);
#ifdef __cplusplus
}
#endif

View File

@ -11,10 +11,22 @@ extern "C" {
s32 IOS_Open(const char *, u32);
s32 IOS_Close(s32);
s32 IOS_CloseAsync(IOSFd, IOSIpcCb, void *);
s32 IOS_Read(IOSFd, void *, u32);
s32 IOS_ReadAsync(IOSFd, void *, u32, IOSIpcCb, void *);
s32 IOS_Write(IOSFd, void *, u32);
s32 IOS_WriteAsync(IOSFd, void *, u32, IOSIpcCb, void *);
s32 IOS_Ioctl(IOSFd, s32, void *, u32, void *, u32);
IOSError IOS_Ioctlv(IOSFd, s32, u32, u32, IOSIoVector *);
s32 IOS_IoctlvReboot(s32, s32, u32, u32, IOSIoVector *);
s32 IOS_Seek(IOSFd, s32, u32);
s32 IOS_SeekAsync(IOSFd, s32, u32, IOSIpcCb, void *);
s32 IOS_IoctlAsync(s32, s32, void *, u32, void *, u32, IOSIpcCb, void *);
#ifdef __cplusplus

View File

@ -119,7 +119,9 @@ s32 NANDWrite(NANDFileInfo *, const void *, u32);
s32 NANDPrivateOpenAsync(const char *, NANDFileInfo *, const u8, NANDCallback, NANDCommandBlock *);
BOOL nandIsInitialized(void);
s32 nandConvertErrorCode(const ISFSError);
void nandGetParentDirectory(char *, const char *);
#ifdef __cplusplus
}

Binary file not shown.

View File

@ -203,6 +203,652 @@ static IOSError _FSGetFileStatsCb(IOSError ret, void* ctxt) {
return rc;
}
s32 ISFS_CreateDir(const u8* dname, u32 dirAttr, u32 ownerAcc, u32 groupAcc, u32 othersAcc) {
ISFSError rc = ISFS_ERROR_OK;
ISFSPathAttrArgs* pathAttrArgs;
__isfsCtxt* blCtxt = 0;
u32 len;
if ((dname == NULL) || (__fsFd < 0) || ((len = strnlen(dname, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
blCtxt = iosAllocAligned(hId, sizeof(*blCtxt), 32);
if (blCtxt == NULL) {
rc = IOS_ERROR_FAIL_ALLOC;
goto out;
}
pathAttrArgs = (ISFSPathAttrArgs*)blCtxt->ioBuf;
memcpy(pathAttrArgs->path, dname, len + 1);
pathAttrArgs->attr = (u8)dirAttr;
pathAttrArgs->ownerAccess = (u8)ownerAcc;
pathAttrArgs->groupAccess = (u8)groupAcc;
pathAttrArgs->othersAccess = (u8)othersAcc;
rc = IOS_Ioctl(__fsFd, 3, pathAttrArgs, sizeof(*pathAttrArgs), NULL, 0);
out:
/* they seem to have had a macro for this, and the programmer forgot it did a NULL check */
if (blCtxt != NULL) {
if (blCtxt != NULL) {
iosFree(hId, blCtxt);
}
}
return rc;
}
s32 ISFS_CreateDirAsync(const u8* dname, u32 dirAttr, u32 ownerAcc, u32 groupAcc, u32 othersAcc, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = ISFS_ERROR_OK;
u32 len;
ISFSPathAttrArgs* pathAttrArgs;
__isfsCtxt* ctxt;
if ((dname == NULL) || (__fsFd < 0) || ((len = strnlen(dname, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
pathAttrArgs = (ISFSPathAttrArgs*)ctxt->ioBuf;
memcpy(pathAttrArgs->path, (void*)dname, len + 1);
pathAttrArgs->attr = dirAttr;
pathAttrArgs->ownerAccess = ownerAcc;
pathAttrArgs->groupAccess = groupAcc;
pathAttrArgs->othersAccess = othersAcc;
rc = IOS_IoctlAsync(__fsFd, 3, pathAttrArgs, sizeof(*pathAttrArgs), NULL, 0, _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_ReadDir(const u8* dname, u8* nameList, u32* num) {
ISFSError rc = ISFS_ERROR_OK;
IOSIoVector* v = 0;
u32 len, numInputs, numOutputs, *numPtr;
char* dnPtr;
__isfsCtxt* blCtxt = 0;
if ((dname == NULL) || (num == NULL) || (__fsFd < 0) || ((u32)nameList & 31) || ((len = strnlen(dname, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
blCtxt = iosAllocAligned(hId, sizeof(*blCtxt), 32);
if (blCtxt == NULL) {
rc = IOS_ERROR_FAIL_ALLOC;
goto out;
}
v = (IOSIoVector*)blCtxt->ioBuf;
dnPtr = (char*)ROUNDUP((u8*)&v[4]);
memcpy(dnPtr, dname, len + 1);
v[0].base = (u8*)dnPtr;
v[0].length = 64;
numPtr = (u32*)ROUNDUP((u32)dnPtr + 64);
v[1].base = (u8*)numPtr;
v[1].length = 4;
if (nameList != NULL) {
numInputs = 2;
numOutputs = 2;
*numPtr = *num;
v[2].base = nameList;
v[2].length = *num * 13;
v[3].base = (u8*)numPtr;
v[3].length = 4;
}
else {
numInputs = 1;
numOutputs = 1;
}
rc = IOS_Ioctlv(__fsFd, 4, numInputs, numOutputs, v);
if (rc != ISFS_ERROR_OK) {
goto out;
}
*num = *numPtr;
out:
if (blCtxt != NULL) {
if (blCtxt != NULL) {
iosFree(hId, blCtxt);
}
}
return rc;
}
s32 ISFS_ReadDirAsync(const u8* dname, u8* nameList, u32* num, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = ISFS_ERROR_OK;
u32 len, numInputs, numOutputs, *numPtr;
IOSIoVector* v = 0;
__isfsCtxt* ctxt = 0;
char* dnPtr;
if ((dname == NULL) || (num == NULL) || (__fsFd < 0) || ((u32)nameList & 31) || ((len = strnlen(dname, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 2;
ctxt->args.num = num;
v = (IOSIoVector*)ctxt->ioBuf;
dnPtr = (char*)ROUNDUP((u8*)&v[4]);
memcpy(dnPtr, dname, len + 1);
v[0].base = (u8*)dnPtr;
v[0].length = 64;
numPtr = (u32*)ROUNDUP((u32)dnPtr + 64);
v[1].base = (u8*)numPtr;
v[1].length = 4;
if (nameList != NULL) {
numInputs = 2;
numOutputs = 2;
*numPtr = *num;
v[2].base = nameList;
v[2].length = *num * 13;
v[3].base = (u8*)numPtr;
v[3].length = 4;
}
else {
numInputs = 1;
numOutputs = 1;
}
rc = IOS_IoctlvAsync(__fsFd, 4, numInputs, numOutputs, v, _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_GetAttr(const u8* name, IOSUid* ownerId, IOSGid* groupId, u32* attr, u32* ownerAcc, u32* groupAcc, u32* othersAcc) {
ISFSError rc = ISFS_ERROR_OK;
ISFSPathAttrArgs* pathAttrArgs;
u8* ptr;
u32 len;
__isfsCtxt* blCtxt = 0;
if ((name == NULL) || (__fsFd < 0) ||
((len = strnlen(name, 64)) == 64) ||
(ownerId == NULL) || (groupId == NULL) || (attr == NULL) ||
(ownerAcc == NULL) || (groupAcc == NULL) || (othersAcc == NULL)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
blCtxt = iosAllocAligned(hId, sizeof(*blCtxt), 32);
if (blCtxt == NULL) {
rc = IOS_ERROR_FAIL_ALLOC;
goto out;
}
ptr = (u8*)blCtxt->ioBuf;
memcpy(ptr, name, len + 1);
pathAttrArgs = (ISFSPathAttrArgs*)ROUNDUP(ptr + 64);
rc = IOS_Ioctl(__fsFd, 6, ptr, 64, pathAttrArgs, sizeof(*pathAttrArgs));
if (rc != IOS_ERROR_OK) {
goto out;
}
*ownerId = pathAttrArgs->ownerId;
*groupId = pathAttrArgs->groupId;
*attr = pathAttrArgs->attr;
*ownerAcc = pathAttrArgs->ownerAccess;
*groupAcc = pathAttrArgs->groupAccess;
*othersAcc = pathAttrArgs->othersAccess;
out:
if (blCtxt != NULL) {
if (blCtxt != NULL) {
iosFree(hId, blCtxt);
}
}
return rc;
}
s32 ISFS_GetAttrAsync(const u8* name, IOSUid* ownerId, IOSGid* groupId, u32* attr, u32* ownerAcc, u32* groupAcc, u32* othersAcc, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = ISFS_ERROR_OK;
__isfsCtxt *ctxt;
ISFSPathAttrArgs *pathAttrArgs;
u8 *ptr;
u32 len;
if ((name == NULL) || (__fsFd < 0) ||
((len = strnlen(name, 64)) == 64) ||
(ownerId == NULL) || (groupId == NULL) || (attr == NULL) ||
(ownerAcc == NULL) || (groupAcc == NULL) || (othersAcc == NULL)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->args.ga.ownerId = ownerId;
ctxt->args.ga.groupId = groupId;
ctxt->args.ga.attr = attr;
ctxt->args.ga.ownerAcc = ownerAcc;
ctxt->args.ga.groupAcc = groupAcc;
ctxt->args.ga.othersAcc = othersAcc;
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 3;
ptr = (u8*)ctxt->ioBuf;
memcpy(ptr, name, len + 1);
pathAttrArgs = (ISFSPathAttrArgs*)ROUNDUP(ptr + 64);
rc = IOS_IoctlAsync(__fsFd, 6, ptr, 64, pathAttrArgs, sizeof(*pathAttrArgs), _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_Delete(const u8* name) {
ISFSError rc = ISFS_ERROR_OK;
u32 len;
__isfsCtxt* blCtxt = 0;
if ((name == NULL) || (__fsFd < 0) || ((len = strnlen(name, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
blCtxt = iosAllocAligned(hId, sizeof(*blCtxt), 32);
if (blCtxt == NULL) {
rc = IOS_ERROR_FAIL_ALLOC;
goto out;
}
memcpy(blCtxt->ioBuf, name, len + 1);
rc = IOS_Ioctl(__fsFd, 7, blCtxt->ioBuf, 64, NULL, 0);
out:
if (blCtxt != NULL) {
if (blCtxt != NULL) {
iosFree(hId, blCtxt);
}
}
return rc;
}
s32 ISFS_DeleteAsync(const u8* name, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = ISFS_ERROR_OK;
u32 len;
__isfsCtxt* ctxt;
if ((name == NULL) || (__fsFd < 0) || ((len = strnlen(name, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
memcpy(ctxt->ioBuf, name, len + 1);
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
rc = IOS_IoctlAsync(__fsFd, 7, ctxt->ioBuf, 64, NULL, 0, _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_Rename(const u8* oldName, const u8* newName) {
ISFSError rc = ISFS_ERROR_OK;
ISFSPathsArgs* pathsArgs;
u32 oldLen, newLen;
__isfsCtxt* blCtxt = 0;
if ((oldName == NULL) || (newName == NULL) || (__fsFd < 0) ||
((oldLen = strnlen(oldName, 64)) == 64) ||
((newLen = strnlen(newName, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
blCtxt = iosAllocAligned(hId, sizeof(*blCtxt), 32);
if (blCtxt == NULL) {
rc = IOS_ERROR_FAIL_ALLOC;
goto out;
}
pathsArgs = (ISFSPathsArgs*)blCtxt->ioBuf;
memcpy(pathsArgs->path1, oldName, oldLen + 1);
memcpy(pathsArgs->path2, newName, newLen + 1);
rc = IOS_Ioctl(__fsFd, 8, pathsArgs, sizeof(*pathsArgs), NULL, 0);
out:
if (blCtxt != NULL) {
if (blCtxt != NULL) {
iosFree(hId, blCtxt);
}
}
return rc;
}
s32 ISFS_RenameAsync(const u8* oldName, const u8* newName, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = ISFS_ERROR_OK;
ISFSPathsArgs* pathsArgs;
u32 oldLen, newLen;
__isfsCtxt* ctxt;
if ((oldName == NULL) || (newName == NULL) || (__fsFd < 0) ||
((oldLen = strnlen(oldName, 64)) == 64) ||
((newLen = strnlen(newName, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
pathsArgs = (ISFSPathsArgs*)ctxt->ioBuf;
memcpy(pathsArgs->path1, oldName, oldLen + 1);
memcpy(pathsArgs->path2, newName, newLen + 1);
rc = IOS_IoctlAsync(__fsFd, 8, pathsArgs, sizeof(*pathsArgs), NULL, 0, _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_GetUsage(const u8* dname, u32* nblocks, u32* ninodes) {
ISFSError rc = ISFS_ERROR_OK;
IOSIoVector* v = 0;
u32 len, *blkPtr, *inodePtr;
char* dnPtr;
__isfsCtxt* blCtxt = 0;
if ((dname == NULL) || (__fsFd < 0) ||
(nblocks == NULL) || (ninodes == NULL) ||
((len = strnlen(dname, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
blCtxt = iosAllocAligned(hId, sizeof(*blCtxt), 32);
if (blCtxt == NULL) {
rc = IOS_ERROR_FAIL_ALLOC;
goto out;
}
v = (IOSIoVector*)blCtxt->ioBuf;
dnPtr = (char*)ROUNDUP((u8*)&v[3]);
memcpy(dnPtr, dname, len + 1);
v[0].base = (u8*)dnPtr;
v[0].length = 64;
blkPtr = (u32*) ROUNDUP(((u32)dnPtr) + 64);
inodePtr = (u32*) ROUNDUP(((u32)blkPtr) + 4);
v[1].base = (u8*) blkPtr;
v[1].length = 4;
v[2].base = (u8*)inodePtr;
v[2].length = 4;
rc = IOS_Ioctlv(__fsFd, 12, 1, 2, v);
if (rc != ISFS_ERROR_OK) {
goto out;
}
*nblocks = *blkPtr;
*ninodes = *inodePtr;
out:
if (blCtxt != NULL) {
if (blCtxt != NULL) {
iosFree(hId, blCtxt);
}
}
return rc;
}
s32 ISFS_CreateFile(const u8* fname, u32 fileAttr, u32 ownerAcc, u32 groupAcc, u32 othersAcc) {
ISFSError rc = ISFS_ERROR_OK;
ISFSPathAttrArgs* pathAttrArgs;
u32 len;
__isfsCtxt* blCtxt = NULL;
if ((fname == NULL) || (__fsFd < 0) || ((len = strnlen(fname, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
blCtxt = iosAllocAligned(hId, sizeof(*blCtxt), 32);
if (blCtxt == NULL) {
rc = IOS_ERROR_FAIL_ALLOC;
goto out;
}
pathAttrArgs = (ISFSPathAttrArgs*)blCtxt->ioBuf;
memcpy(pathAttrArgs->path, fname, len + 1);
pathAttrArgs->attr = fileAttr;
pathAttrArgs->ownerAccess = ownerAcc;
pathAttrArgs->groupAccess = groupAcc;
pathAttrArgs->othersAccess = othersAcc;
rc = IOS_Ioctl(__fsFd, 9, pathAttrArgs, sizeof(*pathAttrArgs), NULL, 0);
out:
if (blCtxt != NULL) {
if (blCtxt != NULL) {
iosFree(hId, blCtxt);
}
}
return rc;
}
s32 ISFS_CreateFileAsync(const u8* fname, u32 fileAttr, u32 ownerAcc, u32 groupAcc, u32 othersAcc, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = ISFS_ERROR_OK;
ISFSPathAttrArgs* pathAttrArgs;
u32 len;
__isfsCtxt* ctxt;
if ((fname == NULL) || (__fsFd < 0) || ((len = strnlen(fname, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
pathAttrArgs = (ISFSPathAttrArgs*)ctxt->ioBuf;
memcpy(pathAttrArgs->path, fname, len + 1);
pathAttrArgs->attr = fileAttr;
pathAttrArgs->ownerAccess = ownerAcc;
pathAttrArgs->groupAccess = groupAcc;
pathAttrArgs->othersAccess = othersAcc;
rc = IOS_IoctlAsync(__fsFd, 9, pathAttrArgs, sizeof(*pathAttrArgs), NULL, 0, _isfsFuncCb, ctxt);
out:
return rc;
}
IOSFd ISFS_Open(const u8* fname, u32 access) {
ISFSError rc = ISFS_ERROR_OK;
u32 len;
__isfsCtxt* blCtxt = 0;
if ((fname == NULL) || ((len = strnlen(fname, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
blCtxt = iosAllocAligned(hId, sizeof(*blCtxt), 32);
if (blCtxt == NULL) {
rc = IOS_ERROR_FAIL_ALLOC;
goto out;
}
memcpy(blCtxt->ioBuf, fname, len + 1);
rc = IOS_Open((const char*)blCtxt->ioBuf, access);
out:
if (blCtxt != NULL) {
if (blCtxt != NULL) {
iosFree(hId, blCtxt);
}
}
return rc;
}
IOSFd ISFS_OpenAsync(const u8* fname, u32 access, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = ISFS_ERROR_OK;
u32 len;
__isfsCtxt* ctxt;
if ((fname == NULL) || ((len = strnlen(fname, 64)) == 64)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
memcpy(ctxt->ioBuf, fname, len + 1);
rc = IOS_OpenAsync((const char*)ctxt->ioBuf, access, _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_GetFileStats(IOSFd fd, ISFSFileStats* stats) {
ISFSError rc = ISFS_ERROR_OK;
__isfsCtxt* blCtxt = 0;
if ((stats == NULL) || ((u32)stats & 31)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
blCtxt = iosAllocAligned(hId, sizeof(*blCtxt), 32);
if (blCtxt == NULL) {
rc = IOS_ERROR_FAIL_ALLOC;
goto out;
}
rc = IOS_Ioctl(fd, 11, NULL, 0, blCtxt->ioBuf, sizeof(*stats));
if (rc != IOS_ERROR_OK) {
goto out;
}
memcpy(stats, blCtxt->ioBuf, sizeof(*stats));
out:
if (blCtxt != NULL) {
if (blCtxt != NULL) {
iosFree(hId, blCtxt);
}
}
return rc;
}
s32 ISFS_GetFileStatsAsync(IOSFd fd, ISFSFileStats* stats, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = ISFS_ERROR_OK;
__isfsCtxt* ctxt;
if ((stats == NULL) || ((u32)stats & 31)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 5;
ctxt->args.fstats = stats;
rc = IOS_IoctlAsync(fd, 11, NULL, 0, ctxt->ioBuf, sizeof(*stats), _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_Seek(IOSFd fd, s32 offset, u32 whence) {
return IOS_Seek(fd, offset, whence);
}
s32 ISFS_SeekAsync(IOSFd fd, s32 offset, u32 whence, ISFSCallback cb, void* fsCtxt) {
ISFSError rc;
__isfsCtxt* ctxt;
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
rc = IOS_SeekAsync(fd, offset, whence, _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_Read(s32 fd, u8 *pBuffer, u32 bufSize) {
/* nullptr check and alignment to 0x20 */
if (pBuffer == NULL || (u32)pBuffer & 31) {
@ -210,4 +856,109 @@ s32 ISFS_Read(s32 fd, u8 *pBuffer, u32 bufSize) {
}
return IOS_Read(fd, pBuffer, bufSize);
}
s32 ISFS_ReadAsync(IOSFd fd, u8* buf, u32 size, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = ISFS_ERROR_OK;
__isfsCtxt* ctxt;
if ((buf == NULL) || ((u32)buf & 31)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
rc = IOS_ReadAsync(fd, buf, size, _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_Write(IOSFd fd, const u8* buf, u32 size) {
ISFSError rc = ISFS_ERROR_OK;
if ((buf == NULL) || ((u32)buf & 31)) {
rc = ISFS_ERROR_INVALID;
goto out;
}
rc = IOS_Write(fd, (u8*)buf, size);
out:
return rc;
}
s32 ISFS_WriteAsync(IOSFd fd, const u8* buf, u32 size, ISFSCallback cb, void* fsCtxt) {
ISFSError rc = 0;
__isfsCtxt* ctxt;
if ((buf == NULL) || ((u32)buf & (u32)(31))) {
rc = ISFS_ERROR_INVALID;
goto out;
}
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = ISFS_ERROR_BUSY;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
rc = IOS_WriteAsync(fd, (void*)buf, size, _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_Close(IOSFd fd) {
return IOS_Close(fd);
}
s32 ISFS_CloseAsync(IOSFd fd, ISFSCallback cb, void* fsCtxt) {
ISFSError rc;
__isfsCtxt* ctxt;
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (ctxt == NULL) {
rc = -118;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
rc = IOS_CloseAsync(fd, _isfsFuncCb, ctxt);
out:
return rc;
}
s32 ISFS_ShutdownAsync(ISFSCallback cb, void* fsCtxt) {
__isfsCtxt* ctxt;
s32 rc = 0;
ctxt = iosAllocAligned(hId, sizeof(*ctxt), 32);
if (__fsFd < 0) {
rc = -101;
goto out;
}
ctxt->cb = cb;
ctxt->ctxt = fsCtxt;
ctxt->func = 0;
rc = IOS_IoctlAsync(__fsFd, 13, NULL, 0, NULL, 0, _isfsFuncCb, ctxt);
out:
return rc;
}

View File

@ -0,0 +1,131 @@
#include <revolution/nand.h>
#include <revolution/fs.h>
static void nandReadCloseCallback(ISFSError, void *);
static void nandCloseCallback(ISFSError, void *);
static void nandSafeCloseCallback(ISFSError, void *);
s32 nandSafeCloseAsync(NANDFileInfo *, NANDCallback, NANDCommandBlock *, BOOL);
void nandReadOpenCallback(ISFSError result, void* ctxt) {
NANDCommandBlock* b = (NANDCommandBlock*)ctxt;
if (result >= 0) {
((NANDFileInfo*)(b->fileInfo))->fileDescriptor = result;
((NANDFileInfo*)(b->fileInfo))->stage = 2;
if (!(b->simpleFlag)) {
((NANDFileInfo*)(b->fileInfo))->mark = 3;
}
else {
((NANDFileInfo*)(b->fileInfo))->mark = 5;
}
((NANDCallback)(b->callback))(NAND_RESULT_OK, b);
}
else {
((NANDCallback)(b->callback))(nandConvertErrorCode(result), b);
}
}
s32 NANDSafeCloseAsync(NANDFileInfo* info, NANDCallback cb, NANDCommandBlock* block) {
return nandSafeCloseAsync(info, cb, block, FALSE);
}
s32 nandSafeCloseAsync(NANDFileInfo* info, NANDCallback cb, NANDCommandBlock* block, BOOL simple_flag) {
ISFSError err = ISFS_ERROR_UNKNOWN;
if (!nandIsInitialized()) {
return NAND_RESULT_FATAL_ERROR;
}
if (!(((info->mark == 3) && !simple_flag) || ((info->mark == 5) && simple_flag))) {
return NAND_RESULT_INVALID;
}
block->simpleFlag = simple_flag;
if (info->accType == 1) {
block->fileInfo = info;
block->callback = cb;
err = ISFS_CloseAsync(info->fileDescriptor, nandReadCloseCallback, block);
}
else if ((info->accType == 2) || (info->accType == 3)) {
block->fileInfo = info;
block->callback = cb;
block->state = 10;
err = ISFS_CloseAsync(info->fileDescriptor, nandSafeCloseCallback, block);
}
else {
err = ISFS_ERROR_INVALID;
}
return nandConvertErrorCode(err);
}
void nandSafeCloseCallback(ISFSError result, void* ctxt) {
NANDCommandBlock* b= (NANDCommandBlock*)ctxt;
if (result == 0) {
NANDFileInfo* info = b->fileInfo;
ISFSError ret = ISFS_ERROR_UNKNOWN;
if (b->state == 12) {
info->stage = 8;
}
if ((b->state == 12) && b->simpleFlag) {
b->state += 2;
}
else {
++b->state;
}
if (b->state == 11) {
info->stage = 6;
ret = ISFS_CloseAsync(info->origFd, nandSafeCloseCallback, ctxt);
}
else if (b->state == 12) {
info->stage = 7;
ret = ISFS_RenameAsync((u8*)(info->tmpPath), (u8*)(info->origPath), nandSafeCloseCallback, ctxt);
}
else if (b->state == 13) {
char tmpdir[64] = "";
nandGetParentDirectory(tmpdir, info->tmpPath);
ret = ISFS_DeleteAsync((u8*)tmpdir, nandSafeCloseCallback, ctxt);
}
else if (b->state == 14) {
if (!(b->simpleFlag)) {
info->stage = 9;
}
info->mark = 4;
((NANDCallback)(b->callback))(nandConvertErrorCode(result), b);
return;
}
if (ret != 0) {
((NANDCallback)(b->callback))(nandConvertErrorCode(ret), b);
}
}
}
static void nandReadCloseCallback(ISFSError result, void* ctxt) {
NANDCommandBlock* b = (NANDCommandBlock*)ctxt;
if (result == 0) {
((NANDFileInfo*)(b->fileInfo))->stage = 7;
((NANDFileInfo*)(b->fileInfo))->mark = 4;
}
((NANDCallback)(b->callback))(nandConvertErrorCode(result), b);
}
static void nandCloseCallback(ISFSError result, void* ctxt) {
NANDCommandBlock* b = (NANDCommandBlock*)ctxt;
if (result == 0) {
((NANDFileInfo*)(b->fileInfo))->stage = 7;
((NANDFileInfo*)(b->fileInfo))->mark = 2;
}
((NANDCallback)(b->callback))(nandConvertErrorCode(result), b);
}