GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_name_test.c Lines: 16 16 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_name_test                             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 attributes are checked to see if the entry is a       */
49
/*    directory.  If not, the appropriate error code is returned to the   */
50
/*    caller.                                                             */
51
/*                                                                        */
52
/*  INPUT                                                                 */
53
/*                                                                        */
54
/*    media_ptr                             Media control block pointer   */
55
/*    directory_name                        Directory name pointer        */
56
/*                                                                        */
57
/*  OUTPUT                                                                */
58
/*                                                                        */
59
/*    return status                                                       */
60
/*                                                                        */
61
/*  CALLS                                                                 */
62
/*                                                                        */
63
/*    _fx_directory_search                  Search for the file name in   */
64
/*                                          the directory structure       */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Application Code                                                    */
69
/*                                                                        */
70
/*  RELEASE HISTORY                                                       */
71
/*                                                                        */
72
/*    DATE              NAME                      DESCRIPTION             */
73
/*                                                                        */
74
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
75
/*  09-30-2020     William E. Lamie         Modified comment(s),          */
76
/*                                            resulting in version 6.1    */
77
/*                                                                        */
78
/**************************************************************************/
79
251
UINT  _fx_directory_name_test(FX_MEDIA *media_ptr, CHAR *directory_name)
80
{
81
82
UINT         status;
83
FX_DIR_ENTRY dir_entry;
84
85
86
#ifndef FX_MEDIA_STATISTICS_DISABLE
87
88
    /* Increment the number of times this service has been called.  */
89
251
    media_ptr -> fx_media_directory_name_tests++;
90
#endif
91
92
    /* Setup pointer to media name buffer.  */
93
251
    dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
94
95
    /* Clear the short name string.  */
96
251
    dir_entry.fx_dir_entry_short_name[0] =  0;
97
98
    /* Check the media to make sure it is open.  */
99
251
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
100
    {
101
102
        /* Return the media not opened error.  */
103
1
        return(FX_MEDIA_NOT_OPEN);
104
    }
105
106
    /* If trace is enabled, insert this event into the trace buffer.  */
107
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_NAME_TEST, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
108
109
    /* Protect against other threads accessing the media.  */
110
250
    FX_PROTECT
111
112
    /* Search the system for the supplied directory name.  */
113
250
    status =  _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
114
115
    /* Determine if the search was successful.  */
116
250
    if (status != FX_SUCCESS)
117
    {
118
119
        /* Release media protection.  */
120
1
        FX_UNPROTECT
121
122
        /* Return the error code.  */
123
1
        return(status);
124
    }
125
126
    /* Check to see if the entry is a directory.  */
127
249
    if (!(dir_entry.fx_dir_entry_attributes & (UCHAR)FX_DIRECTORY))
128
    {
129
130
        /* Release media protection.  */
131
48
        FX_UNPROTECT
132
133
        /* Return the not a directory error code.  */
134
48
        return(FX_NOT_DIRECTORY);
135
    }
136
137
    /* Release media protection.  */
138
201
    FX_UNPROTECT
139
140
    /* Directory name test is complete, return successful status.  */
141
201
    return(FX_SUCCESS);
142
}
143