µ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++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2018 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
29
31
32// ----------------------------------------------------------------------------
33
34#if defined(__clang__)
35#pragma clang diagnostic ignored "-Wc++98-compat"
36#endif
37
38// ----------------------------------------------------------------------------
39
40namespace os
41{
42 namespace posix
43 {
44 // ========================================================================
45
47 const char* name) :
49 { impl, name }
50 {
51#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
52 trace::printf ("block_device_partition::%s(\"%s\")=@%p\n", __func__,
53 name_, this);
54#endif
55 }
56
58 {
59#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
60 trace::printf ("block_device_partition::%s() @%p %s\n", __func__, this,
61 name_);
62#endif
63 }
64
65 // ------------------------------------------------------------------------
66
67 void
69 {
70#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
71 trace::printf ("block_device_partition::%s(%u,%u) @%p\n", __func__,
72 offset, nblocks, this);
73#endif
74
75 impl ().configure (offset, nblocks);
76 }
77
78 // ========================================================================
79
81 block_device& parent) :
82 parent_ (parent)
83 {
84#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
85 trace::printf ("block_device_partition_impl::%s()=@%p\n", __func__, this);
86#endif
87 }
88
90 {
91#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
92 trace::printf ("block_device_partition_impl::%s() @%p\n", __func__, this);
93#endif
94 }
95
96 // ----------------------------------------------------------------------
97
98#pragma GCC diagnostic push
99#pragma GCC diagnostic ignored "-Wunused-parameter"
100
101 int
102 block_device_partition_impl::do_vioctl (int request, std::va_list args)
103 {
104 errno = ENOSYS;
105 return -1;
106 }
107
108#pragma GCC diagnostic pop
109
110 void
112 {
113#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
114 trace::printf ("block_device_partition_impl::%s(%u,%u) @%p\n", __func__,
115 offset, nblocks, this);
116#endif
117
118 partition_offset_blocks_ = offset;
119 assert(nblocks > 0);
120 num_blocks_ = nblocks;
121
122 // Inherit from parent.
123 block_logical_size_bytes_ = parent_.block_logical_size_bytes ();
124 block_physical_size_bytes_ = parent_.block_physical_size_bytes ();
125 }
126
127 int
128 block_device_partition_impl::do_vopen (const char* path, int oflag,
129 std::va_list args)
130 {
131#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
132 trace::printf ("block_device_partition_impl::%s(%d) @%p\n", __func__,
133 oflag, this);
134#endif
135
136 return parent_.vopen (path, oflag, args);
137 }
138
139 ssize_t
141 std::size_t nblocks)
142 {
143#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
144 trace::printf ("block_device_partition_impl::%s(0x%X, %u, %u) @%p\n",
145 __func__, buf, blknum, nblocks, this);
146#endif
147
148 return parent_.read_block (buf, blknum + partition_offset_blocks_,
149 nblocks);
150 }
151
152 ssize_t
154 blknum_t blknum,
155 std::size_t nblocks)
156 {
157#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
158 trace::printf ("block_device_partition_impl::%s(0x%X, %u, %u) @%p\n",
159 __func__, buf, blknum, nblocks, this);
160#endif
161
162 return parent_.write_block (buf, blknum + partition_offset_blocks_,
163 nblocks);
164 }
165
166 void
168 {
169#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
170 trace::printf ("block_device_partition_impl::%s() @%p\n", __func__, this);
171#endif
172
173 return parent_.sync ();
174 }
175
176 int
178 {
179#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
180 trace::printf ("block_device_partition_impl::%s() @%p\n", __func__, this);
181#endif
182
183 return parent_.close ();
184 }
185
186 // ==========================================================================
187 } /* namespace posix */
188} /* namespace os */
189
190// ----------------------------------------------------------------------------
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.
const char * name(void) const
Definition device.h:310
off_t offset(void)
Definition io.h:461
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
System namespace.