Add archive STDIO device driver (#443)

This commit is contained in:
Chris Feger 2020-04-15 18:06:36 -04:00 committed by GitHub
parent 87734ae8d9
commit 175dd62a90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 565 additions and 363 deletions

View File

@ -86,7 +86,7 @@ extern "C" {
#include <3ds/applets/miiselector.h>
#include <3ds/sdmc.h>
#include <3ds/archive.h>
#include <3ds/romfs.h>
#include <3ds/font.h>
#include <3ds/mii.h>
@ -142,4 +142,3 @@ extern "C" {
* @example threads/thread-basic/source/main.c
* @example time/rtc/source/main.c
*/

View File

@ -0,0 +1,43 @@
/**
* @file archive.h
* @brief FS_Archive driver
*/
#pragma once
#include <sys/types.h>
#include <3ds/types.h>
#include <3ds/services/fs.h>
#define ARCHIVE_DIRITER_MAGIC 0x68637261 /* "arch" */
/*! Open directory struct */
typedef struct
{
u32 magic; /*! "arch" */
Handle fd; /*! CTRU handle */
ssize_t index; /*! Current entry index */
size_t size; /*! Current batch size */
FS_DirectoryEntry entry_data[32]; /*! Temporary storage for reading entries */
} archive_dir_t;
/// Mounts the SD
Result archiveMountSdmc(void);
/// Mounts and opens an archive as deviceName
/// Returns either an archive open error code, or -1 for generic failure
Result archiveMount(FS_ArchiveID archiveID, FS_Path archivePath, const char *deviceName);
/// Uses FSUSER_ControlArchive with control action ARCHIVE_ACTION_COMMIT_SAVE_DATA on the opened archive. Not done automatically at unmount.
/// Returns -1 if the specified device is not found
Result archiveCommitSaveData(const char *deviceName);
/// Unmounts the specified device, closing its archive in the process
/// Returns -1 if the specified device was not found
Result archiveUnmount(const char *deviceName);
/// Unmounts all devices and cleans up any resources used by the driver
Result archiveUnmountAll(void);
/// Get a file's mtime
Result archive_getmtime(const char *name, u64 *mtime);

View File

@ -1,34 +0,0 @@
/**
* @file sdmc.h
* @brief SDMC driver.
*/
#pragma once
#include <sys/types.h>
#include <3ds/types.h>
#include <3ds/services/fs.h>
#define SDMC_DIRITER_MAGIC 0x73646D63 /* "sdmc" */
/*! Open directory struct */
typedef struct
{
u32 magic; /*! "sdmc" */
Handle fd; /*! CTRU handle */
ssize_t index; /*! Current entry index */
size_t size; /*! Current batch size */
FS_DirectoryEntry entry_data[32]; /*! Temporary storage for reading entries */
} sdmc_dir_t;
/// Initializes the SDMC driver.
Result sdmcInit(void);
/// Enable/disable copy in sdmc_write
void sdmcWriteSafe(bool enable);
/// Exits the SDMC driver.
Result sdmcExit(void);
/// Get a file's mtime
Result sdmc_getmtime(const char *name, u64 *mtime);

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,14 @@
#include <3ds/types.h>
#include <3ds/srv.h>
#include <3ds/gfx.h>
#include <3ds/sdmc.h>
#include <3ds/archive.h>
#include <3ds/services/apt.h>
#include <3ds/services/fs.h>
#include <3ds/services/hid.h>
void __attribute__((weak)) __appExit(void) {
// Exit services
sdmcExit();
archiveUnmountAll();
fsExit();
hidExit();

View File

@ -1,7 +1,7 @@
#include <3ds/types.h>
#include <3ds/srv.h>
#include <3ds/gfx.h>
#include <3ds/sdmc.h>
#include <3ds/archive.h>
#include <3ds/services/apt.h>
#include <3ds/services/fs.h>
#include <3ds/services/hid.h>
@ -13,5 +13,5 @@ void __attribute__((weak)) __appInit(void) {
hidInit();
fsInit();
sdmcInit();
archiveMountSdmc();
}