GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_information_get.c Lines: 39 39 100.0 %
Date: 2024-01-10 21:53:23 Branches: 28 28 100.0 %

Line Branch Exec Source
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_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_directory_information_get                       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 directory name.  */
48
/*    If found, the complete file parameters are placed in all non-NULL   */
49
/*    return parameters.  If the file name is not found, the appropriate  */
50
/*    error code is returned to the caller.                               */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    media_ptr                             Media control block pointer   */
55
/*    directory_name                        Directory name pointer        */
56
/*    attributes                            Pointer to attributes         */
57
/*    size                                  Pointer to size               */
58
/*    year                                  Pointer to year               */
59
/*    month                                 Pointer to month              */
60
/*    day                                   Pointer to day                */
61
/*    hour                                  Pointer to hour               */
62
/*    minute                                Pointer to minute             */
63
/*    second                                Pointer to second             */
64
/*                                                                        */
65
/*  OUTPUT                                                                */
66
/*                                                                        */
67
/*    return status                                                       */
68
/*                                                                        */
69
/*  CALLS                                                                 */
70
/*                                                                        */
71
/*    _fx_directory_search                  Search for the file name in   */
72
/*                                          the directory structure       */
73
/*                                                                        */
74
/*  CALLED BY                                                             */
75
/*                                                                        */
76
/*    Application Code                                                    */
77
/*                                                                        */
78
/*  RELEASE HISTORY                                                       */
79
/*                                                                        */
80
/*    DATE              NAME                      DESCRIPTION             */
81
/*                                                                        */
82
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
83
/*  09-30-2020     William E. Lamie         Modified comment(s), verified */
84
/*                                            memcpy usage,               */
85
/*                                            resulting in version 6.1    */
86
/*                                                                        */
87
/**************************************************************************/
88
7
UINT  _fx_directory_information_get(FX_MEDIA *media_ptr, CHAR *directory_name,
89
                                    UINT *attributes, ULONG *size,
90
                                    UINT *year, UINT *month, UINT *day,
91
                                    UINT *hour, UINT *minute, UINT *second)
92
{
93
94
UINT         status;
95
FX_DIR_ENTRY dir_entry;
96
ULONG        open_count;
97
FX_FILE     *search_ptr;
98
99
100
#ifndef FX_MEDIA_STATISTICS_DISABLE
101
102
    /* Increment the number of times this service has been called.  */
103
7
    media_ptr -> fx_media_directory_information_gets++;
104
#endif
105
106
    /* Setup pointer to media name buffer.  */
107
7
    dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
108
109
    /* Clear the short name string.  */
110
7
    dir_entry.fx_dir_entry_short_name[0] =  0;
111
112
    /* Check the media to make sure it is open.  */
113
7
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
114
    {
115
116
        /* Return the media not opened error.  */
117
1
        return(FX_MEDIA_NOT_OPEN);
118
    }
119
120
    /* If trace is enabled, insert this event into the trace buffer.  */
121
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_INFORMATION_GET, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
122
123
    /* Protect against other threads accessing the media.  */
124
6
    FX_PROTECT
125
126
    /* Search the system for the supplied directory name.  */
127
6
    status =  _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
128
129
    /* Determine if the search was successful.  */
130
6
    if (status != FX_SUCCESS)
131
    {
132
133
        /* Release media protection.  */
134
1
        FX_UNPROTECT
135
136
        /* Return the error code.  */
137
1
        return(status);
138
    }
139
140
    /* Check the list of open files for others open for writing.  */
141
5
    open_count =  media_ptr -> fx_media_opened_file_count;
142
5
    search_ptr =  media_ptr -> fx_media_opened_file_list;
143
20
    while (open_count)
144
    {
145
146
        /* Look at each opened file to see if the same file is opened
147
           for writing.  */
148
16
        if ((search_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector == dir_entry.fx_dir_entry_log_sector) &&
149
7
            (search_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset == dir_entry.fx_dir_entry_byte_offset) &&
150
3
            (search_ptr -> fx_file_open_mode))
151
        {
152
153
            /* The file has been opened for writing by a previous call. Use the information used by
154
               the writer instead of what is currently on the media.  */
155
1
            _fx_utility_memory_copy((UCHAR *)&search_ptr -> fx_file_dir_entry, (UCHAR *)&dir_entry, sizeof(FX_DIR_ENTRY)); /* Use case of memcpy is verified. */
156
1
            break;
157
        }
158
159
        /* Adjust the pointer and decrement the search count.  */
160
15
        search_ptr =  search_ptr -> fx_file_opened_next;
161
15
        open_count--;
162
    }
163
164
    /* Check to see if attributes are required.  */
165
5
    if (attributes)
166
    {
167
168
        /* Pickup the attributes.  */
169
3
        *attributes =  dir_entry.fx_dir_entry_attributes;
170
    }
171
172
    /* Check to see if the size is required.  */
173
5
    if (size)
174
    {
175
176
        /* Pickup the size.  */
177
3
        *size =  (ULONG)dir_entry.fx_dir_entry_file_size;
178
    }
179
180
    /* Check to see if the year is required.  */
181
5
    if (year)
182
    {
183
184
        /* Pickup the year.  */
185
3
        *year =  ((dir_entry.fx_dir_entry_date >> FX_YEAR_SHIFT) & FX_YEAR_MASK) +
186
                                                                        FX_BASE_YEAR;
187
    }
188
189
    /* Check to see if the month is required.  */
190
5
    if (month)
191
    {
192
193
        /* Pickup the month.  */
194
3
        *month =  (dir_entry.fx_dir_entry_date >> FX_MONTH_SHIFT) & FX_MONTH_MASK;
195
    }
196
197
    /* Check to see if the day is required.  */
198
5
    if (day)
199
    {
200
201
        /* Pickup the day.  */
202
3
        *day =  dir_entry.fx_dir_entry_date & FX_DAY_MASK;
203
    }
204
205
    /* Check to see if the hour is required.  */
206
5
    if (hour)
207
    {
208
209
        /* Pickup the hour.  */
210
3
        *hour =  (dir_entry.fx_dir_entry_time >> FX_HOUR_SHIFT) & FX_HOUR_MASK;
211
    }
212
213
    /* Check to see if the minute is required.  */
214
5
    if (minute)
215
    {
216
217
        /* Pickup the minute.  */
218
4
        *minute =  (dir_entry.fx_dir_entry_time >> FX_MINUTE_SHIFT) & FX_MINUTE_MASK;
219
    }
220
221
    /* Check to see if the second is required.  */
222
5
    if (second)
223
    {
224
225
        /* Pickup the second.  */
226
4
        *second =  (dir_entry.fx_dir_entry_time & FX_SECOND_MASK) * 2;
227
    }
228
229
    /* Release media protection.  */
230
5
    FX_UNPROTECT
231
232
    /* Directory information get is complete, return successful status.  */
233
5
    return(FX_SUCCESS);
234
}
235