2009-11-21 01:45:08 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
2009-11-22 21:56:32 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2009-11-26 19:30:12 +00:00
|
|
|
#include "Entry.h"
|
2009-11-22 21:56:32 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "Endian.h"
|
2009-12-06 02:44:01 +00:00
|
|
|
#include "BlockDevice.h"
|
2009-11-21 01:45:08 +00:00
|
|
|
#include "Exception.h"
|
|
|
|
|
2009-11-22 21:56:32 +00:00
|
|
|
|
2009-11-21 01:45:08 +00:00
|
|
|
using namespace ProFUSE;
|
2009-11-22 21:56:32 +00:00
|
|
|
using namespace LittleEndian;
|
2009-11-21 01:45:08 +00:00
|
|
|
|
2009-11-22 21:56:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
Directory::Directory(unsigned type, const char *name) :
|
|
|
|
Entry(type, name)
|
|
|
|
{
|
|
|
|
#undef __METHOD__
|
|
|
|
#define __METHOD__ "Directory::Directory"
|
|
|
|
|
|
|
|
|
|
|
|
_access = 0xe3;
|
2009-11-21 01:45:08 +00:00
|
|
|
_entryLength = 0x27;
|
|
|
|
_entriesPerBlock = 13;
|
|
|
|
_fileCount = 0;
|
2009-11-22 21:56:32 +00:00
|
|
|
_version = 5; // ProDOS FST uses 5, ProDOS uses 0.
|
|
|
|
_minVersion = 0;
|
2009-11-21 01:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Directory::Directory(const void *bp) :
|
2009-11-22 21:56:32 +00:00
|
|
|
Entry(4 + (const uint8_t *)bp),
|
2009-11-21 01:45:08 +00:00
|
|
|
_creation(0, 0)
|
|
|
|
{
|
|
|
|
#undef __METHOD__
|
|
|
|
#define __METHOD__ "Directory::Directory"
|
|
|
|
|
2009-11-22 21:56:32 +00:00
|
|
|
// input is a block pointer. To simplify,
|
|
|
|
// create a new pointer past the 4-byte linked list part.
|
2009-11-26 19:30:12 +00:00
|
|
|
const void *dp = 4 + (const uint8_t *)bp;
|
2009-11-21 01:45:08 +00:00
|
|
|
|
2009-11-22 21:56:32 +00:00
|
|
|
_creation = DateTime(Read16(dp, 0x18), Read16(dp, 0x1a));
|
2009-11-21 01:45:08 +00:00
|
|
|
|
2009-11-22 21:56:32 +00:00
|
|
|
_version = Read8(dp, 0x1c);
|
|
|
|
_minVersion = Read8(dp, 0x1d);
|
2009-11-21 01:45:08 +00:00
|
|
|
|
2009-11-22 21:56:32 +00:00
|
|
|
_access = Read8(dp, 0x1e);
|
|
|
|
_entryLength = Read8(dp, 0x1f);
|
|
|
|
_entriesPerBlock = Read8(dp, 0x20);
|
2009-11-21 01:45:08 +00:00
|
|
|
|
2009-11-26 19:30:12 +00:00
|
|
|
_fileCount = Read16(dp, 0x21);
|
2009-11-22 21:56:32 +00:00
|
|
|
|
|
|
|
// parse child file entries ... requires ability to read other blocks.
|
2009-11-21 01:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Directory::~Directory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-11-26 19:30:12 +00:00
|
|
|
void Directory::setAccess(unsigned access)
|
2009-11-21 01:45:08 +00:00
|
|
|
{
|
|
|
|
#undef __METHOD__
|
|
|
|
#define __METHOD__ "Directory::setAccess"
|
|
|
|
|
2009-11-26 19:30:12 +00:00
|
|
|
|
2009-11-21 01:45:08 +00:00
|
|
|
_access = access;
|
|
|
|
|
|
|
|
// todo -- mark dirty? update block?
|
|
|
|
}
|
|
|
|
|
2009-12-06 02:44:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Directory::loadChildren(BlockDevice *device, unsigned block)
|
|
|
|
{
|
|
|
|
uint8_t buffer[512];
|
|
|
|
unsigned next;
|
|
|
|
bool first = true;
|
|
|
|
unsigned offset;
|
|
|
|
|
|
|
|
// set of already-visited blocks?
|
|
|
|
|
|
|
|
while(block)
|
|
|
|
{
|
|
|
|
device->read(block, buffer);
|
|
|
|
|
|
|
|
next = Read16(buffer, 2);
|
|
|
|
|
|
|
|
_entryBlocks.push_back(block);
|
|
|
|
|
|
|
|
offset = 4;
|
|
|
|
if (!first)
|
|
|
|
{
|
|
|
|
// storage type 0 is deleted, don't load...
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
first = false;
|
|
|
|
block = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|