mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-22 18:26:39 +00:00
Custom devoptab wrappers (part 3).
Add some minor tweaks to the devoptab macros.
This commit is contained in:
parent
c392a9f126
commit
e6caff3b17
3 changed files with 36 additions and 66 deletions
|
@ -56,19 +56,17 @@ do { \
|
|||
#define DEVOPTAB_RETURN_UNSUPPORTED_OP r->_errno = ENOSYS; \
|
||||
return -1;
|
||||
|
||||
#define DEVOPTAB_INIT_VARS(type, decl) devoptabControlMutex(true); \
|
||||
#define DEVOPTAB_INIT_VARS(type) devoptabControlMutex(true); \
|
||||
DEVOPTAB_DECL_ERROR_STATE; \
|
||||
decl
|
||||
DEVOPTAB_DECL_DEV_CTX; \
|
||||
if (!dev_ctx->initialized) DEVOPTAB_SET_ERROR_AND_EXIT(ENODEV);
|
||||
|
||||
#define DEVOPTAB_INIT_VARS_WITH_FILE_STATE(fs_type, file_type) DEVOPTAB_INIT_VARS(fs_type,); \
|
||||
#define DEVOPTAB_INIT_FILE_VARS(fs_type, file_type) DEVOPTAB_INIT_VARS(fs_type); \
|
||||
DEVOPTAB_DECL_FILE_STATE(file_type)
|
||||
|
||||
#define DEVOPTAB_INIT_VARS_WITH_DIR_STATE(fs_type, dir_type) DEVOPTAB_INIT_VARS(fs_type,); \
|
||||
#define DEVOPTAB_INIT_DIR_VARS(fs_type, dir_type) DEVOPTAB_INIT_VARS(fs_type); \
|
||||
DEVOPTAB_DECL_DIR_STATE(dir_type)
|
||||
|
||||
#define DEVOPTAB_INIT_FS_ACCESS(type) DEVOPTAB_DECL_DEV_CTX; \
|
||||
DEVOPTAB_DECL_FS_CTX(type)
|
||||
|
||||
#define DEVOPTAB_DEINIT_VARS devoptabControlMutex(false)
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
|
||||
/* Helper macros. */
|
||||
|
||||
#define HFS_DEV_INIT_VARS DEVOPTAB_INIT_VARS(HashFileSystemContext,)
|
||||
#define HFS_DEV_INIT_FILE_VARS DEVOPTAB_INIT_VARS_WITH_FILE_STATE(HashFileSystemContext, HashFileSystemFileState)
|
||||
#define HFS_DEV_INIT_DIR_VARS DEVOPTAB_INIT_VARS_WITH_DIR_STATE(HashFileSystemContext, HashFileSystemDirectoryState)
|
||||
#define HFS_DEV_INIT_FS_ACCESS DEVOPTAB_INIT_FS_ACCESS(HashFileSystemContext)
|
||||
#define HFS_DEV_INIT_VARS DEVOPTAB_INIT_VARS(HashFileSystemContext)
|
||||
#define HFS_DEV_INIT_FILE_VARS DEVOPTAB_INIT_FILE_VARS(HashFileSystemContext, HashFileSystemFileState)
|
||||
#define HFS_DEV_INIT_DIR_VARS DEVOPTAB_INIT_DIR_VARS(HashFileSystemContext, HashFileSystemDirectoryState)
|
||||
#define HFS_DEV_INIT_FS_ACCESS DEVOPTAB_DECL_FS_CTX(HashFileSystemContext)
|
||||
|
||||
/* Type definitions. */
|
||||
|
||||
|
@ -137,10 +137,7 @@ static int hfsdev_close(struct _reent *r, void *fd)
|
|||
/* Sanity check. */
|
||||
if (!file) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Closing \"%s:/%s\".", dev_ctx->name, file->name);
|
||||
#endif
|
||||
|
||||
/* Reset file descriptor. */
|
||||
memset(file, 0, sizeof(HashFileSystemFileState));
|
||||
|
@ -204,10 +201,7 @@ static off_t hfsdev_seek(struct _reent *r, void *fd, off_t pos, int dir)
|
|||
/* Don't allow positive seeks beyond the end of file. */
|
||||
if (offset > (off_t)file->hfs_entry->size) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Seeking to offset 0x%lX from \"%s:/%s\".", offset, dev_ctx->name, file->name);
|
||||
#endif
|
||||
|
||||
/* Adjust offset. */
|
||||
file->offset = (u64)offset;
|
||||
|
@ -220,7 +214,6 @@ end:
|
|||
static int hfsdev_fstat(struct _reent *r, void *fd, struct stat *st)
|
||||
{
|
||||
HFS_DEV_INIT_FILE_VARS;
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
|
||||
/* Sanity check. */
|
||||
if (!file || !st) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
|
||||
|
@ -272,10 +265,7 @@ static DIR_ITER *hfsdev_diropen(struct _reent *r, DIR_ITER *dirState, const char
|
|||
if (!(path = hfsdev_get_truncated_path(r, path))) DEVOPTAB_EXIT;
|
||||
if (*path) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Opening directory \"%s:/\".", dev_ctx->name);
|
||||
#endif
|
||||
|
||||
/* Reset directory state. */
|
||||
memset(dir, 0, sizeof(HashFileSystemDirectoryState));
|
||||
|
@ -292,14 +282,12 @@ static int hfsdev_dirreset(struct _reent *r, DIR_ITER *dirState)
|
|||
{
|
||||
HFS_DEV_INIT_DIR_VARS;
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Resetting directory state for \"%s:/\".", dev_ctx->name);
|
||||
#endif
|
||||
|
||||
/* Reset directory state. */
|
||||
dir->index = 0;
|
||||
|
||||
end:
|
||||
DEVOPTAB_DEINIT_VARS;
|
||||
DEVOPTAB_RETURN_INT(0);
|
||||
}
|
||||
|
@ -341,14 +329,12 @@ static int hfsdev_dirclose(struct _reent *r, DIR_ITER *dirState)
|
|||
{
|
||||
HFS_DEV_INIT_DIR_VARS;
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Closing directory \"%s:/\".", dev_ctx->name);
|
||||
#endif
|
||||
|
||||
/* Reset directory state. */
|
||||
memset(dir, 0, sizeof(HashFileSystemDirectoryState));
|
||||
|
||||
end:
|
||||
DEVOPTAB_DEINIT_VARS;
|
||||
DEVOPTAB_RETURN_INT(0);
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
|
||||
/* Helper macros. */
|
||||
|
||||
#define PFS_DEV_INIT_VARS DEVOPTAB_INIT_VARS(PartitionFileSystemContext,)
|
||||
#define PFS_DEV_INIT_FILE_VARS DEVOPTAB_INIT_VARS_WITH_FILE_STATE(PartitionFileSystemContext, PartitionFileSystemFileState)
|
||||
#define PFS_DEV_INIT_DIR_VARS DEVOPTAB_INIT_VARS_WITH_DIR_STATE(PartitionFileSystemContext, PartitionFileSystemDirectoryState)
|
||||
#define PFS_DEV_INIT_FS_ACCESS DEVOPTAB_INIT_FS_ACCESS(PartitionFileSystemContext)
|
||||
#define PFS_DEV_INIT_VARS DEVOPTAB_INIT_VARS(PartitionFileSystemContext)
|
||||
#define PFS_DEV_INIT_FILE_VARS DEVOPTAB_INIT_FILE_VARS(PartitionFileSystemContext, PartitionFileSystemFileState)
|
||||
#define PFS_DEV_INIT_DIR_VARS DEVOPTAB_INIT_DIR_VARS(PartitionFileSystemContext, PartitionFileSystemDirectoryState)
|
||||
#define PFS_DEV_INIT_FS_ACCESS DEVOPTAB_DECL_FS_CTX(PartitionFileSystemContext)
|
||||
|
||||
/* Type definitions. */
|
||||
|
||||
|
@ -137,10 +137,7 @@ static int pfsdev_close(struct _reent *r, void *fd)
|
|||
/* Sanity check. */
|
||||
if (!file) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Closing \"%s:/%s\".", dev_ctx->name, file->name);
|
||||
#endif
|
||||
|
||||
/* Reset file descriptor. */
|
||||
memset(file, 0, sizeof(PartitionFileSystemFileState));
|
||||
|
@ -204,10 +201,7 @@ static off_t pfsdev_seek(struct _reent *r, void *fd, off_t pos, int dir)
|
|||
/* Don't allow positive seeks beyond the end of file. */
|
||||
if (offset > (off_t)file->pfs_entry->size) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Seeking to offset 0x%lX from \"%s:/%s\".", offset, dev_ctx->name, file->name);
|
||||
#endif
|
||||
|
||||
/* Adjust offset. */
|
||||
file->offset = (u64)offset;
|
||||
|
@ -220,7 +214,6 @@ end:
|
|||
static int pfsdev_fstat(struct _reent *r, void *fd, struct stat *st)
|
||||
{
|
||||
PFS_DEV_INIT_FILE_VARS;
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
|
||||
/* Sanity check. */
|
||||
if (!file || !st) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
|
||||
|
@ -272,10 +265,7 @@ static DIR_ITER *pfsdev_diropen(struct _reent *r, DIR_ITER *dirState, const char
|
|||
if (!(path = pfsdev_get_truncated_path(r, path))) DEVOPTAB_EXIT;
|
||||
if (*path) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Opening directory \"%s:/\".", dev_ctx->name);
|
||||
#endif
|
||||
|
||||
/* Reset directory state. */
|
||||
memset(dir, 0, sizeof(PartitionFileSystemDirectoryState));
|
||||
|
@ -292,14 +282,12 @@ static int pfsdev_dirreset(struct _reent *r, DIR_ITER *dirState)
|
|||
{
|
||||
PFS_DEV_INIT_DIR_VARS;
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Resetting directory state for \"%s:/\".", dev_ctx->name);
|
||||
#endif
|
||||
|
||||
/* Reset directory state. */
|
||||
dir->index = 0;
|
||||
|
||||
end:
|
||||
DEVOPTAB_DEINIT_VARS;
|
||||
DEVOPTAB_RETURN_INT(0);
|
||||
}
|
||||
|
@ -341,14 +329,12 @@ static int pfsdev_dirclose(struct _reent *r, DIR_ITER *dirState)
|
|||
{
|
||||
PFS_DEV_INIT_DIR_VARS;
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
DEVOPTAB_DECL_DEV_CTX;
|
||||
LOG_MSG_DEBUG("Closing directory \"%s:/\".", dev_ctx->name);
|
||||
#endif
|
||||
|
||||
/* Reset directory state. */
|
||||
memset(dir, 0, sizeof(PartitionFileSystemDirectoryState));
|
||||
|
||||
end:
|
||||
DEVOPTAB_DEINIT_VARS;
|
||||
DEVOPTAB_RETURN_INT(0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue