mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 14:49:22 +08:00
Add file creation logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3542 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+2
-2
@@ -37,8 +37,8 @@ ifeq ($(CONFIG_FS_NXFFS),y)
|
||||
ASRCS +=
|
||||
CSRCS += nxffs_block.c nxffs_blockstats.c nxffs_cache.c nxffs_dirent.c \
|
||||
nxffs_initialize.c nxffs_inode.c nxffs_ioctl.c nxffs_open.c \
|
||||
nxffs_read.c nxffs_reformat.c nxffs_stat.c nxffs_unlink.c \
|
||||
nxffs_util.c nxffs_write.c
|
||||
nxffs_pack.c nxffs_read.c nxffs_reformat.c nxffs_stat.c \
|
||||
nxffs_unlink.c nxffs_util.c nxffs_write.c
|
||||
|
||||
# Argument for dependency checking
|
||||
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ actual relationship is determined by the FLASH geometry reported by the MTD
|
||||
driver.
|
||||
|
||||
ERASE LOGICAL Inodes begin with a inode header. inode may
|
||||
BLOCK BLOCK CONTENTS be marked as "deleted," pending clean-up.
|
||||
BLOCK BLOCK CONTENTS be marked as "deleted," pending re-packing.
|
||||
n 4*n --+--------------+
|
||||
|BBBBBBBBBBBBBB| Logic block header
|
||||
|IIIIIIIIIIIIII| Inodes begin with a inode header
|
||||
@@ -42,7 +42,7 @@ General operation
|
||||
supporting wear leveling by using all FLASH blocks equally.
|
||||
|
||||
When the FLASH becomes full (no more space at the end of the FLASH), a
|
||||
clean-up operation must be performed: All inodes marked deleted are
|
||||
re-packing operation must be performed: All inodes marked deleted are
|
||||
finally removed and the remaining inodes are packed at the beginning of
|
||||
the FLASH. Allocations then continue at the freed FLASH memory at the
|
||||
end of the FLASH.
|
||||
@@ -89,7 +89,7 @@ that you should be aware before opting to use NXFFS:
|
||||
5. Files may be opened for reading or for writing, but not both: The O_RDWR
|
||||
open flag is not supported.
|
||||
|
||||
6. The clean-up process occurs only during a write when the free FLASH
|
||||
6. The re-packing process occurs only during a write when the free FLASH
|
||||
memory at the end of the FLASH is exhausted. Thus, occasionally, file
|
||||
writing may take a long time.
|
||||
|
||||
|
||||
+245
-64
@@ -61,7 +61,7 @@
|
||||
* the FLASH geometry reported by the MTD driver.
|
||||
*
|
||||
* ERASE LOGICAL Inodes begin with a inode header. inode may
|
||||
* BLOCK BLOCK CONTENTS be marked as "deleted," pending clean-up.
|
||||
* BLOCK BLOCK CONTENTS be marked as "deleted," pending re-packing.
|
||||
* n 4*n --+--------------+
|
||||
* |BBBBBBBBBBBBBB| Logic block header
|
||||
* |IIIIIIIIIIIIII| Inodes begin with a inode header
|
||||
@@ -95,7 +95,7 @@
|
||||
* supporting wear leveling by using all FLASH blocks equally.
|
||||
*
|
||||
* When the FLASH becomes full (no more space at the end of the FLASH), a
|
||||
* clean-up operation must be performed: All inodes marked deleted are
|
||||
* re-packing operation must be performed: All inodes marked deleted are
|
||||
* finally removed and the remaining inodes are packed at the beginning of
|
||||
* the FLASH. Allocations then continue at the freed FLASH memory at the
|
||||
* end of the FLASH.
|
||||
@@ -130,7 +130,7 @@
|
||||
* string providing some illusion of directories.
|
||||
* 5. Files may be opened for reading or for writing, but not both: The O_RDWR
|
||||
* open flag is not supported.
|
||||
* 6. The clean-up process occurs only during a write when the free FLASH
|
||||
* 6. The re-packing process occurs only during a write when the free FLASH
|
||||
* memory at the end of the FLASH is exhausted. Thus, occasionally, file
|
||||
* writing may take a long time.
|
||||
* 7. Another limitation is that there can be only a single NXFFS volume
|
||||
@@ -175,7 +175,7 @@
|
||||
* flash beyond this point is erased.
|
||||
*/
|
||||
|
||||
#define NXFFS_NERASED 128
|
||||
#define NXFFS_NERASED 128
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
@@ -185,8 +185,8 @@
|
||||
|
||||
struct nxffs_block_s
|
||||
{
|
||||
uint8_t magic[4]; /* 0-3: Magic number for valid block */
|
||||
uint8_t state; /* 4: Block state: See BLOCK_STATE_* */
|
||||
uint8_t magic[4]; /* 0-3: Magic number for valid block */
|
||||
uint8_t state; /* 4: Block state: See BLOCK_STATE_* */
|
||||
};
|
||||
#define SIZEOF_NXFFS_BLOCK_HDR 5
|
||||
|
||||
@@ -194,25 +194,25 @@ struct nxffs_block_s
|
||||
|
||||
struct nxffs_inode_s
|
||||
{
|
||||
uint8_t magic[4]; /* 0-3: Magic number for valid inode */
|
||||
uint8_t state; /* 4: Inode state: See INODE_STATE_* */
|
||||
uint8_t noffset; /* 5: Offset to the file name from the header */
|
||||
uint8_t doffset; /* 5: Offset to data from file header */
|
||||
uint8_t utc[4]; /* 7-9: Creation time */
|
||||
uint8_t crc[4]; /* 10-13: CRC32 */
|
||||
uint8_t datlen[4]; /* 14-17: Length of data in bytes */
|
||||
/* 18-: Variable length file name follows */
|
||||
uint8_t magic[4]; /* 0-3: Magic number for valid inode */
|
||||
uint8_t state; /* 4: Inode state: See INODE_STATE_* */
|
||||
uint8_t namlen; /* 5: Length of the inode name */
|
||||
uint8_t noffs[4]; /* 6-9: FLASH offset to the file name */
|
||||
uint8_t doffs[4]; /* 10-13: FLASH offset to the first data block */
|
||||
uint8_t utc[4]; /* 14-17: Creation time */
|
||||
uint8_t crc[4]; /* 18-21: CRC32 */
|
||||
uint8_t datlen[4]; /* 22-25: Length of data in bytes */
|
||||
};
|
||||
#define SIZEOF_NXFFS_INODE_HDR 18
|
||||
#define SIZEOF_NXFFS_INODE_HDR 26
|
||||
|
||||
/* This structure defines each packed NXFFS data header on the FLASH media */
|
||||
|
||||
struct nxffs_data_s
|
||||
{
|
||||
uint8_t magic[4]; /* 0-3: Magic number for valid data */
|
||||
uint8_t crc[4]; /* 4-7: CRC32 */
|
||||
uint8_t datlen[4]; /* 8-11: Length of data in bytes */
|
||||
/* 12-: Variable length data follows */
|
||||
uint8_t magic[4]; /* 0-3: Magic number for valid data */
|
||||
uint8_t crc[4]; /* 4-7: CRC32 */
|
||||
uint8_t datlen[4]; /* 8-11: Length of data in bytes */
|
||||
/* 12-: Variable length data follows */
|
||||
};
|
||||
#define SIZEOF_NXFFS_DATA_HDR 12
|
||||
|
||||
@@ -222,29 +222,12 @@ struct nxffs_data_s
|
||||
|
||||
struct nxffs_entry_s
|
||||
{
|
||||
off_t hoffset; /* Offset to the inode on the media */
|
||||
off_t doffset; /* Offset to the data on the media */
|
||||
FAR char *name; /* inode name */
|
||||
uint32_t utc; /* Time stamp */
|
||||
uint32_t datlen; /* Length of inode data */
|
||||
};
|
||||
|
||||
/* This structure represents the overall state of on NXFFS instance. */
|
||||
|
||||
struct nxffs_volume_s
|
||||
{
|
||||
FAR struct mtd_dev_s *mtd; /* Supports FLASH access */
|
||||
sem_t exclsem; /* Used to assure thread-safe access */
|
||||
struct mtd_geometry_s geo; /* Device geometry */
|
||||
uint8_t wrbusy: 1; /* 1: Volume open for writing */
|
||||
uint8_t blkper; /* R/W blocks per erase block */
|
||||
uint8_t ncached; /* Number of blocks in cache */
|
||||
uint16_t iooffset; /* Next offset in read/write access (in ioblock) */
|
||||
off_t inoffset; /* Offset to the first valid inode header */
|
||||
off_t froffset; /* Offset to the first free byte */
|
||||
off_t ioblock; /* Current block number being accessed */
|
||||
off_t cblock; /* Starting block number in cache */
|
||||
FAR uint8_t *cache; /* Allocated erase block */
|
||||
off_t hoffset; /* FLASH offset to the inode header */
|
||||
off_t noffset; /* FLASH offset to the inode name */
|
||||
off_t doffset; /* FLASH offset to the first data header */
|
||||
FAR char *name; /* inode name */
|
||||
uint32_t utc; /* Time stamp */
|
||||
uint32_t datlen; /* Length of inode data */
|
||||
};
|
||||
|
||||
/* This structure describes the state of one open file. This structure
|
||||
@@ -253,10 +236,10 @@ struct nxffs_volume_s
|
||||
|
||||
struct nxffs_ofile_s
|
||||
{
|
||||
struct nxffs_ofile_s *flink; /* Supports a singly linked list */
|
||||
int16_t crefs; /* Reference count */
|
||||
mode_t mode; /* Open mode */
|
||||
struct nxffs_entry_s entry; /* Describes the NXFFS inode entry */
|
||||
struct nxffs_ofile_s *flink; /* Supports a singly linked list */
|
||||
int16_t crefs; /* Reference count */
|
||||
mode_t mode; /* Open mode */
|
||||
struct nxffs_entry_s entry; /* Describes the NXFFS inode entry */
|
||||
};
|
||||
|
||||
/* A file opened for writing require some additional information */
|
||||
@@ -265,7 +248,7 @@ struct nxffs_wrfile_s
|
||||
{
|
||||
/* The following fields provide the common open file information. */
|
||||
|
||||
struct nxffs_ofile_s ofile;
|
||||
struct nxffs_ofile_s ofile;
|
||||
|
||||
/* The following fields are required to support the current write
|
||||
* operation. Note that the size of the current block can be determined
|
||||
@@ -279,24 +262,46 @@ struct nxffs_wrfile_s
|
||||
* 5. If the end of the FLASH block is encountered, the data block CRC is
|
||||
* calculated and the block header is also written to flash.
|
||||
* 6. When the file is closed, the final, partial data block is written to
|
||||
* FLASH in the same way. The final file size is determined, the header
|
||||
* FLASH in the same way. Any previously identified file with the same
|
||||
* name is deleted. The final file size is determined, the header
|
||||
* CRC is calculated, and the inode header is written to FLASH, completing
|
||||
* the write operation.
|
||||
*/
|
||||
|
||||
uint16_t wrlen; /* Number of bytes written in data block */
|
||||
off_t dathdr; /* FLASH offset to the current data header */
|
||||
bool truncate; /* Delete a file of the same name */
|
||||
uint16_t wrlen; /* Number of bytes written in data block */
|
||||
off_t dathdr; /* FLASH offset to the current data header */
|
||||
};
|
||||
|
||||
/* This structure represents the overall state of on NXFFS instance. */
|
||||
|
||||
struct nxffs_volume_s
|
||||
{
|
||||
FAR struct mtd_dev_s *mtd; /* Supports FLASH access */
|
||||
sem_t exclsem; /* Used to assure thread-safe access */
|
||||
struct mtd_geometry_s geo; /* Device geometry */
|
||||
uint8_t wrbusy: 1; /* 1: Volume open for writing */
|
||||
uint8_t blkper; /* R/W blocks per erase block */
|
||||
uint8_t ncached; /* Number of blocks in cache */
|
||||
uint16_t iooffset; /* Next offset in read/write access (in ioblock) */
|
||||
off_t inoffset; /* Offset to the first valid inode header */
|
||||
off_t froffset; /* Offset to the first free byte */
|
||||
off_t nblocks; /* Number of R/W blocks on volume */
|
||||
off_t ioblock; /* Current block number being accessed */
|
||||
off_t cblock; /* Starting block number in cache */
|
||||
FAR struct nxffs_ofile_s *ofiles; /* A singly-linked list of open files */
|
||||
FAR uint8_t *cache; /* Allocated erase block */
|
||||
};
|
||||
|
||||
/* This structure describes the state of the blocks on the NXFFS volume */
|
||||
|
||||
struct nxffs_blkstats_s
|
||||
{
|
||||
off_t nblocks; /* Total number of FLASH blocks */
|
||||
off_t ngood; /* Number of good FLASH blocks found */
|
||||
off_t nbad; /* Number of well-formatted FLASH blocks marked as bad */
|
||||
off_t nunformat; /* Number of unformatted FLASH blocks */
|
||||
off_t ncorrupt; /* Number of blocks with correupted format info */
|
||||
off_t nblocks; /* Total number of FLASH blocks */
|
||||
off_t ngood; /* Number of good FLASH blocks found */
|
||||
off_t nbad; /* Number of well-formatted FLASH blocks marked as bad */
|
||||
off_t nunformat; /* Number of unformatted FLASH blocks */
|
||||
off_t ncorrupt; /* Number of blocks with correupted format info */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@@ -327,10 +332,6 @@ extern const uint8_t g_datamagic[NXFFS_MAGICSIZE];
|
||||
extern struct nxffs_volume_s g_volume;
|
||||
#endif
|
||||
|
||||
/* A singly-linked list of open files */
|
||||
|
||||
extern struct nxffs_ofile_s *g_ofiles;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
@@ -345,10 +346,11 @@ extern struct nxffs_ofile_s *g_ofiles;
|
||||
*
|
||||
* The first, lower limit must be recalculated: (1) initially, (2)
|
||||
* whenever the first inode is deleted, or (3) whenever inode is moved
|
||||
* as part of the clean-up operation.
|
||||
* as part of the file system packing operation.
|
||||
*
|
||||
* The second, upper limit must be (1) incremented whenever new file
|
||||
* data is written, or (2) recalculated as part of the clean-up operation.
|
||||
* data is written, or (2) recalculated as part of the file system packing
|
||||
* operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - Identifies the NXFFS volume
|
||||
@@ -379,7 +381,24 @@ extern int nxffs_limits(FAR struct nxffs_volume_s *volume);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern uint16_t nxffs_rdle16(const uint8_t *val);
|
||||
extern uint16_t nxffs_rdle16(FAR const uint8_t *val);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrle16
|
||||
*
|
||||
* Description:
|
||||
* Put a (possibly unaligned) 16-bit little endian value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dest - A pointer to the first byte to save the little endian value.
|
||||
* val - The 16-bit value to be saved.
|
||||
*
|
||||
* Returned Values:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern void nxffs_wrle16(uint8_t *dest, uint16_t val);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_rdle32
|
||||
@@ -397,7 +416,43 @@ extern uint16_t nxffs_rdle16(const uint8_t *val);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern uint32_t nxffs_rdle32(const uint8_t *val);
|
||||
extern uint32_t nxffs_rdle32(FAR const uint8_t *val);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrle32
|
||||
*
|
||||
* Description:
|
||||
* Put a (possibly unaligned) 32-bit little endian value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dest - A pointer to the first byte to save the little endian value.
|
||||
* val - The 32-bit value to be saved.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern void nxffs_wrle32(uint8_t *dest, uint32_t val);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_erased
|
||||
*
|
||||
* Description:
|
||||
* Check if the block of memory if in the erased state.
|
||||
*
|
||||
* Input Parameters:
|
||||
* buffer - Address of the start of the memory to check.
|
||||
* buflen - The number of bytes to check.
|
||||
*
|
||||
* Returned Values:
|
||||
* true: memory is erased; false: memory is not erased
|
||||
*
|
||||
* Defined in nxffs_util.c
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern bool nxffs_erased(FAR const uint8_t *buffer, size_t buflen);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_rdcache
|
||||
@@ -701,6 +756,7 @@ extern int nxffs_reformat(FAR struct nxffs_volume_s *volume);
|
||||
* name is one of the opened files.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - Describes the NXFFS volume.
|
||||
* name - The name of the inode to check.
|
||||
*
|
||||
* Returned Value:
|
||||
@@ -712,8 +768,115 @@ extern int nxffs_reformat(FAR struct nxffs_volume_s *volume);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern FAR struct nxffs_ofile_s *nxffs_findofile(FAR const char *name);
|
||||
extern FAR struct nxffs_ofile_s *nxffs_findofile(FAR struct nxffs_volume_s *volume,
|
||||
FAR const char *name);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrreserve
|
||||
*
|
||||
* Description:
|
||||
* Find a valid location for a file system object of 'size'. A valid
|
||||
* location will have these properties:
|
||||
*
|
||||
* 1. It will lie in the free flash region.
|
||||
* 2. It will have enough contiguous memory to hold the entire object
|
||||
* 3. The memory at this location will be fully erased.
|
||||
*
|
||||
* This function will only perform the checks of 1) and 2). The
|
||||
* end-of-filesystem offset, froffset, is update past this memory which,
|
||||
* in effect, reserves the memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - Describes the NXFFS volume
|
||||
* size - The size of the object to be reserved.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned indicating the nature of the failure. Of special interest
|
||||
* the return error of -ENOSPC which means that the FLASH volume is
|
||||
* full and should be repacked.
|
||||
*
|
||||
* On successful return the following are also valid:
|
||||
*
|
||||
* volume->ioblock - Read/write block number of the block containing the
|
||||
* candidate oject position
|
||||
* volume->iooffset - The offset in the block to the candidate object
|
||||
* position.
|
||||
* volume->froffset - Updated offset to the first free FLASH block after
|
||||
* the reserved memory.
|
||||
*
|
||||
*
|
||||
* Defined in nxffs_write.c
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern int nxffs_wrreserve(FAR struct nxffs_volume_s *volume, size_t size);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrverify
|
||||
*
|
||||
* Description:
|
||||
* Find a valid location for the object. A valid location will have
|
||||
* these properties:
|
||||
*
|
||||
* 1. It will lie in the free flash region.
|
||||
* 2. It will have enough contiguous memory to hold the entire header
|
||||
* (excluding the file name which may lie in the next block).
|
||||
* 3. The memory at this location will be fully erased.
|
||||
*
|
||||
* This function will only perform the check 3). On entry it assumes the
|
||||
* following settings (left by nxffs_wrreserve()):
|
||||
*
|
||||
* volume->ioblock - Read/write block number of the block containing the
|
||||
* candidate oject position
|
||||
* volume->iooffset - The offset in the block to the candidate object
|
||||
* position.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - Describes the NXFFS volume
|
||||
* size - The size of the object to be verifed.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned indicating the nature of the failure. Of special interest
|
||||
* the return error of -ENOSPC which means that the FLASH volume is
|
||||
* full and should be repacked.
|
||||
*
|
||||
* On successful return the following are also valid:
|
||||
*
|
||||
* volume->ioblock - Read/write block number of the block containing the
|
||||
* verified object position
|
||||
* volume->iooffset - The offset in the block to the verified object
|
||||
* position.
|
||||
* volume->froffset - Updated offset to the first free FLASH block.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern int nxffs_wrverify(FAR struct nxffs_volume_s *volume, size_t size);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrblkhdr
|
||||
*
|
||||
* Description:
|
||||
* Write the block header information. This is done (1) whenever the end-
|
||||
* block is encountered and (2) also when the file is closed in order to
|
||||
* flush the final block of data to FLASH.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - Describes the state of the NXFFS volume
|
||||
* wrfile - Describes the state of the open file
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success; Otherwise, a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
* Defined in nxffs_write.c
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern int nxffs_wrblkhdr(FAR struct nxffs_volume_s *volume,
|
||||
FAR struct nxffs_wrfile_s *wrfile);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_rminode
|
||||
*
|
||||
@@ -733,6 +896,24 @@ extern FAR struct nxffs_ofile_s *nxffs_findofile(FAR const char *name);
|
||||
|
||||
extern int nxffs_rminode(FAR struct nxffs_volume_s *volume, FAR const char *name);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_pack
|
||||
*
|
||||
* Description:
|
||||
* Pack and re-write the filesystem in order to free up memory at the end
|
||||
* of FLASH.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - The volume to be packed.
|
||||
*
|
||||
* Returned Values:
|
||||
* Zero on success; Otherwise, a negated errno value is returned to
|
||||
* indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern int nxffs_pack(FAR struct nxffs_volume_s *volume);
|
||||
|
||||
/****************************************************************************
|
||||
* Standard mountpoint operation methods
|
||||
*
|
||||
|
||||
@@ -105,7 +105,7 @@ int nxffs_verifyblock(FAR struct nxffs_volume_s *volume, off_t block)
|
||||
|
||||
/* Check if the block has a magic number (meaning that it is not
|
||||
* erased) and that it is valid (meaning that it is not marked
|
||||
* for cleanup)
|
||||
* for deletion)
|
||||
*/
|
||||
|
||||
blkhdr = (FAR struct nxffs_block_s *)volume->cache;
|
||||
@@ -147,7 +147,7 @@ int nxffs_validblock(struct nxffs_volume_s *volume, off_t *block)
|
||||
|
||||
/* Loop for each possible block or until a valid block is found */
|
||||
|
||||
for (i = *block; i < volume->geo.neraseblocks * volume->blkper; i++)
|
||||
for (i = *block; i < volume->nblocks; i++)
|
||||
{
|
||||
/* Loop until we find a valid block */
|
||||
|
||||
@@ -161,6 +161,10 @@ int nxffs_validblock(struct nxffs_volume_s *volume, off_t *block)
|
||||
}
|
||||
}
|
||||
|
||||
/* ENOSPC is special return value that means that there is no further,
|
||||
* valid blocks left in the volume.
|
||||
*/
|
||||
|
||||
fdbg("No valid block found\n");
|
||||
return -ENOENT;
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
@@ -206,9 +206,12 @@ int nxffs_initialize(FAR struct mtd_dev_s *mtd)
|
||||
goto errout_with_volume;
|
||||
}
|
||||
|
||||
/* Get the number of R/W blocks per erase block */
|
||||
/* Get the number of R/W blocks per erase block and the total number o
|
||||
* R/W blocks
|
||||
*/
|
||||
|
||||
volume->blkper = volume->geo.erasesize / volume->geo.blocksize;
|
||||
volume->blkper = volume->geo.erasesize / volume->geo.blocksize;
|
||||
volume->nblocks = volume->geo.neraseblocks * volume->blkper;
|
||||
DEBUGASSERT((off_t)volume->blkper * volume->geo.blocksize == volume->geo.erasesize);
|
||||
|
||||
/* Check if there is a valid NXFFS file system on the flash */
|
||||
@@ -274,10 +277,11 @@ errout_with_volume:
|
||||
*
|
||||
* The first, lower limit must be recalculated: (1) initially, (2)
|
||||
* whenever the first inode is deleted, or (3) whenever inode is moved
|
||||
* as part of the clean-up operation.
|
||||
* as part of the file system packing operation.
|
||||
*
|
||||
* The second, upper limit must be (1) incremented whenever new file
|
||||
* data is written, or (2) recalculated as part of the clean-up operation.
|
||||
* data is written, or (2) recalculated as part of the file system packing
|
||||
* operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - Identifies the NXFFS volume
|
||||
@@ -477,5 +481,9 @@ int nxffs_bind(FAR struct inode *blkdriver, FAR const void *data,
|
||||
|
||||
int nxffs_unbind(FAR void *handle, FAR struct inode **blkdriver)
|
||||
{
|
||||
return g_ofiles ? -EBUSY : OK;
|
||||
#ifndef CONFIG_NXFSS_PREALLOCATED
|
||||
# error "No design to support dynamic allocation of volumes"
|
||||
#else
|
||||
return g_volume.ofiles ? -EBUSY : OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
+10
-16
@@ -93,7 +93,7 @@ static int nxffs_rdentry(FAR struct nxffs_volume_s *volume, off_t offset,
|
||||
struct nxffs_inode_s inode;
|
||||
uint32_t ecrc;
|
||||
uint32_t crc;
|
||||
int namelen;
|
||||
int namlen;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(volume && entry);
|
||||
@@ -119,7 +119,8 @@ static int nxffs_rdentry(FAR struct nxffs_volume_s *volume, off_t offset,
|
||||
/* Copy the packed header into the user-friendly buffer */
|
||||
|
||||
entry->hoffset = offset;
|
||||
entry->doffset = offset + inode.doffset;
|
||||
entry->noffset = nxffs_rdle32(inode.noffs);
|
||||
entry->doffset = nxffs_rdle32(inode.doffs);
|
||||
entry->utc = nxffs_rdle32(inode.utc);
|
||||
entry->datlen = nxffs_rdle32(inode.datlen);
|
||||
|
||||
@@ -132,34 +133,27 @@ static int nxffs_rdentry(FAR struct nxffs_volume_s *volume, off_t offset,
|
||||
|
||||
/* Allocate memory to hold the variable-length file name */
|
||||
|
||||
namelen = (int)inode.doffset - (int)inode.noffset;
|
||||
if (namelen < 0)
|
||||
{
|
||||
fdbg("Bad offsets, name: %d data: %d\n", inode.noffset, inode.doffset);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
entry->name = (FAR char *)kmalloc(namelen+1);
|
||||
entry->name = (FAR char *)kmalloc(inode.namlen + 1);
|
||||
if (!entry->name)
|
||||
{
|
||||
fdbg("Failed to allocate name, namelen: %d\n", namelen);
|
||||
fdbg("Failed to allocate name, namlen: %d\n", inode.namlen);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Read the file name from the expected offset in FLASH */
|
||||
|
||||
nxffs_ioseek(volume, offset + inode.noffset);
|
||||
ret = nxffs_rddata(volume, (FAR uint8_t*)entry->name, namelen);
|
||||
nxffs_ioseek(volume, entry->noffset);
|
||||
ret = nxffs_rddata(volume, (FAR uint8_t*)entry->name, namlen);
|
||||
if (ret < 0)
|
||||
{
|
||||
fdbg("Failed to read inode, offset %d: %d\n", offset, -ret);
|
||||
return -EIO;
|
||||
}
|
||||
entry->name[namelen] = '\0';
|
||||
entry->name[namlen] = '\0';
|
||||
|
||||
/* Finish the CRC calculation and verify the entry */
|
||||
|
||||
crc = crc32part(entry->name, namelen, crc);
|
||||
crc = crc32part((FAR const uint8_t *)entry->name, namlen, crc);
|
||||
if (crc != ecrc)
|
||||
{
|
||||
fdbg("CRC entry: %08x CRC calculated: %08x\n", ecrc, crc);
|
||||
@@ -332,7 +326,7 @@ int nxffs_findinode(FAR struct nxffs_volume_s *volume, FAR const char *name,
|
||||
int ret;
|
||||
|
||||
/* Start with the first valid inode that was discovered when the volume
|
||||
* was created (or modified after the last cleanup).
|
||||
* was created (or modified after the last file system re-packing).
|
||||
*/
|
||||
|
||||
offset = volume->inoffset;
|
||||
|
||||
+541
-42
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
||||
/****************************************************************************
|
||||
* fs/nxffs/nxffs_pack.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* References: Linux/Documentation/filesystems/romfs.txt
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "nxffs.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_pack
|
||||
*
|
||||
* Description:
|
||||
* Pack and re-write the filesystem in order to free up memory at the end
|
||||
* of FLASH.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - The volume to be packed.
|
||||
*
|
||||
* Returned Values:
|
||||
* Zero on success; Otherwise, a negated errno value is returned to
|
||||
* indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nxffs_pack(FAR struct nxffs_volume_s *volume)
|
||||
{
|
||||
# warning "Missing logic"
|
||||
return -ENOSYS;
|
||||
}
|
||||
@@ -148,12 +148,10 @@ static int nxffs_format(FAR struct nxffs_volume_s *volume)
|
||||
static int nxffs_badblocks(FAR struct nxffs_volume_s *volume)
|
||||
{
|
||||
FAR uint8_t *blkptr; /* Pointer to next block data */
|
||||
FAR uint8_t *datptr; /* Pointer to next data byte */
|
||||
off_t eblock; /* Erase block number */
|
||||
off_t lblock; /* Logical block number */
|
||||
ssize_t nxfrd; /* Number of blocks transferred */
|
||||
uint16_t blkndx; /* Logical block data index */
|
||||
bool bad; /* TRUE: block is bad */
|
||||
bool good; /* TRUE: block is good */
|
||||
bool modified; /* TRUE: The erase block has been modified */
|
||||
int i;
|
||||
|
||||
@@ -182,32 +180,19 @@ static int nxffs_badblocks(FAR struct nxffs_volume_s *volume)
|
||||
|
||||
/* Check block header */
|
||||
|
||||
bad = false;
|
||||
good = true;
|
||||
if (memcmp(blkhdr->magic, g_blockmagic, NXFFS_MAGICSIZE) != 0 ||
|
||||
blkhdr->state != BLOCK_STATE_GOOD)
|
||||
{
|
||||
bad = true;;
|
||||
good = false;
|
||||
}
|
||||
|
||||
/* Check that block data is erased */
|
||||
|
||||
else
|
||||
{
|
||||
/* Check every byte in the block payload */
|
||||
|
||||
for (blkndx = SIZEOF_NXFFS_BLOCK_HDR, datptr = &blkptr[blkndx];
|
||||
blkndx < volume->geo.blocksize;
|
||||
blkndx++)
|
||||
{
|
||||
/* If the data byte is not in the erased state, then the block is bad */
|
||||
|
||||
uint8_t byte = *datptr++;
|
||||
if (byte != CONFIG_NXFFS_ERASEDSTATE)
|
||||
{
|
||||
bad = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
good = nxffs_erased(&blkptr[SIZEOF_NXFFS_BLOCK_HDR],
|
||||
volume->geo.blocksize - SIZEOF_NXFFS_BLOCK_HDR);
|
||||
}
|
||||
|
||||
/* If the block is bad, attempt to re-write the block header indicating
|
||||
@@ -215,7 +200,7 @@ static int nxffs_badblocks(FAR struct nxffs_volume_s *volume)
|
||||
* possible, depending upon failure modes.
|
||||
*/
|
||||
|
||||
if (bad)
|
||||
if (!good)
|
||||
{
|
||||
memcpy(blkhdr->magic, g_blockmagic, NXFFS_MAGICSIZE);
|
||||
blkhdr->state = BLOCK_STATE_BAD;
|
||||
|
||||
@@ -107,7 +107,7 @@ int nxffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
|
||||
memset(buf, 0, sizeof(struct statfs));
|
||||
buf->f_type = NXFFS_MAGIC;
|
||||
buf->f_bsize = volume->geo.blocksize;
|
||||
buf->f_blocks = volume->geo.neraseblocks * volume->blkper;
|
||||
buf->f_blocks = volume->nblocks;
|
||||
buf->f_namelen = volume->geo.blocksize - SIZEOF_NXFFS_BLOCK_HDR - SIZEOF_NXFFS_INODE_HDR;
|
||||
ret = OK;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ int nxffs_rminode(FAR struct nxffs_volume_s *volume, FAR const char *name)
|
||||
|
||||
/* Check if the file is open */
|
||||
|
||||
ofile = nxffs_findofile(name);
|
||||
ofile = nxffs_findofile(volume, name);
|
||||
if (ofile)
|
||||
{
|
||||
/* We can't remove the inode if it is open */
|
||||
|
||||
+75
-4
@@ -74,16 +74,37 @@
|
||||
* Input Parameters:
|
||||
* val - A pointer to the first byte of the little endian value.
|
||||
*
|
||||
* Returned Values:
|
||||
* Returned Value:
|
||||
* A uint16_t representing the whole 16-bit integer value
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint16_t nxffs_rdle16(const uint8_t *val)
|
||||
uint16_t nxffs_rdle16(FAR const uint8_t *val)
|
||||
{
|
||||
return (uint16_t)val[1] << 8 | (uint16_t)val[0];
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrle16
|
||||
*
|
||||
* Description:
|
||||
* Put a (possibly unaligned) 16-bit little endian value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dest - A pointer to the first byte to save the little endian value.
|
||||
* val - The 16-bit value to be saved.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void nxffs_wrle16(uint8_t *dest, uint16_t val)
|
||||
{
|
||||
dest[0] = val & 0xff; /* Little endian means LS byte first in byte stream */
|
||||
dest[1] = val >> 8;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_rdle32
|
||||
*
|
||||
@@ -93,15 +114,65 @@ uint16_t nxffs_rdle16(const uint8_t *val)
|
||||
* Input Parameters:
|
||||
* val - A pointer to the first byte of the little endian value.
|
||||
*
|
||||
* Returned Values:
|
||||
* Returned Value:
|
||||
* A uint32_t representing the whole 32-bit integer value
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t nxffs_rdle32(const uint8_t *val)
|
||||
uint32_t nxffs_rdle32(FAR const uint8_t *val)
|
||||
{
|
||||
/* Little endian means LS halfword first in byte stream */
|
||||
|
||||
return (uint32_t)nxffs_rdle16(&val[2]) << 16 | (uint32_t)nxffs_rdle16(val);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrle32
|
||||
*
|
||||
* Description:
|
||||
* Put a (possibly unaligned) 32-bit little endian value.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dest - A pointer to the first byte to save the little endian value.
|
||||
* val - The 32-bit value to be saved.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void nxffs_wrle32(uint8_t *dest, uint32_t val)
|
||||
{
|
||||
/* Little endian means LS halfword first in byte stream */
|
||||
|
||||
nxffs_wrle16(dest, (uint16_t)(val & 0xffff));
|
||||
nxffs_wrle16(dest+2, (uint16_t)(val >> 16));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_erased
|
||||
*
|
||||
* Description:
|
||||
* Check if the block of memory if in the erased state.
|
||||
*
|
||||
* Input Parameters:
|
||||
* buffer - Address of the start of the memory to check.
|
||||
* buflen - The number of bytes to check.
|
||||
*
|
||||
* Returned Values:
|
||||
* true: memory is erased; false: memory is not erased
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool nxffs_erased(FAR const uint8_t *buffer, size_t buflen)
|
||||
{
|
||||
for (; buflen; buflen--)
|
||||
{
|
||||
if (*buffer != CONFIG_NXFFS_ERASEDSTATE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
buffer++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -145,3 +145,249 @@ errout_with_semaphore:
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrreserve
|
||||
*
|
||||
* Description:
|
||||
* Find a valid location for a file system object of 'size'. A valid
|
||||
* location will have these properties:
|
||||
*
|
||||
* 1. It will lie in the free flash region.
|
||||
* 2. It will have enough contiguous memory to hold the entire object
|
||||
* 3. The memory at this location will be fully erased.
|
||||
*
|
||||
* This function will only perform the checks of 1) and 2). The
|
||||
* end-of-filesystem offset, froffset, is update past this memory which,
|
||||
* in effect, reserves the memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - Describes the NXFFS volume
|
||||
* size - The size of the object to be reserved.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned indicating the nature of the failure. Of special interest
|
||||
* the return error of -ENOSPC which means that the FLASH volume is
|
||||
* full and should be repacked.
|
||||
*
|
||||
* On successful return the following are also valid:
|
||||
*
|
||||
* volume->ioblock - Read/write block number of the block containing the
|
||||
* candidate oject position
|
||||
* volume->iooffset - The offset in the block to the candidate object
|
||||
* position.
|
||||
* volume->froffset - Updated offset to the first free FLASH block after
|
||||
* the reserved memory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nxffs_wrreserve(FAR struct nxffs_volume_s *volume, size_t size)
|
||||
{
|
||||
off_t offset;
|
||||
int ret;
|
||||
|
||||
/* Seek to the beginning of the free FLASH region */
|
||||
|
||||
offset = volume->froffset;
|
||||
nxffs_ioseek(volume, offset);
|
||||
|
||||
/* Check for a seek past the end of the volume */
|
||||
|
||||
if (volume->ioblock >= volume->nblocks)
|
||||
{
|
||||
/* Return -ENOSPC to indicate that the volume is full */
|
||||
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
/* Make sure that there is space there to hold the entire object */
|
||||
|
||||
DEBUGASSERT(volume->iooffset >= SIZEOF_NXFFS_BLOCK_HDR);
|
||||
if (volume->iooffset + size > volume->geo.blocksize)
|
||||
{
|
||||
/* We will need to skip to the next block. But first, check if we are
|
||||
* already at the final block.
|
||||
*/
|
||||
|
||||
if (volume->ioblock + 1 >= volume->geo.neraseblocks)
|
||||
{
|
||||
/* Return -ENOSPC to indicate that the volume is full */
|
||||
|
||||
fdbg("No space in last block\n");
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
/* This is not the last block in the volume, so just seek to the
|
||||
* beginning of the next, valid block.
|
||||
*/
|
||||
|
||||
volume->ioblock++;
|
||||
ret = nxffs_validblock(volume, &volume->ioblock);
|
||||
if (ret < 0)
|
||||
{
|
||||
fdbg("No more valid blocks\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
volume->iooffset = SIZEOF_NXFFS_BLOCK_HDR;
|
||||
offset = volume->ioblock * volume->geo.blocksize + SIZEOF_NXFFS_BLOCK_HDR;
|
||||
}
|
||||
|
||||
/* Update the pointer to the first next free FLASH memory -- reserving this
|
||||
* block of memory.
|
||||
*/
|
||||
|
||||
volume->froffset = offset + size;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrverify
|
||||
*
|
||||
* Description:
|
||||
* Find a valid location for the object. A valid location will have
|
||||
* these properties:
|
||||
*
|
||||
* 1. It will lie in the free flash region.
|
||||
* 2. It will have enough contiguous memory to hold the entire header
|
||||
* (excluding the file name which may lie in the next block).
|
||||
* 3. The memory at this location will be fully erased.
|
||||
*
|
||||
* This function will only perform the check 3). On entry it assumes the
|
||||
* following settings (left by nxffs_wrreserve()):
|
||||
*
|
||||
* volume->ioblock - Read/write block number of the block containing the
|
||||
* candidate oject position
|
||||
* volume->iooffset - The offset in the block to the candidate object
|
||||
* position.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - Describes the NXFFS volume
|
||||
* size - The size of the object to be verifed.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned indicating the nature of the failure. Of special interest
|
||||
* the return error of -ENOSPC which means that the FLASH volume is
|
||||
* full and should be repacked.
|
||||
*
|
||||
* On successful return the following are also valid:
|
||||
*
|
||||
* volume->ioblock - Read/write block number of the block containing the
|
||||
* verified object position
|
||||
* volume->iooffset - The offset in the block to the verified object
|
||||
* position.
|
||||
* volume->froffset - Updated offset to the first free FLASH block.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nxffs_wrverify(FAR struct nxffs_volume_s *volume, size_t size)
|
||||
{
|
||||
uint16_t iooffset;
|
||||
int nerased;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Search to the very last block in the volume if we have to */
|
||||
|
||||
while (volume->ioblock < volume->nblocks)
|
||||
{
|
||||
/* Make sure that the block is in memory */
|
||||
|
||||
ret = nxffs_rdcache(volume, volume->ioblock, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
fdbg("nxffsx_rdcache failed: %d\n", -ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Search to the very end of this block if we have to */
|
||||
|
||||
iooffset = volume->iooffset;
|
||||
nerased = 0;
|
||||
|
||||
for (i = volume->iooffset; i <= volume->geo.blocksize - size; i++)
|
||||
{
|
||||
/* Is this byte erased? */
|
||||
|
||||
if (volume->cache[i] == CONFIG_NXFFS_ERASEDSTATE)
|
||||
{
|
||||
/* Yes.. increment the count of contiguous, erased bytes */
|
||||
|
||||
nerased++;
|
||||
|
||||
/* Is the whole header memory erased? */
|
||||
|
||||
if (nerased >= size)
|
||||
{
|
||||
/* Yes.. this this is where we will put the object */
|
||||
|
||||
off_t offset = volume->ioblock * volume->geo.blocksize + iooffset;
|
||||
|
||||
/* Update the free flash offset and return success */
|
||||
|
||||
volume->froffset = offset + size;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* This byte is not erased! (It should be unless the block is bad) */
|
||||
|
||||
else
|
||||
{
|
||||
nerased = 0;
|
||||
iooffset = volume->iooffset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we get here, then we have looked at every byte in the the block
|
||||
* and did not find any sequence of erased bytes long enough to hold
|
||||
* the object. Skip to the next, valid block.
|
||||
*/
|
||||
|
||||
volume->ioblock++;
|
||||
ret = nxffs_validblock(volume, &volume->ioblock);
|
||||
if (ret < 0)
|
||||
{
|
||||
fdbg("No more valid blocks\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
volume->iooffset = size;
|
||||
volume->froffset = volume->ioblock * volume->geo.blocksize + size;
|
||||
}
|
||||
|
||||
/* Return -ENOSPC if there is no erased memory left in the volume for
|
||||
* the object.
|
||||
*/
|
||||
|
||||
fdbg("Not enough memory left to hold the file header\n");
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxffs_wrblkhdr
|
||||
*
|
||||
* Description:
|
||||
* Write the block header information. This is done (1) whenever the end-
|
||||
* block is encountered and (2) also when the file is closed in order to
|
||||
* flush the final block of data to FLASH.
|
||||
*
|
||||
* Input Parameters:
|
||||
* volume - Describes the state of the NXFFS volume
|
||||
* wrfile - Describes the state of the open file
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success; Otherwise, a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nxffs_wrblkhdr(FAR struct nxffs_volume_s *volume,
|
||||
FAR struct nxffs_wrfile_s *wrfile)
|
||||
{
|
||||
#warning "Missing logic"
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user