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 /** File */
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_file_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 file. If found, */
47 /* the attribute read request is valid and the directory entry will be */
48 /* in order to pickup the file's attributes. Otherwise, if the file */
49 /* is not found, the appropriate error code is returned to the caller. */
50 /* */
51 /* INPUT */
52 /* */
53 /* media_ptr Media control block pointer */
54 /* file_name File name pointer */
55 /* attributes_ptr Return attributes pointer */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* return status */
60 /* */
61 /* CALLS */
62 /* */
63 /* _fx_directory_search Search for the file name in */
64 /* the directory structure */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application Code */
69 /* */
70 /* RELEASE HISTORY */
71 /* */
72 /* DATE NAME DESCRIPTION */
73 /* */
74 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
75 /* 09-30-2020 William E. Lamie Modified comment(s), */
76 /* resulting in version 6.1 */
77 /* */
78 /**************************************************************************/
_fx_file_attributes_read(FX_MEDIA * media_ptr,CHAR * file_name,UINT * attributes_ptr)79 UINT _fx_file_attributes_read(FX_MEDIA *media_ptr, CHAR *file_name, UINT *attributes_ptr)
80 {
81
82 UINT status;
83 FX_DIR_ENTRY dir_entry;
84
85 #ifdef TX_ENABLE_EVENT_TRACE
86 TX_TRACE_BUFFER_ENTRY *trace_event;
87 ULONG trace_timestamp;
88 #endif
89 UCHAR not_a_file_attr;
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_file_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 not_a_file_attr = FX_DIRECTORY | FX_VOLUME;
113
114 /* If trace is enabled, insert this event into the trace buffer. */
115 FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_ATTRIBUTES_READ, media_ptr, file_name, 0, 0, FX_TRACE_FILE_EVENTS, &trace_event, &trace_timestamp)
116
117 /* Protect against other threads accessing the media. */
118 FX_PROTECT
119
120 /* Search the system for the supplied file name. */
121 status = _fx_directory_search(media_ptr, file_name, &dir_entry, FX_NULL, FX_NULL);
122
123 /* Determine if the search was successful. */
124 if (status != FX_SUCCESS)
125 {
126
127 /* Release media protection. */
128 FX_UNPROTECT
129
130 /* Return the error code. */
131 return(status);
132 }
133
134 /* Check to make sure the found entry is a file. */
135 if (dir_entry.fx_dir_entry_attributes & not_a_file_attr)
136 {
137
138 /* Release media protection. */
139 FX_UNPROTECT
140
141 /* Return the not a file error code. */
142 return(FX_NOT_A_FILE);
143 }
144
145 /* Place the current attributes into the destination. */
146 *attributes_ptr = (UINT)dir_entry.fx_dir_entry_attributes;
147
148 /* Update the trace event with the attributes read. */
149 FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_FILE_ATTRIBUTES_READ, 0, 0, dir_entry.fx_dir_entry_attributes, 0)
150
151 /* Release media protection. */
152 FX_UNPROTECT
153
154 /* File attribute read is complete, return successful status. */
155 return(FX_SUCCESS);
156 }
157
158