fx_directory_short_name_get_extended.c
| 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_short_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 short file name via the supplied long file */ | ||
| 45 | /* name. If the long file name is really a short file name, the short */ | ||
| 46 | /* file name will be returned. */ | ||
| 47 | /* */ | ||
| 48 | /* INPUT */ | ||
| 49 | /* */ | ||
| 50 | /* media_ptr Media control block pointer */ | ||
| 51 | /* long_file_name Pointer to long (max 255) name*/ | ||
| 52 | /* short_file_name Pointer to short (8.3) name */ | ||
| 53 | /* short_file_name_length Buffer length for short 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 | 423 | UINT _fx_directory_short_name_get_extended(FX_MEDIA *media_ptr, CHAR *long_file_name, CHAR *short_file_name, UINT short_file_name_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 | 423 | 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 | 423 | 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_SHORT_NAME_GET, media_ptr, long_file_name, short_file_name, 0, FX_TRACE_DIRECTORY_EVENTS, 0, 0) | ||
| 84 | |||
| 85 | /* Protect against other threads accessing the media. */ | ||
| 86 | 235 | FX_PROTECT | |
| 87 | |||
| 88 | /* Search the system for the supplied short directory name. */ | ||
| 89 | 423 | status = _fx_directory_search(media_ptr, long_file_name, &dir_entry, FX_NULL, FX_NULL); | |
| 90 | |||
| 91 | /* Determine if the search was successful. */ | ||
| 92 |
4/4✓ Branch 3 → 4 taken 4 times.
✓ Branch 3 → 5 taken 184 times.
✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 7 taken 230 times.
|
423 | if (status != FX_SUCCESS) |
| 93 | { | ||
| 94 | |||
| 95 | /* Release media protection. */ | ||
| 96 | 5 | FX_UNPROTECT | |
| 97 | |||
| 98 | /* Return the error code. */ | ||
| 99 | 9 | return(status); | |
| 100 | } | ||
| 101 | |||
| 102 | /* Determine if there is a short name. */ | ||
| 103 |
4/4✓ Branch 5 → 6 taken 172 times.
✓ Branch 5 → 14 taken 12 times.
✓ Branch 7 → 8 taken 215 times.
✓ Branch 7 → 16 taken 15 times.
|
414 | if (dir_entry.fx_dir_entry_short_name[0]) |
| 104 | { | ||
| 105 | |||
| 106 | /* Yes, there is a short name. Copy the short file name portion into the destination string. */ | ||
| 107 | 387 | i = 0; | |
| 108 |
11/11✓ Branch 8 → 9 taken 1144 times.
✓ Branch 8 → 11 taken 12 times.
✓ Branch 9 → 10 taken 988 times.
✓ Branch 9 → 11 taken 156 times.
✓ Branch 10 → 7 taken 984 times.
✓ Branch 10 → 11 taken 1434 times.
✓ Branch 10 → 13 taken 15 times.
✓ Branch 11 → 12 taken 1235 times.
✓ Branch 11 → 13 taken 195 times.
✓ Branch 12 → 9 taken 1230 times.
✓ Branch 12 → 13 taken 5 times.
|
2601 | while ((i < (FX_MAX_SHORT_NAME_LEN - 1)) && (dir_entry.fx_dir_entry_short_name[i]) && (i < (short_file_name_length - 1))) |
| 109 | { | ||
| 110 | |||
| 111 | /* Copy a character of the long file name into the destination name. */ | ||
| 112 | 2214 | short_file_name[i] = dir_entry.fx_dir_entry_short_name[i]; | |
| 113 | |||
| 114 | /* Move to next character. */ | ||
| 115 | 2214 | i++; | |
| 116 | } | ||
| 117 | |||
| 118 | /* Ensure the short file name is NULL terminated. */ | ||
| 119 | 387 | short_file_name[i] = FX_NULL; | |
| 120 | |||
| 121 | /* Check if the buffer is too short for the name. */ | ||
| 122 |
8/8✓ Branch 11 → 12 taken 16 times.
✓ Branch 11 → 22 taken 156 times.
✓ Branch 12 → 13 taken 4 times.
✓ Branch 12 → 22 taken 12 times.
✓ Branch 13 → 14 taken 20 times.
✓ Branch 13 → 24 taken 195 times.
✓ Branch 14 → 15 taken 5 times.
✓ Branch 14 → 24 taken 15 times.
|
387 | if ((i == (short_file_name_length - 1)) && (dir_entry.fx_dir_entry_short_name[i])) |
| 123 | { | ||
| 124 | |||
| 125 | /* Buffer too short, return error. */ | ||
| 126 | 9 | status = FX_BUFFER_ERROR; | |
| 127 | } | ||
| 128 | } | ||
| 129 | else | ||
| 130 | { | ||
| 131 | |||
| 132 | /* There is no long file name, simply copy the long file name into the short file name destination. */ | ||
| 133 | 27 | i = 0; | |
| 134 |
11/11✓ Branch 16 → 17 taken 96 times.
✓ Branch 16 → 19 taken 4 times.
✓ Branch 17 → 18 taken 92 times.
✓ Branch 17 → 19 taken 4 times.
✓ Branch 18 → 15 taken 88 times.
✓ Branch 18 → 19 taken 124 times.
✓ Branch 18 → 21 taken 5 times.
✓ Branch 19 → 20 taken 115 times.
✓ Branch 19 → 21 taken 5 times.
✓ Branch 20 → 17 taken 110 times.
✓ Branch 20 → 21 taken 5 times.
|
225 | while ((i < (FX_MAX_SHORT_NAME_LEN - 1)) && (dir_entry.fx_dir_entry_name[i]) && (i < (short_file_name_length - 1))) |
| 135 | { | ||
| 136 | |||
| 137 | /* Copy a character of the file name into the destination name. */ | ||
| 138 | 198 | short_file_name[i] = dir_entry.fx_dir_entry_name[i]; | |
| 139 | |||
| 140 | /* Move to next character. */ | ||
| 141 | 198 | i++; | |
| 142 | } | ||
| 143 | |||
| 144 | /* Ensure the short file name is NULL terminated. */ | ||
| 145 | 27 | short_file_name[i] = FX_NULL; | |
| 146 | |||
| 147 | /* Check if the buffer is too short for the name. */ | ||
| 148 |
8/8✓ Branch 19 → 20 taken 8 times.
✓ Branch 19 → 22 taken 4 times.
✓ Branch 20 → 21 taken 4 times.
✓ Branch 20 → 22 taken 4 times.
✓ Branch 21 → 22 taken 10 times.
✓ Branch 21 → 24 taken 5 times.
✓ Branch 22 → 23 taken 5 times.
✓ Branch 22 → 24 taken 5 times.
|
27 | if ((i == (short_file_name_length - 1)) && (dir_entry.fx_dir_entry_name[i])) |
| 149 | { | ||
| 150 | |||
| 151 | /* Buffer too short, return error. */ | ||
| 152 | 9 | status = FX_BUFFER_ERROR; | |
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | /* Release media protection. */ | ||
| 157 | 230 | FX_UNPROTECT | |
| 158 | |||
| 159 | /* Return the completion status. */ | ||
| 160 | 414 | return(status); | |
| 161 | } | ||
| 162 | |||
| 163 |