107 lines
2.9 KiB
C
Raw Normal View History

#pragma once
#include "common.h"
2016-02-16 16:15:08 +01:00
typedef enum {
2016-03-21 16:58:35 +01:00
T_ROOT,
T_DIR,
T_FILE,
T_DOTDOT
2016-02-16 16:15:08 +01:00
} EntryType;
#define MAX_ENTRIES 1024
#define PERM_SDCARD (1<<0)
#define PERM_RAMDRIVE (1<<1)
#define PERM_EMUNAND (1<<2)
#define PERM_SYSNAND (1<<3)
#define PERM_IMAGE (1<<4)
#define PERM_MEMORY (1<<5)
#define PERM_A9LH ((1<<6) | PERM_SYSNAND)
#define PERM_BASE (PERM_SDCARD | PERM_RAMDRIVE)
#define PERM_ALL (PERM_SDCARD | PERM_RAMDRIVE | PERM_EMUNAND | PERM_SYSNAND | PERM_IMAGE | PERM_MEMORY)
2016-02-16 16:15:08 +01:00
typedef struct {
char* name; // should point to the correct portion of the path
char path[256];
2016-02-27 19:58:41 +01:00
u64 size;
EntryType type;
2016-02-27 19:58:41 +01:00
u8 marked;
2016-02-16 16:15:08 +01:00
} DirEntry;
typedef struct {
u32 n_entries;
DirEntry entry[MAX_ENTRIES];
} DirStruct;
2016-03-11 01:29:14 +01:00
bool InitSDCardFS();
2016-04-05 15:20:48 +02:00
bool InitExtFS();
void DeinitExtFS();
void DeinitSDCardFS();
2016-02-29 22:51:20 +01:00
/** Check if writing to this path is allowed **/
bool CheckWritePermissions(const char* path);
/** Set new write permissions */
bool SetWritePermissions(u32 perm, bool add_perm);
2016-02-29 22:51:20 +01:00
/** Get write permissions */
u32 GetWritePermissions();
2016-05-19 21:24:49 +02:00
/** Create / open file and write the provided data to it **/
2016-06-17 17:12:11 +02:00
bool FileSetData(const char* path, const u8* data, size_t size, size_t foffset, bool create);
2016-03-11 01:29:14 +01:00
/** Read data from file@offset **/
size_t FileGetData(const char* path, u8* data, size_t size, size_t foffset);
2016-02-26 19:43:30 +01:00
2016-04-10 15:55:39 +02:00
/** Get size of file **/
size_t FileGetSize(const char* path);
/** Get SHA-256 of file **/
bool FileGetSha256(const char* path, u8* sha256);
/** Find data in file **/
u32 FileFindData(const char* path, u8* data, u32 size, u32 offset);
2016-06-17 19:28:43 +02:00
/** Inject file into file @offset **/
bool FileInjectFile(const char* dest, const char* orig, u32 offset);
/** Recursively copy a file or directory **/
bool PathCopy(const char* destdir, const char* orig);
2016-04-29 02:21:36 +02:00
/** Recursively move a file or directory **/
bool PathMove(const char* destdir, const char* orig);
/** Recursively delete a file or directory **/
bool PathDelete(const char* path);
2016-03-14 23:38:43 +01:00
/** Rename file / folder in path to new name **/
bool PathRename(const char* path, const char* newname);
2016-03-14 23:58:25 +01:00
/** Create a new directory in cpath **/
bool DirCreate(const char* cpath, const char* dirname);
2016-02-26 19:43:30 +01:00
/** Create a screenshot of the current framebuffer **/
void CreateScreenshot();
2016-02-26 19:43:30 +01:00
/** Get directory content under a given path **/
2016-02-29 16:14:39 +01:00
void GetDirContents(DirStruct* contents, const char* path);
2016-02-27 19:58:41 +01:00
/** Gets remaining space in filesystem in bytes */
uint64_t GetFreeSpace(const char* path);
2016-02-27 19:58:41 +01:00
/** Gets total spacein filesystem in bytes */
uint64_t GetTotalSpace(const char* path);
2016-02-29 22:27:04 +01:00
2016-03-16 18:46:05 +01:00
/** Return the offset - in sectors - of the FAT partition on the drive **/
uint64_t GetPartitionOffsetSector(const char* path);
/** Helper function to get drive number from path */
int PathToNumFS(const char* path);
2016-04-05 15:20:48 +02:00
/** Check if drive is mounted */
bool IsMountedFS(const char* path);
2016-02-29 22:27:04 +01:00
/** Helper function for copying DirEntry structs */
void DirEntryCpy(DirEntry* dest, const DirEntry* orig);