]> Chaos Git - corbenik/ctrulib.git/commitdiff
FS : started implementing FS services (thanks yellows8)
authorsmea <smealum@gmail.com>
Wed, 22 Jan 2014 21:35:46 +0000 (22:35 +0100)
committersmea <smealum@gmail.com>
Wed, 22 Jan 2014 21:35:46 +0000 (22:35 +0100)
libctru/include/ctr/FS.h [new file with mode: 0644]
libctru/source/FS.c [new file with mode: 0644]

diff --git a/libctru/include/ctr/FS.h b/libctru/include/ctr/FS.h
new file mode 100644 (file)
index 0000000..1881c19
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef FS_H
+#define FS_H
+
+#define FS_OPEN_READ (1<<0)
+#define FS_OPEN_WRITE (1<<1)
+#define FS_OPEN_CREATE (1<<2)
+
+#define FS_ATTRIBUTE_READONLY (0x00000001)
+#define FS_ATTRIBUTE_ARCHIVE (0x00000100)
+#define FS_ATTRIBUTE_HIDDEN (0x00010000)
+#define FS_ATTRIBUTE_DIRECTORY (0x01000000)
+
+typedef enum{
+       PATH_INVALID = 0,       // Specifies an invalid path.
+       PATH_EMPTY = 1,         // Specifies an empty path.
+       PATH_BINARY = 2,        // Specifies a binary path, which is non-text based.
+       PATH_CHAR = 3,          // Specifies a text based path with a 8-bit byte per character.
+       PATH_WCHAR = 4,         // Specifies a text based path with a 16-bit short per character.
+}FS_pathType;
+
+typedef struct{
+       FS_pathType type;
+       u32 size;
+       u8* data;
+}FS_path;
+
+typedef struct{
+       u32 id;
+       FS_path lowPath;
+}FS_archive;
+
+
+Result FSUSER_Initialize(Handle handle);
+Result FSUSER_OpenFile(Handle handle, Handle* out, u32 archiveid, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
+
+Result FSFILE_Close(Handle handle);
+Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, u32 *buffer, u32 size);
+Result FSFILE_GetSize(Handle handle, u64 *size);
+
+#endif
diff --git a/libctru/source/FS.c b/libctru/source/FS.c
new file mode 100644 (file)
index 0000000..d5ffe65
--- /dev/null
@@ -0,0 +1,90 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctr/types.h>
+#include <ctr/FS.h>
+#include <ctr/svc.h>
+
+Result FSUSER_Initialize(Handle handle)
+{
+       u32* cmdbuf=getThreadCommandBuffer();
+       cmdbuf[0]=0x08010002; //request header code
+       cmdbuf[1]=32;
+       
+       Result ret=0;
+       if((ret=svc_sendSyncRequest(handle)))return ret;
+       
+       return cmdbuf[1];
+}
+
+Result FSUSER_OpenFile(Handle handle, Handle* out, u32 archiveid, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes)
+{
+       u32* cmdbuf=getThreadCommandBuffer();
+
+       cmdbuf[0]=0x08030204;
+       cmdbuf[1]=0;
+       cmdbuf[2]=archive.id;
+       cmdbuf[3]=archive.lowPath.type;
+       cmdbuf[4]=archive.lowPath.size;
+       cmdbuf[5]=fileLowPath.type;
+       cmdbuf[6]=fileLowPath.size;
+       cmdbuf[7]=openflags;
+       cmdbuf[8]=attributes;
+       cmdbuf[9]=(archive.lowPath.size<<14)|0x802;
+       cmdbuf[10]=(u32)archive.lowPath.data;
+       cmdbuf[11]=(fileLowPath.size<<14)|2;
+       cmdbuf[12]=(u32)fileLowPath.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();
+
+       cmdbuf[0]=0x08080000;
+
+       Result ret=0;
+       if((ret=svc_sendSyncRequest(handle)))return ret;
+
+       return cmdbuf[1];
+}
+
+Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, u32 *buffer, u32 size)
+{
+       u32 *cmdbuf=getThreadCommandBuffer();
+       cmdbuf[0]=0x080200C2;
+       cmdbuf[1]=(u32)offset;
+       cmdbuf[2]=(u32)(offset>>32);
+       cmdbuf[3]=size;
+       cmdbuf[4]=(size<<4)|12;
+       cmdbuf[5]=(u32)buffer;
+       Result ret=0;
+       if((ret=svc_sendSyncRequest(handle)))return ret;
+
+       if(bytesRead)*bytesRead=cmdbuf[2];
+
+       return cmdbuf[1];
+}
+
+Result FSFILE_GetSize(Handle handle, u64 *size)
+{
+       u32 *cmdbuf=getThreadCommandBuffer();
+       cmdbuf[0] = 0x08040000;
+       Result ret=0;
+       if((ret=svc_sendSyncRequest(handle)))return ret;
+       if(size)*size = *((u64*)&cmdbuf[2]);
+       return cmdbuf[1];
+}