28#ifndef CMSIS_PLUS_POSIX_IO_BLOCK_DEVICE_H_
29#define CMSIS_PLUS_POSIX_IO_BLOCK_DEVICE_H_
33#if defined(__cplusplus)
37#if defined(OS_USE_OS_APP_CONFIG_H)
38#include <cmsis-plus/os-app-config.h>
45#pragma GCC diagnostic push
48#pragma clang diagnostic ignored "-Wc++98-compat"
59 class block_device_impl;
122 vioctl (
int request, std::va_list args)
override;
164#pragma GCC diagnostic push
165#pragma GCC diagnostic ignored "-Wpadded"
220 do_read (
void* buf, std::size_t nbyte)
override;
223 do_write (
const void* buf, std::size_t nbyte)
override;
233 std::size_t nblocks) = 0;
246 std::size_t block_logical_size_bytes_ = 0;
248 std::size_t block_physical_size_bytes_ = 0;
257#pragma GCC diagnostic pop
279 template<
typename ... Args>
339 template<
typename T,
typename L>
358 template<
typename ... Args>
394 close (
void)
override;
397 read (
void* buf, std::size_t nbyte)
override;
400 write (
const void* buf, std::size_t nbyte)
override;
403 writev (
const struct iovec* iov,
int iovcnt)
override;
406 vfcntl (
int cmd, std::va_list args)
override;
409 vioctl (
int request, std::va_list args)
override;
412 lseek (off_t offset,
int whence)
override;
423 sync (
void)
override;
466 return impl ().num_blocks_;
472 return impl ().block_logical_size_bytes_;
478 return impl ().block_physical_size_bytes_;
490 template<
typename ... Args>
492 const char* name, Args&&... args) :
494 { impl_instance_,
name },
496 { std::forward<Args>(args)... }
498#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
499 trace::printf (
"block_device_implementable::%s(\"%s\")=@%p\n",
500 __func__, name_,
this);
507#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
508 trace::printf (
"block_device_implementable::%s() @%p %s\n", __func__,
522 template<
typename T,
typename L>
523 template<
typename ... Args>
527 { impl_instance_,
name },
529 { std::forward<Args>(args)... },
532#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
533 trace::printf (
"block_device_lockable::%s(\"%s\")=@%p\n", __func__,
538 template<
typename T,
typename L>
541#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
542 trace::printf (
"block_device_lockable::%s() @%p %s\n", __func__,
this,
549 template<
typename T,
typename L>
553#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
554 trace::printf (
"block_device_lockable::%s() @%p\n", __func__,
this);
557 std::lock_guard<L> lock
563 template<
typename T,
typename L>
567#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
568 trace::printf (
"block_device_lockable::%s(0x0%X, %u) @%p\n", __func__,
572 std::lock_guard<L> lock
578 template<
typename T,
typename L>
582#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
583 trace::printf (
"block_device_lockable::%s(0x0%X, %u) @%p\n", __func__,
587 std::lock_guard<L> lock
593 template<
typename T,
typename L>
597#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
598 trace::printf (
"block_device_lockable::%s(0x0%X, %d) @%p\n", __func__,
602 std::lock_guard<L> lock
608 template<
typename T,
typename L>
612#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
613 trace::printf (
"block_device_lockable::%s(%d) @%p\n", __func__, cmd,
617 std::lock_guard<L> lock
623 template<
typename T,
typename L>
627#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
628 trace::printf (
"block_device_lockable::%s(%d) @%p\n", __func__, request,
632 std::lock_guard<L> lock
638 template<
typename T,
typename L>
642#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
643 trace::printf (
"block_device_lockable::%s(%d, %d) @%p\n", __func__,
644 offset, whence,
this);
647 std::lock_guard<L> lock
653 template<
typename T,
typename L>
658#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
659 trace::printf (
"block_device_lockable::%s(%p, %u, %u) @%p\n", __func__,
660 buf, blknum, nblocks,
this);
663 std::lock_guard<L> lock
669 template<
typename T,
typename L>
675#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
676 trace::printf (
"block_device_lockable::%s(%p, %u, %u) @%p\n", __func__,
677 buf, blknum, nblocks,
this);
680 std::lock_guard<L> lock
686 template<
typename T,
typename L>
690#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
691 trace::printf (
"block_device_lockable::%s() @%p\n", __func__,
this);
694 std::lock_guard<L> lock
700 template<
typename T,
typename L>
711#pragma GCC diagnostic pop
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
value_type & impl(void) const
block_device_implementable(const char *name, Args &&... args)
virtual ~block_device_implementable() override
virtual int vfcntl(int cmd, std::va_list args) override
virtual ssize_t writev(const struct iovec *iov, int iovcnt) override
virtual ssize_t read(void *buf, std::size_t nbyte) override
virtual void sync(void) override
virtual off_t lseek(off_t offset, int whence) override
virtual int vioctl(int request, std::va_list args) override
virtual int close(void) override
virtual ssize_t write_block(const void *buf, blknum_t blknum, std::size_t nblocks=1) override
block_device_lockable(const char *name, lockable_type &locker, Args &&... args)
virtual ssize_t read_block(void *buf, blknum_t blknum, std::size_t nblocks=1) override
virtual ssize_t write(const void *buf, std::size_t nbyte) override
value_type & impl(void) const
virtual ~block_device_lockable() override
std::size_t block_physical_size_bytes(void)
virtual ~block_device() override
std::size_t block_logical_size_bytes(void)
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 close(void) override
const char * name(void) const
virtual off_t lseek(off_t offset, int whence)
virtual ssize_t write(const void *buf, std::size_t nbyte)
virtual ssize_t read(void *buf, std::size_t nbyte)
virtual ssize_t writev(const struct iovec *iov, int iovcnt)
virtual int vfcntl(int cmd, std::va_list args)
int printf(const char *format,...)
Write a formatted string to the trace device.