FS : started implementing FS services (thanks yellows8)
This commit is contained in:
parent
f2d577a3e9
commit
dd36d587eb
40
libctru/include/ctr/FS.h
Normal file
40
libctru/include/ctr/FS.h
Normal file
@ -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
|
90
libctru/source/FS.c
Normal file
90
libctru/source/FS.c
Normal file
@ -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];
|
||||
}
|
Loading…
Reference in New Issue
Block a user