From a8e5cb01f994b11cfaa0f3951f9b7c88326a94b0 Mon Sep 17 00:00:00 2001 From: smea Date: Tue, 28 Jan 2014 18:36:54 +0100 Subject: [PATCH] FS : FSUSER_OpenDirectory, FSUSER_OpenFile, FSDIR_Read --- libctru/include/ctr/FS.h | 8 ++++++ libctru/source/FS.c | 62 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/libctru/include/ctr/FS.h b/libctru/include/ctr/FS.h index 2d5da64..e84e830 100644 --- a/libctru/include/ctr/FS.h +++ b/libctru/include/ctr/FS.h @@ -31,9 +31,15 @@ typedef struct{ Handle handleLow, handleHigh; }FS_archive; +static inline FS_path FS_makePath(FS_pathType type, char* path) +{ + 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 FSFILE_Close(Handle handle); @@ -41,4 +47,6 @@ Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, u32 *buffer, u32 s Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, u32 *buffer, u32 size, u32 flushFlags); Result FSFILE_GetSize(Handle handle, u64 *size); +Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, u16 *buffer); + #endif diff --git a/libctru/source/FS.c b/libctru/source/FS.c index 7a91c22..1fcdd1f 100644 --- a/libctru/source/FS.c +++ b/libctru/source/FS.c @@ -17,7 +17,30 @@ Result FSUSER_Initialize(Handle handle) return cmdbuf[1]; } -Result FSUSER_OpenFileDirectly(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) +Result FSUSER_OpenFile(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) //archive needs to have been opened +{ + u32* cmdbuf=getThreadCommandBuffer(); + + cmdbuf[0]=0x080201C2; + cmdbuf[1]=0; + cmdbuf[2]=archive.handleLow; + cmdbuf[3]=archive.handleHigh; + cmdbuf[4]=fileLowPath.type; + cmdbuf[5]=fileLowPath.size; + cmdbuf[6]=openflags; + cmdbuf[7]=attributes; + cmdbuf[8]=(fileLowPath.size<<14)|2; + cmdbuf[9]=(u32)fileLowPath.data; + + Result ret=0; + if((ret=svc_sendSyncRequest(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 { u32* cmdbuf=getThreadCommandBuffer(); @@ -64,6 +87,26 @@ Result FSUSER_OpenArchive(Handle handle, FS_archive* archive) return cmdbuf[1]; } +Result FSUSER_OpenDirectory(Handle handle, Handle* out, FS_archive archive, FS_path dirLowPath) +{ + u32* cmdbuf=getThreadCommandBuffer(); + + cmdbuf[0]=0x080B0102; + cmdbuf[1]=archive.handleLow; + cmdbuf[2]=archive.handleHigh; + cmdbuf[3]=dirLowPath.type; + cmdbuf[4]=dirLowPath.size; + cmdbuf[5]=(dirLowPath.size<<14)|0x2; + cmdbuf[6]=(u32)dirLowPath.data; + + Result ret=0; + if((ret=svc_sendSyncRequest(handle)))return ret; + + if(out)*out=cmdbuf[3]; + + return cmdbuf[1]; +} + Result FSFILE_Close(Handle handle) { u32* cmdbuf=getThreadCommandBuffer(); @@ -130,3 +173,20 @@ Result FSFILE_GetSize(Handle handle, u64 *size) return cmdbuf[1]; } + +Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, u16 *buffer) +{ + u32 *cmdbuf=getThreadCommandBuffer(); + + cmdbuf[0]=0x08010042; + cmdbuf[1]=entrycount; + cmdbuf[2]=((entrycount*0x228)<<4)|0xC; + cmdbuf[3]=(u32)buffer; + + Result ret=0; + if((ret=svc_sendSyncRequest(handle)))return ret; + + if(entriesRead)*entriesRead=cmdbuf[2]; + + return cmdbuf[1]; +}