return (FS_path){type, strlen(path)+1, (u8*)path};
}
-Result FSUSER_Initialize(Handle handle);
-Result FSUSER_OpenArchive(Handle handle, FS_archive* archive);
-Result FSUSER_OpenDirectory(Handle handle, 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_OpenFileDirectly(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
-Result FSUSER_CloseArchive(Handle handle, FS_archive* archive);
+Result fsInit(void);
+Result fsExit(void);
+
+Result FSUSER_Initialize(Handle* handle);
+Result FSUSER_OpenArchive(Handle* handle, FS_archive* archive);
+Result FSUSER_OpenDirectory(Handle* handle, 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_OpenFileDirectly(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
+Result FSUSER_CloseArchive(Handle* handle, FS_archive* archive);
Result FSFILE_Close(Handle handle);
Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, u32 *buffer, u32 size);
#include <string.h>
#include <3ds/types.h>
#include <3ds/FS.h>
+#include <3ds/srv.h>
#include <3ds/svc.h>
+Handle fsuHandle;
-Result FSUSER_Initialize(Handle handle)
+Result fsInit(void)
{
+ return srvGetServiceHandle(&fsuHandle, "fs:USER");
+}
+
+Result fsExit(void)
+{
+ return svcCloseHandle(fsuHandle);
+}
+
+Result FSUSER_Initialize(Handle* handle)
+{
+ if(!handle)handle=&fsuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x08010002; //request header code
cmdbuf[1]=32;
Result ret=0;
- if((ret=svcSendSyncRequest(handle)))return ret;
+ if((ret=svcSendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}
-Result FSUSER_OpenFile(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) //archive needs to have been opened
+Result FSUSER_OpenFile(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) //archive needs to have been opened
{
+ if(!handle)handle=&fsuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x080201C2;
cmdbuf[9]=(u32)fileLowPath.data;
Result ret=0;
- if((ret=svcSendSyncRequest(handle)))return ret;
+ if((ret=svcSendSyncRequest(*handle)))return ret;
if(out)*out=cmdbuf[3];
return cmdbuf[1];
}
-Result FSUSER_OpenFileDirectly(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) //no need to have archive opened
+Result FSUSER_OpenFileDirectly(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) //no need to have archive opened
{
+ if(!handle)handle=&fsuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x08030204;
cmdbuf[12]=(u32)fileLowPath.data;
Result ret=0;
- if((ret=svcSendSyncRequest(handle)))return ret;
+ if((ret=svcSendSyncRequest(*handle)))return ret;
if(out)*out=cmdbuf[3];
return cmdbuf[1];
}
-Result FSUSER_OpenArchive(Handle handle, FS_archive* archive)
+Result FSUSER_OpenArchive(Handle* handle, FS_archive* archive)
{
if(!archive)return -2;
+ if(!handle)handle=&fsuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x080C00C2;
cmdbuf[5]=(u32)archive->lowPath.data;
Result ret=0;
- if((ret=svcSendSyncRequest(handle)))return ret;
+ if((ret=svcSendSyncRequest(*handle)))return ret;
archive->handleLow=cmdbuf[2];
archive->handleHigh=cmdbuf[3];
return cmdbuf[1];
}
-Result FSUSER_OpenDirectory(Handle handle, Handle* out, FS_archive archive, FS_path dirLowPath)
+Result FSUSER_OpenDirectory(Handle* handle, Handle* out, FS_archive archive, FS_path dirLowPath)
{
+ if(!handle)handle=&fsuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x080B0102;
cmdbuf[6]=(u32)dirLowPath.data;
Result ret=0;
- if((ret=svcSendSyncRequest(handle)))return ret;
+ if((ret=svcSendSyncRequest(*handle)))return ret;
if(out)*out=cmdbuf[3];
return cmdbuf[1];
}
-Result FSUSER_CloseArchive(Handle handle, FS_archive* archive)
+Result FSUSER_CloseArchive(Handle* handle, FS_archive* archive)
{
if(!archive)return -2;
+ if(!handle)handle=&fsuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x080E0080;
cmdbuf[2]=archive->handleLow;
Result ret=0;
- if((ret=svcSendSyncRequest(handle)))return ret;
+ if((ret=svcSendSyncRequest(*handle)))return ret;
return cmdbuf[1];
}