From c6436bfdbb6c99d2a2a7ff33c917dc6234ac2d46 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Wed, 11 Aug 2021 12:34:43 +0300 Subject: [PATCH] fsutils/mksmartfs: fix confusing ioctl return value with errno value Signed-off-by: Juha Niskanen --- fsutils/mksmartfs/mksmartfs.c | 38 +++++++++-------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/fsutils/mksmartfs/mksmartfs.c b/fsutils/mksmartfs/mksmartfs.c index 0739c80ca..46f17ef2a 100644 --- a/fsutils/mksmartfs/mksmartfs.c +++ b/fsutils/mksmartfs/mksmartfs.c @@ -38,22 +38,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -129,13 +113,7 @@ out: * nrootdirs - Number of root directory entries to create. * * Return: - * Zero (OK) on success; -1 (ERROR) on failure with errno set: - * - * EINVAL - NULL block driver string, bad number of FATS in 'fmt', bad FAT - * size in 'fmt', bad cluster size in 'fmt' - * ENOENT - 'pathname' does not refer to anything in the filesystem. - * ENOTBLK - 'pathname' does not refer to a block driver - * EACCES - block driver does not support wrie or geometry methods + * Zero (OK) on success; -1 (ERROR) on failure with errno set. * * Assumptions: * - The caller must assure that the block driver is not mounted and not in @@ -158,7 +136,7 @@ int mksmartfs(FAR const char *pathname, uint16_t sectorsize) int x; int ret; - /* Find the inode of the block driver identified by 'source' */ + /* Find the inode of the block driver identified by 'pathname' */ fd = open(pathname, O_RDWR); if (fd < 0) @@ -176,14 +154,20 @@ int mksmartfs(FAR const char *pathname, uint16_t sectorsize) #endif if (ret != OK) { + ret = -errno; goto errout_with_driver; } /* Get the format information so we know how big the sectors are */ ret = ioctl(fd, BIOC_GETFORMAT, (unsigned long) &fmt); + if (ret != OK) + { + ret = -errno; + goto errout_with_driver; + } - /* Now Write the filesystem to media. Loop for each root dir entry and + /* Now write the filesystem to media. Loop for each root dir entry and * allocate the reserved Root Dir Entry, then write a blank root dir for * it. */ @@ -211,7 +195,7 @@ int mksmartfs(FAR const char *pathname, uint16_t sectorsize) /* Issue a write to the sector, single byte */ ret = ioctl(fd, BIOC_WRITESECT, (unsigned long) &request); - if (ret != 0) + if (ret != OK) { ret = -EIO; goto errout_with_driver; @@ -226,8 +210,6 @@ errout_with_driver: errout: - /* Release all allocated memory */ - /* Return any reported errors */ if (ret < 0)