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 /**   Unicode                                                             */
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_unicode.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _fx_unicode_short_name_get_extended                 PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    William E. Lamie, Microsoft Corporation                             */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function finds the short name associated with the supplied     */
44 /*    unicode name.                                                       */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    media_ptr                             Pointer to media              */
49 /*    source_unicode_name                   Pointer to unicode name       */
50 /*    source_unicode_length                 Length of unicode name        */
51 /*    destination_short_name                Pointer to destination name   */
52 /*    short_name_buffer_length              Buffer length of short name   */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    Completion Status                                                   */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _fx_unicode_directory_search          Search for unicode name       */
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 /**************************************************************************/
_fx_unicode_short_name_get_extended(FX_MEDIA * media_ptr,UCHAR * source_unicode_name,ULONG source_unicode_length,CHAR * destination_short_name,ULONG short_name_buffer_length)75 UINT  _fx_unicode_short_name_get_extended(FX_MEDIA *media_ptr, UCHAR *source_unicode_name, ULONG source_unicode_length,
76                                  CHAR *destination_short_name, ULONG short_name_buffer_length)
77 {
78 
79 UINT         status;
80 ULONG        temp_unicode_length;
81 FX_DIR_ENTRY dir_entry;
82 
83 
84     /* Setup pointer to media name buffer.  */
85     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     dir_entry.fx_dir_entry_short_name[0] =  0;
89 
90     /* Check the media to make sure it is open.  */
91     if (media_ptr -> fx_media_id != FX_MEDIA_ID)
92     {
93 
94         /* Return the media not opened error.  */
95         return(FX_MEDIA_NOT_OPEN);
96     }
97 
98 
99     /* Null terminate the short return name.  */
100     destination_short_name[0] =  (UCHAR)0;
101 
102     /* Setup temporary unicode name length for search call.  */
103     temp_unicode_length =  source_unicode_length;
104 
105     /* If trace is enabled, insert this event into the trace buffer.  */
106     FX_TRACE_IN_LINE_INSERT(FX_TRACE_UNICODE_SHORT_NAME_GET, media_ptr, source_unicode_name, source_unicode_length, destination_short_name, FX_TRACE_FILE_EVENTS, 0, 0)
107 
108     /* Protect against other threads accessing the media.  */
109     FX_PROTECT
110 
111     /* Search the system for the supplied short name and return the unicode name if there is a match.  */
112     status =  _fx_unicode_directory_search(media_ptr, &dir_entry, (UCHAR *)destination_short_name, short_name_buffer_length, source_unicode_name, &temp_unicode_length, 0);
113 
114     /* Release media protection.  */
115     FX_UNPROTECT
116 
117     /* Return successful completion status.  */
118     return(status);
119 }
120 
121