GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_name_test.c Lines: 16 16 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_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
/**************************************************************************/
71
251
UINT  _fx_directory_name_test(FX_MEDIA *media_ptr, CHAR *directory_name)
72
{
73
74
UINT         status;
75
FX_DIR_ENTRY dir_entry;
76
77
78
#ifndef FX_MEDIA_STATISTICS_DISABLE
79
80
    /* Increment the number of times this service has been called.  */
81
251
    media_ptr -> fx_media_directory_name_tests++;
82
#endif
83
84
    /* Setup pointer to media name buffer.  */
85
251
    dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
86
87
    /* Clear the short name string.  */
88
251
    dir_entry.fx_dir_entry_short_name[0] =  0;
89
90
    /* Check the media to make sure it is open.  */
91
251
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
92
    {
93
94
        /* Return the media not opened error.  */
95
1
        return(FX_MEDIA_NOT_OPEN);
96
    }
97
98
    /* If trace is enabled, insert this event into the trace buffer.  */
99
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_NAME_TEST, media_ptr, directory_name, 0, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
100
101
    /* Protect against other threads accessing the media.  */
102
250
    FX_PROTECT
103
104
    /* Search the system for the supplied directory name.  */
105
250
    status =  _fx_directory_search(media_ptr, directory_name, &dir_entry, FX_NULL, FX_NULL);
106
107
    /* Determine if the search was successful.  */
108
250
    if (status != FX_SUCCESS)
109
    {
110
111
        /* Release media protection.  */
112
1
        FX_UNPROTECT
113
114
        /* Return the error code.  */
115
1
        return(status);
116
    }
117
118
    /* Check to see if the entry is a directory.  */
119
249
    if (!(dir_entry.fx_dir_entry_attributes & (UCHAR)FX_DIRECTORY))
120
    {
121
122
        /* Release media protection.  */
123
48
        FX_UNPROTECT
124
125
        /* Return the not a directory error code.  */
126
48
        return(FX_NOT_DIRECTORY);
127
    }
128
129
    /* Release media protection.  */
130
201
    FX_UNPROTECT
131
132
    /* Directory name test is complete, return successful status.  */
133
201
    return(FX_SUCCESS);
134
}
135