GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_long_name_get_extended.c Lines: 17 17 100.0 %
Date: 2024-01-10 21:53:23 Branches: 12 12 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_directory.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _fx_directory_long_name_get_extended                PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    William E. Lamie, Microsoft Corporation                             */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function gets the long file name via the supplied short file   */
45
/*    name. If there is no long file name, the short file name will be    */
46
/*    returned.                                                           */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    media_ptr                             Media control block pointer   */
51
/*    short_file_name                       Pointer to short (8.3) name   */
52
/*    long_file_name                        Pointer to long (max 255) name*/
53
/*    long_file_name_buffer_length          Buffer length for long name   */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    return status                                                       */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _fx_directory_search                  Search for the file name in   */
62
/*                                                                        */
63
/*  CALLED BY                                                             */
64
/*                                                                        */
65
/*    Application Code                                                    */
66
/*                                                                        */
67
/*  RELEASE HISTORY                                                       */
68
/*                                                                        */
69
/*    DATE              NAME                      DESCRIPTION             */
70
/*                                                                        */
71
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
72
/*  09-30-2020     William E. Lamie         Modified comment(s),          */
73
/*                                            resulting in version 6.1    */
74
/*                                                                        */
75
/**************************************************************************/
76
8
UINT  _fx_directory_long_name_get_extended(FX_MEDIA *media_ptr, CHAR *short_file_name, CHAR *long_file_name, UINT long_file_name_buffer_length)
77
{
78
79
UINT         status;
80
UINT         i;
81
FX_DIR_ENTRY dir_entry;
82
83
84
    /* Setup pointer to media name buffer.  */
85
8
    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
8
    dir_entry.fx_dir_entry_short_name[0] =  0;
89
90
    /* If trace is enabled, insert this event into the trace buffer.  */
91
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_DIRECTORY_LONG_NAME_GET, media_ptr, short_file_name, long_file_name, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0)
92
93
    /* Protect against other threads accessing the media.  */
94
8
    FX_PROTECT
95
96
    /* Search the system for the supplied short directory name.  */
97
8
    status =  _fx_directory_search(media_ptr, short_file_name, &dir_entry, FX_NULL, FX_NULL);
98
99
    /* Determine if the search was successful.  */
100
8
    if (status != FX_SUCCESS)
101
    {
102
103
        /* Release media protection.  */
104
1
        FX_UNPROTECT
105
106
        /* Return the error code.  */
107
1
        return(status);
108
    }
109
110
    /* Copy the long name portion into the destination string.  */
111
7
    i =  0;
112

306
    while ((i < (FX_MAX_LONG_NAME_LEN - 1)) && (dir_entry.fx_dir_entry_name[i]) && (i < (long_file_name_buffer_length - 1)))
113
    {
114
115
        /* Copy a character of the long name into the destination name.  */
116
299
        long_file_name[i] =  dir_entry.fx_dir_entry_name[i];
117
118
        /* Move to next character.  */
119
299
        i++;
120
    }
121
122
    /* Ensure the long file name is NULL terminated.  */
123
7
    long_file_name[i] =  FX_NULL;
124
125
    /* Check if the buffer is too short for the name.  */
126

7
    if ((i == (long_file_name_buffer_length - 1)) && (dir_entry.fx_dir_entry_name[i]))
127
    {
128
129
        /* Buffer too short, return error.  */
130
1
        status = FX_BUFFER_ERROR;
131
    }
132
133
    /* Release media protection.  */
134
7
    FX_UNPROTECT
135
136
    /* Return the completion status.  */
137
7
    return(status);
138
}
139