File indexing completed on 2025-05-11 08:24:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifdef HAVE_CONFIG_H
0019 #include "config.h"
0020 #endif
0021
0022 #include <sys/types.h>
0023 #include <sys/stat.h>
0024 #include <fcntl.h>
0025 #include <unistd.h>
0026 #include <errno.h>
0027 #include <stdlib.h>
0028
0029 #include <rtems/libio_.h>
0030
0031 #include "fat.h"
0032 #include "fat_fat_operations.h"
0033 #include "fat_file.h"
0034
0035 #include "msdos.h"
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 static void
0048 msdos_set_handlers(rtems_filesystem_location_info_t *loc)
0049 {
0050 msdos_fs_info_t *fs_info = loc->mt_entry->fs_info;
0051 fat_file_fd_t *fat_fd = loc->node_access;
0052
0053 if (fat_fd->fat_file_type == FAT_DIRECTORY)
0054 loc->handlers = fs_info->directory_handlers;
0055 else
0056 loc->handlers = fs_info->file_handlers;
0057 }
0058
0059 static bool msdos_is_directory(
0060 rtems_filesystem_eval_path_context_t *ctx,
0061 void *arg
0062 )
0063 {
0064 rtems_filesystem_location_info_t *currentloc =
0065 rtems_filesystem_eval_path_get_currentloc( ctx );
0066 fat_file_fd_t *fat_fd = currentloc->node_access;
0067
0068 return fat_fd->fat_file_type == FAT_DIRECTORY;
0069 }
0070
0071 static rtems_filesystem_eval_path_generic_status msdos_eval_token(
0072 rtems_filesystem_eval_path_context_t *ctx,
0073 void *arg,
0074 const char *token,
0075 size_t tokenlen
0076 )
0077 {
0078 rtems_filesystem_eval_path_generic_status status =
0079 RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE;
0080
0081 if (rtems_filesystem_is_current_directory(token, tokenlen)) {
0082 rtems_filesystem_eval_path_clear_token(ctx);
0083 status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE;
0084 } else {
0085 rtems_filesystem_location_info_t *currentloc =
0086 rtems_filesystem_eval_path_get_currentloc(ctx);
0087 int rc = msdos_find_name(currentloc, token, tokenlen);
0088
0089 if (rc == RC_OK) {
0090 rtems_filesystem_eval_path_clear_token(ctx);
0091 msdos_set_handlers(currentloc);
0092 if (rtems_filesystem_eval_path_has_path(ctx)) {
0093 status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE;
0094 }
0095 } else if (rc == MSDOS_NAME_NOT_FOUND_ERR) {
0096 status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY;
0097 } else {
0098 rtems_filesystem_eval_path_error(ctx, 0);
0099 }
0100 }
0101
0102 return status;
0103 }
0104
0105 static const rtems_filesystem_eval_path_generic_config msdos_eval_config = {
0106 .is_directory = msdos_is_directory,
0107 .eval_token = msdos_eval_token
0108 };
0109
0110 void msdos_eval_path(rtems_filesystem_eval_path_context_t *ctx)
0111 {
0112 rtems_filesystem_eval_path_generic(ctx, NULL, &msdos_eval_config);
0113 }