This is an automated email from the ASF dual-hosted git repository.

ligd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4ebcc130b91862eaeb7657381ba85ca1325d2669
Author: Xiang Xiao <[email protected]>
AuthorDate: Sun Jul 28 15:25:24 2024 +0800

    fs/romfs: Remove the reference to OK and ERROR
    
    and fix the minor style issue
    
    Signed-off-by: Xiang Xiao <[email protected]>
---
 fs/romfs/fs_romfs.c     | 72 ++++++++++++++++++++++---------------------
 fs/romfs/fs_romfsutil.c | 81 ++++++++++++++++++++++++-------------------------
 2 files changed, 78 insertions(+), 75 deletions(-)

diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c
index 3cbcddf287..54ac0adcf4 100644
--- a/fs/romfs/fs_romfs.c
+++ b/fs/romfs/fs_romfs.c
@@ -188,7 +188,7 @@ static int romfs_open(FAR struct file *filep, FAR const 
char *relpath,
     }
 
   ret = romfs_checkmount(rm);
-  if (ret != OK)
+  if (ret < 0)
     {
       ferr("ERROR: romfs_checkmount failed: %d\n", ret);
       goto errout_with_lock;
@@ -394,7 +394,7 @@ static ssize_t romfs_read(FAR struct file *filep, FAR char 
*buffer,
     }
 
   ret = romfs_checkmount(rm);
-  if (ret != OK)
+  if (ret < 0)
     {
       ferr("ERROR: romfs_checkmount failed: %d\n", ret);
       goto errout_with_lock;
@@ -553,7 +553,7 @@ static off_t romfs_seek(FAR struct file *filep, off_t 
offset, int whence)
     }
 
   ret = romfs_checkmount(rm);
-  if (ret != OK)
+  if (ret < 0)
     {
        ferr("ERROR: romfs_checkmount failed: %d\n", ret);
        goto errout_with_lock;
@@ -596,14 +596,12 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 
   rf = filep->f_priv;
 
-  /* Only one ioctl command is supported */
-
   if (cmd == FIOC_FILEPATH)
     {
       FAR char *ptr = (FAR char *)((uintptr_t)arg);
       inode_getpath(filep->f_inode, ptr, PATH_MAX);
       strlcat(ptr, rf->rf_path, PATH_MAX);
-      return OK;
+      return 0;
     }
   else if (cmd == FIOC_XIPBASE)
     {
@@ -613,7 +611,7 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
       if (rm->rm_xipbase != 0)
         {
           *ptr = (uintptr_t)rm->rm_xipbase + rf->rf_startoffset;
-          return OK;
+          return 0;
         }
       else
         {
@@ -646,7 +644,7 @@ static int romfs_mmap(FAR struct file *filep, FAR struct 
mm_map_entry_s *map)
       map->length != 0 && map->offset + map->length <= rf->rf_size)
     {
       map->vaddr = rm->rm_xipbase + rf->rf_startoffset + map->offset;
-      return OK;
+      return 0;
     }
 
   return -ENOTTY;
@@ -688,7 +686,7 @@ static int romfs_dup(FAR const struct file *oldp, FAR 
struct file *newp)
     }
 
   ret = romfs_checkmount(rm);
-  if (ret != OK)
+  if (ret < 0)
     {
       ferr("ERROR: romfs_checkmount failed: %d\n", ret);
       goto errout_with_lock;
@@ -731,7 +729,6 @@ static int romfs_dup(FAR const struct file *oldp, FAR 
struct file *newp)
   /* Attach the new private date to the new struct file instance */
 
   newp->f_priv = newrf;
-
   rm->rm_refs++;
 
 errout_with_lock:
@@ -742,7 +739,7 @@ errout_with_lock:
 /****************************************************************************
  * Name: romfs_fstat
  *
- * Description:
+ * Description
  *   Obtain information about an open file associated with the file
  *   descriptor 'fd', and will write it to the area pointed to by 'buf'.
  *
@@ -792,7 +789,7 @@ static int romfs_fstat(FAR const struct file *filep, FAR 
struct stat *buf)
 /****************************************************************************
  * Name: romfs_opendir
  *
- * Description:
+ * Description
  *   Open a directory for read access
  *
  ****************************************************************************/
@@ -830,7 +827,7 @@ static int romfs_opendir(FAR struct inode *mountpt, FAR 
const char *relpath,
     }
 
   ret = romfs_checkmount(rm);
-  if (ret != OK)
+  if (ret < 0)
     {
       ferr("ERROR: romfs_checkmount failed: %d\n", ret);
       goto errout_with_lock;
@@ -868,7 +865,7 @@ static int romfs_opendir(FAR struct inode *mountpt, FAR 
const char *relpath,
 
   *dir = &rdir->base;
   nxrmutex_unlock(&rm->rm_lock);
-  return OK;
+  return 0;
 
 errout_with_lock:
   nxrmutex_unlock(&rm->rm_lock);
@@ -881,7 +878,8 @@ errout_with_rdir:
 /****************************************************************************
  * Name: romfs_closedir
  *
- * Description: Close the directory
+ * Description
+ *   Close the directory
  *
  ****************************************************************************/
 
@@ -896,7 +894,8 @@ static int romfs_closedir(FAR struct inode *mountpt,
 /****************************************************************************
  * Name: romfs_readdir
  *
- * Description: Read the next directory entry
+ * Description
+ *   Read the next directory entry
  *
  ****************************************************************************/
 
@@ -934,7 +933,7 @@ static int romfs_readdir(FAR struct inode *mountpt,
     }
 
   ret = romfs_checkmount(rm);
-  if (ret != OK)
+  if (ret < 0)
     {
       ferr("ERROR: omfs_checkmount failed: %d\n", ret);
       goto errout_with_lock;
@@ -1019,7 +1018,8 @@ errout_with_lock:
 /****************************************************************************
  * Name: romfs_rewindir
  *
- * Description: Reset directory read to the first entry
+ * Description
+ *   Reset directory read to the first entry
  *
  ****************************************************************************/
 
@@ -1050,7 +1050,7 @@ static int romfs_rewinddir(FAR struct inode *mountpt,
     }
 
   ret = romfs_checkmount(rm);
-  if (ret == OK)
+  if (ret >= 0)
     {
 #ifdef CONFIG_FS_ROMFS_CACHE_NODE
       rdir->currnode = rdir->firstnode;
@@ -1066,11 +1066,12 @@ static int romfs_rewinddir(FAR struct inode *mountpt,
 /****************************************************************************
  * Name: romfs_bind
  *
- * Description: This implements a portion of the mount operation. This
- *  function allocates and initializes the mountpoint private data and
- *  binds the blockdriver inode to the filesystem private data.  The final
- *  binding of the private data (containing the blockdriver) to the
- *  mountpoint is performed by mount().
+ * Description
+ *   This implements a portion of the mount operation. This
+ *   function allocates and initializes the mountpoint private data and
+ *   binds the blockdriver inode to the filesystem private data.  The final
+ *   binding of the private data (containing the blockdriver) to the
+ *   mountpoint is performed by mount().
  *
  ****************************************************************************/
 
@@ -1091,7 +1092,7 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR 
const void *data,
     }
 
   if (blkdriver->u.i_bops->open != NULL &&
-      (ret = blkdriver->u.i_bops->open(blkdriver)) != OK)
+      (ret = blkdriver->u.i_bops->open(blkdriver)) < 0)
     {
       ferr("ERROR: No open method\n");
       return ret;
@@ -1108,7 +1109,7 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR 
const void *data,
     }
 
   /* Initialize the allocated mountpt state structure.  The filesystem is
-   * responsible for one reference ont the blkdriver inode and does not
+   * responsible for one reference on the blkdriver inode and does not
    * have to addref() here (but does have to release in ubind().
    */
 
@@ -1171,7 +1172,7 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR 
const void *data,
   /* Mounted! */
 
   *handle = rm;
-  return OK;
+  return 0;
 
 errout_with_buffer:
   fs_heap_free(rm->rm_devbuffer);
@@ -1192,7 +1193,8 @@ errout:
 /****************************************************************************
  * Name: romfs_unbind
  *
- * Description: This implements the filesystem portion of the umount
+ * Description
+ *   This implements the filesystem portion of the umount
  *   operation.
  *
  ****************************************************************************/
@@ -1271,7 +1273,7 @@ static int romfs_unbind(FAR void *handle, FAR struct 
inode **blkdriver,
 #endif
       nxrmutex_destroy(&rm->rm_lock);
       fs_heap_free(rm);
-      return OK;
+      return 0;
     }
 
   nxrmutex_unlock(&rm->rm_lock);
@@ -1281,7 +1283,8 @@ static int romfs_unbind(FAR void *handle, FAR struct 
inode **blkdriver,
 /****************************************************************************
  * Name: romfs_statfs
  *
- * Description: Return filesystem statistics
+ * Description
+ *   Return filesystem statistics
  *
  ****************************************************************************/
 
@@ -1339,7 +1342,7 @@ errout_with_lock:
 /****************************************************************************
  * Name: romfs_stat_common
  *
- * Description:
+ * Description
  *   Return information about a file or directory
  *
  ****************************************************************************/
@@ -1389,13 +1392,14 @@ static int romfs_stat_common(uint8_t type, uint32_t 
size,
   buf->st_size    = size;
   buf->st_blksize = sectorsize;
   buf->st_blocks  = (buf->st_size + sectorsize - 1) / sectorsize;
-  return OK;
+  return 0;
 }
 
 /****************************************************************************
  * Name: romfs_stat
  *
- * Description: Return information about a file or directory
+ * Description
+ *   Return information about a file or directory
  *
  ****************************************************************************/
 
@@ -1426,7 +1430,7 @@ static int romfs_stat(FAR struct inode *mountpt, FAR 
const char *relpath,
     }
 
   ret = romfs_checkmount(rm);
-  if (ret != OK)
+  if (ret < 0)
     {
       ferr("ERROR: romfs_checkmount failed: %d\n", ret);
       goto errout_with_lock;
diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c
index c8d73dc786..d597d157ae 100644
--- a/fs/romfs/fs_romfsutil.c
+++ b/fs/romfs/fs_romfsutil.c
@@ -25,14 +25,13 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
-#include <sys/types.h>
 
+#include <sys/types.h>
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
-#include <assert.h>
 #include <debug.h>
 
 #include <nuttx/kmalloc.h>
@@ -147,7 +146,7 @@ static inline int romfs_checkentry(FAR struct 
romfs_mountpt_s *rm,
         }
 
       nodeinfo->rn_next       = next;
-      return OK;
+      return 0;
     }
 
   /* The entry is not a directory or it does not have the matching name */
@@ -318,7 +317,7 @@ static int romfs_nodeinfo_compare(FAR const void *a, FAR 
const void *b)
  * Name: romfs_searchdir
  *
  * Description:
- *   This is part of the romfs_finddirentry log.  Search the directory
+ *   This is part of the romfs_finddirentry.  Search the directory
  *   beginning at nodeinfo->rn_offset for entryname.
  *
  ****************************************************************************/
@@ -338,7 +337,7 @@ static inline int romfs_searchdir(FAR struct 
romfs_mountpt_s *rm,
   if (cnodeinfo)
     {
       memcpy(nodeinfo, *cnodeinfo, sizeof(*nodeinfo));
-      return OK;
+      return 0;
     }
 #else
   uint32_t offset;
@@ -352,6 +351,7 @@ static inline int romfs_searchdir(FAR struct 
romfs_mountpt_s *rm,
    */
 
   offset = nodeinfo->rn_offset;
+
   do
     {
       /* Read the sector into memory (do this before calling
@@ -376,11 +376,11 @@ static inline int romfs_searchdir(FAR struct 
romfs_mountpt_s *rm,
        */
 
       ret = romfs_checkentry(rm, offset, entryname, entrylen, nodeinfo);
-      if (ret == OK)
+      if (ret >= 0)
         {
           /* Its a match! Return success */
 
-          return OK;
+          return ret;
         }
 
       /* No match... select the offset to the next entry */
@@ -510,8 +510,7 @@ static int romfs_alloc_spareregion(FAR struct list_node 
*list,
 
   /* Not found */
 
-  ferr("No space for start %" PRIu32 ", end %" PRIu32 "\n", start,
-        end);
+  ferr("No space for start %" PRIu32 ", end %" PRIu32 "\n", start, end);
   return -ENOENT;
 }
 
@@ -555,7 +554,7 @@ static int romfs_hwwrite(FAR struct romfs_mountpt_s *rm, 
FAR uint8_t *buffer,
 
   if (ret == (ssize_t)nsectors)
     {
-      ret = OK;
+      ret = 0;
     }
 
   return ret;
@@ -575,7 +574,7 @@ static int romfs_devcachewrite(FAR struct romfs_mountpt_s 
*rm,
   int ret;
 
   ret = romfs_hwwrite(rm, rm->rm_devbuffer, sector, 1);
-  if (ret == OK)
+  if (ret >= 0)
     {
       rm->rm_cachesector = sector;
     }
@@ -653,6 +652,7 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm,
 
   origoffset = offset;
   child = nodeinfo->rn_child;
+
   do
     {
       /* Fetch the directory entry at this offset */
@@ -730,7 +730,7 @@ static int romfs_cachenode(FAR struct romfs_mountpt_s *rm,
 int romfs_hwread(FAR struct romfs_mountpt_s *rm, FAR uint8_t *buffer,
                  uint32_t sector, unsigned int nsectors)
 {
-  int ret = OK;
+  int ret = 0;
 
   /* Check the access mode */
 
@@ -750,13 +750,13 @@ int romfs_hwread(FAR struct romfs_mountpt_s *rm, FAR 
uint8_t *buffer,
       ssize_t nsectorsread =
         inode->u.i_bops->read(inode, buffer, sector, nsectors);
 
-      if (nsectorsread == (ssize_t)nsectors)
+      if (nsectorsread < 0)
         {
-          ret = OK;
+          ret = nsectorsread;
         }
-      else if (nsectorsread < 0)
+      else if (nsectorsread != (ssize_t)nsectors)
         {
-          ret = nsectorsread;
+          ret = -EINVAL;
         }
     }
 
@@ -823,7 +823,7 @@ int romfs_filecacheread(FAR struct romfs_mountpt_s *rm,
       rf->rf_cachesector = sector;
     }
 
-  return OK;
+  return 0;
 }
 
 /****************************************************************************
@@ -853,7 +853,7 @@ int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm)
 #endif
 
   ret = inode->u.i_bops->geometry(inode, &geo);
-  if (ret != OK)
+  if (ret < 0)
     {
       return ret;
     }
@@ -867,10 +867,7 @@ int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm)
 
   rm->rm_hwsectorsize = geo.geo_sectorsize;
   rm->rm_hwnsectors   = geo.geo_nsectors;
-
-  /* Determine if block driver supports the XIP mode of operation */
-
-  rm->rm_cachesector = (uint32_t)-1;
+  rm->rm_cachesector  = (uint32_t)-1;
 
   /* Allocate the device cache buffer for normal sector accesses */
 
@@ -880,11 +877,13 @@ int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm)
       return -ENOMEM;
     }
 
+  /* Determine if block driver supports the XIP mode of operation */
+
   if (inode->u.i_bops->ioctl)
     {
       ret = inode->u.i_bops->ioctl(inode, BIOC_XIPBASE,
                                    (unsigned long)&rm->rm_xipbase);
-      if (ret == OK && rm->rm_xipbase)
+      if (ret >= 0 && rm->rm_xipbase)
         {
           /* Yes.. Then we will directly access the media (vs.
            * copying into an allocated sector buffer.
@@ -892,14 +891,14 @@ int romfs_hwconfigure(FAR struct romfs_mountpt_s *rm)
 
           rm->rm_buffer      = rm->rm_xipbase;
           rm->rm_cachesector = 0;
-          return OK;
+          return 0;
         }
     }
 
   /* The device cache buffer for normal sector accesses */
 
   rm->rm_buffer = rm->rm_devbuffer;
-  return OK;
+  return 0;
 }
 
 /****************************************************************************
@@ -991,7 +990,7 @@ int romfs_fsconfigure(FAR struct romfs_mountpt_s *rm, FAR 
const void *data)
   /* and return success */
 
   rm->rm_mounted = true;
-  return OK;
+  return 0;
 }
 
 /****************************************************************************
@@ -1045,7 +1044,7 @@ int romfs_fileconfigure(FAR struct romfs_mountpt_s *rm,
         }
     }
 
-  return OK;
+  return 0;
 }
 
 /****************************************************************************
@@ -1063,7 +1062,7 @@ int romfs_checkmount(FAR struct romfs_mountpt_s *rm)
   struct geometry geo;
   int ret;
 
-  /* If the fs_mounted flag is false, then we have already handled the loss
+  /* If the rm_mounted flag is false, then we have already handled the loss
    * of the mount.
    */
 
@@ -1078,9 +1077,9 @@ int romfs_checkmount(FAR struct romfs_mountpt_s *rm)
       if (inode->u.i_bops->geometry)
         {
           ret = inode->u.i_bops->geometry(inode, &geo);
-          if (ret == OK && geo.geo_available && !geo.geo_mediachanged)
+          if (ret >= 0 && geo.geo_available && !geo.geo_mediachanged)
             {
-              return OK;
+              return 0;
             }
         }
 
@@ -1151,7 +1150,7 @@ int romfs_finddirentry(FAR struct romfs_mountpt_s *rm,
 
   if (!path || path[0] == '\0')
     {
-      return OK;
+      return 0;
     }
 
   /* Then loop for each directory/file component in the full path */
@@ -1179,7 +1178,7 @@ int romfs_finddirentry(FAR struct romfs_mountpt_s *rm,
 
       if (entrylen == 0)
         {
-          return OK;
+          return 0;
         }
 
       /* Long path segment names will be truncated to NAME_MAX */
@@ -1205,7 +1204,7 @@ int romfs_finddirentry(FAR struct romfs_mountpt_s *rm,
         {
           /* Yes.. return success */
 
-          return OK;
+          return 0;
         }
 
       /* No... If that was not the last path component, then it had
@@ -1224,7 +1223,7 @@ int romfs_finddirentry(FAR struct romfs_mountpt_s *rm,
       entryname = terminator;
     }
 
-  return ERROR; /* Won't get here */
+  return -EINVAL; /* Won't get here */
 }
 
 /****************************************************************************
@@ -1292,7 +1291,7 @@ int romfs_parsedirentry(FAR struct romfs_mountpt_s *rm, 
uint32_t offset,
   *pinfo = romfs_devread32(rm, ndx + ROMFS_FHDR_INFO);
   *psize = romfs_devread32(rm, ndx + ROMFS_FHDR_SIZE);
 
-  return OK;
+  return 0;
 }
 
 /****************************************************************************
@@ -1307,16 +1306,16 @@ int romfs_parsefilename(FAR struct romfs_mountpt_s *rm, 
uint32_t offset,
                         FAR char *pname)
 {
   int16_t  ndx;
-  uint16_t namelen;
+  uint16_t namelen = 0;
   uint16_t chunklen;
-  bool     done;
+  bool     done = false;
 
   /* Loop until the whole name is obtained or until NAME_MAX characters
    * of the name have been parsed.
    */
 
   offset += ROMFS_FHDR_NAME;
-  for (namelen = 0, done = false; namelen < NAME_MAX && !done; )
+  while (namelen < NAME_MAX && !done)
     {
       /* Read the sector into memory */
 
@@ -1359,7 +1358,7 @@ int romfs_parsefilename(FAR struct romfs_mountpt_s *rm, 
uint32_t offset,
   /* Terminate the name (NAME_MAX+1 chars total) and return success */
 
   pname[namelen] = '\0';
-  return OK;
+  return 0;
 }
 
 /****************************************************************************
@@ -1378,7 +1377,7 @@ int romfs_datastart(FAR struct romfs_mountpt_s *rm,
 #ifdef CONFIG_FS_ROMFS_CACHE_NODE
   *start = ROMFS_ALIGNUP(nodeinfo->rn_offset +
                          ROMFS_FHDR_NAME + nodeinfo->rn_namesize + 1);
-  return OK;
+  return 0;
 #else
   uint32_t offset = nodeinfo->rn_offset;
   int16_t ndx;
@@ -1411,7 +1410,7 @@ int romfs_datastart(FAR struct romfs_mountpt_s *rm,
           /* Yes.. then the data starts at the next chunk */
 
           *start = offset;
-          return OK;
+          return 0;
         }
     }
 

Reply via email to