53 static const unsigned int MAX_FILENAME_LENGTH = 32;
67 virtual PropWare::ErrorCode
open () = 0;
74 virtual PropWare::ErrorCode
close () {
75 const PropWare::ErrorCode err = this->
flush();
86 virtual PropWare::ErrorCode
flush () = 0;
92 return this->m_length;
112 PropWare::ErrorCode
seek (
const int32_t offset,
const SeekDir way) {
116 if (offset > this->m_length || 0 > offset)
119 this->m_ptr = offset;
123 absolute = offset + this->m_ptr;
124 if (0 > offset || offset > this->m_length)
127 this->m_ptr = (uint32_t) absolute;
131 absolute = this->m_length - offset;
132 if (0 > offset || offset > this->m_length)
135 this->m_ptr = (uint32_t) absolute;
147 PropWare::ErrorCode
seek (
const int32_t position) {
148 return this->
seek(position, SeekDir::BEG);
158 m_driver(fs.get_driver()),
159 m_fsBufMeta(&fs.m_dirMeta),
165 this->m_buf = &fs.m_buf;
167 this->m_buf = buffer;
169 this->m_contentMeta.
name = name;
178 void print_status (
const char classStr[] =
"File",
const bool printBlocks =
false)
const {
179 this->m_logger->
printf(
"File Status - PropWare::%s@0x%08X\n", classStr, (
unsigned int)
this);
180 this->m_logger->
println(
"=========================================");
181 this->m_logger->
println(
"Common");
182 this->m_logger->
println(
"------");
183 this->m_logger->
printf(
"\tFile name: %s\n", this->m_name);
184 this->m_logger->
printf(
"\tLogger: 0x%08X\n", (
unsigned int) this->m_logger);
185 this->m_logger->printf(
"\tDriver: 0x%08X\n", (
unsigned int) this->m_driver);
186 this->m_logger->printf(
"\tBuffer: 0x%08X\n", (
unsigned int) this->m_buf);
187 this->m_logger->printf(
"\tLength: 0x%08X/%d\n", this->m_length, this->m_length);
189 if (NULL != this->m_buf) {
190 this->m_logger->println(
"Buffer");
191 this->m_logger->println(
"------");
192 this->m_logger->printf(
"\tData address: 0x%08X\n", (
unsigned int) this->m_buf->buf);
193 this->m_logger->printf(
"\tMeta address: 0x%08X\n", (
unsigned int) this->m_buf->meta);
194 if (NULL != this->m_buf->buf && NULL != this->m_buf->meta) {
195 this->m_logger->printf(
"\tID: %d\n", this->m_buf->meta->id);
196 this->m_logger->printf(
"\tModdified: %s\n",
Utility::to_string(this->m_buf->meta->mod));
197 this->m_logger->printf(
"\tCur. cluster's start sector: 0x%08X/%u\n",
198 this->m_buf->meta->curTier2Addr,
199 this->m_buf->meta->curTier2Addr);
200 this->m_logger->printf(
"\tCur. sector offset from cluster start: %u\n",
201 this->m_buf->meta->curTier1Offset);
202 this->m_logger->printf(
"\tCurrent allocation unit: 0x%08X/%u\n", this->m_buf->meta->curTier2,
203 this->m_buf->meta->curTier2);
204 this->m_logger->printf(
"\tNext allocation unit: 0x%08X/%u\n", this->m_buf->meta->nextTier2,
205 this->m_buf->meta->nextTier2);
214 char m_name[MAX_FILENAME_LENGTH];
228 PropWare::ErrorCode m_error;
PropWare::ErrorCode seek(const int32_t position)
virtual PropWare::ErrorCode flush()=0
Flush any modified data back to the SD card.
static void print_block(const Printer &printer, const Buffer &buffer, const size_t words=512, const uint8_t wordsPerLine=16)
Print the formatted contents of a buffer.
Interface for all filesystems, such as FAT 16/32.
virtual PropWare::ErrorCode open()=0
Open the file.
Generic definitions and functions for the Parallax Propeller.
int32_t get_length() const
Return the number of bytes (characters) in the file.
const PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
void printf(const char fmt[], const T first, const Targs...remaining) const
Similar in functionality to the C-standard function printf.
static const char * to_string(const bool b)
Convert a boolean to the string-literal either "true" or "false"
Container class that has formatting methods for human-readable output. This class can be constructed ...
virtual PropWare::ErrorCode close()
Close a file - a required step in any workflow that includes opening a file.
Any device that uses blocks as hardware level abstraction.
Basic file interface for opening and closing files.
PropWare::ErrorCode seek(const int32_t offset, const SeekDir way)
Sets the position of the next character to be read or written.
int32_t tell() const
Obtain the value of the file position indicator.
In-memory buffer containing a single block of data.
void println(const char string[]) const
Print a null-terminated string followed by a newline (' ')