1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** FileX Component */
16 /** */
17 /** Directory */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define FX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "fx_api.h"
28 #include "fx_system.h"
29 #include "fx_directory.h"
30 #include "fx_file.h"
31 #include "fx_utility.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _fx_directory_name_test PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* William E. Lamie, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function first attempts to find the specified directory name. */
47 /* If found, the attributes are checked to see if the entry is a */
48 /* directory. If not, the appropriate error code is returned to the */
49 /* caller. */
50 /* */
51 /* INPUT */
52 /* */
53 /* media_ptr Media control block pointer */
54 /* directory_name Directory name pointer */
55 /* */
56 /* OUTPUT */
57 /* */
58 /* return status */
59 /* */
60 /* CALLS */
61 /* */
62 /* _fx_directory_search Search for the file name in */
63 /* the directory structure */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application Code */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
74 /* 09-30-2020 William E. Lamie Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* */
77 /**************************************************************************/
_fx_directory_name_test(FX_MEDIA * media_ptr,CHAR * directory_name)78 UINT _fx_directory_name_test(FX_MEDIA *media_ptr, CHAR *directory_name)
79 {
80
81 UINT status;
82 FX_DIR_ENTRY dir_entry;
83
84
85 #ifndef FX_MEDIA_STATISTICS_DISABLE
86
87 /* Increment the number of times this service has been called. */
88 media_ptr -> fx_media_directory_name_tests++;
89 #endif
90
91 /* Setup pointer to media name buffer. */
92 dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
93
94 /* Clear the short name string. */
95 dir_entry.fx_dir_entry_short_name[0] = 0;
96
97 /* Check the media to make sure it is open. */
98 if (media_ptr -> fx_media_id != FX_MEDIA_ID)
99 {
100
101 /* Return the media not opened error. */
102 return(FX_MEDIA_NOT_OPEN);
103 }
104
105 /* If trace is enabled, insert this event into the trace buffer. */
106 FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_NAME_TEST, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
107
108 /* Protect against other threads accessing the media. */
109 FX_PROTECT
110
111 /* Search the system for the supplied directory name. */
112 status = _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
113
114 /* Determine if the search was successful. */
115 if (status != FX_SUCCESS)
116 {
117
118 /* Release media protection. */
119 FX_UNPROTECT
120
121 /* Return the error code. */
122 return(status);
123 }
124
125 /* Check to see if the entry is a directory. */
126 if (!(dir_entry.fx_dir_entry_attributes & (UCHAR)FX_DIRECTORY))
127 {
128
129 /* Release media protection. */
130 FX_UNPROTECT
131
132 /* Return the not a directory error code. */
133 return(FX_NOT_DIRECTORY);
134 }
135
136 /* Release media protection. */
137 FX_UNPROTECT
138
139 /* Directory name test is complete, return successful status. */
140 return(FX_SUCCESS);
141 }
142
143