1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2017-04-03 Urey the first version
9 * 2022-06-01 Meco Man improve the init process
10 */
11 #include <rtthread.h>
12 #include <rtdevice.h>
13
14 #define DBG_TAG "FileSystem"
15 #define DBG_LVL DBG_INFO
16 #include <rtdbg.h>
17
18 #ifdef RT_USING_DFS
19 #include <dfs_fs.h>
20
mnt_init(void)21 static int mnt_init(void)
22 {
23 #ifdef RT_USING_DFS_WINSHAREDIR
24 extern int dfs_win32_init(void);
25 extern rt_err_t rt_win_sharedir_init(const char *name);
26
27 dfs_win32_init();
28 rt_win_sharedir_init("wshare");
29
30 if (dfs_mount("wshare", "/", "wdir", 0, 0) == 0)
31 {
32 LOG_I("[wshare] File System on root ('wshare') initialized!");
33 }
34 else
35 {
36 LOG_E("[wshare] File System on root ('wshare') initialization failed!");
37 }
38
39 if (dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
40 #else
41 if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
42 #endif /* RT_USING_DFS_WINSHAREDIR */
43 {
44 LOG_I("[sd0] File System on SD ('sd0') initialized!");
45 }
46 else
47 {
48 LOG_W("[sd0] File System on SD ('sd0') initialization failed!");
49 LOG_W("[sd0] Try to format and re-mount...");
50 if (dfs_mkfs("elm", "sd0") == 0)
51 {
52 #ifdef RT_USING_DFS_WINSHAREDIR
53 if (dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
54 #else
55 if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
56 #endif /* RT_USING_DFS_WINSHAREDIR */
57 {
58 LOG_I("[sd0] File System on SD ('sd0') initialized!");
59 return 0;
60 }
61 }
62
63 LOG_E("[sd0] File System on SD ('sd0') initialization failed!");
64 }
65 return 0;
66 }
67 INIT_ENV_EXPORT(mnt_init);
68 #endif /* RT_USING_DFS */
69