Skip to content

Commit b7c2b1f

Browse files
authored
Merge pull request #6120 from ARMmbed/g-fat-errors
fatfs: Update error code mapping
2 parents a93342f + b40ff8a commit b7c2b1f

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

features/filesystem/fat/FATFileSystem.cpp

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,48 @@
3535
static int fat_error_remap(FRESULT res)
3636
{
3737
switch(res) {
38-
case FR_OK: /* (0) Succeeded */
39-
return 0; /* no error */
40-
case FR_DISK_ERR: /* (1) A hard error occurred in the low level disk I/O layer */
41-
case FR_NOT_READY: /* (3) The physical drive cannot work */
42-
return -EIO; /* I/O error */
43-
case FR_NO_FILE: /* (4) Could not find the file */
44-
case FR_NO_PATH: /* (5) Could not find the path */
45-
case FR_INVALID_NAME: /* (6) The path name format is invalid */
46-
case FR_INVALID_DRIVE: /* (11) The logical drive number is invalid */
47-
case FR_NO_FILESYSTEM: /* (13) There is no valid FAT volume */
48-
return -ENOENT; /* No such file or directory */
49-
case FR_DENIED: /* (7) Access denied due to prohibited access or directory full */
50-
return -EACCES; /* Permission denied */
51-
case FR_EXIST: /* (8) Access denied due to prohibited access */
52-
return -EEXIST; /* File exists */
53-
case FR_WRITE_PROTECTED: /* (10) The physical drive is write protected */
54-
case FR_LOCKED: /* (16) The operation is rejected according to the file sharing policy */
55-
return -EACCES; /* Permission denied */
56-
case FR_INVALID_OBJECT: /* (9) The file/directory object is invalid */
57-
return -EFAULT; /* Bad address */
58-
case FR_NOT_ENABLED: /* (12) The volume has no work area */
59-
return -ENXIO; /* No such device or address */
60-
case FR_NOT_ENOUGH_CORE: /* (17) LFN working buffer could not be allocated */
61-
return -ENOMEM; /* Not enough space */
62-
case FR_TOO_MANY_OPEN_FILES: /* (18) Number of open files > _FS_LOCK */
63-
return -ENFILE; /* Too many open files in system */
64-
case FR_INVALID_PARAMETER: /* (19) Given parameter is invalid */
65-
return -ENOEXEC; /* Exec format error */
66-
case FR_INT_ERR: /* (2) Assertion failed */
67-
case FR_MKFS_ABORTED: /* (14) The f_mkfs() aborted due to any parameter error */
68-
case FR_TIMEOUT: /* (15) Could not get a grant to access the volume within defined period */
69-
default: /* Bad file number */
38+
case FR_OK: // (0) Succeeded
39+
return 0;
40+
case FR_DISK_ERR: // (1) A hard error occurred in the low level disk I/O layer
41+
return -EIO;
42+
case FR_INT_ERR: // (2) Assertion failed
43+
return -1;
44+
case FR_NOT_READY: // (3) The physical drive cannot work
45+
return -EIO;
46+
case FR_NO_FILE: // (4) Could not find the file
47+
return -ENOENT;
48+
case FR_NO_PATH: // (5) Could not find the path
49+
return -ENOTDIR;
50+
case FR_INVALID_NAME: // (6) The path name format is invalid
51+
return -EINVAL;
52+
case FR_DENIED: // (7) Access denied due to prohibited access or directory full
53+
return -EACCES;
54+
case FR_EXIST: // (8) Access denied due to prohibited access
55+
return -EEXIST;
56+
case FR_INVALID_OBJECT: // (9) The file/directory object is invalid
7057
return -EBADF;
58+
case FR_WRITE_PROTECTED: // (10) The physical drive is write protected
59+
return -EACCES;
60+
case FR_INVALID_DRIVE: // (11) The logical drive number is invalid
61+
return -ENODEV;
62+
case FR_NOT_ENABLED: // (12) The volume has no work area
63+
return -ENODEV;
64+
case FR_NO_FILESYSTEM: // (13) There is no valid FAT volume
65+
return -EINVAL;
66+
case FR_MKFS_ABORTED: // (14) The f_mkfs() aborted due to any problem
67+
return -EIO;
68+
case FR_TIMEOUT: // (15) Could not get a grant to access the volume within defined period
69+
return -ETIMEDOUT;
70+
case FR_LOCKED: // (16) The operation is rejected according to the file sharing policy
71+
return -EBUSY;
72+
case FR_NOT_ENOUGH_CORE: // (17) LFN working buffer could not be allocated
73+
return -ENOMEM;
74+
case FR_TOO_MANY_OPEN_FILES: // (18) Number of open files > FF_FS_LOCK
75+
return -ENFILE;
76+
case FR_INVALID_PARAMETER: // (19) Given parameter is invalid
77+
return -EINVAL;
78+
default:
79+
return -res;
7180
}
7281
}
7382

0 commit comments

Comments
 (0)