1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief MSDOS Evaluation Routines |
---|
5 | * @ingroup libfs |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
10 | * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru> |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <sys/types.h> |
---|
22 | #include <sys/stat.h> |
---|
23 | #include <fcntl.h> |
---|
24 | #include <unistd.h> |
---|
25 | #include <errno.h> |
---|
26 | #include <stdlib.h> |
---|
27 | |
---|
28 | #include <rtems/libio_.h> |
---|
29 | |
---|
30 | #include "fat.h" |
---|
31 | #include "fat_fat_operations.h" |
---|
32 | #include "fat_file.h" |
---|
33 | |
---|
34 | #include "msdos.h" |
---|
35 | |
---|
36 | /* msdos_set_handlers -- |
---|
37 | * Set handlers for the node with specified type(i.e. handlers for file |
---|
38 | * or directory). |
---|
39 | * |
---|
40 | * PARAMETERS: |
---|
41 | * loc - node description |
---|
42 | * |
---|
43 | * RETURNS: |
---|
44 | * None |
---|
45 | */ |
---|
46 | static void |
---|
47 | msdos_set_handlers(rtems_filesystem_location_info_t *loc) |
---|
48 | { |
---|
49 | msdos_fs_info_t *fs_info = loc->mt_entry->fs_info; |
---|
50 | fat_file_fd_t *fat_fd = loc->node_access; |
---|
51 | |
---|
52 | if (fat_fd->fat_file_type == FAT_DIRECTORY) |
---|
53 | loc->handlers = fs_info->directory_handlers; |
---|
54 | else |
---|
55 | loc->handlers = fs_info->file_handlers; |
---|
56 | } |
---|
57 | |
---|
58 | static bool msdos_is_directory( |
---|
59 | rtems_filesystem_eval_path_context_t *ctx, |
---|
60 | void *arg |
---|
61 | ) |
---|
62 | { |
---|
63 | rtems_filesystem_location_info_t *currentloc = |
---|
64 | rtems_filesystem_eval_path_get_currentloc( ctx ); |
---|
65 | fat_file_fd_t *fat_fd = currentloc->node_access; |
---|
66 | |
---|
67 | return fat_fd->fat_file_type == MSDOS_DIRECTORY; |
---|
68 | } |
---|
69 | |
---|
70 | static rtems_filesystem_eval_path_generic_status msdos_eval_token( |
---|
71 | rtems_filesystem_eval_path_context_t *ctx, |
---|
72 | void *arg, |
---|
73 | const char *token, |
---|
74 | size_t tokenlen |
---|
75 | ) |
---|
76 | { |
---|
77 | rtems_filesystem_eval_path_generic_status status = |
---|
78 | RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE; |
---|
79 | |
---|
80 | if (rtems_filesystem_is_current_directory(token, tokenlen)) { |
---|
81 | rtems_filesystem_eval_path_clear_token(ctx); |
---|
82 | status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE; |
---|
83 | } else { |
---|
84 | rtems_filesystem_location_info_t *currentloc = |
---|
85 | rtems_filesystem_eval_path_get_currentloc(ctx); |
---|
86 | int rc = msdos_find_name(currentloc, token, tokenlen); |
---|
87 | |
---|
88 | if (rc == RC_OK) { |
---|
89 | rtems_filesystem_eval_path_clear_token(ctx); |
---|
90 | msdos_set_handlers(currentloc); |
---|
91 | if (rtems_filesystem_eval_path_has_path(ctx)) { |
---|
92 | status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE; |
---|
93 | } |
---|
94 | } else if (rc == MSDOS_NAME_NOT_FOUND_ERR) { |
---|
95 | status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY; |
---|
96 | } else { |
---|
97 | rtems_filesystem_eval_path_error(ctx, 0); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | return status; |
---|
102 | } |
---|
103 | |
---|
104 | static const rtems_filesystem_eval_path_generic_config msdos_eval_config = { |
---|
105 | .is_directory = msdos_is_directory, |
---|
106 | .eval_token = msdos_eval_token |
---|
107 | }; |
---|
108 | |
---|
109 | void msdos_eval_path(rtems_filesystem_eval_path_context_t *ctx) |
---|
110 | { |
---|
111 | rtems_filesystem_eval_path_generic(ctx, NULL, &msdos_eval_config); |
---|
112 | } |
---|