GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_directory_long_name_get_extended.c Lines: 17 17 100.0 %
Date: 2026-03-06 18:49:02 Branches: 12 12 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_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
/**************************************************************************/
68
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)
69
{
70
71
UINT         status;
72
UINT         i;
73
FX_DIR_ENTRY dir_entry;
74
75
76
    /* Setup pointer to media name buffer.  */
77
8
    dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
78
79
    /* Clear the short name string.  */
80
8
    dir_entry.fx_dir_entry_short_name[0] =  0;
81
82
    /* If trace is enabled, insert this event into the trace buffer.  */
83
    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)
84
85
    /* Protect against other threads accessing the media.  */
86
8
    FX_PROTECT
87
88
    /* Search the system for the supplied short directory name.  */
89
8
    status =  _fx_directory_search(media_ptr, short_file_name, &dir_entry, FX_NULL, FX_NULL);
90
91
    /* Determine if the search was successful.  */
92
8
    if (status != FX_SUCCESS)
93
    {
94
95
        /* Release media protection.  */
96
1
        FX_UNPROTECT
97
98
        /* Return the error code.  */
99
1
        return(status);
100
    }
101
102
    /* Copy the long name portion into the destination string.  */
103
7
    i =  0;
104

306
    while ((i < (FX_MAX_LONG_NAME_LEN - 1)) && (dir_entry.fx_dir_entry_name[i]) && (i < (long_file_name_buffer_length - 1)))
105
    {
106
107
        /* Copy a character of the long name into the destination name.  */
108
299
        long_file_name[i] =  dir_entry.fx_dir_entry_name[i];
109
110
        /* Move to next character.  */
111
299
        i++;
112
    }
113
114
    /* Ensure the long file name is NULL terminated.  */
115
7
    long_file_name[i] =  FX_NULL;
116
117
    /* Check if the buffer is too short for the name.  */
118

7
    if ((i == (long_file_name_buffer_length - 1)) && (dir_entry.fx_dir_entry_name[i]))
119
    {
120
121
        /* Buffer too short, return error.  */
122
1
        status = FX_BUFFER_ERROR;
123
    }
124
125
    /* Release media protection.  */
126
7
    FX_UNPROTECT
127
128
    /* Return the completion status.  */
129
7
    return(status);
130
}
131