13#ifndef CMSIS_PLUS_POSIX_IO_BLOCK_DEVICE_H_
14#define CMSIS_PLUS_POSIX_IO_BLOCK_DEVICE_H_
18#if defined(__cplusplus)
22#if defined(OS_USE_OS_APP_CONFIG_H)
23#include <cmsis-plus/os-app-config.h>
30#pragma GCC diagnostic push
32#pragma clang diagnostic ignored "-Wc++98-compat"
43 class block_device_impl;
55#pragma GCC diagnostic push
57#elif defined(__GNUC__)
58#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
59#pragma GCC diagnostic ignored "-Wsuggest-final-types"
112 vioctl (
int request, std::va_list args)
override;
151#pragma GCC diagnostic pop
155#pragma GCC diagnostic push
156#if defined(__clang__)
157#pragma clang diagnostic ignored "-Wpadded"
158#elif defined(__GNUC__)
159#pragma GCC diagnostic ignored "-Wpadded"
215 do_read (
void* buf, std::size_t nbyte)
override;
218 do_write (
const void* buf, std::size_t nbyte)
override;
228 std::size_t nblocks) = 0;
241 std::size_t block_logical_size_bytes_ = 0;
243 std::size_t block_physical_size_bytes_ = 0;
252#pragma GCC diagnostic pop
256#pragma GCC diagnostic push
257#if defined(__clang__)
258#elif defined(__GNUC__)
259#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
260#pragma GCC diagnostic ignored "-Wsuggest-final-types"
280 template<
typename ... Args>
337#pragma GCC diagnostic pop
341 template<
typename T,
typename L>
360 template<
typename ... Args>
396 close (
void)
override;
399 read (
void* buf, std::size_t nbyte)
override;
402 write (
const void* buf, std::size_t nbyte)
override;
408 vfcntl (
int cmd, std::va_list args)
override;
411 vioctl (
int request, std::va_list args)
override;
414 lseek (off_t offset,
int whence)
override;
425 sync (
void)
override;
468 return impl ().num_blocks_;
474 return impl ().block_logical_size_bytes_;
480 return impl ().block_physical_size_bytes_;
492 template<
typename ... Args>
494 const char* name, Args&&... args) :
496 { impl_instance_,
name },
498 { std::forward<Args>(args)... }
500#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
501 trace::printf (
"block_device_implementable::%s(\"%s\")=@%p\n",
502 __func__, name_,
this);
506#pragma GCC diagnostic push
507#if defined(__clang__)
508#elif defined(__GNUC__)
509#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
514#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
515 trace::printf (
"block_device_implementable::%s() @%p %s\n", __func__,
519#pragma GCC diagnostic pop
530 template<
typename T,
typename L>
531 template<
typename ... Args>
535 { impl_instance_,
name },
537 { std::forward<Args>(args)... },
540#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
541 trace::printf (
"block_device_lockable::%s(\"%s\")=@%p\n", __func__,
546 template<
typename T,
typename L>
549#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
550 trace::printf (
"block_device_lockable::%s() @%p %s\n", __func__,
this,
557 template<
typename T,
typename L>
561#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
562 trace::printf (
"block_device_lockable::%s() @%p\n", __func__,
this);
565 std::lock_guard<L> lock
571 template<
typename T,
typename L>
575#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
576 trace::printf (
"block_device_lockable::%s(0x0%X, %u) @%p\n", __func__,
580 std::lock_guard<L> lock
586 template<
typename T,
typename L>
590#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
591 trace::printf (
"block_device_lockable::%s(0x0%X, %u) @%p\n", __func__,
595 std::lock_guard<L> lock
601 template<
typename T,
typename L>
605#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
606 trace::printf (
"block_device_lockable::%s(0x0%X, %d) @%p\n", __func__,
610 std::lock_guard<L> lock
616 template<
typename T,
typename L>
620#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
621 trace::printf (
"block_device_lockable::%s(%d) @%p\n", __func__, cmd,
625 std::lock_guard<L> lock
631 template<
typename T,
typename L>
635#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
636 trace::printf (
"block_device_lockable::%s(%d) @%p\n", __func__, request,
640 std::lock_guard<L> lock
646 template<
typename T,
typename L>
650#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
651 trace::printf (
"block_device_lockable::%s(%d, %d) @%p\n", __func__,
652 offset, whence,
this);
655 std::lock_guard<L> lock
661 template<
typename T,
typename L>
666#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
667 trace::printf (
"block_device_lockable::%s(%p, %u, %u) @%p\n", __func__,
668 buf, blknum, nblocks,
this);
671 std::lock_guard<L> lock
677 template<
typename T,
typename L>
683#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
684 trace::printf (
"block_device_lockable::%s(%p, %u, %u) @%p\n", __func__,
685 buf, blknum, nblocks,
this);
688 std::lock_guard<L> lock
694 template<
typename T,
typename L>
698#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
699 trace::printf (
"block_device_lockable::%s() @%p\n", __func__,
this);
702 std::lock_guard<L> lock
708 template<
typename T,
typename L>
719#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 ssize_t writev(const iovec *iov, int iovcnt) override
virtual int vfcntl(int cmd, std::va_list args) 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 ssize_t writev(const iovec *iov, int iovcnt)
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 int vfcntl(int cmd, std::va_list args)
int printf(const char *format,...)
Write a formatted string to the trace device.