Remove service handle parameter from FSUSER IPC wrappers

This commit is contained in:
fincs 2015-09-06 17:54:36 +02:00
parent 9b1e6bfc39
commit 053c71ad08
4 changed files with 74 additions and 163 deletions

View File

@ -129,27 +129,27 @@ typedef struct
Result fsInit(void); Result fsInit(void);
Result fsExit(void); Result fsExit(void);
Handle *fsGetSessionHandle(); Handle *fsGetSessionHandle(void);
FS_path FS_makePath(FS_pathType type, const char *path); FS_path FS_makePath(FS_pathType type, const char *path);
Result FSUSER_Initialize(Handle* handle); Result FSUSER_Initialize(void);
Result FSUSER_OpenArchive(Handle* handle, FS_archive* archive); Result FSUSER_OpenArchive(FS_archive* archive);
Result FSUSER_OpenDirectory(Handle* handle, Handle* out, FS_archive archive, FS_path dirLowPath); Result FSUSER_OpenDirectory(Handle* out, FS_archive archive, FS_path dirLowPath);
Result FSUSER_OpenFile(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes); Result FSUSER_OpenFile(Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
Result FSUSER_OpenFileDirectly(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes); Result FSUSER_OpenFileDirectly(Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
Result FSUSER_CloseArchive(Handle* handle, FS_archive* archive); Result FSUSER_CloseArchive(FS_archive* archive);
Result FSUSER_CreateFile(Handle* handle, FS_archive archive, FS_path fileLowPath, u32 fileSize); Result FSUSER_CreateFile(FS_archive archive, FS_path fileLowPath, u32 fileSize);
Result FSUSER_CreateDirectory(Handle* handle, FS_archive archive, FS_path dirLowPath); Result FSUSER_CreateDirectory(FS_archive archive, FS_path dirLowPath);
Result FSUSER_DeleteFile(Handle *handle, FS_archive archive, FS_path fileLowPath); Result FSUSER_DeleteFile(FS_archive archive, FS_path fileLowPath);
Result FSUSER_DeleteDirectory(Handle *handle, FS_archive archive, FS_path dirLowPath); Result FSUSER_DeleteDirectory(FS_archive archive, FS_path dirLowPath);
Result FSUSER_DeleteDirectoryRecursively(Handle *handle, FS_archive archive, FS_path dirLowPath); Result FSUSER_DeleteDirectoryRecursively(FS_archive archive, FS_path dirLowPath);
Result FSUSER_RenameFile(Handle *handle, FS_archive srcArchive, FS_path srcFileLowPath, FS_archive destArchive, FS_path destFileLowPath); Result FSUSER_RenameFile(FS_archive srcArchive, FS_path srcFileLowPath, FS_archive destArchive, FS_path destFileLowPath);
Result FSUSER_RenameDirectory(Handle *handle, FS_archive srcArchive, FS_path srcDirLowPath, FS_archive destArchive, FS_path destDirLowPath); Result FSUSER_RenameDirectory(FS_archive srcArchive, FS_path srcDirLowPath, FS_archive destArchive, FS_path destDirLowPath);
Result FSUSER_GetSdmcArchiveResource(Handle *handle, u32 *sectorSize, u32 *clusterSize, u32 *numClusters, u32 *freeClusters); Result FSUSER_GetSdmcArchiveResource(u32 *sectorSize, u32 *clusterSize, u32 *numClusters, u32 *freeClusters);
Result FSUSER_GetNandArchiveResource(Handle *handle, u32 *sectorSize, u32 *clusterSize, u32 *numClusters, u32 *freeClusters); Result FSUSER_GetNandArchiveResource(u32 *sectorSize, u32 *clusterSize, u32 *numClusters, u32 *freeClusters);
Result FSUSER_IsSdmcDetected(Handle *handle, u8 *detected); Result FSUSER_IsSdmcDetected(u8 *detected);
Result FSUSER_IsSdmcWritable(Handle *handle, u8 *writable); Result FSUSER_IsSdmcWritable(u8 *writable);
Result FSFILE_Close(Handle handle); Result FSFILE_Close(Handle handle);
Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, void *buffer, u32 size); Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, void *buffer, u32 size);

View File

@ -137,7 +137,7 @@ Result romfsInit(void)
FS_archive arch = { ARCH_SDMC, { PATH_EMPTY, 1, (u8*)"" }, 0, 0 }; FS_archive arch = { ARCH_SDMC, { PATH_EMPTY, 1, (u8*)"" }, 0, 0 };
FS_path path = { PATH_WCHAR, units+1, (u8*)__utf16path }; FS_path path = { PATH_WCHAR, units+1, (u8*)__utf16path };
Result rc = FSUSER_OpenFileDirectly(NULL, &romFS_file, arch, path, FS_OPEN_READ, FS_ATTRIBUTE_NONE); Result rc = FSUSER_OpenFileDirectly(&romFS_file, arch, path, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
if (rc) return rc; if (rc) return rc;
_3DSX_Header hdr; _3DSX_Header hdr;
@ -155,7 +155,7 @@ Result romfsInit(void)
FS_archive arch = { ARCH_ROMFS, { PATH_EMPTY, 1, (u8*)"" }, 0, 0 }; FS_archive arch = { ARCH_ROMFS, { PATH_EMPTY, 1, (u8*)"" }, 0, 0 };
FS_path path = { PATH_BINARY, sizeof(zeros), zeros }; FS_path path = { PATH_BINARY, sizeof(zeros), zeros };
Result rc = FSUSER_OpenFileDirectly(NULL, &romFS_file, arch, path, FS_OPEN_READ, FS_ATTRIBUTE_NONE); Result rc = FSUSER_OpenFileDirectly(&romFS_file, arch, path, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
if (rc) return rc; if (rc) return rc;
} }

View File

@ -227,7 +227,7 @@ Result sdmcInit(void)
if(sdmcInitialised) if(sdmcInitialised)
return rc; return rc;
rc = FSUSER_OpenArchive(NULL, &sdmcArchive); rc = FSUSER_OpenArchive(&sdmcArchive);
if(rc == 0) if(rc == 0)
{ {
@ -287,7 +287,7 @@ Result sdmcExit(void)
if(!sdmcInitialised) return rc; if(!sdmcInitialised) return rc;
rc = FSUSER_CloseArchive(NULL, &sdmcArchive); rc = FSUSER_CloseArchive(&sdmcArchive);
if(rc == 0) if(rc == 0)
{ {
RemoveDevice("sdmc"); RemoveDevice("sdmc");
@ -364,7 +364,7 @@ sdmc_open(struct _reent *r,
/* Test O_EXCL. */ /* Test O_EXCL. */
if((flags & O_CREAT) && (flags & O_EXCL)) if((flags & O_CREAT) && (flags & O_EXCL))
{ {
rc = FSUSER_CreateFile(NULL, sdmcArchive, fs_path, 0); rc = FSUSER_CreateFile(sdmcArchive, fs_path, 0);
if(rc != 0) if(rc != 0)
{ {
r->_errno = sdmc_translate_error(rc); r->_errno = sdmc_translate_error(rc);
@ -377,7 +377,7 @@ sdmc_open(struct _reent *r,
attributes |= FS_ATTRIBUTE_READONLY;*/ attributes |= FS_ATTRIBUTE_READONLY;*/
/* open the file */ /* open the file */
rc = FSUSER_OpenFile(NULL, &fd, sdmcArchive, fs_path, rc = FSUSER_OpenFile(&fd, sdmcArchive, fs_path,
sdmc_flags, attributes); sdmc_flags, attributes);
if(rc == 0) if(rc == 0)
{ {
@ -667,7 +667,7 @@ sdmc_stat(struct _reent *r,
if(fs_path.data == NULL) if(fs_path.data == NULL)
return -1; return -1;
if((rc = FSUSER_OpenFile(NULL, &fd, sdmcArchive, fs_path, if((rc = FSUSER_OpenFile(&fd, sdmcArchive, fs_path,
FS_OPEN_READ, FS_ATTRIBUTE_NONE)) == 0) FS_OPEN_READ, FS_ATTRIBUTE_NONE)) == 0)
{ {
sdmc_file_t tmpfd = { .fd = fd }; sdmc_file_t tmpfd = { .fd = fd };
@ -676,7 +676,7 @@ sdmc_stat(struct _reent *r,
return rc; return rc;
} }
else if((rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, fs_path)) == 0) else if((rc = FSUSER_OpenDirectory(&fd, sdmcArchive, fs_path)) == 0)
{ {
memset(st, 0, sizeof(struct stat)); memset(st, 0, sizeof(struct stat));
st->st_nlink = 1; st->st_nlink = 1;
@ -726,7 +726,7 @@ sdmc_unlink(struct _reent *r,
if(fs_path.data == NULL) if(fs_path.data == NULL)
return -1; return -1;
rc = FSUSER_DeleteFile(NULL, sdmcArchive, fs_path); rc = FSUSER_DeleteFile(sdmcArchive, fs_path);
if(rc == 0) if(rc == 0)
return 0; return 0;
@ -754,7 +754,7 @@ sdmc_chdir(struct _reent *r,
if(fs_path.data == NULL) if(fs_path.data == NULL)
return -1; return -1;
rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, fs_path); rc = FSUSER_OpenDirectory(&fd, sdmcArchive, fs_path);
if(rc == 0) if(rc == 0)
{ {
FSDIR_Close(fd); FSDIR_Close(fd);
@ -795,11 +795,11 @@ sdmc_rename(struct _reent *r,
if(fs_path_new.data == NULL) if(fs_path_new.data == NULL)
return -1; return -1;
rc = FSUSER_RenameFile(NULL, sdmcArchive, fs_path_old, sdmcArchive, fs_path_new); rc = FSUSER_RenameFile(sdmcArchive, fs_path_old, sdmcArchive, fs_path_new);
if(rc == 0) if(rc == 0)
return 0; return 0;
rc = FSUSER_RenameDirectory(NULL, sdmcArchive, fs_path_old, sdmcArchive, fs_path_new); rc = FSUSER_RenameDirectory(sdmcArchive, fs_path_old, sdmcArchive, fs_path_new);
if(rc == 0) if(rc == 0)
return 0; return 0;
@ -830,7 +830,7 @@ sdmc_mkdir(struct _reent *r,
/* TODO: Use mode to set directory attributes. */ /* TODO: Use mode to set directory attributes. */
rc = FSUSER_CreateDirectory(NULL, sdmcArchive, fs_path); rc = FSUSER_CreateDirectory(sdmcArchive, fs_path);
if(rc == 0) if(rc == 0)
return 0; return 0;
@ -865,7 +865,7 @@ sdmc_diropen(struct _reent *r,
sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct); sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
/* open the directory */ /* open the directory */
rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, fs_path); rc = FSUSER_OpenDirectory(&fd, sdmcArchive, fs_path);
if(rc == 0) if(rc == 0)
{ {
dir->fd = fd; dir->fd = fd;
@ -1002,7 +1002,6 @@ sdmc_statvfs(struct _reent *r,
u8 writable = 0; u8 writable = 0;
rc = FSUSER_GetSdmcArchiveResource(NULL, rc = FSUSER_GetSdmcArchiveResource(NULL,
NULL,
&clusterSize, &clusterSize,
&numClusters, &numClusters,
&freeClusters); &freeClusters);
@ -1021,7 +1020,7 @@ sdmc_statvfs(struct _reent *r,
buf->f_flag = ST_NOSUID; buf->f_flag = ST_NOSUID;
buf->f_namemax = 0; //??? how to get buf->f_namemax = 0; //??? how to get
rc = FSUSER_IsSdmcWritable(NULL, &writable); rc = FSUSER_IsSdmcWritable(&writable);
if(rc != 0 || !writable) if(rc != 0 || !writable)
buf->f_flag |= ST_RDONLY; buf->f_flag |= ST_RDONLY;
@ -1147,7 +1146,7 @@ sdmc_rmdir(struct _reent *r,
if(fs_path.data == NULL) if(fs_path.data == NULL)
return -1; return -1;
rc = FSUSER_DeleteDirectory(NULL, sdmcArchive, fs_path); rc = FSUSER_DeleteDirectory(sdmcArchive, fs_path);
if(rc == 0) if(rc == 0)
return 0; return 0;

View File

@ -48,7 +48,7 @@ fsInit(void)
if (fsInitialised) return ret; if (fsInitialised) return ret;
if((ret=srvGetServiceHandle(&fsuHandle, "fs:USER"))!=0)return ret; if((ret=srvGetServiceHandle(&fsuHandle, "fs:USER"))!=0)return ret;
if(__get_handle_from_list("fs:USER")==0)ret=FSUSER_Initialize(NULL); if(__get_handle_from_list("fs:USER")==0)ret=FSUSER_Initialize();
fsInitialised = true; fsInitialised = true;
@ -73,16 +73,12 @@ fsExit(void)
* *
* @returns Handle * @returns Handle
*/ */
Handle *fsGetSessionHandle() Handle *fsGetSessionHandle(void)
{ {
return &fsuHandle; return &fsuHandle;
} }
/*! Initialize FS service handle /*! Initialize FS service handle
*
* If @a handle is NULL, this initializes @ref fsuHandle.
*
* @param[in] handle fs:USER service handle
* *
* @returns error * @returns error
* *
@ -103,15 +99,11 @@ Handle *fsGetSessionHandle()
* 1 | Result code * 1 | Result code
*/ */
Result Result
FSUSER_Initialize(Handle* handle) FSUSER_Initialize(void)
{ {
if(!handle) // don't run command if we got handle from the list
{ if(fsuHandle != 0 && __get_handle_from_list("fs:USER")!=0)
// don't run command if we got handle from the list return 0;
handle = &fsuHandle;
if(fsuHandle != 0 && __get_handle_from_list("fs:USER")!=0)
return 0;
}
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
@ -119,7 +111,7 @@ FSUSER_Initialize(Handle* handle)
cmdbuf[1] = 0x20; cmdbuf[1] = 0x20;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
return cmdbuf[1]; return cmdbuf[1];
@ -127,7 +119,6 @@ FSUSER_Initialize(Handle* handle)
/*! Open a file /*! Open a file
* *
* @param[in] handle fs:USER handle
* @param[out] out Output handle * @param[out] out Output handle
* @param[in] archive Open archive * @param[in] archive Open archive
* @param[in] fileLowPath File path * @param[in] fileLowPath File path
@ -168,16 +159,12 @@ FSUSER_Initialize(Handle* handle)
* 3 | File handle * 3 | File handle
*/ */
Result Result
FSUSER_OpenFile(Handle *handle, FSUSER_OpenFile(Handle *out,
Handle *out,
FS_archive archive, FS_archive archive,
FS_path fileLowPath, FS_path fileLowPath,
u32 openFlags, u32 openFlags,
u32 attributes) u32 attributes)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x080201C2; cmdbuf[0] = 0x080201C2;
@ -192,7 +179,7 @@ FSUSER_OpenFile(Handle *handle,
cmdbuf[9] = (u32)fileLowPath.data; cmdbuf[9] = (u32)fileLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
if(out) if(out)
@ -203,7 +190,6 @@ FSUSER_OpenFile(Handle *handle,
/*! Open a file /*! Open a file
* *
* @param[in] handle fs:USER handle
* @param[out] out Output handle * @param[out] out Output handle
* @param[in] archive Open archive * @param[in] archive Open archive
* @param[in] fileLowPath File path * @param[in] fileLowPath File path
@ -247,16 +233,12 @@ FSUSER_OpenFile(Handle *handle,
* 3 | File handle * 3 | File handle
*/ */
Result Result
FSUSER_OpenFileDirectly(Handle *handle, FSUSER_OpenFileDirectly(Handle *out,
Handle *out,
FS_archive archive, FS_archive archive,
FS_path fileLowPath, FS_path fileLowPath,
u32 openFlags, u32 openFlags,
u32 attributes) u32 attributes)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[ 0] = 0x08030204; cmdbuf[ 0] = 0x08030204;
@ -274,7 +256,7 @@ FSUSER_OpenFileDirectly(Handle *handle,
cmdbuf[12] = (u32)fileLowPath.data; cmdbuf[12] = (u32)fileLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
if(out) if(out)
@ -285,7 +267,6 @@ FSUSER_OpenFileDirectly(Handle *handle,
/*! Delete a file /*! Delete a file
* *
* @param[in] handle fs:USER handle
* @param[in] archive Open archive * @param[in] archive Open archive
* @param[in] fileLowPath File path * @param[in] fileLowPath File path
* *
@ -314,13 +295,9 @@ FSUSER_OpenFileDirectly(Handle *handle,
* 1 | Result code * 1 | Result code
*/ */
Result Result
FSUSER_DeleteFile(Handle *handle, FSUSER_DeleteFile(FS_archive archive,
FS_archive archive,
FS_path fileLowPath) FS_path fileLowPath)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08040142; cmdbuf[0] = 0x08040142;
@ -333,7 +310,7 @@ FSUSER_DeleteFile(Handle *handle,
cmdbuf[7] = (u32)fileLowPath.data; cmdbuf[7] = (u32)fileLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
return cmdbuf[1]; return cmdbuf[1];
@ -341,7 +318,6 @@ FSUSER_DeleteFile(Handle *handle,
/*! Renames or moves a file. /*! Renames or moves a file.
* *
* @param[in] handle fs:USER handle
* @param[in] srcArchive Open archive of source * @param[in] srcArchive Open archive of source
* @param[in] srcFileLowPath File path to source * @param[in] srcFileLowPath File path to source
* @param[in] destArchive Open archive of destination * @param[in] destArchive Open archive of destination
@ -378,15 +354,11 @@ FSUSER_DeleteFile(Handle *handle,
* 1 | Result code * 1 | Result code
*/ */
Result Result
FSUSER_RenameFile(Handle *handle, FSUSER_RenameFile(FS_archive srcArchive,
FS_archive srcArchive,
FS_path srcFileLowPath, FS_path srcFileLowPath,
FS_archive destArchive, FS_archive destArchive,
FS_path destFileLowPath) FS_path destFileLowPath)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08050244; cmdbuf[0] = 0x08050244;
@ -405,7 +377,7 @@ FSUSER_RenameFile(Handle *handle,
cmdbuf[13] = (u32)destFileLowPath.data; cmdbuf[13] = (u32)destFileLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
return cmdbuf[1]; return cmdbuf[1];
@ -413,7 +385,6 @@ FSUSER_RenameFile(Handle *handle,
/*! Delete a directory /*! Delete a directory
* *
* @param[in] handle fs:USER handle
* @param[in] archive Open archive * @param[in] archive Open archive
* @param[in] dirLowPath Directory path * @param[in] dirLowPath Directory path
* *
@ -442,13 +413,9 @@ FSUSER_RenameFile(Handle *handle,
* 1 | Result code * 1 | Result code
*/ */
Result Result
FSUSER_DeleteDirectory(Handle *handle, FSUSER_DeleteDirectory(FS_archive archive,
FS_archive archive,
FS_path dirLowPath) FS_path dirLowPath)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08060142; cmdbuf[0] = 0x08060142;
@ -461,7 +428,7 @@ FSUSER_DeleteDirectory(Handle *handle,
cmdbuf[7] = (u32)dirLowPath.data; cmdbuf[7] = (u32)dirLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
return cmdbuf[1]; return cmdbuf[1];
@ -469,7 +436,6 @@ FSUSER_DeleteDirectory(Handle *handle,
/*! Delete a directory and all sub directories/files recursively /*! Delete a directory and all sub directories/files recursively
* *
* @param[in] handle fs:USER handle
* @param[in] archive Open archive * @param[in] archive Open archive
* @param[in] dirLowPath Directory path * @param[in] dirLowPath Directory path
* *
@ -498,13 +464,9 @@ FSUSER_DeleteDirectory(Handle *handle,
* 1 | Result code * 1 | Result code
*/ */
Result Result
FSUSER_DeleteDirectoryRecursively(Handle *handle, FSUSER_DeleteDirectoryRecursively(FS_archive archive,
FS_archive archive,
FS_path dirLowPath) FS_path dirLowPath)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08070142; cmdbuf[0] = 0x08070142;
@ -517,7 +479,7 @@ FSUSER_DeleteDirectoryRecursively(Handle *handle,
cmdbuf[7] = (u32)dirLowPath.data; cmdbuf[7] = (u32)dirLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
return cmdbuf[1]; return cmdbuf[1];
@ -525,7 +487,6 @@ FSUSER_DeleteDirectoryRecursively(Handle *handle,
/*! Create a File /*! Create a File
* *
* @param[in] handle fs:USER handle
* @param[in] archive Open archive * @param[in] archive Open archive
* @param[in] fileLowPath File path * @param[in] fileLowPath File path
* @param[in] fileSize Size of new file in bytes * @param[in] fileSize Size of new file in bytes
@ -558,14 +519,10 @@ FSUSER_DeleteDirectoryRecursively(Handle *handle,
* 1 | Result code * 1 | Result code
*/ */
Result Result
FSUSER_CreateFile(Handle* handle, FSUSER_CreateFile(FS_archive archive,
FS_archive archive, FS_path fileLowPath,
FS_path fileLowPath,
u32 fileSize) u32 fileSize)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08080202; cmdbuf[0] = 0x08080202;
@ -581,7 +538,7 @@ FSUSER_CreateFile(Handle* handle,
cmdbuf[10] = (u32)fileLowPath.data; cmdbuf[10] = (u32)fileLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
return cmdbuf[1]; return cmdbuf[1];
@ -589,7 +546,6 @@ FSUSER_CreateFile(Handle* handle,
/*! Create a directory /*! Create a directory
* *
* @param[in] handle fs:USER handle
* @param[in] archive Open archive * @param[in] archive Open archive
* @param[in] dirLowPath Directory path to create * @param[in] dirLowPath Directory path to create
* *
@ -619,13 +575,9 @@ FSUSER_CreateFile(Handle* handle,
* 1 | Result code * 1 | Result code
*/ */
Result Result
FSUSER_CreateDirectory(Handle *handle, FSUSER_CreateDirectory(FS_archive archive,
FS_archive archive,
FS_path dirLowPath) FS_path dirLowPath)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08090182; cmdbuf[0] = 0x08090182;
@ -639,7 +591,7 @@ FSUSER_CreateDirectory(Handle *handle,
cmdbuf[8] = (u32)dirLowPath.data; cmdbuf[8] = (u32)dirLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
return cmdbuf[1]; return cmdbuf[1];
@ -647,7 +599,6 @@ FSUSER_CreateDirectory(Handle *handle,
/*! Renames or moves a directory. /*! Renames or moves a directory.
* *
* @param[in] handle fs:USER handle
* @param[in] srcArchive Open archive of source * @param[in] srcArchive Open archive of source
* @param[in] srcDirLowPath Dir path to source * @param[in] srcDirLowPath Dir path to source
* @param[in] destArchive Open archive of destination * @param[in] destArchive Open archive of destination
@ -684,15 +635,11 @@ FSUSER_CreateDirectory(Handle *handle,
* 1 | Result code * 1 | Result code
*/ */
Result Result
FSUSER_RenameDirectory(Handle *handle, FSUSER_RenameDirectory(FS_archive srcArchive,
FS_archive srcArchive,
FS_path srcDirLowPath, FS_path srcDirLowPath,
FS_archive destArchive, FS_archive destArchive,
FS_path destDirLowPath) FS_path destDirLowPath)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x080A0244; cmdbuf[0] = 0x080A0244;
@ -711,7 +658,7 @@ FSUSER_RenameDirectory(Handle *handle,
cmdbuf[13] = (u32)destDirLowPath.data; cmdbuf[13] = (u32)destDirLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
return cmdbuf[1]; return cmdbuf[1];
@ -719,7 +666,6 @@ FSUSER_RenameDirectory(Handle *handle,
/*! Open a directory /*! Open a directory
* *
* @param[in] handle fs:USER handle
* @param[out] out Output handle * @param[out] out Output handle
* @param[in] archive Open archive * @param[in] archive Open archive
* @param[in] dirLowPath Directory path * @param[in] dirLowPath Directory path
@ -749,14 +695,10 @@ FSUSER_RenameDirectory(Handle *handle,
* 2 | Directory handle * 2 | Directory handle
*/ */
Result Result
FSUSER_OpenDirectory(Handle *handle, FSUSER_OpenDirectory(Handle *out,
Handle *out,
FS_archive archive, FS_archive archive,
FS_path dirLowPath) FS_path dirLowPath)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x080B0102; cmdbuf[0] = 0x080B0102;
@ -768,7 +710,7 @@ FSUSER_OpenDirectory(Handle *handle,
cmdbuf[6] = (u32)dirLowPath.data; cmdbuf[6] = (u32)dirLowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
if(out) if(out)
@ -779,7 +721,6 @@ FSUSER_OpenDirectory(Handle *handle,
/*! Open an archive /*! Open an archive
* *
* @param[in] handle fs:USER handle
* @param[in,out] archive Archive to open * @param[in,out] archive Archive to open
* *
* @returns error * @returns error
@ -807,15 +748,11 @@ FSUSER_OpenDirectory(Handle *handle,
* 3 | archive->handleHigh * 3 | archive->handleHigh
*/ */
Result Result
FSUSER_OpenArchive(Handle *handle, FSUSER_OpenArchive(FS_archive *archive)
FS_archive *archive)
{ {
if(!archive) if(!archive)
return -2; return -2;
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x080C00C2; cmdbuf[0] = 0x080C00C2;
@ -826,7 +763,7 @@ FSUSER_OpenArchive(Handle *handle,
cmdbuf[5] = (u32)archive->lowPath.data; cmdbuf[5] = (u32)archive->lowPath.data;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
archive->handleLow = cmdbuf[2]; archive->handleLow = cmdbuf[2];
@ -838,7 +775,6 @@ FSUSER_OpenArchive(Handle *handle,
/*! Close an open archive /*! Close an open archive
* *
* @param[in] handle fs:USER handle
* @param[in,out] archive Archive to close * @param[in,out] archive Archive to close
* *
* @returns error * @returns error
@ -861,15 +797,11 @@ FSUSER_OpenArchive(Handle *handle,
* 1 | Result code * 1 | Result code
*/ */
Result Result
FSUSER_CloseArchive(Handle *handle, FSUSER_CloseArchive(FS_archive *archive)
FS_archive *archive)
{ {
if(!archive) if(!archive)
return -2; return -2;
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x080E0080; cmdbuf[0] = 0x080E0080;
@ -877,7 +809,7 @@ FSUSER_CloseArchive(Handle *handle,
cmdbuf[2] = archive->handleHigh; cmdbuf[2] = archive->handleHigh;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
return cmdbuf[1]; return cmdbuf[1];
@ -885,7 +817,6 @@ FSUSER_CloseArchive(Handle *handle,
/*! Get SD FAT information /*! Get SD FAT information
* *
* @param[in] handle fs:USER handle
* @param[out] sectorSize Sector size (bytes) * @param[out] sectorSize Sector size (bytes)
* @param[out] clusterSize Cluster size (bytes) * @param[out] clusterSize Cluster size (bytes)
* @param[out] numClusters Total number of clusters * @param[out] numClusters Total number of clusters
@ -913,21 +844,17 @@ FSUSER_CloseArchive(Handle *handle,
* 5 | Free space (clusters) * 5 | Free space (clusters)
*/ */
Result Result
FSUSER_GetSdmcArchiveResource(Handle *handle, FSUSER_GetSdmcArchiveResource(u32 *sectorSize,
u32 *sectorSize,
u32 *clusterSize, u32 *clusterSize,
u32 *numClusters, u32 *numClusters,
u32 *freeClusters) u32 *freeClusters)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08140000; cmdbuf[0] = 0x08140000;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
if(sectorSize) if(sectorSize)
@ -947,7 +874,6 @@ FSUSER_GetSdmcArchiveResource(Handle *handle,
/*! Get NAND information /*! Get NAND information
* *
* @param[in] handle fs:USER handle
* @param[out] sectorSize Sector size (bytes) * @param[out] sectorSize Sector size (bytes)
* @param[out] clusterSize Cluster size (bytes) * @param[out] clusterSize Cluster size (bytes)
* @param[out] numClusters Total number of clusters * @param[out] numClusters Total number of clusters
@ -975,21 +901,17 @@ FSUSER_GetSdmcArchiveResource(Handle *handle,
* 5 | Free space (clusters) * 5 | Free space (clusters)
*/ */
Result Result
FSUSER_GetNandArchiveResource(Handle *handle, FSUSER_GetNandArchiveResource(u32 *sectorSize,
u32 *sectorSize,
u32 *clusterSize, u32 *clusterSize,
u32 *numClusters, u32 *numClusters,
u32 *freeClusters) u32 *freeClusters)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08150000; cmdbuf[0] = 0x08150000;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
if(sectorSize) if(sectorSize)
@ -1009,7 +931,6 @@ FSUSER_GetNandArchiveResource(Handle *handle,
/*! Check if SD card is detected /*! Check if SD card is detected
* *
* @param[in] handle fs:USER handle
* @param[out] detected Output detected state * @param[out] detected Output detected state
* *
* @returns error * @returns error
@ -1031,18 +952,14 @@ FSUSER_GetNandArchiveResource(Handle *handle,
* 2 | Whether SD is detected * 2 | Whether SD is detected
*/ */
Result Result
FSUSER_IsSdmcDetected(Handle *handle, FSUSER_IsSdmcDetected(u8 *detected)
u8 *detected)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08170000; cmdbuf[0] = 0x08170000;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
if(detected) if(detected)
@ -1053,7 +970,6 @@ FSUSER_IsSdmcDetected(Handle *handle,
/*! Check if SD card is writable /*! Check if SD card is writable
* *
* @param[in] handle fs:USER handle
* @param[out] writable Output writable state * @param[out] writable Output writable state
* *
* @returns error * @returns error
@ -1075,18 +991,14 @@ FSUSER_IsSdmcDetected(Handle *handle,
* 2 | Whether SD is writable * 2 | Whether SD is writable
*/ */
Result Result
FSUSER_IsSdmcWritable(Handle *handle, FSUSER_IsSdmcWritable(u8 *writable)
u8 *writable)
{ {
if(!handle)
handle = &fsuHandle;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = 0x08180000; cmdbuf[0] = 0x08180000;
Result ret = 0; Result ret = 0;
if((ret = svcSendSyncRequest(*handle))) if((ret = svcSendSyncRequest(fsuHandle)))
return ret; return ret;
if(writable) if(writable)