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 |
|
|
/** Directory */ |
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_directory.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _fx_directory_short_name_get_extended PORTABLE C */ |
37 |
|
|
/* 6.1 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* William E. Lamie, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function gets the short file name via the supplied long file */ |
45 |
|
|
/* name. If the long file name is really a short file name, the short */ |
46 |
|
|
/* file name will be returned. */ |
47 |
|
|
/* */ |
48 |
|
|
/* INPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* media_ptr Media control block pointer */ |
51 |
|
|
/* long_file_name Pointer to long (max 255) name*/ |
52 |
|
|
/* short_file_name Pointer to short (8.3) name */ |
53 |
|
|
/* short_file_name_length Buffer length for short name */ |
54 |
|
|
/* */ |
55 |
|
|
/* OUTPUT */ |
56 |
|
|
/* */ |
57 |
|
|
/* return status */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLS */ |
60 |
|
|
/* */ |
61 |
|
|
/* _fx_directory_search Search for the file name in */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* Application Code */ |
66 |
|
|
/* */ |
67 |
|
|
/* RELEASE HISTORY */ |
68 |
|
|
/* */ |
69 |
|
|
/* DATE NAME DESCRIPTION */ |
70 |
|
|
/* */ |
71 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
72 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
73 |
|
|
/* resulting in version 6.1 */ |
74 |
|
|
/* */ |
75 |
|
|
/**************************************************************************/ |
76 |
|
47 |
UINT _fx_directory_short_name_get_extended(FX_MEDIA *media_ptr, CHAR *long_file_name, CHAR *short_file_name, UINT short_file_name_length) |
77 |
|
|
{ |
78 |
|
|
|
79 |
|
|
UINT status; |
80 |
|
|
UINT i; |
81 |
|
|
FX_DIR_ENTRY dir_entry; |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
/* Setup pointer to media name buffer. */ |
85 |
|
47 |
dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN; |
86 |
|
|
|
87 |
|
|
/* Clear the short name string. */ |
88 |
|
47 |
dir_entry.fx_dir_entry_short_name[0] = 0; |
89 |
|
|
|
90 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
91 |
|
|
FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_SHORT_NAME_GET, media_ptr, long_file_name, short_file_name, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0) |
92 |
|
|
|
93 |
|
|
/* Protect against other threads accessing the media. */ |
94 |
|
47 |
FX_PROTECT |
95 |
|
|
|
96 |
|
|
/* Search the system for the supplied short directory name. */ |
97 |
|
47 |
status = _fx_directory_search(media_ptr, long_file_name, &dir_entry, FX_NULL, FX_NULL); |
98 |
|
|
|
99 |
|
|
/* Determine if the search was successful. */ |
100 |
✓✓ |
47 |
if (status != FX_SUCCESS) |
101 |
|
|
{ |
102 |
|
|
|
103 |
|
|
/* Release media protection. */ |
104 |
|
1 |
FX_UNPROTECT |
105 |
|
|
|
106 |
|
|
/* Return the error code. */ |
107 |
|
1 |
return(status); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
/* Determine if there is a short name. */ |
111 |
✓✓ |
46 |
if (dir_entry.fx_dir_entry_short_name[0]) |
112 |
|
|
{ |
113 |
|
|
|
114 |
|
|
/* Yes, there is a short name. Copy the short file name portion into the destination string. */ |
115 |
|
43 |
i = 0; |
116 |
✓✓✓✓ ✓✓ |
289 |
while ((i < (FX_MAX_SHORT_NAME_LEN - 1)) && (dir_entry.fx_dir_entry_short_name[i]) && (i < (short_file_name_length - 1))) |
117 |
|
|
{ |
118 |
|
|
|
119 |
|
|
/* Copy a character of the long file name into the destination name. */ |
120 |
|
246 |
short_file_name[i] = dir_entry.fx_dir_entry_short_name[i]; |
121 |
|
|
|
122 |
|
|
/* Move to next character. */ |
123 |
|
246 |
i++; |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
/* Ensure the short file name is NULL terminated. */ |
127 |
|
43 |
short_file_name[i] = FX_NULL; |
128 |
|
|
|
129 |
|
|
/* Check if the buffer is too short for the name. */ |
130 |
✓✓✓✓
|
43 |
if ((i == (short_file_name_length - 1)) && (dir_entry.fx_dir_entry_short_name[i])) |
131 |
|
|
{ |
132 |
|
|
|
133 |
|
|
/* Buffer too short, return error. */ |
134 |
|
1 |
status = FX_BUFFER_ERROR; |
135 |
|
|
} |
136 |
|
|
} |
137 |
|
|
else |
138 |
|
|
{ |
139 |
|
|
|
140 |
|
|
/* There is no long file name, simply copy the long file name into the short file name destination. */ |
141 |
|
3 |
i = 0; |
142 |
✓✓✓✓ ✓✓ |
25 |
while ((i < (FX_MAX_SHORT_NAME_LEN - 1)) && (dir_entry.fx_dir_entry_name[i]) && (i < (short_file_name_length - 1))) |
143 |
|
|
{ |
144 |
|
|
|
145 |
|
|
/* Copy a character of the file name into the destination name. */ |
146 |
|
22 |
short_file_name[i] = dir_entry.fx_dir_entry_name[i]; |
147 |
|
|
|
148 |
|
|
/* Move to next character. */ |
149 |
|
22 |
i++; |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
/* Ensure the short file name is NULL terminated. */ |
153 |
|
3 |
short_file_name[i] = FX_NULL; |
154 |
|
|
|
155 |
|
|
/* Check if the buffer is too short for the name. */ |
156 |
✓✓✓✓
|
3 |
if ((i == (short_file_name_length - 1)) && (dir_entry.fx_dir_entry_name[i])) |
157 |
|
|
{ |
158 |
|
|
|
159 |
|
|
/* Buffer too short, return error. */ |
160 |
|
1 |
status = FX_BUFFER_ERROR; |
161 |
|
|
} |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
/* Release media protection. */ |
165 |
|
46 |
FX_UNPROTECT |
166 |
|
|
|
167 |
|
|
/* Return the completion status. */ |
168 |
|
46 |
return(status); |
169 |
|
|
} |
170 |
|
|
|