mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-10-30 07:21:46 +00:00
596928a3c6
Takes care of retrieving a FsStorage object for any FAT eMMC BIS partition, mounting it via FatFs and creating a virtual devoptab device that can be used to carry out FS operations. All write operations have been stubbed, disabled or ifdef'd out of the code. Other changes include: * cert: update code to use the new BIS storage interface. * defines: remove BIS_SYSTEM_PARTITION_MOUNT_NAME macro. * devoptab: slightly improve macros. * devoptab: add operation table for FatFs devices. * devoptab: add rodev_fstat(). * devoptab: add devoptabMountFatFsDevice(). * fatfs: update diskio code to use the new BIS storage interface. * fatfs: update configuration. * save: update code to use regular C I/O calls instead of FatFs calls. * tik: update code to use the new BIS storage interface. * utils: remove eMMC BIS System partition (un)mount code.
107 lines
4.5 KiB
C
107 lines
4.5 KiB
C
/*
|
|
* nxdt_devoptab.h
|
|
*
|
|
* Copyright (c) 2020-2024, DarkMatterCore <pabloacurielz@gmail.com>.
|
|
*
|
|
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
|
|
*
|
|
* nxdumptool is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* nxdumptool is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifndef __NXDT_DEVOPTAB_H__
|
|
#define __NXDT_DEVOPTAB_H__
|
|
|
|
#include "../pfs.h"
|
|
#include "../hfs.h"
|
|
#include "../romfs.h"
|
|
#include "../fatfs/ff.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define DEVOPTAB_MOUNT_NAME_LENGTH 32 // Including NULL terminator.
|
|
|
|
#define DEVOPTAB_INIT_ERROR_STATE r->_errno = 0
|
|
#define DEVOPTAB_DECL_DEV_CTX DevoptabDeviceContext *dev_ctx = (DevoptabDeviceContext*)r->deviceData
|
|
#define DEVOPTAB_DECL_FS_CTX(type) type *fs_ctx = (type*)dev_ctx->fs_ctx
|
|
#define DEVOPTAB_DECL_FILE_STATE(type) type *file = (type*)fd
|
|
#define DEVOPTAB_DECL_DIR_STATE(type) type *dir = (type*)dirState->dirStruct
|
|
|
|
#define DEVOPTAB_SET_ERROR(x) r->_errno = (x)
|
|
#define DEVOPTAB_IS_ERROR_SET (r->_errno != 0)
|
|
|
|
#define DEVOPTAB_EXIT goto end
|
|
#define DEVOPTAB_SET_ERROR_AND_EXIT(x) \
|
|
do { \
|
|
DEVOPTAB_SET_ERROR(x); \
|
|
DEVOPTAB_EXIT; \
|
|
} while(0)
|
|
|
|
#define DEVOPTAB_RETURN_INT(x) return (DEVOPTAB_IS_ERROR_SET ? -1 : (x))
|
|
#define DEVOPTAB_RETURN_PTR(x) return (DEVOPTAB_IS_ERROR_SET ? NULL : (x))
|
|
#define DEVOPTAB_RETURN_BOOL return (DEVOPTAB_IS_ERROR_SET ? false : true)
|
|
#define DEVOPTAB_RETURN_UNSUPPORTED_OP r->_errno = ENOSYS; \
|
|
return -1
|
|
|
|
#define DEVOPTAB_INIT_VARS devoptabControlMutex(true); \
|
|
DEVOPTAB_INIT_ERROR_STATE; \
|
|
DEVOPTAB_DECL_DEV_CTX; \
|
|
if (!dev_ctx->initialized) DEVOPTAB_SET_ERROR_AND_EXIT(ENODEV)
|
|
|
|
#define DEVOPTAB_INIT_FILE_VARS(type) DEVOPTAB_INIT_VARS; \
|
|
DEVOPTAB_DECL_FILE_STATE(type)
|
|
|
|
#define DEVOPTAB_INIT_DIR_VARS(type) DEVOPTAB_INIT_VARS; \
|
|
if (!dirState) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL); \
|
|
DEVOPTAB_DECL_DIR_STATE(type)
|
|
|
|
#define DEVOPTAB_DEINIT_VARS devoptabControlMutex(false)
|
|
|
|
typedef struct {
|
|
bool initialized; ///< Device initialization flag.
|
|
char name[DEVOPTAB_MOUNT_NAME_LENGTH]; ///< Mount name string, without a trailing colon (:).
|
|
time_t mount_time; ///< Mount time.
|
|
devoptab_t device; ///< Devoptab virtual device interface. Provides a way to use libcstd I/O calls on the mounted filesystem.
|
|
void *fs_ctx; ///< Pointer to actual type-specific filesystem context (PartitionFileSystemContext, HashFileSystemContext, RomFileSystemContext, FATFS).
|
|
} DevoptabDeviceContext;
|
|
|
|
/// Mounts a virtual Partition FS device using the provided Partition FS context and a mount name.
|
|
bool devoptabMountPartitionFileSystemDevice(PartitionFileSystemContext *pfs_ctx, const char *name);
|
|
|
|
/// Mounts a virtual Hash FS device using the provided Hash FS context and a mount name.
|
|
bool devoptabMountHashFileSystemDevice(HashFileSystemContext *hfs_ctx, const char *name);
|
|
|
|
/// Mounts a virtual RomFS device using the provided RomFS context and a mount name.
|
|
bool devoptabMountRomFileSystemDevice(RomFileSystemContext *romfs_ctx, const char *name);
|
|
|
|
/// Mounts a virtual FatFs device using the provided FATFS object and a mount name.
|
|
bool devoptabMountFatFsDevice(FATFS *fatfs, const char *name);
|
|
|
|
/// Unmounts a previously mounted virtual device.
|
|
void devoptabUnmountDevice(const char *name);
|
|
|
|
/// Unmounts all previously mounted virtual devices.
|
|
void devoptabUnmountAllDevices(void);
|
|
|
|
/// (Un)locks the devoptab mutex. Used by filesystem-specific devoptab interfaces.
|
|
void devoptabControlMutex(bool lock);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __NXDT_DEVOPTAB_H__ */
|