extmod/vfs_fat_file: Allow file obj to respond to ioctl flush request.
This commit is contained in:
parent
e50cb73b7a
commit
bd476acd41
|
@ -108,15 +108,6 @@ STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t siz
|
||||||
return sz_out;
|
return sz_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t file_obj_flush(mp_obj_t self_in) {
|
|
||||||
pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
|
||||||
FRESULT res = f_sync(&self->fp);
|
|
||||||
if (res != FR_OK) {
|
|
||||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
|
||||||
}
|
|
||||||
return mp_const_none;
|
|
||||||
}
|
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(file_obj_flush_obj, file_obj_flush);
|
|
||||||
|
|
||||||
STATIC mp_obj_t file_obj_close(mp_obj_t self_in) {
|
STATIC mp_obj_t file_obj_close(mp_obj_t self_in) {
|
||||||
pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
@ -164,6 +155,14 @@ STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
|
||||||
s->offset = f_tell(&self->fp);
|
s->offset = f_tell(&self->fp);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
} else if (request == MP_STREAM_FLUSH) {
|
||||||
|
FRESULT res = f_sync(&self->fp);
|
||||||
|
if (res != FR_OK) {
|
||||||
|
*errcode = fresult_to_errno_table[res];
|
||||||
|
return MP_STREAM_ERROR;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
*errcode = MP_EINVAL;
|
*errcode = MP_EINVAL;
|
||||||
return MP_STREAM_ERROR;
|
return MP_STREAM_ERROR;
|
||||||
|
@ -243,7 +242,7 @@ STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_readlines), MP_ROM_PTR(&mp_stream_unbuffered_readlines_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_readlines), MP_ROM_PTR(&mp_stream_unbuffered_readlines_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&file_obj_flush_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&file_obj_close_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&file_obj_close_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_seek), MP_ROM_PTR(&mp_stream_seek_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_seek), MP_ROM_PTR(&mp_stream_seek_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_tell), MP_ROM_PTR(&mp_stream_tell_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_tell), MP_ROM_PTR(&mp_stream_tell_obj) },
|
||||||
|
|
Loading…
Reference in New Issue