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_attributes_read 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. If */
47 /* found, the attribute read request is valid and the directory entry */
48 /* will be read in order to pickup the directory's attributes. */
49 /* Otherwise, if the directory is not found, the appropriate error */
50 /* code is returned to the caller. */
51 /* */
52 /* INPUT */
53 /* */
54 /* media_ptr Media control block pointer */
55 /* directory_name Directory name pointer */
56 /* attributes_ptr Return attributes pointer */
57 /* */
58 /* OUTPUT */
59 /* */
60 /* return status */
61 /* */
62 /* CALLS */
63 /* */
64 /* _fx_directory_search Search for the file name in */
65 /* the directory structure */
66 /* */
67 /* CALLED BY */
68 /* */
69 /* Application Code */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
76 /* 09-30-2020 William E. Lamie Modified comment(s), */
77 /* resulting in version 6.1 */
78 /* */
79 /**************************************************************************/
_fx_directory_attributes_read(FX_MEDIA * media_ptr,CHAR * directory_name,UINT * attributes_ptr)80 UINT _fx_directory_attributes_read(FX_MEDIA *media_ptr, CHAR *directory_name, UINT *attributes_ptr)
81 {
82
83 UINT status;
84 FX_DIR_ENTRY dir_entry;
85
86 #ifdef TX_ENABLE_EVENT_TRACE
87 TX_TRACE_BUFFER_ENTRY *trace_event;
88 ULONG trace_timestamp;
89 #endif
90
91
92 #ifndef FX_MEDIA_STATISTICS_DISABLE
93
94 /* Increment the number of times this service has been called. */
95 media_ptr -> fx_media_directory_attributes_reads++;
96 #endif
97
98 /* Setup pointer to media name buffer. */
99 dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
100
101 /* Clear the short name string. */
102 dir_entry.fx_dir_entry_short_name[0] = 0;
103
104 /* Check the media to make sure it is open. */
105 if (media_ptr -> fx_media_id != FX_MEDIA_ID)
106 {
107
108 /* Return the media not opened error. */
109 return(FX_MEDIA_NOT_OPEN);
110 }
111
112 /* If trace is enabled, insert this event into the trace buffer. */
113 FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_ATTRIBUTES_READ, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, &trace_event, &trace_timestamp)
114
115 /* Protect against other threads accessing the media. */
116 FX_PROTECT
117
118 /* Search the system for the supplied file name. */
119 status = _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
120
121 /* Determine if the search was successful. */
122 if (status != FX_SUCCESS)
123 {
124
125 /* Release media protection. */
126 FX_UNPROTECT
127
128 /* Return the error code. */
129 return(status);
130 }
131
132 /* Check to make sure the found entry is a file. */
133 if ((dir_entry.fx_dir_entry_attributes & (UCHAR)(FX_DIRECTORY)) == 0)
134 {
135
136 /* Release media protection. */
137 FX_UNPROTECT
138
139 /* Return the not a file error code. */
140 return(FX_NOT_DIRECTORY);
141 }
142
143 /* Place the current attributes into the destination. */
144 *attributes_ptr = (UINT)dir_entry.fx_dir_entry_attributes;
145
146 /* Update the trace event with the attributes read. */
147 FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_DIRECTORY_ATTRIBUTES_READ, 0, 0, dir_entry.fx_dir_entry_attributes, 0)
148
149 /* Release media protection. */
150 FX_UNPROTECT
151
152 /* File attribute read is complete, return successful status. */
153 return(FX_SUCCESS);
154 }
155
156