3
3
* @brief Implementation of vfs_user.h
4
4
*
5
5
* DAPLink Interface Firmware
6
- * Copyright (c) 2009-2019 , ARM Limited, All Rights Reserved
6
+ * Copyright (c) 2009-2020 , ARM Limited, All Rights Reserved
7
7
* SPDX-License-Identifier: Apache-2.0
8
8
*
9
9
* Licensed under the Apache License, Version 2.0 (the "License"); you may
23
23
#include "ctype.h"
24
24
#include "string.h"
25
25
26
+ #include "vfs_user.h"
26
27
#include "vfs_manager.h"
27
28
#include "macro.h"
28
29
#include "error.h"
@@ -169,9 +170,28 @@ void vfs_user_build_filesystem()
169
170
}
170
171
}
171
172
173
+ // Default file change hook.
174
+ __WEAK bool vfs_user_file_change_handler_hook (const vfs_filename_t filename , vfs_file_change_t change ,
175
+ vfs_file_t file , vfs_file_t new_file_data )
176
+ {
177
+ return false;
178
+ }
179
+
180
+ // Default magic file hook.
181
+ __WEAK bool vfs_user_magic_file_hook (const vfs_filename_t filename , bool * do_remount )
182
+ {
183
+ return false;
184
+ }
185
+
172
186
// Callback to handle changes to the root directory. Should be used with vfs_set_file_change_callback
173
187
void vfs_user_file_change_handler (const vfs_filename_t filename , vfs_file_change_t change , vfs_file_t file , vfs_file_t new_file_data )
174
188
{
189
+ // Call file changed hook. If it returns true, then it handled the request and we have nothing
190
+ // more to do.
191
+ if (vfs_user_file_change_handler_hook (filename , change , file , new_file_data )) {
192
+ return ;
193
+ }
194
+
175
195
// Allow settings to be changed if automation mode is
176
196
// enabled or if the user is holding the reset button
177
197
bool btn_pressed = gpio_get_reset_btn ();
@@ -184,73 +204,81 @@ void vfs_user_file_change_handler(const vfs_filename_t filename, vfs_file_change
184
204
// Unused
185
205
}
186
206
187
- if (VFS_FILE_CREATED == change ) {
207
+ else if (VFS_FILE_CREATED == change ) {
208
+ bool do_remount = true; // Almost all magic files cause a remount.
188
209
int32_t which_magic_file = -1 ;
189
210
190
- // Compare the new file's name to our table of magic filenames.
191
- for (int32_t i = 0 ; i < ARRAY_SIZE (s_magic_file_info ); ++ i ) {
192
- if (!memcmp (filename , s_magic_file_info [i ].name , sizeof (vfs_filename_t ))) {
193
- which_magic_file = i ;
211
+ // Let the hook examine the filename. If it returned false then look for the standard
212
+ // magic files.
213
+ if (!vfs_user_magic_file_override (filename , & do_remount )) {
214
+ // Compare the new file's name to our table of magic filenames.
215
+ for (int32_t i = 0 ; i < ARRAY_SIZE (s_magic_file_info ); ++ i ) {
216
+ if (!memcmp (filename , s_magic_file_info [i ].name , sizeof (vfs_filename_t ))) {
217
+ which_magic_file = i ;
218
+ }
194
219
}
195
- }
196
-
197
- // Check if we matched a magic filename and handle it.
198
- if (which_magic_file != -1 ) {
199
- bool do_remount = true; // Almost all magic files cause a remount.
200
-
201
- switch (which_magic_file ) {
202
- case kDAPLinkModeActionFile :
203
- if (daplink_is_interface ()) {
204
- config_ram_set_hold_in_bl (true);
205
- } else {
206
- // Do nothing - bootloader will go to interface by default
207
- }
208
- break ;
209
- case kTestAssertActionFile :
210
- // Test asserts
211
- util_assert (0 );
212
- do_remount = false;
213
- break ;
214
- case kRefreshActionFile :
215
- // Remount to update the drive
216
- break ;
217
- case kEraseActionFile :
218
- erase_target ();
219
- break ;
220
- case kAutoResetConfigFile :
221
- config_set_auto_rst (true);
222
- break ;
223
- case kHardResetConfigFile :
224
- config_set_auto_rst (false);
225
- break ;
226
- case kAutomationOnConfigFile :
227
- config_set_automation_allowed (true);
228
- break ;
229
- case kAutomationOffConfigFile :
230
- config_set_automation_allowed (false);
231
- break ;
232
- case kOverflowOnConfigFile :
233
- config_set_overflow_detect (true);
234
- break ;
235
- case kOverflowOffConfigFile :
236
- config_set_overflow_detect (false);
237
- break ;
238
- case kMSDOnConfigFile :
239
- config_ram_set_disable_msd (false);
240
- break ;
241
- case kMSDOffConfigFile :
242
- config_ram_set_disable_msd (true);
243
- break ;
244
220
221
+ // Check if we matched a magic filename and handle it.
222
+ if (which_magic_file != -1 ) {
223
+ switch (which_magic_file ) {
224
+ case kDAPLinkModeActionFile :
225
+ if (daplink_is_interface ()) {
226
+ config_ram_set_hold_in_bl (true);
227
+ } else {
228
+ // Do nothing - bootloader will go to interface by default
229
+ }
230
+ break ;
231
+ case kTestAssertActionFile :
232
+ // Test asserts
233
+ util_assert (0 );
234
+ do_remount = false;
235
+ break ;
236
+ case kRefreshActionFile :
237
+ // Remount to update the drive
238
+ break ;
239
+ case kEraseActionFile :
240
+ erase_target ();
241
+ break ;
242
+ case kAutoResetConfigFile :
243
+ config_set_auto_rst (true);
244
+ break ;
245
+ case kHardResetConfigFile :
246
+ config_set_auto_rst (false);
247
+ break ;
248
+ case kAutomationOnConfigFile :
249
+ config_set_automation_allowed (true);
250
+ break ;
251
+ case kAutomationOffConfigFile :
252
+ config_set_automation_allowed (false);
253
+ break ;
254
+ case kOverflowOnConfigFile :
255
+ config_set_overflow_detect (true);
256
+ break ;
257
+ case kOverflowOffConfigFile :
258
+ config_set_overflow_detect (false);
259
+ break ;
260
+ case kMSDOnConfigFile :
261
+ config_ram_set_disable_msd (false);
262
+ break ;
263
+ case kMSDOffConfigFile :
264
+ config_ram_set_disable_msd (true);
265
+ break ;
266
+ default :
267
+ assert (false);
268
+ }
245
269
}
246
-
247
- if (do_remount ) {
248
- vfs_mngr_fs_remount ();
270
+ else {
271
+ do_remount = false;
249
272
}
250
273
}
274
+
275
+ // Remount if requested.
276
+ if (do_remount ) {
277
+ vfs_mngr_fs_remount ();
278
+ }
251
279
}
252
280
253
- if (VFS_FILE_DELETED == change ) {
281
+ else if (VFS_FILE_DELETED == change ) {
254
282
if (!memcmp (filename , assert_file , sizeof (vfs_filename_t ))) {
255
283
// Clear assert and remount to update the drive
256
284
util_assert_clear ();
0 commit comments