GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_attributes_read.c Lines: 17 17 100.0 %
Date: 2024-01-10 21:53:23 Branches: 6 6 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_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
/*  RELEASE HISTORY                                                       */
73
/*                                                                        */
74
/*    DATE              NAME                      DESCRIPTION             */
75
/*                                                                        */
76
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
77
/*  09-30-2020     William E. Lamie         Modified comment(s),          */
78
/*                                            resulting in version 6.1    */
79
/*                                                                        */
80
/**************************************************************************/
81
6
UINT  _fx_directory_attributes_read(FX_MEDIA *media_ptr, CHAR *directory_name, UINT *attributes_ptr)
82
{
83
84
UINT                   status;
85
FX_DIR_ENTRY           dir_entry;
86
87
#ifdef TX_ENABLE_EVENT_TRACE
88
TX_TRACE_BUFFER_ENTRY *trace_event;
89
ULONG                  trace_timestamp;
90
#endif
91
92
93
#ifndef FX_MEDIA_STATISTICS_DISABLE
94
95
    /* Increment the number of times this service has been called.  */
96
6
    media_ptr -> fx_media_directory_attributes_reads++;
97
#endif
98
99
    /* Setup pointer to media name buffer.  */
100
6
    dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
101
102
    /* Clear the short name string.  */
103
6
    dir_entry.fx_dir_entry_short_name[0] =  0;
104
105
    /* Check the media to make sure it is open.  */
106
6
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
107
    {
108
109
        /* Return the media not opened error.  */
110
1
        return(FX_MEDIA_NOT_OPEN);
111
    }
112
113
    /* If trace is enabled, insert this event into the trace buffer.  */
114
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_ATTRIBUTES_READ, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, &trace_event, &trace_timestamp)
115
116
    /* Protect against other threads accessing the media.  */
117
5
    FX_PROTECT
118
119
    /* Search the system for the supplied file name.  */
120
5
    status =  _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
121
122
    /* Determine if the search was successful.  */
123
5
    if (status != FX_SUCCESS)
124
    {
125
126
        /* Release media protection.  */
127
1
        FX_UNPROTECT
128
129
        /* Return the error code.  */
130
1
        return(status);
131
    }
132
133
    /* Check to make sure the found entry is a file.  */
134
4
    if ((dir_entry.fx_dir_entry_attributes & (UCHAR)(FX_DIRECTORY)) == 0)
135
    {
136
137
        /* Release media protection.  */
138
1
        FX_UNPROTECT
139
140
        /* Return the not a file error code.  */
141
1
        return(FX_NOT_DIRECTORY);
142
    }
143
144
    /* Place the current attributes into the destination.  */
145
3
    *attributes_ptr =  (UINT)dir_entry.fx_dir_entry_attributes;
146
147
    /* Update the trace event with the attributes read.  */
148
    FX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, FX_TRACE_DIRECTORY_ATTRIBUTES_READ, 0, 0, dir_entry.fx_dir_entry_attributes, 0)
149
150
    /* Release media protection.  */
151
3
    FX_UNPROTECT
152
153
    /* File attribute read is complete, return successful status.  */
154
3
    return(FX_SUCCESS);
155
}
156