Skip to content

Commit 84679e0

Browse files
Alex Marchdpgeorge
Alex March
authored andcommitted
extmod/vfs_fat_file: Check fatfs f_sync() and f_close() returns for errors.
1 parent 17ba6ef commit 84679e0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

extmod/vfs_fat_file.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,20 @@ STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t siz
110110

111111
STATIC mp_obj_t file_obj_flush(mp_obj_t self_in) {
112112
pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
113-
f_sync(&self->fp);
113+
FRESULT res = f_sync(&self->fp);
114+
if (res != FR_OK) {
115+
mp_raise_OSError(fresult_to_errno_table[res]);
116+
}
114117
return mp_const_none;
115118
}
116119
STATIC MP_DEFINE_CONST_FUN_OBJ_1(file_obj_flush_obj, file_obj_flush);
117120

118121
STATIC mp_obj_t file_obj_close(mp_obj_t self_in) {
119122
pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
120-
f_close(&self->fp);
123+
FRESULT res = f_close(&self->fp);
124+
if (res != FR_OK) {
125+
mp_raise_OSError(fresult_to_errno_table[res]);
126+
}
121127
return mp_const_none;
122128
}
123129
STATIC MP_DEFINE_CONST_FUN_OBJ_1(file_obj_close_obj, file_obj_close);

0 commit comments

Comments
 (0)