Skip to content

Commit dc43508

Browse files
committed
extmod/vfs_fat_file: Use MP_Exxx errno constants.
1 parent 016dba0 commit dc43508

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

extmod/vfs_fat_file.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "py/nlr.h"
3636
#include "py/runtime.h"
3737
#include "py/stream.h"
38+
#include "py/mperrno.h"
3839
#include "lib/fatfs/ff.h"
3940
#include "extmod/vfs_fat_file.h"
4041

@@ -49,25 +50,25 @@ extern const mp_obj_type_t mp_type_textio;
4950
// this table converts from FRESULT to POSIX errno
5051
const byte fresult_to_errno_table[20] = {
5152
[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,
7172
};
7273

7374
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
101102
}
102103
if (sz_out != size) {
103104
// The FatFS documentation says that this means disk full.
104-
*errcode = ENOSPC;
105+
*errcode = MP_ENOSPC;
105106
return MP_STREAM_ERROR;
106107
}
107108
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,
140141

141142
case 1: // SEEK_CUR
142143
if (s->offset != 0) {
143-
*errcode = ENOTSUP;
144+
*errcode = MP_EOPNOTSUPP;
144145
return MP_STREAM_ERROR;
145146
}
146147
// 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,
155156
return 0;
156157

157158
} else {
158-
*errcode = EINVAL;
159+
*errcode = MP_EINVAL;
159160
return MP_STREAM_ERROR;
160161
}
161162
}

0 commit comments

Comments
 (0)