9
0
Fork 0

fs open: pass error from stat

We used to simply answer with -ENOENT in open() when the
initial call to stat() failed. Instead, forward the error from
stat().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2012-02-27 09:30:11 +01:00
parent b5e5b06d8b
commit 3f637f7dc4
1 changed files with 6 additions and 6 deletions

12
fs/fs.c
View File

@ -480,20 +480,20 @@ int open(const char *pathname, int flags, ...)
struct fs_device_d *fsdev; struct fs_device_d *fsdev;
struct fs_driver_d *fsdrv; struct fs_driver_d *fsdrv;
FILE *f; FILE *f;
int exist; int exist_err;
struct stat s; struct stat s;
char *path = normalise_path(pathname); char *path = normalise_path(pathname);
char *freep = path; char *freep = path;
exist = (stat(path, &s) == 0) ? 1 : 0; exist_err = stat(path, &s);
if (exist && S_ISDIR(s.st_mode)) { if (!exist_err && S_ISDIR(s.st_mode)) {
errno = -EISDIR; errno = -EISDIR;
goto out1; goto out1;
} }
if (!exist && !(flags & O_CREAT)) { if (exist_err && !(flags & O_CREAT)) {
errno = -ENOENT; errno = exist_err;
goto out1; goto out1;
} }
@ -517,7 +517,7 @@ int open(const char *pathname, int flags, ...)
goto out; goto out;
} }
if (!exist) { if (exist_err) {
if (NULL != fsdrv->create) if (NULL != fsdrv->create)
errno = fsdrv->create(&fsdev->dev, path, errno = fsdrv->create(&fsdev->dev, path,
S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO); S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO);