diff options
| author | gkostka <kostka.grzegorz@gmail.com> | 2015-12-08 16:43:19 +0100 |
|---|---|---|
| committer | gkostka <kostka.grzegorz@gmail.com> | 2015-12-08 16:43:19 +0100 |
| commit | 52eb9e1a099b937f814427a3af3d02021746e67f (patch) | |
| tree | a3543f11339251606249e8e84b89abc48e22e65b | |
| parent | 33e5e17acb10fef145ac064394d579eb57426e86 (diff) | |
Change ph_flags to ph_refctr in block device interface
| -rw-r--r-- | lwext4/ext4_blockdev.c | 25 | ||||
| -rw-r--r-- | lwext4/ext4_blockdev.h | 7 |
2 files changed, 19 insertions, 13 deletions
diff --git a/lwext4/ext4_blockdev.c b/lwext4/ext4_blockdev.c index 03d15eb..bbc2fef 100644 --- a/lwext4/ext4_blockdev.c +++ b/lwext4/ext4_blockdev.c @@ -46,19 +46,23 @@ int ext4_block_init(struct ext4_blockdev *bdev) { 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,7 +87,12 @@ int ext4_block_fini(struct ext4_blockdev *bdev) { 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 @@ int ext4_block_get_noread(struct ext4_blockdev *bdev, struct ext4_block *b, 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 @@ int ext4_block_set(struct ext4_blockdev *bdev, struct ext4_block *b) 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 @@ int ext4_block_writebytes(struct ext4_blockdev *bdev, uint64_t off, 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 @@ int ext4_block_readbytes(struct ext4_blockdev *bdev, uint64_t off, void *buf, 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; diff --git a/lwext4/ext4_blockdev.h b/lwext4/ext4_blockdev.h index e55f42e..51e4335 100644 --- a/lwext4/ext4_blockdev.h +++ b/lwext4/ext4_blockdev.h @@ -47,9 +47,6 @@ extern "C" { #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 @@ struct ext4_blockdev_iface { /**@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.*/ |
