Skip to content

Commit 551a2a3

Browse files
Merge pull request #5373 from ARMmbed/g-fix-nodev-errno
fs: Correct errno when not finding a mounted filesystem
2 parents 5768693 + 400c254 commit 551a2a3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

platform/mbed_retarget.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
254254
/* The first part of the filename (between first 2 '/') is not a
255255
* registered mount point in the namespace.
256256
*/
257-
return handle_open_errors(-ENOENT, fh_i);
257+
return handle_open_errors(-ENODEV, fh_i);
258258
}
259259

260260
if (path.isFile()) {
261261
res = path.file();
262262
} else {
263263
FileSystemHandle *fs = path.fileSystem();
264264
if (fs == NULL) {
265-
return handle_open_errors(-ENOENT, fh_i);
265+
return handle_open_errors(-ENODEV, fh_i);
266266
}
267267
int posix_mode = openmode_to_posix(openmode);
268268
int err = fs->open(&res, path.fileName(), posix_mode);
@@ -567,7 +567,7 @@ extern "C" int remove(const char *path) {
567567
FilePath fp(path);
568568
FileSystemHandle *fs = fp.fileSystem();
569569
if (fs == NULL) {
570-
errno = ENOENT;
570+
errno = ENODEV;
571571
return -1;
572572
}
573573

@@ -587,7 +587,7 @@ extern "C" int rename(const char *oldname, const char *newname) {
587587
FileSystemHandle *fsNew = fpNew.fileSystem();
588588

589589
if (fsOld == NULL) {
590-
errno = ENOENT;
590+
errno = ENODEV;
591591
return -1;
592592
}
593593

@@ -627,7 +627,7 @@ extern "C" DIR *opendir(const char *path) {
627627
FilePath fp(path);
628628
FileSystemHandle* fs = fp.fileSystem();
629629
if (fs == NULL) {
630-
errno = ENOENT;
630+
errno = ENODEV;
631631
return NULL;
632632
}
633633

@@ -679,7 +679,10 @@ extern "C" void seekdir(DIR *dir, off_t off) {
679679
extern "C" int mkdir(const char *path, mode_t mode) {
680680
FilePath fp(path);
681681
FileSystemHandle *fs = fp.fileSystem();
682-
if (fs == NULL) return -1;
682+
if (fs == NULL) {
683+
errno = ENODEV;
684+
return -1;
685+
}
683686

684687
int err = fs->mkdir(fp.fileName(), mode);
685688
if (err < 0) {
@@ -693,7 +696,10 @@ extern "C" int mkdir(const char *path, mode_t mode) {
693696
extern "C" int stat(const char *path, struct stat *st) {
694697
FilePath fp(path);
695698
FileSystemHandle *fs = fp.fileSystem();
696-
if (fs == NULL) return -1;
699+
if (fs == NULL) {
700+
errno = ENODEV;
701+
return -1;
702+
}
697703

698704
int err = fs->stat(fp.fileName(), st);
699705
if (err < 0) {

0 commit comments

Comments
 (0)