| 103 | } |
| 104 | |
| 105 | static rt_ssize_t blk_dev_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) |
| 106 | { |
| 107 | int ret = 0; |
| 108 | struct fal_blk_device *part; |
| 109 | rt_off_t phy_pos; |
| 110 | rt_size_t phy_size; |
| 111 | |
| 112 | part = (struct fal_blk_device*) dev; |
| 113 | RT_ASSERT(part != RT_NULL); |
| 114 | |
| 115 | /* change the block device's logic address to physical address */ |
| 116 | phy_pos = pos * part->geometry.bytes_per_sector; |
| 117 | phy_size = size * part->geometry.bytes_per_sector; |
| 118 | |
| 119 | ret = fal_partition_erase(part->fal_part, phy_pos, phy_size); |
| 120 | |
| 121 | if (ret == (int) phy_size) |
| 122 | { |
| 123 | ret = fal_partition_write(part->fal_part, phy_pos, buffer, phy_size); |
| 124 | } |
| 125 | |
| 126 | if (ret != (int) phy_size) |
| 127 | { |
| 128 | ret = 0; |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | ret = size; |
| 133 | } |
| 134 | |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | #ifdef RT_USING_DEVICE_OPS |
| 139 | const static struct rt_device_ops blk_dev_ops = |
nothing calls this directly
no test coverage detected