1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** FileX Component                                                       */
16 /**                                                                       */
17 /**   File                                                                */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define FX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "fx_api.h"
28 #include "fx_directory.h"
29 #include "fx_file.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _fx_file_date_time_set                              PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    William E. Lamie, Microsoft Corporation                             */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function sets the specified file's date and time with the      */
45 /*    values provided.                                                    */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    media_ptr                             Media control block pointer   */
50 /*    file_name                             File name pointer             */
51 /*    year                                  Year                          */
52 /*    month                                 Month                         */
53 /*    day                                   Day                           */
54 /*    hour                                  Hour                          */
55 /*    minute                                Minute                        */
56 /*    second                                Second                        */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    return status                                                       */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    _fx_directory_search                  Search for the file name in   */
65 /*                                          the directory structure       */
66 /*    _fx_directory_entry_write             Write the directory entry     */
67 /*                                                                        */
68 /*  CALLED BY                                                             */
69 /*                                                                        */
70 /*    Application Code                                                    */
71 /*                                                                        */
72 /*  RELEASE HISTORY                                                       */
73 /*                                                                        */
74 /*    DATE              NAME                      DESCRIPTION             */
75 /*                                                                        */
76 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
77 /*  09-30-2020     William E. Lamie         Modified comment(s),          */
78 /*                                            resulting in version 6.1    */
79 /*                                                                        */
80 /**************************************************************************/
_fx_file_date_time_set(FX_MEDIA * media_ptr,CHAR * file_name,UINT year,UINT month,UINT day,UINT hour,UINT minute,UINT second)81 UINT  _fx_file_date_time_set(FX_MEDIA *media_ptr, CHAR *file_name,
82                              UINT year, UINT month, UINT day, UINT hour, UINT minute, UINT second)
83 {
84 
85 UINT         status;
86 FX_DIR_ENTRY dir_entry;
87 
88 
89     /* Setup pointer to media name buffer.  */
90     dir_entry.fx_dir_entry_name =  media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN;
91 
92     /* Clear the short name string.  */
93     dir_entry.fx_dir_entry_short_name[0] =  0;
94 
95     /* Check the media to make sure it is open.  */
96     if (media_ptr -> fx_media_id != FX_MEDIA_ID)
97     {
98 
99         /* Return the media not opened error.  */
100         return(FX_MEDIA_NOT_OPEN);
101     }
102 
103     /* If trace is enabled, insert this event into the trace buffer.  */
104     FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_DATE_TIME_SET, media_ptr, file_name, year, month, FX_TRACE_FILE_EVENTS, 0, 0)
105 
106     /* Protect against other threads accessing the media.  */
107     FX_PROTECT
108 
109     /* Search the system for the supplied directory name.  */
110     status =  _fx_directory_search(media_ptr, file_name, &dir_entry, FX_NULL, FX_NULL);
111 
112     /* Determine if the search was successful.  */
113     if (status != FX_SUCCESS)
114     {
115 
116         /* Release media protection.  */
117         FX_UNPROTECT
118 
119         /* Return the error code.  */
120         return(status);
121     }
122 
123     /* Set the new time and date.  */
124     dir_entry.fx_dir_entry_time =  (hour << FX_HOUR_SHIFT) | (minute << FX_MINUTE_SHIFT) | (second / 2);
125     dir_entry.fx_dir_entry_date =  ((year - FX_BASE_YEAR) << FX_YEAR_SHIFT) | (month << FX_MONTH_SHIFT) | day;
126 
127     /* Write the directory entry to the media.  */
128     status = _fx_directory_entry_write(media_ptr, &dir_entry);
129 
130     /* Release media protection.  */
131     FX_UNPROTECT
132 
133     /* Directory information write is complete, return status.  */
134     return(status);
135 }
136 
137