36 if (res < 0)
return (res);
46 if (res < 0)
return (res);
48 if (res < 0)
return (res);
95 if (
device->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
124 return (
write(buf, size,
false));
130 return (
write(buf, size,
true));
149 if (size > remains) size = remains;
155 if (res < 0)
return (
EIO);
157 m_current_pos += res;
164 if (
device->
read(&header, addr,
sizeof(header)) !=
sizeof(header))
194 if (res < 0)
return (res);
204 if (sector == 0L)
return (
ENOSPC);
209 if (
device->
read(&header, addr,
sizeof(header)) !=
sizeof(header))
217 if (
device->
write(addr, &header,
sizeof(header)) !=
sizeof(header))
236 if ((flash->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
239 addr +=
sizeof(entry);
240 if ((flash->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
242 || (entry.
ref != addr)
262 if (
device->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
264 const uint16_t ENTRY_MAX = entry.
size /
sizeof(entry);
267 for (uint16_t i = 0; i < ENTRY_MAX; i++, addr +=
sizeof(entry)) {
268 if (
device->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
275 if ((j & 0x7) == 0) outs <<
endl;
278 if (j & 0x7) outs <<
endl;
289 return (res < 0 ? res : file.
remove());
334 for (uint16_t i = 0; i < flash->
SECTOR_MAX; i++) {
335 if (flash->
read(&header, addr,
sizeof(header)) !=
sizeof(header))
338 if (flash->
erase(addr, SIZE) != 0)
return (
EIO);
345 memset(&header, 0,
sizeof(header));
347 header.
size =
sizeof(header);
348 header.
ref =
sizeof(header);
349 strcpy(header.
name, name);
350 if (flash->
write(addr, &header,
sizeof(header)) !=
sizeof(header))
354 addr +=
sizeof(header);
355 memset(&header, 0,
sizeof(header));
360 if (flash->
write(addr, &header,
sizeof(header)) !=
sizeof(header))
373 if (
device->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
375 const uint16_t ENTRY_MAX = entry.
size /
sizeof(
descr_t);
377 for (uint16_t i = 0; i < ENTRY_MAX; i++, addr +=
sizeof(
descr_t)) {
378 if (
device->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
382 if (strcmp(filename, entry.
name))
continue;
392 descr_t &entry, uint32_t &addr)
403 if (
device->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
406 for (uint16_t i = 0; i < ENTRY_MAX; i++, addr +=
sizeof(
descr_t)) {
407 if (
device->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
412 if (!strcmp(filename, entry.
name)) {
414 int res =
remove(addr, entry.
type);
415 if (res < 0)
return (res);
421 if (dir == 0L)
return (
ENOSPC);
426 if (sector == 0L)
return (
ENOSPC);
429 strcpy(entry.
name, filename);
431 entry.
size =
sizeof(entry);
433 if (
device->
write(addr, &entry,
sizeof(entry)) !=
sizeof(entry))
451 if (
device->
read(&entry, addr,
sizeof(entry)) !=
sizeof(entry))
453 if ((entry.
type != type))
457 uint32_t ref = entry.
ref;
460 memset(&entry, 0,
sizeof(entry));
461 if (
device->
write(addr, &entry,
sizeof(entry)) !=
sizeof(entry))
466 if (
device->
read(&entry, ref,
sizeof(entry)) !=
sizeof(entry))
479 if (size > avail) size = avail;
488 if (size > avail) size = avail;
497 if (size > avail) size = avail;
511 if (
device->
read(&header, addr,
sizeof(header)) !=
sizeof(header))
521 memset(header.
name, 0,
sizeof(header.
name));
522 if (
device->
write(addr, &header,
sizeof(header)) !=
sizeof(header))
542 if (
device->
read(&header, addr,
sizeof(header)) !=
sizeof(header))
550 if (
device->
read(&header, addr,
sizeof(header)) !=
sizeof(header))
558 memset(&header, 0,
sizeof(header));
563 if (
device->
write(addr, &header,
sizeof(header)) !=
sizeof(header))
579 if (
device->
read(&header, addr,
sizeof(header)) !=
sizeof(header))
585 size += (header.
size -
sizeof(header));
592 for (uint16_t i = 0; i < BUF_MAX; i++) {
594 if (
device->
read(buf, addr,
sizeof(buf)) !=
sizeof(buf))
596 uint16_t j =
sizeof(buf) - 1;
597 while (buf[j] == 0xff)
if (j == 0)
break;
else j--;
598 if (j == 0)
continue;
static int write(uint32_t dest, const void *src, size_t size)
uint16_t type
Type of file and entry state.
virtual int write(uint32_t dest, const void *src, size_t size)=0
static const size_t FILENAME_MAX
static int find_end_of_file(uint32_t sector, uint32_t &pos, uint32_t &size)
static uint32_t current_dir_addr
Directory reference entry.
CFFS::descr_t m_entry
Cached directory entry.
File System Master header.
uint32_t m_entry_addr
Entry address.
virtual int read(void *dest, uint32_t src, size_t size)=0
IOStream & tab(IOStream &outs)
static int rm(const char *filename)
static int cd(const char *filename)
static Flash::Device * device
static int mkdir(const char *filename)
static const size_t DIR_MAX
virtual int erase(uint32_t dest, uint8_t size)=0
uint8_t m_flags
File open flags.
const uint16_t SECTOR_MAX
static int lookup(const char *filename, descr_t &entry, uint32_t &addr)
static int create(const char *filename, uint16_t type, uint8_t flags, descr_t &entry, uint32_t &addr)
const uint32_t SECTOR_BYTES
char name[FILENAME_MAX]
Printable name of object(zero terminated).
static uint32_t next_free_sector()
static const uint32_t NULL_REF
char * strcpy_P(char *s1, str_P s2)
virtual int read(void *buf, size_t size)
IOStream & endl(IOStream &outs)
Open for reading and writing.
uint32_t m_file_size
File size.
static const uint32_t DEFAULT_SECTOR_BYTES
static bool begin(Flash::Device *flash)
uint32_t ref
Reference value (pointer).
static int ls(IOStream &outs)
uint32_t m_current_addr
Current flash address.
static int write_P(uint32_t dest, const void *src, size_t size)
static int format(Flash::Device *flash, const char *name)
virtual int write_P(uint32_t dest, const void *scr, size_t size)=0
static int read(void *dest, uint32_t src, size_t size)
Create the file if nonexistent.
static uint32_t next_free_directory()
virtual int write_P(const void *buf, size_t size)
uint32_t m_current_pos
Current logical position.
int open(const char *filename, uint8_t oflag=O_READ)
virtual int write(const void *buf, size_t size)
int seek(uint32_t pos, uint8_t whence=SEEK_SET)
static int rmdir(const char *filename)
int strcmp_P(const char *s1, str_P s2)
uint32_t size
Number of bytes (including header).
const uint32_t SECTOR_MASK
static int remove(uint32_t addr, uint16_t type)