35
35
#include "py/nlr.h"
36
36
#include "py/runtime.h"
37
37
#include "py/stream.h"
38
+ #include "py/mperrno.h"
38
39
#include "lib/fatfs/ff.h"
39
40
#include "extmod/vfs_fat_file.h"
40
41
@@ -49,25 +50,25 @@ extern const mp_obj_type_t mp_type_textio;
49
50
// this table converts from FRESULT to POSIX errno
50
51
const byte fresult_to_errno_table [20 ] = {
51
52
[FR_OK ] = 0 ,
52
- [FR_DISK_ERR ] = EIO ,
53
- [FR_INT_ERR ] = EIO ,
54
- [FR_NOT_READY ] = EBUSY ,
55
- [FR_NO_FILE ] = ENOENT ,
56
- [FR_NO_PATH ] = ENOENT ,
57
- [FR_INVALID_NAME ] = EINVAL ,
58
- [FR_DENIED ] = EACCES ,
59
- [FR_EXIST ] = EEXIST ,
60
- [FR_INVALID_OBJECT ] = EINVAL ,
61
- [FR_WRITE_PROTECTED ] = EROFS ,
62
- [FR_INVALID_DRIVE ] = ENODEV ,
63
- [FR_NOT_ENABLED ] = ENODEV ,
64
- [FR_NO_FILESYSTEM ] = ENODEV ,
65
- [FR_MKFS_ABORTED ] = EIO ,
66
- [FR_TIMEOUT ] = EIO ,
67
- [FR_LOCKED ] = EIO ,
68
- [FR_NOT_ENOUGH_CORE ] = ENOMEM ,
69
- [FR_TOO_MANY_OPEN_FILES ] = EMFILE ,
70
- [FR_INVALID_PARAMETER ] = EINVAL ,
53
+ [FR_DISK_ERR ] = MP_EIO ,
54
+ [FR_INT_ERR ] = MP_EIO ,
55
+ [FR_NOT_READY ] = MP_EBUSY ,
56
+ [FR_NO_FILE ] = MP_ENOENT ,
57
+ [FR_NO_PATH ] = MP_ENOENT ,
58
+ [FR_INVALID_NAME ] = MP_EINVAL ,
59
+ [FR_DENIED ] = MP_EACCES ,
60
+ [FR_EXIST ] = MP_EEXIST ,
61
+ [FR_INVALID_OBJECT ] = MP_EINVAL ,
62
+ [FR_WRITE_PROTECTED ] = MP_EROFS ,
63
+ [FR_INVALID_DRIVE ] = MP_ENODEV ,
64
+ [FR_NOT_ENABLED ] = MP_ENODEV ,
65
+ [FR_NO_FILESYSTEM ] = MP_ENODEV ,
66
+ [FR_MKFS_ABORTED ] = MP_EIO ,
67
+ [FR_TIMEOUT ] = MP_EIO ,
68
+ [FR_LOCKED ] = MP_EIO ,
69
+ [FR_NOT_ENOUGH_CORE ] = MP_ENOMEM ,
70
+ [FR_TOO_MANY_OPEN_FILES ] = MP_EMFILE ,
71
+ [FR_INVALID_PARAMETER ] = MP_EINVAL ,
71
72
};
72
73
73
74
typedef struct _pyb_file_obj_t {
@@ -101,7 +102,7 @@ STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t siz
101
102
}
102
103
if (sz_out != size ) {
103
104
// The FatFS documentation says that this means disk full.
104
- * errcode = ENOSPC ;
105
+ * errcode = MP_ENOSPC ;
105
106
return MP_STREAM_ERROR ;
106
107
}
107
108
return sz_out ;
@@ -140,7 +141,7 @@ STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
140
141
141
142
case 1 : // SEEK_CUR
142
143
if (s -> offset != 0 ) {
143
- * errcode = ENOTSUP ;
144
+ * errcode = MP_EOPNOTSUPP ;
144
145
return MP_STREAM_ERROR ;
145
146
}
146
147
// no-operation
@@ -155,7 +156,7 @@ STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
155
156
return 0 ;
156
157
157
158
} else {
158
- * errcode = EINVAL ;
159
+ * errcode = MP_EINVAL ;
159
160
return MP_STREAM_ERROR ;
160
161
}
161
162
}
0 commit comments