fs/cromfs: Block length only needs to be uint16_t, not uint32_t. Add pading to node structure to assue that alignment is the same on all platforms. tools/gencromfs.c: Fix the target offset of the '.' hard link.

This commit is contained in:
Gregory Nutt 2018-03-24 14:44:38 -06:00
parent 853c1234ac
commit 67e0603b5a
4 changed files with 15 additions and 8 deletions

View File

@ -249,6 +249,8 @@ configuration:
Or the apps/examples/elf example if you like: Or the apps/examples/elf example if you like:
CONFIG_ELF=y
# CONFIG_BINFMT_DISABLE is not set
CONFIG_EXAMPLES_ELF=y CONFIG_EXAMPLES_ELF=y
CONFIG_EXAMPLES_ELF_CROMFS=y CONFIG_EXAMPLES_ELF_CROMFS=y

View File

@ -120,6 +120,7 @@ struct cromfs_volume_s
struct cromfs_node_s struct cromfs_node_s
{ {
uint16_t cn_mode; /* File type, attributes, and access mode bits */ uint16_t cn_mode; /* File type, attributes, and access mode bits */
uint16_t cn_pad; /* Not used */
uint32_t cn_name; /* Offset from the beginning of the volume header to the uint32_t cn_name; /* Offset from the beginning of the volume header to the
* node name string. NUL-terminated. */ * node name string. NUL-terminated. */
uint32_t cn_size; /* Size of the uncompressed data (in bytes) */ uint32_t cn_size; /* Size of the uncompressed data (in bytes) */

View File

@ -71,9 +71,9 @@
struct cromfs_file_s struct cromfs_file_s
{ {
FAR const struct cromfs_node_s *ff_node; /* The open file node */ FAR const struct cromfs_node_s *ff_node; /* The open file node */
uint32_t ff_offset; /* Cached offset (zero means none) */ uint32_t ff_offset; /* Cached block offset (zero means none) */
uint32_t ff_ulen; /* Length of uncompressed data in cache */ uint16_t ff_ulen; /* Length of decompressed data in cache */
FAR uint8_t *ff_buffer; /* Decompression buffer */ FAR uint8_t *ff_buffer; /* Cached, decompressed data */
}; };
/* This is the form of the callback from cromfs_foreach_node(): */ /* This is the form of the callback from cromfs_foreach_node(): */

View File

@ -160,6 +160,7 @@ struct cromfs_volume_s
struct cromfs_node_s struct cromfs_node_s
{ {
uint16_t cn_mode; /* File type, attributes, and access mode bits */ uint16_t cn_mode; /* File type, attributes, and access mode bits */
uint16_t cn_pad; /* Not used */
uint32_t cn_name; /* Offset from the beginning of the volume header to the uint32_t cn_name; /* Offset from the beginning of the volume header to the
* node name string. NUL-terminated. */ * node name string. NUL-terminated. */
uint32_t cn_size; /* Size of the uncompressed data (in bytes) */ uint32_t cn_size; /* Size of the uncompressed data (in bytes) */
@ -920,6 +921,7 @@ static void gen_dirlink(const char *name, uint32_t tgtoffs, bool dirempty)
(unsigned long)g_offset, name); (unsigned long)g_offset, name);
node.cn_mode = TGT_UINT16(DIRLINK_MODEFLAGS); node.cn_mode = TGT_UINT16(DIRLINK_MODEFLAGS);
node.cn_pad = 0;
g_offset += sizeof(struct cromfs_node_s); g_offset += sizeof(struct cromfs_node_s);
node.cn_name = TGT_UINT32(g_offset); node.cn_name = TGT_UINT32(g_offset);
@ -954,17 +956,17 @@ static void gen_directory(const char *path, const char *name, mode_t mode,
subtree_stream = open_tmpfile(); subtree_stream = open_tmpfile();
g_tmpstream = subtree_stream; g_tmpstream = subtree_stream;
/* Update offsets for the subdirectory */
g_parent_offset = g_diroffset; /* New offset for '..' */
g_diroffset = g_offset; /* New offset for '.' */
/* Update the offset to account for the file node which we have not yet /* Update the offset to account for the file node which we have not yet
* written (we can't, we don't have enough information yet) * written (we can't, we don't have enough information yet)
*/ */
g_offset += sizeof(struct cromfs_node_s) + namlen; g_offset += sizeof(struct cromfs_node_s) + namlen;
/* Update offsets for the subdirectory */
g_parent_offset = g_diroffset; /* New offset for '..' */
g_diroffset = g_offset; /* New offset for '.' */
/* We are going to traverse the new directory twice; the first time just /* We are going to traverse the new directory twice; the first time just
* see if the directory is empty. The second time is the real thing. * see if the directory is empty. The second time is the real thing.
*/ */
@ -1002,6 +1004,7 @@ static void gen_directory(const char *path, const char *name, mode_t mode,
(unsigned long)save_offset, path); (unsigned long)save_offset, path);
node.cn_mode = TGT_UINT16(NUTTX_IFDIR | get_mode(mode)); node.cn_mode = TGT_UINT16(NUTTX_IFDIR | get_mode(mode));
node.cn_pad = 0;
save_offset += sizeof(struct cromfs_node_s); save_offset += sizeof(struct cromfs_node_s);
node.cn_name = TGT_UINT32(save_offset); node.cn_name = TGT_UINT32(save_offset);
@ -1118,6 +1121,7 @@ static void gen_file(const char *path, const char *name, mode_t mode,
(unsigned long)blktotal); (unsigned long)blktotal);
node.cn_mode = TGT_UINT16(NUTTX_IFREG | get_mode(mode)); node.cn_mode = TGT_UINT16(NUTTX_IFREG | get_mode(mode));
node.cn_pad = 0;
nodeoffs += sizeof(struct cromfs_node_s); nodeoffs += sizeof(struct cromfs_node_s);
node.cn_name = TGT_UINT32(nodeoffs); node.cn_name = TGT_UINT32(nodeoffs);