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