Difference between revisions of "NAND (SDK)"
Jump to navigation
Jump to search
Hallowizer (talk | contribs) (←Created page with ''''NAND''' is an SDK library that provides filesystem functions. == Public functions == {| class="wikitable sortable" ! Signature ! Description |- | <code>int CreateFi...') |
Hallowizer (talk | contribs) (→File struct: added remaining fields and fixed struct name) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
! Description | ! Description | ||
|- | |- | ||
− | | <code>int | + | | <code>int NANDPrivateCreate(char *path, int permissions, int attributes)</code> |
| Creates a file. <code>path</code> can be a relative path, relative to the data directory of the active [[title]]. <code>permissions</code> is a single number that is put through a function to split it into permissions for owner/group/other. <code>attributes</code> is fed directly to [[:/dev/fs]]. | | Creates a file. <code>path</code> can be a relative path, relative to the data directory of the active [[title]]. <code>permissions</code> is a single number that is put through a function to split it into permissions for owner/group/other. <code>attributes</code> is fed directly to [[:/dev/fs]]. | ||
|- | |- | ||
− | | <code>int | + | | <code>int NANDPrivateCreateAsync(char *path, int permissions, int attributes, void (*callback)(int, void *), void *userData)</code> |
+ | | Same as <code>NANDPrivateCreate</code>, but done asynchronously | ||
+ | |- | ||
+ | | <code>int NANDDelete(char *path)</code> | ||
+ | | Deletes a file or directory | ||
+ | |- | ||
+ | | <code>int NANDRead(struct File *file, char *data, int len)</code> | ||
| Equivalent to IOS_Read, but takes a <code>struct File</code> instead of an <code>fd</code>. | | Equivalent to IOS_Read, but takes a <code>struct File</code> instead of an <code>fd</code>. | ||
|- | |- | ||
− | | <code>int | + | | <code>int NANDReadAsync(struct File *file, char *data, int len, void (*callback)(int, void *), void *userData)</code> |
− | | Asynchronous version of <code> | + | | Asynchronous version of <code>NANDRead</code> |
|- | |- | ||
− | | <code>int | + | | <code>int NANDWrite(struct File *file, char *data, int len)</code> |
| Equivalent to IOS_Write, but takes a <code>struct File</code> instead of an <code>fd</code>. | | Equivalent to IOS_Write, but takes a <code>struct File</code> instead of an <code>fd</code>. | ||
|- | |- | ||
− | | <code>int | + | | <code>int NANDWriteAsync(struct File *file, char *data, int len, void (*callback)(int, void *), void *userData)</code> |
+ | | Asynchronous version of <code>NANDWrite</code> | ||
+ | |- | ||
+ | | <code>int NANDSeekAsync(struct File *file, int offset, SeekMode mode, void (*callback)(int, void *), void *userData)</code> | ||
+ | | Seeks a file asynchronously using IOS_Seek | ||
+ | |- | ||
+ | | <code>int NANDPrivateCreateDirAsync(char *path, int permissions, int attributes, void *userData)</code> | ||
+ | | Same as <code>NANDPrivateCreateAsync</code>, but creates a directory | ||
+ | |- | ||
+ | | <code>int NANDOpen(char *path, struct File *file, int mode)</code> | ||
| Opens the file with IOS_Open and initializes <code>file</code>. <code>path</code> can be a relative path, relative to the current title's data directory. Returns error -102 when trying to open any path starting with <code>[[:/shared2]]</code>. | | Opens the file with IOS_Open and initializes <code>file</code>. <code>path</code> can be a relative path, relative to the current title's data directory. Returns error -102 when trying to open any path starting with <code>[[:/shared2]]</code>. | ||
|- | |- | ||
− | | <code>int | + | | <code>int NANDPrivateOpen(char *path, struct File *file, int mode)</code> |
− | | Same as <code> | + | | Same as <code>NANDOpen</code>, except files in /shared2 are allowed. |
|- | |- | ||
− | | <code>int | + | | <code>int NANDPrivateOpenAsync(char *path, struct File *file, int mode, void (*callback)(int, void *), void *userData)</code> |
− | | Same as <code> | + | | Same as <code>NANDOpenAsync</code>, without the /shared2 check. |
|- | |- | ||
− | | <code>int | + | | <code>int NANDClose(struct File *file)</code> |
| Calls IOS_Close and marks <code>file</code> as closed. | | Calls IOS_Close and marks <code>file</code> as closed. | ||
|- | |- | ||
− | | <code>int | + | | <code>int NANDCloseAsync(struct File *file, void (*callback)(int, void *), void *userData)</code> |
| Calls IOS_CloseAsync and marks <code>file</code> as closed. Also sets <code>unknownAsync</code> to 7, although it is not known what this field actually does. | | Calls IOS_CloseAsync and marks <code>file</code> as closed. Also sets <code>unknownAsync</code> to 7, although it is not known what this field actually does. | ||
+ | |} | ||
+ | |||
+ | == Error codes == | ||
+ | Most error codes are converted from the errors returned by [[IPC (SDK)|IPC]], which usually come directly from [[IOS]] | ||
+ | |||
+ | {| class="wikitable sortable" | ||
+ | ! Error | ||
+ | ! IPC error(s) | ||
+ | ! Description | ||
+ | |- | ||
+ | | 0 | ||
+ | | 0 | ||
+ | | No error | ||
+ | |- | ||
+ | | -1 | ||
+ | | -1, -102, -105 | ||
+ | | Operation not permitted? Returned for EACCESS and EEXIST | ||
+ | |- | ||
+ | | -2 | ||
+ | | -22, -114 | ||
+ | | Memory error? Returned for ENOMEM and some EIO | ||
+ | |- | ||
+ | | -3 | ||
+ | | -118 | ||
+ | | Try again later? Returned for certain ENAMETOOLONG errors | ||
+ | |- | ||
+ | | -5 | ||
+ | | -12 | ||
+ | | Returned for some EIO | ||
+ | |- | ||
+ | | -6 | ||
+ | | -2 | ||
+ | | Returned for some EEXIST | ||
+ | |- | ||
+ | | -8 | ||
+ | | -4, -101 | ||
+ | | Returned for some EINVAL | ||
+ | |- | ||
+ | | -9 | ||
+ | | -108 | ||
+ | | Returned if memory is full | ||
+ | |- | ||
+ | | -10 | ||
+ | | -109 | ||
+ | | Returned for some ENFILE | ||
+ | |- | ||
+ | | -11 | ||
+ | | -107 | ||
+ | | Returned for some ENFILE | ||
+ | |- | ||
+ | | -12 | ||
+ | | -6, -106 | ||
+ | | Returned for ENOENT | ||
+ | |- | ||
+ | | -13 | ||
+ | | -115 | ||
+ | | Returned for ENOTEMPTY | ||
+ | |- | ||
+ | | -14 | ||
+ | | -111 | ||
+ | | Returned if the FD is already open | ||
+ | |- | ||
+ | | -15 | ||
+ | | -116 | ||
+ | | Returned for some ENAMETOOLONG | ||
+ | |- | ||
+ | | -16 | ||
+ | | -110 | ||
+ | | Returned for some ENAMETOOLONG | ||
+ | |- | ||
+ | | -40 | ||
+ | | -103 | ||
+ | | Returned for some EIO | ||
+ | |- | ||
+ | | -64 | ||
+ | | -3, -5, -7, -9, -10, -11, -13, -14, -15, -16, -17, -18, -19, -20, -21, -23, -104, -117 | ||
+ | | Returned for unrecognized error code? None of these error codes are known by the homebrew scene. | ||
+ | |- | ||
+ | | -128 | ||
+ | | -119 | ||
+ | | Returned for fatal error | ||
|} | |} | ||
== File struct == | == File struct == | ||
<pre> | <pre> | ||
− | struct | + | struct NANDFileInfo { |
s32 fd; | s32 fd; | ||
− | u8 | + | s32 tmpFd; |
− | u8 | + | char *realPath; |
− | u8 status; // 1 = open, 2 = closed | + | char *tmpPath; |
+ | u8 safeMode; | ||
+ | u8 lastAutoOperation; // 0 = begin safe open, 1 = /tmp/sys dir created, 2 = opened async or safe, 3 = /tmp/sys/NUM dir created, 4 = /tmp/sys file created, 5 = /tmp/sys file opened, 6 = closing safe, 7 = closed asynchronously, 8 = moved /tmp/sys file to real path | ||
+ | u8 status; // 1 = open, 2 = closed, 3 = safe sync open, 4 = safe close, 5 = safe async open, 6 = safe async close | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | [[Category:SDK]] |
Latest revision as of 03:35, 14 June 2022
NAND is an SDK library that provides filesystem functions.
Public functions
Signature | Description |
---|---|
int NANDPrivateCreate(char *path, int permissions, int attributes)
|
Creates a file. path can be a relative path, relative to the data directory of the active title. permissions is a single number that is put through a function to split it into permissions for owner/group/other. attributes is fed directly to /dev/fs.
|
int NANDPrivateCreateAsync(char *path, int permissions, int attributes, void (*callback)(int, void *), void *userData)
|
Same as NANDPrivateCreate , but done asynchronously
|
int NANDDelete(char *path)
|
Deletes a file or directory |
int NANDRead(struct File *file, char *data, int len)
|
Equivalent to IOS_Read, but takes a struct File instead of an fd .
|
int NANDReadAsync(struct File *file, char *data, int len, void (*callback)(int, void *), void *userData)
|
Asynchronous version of NANDRead
|
int NANDWrite(struct File *file, char *data, int len)
|
Equivalent to IOS_Write, but takes a struct File instead of an fd .
|
int NANDWriteAsync(struct File *file, char *data, int len, void (*callback)(int, void *), void *userData)
|
Asynchronous version of NANDWrite
|
int NANDSeekAsync(struct File *file, int offset, SeekMode mode, void (*callback)(int, void *), void *userData)
|
Seeks a file asynchronously using IOS_Seek |
int NANDPrivateCreateDirAsync(char *path, int permissions, int attributes, void *userData)
|
Same as NANDPrivateCreateAsync , but creates a directory
|
int NANDOpen(char *path, struct File *file, int mode)
|
Opens the file with IOS_Open and initializes file . path can be a relative path, relative to the current title's data directory. Returns error -102 when trying to open any path starting with /shared2 .
|
int NANDPrivateOpen(char *path, struct File *file, int mode)
|
Same as NANDOpen , except files in /shared2 are allowed.
|
int NANDPrivateOpenAsync(char *path, struct File *file, int mode, void (*callback)(int, void *), void *userData)
|
Same as NANDOpenAsync , without the /shared2 check.
|
int NANDClose(struct File *file)
|
Calls IOS_Close and marks file as closed.
|
int NANDCloseAsync(struct File *file, void (*callback)(int, void *), void *userData)
|
Calls IOS_CloseAsync and marks file as closed. Also sets unknownAsync to 7, although it is not known what this field actually does.
|
Error codes
Most error codes are converted from the errors returned by IPC, which usually come directly from IOS
Error | IPC error(s) | Description |
---|---|---|
0 | 0 | No error |
-1 | -1, -102, -105 | Operation not permitted? Returned for EACCESS and EEXIST |
-2 | -22, -114 | Memory error? Returned for ENOMEM and some EIO |
-3 | -118 | Try again later? Returned for certain ENAMETOOLONG errors |
-5 | -12 | Returned for some EIO |
-6 | -2 | Returned for some EEXIST |
-8 | -4, -101 | Returned for some EINVAL |
-9 | -108 | Returned if memory is full |
-10 | -109 | Returned for some ENFILE |
-11 | -107 | Returned for some ENFILE |
-12 | -6, -106 | Returned for ENOENT |
-13 | -115 | Returned for ENOTEMPTY |
-14 | -111 | Returned if the FD is already open |
-15 | -116 | Returned for some ENAMETOOLONG |
-16 | -110 | Returned for some ENAMETOOLONG |
-40 | -103 | Returned for some EIO |
-64 | -3, -5, -7, -9, -10, -11, -13, -14, -15, -16, -17, -18, -19, -20, -21, -23, -104, -117 | Returned for unrecognized error code? None of these error codes are known by the homebrew scene. |
-128 | -119 | Returned for fatal error |
File struct
struct NANDFileInfo { s32 fd; s32 tmpFd; char *realPath; char *tmpPath; u8 safeMode; u8 lastAutoOperation; // 0 = begin safe open, 1 = /tmp/sys dir created, 2 = opened async or safe, 3 = /tmp/sys/NUM dir created, 4 = /tmp/sys file created, 5 = /tmp/sys file opened, 6 = closing safe, 7 = closed asynchronously, 8 = moved /tmp/sys file to real path u8 status; // 1 = open, 2 = closed, 3 = safe sync open, 4 = safe close, 5 = safe async open, 6 = safe async close }