GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_attributes_read.c Lines: 17 17 100.0 %
Date: 2026-03-06 18:49:02 Branches: 6 6 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_attributes_read                       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.  If   */
48
/*    found, the attribute read request is valid and the directory entry  */
49
/*    will be read in order to pickup the directory's attributes.         */
50
/*    Otherwise, if the directory is not found, the appropriate error     */
51
/*    code is returned to the caller.                                     */
52
/*                                                                        */
53
/*  INPUT                                                                 */
54
/*                                                                        */
55
/*    media_ptr                             Media control block pointer   */
56
/*    directory_name                        Directory name pointer        */
57
/*    attributes_ptr                        Return attributes pointer     */
58
/*                                                                        */
59
/*  OUTPUT                                                                */
60
/*                                                                        */
61
/*    return status                                                       */
62
/*                                                                        */
63
/*  CALLS                                                                 */
64
/*                                                                        */
65
/*    _fx_directory_search                  Search for the file name in   */
66
/*                                          the directory structure       */
67
/*                                                                        */
68
/*  CALLED BY                                                             */
69
/*                                                                        */
70
/*    Application Code                                                    */
71
/*                                                                        */
72
/**************************************************************************/
73
6
UINT  _fx_directory_attributes_read(FX_MEDIA *media_ptr, CHAR *directory_name, UINT *attributes_ptr)
74
{
75
76
UINT                   status;
77
FX_DIR_ENTRY           dir_entry;
78
79
#ifdef TX_ENABLE_EVENT_TRACE
80
TX_TRACE_BUFFER_ENTRY *trace_event;
81
ULONG                  trace_timestamp;
82
#endif
83
84
85
#ifndef FX_MEDIA_STATISTICS_DISABLE
86
87
    /* Increment the number of times this service has been called.  */
88
6
    media_ptr -> fx_media_directory_attributes_reads++;
89
#endif
90
91
    /* Setup pointer to media name buffer.  */
92
6
    dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
93
94
    /* Clear the short name string.  */
95
6
    dir_entry.fx_dir_entry_short_name[0] =  0;
96
97
    /* Check the media to make sure it is open.  */
98
6
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
99
    {
100
101
        /* Return the media not opened error.  */
102
1
        return(FX_MEDIA_NOT_OPEN);
103
    }
104
105
    /* If trace is enabled, insert this event into the trace buffer.  */
106
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_ATTRIBUTES_READ, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, &trace_event, &trace_timestamp)
107
108
    /* Protect against other threads accessing the media.  */
109
5
    FX_PROTECT
110
111
    /* Search the system for the supplied file name.  */
112
5
    status =  _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
113
114
    /* Determine if the search was successful.  */
115
5
    if (status != FX_SUCCESS)
116
    {
117
118
        /* Release media protection.  */
119
1
        FX_UNPROTECT
120
121
        /* Return the error code.  */
122
1
        return(status);
123
    }
124
125
    /* Check to make sure the found entry is a file.  */
126
4
    if ((dir_entry.fx_dir_entry_attributes & (UCHAR)(FX_DIRECTORY)) == 0)
127
    {
128
129
        /* Release media protection.  */
130
1
        FX_UNPROTECT
131
132
        /* Return the not a file error code.  */
133
1
        return(FX_NOT_DIRECTORY);
134
    }
135
136
    /* Place the current attributes into the destination.  */
137
3
    *attributes_ptr =  (UINT)dir_entry.fx_dir_entry_attributes;
138
139
    /* Update the trace event with the attributes read.  */
140
    FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_DIRECTORY_ATTRIBUTES_READ, 0, 0, dir_entry.fx_dir_entry_attributes, 0)
141
142
    /* Release media protection.  */
143
3
    FX_UNPROTECT
144
145
    /* File attribute read is complete, return successful status.  */
146
3
    return(FX_SUCCESS);
147
}
148