@@ -64,26 +64,30 @@ inline void filesystem_tick(void) {
64
64
}
65
65
66
66
67
+ __attribute__((unused )) // this function MAY be unused
67
68
static void make_empty_file (FATFS * fatfs , const char * path ) {
68
69
FIL fp ;
69
70
f_open (fatfs , & fp , path , FA_WRITE | FA_CREATE_ALWAYS );
70
71
f_close (& fp );
71
72
}
72
73
74
+ #if CIRCUITPY_FULL_BUILD
75
+ #define MAKE_FILE_WITH_OPTIONAL_CONTENTS (fatfs , filename , string_literal ) do { \
76
+ const byte buffer[] = string_literal; \
77
+ make_file_with_contents(fatfs, filename, buffer, sizeof(buffer) - 1); \
78
+ } while (0)
73
79
74
- static void make_sample_code_file (FATFS * fatfs ) {
75
- #if CIRCUITPY_FULL_BUILD
80
+ static void make_file_with_contents (FATFS * fatfs , const char * filename , const byte * content , UINT size ) {
76
81
FIL fs ;
77
- UINT char_written = 0 ;
78
- const byte buffer [] = "print(\"Hello World!\")\n" ;
79
82
// Create or modify existing code.py file
80
- f_open (fatfs , & fs , "/code.py" , FA_WRITE | FA_CREATE_ALWAYS );
81
- f_write (& fs , buffer , sizeof ( buffer ) - 1 , & char_written );
83
+ f_open (fatfs , & fs , filename , FA_WRITE | FA_CREATE_ALWAYS );
84
+ f_write (& fs , content , size , & size );
82
85
f_close (& fs );
83
- #else
84
- make_empty_file (fatfs , "/code.py" );
85
- #endif
86
86
}
87
+ #else
88
+ #define MAKE_FILE_WITH_OPTIONAL_CONTENTS (fatfs , filename , string_literal ) \
89
+ make_empty_file(fatfs, filename)
90
+ #endif
87
91
88
92
// we don't make this function static because it needs a lot of stack and we
89
93
// want it to be executed without using stack within main() function
@@ -137,11 +141,20 @@ bool filesystem_init(bool create_allowed, bool force_create) {
137
141
// https://specifications.freedesktop.org/trash-spec/trashspec-latest.html
138
142
#endif
139
143
144
+ #if CIRCUITPY_SDCARDIO || CIRCUITPY_SDIOIO
145
+ res = f_mkdir (& vfs_fat -> fatfs , "/sd" );
146
+ #if CIRCUITPY_FULL_BUILD
147
+ MAKE_FILE_WITH_OPTIONAL_CONTENTS (& vfs_fat -> fatfs , "/sd/placeholder.txt" ,
148
+ "SD cards mounted at /sd will hide this file from Python."
149
+ " SD cards are not visible via USB CIRCUITPY.\n" );
150
+ #endif
151
+ #endif
152
+
140
153
#if CIRCUITPY_OS_GETENV
141
154
make_empty_file (& vfs_fat -> fatfs , "/settings.toml" );
142
155
#endif
143
156
// make a sample code.py file
144
- make_sample_code_file (& vfs_fat -> fatfs );
157
+ MAKE_FILE_WITH_OPTIONAL_CONTENTS (& vfs_fat -> fatfs , "/code.py" , "print(\"Hello World!\")\n" );
145
158
146
159
// create empty lib directory
147
160
res = f_mkdir (& vfs_fat -> fatfs , "/lib" );
0 commit comments