mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-09 17:49:23 +02:00
Added a comment in fs_dev.h. Adjusted fs.h formatting, etc. Added support for mounting SaveData.
This commit is contained in:
parent
a405bc4827
commit
0c5efe5f9c
@ -25,6 +25,7 @@ Result fsdevInit(void);
|
|||||||
Result fsdevExit(void);
|
Result fsdevExit(void);
|
||||||
|
|
||||||
/// Mounts the input fs with the specified device name. fsdev will handle closing the fs when required, including when fsdevMountDevice() fails.
|
/// Mounts the input fs with the specified device name. fsdev will handle closing the fs when required, including when fsdevMountDevice() fails.
|
||||||
|
/// Returns -1 when any errors occur.
|
||||||
int fsdevMountDevice(const char *name, FsFileSystem fs);
|
int fsdevMountDevice(const char *name, FsFileSystem fs);
|
||||||
|
|
||||||
/// Unmounts the specified device.
|
/// Unmounts the specified device.
|
||||||
|
@ -4,6 +4,15 @@
|
|||||||
|
|
||||||
#define FS_MAX_PATH 0x301
|
#define FS_MAX_PATH 0x301
|
||||||
|
|
||||||
|
/// For use with fsMountSaveData().
|
||||||
|
#define FS_MOUNTSAVEDATA_INVAL_DEFAULT 0x1
|
||||||
|
|
||||||
|
/// For use with FsSave.
|
||||||
|
#define FS_SAVEDATA_CURRENT_TITLEID 0
|
||||||
|
|
||||||
|
/// For use with FsSave.
|
||||||
|
#define FS_SAVEDATA_USERID_COMMONSAVE 0
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Handle h;
|
Handle h;
|
||||||
} FsFileSystem;
|
} FsFileSystem;
|
||||||
@ -23,13 +32,25 @@ typedef struct {
|
|||||||
/// Directory entry.
|
/// Directory entry.
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char name[FS_MAX_PATH]; ///< Entry name.
|
char name[FS_MAX_PATH]; ///< Entry name.
|
||||||
u8 pad[3];
|
u8 pad[3];
|
||||||
s8 type; ///< See FsEntryType.
|
s8 type; ///< See FsEntryType.
|
||||||
u8 pad2[3]; ///< ?
|
u8 pad2[3]; ///< ?
|
||||||
u64 fileSize; ///< File size.
|
u64 fileSize; ///< File size.
|
||||||
} FsDirectoryEntry;
|
} FsDirectoryEntry;
|
||||||
|
|
||||||
|
/// Save Struct
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u64 titleID; ///< titleID of the savedata to access when accessing other titles' savedata via SaveData, otherwise FS_SAVEDATA_CURRENT_TITLEID.
|
||||||
|
u128 userID; ///< userID of the user-specific savedata to access, otherwise FS_SAVEDATA_USERID_COMMONSAVE. See account.h.
|
||||||
|
u64 saveID; ///< saveID, 0 for SaveData.
|
||||||
|
u64 ContentStorageId; ///< ContentStorageId? See FsContentStorageId.
|
||||||
|
u64 unk_x28; ///< 0 for SystemSaveData/SaveData.
|
||||||
|
u64 unk_x30; ///< 0 for SystemSaveData/SaveData.
|
||||||
|
u64 unk_x38; ///< 0 for SystemSaveData/SaveData.
|
||||||
|
} PACKED FsSave;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ENTRYTYPE_DIR = 0,
|
ENTRYTYPE_DIR = 0,
|
||||||
ENTRYTYPE_FILE = 1
|
ENTRYTYPE_FILE = 1
|
||||||
@ -37,26 +58,40 @@ typedef enum {
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
FS_OPEN_READ = BIT(0), ///< Open for reading.
|
FS_OPEN_READ = BIT(0), ///< Open for reading.
|
||||||
FS_OPEN_WRITE = BIT(1), ///< Open for writing.
|
FS_OPEN_WRITE = BIT(1), ///< Open for writing.
|
||||||
FS_OPEN_APPEND = BIT(2), ///< Append file.
|
FS_OPEN_APPEND = BIT(2), ///< Append file.
|
||||||
} FsFileFlags;
|
} FsFileFlags;
|
||||||
|
|
||||||
/// For use with fsFsOpenDirectory.
|
/// For use with fsFsOpenDirectory.
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
FS_DIROPEN_DIRECTORY = BIT(0), ///< Enable reading directory entries.
|
FS_DIROPEN_DIRECTORY = BIT(0), ///< Enable reading directory entries.
|
||||||
FS_DIROPEN_FILE = BIT(1), ///< Enable reading file entries.
|
FS_DIROPEN_FILE = BIT(1), ///< Enable reading file entries.
|
||||||
} FsDirectoryFlags;
|
} FsDirectoryFlags;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
FS_CONTENTSTORAGEID_NandSystem = 0,
|
||||||
|
FS_CONTENTSTORAGEID_NandUser = 1,
|
||||||
|
FS_CONTENTSTORAGEID_SdCard = 2,
|
||||||
|
} FsContentStorageId;
|
||||||
|
|
||||||
Result fsInitialize();
|
Result fsInitialize();
|
||||||
void fsExit(void);
|
void fsExit(void);
|
||||||
|
|
||||||
Handle fsGetServiceSession(void);
|
Handle fsGetServiceSession(void);
|
||||||
|
|
||||||
Result fsMountSdcard(FsFileSystem* out);
|
Result fsMountSdcard(FsFileSystem* out);
|
||||||
|
Result fsMountSaveData(FsFileSystem* out, u8 inval, FsSave *save);
|
||||||
// todo: Rest of commands here
|
// todo: Rest of commands here
|
||||||
|
|
||||||
|
/// FsFileSystem can be mounted with fs_dev for use with stdio, see fs_dev.h.
|
||||||
|
|
||||||
|
/// Wrapper(s) for fsMountSaveData.
|
||||||
|
/// See FsSave for titleID and userID.
|
||||||
|
Result fsMount_SaveData(FsFileSystem* out, u64 titleID, u128 userID);
|
||||||
|
|
||||||
// IFileSystem
|
// IFileSystem
|
||||||
Result fsFsCreateFile(FsFileSystem* fs, const char* path, size_t size, int flags);
|
Result fsFsCreateFile(FsFileSystem* fs, const char* path, size_t size, int flags);
|
||||||
Result fsFsDeleteFile(FsFileSystem* fs, const char* path);
|
Result fsFsDeleteFile(FsFileSystem* fs, const char* path);
|
||||||
|
@ -308,6 +308,7 @@ static int _fsdevMountDevice(const char *name, FsFileSystem fs, fsdev_fsdevice *
|
|||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsdevMountDevice(const char *name, FsFileSystem fs)
|
int fsdevMountDevice(const char *name, FsFileSystem fs)
|
||||||
{
|
{
|
||||||
return _fsdevMountDevice(name, fs, NULL);
|
return _fsdevMountDevice(name, fs, NULL);
|
||||||
|
@ -87,6 +87,57 @@ Result fsMountSdcard(FsFileSystem* out) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result fsMountSaveData(FsFileSystem* out, u8 inval, FsSave *save) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
u64 inval;//Actually u8.
|
||||||
|
FsSave save;
|
||||||
|
} PACKED *raw;
|
||||||
|
|
||||||
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 51;
|
||||||
|
raw->inval = (u64)inval;
|
||||||
|
memcpy(&raw->save, save, sizeof(FsSave));
|
||||||
|
|
||||||
|
Result rc = ipcDispatch(g_fsHandle);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcCommandResponse r;
|
||||||
|
ipcParseResponse(&r);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
out->h = r.Handles[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrapper(s) for fsMountSaveData.
|
||||||
|
Result fsMount_SaveData(FsFileSystem* out, u64 titleID, u128 userID) {
|
||||||
|
FsSave save;
|
||||||
|
|
||||||
|
memset(&save, 0, sizeof(save));
|
||||||
|
save.titleID = titleID;
|
||||||
|
save.userID = userID;
|
||||||
|
save.ContentStorageId = FS_CONTENTSTORAGEID_NandUser;
|
||||||
|
|
||||||
|
return fsMountSaveData(out, FS_MOUNTSAVEDATA_INVAL_DEFAULT, &save);
|
||||||
|
}
|
||||||
|
|
||||||
// IFileSystem impl
|
// IFileSystem impl
|
||||||
Result fsFsCreateFile(FsFileSystem* fs, const char* path, size_t size, int flags) {
|
Result fsFsCreateFile(FsFileSystem* fs, const char* path, size_t size, int flags) {
|
||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
|
Loading…
Reference in New Issue
Block a user