mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-21 13:08:36 +08:00
imfs: Constify imfs_memfile_bytes_per_block
The CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK value is validated by <rtems/confdefs/libio.h>. Changing this value during runtime could lead to memory corruption. Update #3894.
This commit is contained in:
@@ -196,7 +196,7 @@ static const devFS_data _Filesystem_Root_data = {
|
||||
#error "CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK must be a power of two between 16 and 512"
|
||||
#endif
|
||||
|
||||
int imfs_rq_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK;
|
||||
const int imfs_memfile_bytes_per_block = CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK;
|
||||
|
||||
static IMFS_fs_info_t _IMFS_fs_info;
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ typedef struct IMFS_jnode_tt IMFS_jnode_t;
|
||||
* @endcode
|
||||
*/
|
||||
#define IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK 128
|
||||
extern int imfs_rq_memfile_bytes_per_block;
|
||||
extern int imfs_memfile_bytes_per_block;
|
||||
extern const int imfs_memfile_bytes_per_block;
|
||||
|
||||
#define IMFS_MEMFILE_BYTES_PER_BLOCK imfs_memfile_bytes_per_block
|
||||
#define IMFS_MEMFILE_BLOCK_SLOTS \
|
||||
|
||||
@@ -21,35 +21,6 @@
|
||||
#include <rtems/imfs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int IMFS_determine_bytes_per_block(
|
||||
int *dest_bytes_per_block,
|
||||
int requested_bytes_per_block,
|
||||
int default_bytes_per_block
|
||||
)
|
||||
{
|
||||
bool is_valid = false;
|
||||
int bit_mask;
|
||||
|
||||
/*
|
||||
* check, whether requested bytes per block is valid
|
||||
*/
|
||||
for (bit_mask = 16; !is_valid && (bit_mask <= 512); bit_mask <<= 1) {
|
||||
if (bit_mask == requested_bytes_per_block) {
|
||||
is_valid = true;
|
||||
break;
|
||||
}
|
||||
if(bit_mask > requested_bytes_per_block)
|
||||
break;
|
||||
}
|
||||
*dest_bytes_per_block = ((is_valid)
|
||||
? requested_bytes_per_block
|
||||
: default_bytes_per_block);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IMFS_initialize_support(
|
||||
rtems_filesystem_mount_table_entry_t *mt_entry,
|
||||
@@ -78,12 +49,6 @@ int IMFS_initialize_support(
|
||||
mt_entry->mt_fs_root->location.node_access = root_node;
|
||||
IMFS_Set_handlers( &mt_entry->mt_fs_root->location );
|
||||
|
||||
IMFS_determine_bytes_per_block(
|
||||
&imfs_memfile_bytes_per_block,
|
||||
imfs_rq_memfile_bytes_per_block,
|
||||
IMFS_MEMFILE_DEFAULT_BYTES_PER_BLOCK
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#include <rtems/imfs.h>
|
||||
|
||||
int imfs_memfile_bytes_per_block;
|
||||
|
||||
int IMFS_stat_file(
|
||||
const rtems_filesystem_location_info_t *loc,
|
||||
struct stat *buf
|
||||
|
||||
Reference in New Issue
Block a user