Commit 7fae8989 authored by Flavio Santes's avatar Flavio Santes Committed by Anas Nashif
Browse files

fs/disk: Improve code readability



This commit improves source code readability by breaking long
expressions found at some if statements.

Some minor style issues are also fixed by this patch.

Change-Id: I0c8e42eaf0fca3a98490c54a0ccb941766c50fa3
Signed-off-by: default avatarFlavio Santes <flavio.santes@intel.com>
parent b04cdcd6
Loading
Loading
Loading
Loading
+26 −17
Original line number Diff line number Diff line
@@ -43,8 +43,10 @@ static off_t lba_to_address(uint32_t sector_num)
	off_t flash_addr;

	flash_addr = CONFIG_FS_FLASH_START + sector_num * SECTOR_SIZE;

	__ASSERT(flash_addr < (CONFIG_FS_FLASH_START + CONFIG_FS_VOLUME_SIZE),
		 "FS bound error");

	return flash_addr;
}

@@ -124,10 +126,13 @@ static int read_copy_flash_block(off_t start_addr, uint32_t size,

	/* read one block from flash */
	for (uint32_t i = 0; i < num_read; i++) {
		if (flash_read(flash_dev,
		int rc;

		rc = flash_read(flash_dev,
				fl_addr + (CONFIG_FS_FLASH_MAX_RW_SIZE * i),
				dest_buff + (CONFIG_FS_FLASH_MAX_RW_SIZE * i),
			CONFIG_FS_FLASH_MAX_RW_SIZE) != 0) {
				CONFIG_FS_FLASH_MAX_RW_SIZE);
		if (rc != 0) {
			return -EIO;
		}
	}
@@ -139,8 +144,7 @@ static int read_copy_flash_block(off_t start_addr, uint32_t size,
}

/* input size is either less or equal to a block size, CONFIG_FS_BLOCK_SIZE. */
static int update_flash_block(off_t start_addr, uint32_t size,
				  const void *buff)
static int update_flash_block(off_t start_addr, uint32_t size, const void *buff)
{
	off_t fl_addr;
	uint8_t *src = (uint8_t *)buff;
@@ -148,8 +152,10 @@ static int update_flash_block(off_t start_addr, uint32_t size,

	/* if size is a partial block, perform read-copy with user data */
	if (size < CONFIG_FS_BLOCK_SIZE) {
		if (read_copy_flash_block(start_addr, size, buff, fs_buff) !=
		    0) {
		int rc;

		rc = read_copy_flash_block(start_addr, size, buff, fs_buff);
		if (rc != 0) {
			return -EIO;
		}

@@ -198,12 +204,13 @@ int disk_access_write(const uint8_t *buff, uint32_t start_sector,

	/* check if start address is erased-aligned address  */
	if (fl_addr & (CONFIG_FS_FLASH_ERASE_ALIGNMENT - 1)) {
		off_t block_bnd;

		/* not aligned */
		/* check if the size goes over flash block boundary */
		if ((fl_addr + remaining) <
		    ((fl_addr + CONFIG_FS_BLOCK_SIZE) &
		     ~(CONFIG_FS_BLOCK_SIZE - 1))) {
		block_bnd = fl_addr + CONFIG_FS_BLOCK_SIZE;
		block_bnd = block_bnd & ~(CONFIG_FS_BLOCK_SIZE - 1);
		if ((fl_addr + remaining) < block_bnd) {
			/* not over block boundary (a partial block also) */
			if (update_flash_block(fl_addr, remaining, buff) != 0) {
				return -EIO;
@@ -226,12 +233,14 @@ int disk_access_write(const uint8_t *buff, uint32_t start_sector,

	/* start is an erase-aligned address */
	while (remaining) {
		int rc;

		if (remaining < CONFIG_FS_BLOCK_SIZE) {
			break;
		}

		if (update_flash_block(fl_addr, CONFIG_FS_BLOCK_SIZE,
					buff) != 0) {
		rc = update_flash_block(fl_addr, CONFIG_FS_BLOCK_SIZE, buff);
		if (rc != 0) {
			return -EIO;
		}

+6 −5
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ static void *lba_to_address(uint32_t lba)
{
	__ASSERT(((lba * RAMDISK_SECTOR_SIZE) < RAMDISK_VOLUME_SIZE),
		 "FS bound error");

	return &ramdisk_buf[(lba * RAMDISK_SECTOR_SIZE)];
}