GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_file_attributes_read.c Lines: 18 18 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
/**   File                                                                */
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_file_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 file.  If found, */
48
/*    the attribute read request is valid and the directory entry will be */
49
/*    in order to pickup the file's attributes.  Otherwise, if the file   */
50
/*    is not found, the appropriate error code is returned to the caller. */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    media_ptr                             Media control block pointer   */
55
/*    file_name                             File name pointer             */
56
/*    attributes_ptr                        Return attributes pointer     */
57
/*                                                                        */
58
/*  OUTPUT                                                                */
59
/*                                                                        */
60
/*    return status                                                       */
61
/*                                                                        */
62
/*  CALLS                                                                 */
63
/*                                                                        */
64
/*    _fx_directory_search                  Search for the file name in   */
65
/*                                          the directory structure       */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    Application Code                                                    */
70
/*                                                                        */
71
/**************************************************************************/
72
6
UINT  _fx_file_attributes_read(FX_MEDIA *media_ptr, CHAR *file_name, UINT *attributes_ptr)
73
{
74
75
UINT                   status;
76
FX_DIR_ENTRY           dir_entry;
77
78
#ifdef TX_ENABLE_EVENT_TRACE
79
TX_TRACE_BUFFER_ENTRY *trace_event;
80
ULONG                  trace_timestamp;
81
#endif
82
UCHAR                  not_a_file_attr;
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_file_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
5
    not_a_file_attr = FX_DIRECTORY | FX_VOLUME;
106
107
    /* If trace is enabled, insert this event into the trace buffer.  */
108
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_ATTRIBUTES_READ, media_ptr, file_name, 0, 0, FX_TRACE_FILE_EVENTS, &trace_event, &trace_timestamp)
109
110
    /* Protect against other threads accessing the media.  */
111
5
    FX_PROTECT
112
113
    /* Search the system for the supplied file name.  */
114
5
    status =  _fx_directory_search(media_ptr, file_name, &dir_entry, FX_NULL, FX_NULL);
115
116
    /* Determine if the search was successful.  */
117
5
    if (status != FX_SUCCESS)
118
    {
119
120
        /* Release media protection.  */
121
1
        FX_UNPROTECT
122
123
        /* Return the error code.  */
124
1
        return(status);
125
    }
126
127
    /* Check to make sure the found entry is a file.  */
128
4
    if (dir_entry.fx_dir_entry_attributes & not_a_file_attr)
129
    {
130
131
        /* Release media protection.  */
132
1
        FX_UNPROTECT
133
134
        /* Return the not a file error code.  */
135
1
        return(FX_NOT_A_FILE);
136
    }
137
138
    /* Place the current attributes into the destination.  */
139
3
    *attributes_ptr =  (UINT)dir_entry.fx_dir_entry_attributes;
140
141
    /* Update the trace event with the attributes read.  */
142
    FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_FILE_ATTRIBUTES_READ, 0, 0, dir_entry.fx_dir_entry_attributes, 0)
143
144
    /* Release media protection.  */
145
3
    FX_UNPROTECT
146
147
    /* File attribute read is complete, return successful status.  */
148
3
    return(FX_SUCCESS);
149
}
150