1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-22 10:16:39 +00:00

poc: add file browser for NCA FS sections.

Takes advantage of the recently implemented devoptab interfaces. Supports individual file dumping and multiple file/dir dumping via highlighting. May possibly need some additional testing. The code could potentially be improved, but I'll look into it at a later time -- I just want to release this now.

Other changes include:

* devoptab: comment out log messages.

* utils: add utilsGetDirectorySize() function.
This commit is contained in:
Pablo Curiel 2023-12-26 01:25:29 +01:00
parent 7a0268eeb0
commit c585e8f9d3
6 changed files with 1182 additions and 89 deletions

File diff suppressed because it is too large Load diff

View file

@ -157,6 +157,10 @@ bool utilsCreateConcatenationFile(const char *path);
/// If 'create_last_element' is true, the last element from the provided path will be created as well.
void utilsCreateDirectoryTree(const char *path, bool create_last_element);
/// Calculates the size of a directory by recursively traversing all of its child entries.
/// The provided path must be absolute and it must include the virtual device name it belongs to (e.g. "sdmc:/path/to/dir").
bool utilsGetDirectorySize(const char *path, u64 *out_size);
/// Recursively deletes the directory located at the provided path and all of its contents.
/// The provided path must be absolute and it must include the virtual device name it belongs to (e.g. "sdmc:/path/to/dir").
bool utilsDeleteDirectoryRecursively(const char *path);

View file

@ -206,7 +206,7 @@ bool utilsInitializeResources(void)
/* Load keyset. */
if (!keysLoadKeyset())
{
LOG_MSG_ERROR("Failed to load keyset!\nPlease update your keys file with Lockpick_RCM.\nYou can get an updated build at:" DISCORD_SERVER_URL);
LOG_MSG_ERROR("Failed to load keyset!\nPlease update your keys file with Lockpick_RCM.\nYou can get an updated build at: " DISCORD_SERVER_URL);
break;
}
@ -813,12 +813,84 @@ void utilsCreateDirectoryTree(const char *path, bool create_last_element)
free(tmp);
}
bool utilsGetDirectorySize(const char *path, u64 *out_size)
{
u64 total_size = 0;
char *name_end = NULL, *entry_path = NULL;
DIR *dir = NULL;
struct dirent *entry = NULL;
struct stat st = {0};
bool success = false;
/* Sanity checks. */
if (!path || !*path || !(name_end = strchr(path, ':')) || *(name_end + 1) != '/' || !*(name_end + 2) || !out_size)
{
LOG_MSG_ERROR("Invalid parameters!");
return false;
}
if (!(dir = opendir(path)))
{
LOG_MSG_ERROR("Failed to open directory \"%s\"! (%d).", path, errno);
goto end;
}
if (!(entry_path = calloc(1, FS_MAX_PATH)))
{
LOG_MSG_ERROR("Failed to allocate memory for path buffer!");
goto end;
}
/* Read directory entries. */
while((entry = readdir(dir)))
{
/* Skip current directory and parent directory entries. */
if (!strcmp(".", entry->d_name) || !strcmp("..", entry->d_name)) continue;
/* Generate path to the current entry. */
snprintf(entry_path, FS_MAX_PATH, "%s/%s", path, entry->d_name);
if (entry->d_type == DT_DIR)
{
/* Get directory size. */
u64 dir_size = 0;
if (!utilsGetDirectorySize(entry_path, &dir_size)) goto end;
/* Update size. */
total_size += dir_size;
} else {
/* Get file properties. */
if (stat(entry_path, &st) != 0)
{
LOG_MSG_ERROR("Failed to stat file \"%s\"! (%d).", entry_path, errno);
goto end;
}
/* Update size. */
total_size += st.st_size;
}
}
/* Update output pointer. */
*out_size = total_size;
/* Update return value. */
success = true;
end:
if (entry_path) free(entry_path);
if (dir) closedir(dir);
return success;
}
bool utilsDeleteDirectoryRecursively(const char *path)
{
char *name_end = NULL, *entry_path = NULL;
DIR *dir = NULL;
struct dirent *entry = NULL;
bool success = true;
bool success = false;
/* Sanity checks. */
if (!path || !*path || !(name_end = strchr(path, ':')) || *(name_end + 1) != '/' || !*(name_end + 2))
@ -830,14 +902,12 @@ bool utilsDeleteDirectoryRecursively(const char *path)
if (!(dir = opendir(path)))
{
LOG_MSG_ERROR("Failed to open directory \"%s\"! (%d).", path, errno);
success = false;
goto end;
}
if (!(entry_path = calloc(1, FS_MAX_PATH)))
{
LOG_MSG_ERROR("Failed to allocate memory for path buffer!");
success = false;
goto end;
}
@ -855,11 +925,7 @@ bool utilsDeleteDirectoryRecursively(const char *path)
if (entry->d_type == DT_DIR)
{
/* Delete directory contents. */
if (!utilsDeleteDirectoryRecursively(entry_path))
{
success = false;
break;
}
if (!utilsDeleteDirectoryRecursively(entry_path)) goto end;
/* Delete directory. */
status = rmdir(entry_path);
@ -870,20 +936,17 @@ bool utilsDeleteDirectoryRecursively(const char *path)
if (status != 0)
{
LOG_MSG_ERROR("Failed to delete \"%s\"! (%s, %d).", entry_path, entry->d_type == DT_DIR ? "dir" : "file", errno);
success = false;
break;
LOG_MSG_ERROR("Failed to delete %s \"%s\"! (%d).", entry->d_type == DT_DIR ? "directory" : "file", entry_path, errno);
goto end;
}
}
if (success)
{
closedir(dir);
dir = NULL;
/* Close topmost directory so we can delete it. */
closedir(dir);
dir = NULL;
success = (rmdir(path) == 0);
if (!success) LOG_MSG_ERROR("Failed to delete topmost directory \"%s\"! (%d).", path, errno);
}
success = (rmdir(path) == 0);
if (!success) LOG_MSG_ERROR("Failed to delete topmost directory \"%s\"! (%d).", path, errno);
end:
if (entry_path) free(entry_path);

View file

@ -119,7 +119,7 @@ static int hfsdev_open(struct _reent *r, void *fd, const char *path, int flags,
/* Get truncated path. */
if (!(path = hfsdev_get_truncated_path(r, path))) DEVOPTAB_EXIT;
LOG_MSG_DEBUG("Opening \"%s:/%s\" with flags 0x%X.", dev_ctx->name, path, flags);
//LOG_MSG_DEBUG("Opening \"%s:/%s\" with flags 0x%X.", dev_ctx->name, path, flags);
/* Reset file descriptor. */
memset(file, 0, sizeof(HashFileSystemFileState));
@ -140,7 +140,7 @@ static int hfsdev_close(struct _reent *r, void *fd)
/* Sanity check. */
if (!file) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Closing \"%s:/%s\".", dev_ctx->name, file->name);
//LOG_MSG_DEBUG("Closing \"%s:/%s\".", dev_ctx->name, file->name);
/* Reset file descriptor. */
memset(file, 0, sizeof(HashFileSystemFileState));
@ -158,7 +158,7 @@ static ssize_t hfsdev_read(struct _reent *r, void *fd, char *ptr, size_t len)
/* Sanity check. */
if (!file || !ptr || !len) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Reading 0x%lX byte(s) at offset 0x%lX from \"%s:/%s\".", len, file->offset, dev_ctx->name, file->name);
//LOG_MSG_DEBUG("Reading 0x%lX byte(s) at offset 0x%lX from \"%s:/%s\".", len, file->offset, dev_ctx->name, file->name);
/* Read file data. */
if (!hfsReadEntryData(fs_ctx, file->hfs_entry, ptr, len, file->offset)) DEVOPTAB_SET_ERROR_AND_EXIT(EIO);
@ -204,7 +204,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(EOVERFLOW);
LOG_MSG_DEBUG("Seeking to offset 0x%lX from \"%s:/%s\".", offset, dev_ctx->name, file->name);
//LOG_MSG_DEBUG("Seeking to offset 0x%lX from \"%s:/%s\".", offset, dev_ctx->name, file->name);
/* Adjust offset. */
file->offset = (u64)offset;
@ -221,7 +221,7 @@ static int hfsdev_fstat(struct _reent *r, void *fd, struct stat *st)
/* Sanity check. */
if (!file || !st) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Getting file stats for \"%s:/%s\".", dev_ctx->name, file->name);
//LOG_MSG_DEBUG("Getting file stats for \"%s:/%s\".", dev_ctx->name, file->name);
/* Fill stat info. */
hfsdev_fill_stat(st, file->index, file->hfs_entry, dev_ctx->mount_time);
@ -245,7 +245,7 @@ static int hfsdev_stat(struct _reent *r, const char *file, struct stat *st)
/* Get truncated path. */
if (!(file = hfsdev_get_truncated_path(r, file))) DEVOPTAB_EXIT;
LOG_MSG_DEBUG("Getting file stats for \"%s:/%s\".", dev_ctx->name, file);
//LOG_MSG_DEBUG("Getting file stats for \"%s:/%s\".", dev_ctx->name, file);
/* Get information about the requested Hash FS entry. */
if (!hfsGetEntryIndexByName(fs_ctx, file, &index) || !(hfs_entry = hfsGetEntryByIndex(fs_ctx, index))) DEVOPTAB_SET_ERROR_AND_EXIT(ENOENT);
@ -269,7 +269,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(ENOENT);
LOG_MSG_DEBUG("Opening directory \"%s:/\".", dev_ctx->name);
//LOG_MSG_DEBUG("Opening directory \"%s:/\".", dev_ctx->name);
/* Reset directory state. */
memset(dir, 0, sizeof(HashFileSystemDirectoryState));
@ -286,7 +286,7 @@ static int hfsdev_dirreset(struct _reent *r, DIR_ITER *dirState)
{
HFS_DEV_INIT_DIR_VARS;
LOG_MSG_DEBUG("Resetting directory state for \"%s:/\".", dev_ctx->name);
//LOG_MSG_DEBUG("Resetting directory state for \"%s:/\".", dev_ctx->name);
/* Reset directory state. */
dir->state = 0;
@ -308,7 +308,7 @@ static int hfsdev_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename,
/* Sanity check. */
if (!filename || !filestat) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Getting info for next directory entry in \"%s:/\" (state %u, index %u).", dev_ctx->name, dir->state, dir->index);
//LOG_MSG_DEBUG("Getting info for next directory entry in \"%s:/\" (state %u, index %u).", dev_ctx->name, dir->state, dir->index);
if (dir->state < 2)
{
@ -352,7 +352,7 @@ static int hfsdev_dirclose(struct _reent *r, DIR_ITER *dirState)
{
HFS_DEV_INIT_DIR_VARS;
LOG_MSG_DEBUG("Closing directory \"%s:/\".", dev_ctx->name);
//LOG_MSG_DEBUG("Closing directory \"%s:/\".", dev_ctx->name);
/* Reset directory state. */
memset(dir, 0, sizeof(HashFileSystemDirectoryState));
@ -374,7 +374,7 @@ static int hfsdev_statvfs(struct _reent *r, const char *path, struct statvfs *bu
/* Sanity check. */
if (!buf) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Getting filesystem stats for \"%s:\"", dev_ctx->name);
//LOG_MSG_DEBUG("Getting filesystem stats for \"%s:\"", dev_ctx->name);
/* Get Hash FS total data size. */
if (!hfsGetTotalDataSize(fs_ctx, &ext_fs_size)) DEVOPTAB_SET_ERROR_AND_EXIT(EIO);
@ -411,7 +411,7 @@ static const char *hfsdev_get_truncated_path(struct _reent *r, const char *path)
if (!r || !path || !*path) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Input path: \"%s\".", path);
//LOG_MSG_DEBUG("Input path: \"%s\".", path);
/* Move the path pointer to the start of the actual path. */
do {
@ -445,7 +445,7 @@ static const char *hfsdev_get_truncated_path(struct _reent *r, const char *path)
if (!len && !path_sep_skipped) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
if (len >= FS_MAX_PATH) DEVOPTAB_SET_ERROR_AND_EXIT(ENAMETOOLONG);
LOG_MSG_DEBUG("Truncated path: \"%s\".", path);
//LOG_MSG_DEBUG("Truncated path: \"%s\".", path);
end:
DEVOPTAB_RETURN_PTR(path);

View file

@ -125,7 +125,7 @@ static int romfsdev_open(struct _reent *r, void *fd, const char *path, int flags
/* Get truncated path. */
if (!(path = romfsdev_get_truncated_path(r, path))) DEVOPTAB_EXIT;
LOG_MSG_DEBUG("Opening \"%s:%s\" with flags 0x%X.", dev_ctx->name, path, flags);
//LOG_MSG_DEBUG("Opening \"%s:%s\" with flags 0x%X.", dev_ctx->name, path, flags);
/* Reset file descriptor. */
memset(file, 0, sizeof(RomFileSystemFileState));
@ -145,7 +145,7 @@ static int romfsdev_close(struct _reent *r, void *fd)
/* Sanity check. */
if (!file) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Closing file \"%.*s\" from \"%s:\".", (int)file->file_entry->name_length, file->file_entry->name, dev_ctx->name);
//LOG_MSG_DEBUG("Closing file \"%.*s\" from \"%s:\".", (int)file->file_entry->name_length, file->file_entry->name, dev_ctx->name);
/* Reset file descriptor. */
memset(file, 0, sizeof(RomFileSystemFileState));
@ -163,8 +163,8 @@ static ssize_t romfsdev_read(struct _reent *r, void *fd, char *ptr, size_t len)
/* Sanity check. */
if (!file || !ptr || !len) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Reading 0x%lX byte(s) at offset 0x%lX from file \"%.*s\" in \"%s:\".", len, file->data_offset, (int)file->file_entry->name_length, file->file_entry->name, \
dev_ctx->name);
/*LOG_MSG_DEBUG("Reading 0x%lX byte(s) at offset 0x%lX from file \"%.*s\" in \"%s:\".", len, file->data_offset, (int)file->file_entry->name_length, file->file_entry->name, \
dev_ctx->name);*/
/* Read file data. */
if (!romfsReadFileEntryData(fs_ctx, file->file_entry, ptr, len, file->data_offset)) DEVOPTAB_SET_ERROR_AND_EXIT(EIO);
@ -210,7 +210,7 @@ static off_t romfsdev_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->file_entry->size) DEVOPTAB_SET_ERROR_AND_EXIT(EOVERFLOW);
LOG_MSG_DEBUG("Seeking to offset 0x%lX from file \"%.*s\" in \"%s:\".", offset, (int)file->file_entry->name_length, file->file_entry->name, dev_ctx->name);
//LOG_MSG_DEBUG("Seeking to offset 0x%lX from file \"%.*s\" in \"%s:\".", offset, (int)file->file_entry->name_length, file->file_entry->name, dev_ctx->name);
/* Adjust offset. */
file->data_offset = (u64)offset;
@ -228,7 +228,7 @@ static int romfsdev_fstat(struct _reent *r, void *fd, struct stat *st)
/* Sanity check. */
if (!file || !st) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Getting stats for file \"%.*s\" in \"%s:\".", (int)file->file_entry->name_length, file->file_entry->name, dev_ctx->name);
//LOG_MSG_DEBUG("Getting stats for file \"%.*s\" in \"%s:\".", (int)file->file_entry->name_length, file->file_entry->name, dev_ctx->name);
/* Fill stat info. */
romfsdev_fill_file_stat(st, fs_ctx, file->file_entry, dev_ctx->mount_time);
@ -251,7 +251,7 @@ static int romfsdev_stat(struct _reent *r, const char *file, struct stat *st)
/* Get truncated path. */
if (!(file = romfsdev_get_truncated_path(r, file))) DEVOPTAB_EXIT;
LOG_MSG_DEBUG("Getting file stats for \"%s:%s\".", dev_ctx->name, file);
//LOG_MSG_DEBUG("Getting file stats for \"%s:%s\".", dev_ctx->name, file);
/* Get information about the requested RomFS file entry. */
if (!(file_entry = romfsGetFileEntryByPath(fs_ctx, file))) DEVOPTAB_SET_ERROR_AND_EXIT(ENOENT);
@ -274,7 +274,7 @@ static DIR_ITER *romfsdev_diropen(struct _reent *r, DIR_ITER *dirState, const ch
/* Get truncated path. */
if (!(path = romfsdev_get_truncated_path(r, path))) DEVOPTAB_EXIT;
LOG_MSG_DEBUG("Opening directory \"%s:%s\".", dev_ctx->name, path);
//LOG_MSG_DEBUG("Opening directory \"%s:%s\".", dev_ctx->name, path);
/* Reset directory state. */
memset(dir, 0, sizeof(RomFileSystemDirectoryState));
@ -297,7 +297,7 @@ static int romfsdev_dirreset(struct _reent *r, DIR_ITER *dirState)
{
ROMFS_DEV_INIT_DIR_VARS;
LOG_MSG_DEBUG("Resetting state for directory \"%.*s\" in \"%s:\".", (int)dir->dir_entry->name_length, dir->dir_entry->name, dev_ctx->name);
//LOG_MSG_DEBUG("Resetting state for directory \"%.*s\" in \"%s:\".", (int)dir->dir_entry->name_length, dir->dir_entry->name, dev_ctx->name);
/* Reset directory state. */
dir->state = 0;
@ -317,8 +317,8 @@ static int romfsdev_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename
/* Sanity check. */
if (!filename || !filestat) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Getting info for next entry from directory \"%.*s\" in \"%s:\" (state %u, cur_dir_offset 0x%lX, cur_file_offset 0x%lX).", \
(int)dir->dir_entry->name_length, dir->dir_entry->name, dev_ctx->name, dir->state, dir->cur_dir_offset, dir->cur_file_offset);
/*LOG_MSG_DEBUG("Getting info for next entry from directory \"%.*s\" in \"%s:\" (state %u, cur_dir_offset 0x%lX, cur_file_offset 0x%lX).", \
(int)dir->dir_entry->name_length, dir->dir_entry->name, dev_ctx->name, dir->state, dir->cur_dir_offset, dir->cur_file_offset);*/
if (dir->state < 2)
{
@ -381,7 +381,7 @@ static int romfsdev_dirclose(struct _reent *r, DIR_ITER *dirState)
{
ROMFS_DEV_INIT_DIR_VARS;
LOG_MSG_DEBUG("Closing directory \"%.*s\" in \"%s:\".", (int)dir->dir_entry->name_length, dir->dir_entry->name, dev_ctx->name);
//LOG_MSG_DEBUG("Closing directory \"%.*s\" in \"%s:\".", (int)dir->dir_entry->name_length, dir->dir_entry->name, dev_ctx->name);
/* Reset directory state. */
memset(dir, 0, sizeof(RomFileSystemDirectoryState));
@ -403,7 +403,7 @@ static int romfsdev_statvfs(struct _reent *r, const char *path, struct statvfs *
/* Sanity check. */
if (!buf) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Getting filesystem stats for \"%s:\"", dev_ctx->name);
//LOG_MSG_DEBUG("Getting filesystem stats for \"%s:\"", dev_ctx->name);
/* Get RomFS total data size. */
if (!romfsGetTotalDataSize(fs_ctx, false, &ext_fs_size)) DEVOPTAB_SET_ERROR_AND_EXIT(EIO);
@ -439,7 +439,7 @@ static const char *romfsdev_get_truncated_path(struct _reent *r, const char *pat
if (!r || !path || !*path) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Input path: \"%s\".", path);
//LOG_MSG_DEBUG("Input path: \"%s\".", path);
/* Move the path pointer to the start of the actual path. */
do {
@ -468,7 +468,7 @@ static const char *romfsdev_get_truncated_path(struct _reent *r, const char *pat
len = strlen(path);
if (len >= FS_MAX_PATH) DEVOPTAB_SET_ERROR_AND_EXIT(ENAMETOOLONG);
LOG_MSG_DEBUG("Truncated path: \"%s\".", path);
//LOG_MSG_DEBUG("Truncated path: \"%s\".", path);
end:
DEVOPTAB_RETURN_PTR(path);

View file

@ -119,7 +119,7 @@ static int pfsdev_open(struct _reent *r, void *fd, const char *path, int flags,
/* Get truncated path. */
if (!(path = pfsdev_get_truncated_path(r, path))) DEVOPTAB_EXIT;
LOG_MSG_DEBUG("Opening \"%s:/%s\" with flags 0x%X.", dev_ctx->name, path, flags);
//LOG_MSG_DEBUG("Opening \"%s:/%s\" with flags 0x%X.", dev_ctx->name, path, flags);
/* Reset file descriptor. */
memset(file, 0, sizeof(PartitionFileSystemFileState));
@ -140,7 +140,7 @@ static int pfsdev_close(struct _reent *r, void *fd)
/* Sanity check. */
if (!file) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Closing \"%s:/%s\".", dev_ctx->name, file->name);
//LOG_MSG_DEBUG("Closing \"%s:/%s\".", dev_ctx->name, file->name);
/* Reset file descriptor. */
memset(file, 0, sizeof(PartitionFileSystemFileState));
@ -158,7 +158,7 @@ static ssize_t pfsdev_read(struct _reent *r, void *fd, char *ptr, size_t len)
/* Sanity check. */
if (!file || !ptr || !len) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Reading 0x%lX byte(s) at offset 0x%lX from \"%s:/%s\".", len, file->offset, dev_ctx->name, file->name);
//LOG_MSG_DEBUG("Reading 0x%lX byte(s) at offset 0x%lX from \"%s:/%s\".", len, file->offset, dev_ctx->name, file->name);
/* Read file data. */
if (!pfsReadEntryData(fs_ctx, file->pfs_entry, ptr, len, file->offset)) DEVOPTAB_SET_ERROR_AND_EXIT(EIO);
@ -204,7 +204,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(EOVERFLOW);
LOG_MSG_DEBUG("Seeking to offset 0x%lX from \"%s:/%s\".", offset, dev_ctx->name, file->name);
//LOG_MSG_DEBUG("Seeking to offset 0x%lX from \"%s:/%s\".", offset, dev_ctx->name, file->name);
/* Adjust offset. */
file->offset = (u64)offset;
@ -221,7 +221,7 @@ static int pfsdev_fstat(struct _reent *r, void *fd, struct stat *st)
/* Sanity check. */
if (!file || !st) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Getting file stats for \"%s:/%s\".", dev_ctx->name, file->name);
//LOG_MSG_DEBUG("Getting file stats for \"%s:/%s\".", dev_ctx->name, file->name);
/* Fill stat info. */
pfsdev_fill_stat(st, file->index, file->pfs_entry, dev_ctx->mount_time);
@ -245,7 +245,7 @@ static int pfsdev_stat(struct _reent *r, const char *file, struct stat *st)
/* Get truncated path. */
if (!(file = pfsdev_get_truncated_path(r, file))) DEVOPTAB_EXIT;
LOG_MSG_DEBUG("Getting file stats for \"%s:/%s\".", dev_ctx->name, file);
//LOG_MSG_DEBUG("Getting file stats for \"%s:/%s\".", dev_ctx->name, file);
/* Get information about the requested Partition FS entry. */
if (!pfsGetEntryIndexByName(fs_ctx, file, &index) || !(pfs_entry = pfsGetEntryByIndex(fs_ctx, index))) DEVOPTAB_SET_ERROR_AND_EXIT(ENOENT);
@ -269,7 +269,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(ENOENT);
LOG_MSG_DEBUG("Opening directory \"%s:/\".", dev_ctx->name);
//LOG_MSG_DEBUG("Opening directory \"%s:/\".", dev_ctx->name);
/* Reset directory state. */
memset(dir, 0, sizeof(PartitionFileSystemDirectoryState));
@ -286,7 +286,7 @@ static int pfsdev_dirreset(struct _reent *r, DIR_ITER *dirState)
{
PFS_DEV_INIT_DIR_VARS;
LOG_MSG_DEBUG("Resetting directory state for \"%s:/\".", dev_ctx->name);
//LOG_MSG_DEBUG("Resetting directory state for \"%s:/\".", dev_ctx->name);
/* Reset directory state. */
dir->state = 0;
@ -308,7 +308,7 @@ static int pfsdev_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename,
/* Sanity check. */
if (!filename || !filestat) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Getting info for next directory entry in \"%s:/\" (state %u, index %u).", dev_ctx->name, dir->state, dir->index);
//LOG_MSG_DEBUG("Getting info for next directory entry in \"%s:/\" (state %u, index %u).", dev_ctx->name, dir->state, dir->index);
if (dir->state < 2)
{
@ -352,7 +352,7 @@ static int pfsdev_dirclose(struct _reent *r, DIR_ITER *dirState)
{
PFS_DEV_INIT_DIR_VARS;
LOG_MSG_DEBUG("Closing directory \"%s:/\".", dev_ctx->name);
//LOG_MSG_DEBUG("Closing directory \"%s:/\".", dev_ctx->name);
/* Reset directory state. */
memset(dir, 0, sizeof(PartitionFileSystemDirectoryState));
@ -374,7 +374,7 @@ static int pfsdev_statvfs(struct _reent *r, const char *path, struct statvfs *bu
/* Sanity check. */
if (!buf) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Getting filesystem stats for \"%s:\"", dev_ctx->name);
//LOG_MSG_DEBUG("Getting filesystem stats for \"%s:\"", dev_ctx->name);
/* Get Partition FS total data size. */
if (!pfsGetTotalDataSize(fs_ctx, &ext_fs_size)) DEVOPTAB_SET_ERROR_AND_EXIT(EIO);
@ -411,7 +411,7 @@ static const char *pfsdev_get_truncated_path(struct _reent *r, const char *path)
if (!r || !path || !*path) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
LOG_MSG_DEBUG("Input path: \"%s\".", path);
//LOG_MSG_DEBUG("Input path: \"%s\".", path);
/* Move the path pointer to the start of the actual path. */
do {
@ -445,7 +445,7 @@ static const char *pfsdev_get_truncated_path(struct _reent *r, const char *path)
if (!len && !path_sep_skipped) DEVOPTAB_SET_ERROR_AND_EXIT(EINVAL);
if (len >= FS_MAX_PATH) DEVOPTAB_SET_ERROR_AND_EXIT(ENAMETOOLONG);
LOG_MSG_DEBUG("Truncated path: \"%s\".", path);
//LOG_MSG_DEBUG("Truncated path: \"%s\".", path);
end:
DEVOPTAB_RETURN_PTR(path);