µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::posix::block_device_partition_impl Class Reference

#include <block-device-partition.h>

+ Inheritance diagram for os::posix::block_device_partition_impl:

Public Types

using blknum_t = block_device::blknum_t
 

Public Member Functions

Constructors & Destructor
 block_device_partition_impl (block_device &parent)
 
virtual ~block_device_partition_impl () override
 
Public Member Functions
virtual int do_vioctl (int request, std::va_list args) override
 
virtual int do_vopen (const char *path, int oflag, std::va_list args) override
 
virtual ssize_t do_read_block (void *buf, blknum_t blknum, std::size_t nblocks) override
 
virtual ssize_t do_write_block (const void *buf, blknum_t blknum, std::size_t nblocks) override
 
virtual void do_sync (void) override
 
virtual int do_close (void) override
 
void configure (blknum_t offset, blknum_t nblocks)
 
Public Member Functions
virtual ssize_t do_read (void *buf, std::size_t nbyte) override
 
virtual ssize_t do_write (const void *buf, std::size_t nbyte) override
 
virtual off_t do_lseek (off_t offset, int whence) override
 
Public Member Functions
virtual bool do_is_opened (void) override
 
int open_count (void)
 
Public Member Functions
virtual void do_deallocate (void)
 
virtual bool do_is_connected (void)
 
virtual ssize_t do_writev (const iovec *iov, int iovcnt)
 
virtual int do_vfcntl (int cmd, std::va_list args)
 
virtual int do_isatty (void)
 
virtual int do_fstat (struct stat *buf)
 
off_t offset (void)
 
void offset (off_t offset)
 

Private Attributes

friend block_device_partition
 

Detailed Description

Definition at line 118 of file block-device-partition.h.

Member Typedef Documentation

◆ blknum_t

Constructor & Destructor Documentation

◆ block_device_partition_impl()

os::posix::block_device_partition_impl::block_device_partition_impl ( block_device parent)

Definition at line 67 of file block-device-partition.cpp.

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 }
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59

References os::trace::printf().

◆ ~block_device_partition_impl()

os::posix::block_device_partition_impl::~block_device_partition_impl ( )
overridevirtual

Definition at line 77 of file block-device-partition.cpp.

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 }

References os::trace::printf().

Member Function Documentation

◆ configure()

void os::posix::block_device_partition_impl::configure ( blknum_t  offset,
blknum_t  nblocks 
)

Definition at line 104 of file block-device-partition.cpp.

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 }
off_t offset(void)
Definition io.h:472

References os::posix::io_impl::offset(), and os::trace::printf().

Referenced by os::posix::block_device_partition::configure().

◆ do_close()

int os::posix::block_device_partition_impl::do_close ( void  )
overridevirtual

Implements os::posix::io_impl.

Definition at line 171 of file block-device-partition.cpp.

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 }

References os::trace::printf().

◆ do_deallocate()

void os::posix::io_impl::do_deallocate ( void  )
virtualinherited

Definition at line 482 of file io.cpp.

483 {
484 return;
485 }

◆ do_fstat()

int os::posix::io_impl::do_fstat ( struct stat buf)
virtualinherited

Definition at line 539 of file io.cpp.

540 {
541 errno = ENOSYS; // Not implemented
542 return -1;
543 }

Referenced by os::posix::io::fstat().

◆ do_is_connected()

bool os::posix::io_impl::do_is_connected ( void  )
virtualinherited

Definition at line 496 of file io.cpp.

497 {
498 return true;
499 }

◆ do_is_opened()

bool os::posix::device_impl::do_is_opened ( void  )
overridevirtualinherited

Implements os::posix::io_impl.

Definition at line 216 of file device.cpp.

217 {
218 return (open_count_ > 0);
219 }

◆ do_isatty()

int os::posix::io_impl::do_isatty ( void  )
virtualinherited

Reimplemented in os::posix::tty_impl.

Definition at line 532 of file io.cpp.

533 {
534 errno = ENOTTY; // By default, it is not a TTY.
535 return 0;
536 }

Referenced by os::posix::io::isatty().

◆ do_lseek()

off_t os::posix::block_device_impl::do_lseek ( off_t  offset,
int  whence 
)
overridevirtualinherited

Implements os::posix::io_impl.

Definition at line 206 of file block-device.cpp.

207 {
208#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
209 trace::printf ("block_device_impl::%s(%d, %d) @%p\n", __func__, offset,
210 whence, this);
211#endif
212
213 errno = 0;
214 off_t tmp = offset_;
215
216 switch (whence)
217 {
218 case SEEK_SET:
219 tmp = offset;
220 break;
221
222 case SEEK_CUR:
223 tmp += offset;
224 break;
225
226 case SEEK_END:
227 errno = EINVAL;
228 return -1;
229
230 default:
231 errno = EINVAL;
232 return -1;
233 }
234
235 if (tmp < 0)
236 {
237 errno = EINVAL;
238 return -1;
239 }
240 offset_ = tmp;
241 return tmp;
242 }

References os::posix::io_impl::offset(), and os::trace::printf().

◆ do_read()

ssize_t os::posix::block_device_impl::do_read ( void *  buf,
std::size_t  nbyte 
)
overridevirtualinherited

Implements os::posix::io_impl.

Definition at line 247 of file block-device.cpp.

248 {
249#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
250 trace::printf ("block_device_impl::%s(%p, %u) @%p\n", __func__, buf,
251 nbyte, this);
252#endif
253
254 if ((block_logical_size_bytes_ == 0)
255 || ((nbyte % block_logical_size_bytes_) != 0)
256 || ((static_cast<std::size_t> (offset_) % block_logical_size_bytes_)
257 != 0))
258 {
259 errno = EINVAL;
260 return -1;
261 }
262
263 std::size_t nblocks = nbyte / block_logical_size_bytes_;
264 blknum_t blknum
265 = static_cast<std::size_t> (offset_) / block_logical_size_bytes_;
266
267 if (blknum + nblocks > num_blocks_)
268 {
269 errno = EINVAL;
270 return -1;
271 }
272
273 ssize_t ret = do_read_block (buf, blknum, nblocks);
274 if (ret >= 0)
275 {
276 ret *= static_cast<ssize_t> (block_logical_size_bytes_);
277 }
278 return ret;
279 }
virtual ssize_t do_read_block(void *buf, blknum_t blknum, std::size_t nblocks)=0
block_device::blknum_t blknum_t

References os::posix::block_device_impl::do_read_block(), and os::trace::printf().

◆ do_read_block()

ssize_t os::posix::block_device_partition_impl::do_read_block ( void *  buf,
blknum_t  blknum,
std::size_t  nblocks 
)
overridevirtual

Implements os::posix::block_device_impl.

Definition at line 133 of file block-device-partition.cpp.

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 }

References os::trace::printf().

◆ do_sync()

void os::posix::block_device_partition_impl::do_sync ( void  )
overridevirtual

Implements os::posix::device_impl.

Definition at line 160 of file block-device-partition.cpp.

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 }

References os::trace::printf().

◆ do_vfcntl()

int os::posix::io_impl::do_vfcntl ( int  cmd,
std::va_list  args 
)
virtualinherited

Definition at line 525 of file io.cpp.

526 {
527 errno = ENOSYS; // Not implemented
528 return -1;
529 }

Referenced by os::posix::io::vfcntl().

◆ do_vioctl()

int os::posix::block_device_partition_impl::do_vioctl ( int  request,
std::va_list  args 
)
overridevirtual

Implements os::posix::device_impl.

Definition at line 95 of file block-device-partition.cpp.

96 {
97 errno = ENOSYS;
98 return -1;
99 }

◆ do_vopen()

int os::posix::block_device_partition_impl::do_vopen ( const char *  path,
int  oflag,
std::va_list  args 
)
overridevirtual

Implements os::posix::device_impl.

Definition at line 121 of file block-device-partition.cpp.

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 }

References os::trace::printf().

◆ do_write()

ssize_t os::posix::block_device_impl::do_write ( const void *  buf,
std::size_t  nbyte 
)
overridevirtualinherited

Implements os::posix::io_impl.

Definition at line 282 of file block-device.cpp.

283 {
284#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
285 trace::printf ("block_device_impl::%s(%p, %u) @%p\n", __func__, buf,
286 nbyte, this);
287#endif
288
289 if ((block_logical_size_bytes_ == 0)
290 || ((nbyte % block_logical_size_bytes_) != 0)
291 || ((static_cast<std::size_t> (offset_) % block_logical_size_bytes_)
292 != 0))
293 {
294 errno = EINVAL;
295 return -1;
296 }
297
298 std::size_t nblocks = nbyte / block_logical_size_bytes_;
299 blknum_t blknum
300 = static_cast<std::size_t> (offset_) / block_logical_size_bytes_;
301
302 if (blknum + nblocks > num_blocks_)
303 {
304 errno = EINVAL;
305 return -1;
306 }
307
308 ssize_t ret = do_write_block (buf, blknum, nblocks);
309 if (ret >= 0)
310 {
311 ret *= static_cast<ssize_t> (block_logical_size_bytes_);
312 }
313 return ret;
314 }
virtual ssize_t do_write_block(const void *buf, blknum_t blknum, std::size_t nblocks)=0

References os::posix::block_device_impl::do_write_block(), and os::trace::printf().

◆ do_write_block()

ssize_t os::posix::block_device_partition_impl::do_write_block ( const void *  buf,
blknum_t  blknum,
std::size_t  nblocks 
)
overridevirtual

Implements os::posix::block_device_impl.

Definition at line 146 of file block-device-partition.cpp.

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 }

References os::trace::printf().

◆ do_writev()

ssize_t os::posix::io_impl::do_writev ( const iovec iov,
int  iovcnt 
)
virtualinherited

Definition at line 502 of file io.cpp.

503 {
504 ssize_t total = 0;
505
506#pragma GCC diagnostic push
507#if defined(__clang__)
508#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
509#endif
510 const /* struct */ iovec* p = iov;
511 for (int i = 0; i < iovcnt; ++i, ++p)
512 {
513 ssize_t ret = do_write (p->iov_base, p->iov_len);
514 if (ret < 0)
515 {
516 return ret;
517 }
518 total += ret;
519 }
520#pragma GCC diagnostic pop
521 return total;
522 }
virtual ssize_t do_write(const void *buf, std::size_t nbyte)=0
Definition uio.h:40
void * iov_base
Definition uio.h:41
size_t iov_len
Definition uio.h:42

References os::posix::io_impl::do_write(), iovec::iov_base, and iovec::iov_len.

Referenced by os::posix::io::writev().

◆ offset() [1/2]

void os::posix::io_impl::offset ( off_t  offset)
inlineinherited

Definition at line 478 of file io.h.

479 {
480 offset_ = offset;
481 }

References os::posix::io_impl::offset().

◆ offset() [2/2]

off_t os::posix::io_impl::offset ( void  )
inlineinherited

Definition at line 472 of file io.h.

473 {
474 return offset_;
475 }

Referenced by configure(), os::posix::block_device_impl::do_lseek(), and os::posix::io_impl::offset().

◆ open_count()

int os::posix::device_impl::open_count ( void  )
inlineinherited

Definition at line 324 of file device.h.

325 {
326 return open_count_;
327 }

Member Data Documentation

◆ block_device_partition

friend os::posix::block_device_partition_impl::block_device_partition
private

Definition at line 122 of file block-device-partition.h.


The documentation for this class was generated from the following files: