ref: 52eb9e1a099b937f814427a3af3d02021746e67f
parent: 33e5e17acb10fef145ac064394d579eb57426e86
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue Dec 8 11:43:19 EST 2015
Change ph_flags to ph_refctr in block device interface
--- a/lwext4/ext4_blockdev.c
+++ b/lwext4/ext4_blockdev.c
@@ -46,19 +46,23 @@
{
int rc;
ext4_assert(bdev);
-
+ ext4_assert(bdev->bdif);
ext4_assert(bdev->bdif->open &&
bdev->bdif->close &&
bdev->bdif->bread &&
bdev->bdif->bwrite);
+ if (bdev->bdif->ph_refctr) {
+ bdev->bdif->ph_refctr++;
+ return EOK;
+ }
+
/*Low level block init*/
rc = bdev->bdif->open(bdev);
if (rc != EOK)
return rc;
- bdev->bdif->ph_flags |= EXT4_BDEV_INITIALIZED;
-
+ bdev->bdif->ph_refctr = 1;
return EOK;
}
@@ -83,8 +87,13 @@
{
ext4_assert(bdev);
- bdev->bdif->ph_flags &= ~(EXT4_BDEV_INITIALIZED);
+ if (!bdev->bdif->ph_refctr)
+ return EOK;
+ bdev->bdif->ph_refctr--;
+ if (bdev->bdif->ph_refctr)
+ return EOK;
+
/*Low level block fini*/
return bdev->bdif->close(bdev);
}
@@ -143,7 +152,7 @@
ext4_assert(bdev && b);
- if (!(bdev->bdif->ph_flags & EXT4_BDEV_INITIALIZED))
+ if (!bdev->bdif->ph_refctr)
return EIO;
if (!(lba < bdev->lg_bcnt))
@@ -197,7 +206,7 @@
ext4_assert(bdev && b);
ext4_assert(b->buf);
- if (!(bdev->bdif->ph_flags & EXT4_BDEV_INITIALIZED))
+ if (!bdev->bdif->ph_refctr)
return EIO;
return ext4_bcache_free(bdev->bc, b);
@@ -249,7 +258,7 @@
ext4_assert(bdev && buf);
- if (!(bdev->bdif->ph_flags & EXT4_BDEV_INITIALIZED))
+ if (!bdev->bdif->ph_refctr)
return EIO;
block_idx = (off / bdev->bdif->ph_bsize) + bdev->ph_blk_offset;
@@ -321,7 +330,7 @@
ext4_assert(bdev && buf);
- if (!(bdev->bdif->ph_flags & EXT4_BDEV_INITIALIZED))
+ if (!bdev->bdif->ph_refctr)
return EIO;
block_idx = (off / bdev->bdif->ph_bsize) + bdev->ph_blk_offset;
--- a/lwext4/ext4_blockdev.h
+++ b/lwext4/ext4_blockdev.h
@@ -47,9 +47,6 @@
#include <stdbool.h>
#include <stdint.h>
-/**@brief Initialization status flag*/
-#define EXT4_BDEV_INITIALIZED (1 << 0)
-
struct ext4_blockdev_iface {
/**@brief Open device function
* @param bdev block device.*/
@@ -83,8 +80,8 @@
/**@brief Block size buffer: physical*/
uint8_t *ph_bbuf;
- /**@brief Flags of block device*/
- uint32_t ph_flags;
+ /**@brief Reference counter to block device interface*/
+ uint32_t ph_refctr;
};
/**@brief Definition of the simple block device.*/