1 |
|
|
/**************************************************************************/ |
2 |
|
|
/* */ |
3 |
|
|
/* Copyright (c) Microsoft Corporation. All rights reserved. */ |
4 |
|
|
/* */ |
5 |
|
|
/* This software is licensed under the Microsoft Software License */ |
6 |
|
|
/* Terms for Microsoft Azure RTOS. Full text of the license can be */ |
7 |
|
|
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ |
8 |
|
|
/* and in the root directory of this software. */ |
9 |
|
|
/* */ |
10 |
|
|
/**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** FileX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** File */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
#define FX_SOURCE_CODE |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/* Include necessary system files. */ |
27 |
|
|
|
28 |
|
|
#include "fx_api.h" |
29 |
|
|
#include "fx_system.h" |
30 |
|
|
#include "fx_directory.h" |
31 |
|
|
#include "fx_file.h" |
32 |
|
|
#include "fx_utility.h" |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
/**************************************************************************/ |
36 |
|
|
/* */ |
37 |
|
|
/* FUNCTION RELEASE */ |
38 |
|
|
/* */ |
39 |
|
|
/* _fx_file_attributes_read PORTABLE C */ |
40 |
|
|
/* 6.1 */ |
41 |
|
|
/* AUTHOR */ |
42 |
|
|
/* */ |
43 |
|
|
/* William E. Lamie, Microsoft Corporation */ |
44 |
|
|
/* */ |
45 |
|
|
/* DESCRIPTION */ |
46 |
|
|
/* */ |
47 |
|
|
/* This function first attempts to find the specified file. If found, */ |
48 |
|
|
/* the attribute read request is valid and the directory entry will be */ |
49 |
|
|
/* in order to pickup the file's attributes. Otherwise, if the file */ |
50 |
|
|
/* is not found, the appropriate error code is returned to the caller. */ |
51 |
|
|
/* */ |
52 |
|
|
/* INPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* media_ptr Media control block pointer */ |
55 |
|
|
/* file_name File 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 |
|
|
/**************************************************************************/ |
80 |
|
6 |
UINT _fx_file_attributes_read(FX_MEDIA *media_ptr, CHAR *file_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 |
|
|
UCHAR not_a_file_attr; |
91 |
|
|
|
92 |
|
|
|
93 |
|
|
#ifndef FX_MEDIA_STATISTICS_DISABLE |
94 |
|
|
|
95 |
|
|
/* Increment the number of times this service has been called. */ |
96 |
|
6 |
media_ptr -> fx_media_file_attributes_reads++; |
97 |
|
|
#endif |
98 |
|
|
|
99 |
|
|
/* Setup pointer to media name buffer. */ |
100 |
|
6 |
dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN; |
101 |
|
|
|
102 |
|
|
/* Clear the short name string. */ |
103 |
|
6 |
dir_entry.fx_dir_entry_short_name[0] = 0; |
104 |
|
|
|
105 |
|
|
/* Check the media to make sure it is open. */ |
106 |
✓✓ |
6 |
if (media_ptr -> fx_media_id != FX_MEDIA_ID) |
107 |
|
|
{ |
108 |
|
|
|
109 |
|
|
/* Return the media not opened error. */ |
110 |
|
1 |
return(FX_MEDIA_NOT_OPEN); |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
#ifdef FX_ENABLE_EXFAT |
114 |
|
|
if (media_ptr -> fx_media_FAT_type == FX_exFAT) |
115 |
|
|
{ |
116 |
|
|
not_a_file_attr = FX_DIRECTORY; |
117 |
|
|
} |
118 |
|
|
else |
119 |
|
|
{ |
120 |
|
|
#endif /* FX_ENABLE_EXFAT */ |
121 |
|
5 |
not_a_file_attr = FX_DIRECTORY | FX_VOLUME; |
122 |
|
|
#ifdef FX_ENABLE_EXFAT |
123 |
|
|
} |
124 |
|
|
#endif /* FX_ENABLE_EXFAT */ |
125 |
|
|
|
126 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
127 |
|
|
FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_ATTRIBUTES_READ, media_ptr, file_name, 0, 0, FX_TRACE_FILE_EVENTS, &trace_event, &trace_timestamp) |
128 |
|
|
|
129 |
|
|
/* Protect against other threads accessing the media. */ |
130 |
|
5 |
FX_PROTECT |
131 |
|
|
|
132 |
|
|
/* Search the system for the supplied file name. */ |
133 |
|
5 |
status = _fx_directory_search(media_ptr, file_name, &dir_entry, FX_NULL, FX_NULL); |
134 |
|
|
|
135 |
|
|
/* Determine if the search was successful. */ |
136 |
✓✓ |
5 |
if (status != FX_SUCCESS) |
137 |
|
|
{ |
138 |
|
|
|
139 |
|
|
/* Release media protection. */ |
140 |
|
1 |
FX_UNPROTECT |
141 |
|
|
|
142 |
|
|
/* Return the error code. */ |
143 |
|
1 |
return(status); |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
/* Check to make sure the found entry is a file. */ |
147 |
✓✓ |
4 |
if (dir_entry.fx_dir_entry_attributes & not_a_file_attr) |
148 |
|
|
{ |
149 |
|
|
|
150 |
|
|
/* Release media protection. */ |
151 |
|
1 |
FX_UNPROTECT |
152 |
|
|
|
153 |
|
|
/* Return the not a file error code. */ |
154 |
|
1 |
return(FX_NOT_A_FILE); |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
/* Place the current attributes into the destination. */ |
158 |
|
3 |
*attributes_ptr = (UINT)dir_entry.fx_dir_entry_attributes; |
159 |
|
|
|
160 |
|
|
/* Update the trace event with the attributes read. */ |
161 |
|
|
FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_FILE_ATTRIBUTES_READ, 0, 0, dir_entry.fx_dir_entry_attributes, 0) |
162 |
|
|
|
163 |
|
|
/* Release media protection. */ |
164 |
|
3 |
FX_UNPROTECT |
165 |
|
|
|
166 |
|
|
/* File attribute read is complete, return successful status. */ |
167 |
|
3 |
return(FX_SUCCESS); |
168 |
|
|
} |
169 |
|
|
|