GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_information_get.c Lines: 39 39 100.0 %
Date: 2026-03-06 18:49:02 Branches: 28 28 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
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
/**************************************************************************/
79
7
UINT  _fx_directory_information_get(FX_MEDIA *media_ptr, CHAR *directory_name,
80
                                    UINT *attributes, ULONG *size,
81
                                    UINT *year, UINT *month, UINT *day,
82
                                    UINT *hour, UINT *minute, UINT *second)
83
{
84
85
UINT         status;
86
FX_DIR_ENTRY dir_entry;
87
ULONG        open_count;
88
FX_FILE     *search_ptr;
89
90
91
#ifndef FX_MEDIA_STATISTICS_DISABLE
92
93
    /* Increment the number of times this service has been called.  */
94
7
    media_ptr -> fx_media_directory_information_gets++;
95
#endif
96
97
    /* Setup pointer to media name buffer.  */
98
7
    dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
99
100
    /* Clear the short name string.  */
101
7
    dir_entry.fx_dir_entry_short_name[0] =  0;
102
103
    /* Check the media to make sure it is open.  */
104
7
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
105
    {
106
107
        /* Return the media not opened error.  */
108
1
        return(FX_MEDIA_NOT_OPEN);
109
    }
110
111
    /* If trace is enabled, insert this event into the trace buffer.  */
112
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_INFORMATION_GET, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
113
114
    /* Protect against other threads accessing the media.  */
115
6
    FX_PROTECT
116
117
    /* Search the system for the supplied directory name.  */
118
6
    status =  _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
119
120
    /* Determine if the search was successful.  */
121
6
    if (status != FX_SUCCESS)
122
    {
123
124
        /* Release media protection.  */
125
1
        FX_UNPROTECT
126
127
        /* Return the error code.  */
128
1
        return(status);
129
    }
130
131
    /* Check the list of open files for others open for writing.  */
132
5
    open_count =  media_ptr -> fx_media_opened_file_count;
133
5
    search_ptr =  media_ptr -> fx_media_opened_file_list;
134
20
    while (open_count)
135
    {
136
137
        /* Look at each opened file to see if the same file is opened
138
           for writing.  */
139
16
        if ((search_ptr -> fx_file_dir_entry.fx_dir_entry_log_sector == dir_entry.fx_dir_entry_log_sector) &&
140
7
            (search_ptr -> fx_file_dir_entry.fx_dir_entry_byte_offset == dir_entry.fx_dir_entry_byte_offset) &&
141
3
            (search_ptr -> fx_file_open_mode))
142
        {
143
144
            /* The file has been opened for writing by a previous call. Use the information used by
145
               the writer instead of what is currently on the media.  */
146
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. */
147
1
            break;
148
        }
149
150
        /* Adjust the pointer and decrement the search count.  */
151
15
        search_ptr =  search_ptr -> fx_file_opened_next;
152
15
        open_count--;
153
    }
154
155
    /* Check to see if attributes are required.  */
156
5
    if (attributes)
157
    {
158
159
        /* Pickup the attributes.  */
160
3
        *attributes =  dir_entry.fx_dir_entry_attributes;
161
    }
162
163
    /* Check to see if the size is required.  */
164
5
    if (size)
165
    {
166
167
        /* Pickup the size.  */
168
3
        *size =  (ULONG)dir_entry.fx_dir_entry_file_size;
169
    }
170
171
    /* Check to see if the year is required.  */
172
5
    if (year)
173
    {
174
175
        /* Pickup the year.  */
176
3
        *year =  ((dir_entry.fx_dir_entry_date >> FX_YEAR_SHIFT) & FX_YEAR_MASK) +
177
                                                                        FX_BASE_YEAR;
178
    }
179
180
    /* Check to see if the month is required.  */
181
5
    if (month)
182
    {
183
184
        /* Pickup the month.  */
185
3
        *month =  (dir_entry.fx_dir_entry_date >> FX_MONTH_SHIFT) & FX_MONTH_MASK;
186
    }
187
188
    /* Check to see if the day is required.  */
189
5
    if (day)
190
    {
191
192
        /* Pickup the day.  */
193
3
        *day =  dir_entry.fx_dir_entry_date & FX_DAY_MASK;
194
    }
195
196
    /* Check to see if the hour is required.  */
197
5
    if (hour)
198
    {
199
200
        /* Pickup the hour.  */
201
3
        *hour =  (dir_entry.fx_dir_entry_time >> FX_HOUR_SHIFT) & FX_HOUR_MASK;
202
    }
203
204
    /* Check to see if the minute is required.  */
205
5
    if (minute)
206
    {
207
208
        /* Pickup the minute.  */
209
4
        *minute =  (dir_entry.fx_dir_entry_time >> FX_MINUTE_SHIFT) & FX_MINUTE_MASK;
210
    }
211
212
    /* Check to see if the second is required.  */
213
5
    if (second)
214
    {
215
216
        /* Pickup the second.  */
217
4
        *second =  (dir_entry.fx_dir_entry_time & FX_SECOND_MASK) * 2;
218
    }
219
220
    /* Release media protection.  */
221
5
    FX_UNPROTECT
222
223
    /* Directory information get is complete, return successful status.  */
224
5
    return(FX_SUCCESS);
225
}
226