sandbox: Update os_open() to return an error code
It is convenient to be able to report the system error when available. Update os_open() to return it. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -100,7 +100,7 @@ off_t os_lseek(int fd, off_t offset, int whence)
|
||||
|
||||
int os_open(const char *pathname, int os_flags)
|
||||
{
|
||||
int flags;
|
||||
int flags, ret;
|
||||
|
||||
switch (os_flags & OS_O_MASK) {
|
||||
case OS_O_RDONLY:
|
||||
@@ -127,7 +127,11 @@ int os_open(const char *pathname, int os_flags)
|
||||
*/
|
||||
flags |= O_CLOEXEC;
|
||||
|
||||
return open(pathname, flags, 0644);
|
||||
ret = open(pathname, flags, 0644);
|
||||
if (ret == -1)
|
||||
return -errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int os_close(int fd)
|
||||
@@ -172,7 +176,7 @@ int os_write_file(const char *fname, const void *buf, int size)
|
||||
fd = os_open(fname, OS_O_WRONLY | OS_O_CREAT | OS_O_TRUNC);
|
||||
if (fd < 0) {
|
||||
printf("Cannot open file '%s'\n", fname);
|
||||
return -EIO;
|
||||
return fd;
|
||||
}
|
||||
if (os_write(fd, buf, size) != size) {
|
||||
printf("Cannot write to file '%s'\n", fname);
|
||||
@@ -206,7 +210,7 @@ int os_read_file(const char *fname, void **bufp, int *sizep)
|
||||
fd = os_open(fname, OS_O_RDONLY);
|
||||
if (fd < 0) {
|
||||
printf("Cannot open file '%s'\n", fname);
|
||||
return -EIO;
|
||||
return fd;
|
||||
}
|
||||
size = os_filesize(fd);
|
||||
if (size < 0) {
|
||||
@@ -242,7 +246,7 @@ int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep)
|
||||
ifd = os_open(pathname, os_flags);
|
||||
if (ifd < 0) {
|
||||
printf("Cannot open file '%s'\n", pathname);
|
||||
return -EIO;
|
||||
return ifd;
|
||||
}
|
||||
size = os_filesize(ifd);
|
||||
if (size < 0) {
|
||||
|
||||
@@ -39,11 +39,11 @@ static int host_sb_attach_file(struct udevice *dev, const char *filename)
|
||||
return ret;
|
||||
|
||||
fd = os_open(filename, OS_O_RDWR);
|
||||
if (fd == -1) {
|
||||
if (fd < 0) {
|
||||
printf("Failed to access host backing file '%s', trying read-only\n",
|
||||
filename);
|
||||
fd = os_open(filename, OS_O_RDONLY);
|
||||
if (fd == -1) {
|
||||
if (fd < 0) {
|
||||
printf("- still failed\n");
|
||||
return log_msg_ret("open", -ENOENT);
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ static int sandbox_sf_probe(struct udevice *dev)
|
||||
memset(sandbox_sf_0xff, 0xff, sizeof(sandbox_sf_0xff));
|
||||
|
||||
sbsf->fd = os_open(pdata->filename, 02);
|
||||
if (sbsf->fd == -1) {
|
||||
if (sbsf->fd < 0) {
|
||||
printf("%s: unable to open file '%s'\n", __func__,
|
||||
pdata->filename);
|
||||
ret = -EIO;
|
||||
|
||||
@@ -105,7 +105,7 @@ static int sandbox_scsi_probe(struct udevice *dev)
|
||||
|
||||
if (priv->pathname) {
|
||||
priv->fd = os_open(priv->pathname, OS_O_RDONLY);
|
||||
if (priv->fd != -1) {
|
||||
if (priv->fd >= 0) {
|
||||
ret = os_get_filesize(priv->pathname, &info->file_size);
|
||||
if (ret)
|
||||
return log_msg_ret("sz", ret);
|
||||
|
||||
@@ -342,7 +342,7 @@ static int sandbox_flash_probe(struct udevice *dev)
|
||||
int ret;
|
||||
|
||||
priv->fd = os_open(plat->pathname, OS_O_RDWR);
|
||||
if (priv->fd != -1) {
|
||||
if (priv->fd >= 0) {
|
||||
ret = os_get_filesize(plat->pathname, &info->file_size);
|
||||
if (ret)
|
||||
return log_msg_ret("sz", ret);
|
||||
|
||||
@@ -71,7 +71,7 @@ off_t os_filesize(int fd);
|
||||
*
|
||||
* @pathname: Pathname of file to open
|
||||
* @flags: Flags, like OS_O_RDONLY, OS_O_RDWR
|
||||
* Return: file descriptor, or -1 on error
|
||||
* Return: file descriptor, or -errno on error
|
||||
*/
|
||||
int os_open(const char *pathname, int flags);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user