fs/nxffs/nxffs_pack.c: Appease nxstyle

This commit is contained in:
YAMAMOTO Takashi 2020-11-22 09:50:13 +09:00 committed by Xiang Xiao
parent 99407f4ab9
commit 660db6b248

View File

@ -337,7 +337,8 @@ static inline int nxffs_startpos(FAR struct nxffs_volume_s *volume,
*/ */
nbytes += blkentry.datlen; nbytes += blkentry.datlen;
offset = blkentry.hoffset + SIZEOF_NXFFS_DATA_HDR + blkentry.datlen; offset = blkentry.hoffset + SIZEOF_NXFFS_DATA_HDR +
blkentry.datlen;
} }
/* Make sure there is space at this location for an inode header */ /* Make sure there is space at this location for an inode header */
@ -454,10 +455,10 @@ static int nxffs_destsetup(FAR struct nxffs_volume_s *volume,
/* The destination can be in one of three of states: /* The destination can be in one of three of states:
* *
* State 1: The inode position was not yet been found. This condition can * State 1: The inode position was not yet been found. This condition can
* only occur on initial entry into nxffs_packblock() when there we no space * only occur on initial entry into nxffs_packblock() when there we no
* for the inode header at the end of the previous block. We must now be * space for the inode header at the end of the previous block. We must
* at the beginning of a shiny new I/O block, so we should always have * now be at the beginning of a shiny new I/O block, so we should always
* space for a new inode header right here. * have space for a new inode header right here.
*/ */
if (pack->dest.entry.hoffset == 0) if (pack->dest.entry.hoffset == 0)
@ -528,8 +529,8 @@ static int nxffs_destsetup(FAR struct nxffs_volume_s *volume,
pack->iooffset += namlen; pack->iooffset += namlen;
} }
/* State 3: Inode header not-written, inode name written. Still need the position /* State 3: Inode header not-written, inode name written. Still need the
* of the first data block. * position of the first data block.
* *
* Deal with the special case where the source inode is a zero length file * Deal with the special case where the source inode is a zero length file
* with no data blocks to be transferred. * with no data blocks to be transferred.
@ -539,16 +540,16 @@ static int nxffs_destsetup(FAR struct nxffs_volume_s *volume,
{ {
if (pack->dest.entry.doffset == 0) if (pack->dest.entry.doffset == 0)
{ {
/* Will the data block header plus a minimal amount of data fit in this /* Will the data block header plus a minimal amount of data fit in
* block? (or the whole file if the file is very small). * this block? (or the whole file if the file is very small).
*/ */
mindata = MIN(NXFFS_MINDATA, pack->dest.entry.datlen); mindata = MIN(NXFFS_MINDATA, pack->dest.entry.datlen);
if (pack->iooffset + SIZEOF_NXFFS_DATA_HDR + mindata > if (pack->iooffset + SIZEOF_NXFFS_DATA_HDR + mindata >
volume->geo.blocksize) volume->geo.blocksize)
{ {
/* No.. return an indication that we are at the end of the block /* No.. return an indication that we are at the end of the
* and try again later. * block and try again later.
*/ */
ret = -ENOSPC; ret = -ENOSPC;
@ -560,29 +561,31 @@ static int nxffs_destsetup(FAR struct nxffs_volume_s *volume,
pack->dest.entry.doffset = nxffs_packtell(volume, pack); pack->dest.entry.doffset = nxffs_packtell(volume, pack);
pack->iooffset += SIZEOF_NXFFS_DATA_HDR; pack->iooffset += SIZEOF_NXFFS_DATA_HDR;
/* Initialize the output data stream to start with the first data block */ /* Initialize the output data stream to start with the first data
* block
*/
pack->dest.blkoffset = pack->dest.entry.doffset; pack->dest.blkoffset = pack->dest.entry.doffset;
pack->dest.blklen = 0; pack->dest.blklen = 0;
pack->dest.blkpos = 0; pack->dest.blkpos = 0;
} }
/* State 4: Starting a new block. Verify that there is space in the current /* State 4: Starting a new block. Verify that there is space in the
* block for another (minimal sized) block * current block for another (minimal sized) block
*/ */
if (pack->dest.blkoffset == 0) if (pack->dest.blkoffset == 0)
{ {
/* Will the data block header plus a minimal amount of data fit in this /* Will the data block header plus a minimal amount of data fit in
* block? (or the whole file if the file is very small). * this block? (or the whole file if the file is very small).
*/ */
mindata = MIN(NXFFS_MINDATA, pack->dest.entry.datlen); mindata = MIN(NXFFS_MINDATA, pack->dest.entry.datlen);
if (pack->iooffset + SIZEOF_NXFFS_DATA_HDR + mindata > if (pack->iooffset + SIZEOF_NXFFS_DATA_HDR + mindata >
volume->geo.blocksize) volume->geo.blocksize)
{ {
/* No.. return an indication that we are at the end of the block /* No.. return an indication that we are at the end of the
* and try again later. * block and try again later.
*/ */
ret = -ENOSPC; ret = -ENOSPC;
@ -691,7 +694,8 @@ static int nxffs_wrinodehdr(FAR struct nxffs_volume_s *volume,
/* Calculate the CRC */ /* Calculate the CRC */
crc = crc32((FAR const uint8_t *)inode, SIZEOF_NXFFS_INODE_HDR); crc = crc32((FAR const uint8_t *)inode, SIZEOF_NXFFS_INODE_HDR);
crc = crc32part((FAR const uint8_t *)pack->dest.entry.name, namlen, crc); crc = crc32part((FAR const uint8_t *)pack->dest.entry.name, namlen,
crc);
/* Finish the inode header */ /* Finish the inode header */
@ -742,9 +746,9 @@ static void nxffs_wrdathdr(FAR struct nxffs_volume_s *volume,
if (pack->dest.blklen > 0) if (pack->dest.blklen > 0)
{ {
/* Get the offset in the block corresponding to the location of the data /* Get the offset in the block corresponding to the location of the
* block header. NOTE: This must lie in the same block as we currently have * data block header. NOTE: This must lie in the same block as we
* buffered. * currently have buffered.
*/ */
ioblock = nxffs_getblock(volume, pack->dest.blkoffset); ioblock = nxffs_getblock(volume, pack->dest.blkoffset);
@ -928,8 +932,8 @@ static inline int nxffs_packblock(FAR struct nxffs_volume_s *volume,
} }
/* Loop, transferring data from the source block to the destination pack /* Loop, transferring data from the source block to the destination pack
* buffer until either (1) the source stream is exhausted, (2) the destination * buffer until either (1) the source stream is exhausted, (2) the
* block is full, or (3) an error occurs. * destination block is full, or (3) an error occurs.
*/ */
for (; ; ) for (; ; )
@ -962,8 +966,8 @@ static inline int nxffs_packblock(FAR struct nxffs_volume_s *volume,
ret = nxffs_nextentry(volume, offset, &pack->src.entry); ret = nxffs_nextentry(volume, offset, &pack->src.entry);
if (ret < 0) if (ret < 0)
{ {
/* No more valid inode entries. Just return an end-of-flash error /* No more valid inode entries. Just return an end-of-flash
* indication. * error indication.
*/ */
return -ENOSPC; return -ENOSPC;
@ -989,10 +993,11 @@ static inline int nxffs_packblock(FAR struct nxffs_volume_s *volume,
* the inode header? * the inode header?
*/ */
if (pack->iooffset + SIZEOF_NXFFS_INODE_HDR > volume->geo.blocksize) if (pack->iooffset + SIZEOF_NXFFS_INODE_HDR >
volume->geo.blocksize)
{ {
/* No, just return success... we will handle this condition when /* No, just return success... we will handle this condition
* this function is called on the next I/O block. * when this function is called on the next I/O block.
*/ */
return OK; return OK;
@ -1003,9 +1008,9 @@ static inline int nxffs_packblock(FAR struct nxffs_volume_s *volume,
ret = nxffs_destsetup(volume, pack); ret = nxffs_destsetup(volume, pack);
if (ret < 0) if (ret < 0)
{ {
/* -ENOSPC is a special return value which simply means that all of the /* -ENOSPC is a special return value which simply means that
* has been used up to the end. We need to return OK in this case and * all of the has been used up to the end. We need to return
* resume at the next block. * OK in this case and resume at the next block.
*/ */
if (ret == -ENOSPC) if (ret == -ENOSPC)
@ -1014,7 +1019,8 @@ static inline int nxffs_packblock(FAR struct nxffs_volume_s *volume,
} }
else else
{ {
ferr("ERROR: Failed to configure the dest stream: %d\n", -ret); ferr("ERROR: Failed to configure the dest stream: %d\n",
-ret);
return ret; return ret;
} }
} }
@ -1037,7 +1043,9 @@ static inline int nxffs_packblock(FAR struct nxffs_volume_s *volume,
if (pack->iooffset >= volume->geo.blocksize) if (pack->iooffset >= volume->geo.blocksize)
{ {
/* Yes.. Write the destination data block header and return success */ /* Yes.. Write the destination data block header and return
* success
*/
nxffs_wrdathdr(volume, pack); nxffs_wrdathdr(volume, pack);
return OK; return OK;
@ -1081,10 +1089,10 @@ nxffs_setupwriter(FAR struct nxffs_volume_s *volume,
* this packing activity. The writer may have failed in one of several * this packing activity. The writer may have failed in one of several
* different stages: * different stages:
* *
* hoffset == 0: The write failed early before even FLASH for the inode * hoffset == 0: The write failed early before even FLASH for the
* header was set aside. * inode header was set aside.
* noffset == 0: The write failed after the inode header was set aside, * noffset == 0: The write failed after the inode header was set
* but before the inode name was written. * aside, but before the inode name was written.
* doffset == 0: The write failed after writing the inode name, bue * doffset == 0: The write failed after writing the inode name, bue
* before any data blocks were written to FLASH. * before any data blocks were written to FLASH.
* *
@ -1182,8 +1190,8 @@ static inline int nxffs_packwriter(FAR struct nxffs_volume_s *volume,
} }
/* Loop, transferring data from the source block to the destination pack /* Loop, transferring data from the source block to the destination pack
* buffer until either (1) the source stream is exhausted, (2) the destination * buffer until either (1) the source stream is exhausted, (2) the
* block is full, or (3) an error occurs. * destination block is full, or (3) an error occurs.
*/ */
for (; ; ) for (; ; )
@ -1237,7 +1245,9 @@ static inline int nxffs_packwriter(FAR struct nxffs_volume_s *volume,
if (pack->iooffset >= volume->geo.blocksize) if (pack->iooffset >= volume->geo.blocksize)
{ {
/* Yes.. Write the destination data block header and return success */ /* Yes.. Write the destination data block header and return
* success
*/
nxffs_wrdathdr(volume, pack); nxffs_wrdathdr(volume, pack);
return OK; return OK;
@ -1287,10 +1297,10 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
if (iooffset == 0) if (iooffset == 0)
{ {
/* Offset zero is only returned if no valid blocks were found on the /* Offset zero is only returned if no valid blocks were found on the
* FLASH media or if there are no valid inode entries on the FLASH after * FLASH media or if there are no valid inode entries on the FLASH
* the first valid block. There are two possibilities: (1) there * after the first valid block. There are two possibilities: (1)
* really is nothing on the FLASH, or (2) there is a file being written * there* really is nothing on the FLASH, or (2) there is a file being
* to the FLASH now. * written to the FLASH now.
*/ */
/* Is there a writer? */ /* Is there a writer? */
@ -1350,11 +1360,12 @@ int nxffs_pack(FAR struct nxffs_volume_s *volume)
if (ret == -ENOSPC) if (ret == -ENOSPC)
{ {
/* In the case where the volume is full, nxffs_startpos() will /* In the case where the volume is full, nxffs_startpos() will
* recalculate the free FLASH offset and store it in iooffset. There * recalculate the free FLASH offset and store it in iooffset.
* may be deleted files at the end of FLASH. In this case, we don't * There may be deleted files at the end of FLASH. In this case,
* have to pack any files, we simply have to erase FLASH at the end. * we don't have to pack any files, we simply have to erase FLASH
* But don't do this unless there is some particularly big FLASH * at the end. But don't do this unless there is some particularly
* savings (otherwise, we risk wearing out these final blocks). * big FLASH savings (otherwise, we risk wearing out these final
* blocks).
*/ */
if (iooffset + CONFIG_NXFFS_TAILTHRESHOLD < volume->froffset) if (iooffset + CONFIG_NXFFS_TAILTHRESHOLD < volume->froffset)
@ -1419,7 +1430,8 @@ start_pack:
* previously marked bad blocks. * previously marked bad blocks.
*/ */
ret = MTD_BREAD(volume->mtd, pack.block0, volume->blkper, volume->pack); ret = MTD_BREAD(volume->mtd, pack.block0, volume->blkper,
volume->pack);
if (ret < 0) if (ret < 0)
{ {
ferr("ERROR: Failed to read erase block %d: %d\n", eblock, -ret); ferr("ERROR: Failed to read erase block %d: %d\n", eblock, -ret);
@ -1498,7 +1510,8 @@ start_pack:
if (ret < 0) if (ret < 0)
{ {
/* The error -ENOSPC is a special value that simply /* The error -ENOSPC is a special value that simply
* means that there is nothing further to be packed. * means that there is nothing further to be
* packed.
*/ */
if (ret == -ENOSPC) if (ret == -ENOSPC)
@ -1506,10 +1519,11 @@ start_pack:
packed = true; packed = true;
/* Writing is performed at the end of the free /* Writing is performed at the end of the free
* FLASH region and this implementation is restricted * FLASH region and this implementation is
* to a single writer. The new inode is not * restricted to a single writer. The new
* written to FLASH until the writer is closed * inode is not written to FLASH until the
* and so will not be found by nxffs_packblock(). * writer is closed and so will not be found
* by nxffs_packblock().
*/ */
wrfile = nxffs_setupwriter(volume, &pack); wrfile = nxffs_setupwriter(volume, &pack);
@ -1518,15 +1532,17 @@ start_pack:
{ {
/* Otherwise, something really bad happened */ /* Otherwise, something really bad happened */
ferr("ERROR: Failed to pack into block %d: %d\n", ferr("ERROR: Failed to pack into block %d: "
"%d\n",
block, ret); block, ret);
goto errout_with_pack; goto errout_with_pack;
} }
} }
} }
/* If all of the "normal" inodes have been packed, then check if /* If all of the "normal" inodes have been packed, then
* we need to pack the current, in-progress write operation. * check if we need to pack the current, in-progress write
* operation.
*/ */
if (wrfile) if (wrfile)
@ -1539,7 +1555,8 @@ start_pack:
if (ret < 0) if (ret < 0)
{ {
/* The error -ENOSPC is a special value that simply /* The error -ENOSPC is a special value that simply
* means that there is nothing further to be packed. * means that there is nothing further to be
* packed.
*/ */
if (ret == -ENOSPC) if (ret == -ENOSPC)
@ -1550,7 +1567,8 @@ start_pack:
{ {
/* Otherwise, something really bad happened */ /* Otherwise, something really bad happened */
ferr("ERROR: Failed to pack into block %d: %d\n", ferr("ERROR: Failed to pack into block %d: "
"%d\n",
block, ret); block, ret);
goto errout_with_pack; goto errout_with_pack;
} }
@ -1591,7 +1609,8 @@ start_pack:
/* Write the packed I/O block to FLASH */ /* Write the packed I/O block to FLASH */
ret = MTD_BWRITE(volume->mtd, pack.block0, volume->blkper, volume->pack); ret = MTD_BWRITE(volume->mtd, pack.block0, volume->blkper,
volume->pack);
if (ret < 0) if (ret < 0)
{ {
ferr("ERROR: Failed to write erase block %d [%d]: %d\n", ferr("ERROR: Failed to write erase block %d [%d]: %d\n",