Exemplo n.º 1
0
int nxffs_unlink(FAR struct inode *mountpt, FAR const char *relpath)
{
  FAR struct nxffs_volume_s *volume;
  int ret;

  fvdbg("Entry\n");

  /* Sanity checks */

  DEBUGASSERT(mountpt && mountpt->i_private);

  /* Get the mountpoint private data from the NuttX inode structure */

  volume = mountpt->i_private;
  ret = sem_wait(&volume->exclsem);
  if (ret != OK)
    {
      goto errout;
    }

  /* Then remove the NXFFS inode */

  ret = nxffs_rminode(volume, relpath);
  
  sem_post(&volume->exclsem);
errout:
  return ret;
}
Exemplo n.º 2
0
static inline int nxffs_wrclose(FAR struct nxffs_volume_s *volume,
                                FAR struct nxffs_wrfile_s *wrfile)
{
  int ret;

  /* Is there an unfinalized write data? */

  if (wrfile->datlen > 0)
    {
      /* Yes.. Write the final file block header */

      ret = nxffs_wrblkhdr(volume, wrfile);
      if (ret < 0)
        {
          fdbg("ERROR: Failed to write the final block of the file: %d\n", -ret);
          goto errout;
        }
    }

  /* Truncation is implemented by writing the new file, then deleting the
   * older version of the file.  Note that we removed the entry from the
   * open file list earlier in the close sequence; this will prevent the
   * open file check from failing when we remove the old version of the
   * file.
   */

  if (wrfile->truncate && wrfile->ofile.entry.name)
    {
      fvdbg("Removing old file: %s\n", wrfile->ofile.entry.name);

      ret = nxffs_rminode(volume, wrfile->ofile.entry.name);
      if (ret < 0)
        {
          fdbg("ERROR: nxffs_rminode failed: %d\n", -ret);
          goto errout;
        }
    }

  /* Write the inode header to FLASH */

  ret = nxffs_wrinode(volume, &wrfile->ofile.entry);

  /* The volume is now available for other writers */

errout:
  sem_post(&volume->wrsem);
  return ret;
}