µ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-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13#if defined(OS_USE_OS_APP_CONFIG_H)
14#include <cmsis-plus/os-app-config.h>
15#endif
16
18
20
21// ----------------------------------------------------------------------------
22
23#if defined(__clang__)
24#pragma clang diagnostic ignored "-Wc++98-compat"
25#endif
26
27// ----------------------------------------------------------------------------
28
29namespace os
30{
31 namespace posix
32 {
33 // ========================================================================
34
36 const char* name) :
38 { impl, name }
39 {
40#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
41 trace::printf ("block_device_partition::%s(\"%s\")=@%p\n", __func__,
42 name_, this);
43#endif
44 }
45
47 {
48#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
49 trace::printf ("block_device_partition::%s() @%p %s\n", __func__, this,
50 name_);
51#endif
52 }
53
54 // ------------------------------------------------------------------------
55
56 void
58 {
59#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
60 trace::printf ("block_device_partition::%s(%u,%u) @%p\n", __func__,
61 offset, nblocks, this);
62#endif
63
64 impl ().configure (offset, nblocks);
65 }
66
67 // ========================================================================
68
70 block_device& parent) :
71 parent_ (parent)
72 {
73#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
74 trace::printf ("block_device_partition_impl::%s()=@%p\n", __func__, this);
75#endif
76 }
77
79 {
80#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
81 trace::printf ("block_device_partition_impl::%s() @%p\n", __func__, 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__, this);
164#endif
165
166 return parent_.sync ();
167 }
168
169 int
171 {
172#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE_PARTITION)
173 trace::printf ("block_device_partition_impl::%s() @%p\n", __func__, this);
174#endif
175
176 return parent_.close ();
177 }
178
179 // ==========================================================================
180 } /* namespace posix */
181} /* namespace os */
182
183// ----------------------------------------------------------------------------
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:307
off_t offset(void)
Definition io.h:476
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:60
System namespace.