µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
block-device-partition.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2018-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#if defined(OS_USE_OS_APP_CONFIG_H)
13#include <cmsis-plus/os-app-config.h>
14#endif
15
17
19
20// ----------------------------------------------------------------------------
21
22#if defined(__clang__)
23#pragma clang diagnostic ignored "-Wc++98-compat"
24#endif
25
26// ----------------------------------------------------------------------------
27
28namespace os
29{
30 namespace posix
31 {
32 // ========================================================================
33
35 const char* name)
36 : block_device{ impl, name }
37 {
38#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
39 trace::printf ("block_device_partition::%s(\"%s\")=@%p\n", __func__,
40 name_, this);
41#endif
42 }
43
45 {
46#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
47 trace::printf ("block_device_partition::%s() @%p %s\n", __func__, this,
48 name_);
49#endif
50 }
51
52 // ------------------------------------------------------------------------
53
54 void
56 {
57#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
58 trace::printf ("block_device_partition::%s(%u,%u) @%p\n", __func__,
59 offset, nblocks, this);
60#endif
61
62 impl ().configure (offset, nblocks);
63 }
64
65 // ========================================================================
66
68 block_device& parent)
69 : parent_ (parent)
70 {
71#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
72 trace::printf ("block_device_partition_impl::%s()=@%p\n", __func__,
73 this);
74#endif
75 }
76
78 {
79#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
80 trace::printf ("block_device_partition_impl::%s() @%p\n", __func__,
81 this);
82#endif
83 }
84
85 // ------------------------------------------------------------------------
86
87#pragma GCC diagnostic push
88#if defined(__clang__)
89#pragma clang diagnostic ignored "-Wunused-parameter"
90#elif defined(__GNUC__)
91#pragma GCC diagnostic ignored "-Wunused-parameter"
92#endif
93
94 int
95 block_device_partition_impl::do_vioctl (int request, std::va_list args)
96 {
97 errno = ENOSYS;
98 return -1;
99 }
100
101#pragma GCC diagnostic pop
102
103 void
105 {
106#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
107 trace::printf ("block_device_partition_impl::%s(%u,%u) @%p\n", __func__,
108 offset, nblocks, this);
109#endif
110
111 partition_offset_blocks_ = offset;
112 assert (nblocks > 0);
113 num_blocks_ = nblocks;
114
115 // Inherit from parent.
116 block_logical_size_bytes_ = parent_.block_logical_size_bytes ();
117 block_physical_size_bytes_ = parent_.block_physical_size_bytes ();
118 }
119
120 int
121 block_device_partition_impl::do_vopen (const char* path, int oflag,
122 std::va_list args)
123 {
124#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
125 trace::printf ("block_device_partition_impl::%s(%d) @%p\n", __func__,
126 oflag, this);
127#endif
128
129 return parent_.vopen (path, oflag, args);
130 }
131
132 ssize_t
134 std::size_t nblocks)
135 {
136#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
137 trace::printf ("block_device_partition_impl::%s(0x%X, %u, %u) @%p\n",
138 __func__, buf, blknum, nblocks, this);
139#endif
140
141 return parent_.read_block (buf, blknum + partition_offset_blocks_,
142 nblocks);
143 }
144
145 ssize_t
147 blknum_t blknum,
148 std::size_t nblocks)
149 {
150#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
151 trace::printf ("block_device_partition_impl::%s(0x%X, %u, %u) @%p\n",
152 __func__, buf, blknum, nblocks, this);
153#endif
154
155 return parent_.write_block (buf, blknum + partition_offset_blocks_,
156 nblocks);
157 }
158
159 void
161 {
162#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
163 trace::printf ("block_device_partition_impl::%s() @%p\n", __func__,
164 this);
165#endif
166
167 return parent_.sync ();
168 }
169
170 int
172 {
173#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
174 trace::printf ("block_device_partition_impl::%s() @%p\n", __func__,
175 this);
176#endif
177
178 return parent_.close ();
179 }
180
181 // ========================================================================
182 } /* namespace posix */
183} /* namespace os */
184
185// ----------------------------------------------------------------------------
block_device::blknum_t blknum_t
virtual int do_vopen(const char *path, int oflag, std::va_list args) override
virtual int do_vioctl(int request, std::va_list args) override
virtual ssize_t do_write_block(const void *buf, blknum_t blknum, std::size_t nblocks) override
void configure(blknum_t offset, blknum_t nblocks)
virtual ssize_t do_read_block(void *buf, blknum_t blknum, std::size_t nblocks) override
block_device_partition_impl & impl(void) const
block_device_partition(block_device_impl &impl, const char *name)
void configure(blknum_t offset, blknum_t nblocks)
Block device class.
off_t offset(void)
Definition io.h:472
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
System namespace.