@@ -63,6 +63,8 @@ LOG_MODULE_REGISTER(main);
63
63
64
64
static int lsdir (const char * path );
65
65
#ifdef CONFIG_FS_SAMPLE_CREATE_SOME_ENTRIES
66
+ #define BUF_TO_WRITE_SIZE 512
67
+ static const char buf_to_write [BUF_TO_WRITE_SIZE ];
66
68
static bool create_some_entries (const char * base_path )
67
69
{
68
70
char path [MAX_PATH ];
@@ -83,21 +85,33 @@ static bool create_some_entries(const char *base_path)
83
85
path [base ] = 0 ;
84
86
strcat (& path [base ], SOME_FILE_NAME );
85
87
86
- if (fs_open (& file , path , FS_O_CREATE ) != 0 ) {
88
+ if (fs_open (& file , path , FS_O_CREATE | FS_O_TRUNC | FS_O_WRITE ) != 0 ) {
87
89
LOG_ERR ("Failed to create file %s" , path );
88
90
return false;
89
91
}
92
+
93
+ for (int x = 0 ; x < 1024 ; x ++ ) {
94
+ int ret = fs_write (& file , buf_to_write , BUF_TO_WRITE_SIZE );
95
+ if (ret < 0 ) {
96
+ LOG_ERR ("Failed to write: %d" , ret );
97
+ return false;
98
+ } else if (ret < BUF_TO_WRITE_SIZE ) {
99
+ LOG_ERR ("Incomplete write: %d/%d" , ret , BUF_TO_WRITE_SIZE );
100
+ return false;
101
+ }
102
+ }
103
+
90
104
fs_close (& file );
91
105
92
- path [base ] = 0 ;
93
- strcat (& path [base ], SOME_DIR_NAME );
106
+ // path[base] = 0;
107
+ // strcat(&path[base], SOME_DIR_NAME);
94
108
95
- if (fs_mkdir (path ) != 0 ) {
96
- LOG_ERR ("Failed to create dir %s" , path );
97
- /* If code gets here, it has at least successes to create the
98
- * file so allow function to return true.
99
- */
100
- }
109
+ // if (fs_mkdir(path) != 0) {
110
+ // LOG_ERR("Failed to create dir %s", path);
111
+ // /* If code gets here, it has at least successes to create the
112
+ // * file so allow function to return true.
113
+ // */
114
+ // }
101
115
return true;
102
116
}
103
117
#endif
@@ -161,19 +175,21 @@ int main(void)
161
175
return res ;
162
176
}
163
177
164
- if (lsdir (disk_mount_pt ) == 0 ) {
178
+ // if (lsdir(disk_mount_pt) == 0) {
165
179
#ifdef CONFIG_FS_SAMPLE_CREATE_SOME_ENTRIES
166
180
if (create_some_entries (disk_mount_pt )) {
167
181
lsdir (disk_mount_pt );
168
182
}
169
183
#endif
170
- }
184
+ // }
171
185
} else {
172
186
printk ("Error mounting disk.\n" );
173
187
}
174
188
175
189
fs_unmount (& mp );
176
190
191
+ printk ("Finished." );
192
+
177
193
while (1 ) {
178
194
k_sleep (K_MSEC (1000 ));
179
195
}
0 commit comments