GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_file_date_time_set.c Lines: 15 15 100.0 %
Date: 2026-03-06 18:49:02 Branches: 4 4 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
/**   File                                                                */
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
#include "fx_file.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _fx_file_date_time_set                              PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    William E. Lamie, Microsoft Corporation                             */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function sets the specified file's date and time with the      */
46
/*    values provided.                                                    */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    media_ptr                             Media control block pointer   */
51
/*    file_name                             File name pointer             */
52
/*    year                                  Year                          */
53
/*    month                                 Month                         */
54
/*    day                                   Day                           */
55
/*    hour                                  Hour                          */
56
/*    minute                                Minute                        */
57
/*    second                                Second                        */
58
/*                                                                        */
59
/*  OUTPUT                                                                */
60
/*                                                                        */
61
/*    return status                                                       */
62
/*                                                                        */
63
/*  CALLS                                                                 */
64
/*                                                                        */
65
/*    _fx_directory_search                  Search for the file name in   */
66
/*                                          the directory structure       */
67
/*    _fx_directory_entry_write             Write the directory entry     */
68
/*                                                                        */
69
/*  CALLED BY                                                             */
70
/*                                                                        */
71
/*    Application Code                                                    */
72
/*                                                                        */
73
/**************************************************************************/
74
15
UINT  _fx_file_date_time_set(FX_MEDIA *media_ptr, CHAR *file_name,
75
                             UINT year, UINT month, UINT day, UINT hour, UINT minute, UINT second)
76
{
77
78
UINT         status;
79
FX_DIR_ENTRY dir_entry;
80
81
82
    /* Setup pointer to media name buffer.  */
83
15
    dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
84
85
    /* Clear the short name string.  */
86
15
    dir_entry.fx_dir_entry_short_name[0] =  0;
87
88
    /* Check the media to make sure it is open.  */
89
15
    if (media_ptr -> fx_media_id != FX_MEDIA_ID)
90
    {
91
92
        /* Return the media not opened error.  */
93
1
        return(FX_MEDIA_NOT_OPEN);
94
    }
95
96
    /* If trace is enabled, insert this event into the trace buffer.  */
97
    FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_DATE_TIME_SET, media_ptr, file_name, year, month, FX_TRACE_FILE_EVENTS, 0, 0)
98
99
    /* Protect against other threads accessing the media.  */
100
14
    FX_PROTECT
101
102
    /* Search the system for the supplied directory name.  */
103
14
    status =  _fx_directory_search(media_ptr, file_name, &dir_entry, FX_NULL, FX_NULL);
104
105
    /* Determine if the search was successful.  */
106
14
    if (status != FX_SUCCESS)
107
    {
108
109
        /* Release media protection.  */
110
1
        FX_UNPROTECT
111
112
        /* Return the error code.  */
113
1
        return(status);
114
    }
115
116
    /* Set the new time and date.  */
117
13
    dir_entry.fx_dir_entry_time =  (hour << FX_HOUR_SHIFT) | (minute << FX_MINUTE_SHIFT) | (second / 2);
118
13
    dir_entry.fx_dir_entry_date =  ((year - FX_BASE_YEAR) << FX_YEAR_SHIFT) | (month << FX_MONTH_SHIFT) | day;
119
120
    /* Write the directory entry to the media.  */
121
13
    status = _fx_directory_entry_write(media_ptr, &dir_entry);
122
123
    /* Release media protection.  */
124
13
    FX_UNPROTECT
125
126
    /* Directory information write is complete, return status.  */
127
13
    return(status);
128
}
129