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_system.h"
29 #include "fx_directory.h"
30 #include "fx_utility.h"
31 
32 #ifndef FX_NO_LOCAL_PATH
33 FX_LOCAL_PATH_SETUP
34 #endif
35 
36 
37 /**************************************************************************/
38 /*                                                                        */
39 /*  FUNCTION                                               RELEASE        */
40 /*                                                                        */
41 /*    _fx_directory_first_entry_find                      PORTABLE C      */
42 /*                                                           6.1          */
43 /*  AUTHOR                                                                */
44 /*                                                                        */
45 /*    William E. Lamie, Microsoft Corporation                             */
46 /*                                                                        */
47 /*  DESCRIPTION                                                           */
48 /*                                                                        */
49 /*    This function returns the first directory entry of the current      */
50 /*    working directory.                                                  */
51 /*                                                                        */
52 /*  INPUT                                                                 */
53 /*                                                                        */
54 /*    media_ptr                             Media control block pointer   */
55 /*    directory_name                        Destination for directory     */
56 /*                                            name                        */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    return status                                                       */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _fx_directory_next_entry_find         Find next directory entry     */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    FileX System Functions                                              */
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_directory_first_entry_find(FX_MEDIA * media_ptr,CHAR * directory_name)79 UINT  _fx_directory_first_entry_find(FX_MEDIA *media_ptr, CHAR *directory_name)
80 {
81 
82 UINT status;
83 
84 
85 #ifndef FX_MEDIA_STATISTICS_DISABLE
86 
87     /* Increment the number of times this service has been called.  */
88     media_ptr -> fx_media_directory_first_entry_finds++;
89 #endif
90 
91     /* Check the media to make sure it is open.  */
92     if (media_ptr -> fx_media_id != FX_MEDIA_ID)
93     {
94 
95         /* Return the media not opened error.  */
96         return(FX_MEDIA_NOT_OPEN);
97     }
98 
99     /* If trace is enabled, insert this event into the trace buffer.  */
100     FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_FIRST_ENTRY_FIND, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
101 
102     /* Protect against other threads accessing the media.  */
103     FX_PROTECT
104 
105     /* Determine if a local path is in effect at this point.  */
106 #ifndef FX_NO_LOCAL_PATH
107     if (_tx_thread_current_ptr -> tx_thread_filex_ptr)
108     {
109 
110         /* Yes, there is a local path.  Set the current entry to zero.  */
111         ((FX_PATH *)_tx_thread_current_ptr -> tx_thread_filex_ptr) -> fx_path_current_entry =  0;
112     }
113     else
114     {
115 
116         /* Use global default directory.  Set the current entry to 0 in
117            order to pickup the first entry.  */
118         media_ptr -> fx_media_default_path.fx_path_current_entry =  0;
119     }
120 #else
121 
122     /* Set the current entry to 0 in order to pickup the first entry.  */
123     media_ptr -> fx_media_default_path.fx_path_current_entry =  0;
124 #endif
125 
126     /* Release media protection.  */
127     FX_UNPROTECT
128 
129     /* Call the next directory entry to pickup the first entry.  */
130     status =  _fx_directory_next_entry_find(media_ptr, directory_name);
131 
132     /* Return status to the caller.  */
133     return(status);
134 }
135 
136