µ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_implementable< T > Class Template Reference

#include <block-device.h>

+ Inheritance diagram for os::posix::block_device_implementable< T >:

Public Types

using blknum_t = std::size_t
 
using value_type = T
 
Types & Constants
enum class  type : type_t {
  unknown = 0 ,
  not_set = 1 << 0 ,
  char_device = 1 << 1 ,
  block_device = 1 << 2 ,
  tty = 1 << 3 ,
  file = 1 << 4 ,
  socket = 1 << 5
}
 
using type_t = unsigned int
 

Public Member Functions

Constructors & Destructor
template<typename... Args>
 block_device_implementable (const char *name, Args &&... args)
 
virtual ~block_device_implementable () override
 
Public Member Functions
value_typeimpl (void) const
 
Public Member Functions
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)
 
blknum_t blocks (void)
 
std::size_t block_logical_size_bytes (void)
 
std::size_t block_physical_size_bytes (void)
 
Public Member Functions
virtual ssize_t read (void *buf, std::size_t nbyte)
 
virtual ssize_t write (const void *buf, std::size_t nbyte)
 
virtual ssize_t writev (const iovec *iov, int iovcnt)
 
int fcntl (int cmd,...)
 
virtual int vfcntl (int cmd, std::va_list args)
 
int isatty (void)
 
virtual int fstat (struct stat *buf)
 
virtual off_t lseek (off_t offset, int whence)
 
type_t get_type (void) const
 
file_descriptor_t file_descriptor (void) const
 
bool is_opened (void)
 

Protected Member Functions

Private Member Functions
void file_descriptor (file_descriptor_t fildes)
 
void clear_file_descriptor (void)
 
ioalloc_file_descriptor (void)
 

Public Member Functions

int open (const char *path=nullptr, int oflag=0,...)
 
int vopen (const char *path, int oflag, std::va_list args)
 
virtual int close (void) override
 
int ioctl (int request,...)
 
virtual void sync (void)
 
virtual bool match_name (const char *name) const
 
const char * name (void) const
 
static const char * device_prefix (void)
 

Detailed Description

template<typename T>
class os::posix::block_device_implementable< T >

Definition at line 258 of file block-device.h.

Member Typedef Documentation

◆ blknum_t

using os::posix::block_device::blknum_t = std::size_t
inherited

Definition at line 65 of file block-device.h.

◆ type_t

using os::posix::io::type_t = unsigned int
inherited

Definition at line 125 of file io.h.

◆ value_type

template<typename T >
using os::posix::block_device_implementable< T >::value_type = T

Definition at line 263 of file block-device.h.

Member Enumeration Documentation

◆ type

enum class os::posix::io::type : type_t
stronginherited
Enumerator
unknown 
not_set 
char_device 
block_device 
tty 
file 
socket 

Definition at line 126 of file io.h.

127 {
128 unknown = 0,
129 not_set = 1 << 0,
130 char_device = 1 << 1,
131 block_device = 1 << 2,
132 tty = 1 << 3,
133 file = 1 << 4,
134 socket = 1 << 5
135 };

Constructor & Destructor Documentation

◆ block_device_implementable()

template<typename T >
template<typename... Args>
os::posix::block_device_implementable< T >::block_device_implementable ( const char *  name,
Args &&...  args 
)

Definition at line 482 of file block-device.h.

484 : block_device{ impl_instance_, name }, //
485 impl_instance_{ std::forward<Args> (args)... }
486 {
487#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
488 trace::printf ("block_device_implementable::%s(\"%s\")=@%p\n", __func__,
489 name_, this);
490#endif
491 }
block_device(block_device_impl &impl, const char *name)
const char * name(void) const
Definition device.h:304
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59

References os::trace::printf().

◆ ~block_device_implementable()

template<typename T >
os::posix::block_device_implementable< T >::~block_device_implementable
overridevirtual

Definition at line 499 of file block-device.h.

500 {
501#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
502 trace::printf ("block_device_implementable::%s() @%p %s\n", __func__,
503 this, name_);
504#endif
505 }

References os::trace::printf().

Member Function Documentation

◆ alloc_file_descriptor()

io * os::posix::io::alloc_file_descriptor ( void  )
protectedinherited

Definition at line 189 of file io.cpp.

190 {
191#if defined(OS_TRACE_POSIX_IO_IO)
192 trace::printf ("io::%s() @%p\n", __func__, this);
193#endif
194
196 if (fd < 0)
197 {
198 // If allocation failed, close this object.
199 impl ().do_close ();
201 return nullptr;
202 }
203
204#if defined(OS_TRACE_POSIX_IO_IO)
205 trace::printf ("io::%s() @%p fd=%d\n", __func__, this, fd);
206#endif
207
208 // Return a valid pointer to an object derived from `io`.
209 return this;
210 }
virtual int do_close(void)=0
io_impl & impl(void) const
Definition io.h:464
void clear_file_descriptor(void)
Definition io.h:446

References os::posix::file_descriptors_manager::allocate(), os::posix::io::clear_file_descriptor(), os::posix::io_impl::do_close(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::socket::accept(), os::posix::socket(), os::posix::device::vopen(), and os::posix::file_system::vopen().

◆ block_logical_size_bytes()

std::size_t os::posix::block_device::block_logical_size_bytes ( void  )
inlineinherited
Returns
The number of bytes in a block.

Definition at line 461 of file block-device.h.

462 {
463 return impl ().block_logical_size_bytes_;
464 }
block_device_impl & impl(void) const

References os::posix::block_device::impl().

◆ block_physical_size_bytes()

std::size_t os::posix::block_device::block_physical_size_bytes ( void  )
inlineinherited

Definition at line 467 of file block-device.h.

468 {
469 return impl ().block_physical_size_bytes_;
470 }

References os::posix::block_device::impl().

◆ blocks()

block_device::blknum_t os::posix::block_device::blocks ( void  )
inlineinherited
Returns
The number of blocks.

Definition at line 455 of file block-device.h.

456 {
457 return impl ().num_blocks_;
458 }

References os::posix::block_device::impl().

◆ clear_file_descriptor()

void os::posix::io::clear_file_descriptor ( void  )
inlineprotectedinherited

Definition at line 446 of file io.h.

447 {
448 file_descriptor_ = no_file_descriptor;
449 }
constexpr file_descriptor_t no_file_descriptor
Definition types.h:44

References os::posix::no_file_descriptor.

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

◆ close()

int os::posix::device::close ( void  )
overridevirtualinherited

Reimplemented from os::posix::io.

Reimplemented in os::posix::block_device_lockable< T, L >.

Definition at line 111 of file device.cpp.

112 {
113#if defined(OS_TRACE_POSIX_IO_DEVICE)
114 trace::printf ("device::%s() @%p\n", __func__, this);
115#endif
116
117 errno = 0;
118
119 int ret = 0;
120 if (impl ().open_count_ == 1)
121 {
122 ret = io::close ();
123 }
124
125 if (impl ().open_count_ > 0)
126 {
127 // Must be after close(), to keep do_is_open() true.
128 --(impl ().open_count_);
129 }
130
131 return ret;
132 }
device_impl & impl(void) const
Definition device.h:310
virtual int close(void)
Definition io.cpp:164

References os::posix::io::close(), os::posix::device::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::close().

◆ device_prefix()

const char * os::posix::device::device_prefix ( void  )
inlinestaticinherited

Definition at line 316 of file device.h.

317 {
319 }
#define OS_STRING_POSIX_DEVICE_PREFIX
Definition device.h:32

References OS_STRING_POSIX_DEVICE_PREFIX.

◆ fcntl()

int os::posix::io::fcntl ( int  cmd,
  ... 
)
inherited

Definition at line 363 of file io.cpp.

364 {
365 // Forward to the variadic version of the function.
366 std::va_list args;
367 va_start (args, cmd);
368 int ret = vfcntl (cmd, args);
369 va_end (args);
370
371 return ret;
372 }
virtual int vfcntl(int cmd, std::va_list args)
Definition io.cpp:380

References os::posix::io::vfcntl().

◆ file_descriptor() [1/2]

void os::posix::io::file_descriptor ( file_descriptor_t  fildes)
inlineprotectedinherited

Definition at line 440 of file io.h.

441 {
442 file_descriptor_ = fildes;
443 }

◆ file_descriptor() [2/2]

file_descriptor_t os::posix::io::file_descriptor ( void  ) const
inlineinherited

Definition at line 452 of file io.h.

453 {
454 return file_descriptor_;
455 }

Referenced by os::posix::file_descriptors_manager::allocate(), os::posix::file_descriptors_manager::assign(), os::posix::device::vopen(), and os::posix::vopen().

◆ fstat()

int os::posix::io::fstat ( struct stat buf)
virtualinherited

Reimplemented in os::posix::file_lockable< T, L >.

Definition at line 416 of file io.cpp.

417 {
418#if defined(OS_TRACE_POSIX_IO_IO)
419 trace::printf ("io::%s(%p) @%p\n", __func__, buf, this);
420#endif
421
422 if (buf == nullptr)
423 {
424 errno = EFAULT;
425 return -1;
426 }
427
428 if (!impl ().do_is_opened ())
429 {
430 errno = EBADF; // Not opened.
431 return -1;
432 }
433
434 if (!impl ().do_is_connected ())
435 {
436 errno = EIO; // Not opened.
437 return -1;
438 }
439
440 errno = 0;
441
442 // Execute the implementation specific code.
443 return impl ().do_fstat (buf);
444 }
virtual int do_fstat(struct stat *buf)
Definition io.cpp:539

References os::posix::io_impl::do_fstat(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::file_lockable< T, L >::fstat().

◆ get_type()

io::type_t os::posix::io::get_type ( void  ) const
inlineinherited

Definition at line 434 of file io.h.

435 {
436 return type_;
437 }

Referenced by os::posix::file_descriptors_manager::socket().

◆ impl()

template<typename T >
block_device_implementable< T >::value_type & os::posix::block_device_implementable< T >::impl ( void  ) const

Definition at line 510 of file block-device.h.

511 {
512 return static_cast<value_type&> (impl_);
513 }

◆ ioctl()

int os::posix::device::ioctl ( int  request,
  ... 
)
inherited

Definition at line 135 of file device.cpp.

136 {
137 // Forward to the variadic version of the function.
138 std::va_list args;
139 va_start (args, request);
140 int ret = vioctl (request, args);
141 va_end (args);
142
143 return ret;
144 }
virtual int vioctl(int request, std::va_list args)
Definition device.cpp:152

References os::posix::device::vioctl().

◆ is_opened()

bool os::posix::io::is_opened ( void  )
inlineinherited

Definition at line 458 of file io.h.

459 {
460 return impl ().do_is_opened ();
461 }
virtual bool do_is_opened(void)=0

References os::posix::io_impl::do_is_opened(), and os::posix::io::impl().

◆ isatty()

int os::posix::io::isatty ( void  )
inherited

Definition at line 406 of file io.cpp.

407 {
408 errno = 0;
409
410 // Execute the implementation specific code.
411 return impl ().do_isatty ();
412 }
virtual int do_isatty(void)
Definition io.cpp:532

References os::posix::io_impl::do_isatty(), and os::posix::io::impl().

◆ lseek()

off_t os::posix::io::lseek ( off_t  offset,
int  whence 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 447 of file io.cpp.

448 {
449#if defined(OS_TRACE_POSIX_IO_IO)
450 trace::printf ("io::%s(%d, %d) @%p\n", __func__, offset, whence, this);
451#endif
452
453 if (!impl ().do_is_opened ())
454 {
455 errno = EBADF; // Not opened.
456 return -1;
457 }
458
459 errno = 0;
460
461 // Execute the implementation specific code.
462 return impl ().do_lseek (offset, whence);
463 }
virtual off_t do_lseek(off_t offset, int whence)=0

References os::posix::io_impl::do_lseek(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::lseek(), and os::posix::file_lockable< T, L >::lseek().

◆ match_name()

bool os::posix::device::match_name ( const char *  name) const
virtualinherited

Definition at line 189 of file device.cpp.

190 {
191 assert (name != nullptr);
192 assert (name_ != nullptr);
193
194 return (std::strcmp (name, name_) == 0);
195 }

References os::posix::device::name().

◆ name()

const char * os::posix::device::name ( void  ) const
inlineinherited

Definition at line 304 of file device.h.

305 {
306 return name_;
307 }

Referenced by os::posix::device_registry< T >::link(), and os::posix::device::match_name().

◆ open()

int os::posix::device::open ( const char *  path = nullptr,
int  oflag = 0,
  ... 
)
inherited
Parameters
pathMay be nullptr.
oflagOutput flags
Returns
non-negative file descriptor, -1 on failure

Definition at line 62 of file device.cpp.

63 {
64 // Forward to the variadic version of the function.
65 std::va_list args;
66 va_start (args, oflag);
67 int ret = vopen (path, oflag, args);
68 va_end (args);
69
70 return ret;
71 }
int vopen(const char *path, int oflag, std::va_list args)
Definition device.cpp:74

References os::posix::device::vopen().

◆ read()

ssize_t os::posix::io::read ( void *  buf,
std::size_t  nbyte 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 217 of file io.cpp.

218 {
219#if defined(OS_TRACE_POSIX_IO_IO)
220 trace::printf ("io::%s(0x0%X, %u) @%p\n", __func__, buf, nbyte, this);
221#endif
222
223 if (buf == nullptr)
224 {
225 errno = EFAULT;
226 return -1;
227 }
228
229 if (!impl ().do_is_opened ())
230 {
231 errno = EBADF; // Not opened.
232 return -1;
233 }
234
235 if (!impl ().do_is_connected ())
236 {
237 errno = EIO; // Not opened.
238 return -1;
239 }
240
241 errno = 0;
242
243 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
244 // Before any action described below is taken, and if nbyte is zero,
245 // the read() function may detect and return errors as described below.
246 // In the absence of errors, or if error detection is not performed,
247 // the read() function shall return zero and have no other results.
248 if (nbyte == 0)
249 {
250 return 0; // Nothing to do.
251 }
252
253 // Execute the implementation specific code.
254 ssize_t ret = impl ().do_read (buf, nbyte);
255 if (ret >= 0)
256 {
257 impl ().offset_ += ret;
258 }
259
260#if defined(OS_TRACE_POSIX_IO_IO)
261 trace::printf ("io::%s(0x0%X, %u) @%p n=%d\n", __func__, buf, nbyte,
262 this, ret);
263#endif
264 return ret;
265 }
virtual ssize_t do_read(void *buf, std::size_t nbyte)=0

References os::posix::io_impl::do_read(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::read(), and os::posix::file_lockable< T, L >::read().

◆ read_block()

ssize_t os::posix::block_device::read_block ( void *  buf,
blknum_t  blknum,
std::size_t  nblocks = 1 
)
virtualinherited

Reimplemented in os::posix::block_device_partition_lockable< T, L >, and os::posix::block_device_lockable< T, L >.

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

65 {
66#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
67 trace::printf ("block_device::%s(%p, %u, %u) @%p\n", __func__, buf,
68 blknum, nblocks, this);
69#endif
70
71 if (blknum + nblocks > impl ().num_blocks_)
72 {
73 errno = EINVAL;
74 return -1;
75 }
76
77 if (!impl ().do_is_opened ())
78 {
79 errno = EBADF; // Not opened.
80 return -1;
81 }
82
83 return impl ().do_read_block (buf, blknum, nblocks);
84 }
virtual ssize_t do_read_block(void *buf, blknum_t blknum, std::size_t nblocks)=0

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

Referenced by os::posix::block_device_partition_lockable< T, L >::read_block(), and os::posix::block_device_lockable< T, L >::read_block().

◆ sync()

void os::posix::device::sync ( void  )
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >.

Definition at line 171 of file device.cpp.

172 {
173#if defined(OS_TRACE_POSIX_IO_DEVICE)
174 trace::printf ("device::%s() @%p\n", __func__, this);
175#endif
176
177 if (impl ().open_count_ == 0)
178 {
179 errno = EBADF; // Not opened.
180 return;
181 }
182
183 impl ().do_sync ();
184 }
virtual void do_sync(void)=0

References os::posix::device_impl::do_sync(), os::posix::device::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::sync().

◆ vfcntl()

int os::posix::io::vfcntl ( int  cmd,
std::va_list  args 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 380 of file io.cpp.

381 {
382#if defined(OS_TRACE_POSIX_IO_IO)
383 trace::printf ("io::%s(%d) @%p\n", __func__, cmd, this);
384#endif
385
386 if (!impl ().do_is_opened ())
387 {
388 errno = EBADF; // Not opened.
389 return -1;
390 }
391
392 if (!impl ().do_is_connected ())
393 {
394 errno = EIO; // Not opened.
395 return -1;
396 }
397
398 errno = 0;
399
400 // Execute the implementation specific code.
401 return impl ().do_vfcntl (cmd, args);
402 }
virtual int do_vfcntl(int cmd, std::va_list args)
Definition io.cpp:525

References os::posix::io_impl::do_vfcntl(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::io::fcntl(), os::posix::block_device_lockable< T, L >::vfcntl(), and os::posix::file_lockable< T, L >::vfcntl().

◆ vioctl()

int os::posix::block_device::vioctl ( int  request,
std::va_list  args 
)
overridevirtualinherited

Reimplemented from os::posix::device.

Reimplemented in os::posix::block_device_partition_lockable< T, L >, and os::posix::block_device_lockable< T, L >.

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

112 {
113#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
114 trace::printf ("block_device::%s(%d) @%p\n", __func__, request, this);
115#endif
116
117 if (!impl ().do_is_opened ())
118 {
119 errno = EBADF; // Not opened.
120 return -1;
121 }
122
123 errno = 0;
124
125 switch (static_cast<unsigned int> (request))
126 {
127 case BLKSSZGET:
128 // Get logical device sector size (to be used for read/writes).
129 {
130 std::size_t* sz = va_arg (args, std::size_t*);
131 if (sz == nullptr || impl ().block_logical_size_bytes_ != 0)
132 {
133 errno = EINVAL;
134 return -1;
135 }
136
137 *sz = impl ().block_logical_size_bytes_;
138 return 0;
139 }
140
141 case BLKPBSZGET:
142 // Get physical device sector size (internally used for erase).
143 {
144 std::size_t* sz = va_arg (args, std::size_t*);
145 if (sz == nullptr || impl ().block_physical_size_bytes_ != 0)
146 {
147 errno = EINVAL;
148 return -1;
149 }
150
151 *sz = impl ().block_physical_size_bytes_;
152 return 0;
153 }
154
155 case BLKGETSIZE64:
156 // Get device size in bytes.
157 {
158 uint64_t* sz = va_arg (args, uint64_t*);
159 if (sz == nullptr || impl ().num_blocks_ != 0)
160 {
161 errno = EINVAL;
162 return -1;
163 }
164
165#pragma GCC diagnostic push
166#if defined(__clang__)
167#elif defined(__GNUC__)
168#pragma GCC diagnostic ignored "-Wuseless-cast"
169#endif
170 *sz = (static_cast<uint64_t> (
171 impl ().num_blocks_ * impl ().block_logical_size_bytes_));
172#pragma GCC diagnostic pop
173
174 return 0;
175 }
176
177 default:
178
179 // Execute the implementation specific code.
180 return impl ().do_vioctl (request, args);
181 }
182 }
virtual int do_vioctl(int request, std::va_list args)=0
#define BLKPBSZGET
Definition ioctl.h:103
#define BLKGETSIZE64
Definition ioctl.h:101
#define BLKSSZGET
Definition ioctl.h:100

References BLKGETSIZE64, BLKPBSZGET, BLKSSZGET, os::posix::device_impl::do_vioctl(), os::posix::block_device::impl(), and os::trace::printf().

Referenced by os::posix::block_device_partition_lockable< T, L >::vioctl(), and os::posix::block_device_lockable< T, L >::vioctl().

◆ vopen()

int os::posix::device::vopen ( const char *  path,
int  oflag,
std::va_list  args 
)
inherited
Parameters
pathMay be nullptr.
oflagOutput flags
argsArguments
Returns
non-negative file descriptor, -1 on failure

Definition at line 74 of file device.cpp.

75 {
76#if defined(OS_TRACE_POSIX_IO_DEVICE)
77 trace::printf ("device::%s(\"%s\") @%p\n", __func__, path ? path : "",
78 this);
79#endif
80
81 errno = 0;
82
83 int ret = 0;
84 if (impl ().open_count_ == 0)
85 {
86 // If so, use the implementation to open the device.
87 ret = impl ().do_vopen (path, oflag, args);
88 if (ret < 0)
89 {
90 // Open failed.
91 return -1;
92 }
93
94 auto iop = alloc_file_descriptor ();
95 if (iop == nullptr)
96 {
97 return -1;
98 }
99 }
100 ++(impl ().open_count_);
101 ret = file_descriptor ();
102#if defined(OS_TRACE_POSIX_IO_DEVICE)
103 trace::printf ("device::%s(\"%s\")=%p fd=%d\n", __func__,
104 path ? path : "", this, ret);
105#endif
106
107 return ret;
108 }
virtual int do_vopen(const char *path, int oflag, std::va_list args)=0
file_descriptor_t file_descriptor(void) const
Definition io.h:452
io * alloc_file_descriptor(void)
Definition io.cpp:189

References os::posix::io::alloc_file_descriptor(), os::posix::device_impl::do_vopen(), os::posix::io::file_descriptor(), os::posix::device::impl(), and os::trace::printf().

Referenced by os::posix::device::open().

◆ write()

ssize_t os::posix::io::write ( const void *  buf,
std::size_t  nbyte 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 268 of file io.cpp.

269 {
270#if defined(OS_TRACE_POSIX_IO_IO)
271 trace::printf ("io::%s(0x0%X, %u) @%p\n", __func__, buf, nbyte, this);
272#endif
273
274 if (buf == nullptr)
275 {
276 errno = EFAULT;
277 return -1;
278 }
279
280 if (!impl ().do_is_opened ())
281 {
282 errno = EBADF; // Not opened.
283 return -1;
284 }
285
286 if (!impl ().do_is_connected ())
287 {
288 errno = EIO; // Not opened.
289 return -1;
290 }
291
292 errno = 0;
293
294 // http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html
295 // Before any action described below is taken, and if nbyte is zero
296 // and the file is a regular file, the write() function may detect and
297 // return errors as described below. In the absence of errors, or if
298 // error detection is not performed, the write() function shall return
299 // zero and have no other results. If nbyte is zero and the file is
300 // not a regular file, the results are unspecified.
301 if (nbyte == 0)
302 {
303 return 0; // Nothing to do.
304 }
305
306 // Execute the implementation specific code.
307 ssize_t ret = impl ().do_write (buf, nbyte);
308 if (ret >= 0)
309 {
310 impl ().offset_ += ret;
311 }
312
313#if defined(OS_TRACE_POSIX_IO_IO)
314 trace::printf ("io::%s(0x0%X, %u) @%p n=%d\n", __func__, buf, nbyte,
315 this, ret);
316#endif
317 return ret;
318 }
virtual ssize_t do_write(const void *buf, std::size_t nbyte)=0

References os::posix::io_impl::do_write(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::write(), and os::posix::file_lockable< T, L >::write().

◆ write_block()

ssize_t os::posix::block_device::write_block ( const void *  buf,
blknum_t  blknum,
std::size_t  nblocks = 1 
)
virtualinherited

Reimplemented in os::posix::block_device_partition_lockable< T, L >, and os::posix::block_device_lockable< T, L >.

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

89 {
90#if defined(OS_TRACE_POSIX_IO_BLOCK_DEVICE)
91 trace::printf ("block_device::%s(%p, %u, %u) @%p\n", __func__, buf,
92 blknum, nblocks, this);
93#endif
94
95 if (blknum + nblocks > impl ().num_blocks_)
96 {
97 errno = EINVAL;
98 return -1;
99 }
100
101 if (!impl ().do_is_opened ())
102 {
103 errno = EBADF; // Not opened.
104 return -1;
105 }
106
107 return impl ().do_write_block (buf, blknum, nblocks);
108 }
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(), os::posix::block_device::impl(), and os::trace::printf().

Referenced by os::posix::block_device_partition_lockable< T, L >::write_block(), and os::posix::block_device_lockable< T, L >::write_block().

◆ writev()

ssize_t os::posix::io::writev ( const iovec iov,
int  iovcnt 
)
virtualinherited

Reimplemented in os::posix::block_device_lockable< T, L >, and os::posix::file_lockable< T, L >.

Definition at line 321 of file io.cpp.

322 {
323#if defined(OS_TRACE_POSIX_IO_IO)
324 trace::printf ("io::%s(0x0%X, %d) @%p\n", __func__, iov, iovcnt, this);
325#endif
326
327 if (iov == nullptr)
328 {
329 errno = EFAULT;
330 return -1;
331 }
332
333 if (iovcnt <= 0)
334 {
335 errno = EINVAL;
336 return -1;
337 }
338
339 if (!impl ().do_is_opened ())
340 {
341 errno = EBADF; // Not opened.
342 return -1;
343 }
344
345 if (!impl ().do_is_connected ())
346 {
347 errno = EIO; // Not opened.
348 return -1;
349 }
350
351 errno = 0;
352
353 // Execute the implementation specific code.
354 ssize_t ret = impl ().do_writev (iov, iovcnt);
355 if (ret >= 0)
356 {
357 impl ().offset_ += ret;
358 }
359 return ret;
360 }
virtual ssize_t do_writev(const iovec *iov, int iovcnt)
Definition io.cpp:502

References os::posix::io_impl::do_writev(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::block_device_lockable< T, L >::writev(), and os::posix::file_lockable< T, L >::writev().


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