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 |
|
|
/** 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 |
|
|
/* RELEASE HISTORY */ |
74 |
|
|
/* */ |
75 |
|
|
/* DATE NAME DESCRIPTION */ |
76 |
|
|
/* */ |
77 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
78 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
79 |
|
|
/* resulting in version 6.1 */ |
80 |
|
|
/* */ |
81 |
|
|
/**************************************************************************/ |
82 |
|
15 |
UINT _fx_file_date_time_set(FX_MEDIA *media_ptr, CHAR *file_name, |
83 |
|
|
UINT year, UINT month, UINT day, UINT hour, UINT minute, UINT second) |
84 |
|
|
{ |
85 |
|
|
|
86 |
|
|
UINT status; |
87 |
|
|
FX_DIR_ENTRY dir_entry; |
88 |
|
|
|
89 |
|
|
|
90 |
|
|
/* Setup pointer to media name buffer. */ |
91 |
|
15 |
dir_entry.fx_dir_entry_name = media_ptr -> fx_media_name_buffer + FX_MAX_LONG_NAME_LEN; |
92 |
|
|
|
93 |
|
|
/* Clear the short name string. */ |
94 |
|
15 |
dir_entry.fx_dir_entry_short_name[0] = 0; |
95 |
|
|
|
96 |
|
|
/* Check the media to make sure it is open. */ |
97 |
✓✓ |
15 |
if (media_ptr -> fx_media_id != FX_MEDIA_ID) |
98 |
|
|
{ |
99 |
|
|
|
100 |
|
|
/* Return the media not opened error. */ |
101 |
|
1 |
return(FX_MEDIA_NOT_OPEN); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
105 |
|
|
FX_TRACE_IN_LINE_INSERT(FX_TRACE_FILE_DATE_TIME_SET, media_ptr, file_name, year, month, FX_TRACE_FILE_EVENTS, 0, 0) |
106 |
|
|
|
107 |
|
|
/* Protect against other threads accessing the media. */ |
108 |
|
14 |
FX_PROTECT |
109 |
|
|
|
110 |
|
|
/* Search the system for the supplied directory name. */ |
111 |
|
14 |
status = _fx_directory_search(media_ptr, file_name, &dir_entry, FX_NULL, FX_NULL); |
112 |
|
|
|
113 |
|
|
/* Determine if the search was successful. */ |
114 |
✓✓ |
14 |
if (status != FX_SUCCESS) |
115 |
|
|
{ |
116 |
|
|
|
117 |
|
|
/* Release media protection. */ |
118 |
|
1 |
FX_UNPROTECT |
119 |
|
|
|
120 |
|
|
/* Return the error code. */ |
121 |
|
1 |
return(status); |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
/* Set the new time and date. */ |
125 |
|
13 |
dir_entry.fx_dir_entry_time = (hour << FX_HOUR_SHIFT) | (minute << FX_MINUTE_SHIFT) | (second / 2); |
126 |
|
13 |
dir_entry.fx_dir_entry_date = ((year - FX_BASE_YEAR) << FX_YEAR_SHIFT) | (month << FX_MONTH_SHIFT) | day; |
127 |
|
|
|
128 |
|
|
/* Write the directory entry to the media. */ |
129 |
|
|
#ifdef FX_ENABLE_EXFAT |
130 |
|
|
if (media_ptr -> fx_media_FAT_type == FX_exFAT) |
131 |
|
|
{ |
132 |
|
|
status = _fx_directory_exFAT_entry_write(media_ptr, &dir_entry, UPDATE_FILE); |
133 |
|
|
} |
134 |
|
|
else |
135 |
|
|
{ |
136 |
|
|
#endif /* FX_ENABLE_EXFAT */ |
137 |
|
13 |
status = _fx_directory_entry_write(media_ptr, &dir_entry); |
138 |
|
|
#ifdef FX_ENABLE_EXFAT |
139 |
|
|
} |
140 |
|
|
#endif /* FX_ENABLE_EXFAT */ |
141 |
|
|
|
142 |
|
|
/* Release media protection. */ |
143 |
|
13 |
FX_UNPROTECT |
144 |
|
|
|
145 |
|
|
/* Directory information write is complete, return status. */ |
146 |
|
13 |
return(status); |
147 |
|
|
} |
148 |
|
|
|