13#if defined(OS_USE_OS_APP_CONFIG_H)
14#include <cmsis-plus/os-app-config.h>
30#pragma clang diagnostic ignored "-Wc++98-compat"
45#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
46 trace::printf (
"block_device::%s(\"%s\")=@%p\n", __func__, name_,
this);
54#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
55 trace::printf (
"block_device::%s() @%p %s\n", __func__,
this, name_);
64#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
65 trace::printf (
"block_device::%s(%p, %u, %u) @%p\n", __func__, buf,
66 blknum, nblocks,
this);
69 if (blknum + nblocks >
impl ().num_blocks_)
75 if (!
impl ().do_is_opened ())
88#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
89 trace::printf (
"block_device::%s(%p, %u, %u) @%p\n", __func__, buf,
90 blknum, nblocks,
this);
93 if (blknum + nblocks >
impl ().num_blocks_)
99 if (!
impl ().do_is_opened ())
111#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
112 trace::printf (
"block_device::%s(%d) @%p\n", __func__, request,
this);
115 if (!
impl ().do_is_opened ())
123 switch (
static_cast<unsigned int> (request))
128 std::size_t* sz = va_arg(args, std::size_t*);
129 if (sz ==
nullptr ||
impl ().block_logical_size_bytes_ != 0)
135 *sz =
impl ().block_logical_size_bytes_;
142 std::size_t* sz = va_arg(args, std::size_t*);
143 if (sz ==
nullptr ||
impl ().block_physical_size_bytes_ != 0)
149 *sz =
impl ().block_physical_size_bytes_;
156 uint64_t* sz = va_arg(args, uint64_t*);
157 if (sz ==
nullptr ||
impl ().num_blocks_ != 0)
163#pragma GCC diagnostic push
164#if defined(__clang__)
165#elif defined(__GNUC__)
166#pragma GCC diagnostic ignored "-Wuseless-cast"
168 *sz = (
static_cast<uint64_t
> (
impl ().num_blocks_
169 *
impl ().block_logical_size_bytes_));
170#pragma GCC diagnostic pop
186#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
187 trace::printf (
"block_device_impl::%s()=@%p\n", __func__,
this);
193#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
194 trace::printf (
"block_device_impl::%s() @%p\n", __func__,
this);
197 block_logical_size_bytes_ = 0;
206#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
247#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
248 trace::printf (
"block_device_impl::%s(%p, %u) @%p\n", __func__, buf,
252 if ((block_logical_size_bytes_ == 0)
253 || ((nbyte % block_logical_size_bytes_) != 0)
254 || ((
static_cast<std::size_t
> (offset_) % block_logical_size_bytes_)
261 std::size_t nblocks = nbyte / block_logical_size_bytes_;
262 blknum_t blknum =
static_cast<std::size_t
> (offset_)
263 / block_logical_size_bytes_;
265 if (blknum + nblocks > num_blocks_)
274 ret *=
static_cast<ssize_t
>(block_logical_size_bytes_);
282#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
283 trace::printf (
"block_device_impl::%s(%p, %u) @%p\n", __func__, buf,
287 if ((block_logical_size_bytes_ == 0)
288 || ((nbyte % block_logical_size_bytes_) != 0)
289 || ((
static_cast<std::size_t
> (offset_) % block_logical_size_bytes_)
296 std::size_t nblocks = nbyte / block_logical_size_bytes_;
297 blknum_t blknum =
static_cast<std::size_t
> (offset_)
298 / block_logical_size_bytes_;
300 if (blknum + nblocks > num_blocks_)
309 ret *=
static_cast<ssize_t
>(block_logical_size_bytes_);
virtual ssize_t do_read(void *buf, std::size_t nbyte) override
virtual off_t do_lseek(off_t offset, int whence) override
virtual ssize_t do_read_block(void *buf, blknum_t blknum, std::size_t nblocks)=0
virtual ~block_device_impl() override
virtual ssize_t do_write(const void *buf, std::size_t nbyte) override
virtual ssize_t do_write_block(const void *buf, blknum_t blknum, std::size_t nblocks)=0
block_device::blknum_t blknum_t
virtual ~block_device() override
block_device_impl & impl(void) const
virtual int vioctl(int request, std::va_list args) override
virtual ssize_t read_block(void *buf, blknum_t blknum, std::size_t nblocks=1)
virtual ssize_t write_block(const void *buf, blknum_t blknum, std::size_t nblocks=1)
virtual int do_vioctl(int request, std::va_list args)=0
static void link(value_type *device)
const char * name(void) const
int printf(const char *format,...)
Write a formatted string to the trace device.