Use types with explicit sizes

Focusing on the diskimg library this time, which deals with a lot of
filesystem structures that have specific widths.

This is still a bit lax in places, e.g. using "long" for lengths.
Should either specify a bit width or use di_off_t.

Also, added "override" keyword where appropriate.

Also, bumped library version to 5.0.0.
This commit is contained in:
Andy McFadden 2014-11-24 12:56:19 -08:00
parent edb7c13120
commit aa3145856c
42 changed files with 2254 additions and 2959 deletions

View File

@ -93,8 +93,6 @@
<PostBuildEvent>
<Message>
</Message>
<Command>copy Help\CiderPress.hlp Release\
copy Help\CiderPress.cnt Release\</Command>
</PostBuildEvent>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -137,13 +135,7 @@ copy Help\CiderPress.cnt Release\</Command>
<TypeLibraryName>.\Debug/app.tlb</TypeLibraryName>
<HeaderFileName />
</Midl>
<PostBuildEvent>
<Message>Copying help</Message>
<Command>copy Help\CiderPress.hlp Debug\
copy Help\CiderPress.cnt Debug\
</Command>
</PostBuildEvent>
<PostBuildEvent />
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>

View File

@ -25,8 +25,7 @@
/*
* Initialize ASPI.
*/
DIError
ASPI::Init(void)
DIError ASPI::Init(void)
{
DWORD aspiStatus;
static const char* kASPIDllName = "wnaspi32.dll";
@ -104,8 +103,7 @@ ASPI::~ASPI(void)
*
* Pass in a pointer to a struct that receives the result.
*/
DIError
ASPI::HostAdapterInquiry(unsigned char adapter, AdapterInfo* pAdapterInfo)
DIError ASPI::HostAdapterInquiry(unsigned char adapter, AdapterInfo* pAdapterInfo)
{
SRB_HAInquiry req;
DWORD result;
@ -140,8 +138,7 @@ ASPI::HostAdapterInquiry(unsigned char adapter, AdapterInfo* pAdapterInfo)
/*
* Issue an ASPI query on device type.
*/
DIError
ASPI::GetDeviceType(unsigned char adapter, unsigned char target,
DIError ASPI::GetDeviceType(unsigned char adapter, unsigned char target,
unsigned char lun, unsigned char* pType)
{
SRB_GDEVBlock req;
@ -170,8 +167,7 @@ ASPI::GetDeviceType(unsigned char adapter, unsigned char target,
/*
* Return a printable string for the given device type.
*/
const char*
ASPI::DeviceTypeToString(unsigned char deviceType)
const char* ASPI::DeviceTypeToString(unsigned char deviceType)
{
switch (deviceType) {
case kScsiDevTypeDASD: return "Disk device";
@ -192,8 +188,7 @@ ASPI::DeviceTypeToString(unsigned char deviceType)
/*
* Issue a SCSI device inquiry and return the interesting parts.
*/
DIError
ASPI::DeviceInquiry(unsigned char adapter, unsigned char target,
DIError ASPI::DeviceInquiry(unsigned char adapter, unsigned char target,
unsigned char lun, Inquiry* pInquiry)
{
DIError dierr;
@ -245,8 +240,7 @@ ASPI::DeviceInquiry(unsigned char adapter, unsigned char target,
/*
* Get the capacity of a SCSI block device.
*/
DIError
ASPI::GetDeviceCapacity(unsigned char adapter, unsigned char target,
DIError ASPI::GetDeviceCapacity(unsigned char adapter, unsigned char target,
unsigned char lun, unsigned long* pLastBlock, unsigned long* pBlockSize)
{
DIError dierr;
@ -294,8 +288,7 @@ ASPI::GetDeviceCapacity(unsigned char adapter, unsigned char target,
*
* Returns "true" if the device is ready, "false" if not.
*/
DIError
ASPI::TestUnitReady(unsigned char adapter, unsigned char target,
DIError ASPI::TestUnitReady(unsigned char adapter, unsigned char target,
unsigned char lun, bool* pReady)
{
DIError dierr;
@ -355,8 +348,7 @@ ASPI::TestUnitReady(unsigned char adapter, unsigned char target,
* (possibly modified by extents, but we'll ignore that). For a CD-ROM
* this means 2048-byte blocks.
*/
DIError
ASPI::ReadBlocks(unsigned char adapter, unsigned char target,
DIError ASPI::ReadBlocks(unsigned char adapter, unsigned char target,
unsigned char lun, long startBlock, short numBlocks, long blockSize,
void* buf)
{
@ -397,8 +389,7 @@ ASPI::ReadBlocks(unsigned char adapter, unsigned char target,
/*
* Write one or more blocks to the device.
*/
DIError
ASPI::WriteBlocks(unsigned char adapter, unsigned char target,
DIError ASPI::WriteBlocks(unsigned char adapter, unsigned char target,
unsigned char lun, long startBlock, short numBlocks, long blockSize,
const void* buf)
{
@ -446,8 +437,7 @@ ASPI::WriteBlocks(unsigned char adapter, unsigned char target,
* The Nero ASPI layer typically returns immediately, and hands back an
* SS_ERR when something fails. Win98 ASPI does the SS_PENDING thang.
*/
DIError
ASPI::ExecSCSICommand(SRB_ExecSCSICmd* pSRB)
DIError ASPI::ExecSCSICommand(SRB_ExecSCSICmd* pSRB)
{
HANDLE completionEvent = NULL;
DWORD eventStatus;
@ -522,8 +512,7 @@ ASPI::ExecSCSICommand(SRB_ExecSCSICmd* pSRB)
*
* Only return the devices matching device types in "deviceMask".
*/
DIError
ASPI::GetAccessibleDevices(int deviceMask, ASPIDevice** ppDeviceArray,
DIError ASPI::GetAccessibleDevices(int deviceMask, ASPIDevice** ppDeviceArray,
int* pNumDevices)
{
DIError dierr;

View File

@ -50,9 +50,8 @@
* force the "disk format verification" dialog to come up. No such
* mechanism exists, and for now it doesn't seem worthwhile to add one.
*/
/*static*/ DIError
DiskFSCFFA::TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder,
DiskImg::FSFormat* pFormatFound)
/*static*/ DIError DiskFSCFFA::TestImage(DiskImg* pImg,
DiskImg::SectorOrder imageOrder, DiskImg::FSFormat* pFormatFound)
{
DIError dierr;
long totalBlocks = pImg->GetNumBlocks();
@ -359,9 +358,8 @@ bail:
* If "scanOnly" is set, the full DiskFS initialization isn't performed.
* We just do enough to get the volume size info.
*/
/*static*/ DIError
DiskFSCFFA::OpenSubVolume(DiskImg* pImg, long startBlock, long numBlocks,
bool scanOnly, DiskImg** ppNewImg, DiskFS** ppNewFS)
/*static*/ DIError DiskFSCFFA::OpenSubVolume(DiskImg* pImg, long startBlock,
long numBlocks, bool scanOnly, DiskImg** ppNewImg, DiskFS** ppNewFS)
{
DIError dierr = kDIErrNone;
DiskFS* pNewFS = NULL;
@ -439,8 +437,7 @@ bail:
/*
* Check to see if this is a CFFA volume.
*/
/*static*/ DIError
DiskFSCFFA::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSCFFA::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
if (pImg->GetNumBlocks() < kMinInterestingBlocks)
@ -467,8 +464,7 @@ DiskFSCFFA::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*
* Prep the CFFA "container" for use.
*/
DIError
DiskFSCFFA::Initialize(void)
DIError DiskFSCFFA::Initialize(void)
{
DIError dierr = kDIErrNone;
@ -494,8 +490,7 @@ DiskFSCFFA::Initialize(void)
* We don't handle the volume specially unless it's at least 32MB, which
* means there are at least 2 partitions.
*/
DIError
DiskFSCFFA::FindSubVolumes(void)
DIError DiskFSCFFA::FindSubVolumes(void)
{
DIError dierr;
long startBlock, blocksLeft;
@ -542,8 +537,7 @@ bail:
*
* Updates "startBlock" and "totalBlocksLeft".
*/
DIError
DiskFSCFFA::AddVolumeSeries(int start, int count, long blocksPerVolume,
DIError DiskFSCFFA::AddVolumeSeries(int start, int count, long blocksPerVolume,
long& startBlock, long& totalBlocksLeft)
{
DIError dierr = kDIErrNone;

View File

@ -41,12 +41,11 @@ const int kMaxExtent = 31; // extent counter, 0-31
*
* We test a few fields in the volume directory for validity.
*/
static DIError
TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
static DIError TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
{
DIError dierr = kDIErrNone;
unsigned char dirBuf[kBlkSize * kVolDirCount];
unsigned char* dptr;
uint8_t dirBuf[kBlkSize * kVolDirCount];
uint8_t* dptr;
int i;
assert(sizeof(dirBuf) == DiskFSCPM::kFullDirSize);
@ -79,7 +78,7 @@ TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
}
/* check for a valid filename here; high bit may be set on some bytes */
unsigned char firstLet = *(dptr+1) & 0x7f;
uint8_t firstLet = *(dptr+1) & 0x7f;
if (firstLet < 0x20) {
dierr = kDIErrFilesystemNotFound;
break;
@ -101,8 +100,7 @@ bail:
* On the Apple II, these were always on 5.25" disks. However, it's possible
* to create hard drive volumes up to 8MB.
*/
/*static*/ DIError
DiskFSCPM::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSCPM::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
/* CP/M disks use 1K blocks, so ignore anything with odd count */
@ -139,8 +137,7 @@ DiskFSCPM::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
* on out must be handled somehow, possibly by claiming that the disk is
* completely full and has no files on it.
*/
DIError
DiskFSCPM::Initialize(void)
DIError DiskFSCPM::Initialize(void)
{
DIError dierr = kDIErrNone;
@ -178,12 +175,11 @@ bail:
* A single file can have more than one directory entry. We only want
* to create an A2File object for the first one.
*/
DIError
DiskFSCPM::ReadCatalog(void)
DIError DiskFSCPM::ReadCatalog(void)
{
DIError dierr = kDIErrNone;
unsigned char dirBuf[kFullDirSize];
unsigned char* dptr;
uint8_t dirBuf[kFullDirSize];
uint8_t* dptr;
int i;
for (i = 0; i < kVolDirCount; i++) {
@ -262,8 +258,7 @@ bail:
/*
* Reformat from 11 chars with spaces into clean xxxxx.yyy format.
*/
void
DiskFSCPM::FormatName(char* dstBuf, const char* srcBuf)
void DiskFSCPM::FormatName(char* dstBuf, const char* srcBuf)
{
char workBuf[kDirFileNameLen+1];
char* cp;
@ -299,8 +294,7 @@ DiskFSCPM::FormatName(char* dstBuf, const char* srcBuf)
* (Should probably just get the block list and then walk that, rather than
* having directory parse code in two places.)
*/
DIError
DiskFSCPM::ComputeLength(A2FileCPM* pFile)
DIError DiskFSCPM::ComputeLength(A2FileCPM* pFile)
{
int i;
int best, maxExtent;
@ -342,8 +336,7 @@ DiskFSCPM::ComputeLength(A2FileCPM* pFile)
* Tracks 0, 1, and 2 are always used by the boot loader. The volume directory
* is on the first half of track 3 (blocks 0 and 1).
*/
DIError
DiskFSCPM::ScanFileUsage(void)
DIError DiskFSCPM::ScanFileUsage(void)
{
int cpmBlock;
int i, j;
@ -379,8 +372,7 @@ DiskFSCPM::ScanFileUsage(void)
* "block" is a 512-byte block, so you will have to call here twice for every
* 1K CP/M block.
*/
void
DiskFSCPM::SetBlockUsage(long block, VolumeUsage::ChunkPurpose purpose)
void DiskFSCPM::SetBlockUsage(long block, VolumeUsage::ChunkPurpose purpose)
{
VolumeUsage::ChunkState cstate;
@ -409,8 +401,7 @@ DiskFSCPM::SetBlockUsage(long block, VolumeUsage::ChunkPurpose purpose)
*
* Returns "true" if disk appears to be perfect, "false" otherwise.
*/
bool
DiskFSCPM::CheckDiskIsGood(void)
bool DiskFSCPM::CheckDiskIsGood(void)
{
//DIError dierr;
bool result = true;
@ -454,8 +445,7 @@ DiskFSCPM::CheckDiskIsGood(void)
* Calling GetBlockList twice is probably not the best way to go through life.
* This needs an overhaul.
*/
DIError
A2FileCPM::Open(A2FileDescr** ppOpenFile, bool readOnly,
DIError A2FileCPM::Open(A2FileDescr** ppOpenFile, bool readOnly,
bool rsrcFork /*=false*/)
{
DIError dierr;
@ -474,7 +464,7 @@ A2FileCPM::Open(A2FileDescr** ppOpenFile, bool readOnly,
if (dierr != kDIErrNone)
goto bail;
pOpenFile->fBlockList = new unsigned char[pOpenFile->fBlockCount+1];
pOpenFile->fBlockList = new uint8_t[pOpenFile->fBlockCount+1];
pOpenFile->fBlockList[pOpenFile->fBlockCount] = 0xff;
dierr = GetBlockList(&pOpenFile->fBlockCount, pOpenFile->fBlockList);
@ -503,8 +493,7 @@ bail:
* Call this once with "blockBuf" equal to "NULL" to get the block count,
* then call a second time after allocating blockBuf.
*/
DIError
A2FileCPM::GetBlockList(long* pBlockCount, unsigned char* blockBuf) const
DIError A2FileCPM::GetBlockList(long* pBlockCount, uint8_t* blockBuf) const
{
di_off_t length = fLength;
int blockCount = 0;
@ -565,8 +554,7 @@ A2FileCPM::GetBlockList(long* pBlockCount, unsigned char* blockBuf) const
/*
* Dump the contents of the A2File structure.
*/
void
A2FileCPM::Dump(void) const
void A2FileCPM::Dump(void) const
{
LOGI("A2FileCPM '%s' length=%ld", fFileName, (long) fLength);
}
@ -581,8 +569,7 @@ A2FileCPM::Dump(void) const
/*
* Read a chunk of data from the current offset.
*/
DIError
A2FDCPM::Read(void* buf, size_t len, size_t* pActual)
DIError A2FDCPM::Read(void* buf, size_t len, size_t* pActual)
{
LOGI(" CP/M reading %d bytes from '%s' (offset=%ld)",
len, fpFile->GetPathName(), (long) fOffset);
@ -602,7 +589,7 @@ A2FDCPM::Read(void* buf, size_t len, size_t* pActual)
DIError dierr = kDIErrNone;
const int kCPMBlockSize = kBlkSize*2;
assert(kCPMBlockSize == 1024);
unsigned char blkBuf[kCPMBlockSize];
uint8_t blkBuf[kCPMBlockSize];
int blkIndex = (int) (fOffset / kCPMBlockSize);
int bufOffset = (int) (fOffset % kCPMBlockSize); // (& 0x3ff)
size_t thisCount;
@ -669,8 +656,7 @@ A2FDCPM::Read(void* buf, size_t len, size_t* pActual)
/*
* Write data at the current offset.
*/
DIError
A2FDCPM::Write(const void* buf, size_t len, size_t* pActual)
DIError A2FDCPM::Write(const void* buf, size_t len, size_t* pActual)
{
return kDIErrNotSupported;
}
@ -678,8 +664,7 @@ A2FDCPM::Write(const void* buf, size_t len, size_t* pActual)
/*
* Seek to a new offset.
*/
DIError
A2FDCPM::Seek(di_off_t offset, DIWhence whence)
DIError A2FDCPM::Seek(di_off_t offset, DIWhence whence)
{
di_off_t fileLength = ((A2FileCPM*) fpFile)->fLength;
@ -714,8 +699,7 @@ A2FDCPM::Seek(di_off_t offset, DIWhence whence)
/*
* Return current offset.
*/
di_off_t
A2FDCPM::Tell(void)
di_off_t A2FDCPM::Tell(void)
{
return fOffset;
}
@ -723,8 +707,7 @@ A2FDCPM::Tell(void)
/*
* Release file state, such as it is.
*/
DIError
A2FDCPM::Close(void)
DIError A2FDCPM::Close(void)
{
fpFile->CloseDescr(this);
return kDIErrNone;
@ -733,13 +716,11 @@ A2FDCPM::Close(void)
/*
* Return the #of sectors/blocks in the file.
*/
long
A2FDCPM::GetSectorCount(void) const
long A2FDCPM::GetSectorCount(void) const
{
return fBlockCount * 4;
}
long
A2FDCPM::GetBlockCount(void) const
long A2FDCPM::GetBlockCount(void) const
{
return fBlockCount * 2;
}
@ -747,8 +728,7 @@ A2FDCPM::GetBlockCount(void) const
/*
* Return the Nth track/sector in this file.
*/
DIError
A2FDCPM::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
DIError A2FDCPM::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
{
long cpmIdx = sectorIdx / 4; // 4 256-byte sectors per 1K CP/M block
if (cpmIdx >= fBlockCount)
@ -766,8 +746,7 @@ A2FDCPM::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
* Return the Nth 512-byte block in this file. Since things aren't stored
* in 512-byte blocks, we grab the appropriate 1K block and pick half.
*/
DIError
A2FDCPM::GetStorage(long blockIdx, long* pBlock) const
DIError A2FDCPM::GetStorage(long blockIdx, long* pBlock) const
{
long cpmIdx = blockIdx / 2; // 4 256-byte sectors per 1K CP/M block
if (cpmIdx >= fBlockCount)

View File

@ -13,8 +13,7 @@
/*
* Blank out the volume usage map, setting all entries to "embedded".
*/
void
DiskFSContainer::SetVolumeUsageMap(void)
void DiskFSContainer::SetVolumeUsageMap(void)
{
VolumeUsage::ChunkState cstate;
long block;
@ -34,8 +33,7 @@ DiskFSContainer::SetVolumeUsageMap(void)
* Create a "placeholder" sub-volume. Useful for some of the tools when
* dealing with unformatted (or unknown-formatted) partitions.
*/
DIError
DiskFSContainer::CreatePlaceholder(long startBlock, long numBlocks,
DIError DiskFSContainer::CreatePlaceholder(long startBlock, long numBlocks,
const char* partName, const char* partType,
DiskImg** ppNewImg, DiskFS** ppNewFS)
{

View File

@ -103,18 +103,18 @@ public:
~BitBuffer(void) {}
void SetFile(GenericFD* pGFD) { fpGFD = pGFD; }
void PutBits(unsigned char bits, int numBits);
unsigned char GetBits(int numBits);
void PutBits(uint8_t bits, int numBits);
uint8_t GetBits(int numBits);
bool IOFailure(void) const { return fIOFailure; }
static unsigned char Reverse(unsigned char val);
static uint8_t Reverse(uint8_t val);
private:
GenericFD* fpGFD;
unsigned char fBits;
int fBitCount;
bool fIOFailure;
GenericFD* fpGFD;
uint8_t fBits;
int fBitCount;
bool fIOFailure;
};
/*
@ -124,8 +124,7 @@ private:
* reverse order in which they were passed in). As soon as we get 8 bits
* we flush.
*/
void
WrapperDDD::BitBuffer::PutBits(unsigned char bits, int numBits)
void WrapperDDD::BitBuffer::PutBits(uint8_t bits, int numBits)
{
assert(fBitCount >= 0 && fBitCount < 8);
assert(numBits > 0 && numBits <= 8);
@ -153,15 +152,14 @@ WrapperDDD::BitBuffer::PutBits(unsigned char bits, int numBits)
* These come out in the order in which they appear in the file, which
* means that in some cases they will have to be reversed.
*/
unsigned char
WrapperDDD::BitBuffer::GetBits(int numBits)
uint8_t WrapperDDD::BitBuffer::GetBits(int numBits)
{
assert(fBitCount >= 0 && fBitCount < 8);
assert(numBits > 0 && numBits <= 8);
assert(fpGFD != NULL);
DIError dierr;
unsigned char retVal;
uint8_t retVal;
if (fBitCount == 0) {
/* have no bits */
@ -199,11 +197,10 @@ WrapperDDD::BitBuffer::GetBits(int numBits)
/*
* Utility function to reverse the order of bits in a byte.
*/
/*static*/ unsigned char
WrapperDDD::BitBuffer::Reverse(unsigned char val)
/*static*/ uint8_t WrapperDDD::BitBuffer::Reverse(uint8_t val)
{
int i;
unsigned char result = 0; // init is to make valgrind happy
uint8_t result = 0; // init is to make valgrind happy
for (i = 0; i < 8; i++) {
result = (result << 1) + (val & 0x01);
@ -224,7 +221,7 @@ WrapperDDD::BitBuffer::Reverse(unsigned char val)
* These are all odd, which when they're written in reverse order means
* they all have their hi bits set.
*/
static const unsigned char kFavoriteBitEnc[kNumFavorites] = {
static const uint8_t kFavoriteBitEnc[kNumFavorites] = {
0x03, 0x09, 0x1f, 0x0f, 0x07, 0x1b, 0x0b, 0x0d, 0x15, 0x37,
0x3d, 0x25, 0x05, 0xb1, 0x11, 0x21, 0x01, 0x57, 0x5d, 0x1d
};
@ -240,8 +237,7 @@ static const int kFavoriteBitEncLen[kNumFavorites] = {
* Assumes pSrcGFD points to DOS-ordered sectors. (This is enforced when the
* disk image is first being created.)
*/
/*static*/ DIError
WrapperDDD::PackDisk(GenericFD* pSrcGFD, GenericFD* pWrapperGFD,
/*static*/ DIError WrapperDDD::PackDisk(GenericFD* pSrcGFD, GenericFD* pWrapperGFD,
short diskVolNum)
{
DIError dierr = kDIErrNone;
@ -256,13 +252,13 @@ WrapperDDD::PackDisk(GenericFD* pSrcGFD, GenericFD* pWrapperGFD,
bitBuffer.SetFile(pWrapperGFD);
bitBuffer.PutBits(0x00, 3);
bitBuffer.PutBits((unsigned char)diskVolNum, 8);
bitBuffer.PutBits((uint8_t)diskVolNum, 8);
/*
* Process all tracks.
*/
for (int track = 0; track < kNumTracks; track++) {
unsigned char trackBuf[kTrackLen];
uint8_t trackBuf[kTrackLen];
dierr = pSrcGFD->Read(trackBuf, kTrackLen);
if (dierr != kDIErrNone) {
@ -291,11 +287,10 @@ bail:
/*
* Compress a track full of data.
*/
/*static*/ void
WrapperDDD::PackTrack(const unsigned char* trackBuf, BitBuffer* pBitBuf)
/*static*/ void WrapperDDD::PackTrack(const uint8_t* trackBuf, BitBuffer* pBitBuf)
{
unsigned short freqCounts[kNumSymbols];
unsigned char favorites[kNumFavorites];
uint16_t freqCounts[kNumSymbols];
uint8_t favorites[kNumFavorites];
int i, fav;
ComputeFreqCounts(trackBuf, freqCounts);
@ -309,7 +304,7 @@ WrapperDDD::PackTrack(const unsigned char* trackBuf, BitBuffer* pBitBuf)
* Compress track data. Store runs as { 0x97 char count }, where
* a count of zero means 256.
*/
const unsigned char* ucp = trackBuf;
const uint8_t* ucp = trackBuf;
for (i = 0; i < kTrackLen; i++, ucp++) {
if (i < (kTrackLen-3) &&
*ucp == *(ucp+1) &&
@ -361,16 +356,15 @@ WrapperDDD::PackTrack(const unsigned char* trackBuf, BitBuffer* pBitBuf)
* bytes or longer are completely ignored.
*
* "trackBuf" holds kTrackLen bytes of data, and "freqCounts" holds
* kNumSymbols (256) unsigned shorts.
* kNumSymbols (256) 16-bit values.
*/
/*static*/ void
WrapperDDD::ComputeFreqCounts(const unsigned char* trackBuf,
unsigned short* freqCounts)
/*static*/ void WrapperDDD::ComputeFreqCounts(const uint8_t* trackBuf,
uint16_t* freqCounts)
{
const unsigned char* ucp;
const uint8_t* ucp;
int i;
memset(freqCounts, 0, 256 * sizeof(unsigned short));
memset(freqCounts, 0, 256 * sizeof(uint16_t));
ucp = trackBuf;
for (i = 0; i < kTrackLen; i++, ucp++) {
@ -407,19 +401,18 @@ WrapperDDD::ComputeFreqCounts(const unsigned char* trackBuf,
*
* Modifies "freqCounts".
*/
/*static*/ void
WrapperDDD::ComputeFavorites(unsigned short* freqCounts,
unsigned char* favorites)
/*static*/ void WrapperDDD::ComputeFavorites(uint16_t* freqCounts,
uint8_t* favorites)
{
int i, fav;
for (fav = 0; fav < kNumFavorites; fav++) {
unsigned short bestCount = 0;
unsigned char bestSym = 0;
uint16_t bestCount = 0;
uint8_t bestSym = 0;
for (i = 0; i < kNumSymbols; i++) {
if (freqCounts[i] >= bestCount) {
bestSym = (unsigned char) i;
bestSym = (uint8_t) i;
bestCount = freqCounts[i];
}
}
@ -445,7 +438,7 @@ WrapperDDD::ComputeFavorites(unsigned short* freqCounts,
* This is the reverse of the kFavoriteBitEnc table. The bits are
* reversed and lack the high bit.
*/
static const unsigned char kFavoriteBitDec[kNumFavorites] = {
static const uint8_t kFavoriteBitDec[kNumFavorites] = {
0x04, 0x01, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a, 0x06, 0x05, 0x1b,
0x0f, 0x09, 0x08, 0x03, 0x02, 0x01, 0x00, 0x35, 0x1d, 0x1c
};
@ -455,13 +448,12 @@ static const unsigned char kFavoriteBitDec[kNumFavorites] = {
*
* The result is an unadorned DOS-ordered image.
*/
/*static*/ DIError
WrapperDDD::UnpackDisk(GenericFD* pGFD, GenericFD* pNewGFD,
/*static*/ DIError WrapperDDD::UnpackDisk(GenericFD* pGFD, GenericFD* pNewGFD,
short* pDiskVolNum)
{
DIError dierr = kDIErrNone;
BitBuffer bitBuffer;
unsigned char val;
uint8_t val;
long lbuf;
assert(pGFD != NULL);
@ -487,7 +479,7 @@ WrapperDDD::UnpackDisk(GenericFD* pGFD, GenericFD* pNewGFD,
int track;
for (track = 0; track < kNumTracks; track++) {
unsigned char trackBuf[kTrackLen];
uint8_t trackBuf[kTrackLen];
if (!UnpackTrack(&bitBuffer, trackBuf)) {
LOGI(" DDD failed unpacking track %d", track);
@ -543,12 +535,11 @@ bail:
*
* Returns "true" if all went well, "false" if something failed.
*/
/*static*/ bool
WrapperDDD::UnpackTrack(BitBuffer* pBitBuffer, unsigned char* trackBuf)
/*static*/ bool WrapperDDD::UnpackTrack(BitBuffer* pBitBuffer, uint8_t* trackBuf)
{
unsigned char favorites[kNumFavorites];
unsigned char val;
unsigned char* trackPtr;
uint8_t favorites[kNumFavorites];
uint8_t val;
uint8_t* trackPtr;
int fav;
/*
@ -609,7 +600,7 @@ WrapperDDD::UnpackTrack(BitBuffer* pBitBuffer, unsigned char* trackBuf)
}
if (extraBits == 4) {
/* we didn't get it, this must be RLE */
unsigned char rleChar;
uint8_t rleChar;
int rleCount;
(void) pBitBuffer->GetBits(1); // get last bit of 0x97
@ -635,4 +626,3 @@ WrapperDDD::UnpackTrack(BitBuffer* pBitBuffer, unsigned char* trackBuf)
return true;
}

View File

@ -47,15 +47,13 @@ uint32_t DiskImgLib::Get24BE(const uint8_t* ptr)
(uint32_t) *ptr << 16;
}
void
DiskImgLib::PutShortLE(uint8_t* ptr, uint16_t val)
void DiskImgLib::PutShortLE(uint8_t* ptr, uint16_t val)
{
*ptr++ = (uint8_t) val;
*ptr = val >> 8;
}
void
DiskImgLib::PutLongLE(uint8_t* ptr, uint32_t val)
void DiskImgLib::PutLongLE(uint8_t* ptr, uint32_t val)
{
*ptr++ = (uint8_t) val;
*ptr++ = (uint8_t) (val >> 8);
@ -63,15 +61,13 @@ DiskImgLib::PutLongLE(uint8_t* ptr, uint32_t val)
*ptr = (uint8_t) (val >> 24);
}
void
DiskImgLib::PutShortBE(uint8_t* ptr, uint16_t val)
void DiskImgLib::PutShortBE(uint8_t* ptr, uint16_t val)
{
*ptr++ = val >> 8;
*ptr = (uint8_t) val;
}
void
DiskImgLib::PutLongBE(uint8_t* ptr, uint32_t val)
void DiskImgLib::PutLongBE(uint8_t* ptr, uint32_t val)
{
*ptr++ = (uint8_t) (val >> 24);
*ptr++ = (uint8_t) (val >> 16);
@ -83,8 +79,7 @@ DiskImgLib::PutLongBE(uint8_t* ptr, uint32_t val)
/*
* Read a two-byte little-endian value.
*/
DIError
DiskImgLib::ReadShortLE(GenericFD* pGFD, uint16_t* pBuf)
DIError DiskImgLib::ReadShortLE(GenericFD* pGFD, uint16_t* pBuf)
{
DIError dierr;
uint8_t val[2];
@ -100,8 +95,7 @@ DiskImgLib::ReadShortLE(GenericFD* pGFD, uint16_t* pBuf)
/*
* Read a four-byte little-endian value.
*/
DIError
DiskImgLib::ReadLongLE(GenericFD* pGFD, uint32_t* pBuf)
DIError DiskImgLib::ReadLongLE(GenericFD* pGFD, uint32_t* pBuf)
{
DIError dierr;
uint8_t val[4];
@ -159,7 +153,7 @@ DIError DiskImgLib::WriteShortLE(GenericFD* pGFD, uint16_t val)
*/
DIError DiskImgLib::WriteLongLE(GenericFD* pGFD, uint32_t val)
{
unsigned char buf;
uint8_t buf;
buf = (uint8_t) val;
pGFD->Write(&buf, 1);
@ -176,7 +170,7 @@ DIError DiskImgLib::WriteLongLE(GenericFD* pGFD, uint32_t val)
*/
DIError DiskImgLib::WriteShortBE(GenericFD* pGFD, uint16_t val)
{
unsigned char buf;
uint8_t buf;
buf = val >> 8;
pGFD->Write(&buf, 1);
@ -189,15 +183,15 @@ DIError DiskImgLib::WriteShortBE(GenericFD* pGFD, uint16_t val)
*/
DIError DiskImgLib::WriteLongBE(GenericFD* pGFD, uint32_t val)
{
unsigned char buf;
uint8_t buf;
buf = (unsigned char) (val >> 24);
buf = (uint8_t) (val >> 24);
pGFD->Write(&buf, 1);
buf = (unsigned char) (val >> 16);
buf = (uint8_t) (val >> 16);
pGFD->Write(&buf, 1);
buf = (unsigned char) (val >> 8);
buf = (uint8_t) (val >> 8);
pGFD->Write(&buf, 1);
buf = (unsigned char) val;
buf = (uint8_t) val;
return pGFD->Write(&buf, 1);
}
@ -209,8 +203,7 @@ DIError DiskImgLib::WriteLongBE(GenericFD* pGFD, uint32_t val)
*
* Always returns a pointer to a string; never returns NULL.
*/
const char*
DiskImgLib::FilenameOnly(const char* pathname, char fssep)
const char* DiskImgLib::FilenameOnly(const char* pathname, char fssep)
{
const char* retstr;
const char* pSlash;
@ -274,8 +267,7 @@ bail:
*
* We guarantee that there is at least one character after the '.'.
*/
const char*
DiskImgLib::FindExtension(const char* pathname, char fssep)
const char* DiskImgLib::FindExtension(const char* pathname, char fssep)
{
const char* pFilename;
const char* pExt;
@ -302,8 +294,7 @@ DiskImgLib::FindExtension(const char* pathname, char fssep)
*
* TODO: should be "StrdupNew()"
*/
char*
DiskImgLib::StrcpyNew(const char* str)
char* DiskImgLib::StrcpyNew(const char* str)
{
char* newStr;
@ -320,8 +311,7 @@ DiskImgLib::StrcpyNew(const char* str)
/*
* Convert the value from GetLastError() to its DIError counterpart.
*/
DIError
DiskImgLib::LastErrorToDIError(void)
DIError DiskImgLib::LastErrorToDIError(void)
{
DWORD lastErr = ::GetLastError();
@ -353,8 +343,7 @@ DiskImgLib::LastErrorToDIError(void)
* Returns "true" if we're running on Win9x (Win95, Win98, WinME), "false"
* if not (could be WinNT/2K/XP or even Win31 with Win32s).
*/
bool
DiskImgLib::IsWin9x(void)
bool DiskImgLib::IsWin9x(void)
{
OSVERSIONINFO osvers;
BOOL result;

View File

@ -39,8 +39,7 @@ const int kMaxTSIterations = 32;
/*
* Get a pointer to the Nth entry in a catalog sector.
*/
static inline unsigned char*
GetCatalogEntryPtr(unsigned char* basePtr, int entryNum)
static inline uint8_t* GetCatalogEntryPtr(uint8_t* basePtr, int entryNum)
{
assert(entryNum >= 0 && entryNum < kCatalogEntriesPerSect);
return basePtr + kCatalogEntryOffset + entryNum * kCatalogEntrySize;
@ -70,11 +69,11 @@ GetCatalogEntryPtr(unsigned char* basePtr, int entryNum)
*
* DISK198B (Aliens+docs) gets 3 and bails with a self-reference.
*/
static DIError
TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder, int* pGoodCount)
static DIError TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder,
int* pGoodCount)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
int numTracks, numSectors;
int catTrack, catSect;
int foundGood = 0;
@ -147,8 +146,7 @@ bail:
/*
* Test to see if the image is a DOS 3.2 or DOS 3.3 disk.
*/
/*static*/ DIError
DiskFSDOS33::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSDOS33::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
if (pImg->GetNumTracks() > kMaxInterestingTracks)
@ -198,8 +196,7 @@ DiskFSDOS33::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
* on out must be handled somehow, possibly by claiming that the disk is
* completely full and has no files on it.
*/
DIError
DiskFSDOS33::Initialize(InitMode initMode)
DIError DiskFSDOS33::Initialize(InitMode initMode)
{
DIError dierr = kDIErrNone;
@ -250,8 +247,7 @@ bail:
/*
* Read some fields from the disk Volume Table of Contents.
*/
DIError
DiskFSDOS33::ReadVTOC(void)
DIError DiskFSDOS33::ReadVTOC(void)
{
DIError dierr;
@ -291,8 +287,7 @@ bail:
* Call this if fpImg's volume num (derived from nibble formats) or
* the VTOC's volume number changes.
*/
void
DiskFSDOS33::UpdateVolumeNum(void)
void DiskFSDOS33::UpdateVolumeNum(void)
{
/* use the sector-embedded volume number, if available */
if (fpImg->GetDOSVolumeNum() == DiskImg::kVolumeNumNotSet)
@ -308,8 +303,7 @@ DiskFSDOS33::UpdateVolumeNum(void)
/*
* Set the disk volume number (fDiskVolumeNum) and derived fields.
*/
void
DiskFSDOS33::SetDiskVolumeNum(int val)
void DiskFSDOS33::SetDiskVolumeNum(int val)
{
if (val < 0 || val > 255) {
// Actual valid range should be 1-254, but it's possible for a
@ -330,8 +324,7 @@ DiskFSDOS33::SetDiskVolumeNum(int val)
/*
* Dump some VTOC fields.
*/
void
DiskFSDOS33::DumpVTOC(void)
void DiskFSDOS33::DumpVTOC(void)
{
LOGI("VTOC catalog: track=%d sector=%d",
@ -343,8 +336,7 @@ DiskFSDOS33::DumpVTOC(void)
/*
* Update an entry in the VolumeUsage map, watching for conflicts.
*/
void
DiskFSDOS33::SetSectorUsage(long track, long sector,
void DiskFSDOS33::SetSectorUsage(long track, long sector,
VolumeUsage::ChunkPurpose purpose)
{
VolumeUsage::ChunkState cstate;
@ -378,8 +370,7 @@ DiskFSDOS33::SetSectorUsage(long track, long sector,
* various files, and mark the tracks as owned by DOS if nobody else
* claims them.
*/
DIError
DiskFSDOS33::ScanVolBitmap(void)
DIError DiskFSDOS33::ScanVolBitmap(void)
{
DIError dierr;
VolumeUsage::ChunkState cstate;
@ -397,13 +388,13 @@ DiskFSDOS33::ScanVolBitmap(void)
int i;
for (i = 0; i < kMaxTracks; i++) {
unsigned long val, origVal;
uint32_t val, origVal;
int bit;
val = (unsigned long) fVTOC[0x38 + i*4] << 24;
val |= (unsigned long) fVTOC[0x39 + i*4] << 16;
val |= (unsigned long) fVTOC[0x3a + i*4] << 8;
val |= (unsigned long) fVTOC[0x3b + i*4];
val = (uint32_t) fVTOC[0x38 + i*4] << 24;
val |= (uint32_t) fVTOC[0x39 + i*4] << 16;
val |= (uint32_t) fVTOC[0x3a + i*4] << 8;
val |= (uint32_t) fVTOC[0x3b + i*4];
origVal = val;
/* init the VolumeUsage stuff */
@ -433,8 +424,7 @@ bail:
/*
* Load the VTOC into the buffer.
*/
DIError
DiskFSDOS33::LoadVolBitmap(void)
DIError DiskFSDOS33::LoadVolBitmap(void)
{
DIError dierr;
@ -451,8 +441,7 @@ DiskFSDOS33::LoadVolBitmap(void)
/*
* Save our copy of the volume bitmap.
*/
DIError
DiskFSDOS33::SaveVolBitmap(void)
DIError DiskFSDOS33::SaveVolBitmap(void)
{
if (!fVTOCLoaded) {
assert(false);
@ -467,8 +456,7 @@ DiskFSDOS33::SaveVolBitmap(void)
*
* It's okay to call this if the bitmap isn't loaded.
*/
void
DiskFSDOS33::FreeVolBitmap(void)
void DiskFSDOS33::FreeVolBitmap(void)
{
fVTOCLoaded = false;
@ -480,14 +468,13 @@ DiskFSDOS33::FreeVolBitmap(void)
/*
* Return entry N from the VTOC.
*/
inline unsigned long
DiskFSDOS33::GetVTOCEntry(const unsigned char* pVTOC, long track) const
inline uint32_t DiskFSDOS33::GetVTOCEntry(const uint8_t* pVTOC, long track) const
{
unsigned long val;
val = (unsigned long) pVTOC[0x38 + track*4] << 24;
val |= (unsigned long) pVTOC[0x39 + track*4] << 16;
val |= (unsigned long) pVTOC[0x3a + track*4] << 8;
val |= (unsigned long) pVTOC[0x3b + track*4];
uint32_t val;
val = (uint32_t) pVTOC[0x38 + track*4] << 24;
val |= (uint32_t) pVTOC[0x39 + track*4] << 16;
val |= (uint32_t) pVTOC[0x3a + track*4] << 8;
val |= (uint32_t) pVTOC[0x3b + track*4];
return val;
}
@ -497,11 +484,10 @@ DiskFSDOS33::GetVTOCEntry(const unsigned char* pVTOC, long track) const
*
* Only touches the in-memory copy.
*/
DIError
DiskFSDOS33::AllocSector(TrackSector* pTS)
DIError DiskFSDOS33::AllocSector(TrackSector* pTS)
{
unsigned long val;
unsigned long mask;
uint32_t val;
uint32_t mask;
long track, numSectPerTrack;
/* we could compute "mask", but it's faster and easier to do this */
@ -567,7 +553,7 @@ DiskFSDOS33::AllocSector(TrackSector* pTS)
/*
* Mostly for fun, update the VTOC allocation thingy.
*/
fVTOC[0x30] = (unsigned char) track; // last track where alloc happened
fVTOC[0x30] = (uint8_t) track; // last track where alloc happened
if (track < kVTOCTrack)
fVTOC[0x31] = 0xff; // descending
else
@ -584,8 +570,7 @@ DiskFSDOS33::AllocSector(TrackSector* pTS)
*
* If "withDOS" is set, mark the first 3 tracks as in-use.
*/
DIError
DiskFSDOS33::CreateEmptyBlockMap(bool withDOS)
DIError DiskFSDOS33::CreateEmptyBlockMap(bool withDOS)
{
DIError dierr;
long track, sector, maxTrack;
@ -627,20 +612,19 @@ DiskFSDOS33::CreateEmptyBlockMap(bool withDOS)
*
* Returns "true" if it's in use, "false" otherwise.
*/
bool
DiskFSDOS33::GetSectorUseEntry(long track, int sector) const
bool DiskFSDOS33::GetSectorUseEntry(long track, int sector) const
{
assert(fVTOCLoaded);
assert(track >= 0 && track < fpImg->GetNumTracks());
assert(sector >= 0 && sector < fpImg->GetNumSectPerTrack());
unsigned long val, mask;
uint32_t val, mask;
val = GetVTOCEntry(fVTOC, track);
//val = (unsigned long) fVTOC[0x38 + track*4] << 24;
//val |= (unsigned long) fVTOC[0x39 + track*4] << 16;
//val |= (unsigned long) fVTOC[0x3a + track*4] << 8;
//val |= (unsigned long) fVTOC[0x3b + track*4];
//val = (uint32_t) fVTOC[0x38 + track*4] << 24;
//val |= (uint32_t) fVTOC[0x39 + track*4] << 16;
//val |= (uint32_t) fVTOC[0x3a + track*4] << 8;
//val |= (uint32_t) fVTOC[0x3b + track*4];
/*
* The highest-numbered sector is now in the high bit. If this is a
@ -655,14 +639,13 @@ DiskFSDOS33::GetSectorUseEntry(long track, int sector) const
/*
* Change the state of an entry in the VTOC sector use map.
*/
void
DiskFSDOS33::SetSectorUseEntry(long track, int sector, bool inUse)
void DiskFSDOS33::SetSectorUseEntry(long track, int sector, bool inUse)
{
assert(fVTOCLoaded);
assert(track >= 0 && track < fpImg->GetNumTracks());
assert(sector >= 0 && sector < fpImg->GetNumSectPerTrack());
unsigned long val, mask;
uint32_t val, mask;
val = GetVTOCEntry(fVTOC, track);
@ -673,18 +656,17 @@ DiskFSDOS33::SetSectorUseEntry(long track, int sector, bool inUse)
else
val |= mask;
fVTOC[0x38 + track*4] = (unsigned char) (val >> 24);
fVTOC[0x39 + track*4] = (unsigned char) (val >> 16);
fVTOC[0x3a + track*4] = (unsigned char) (val >> 8);
fVTOC[0x3b + track*4] = (unsigned char) val;
fVTOC[0x38 + track*4] = (uint8_t) (val >> 24);
fVTOC[0x39 + track*4] = (uint8_t) (val >> 16);
fVTOC[0x3a + track*4] = (uint8_t) (val >> 8);
fVTOC[0x3b + track*4] = (uint8_t) val;
}
/*
* Get the amount of free space remaining.
*/
DIError
DiskFSDOS33::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
DIError DiskFSDOS33::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
int* pUnitSize) const
{
DIError dierr;
@ -720,8 +702,7 @@ DiskFSDOS33::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
* disks had DOS removed to add space, un-set the last few sectors of track 2
* that weren't actually used by DOS, or did some other funky thing.
*/
void
DiskFSDOS33::FixVolumeUsageMap(void)
void DiskFSDOS33::FixVolumeUsageMap(void)
{
VolumeUsage::ChunkState cstate;
int track, sector;
@ -749,11 +730,10 @@ DiskFSDOS33::FixVolumeUsageMap(void)
*
* Fills out "fCatalogSectors" as it works.
*/
DIError
DiskFSDOS33::ReadCatalog(void)
DIError DiskFSDOS33::ReadCatalog(void)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
int catTrack, catSect;
int iterations;
@ -821,12 +801,11 @@ bail:
* Pass in the track, sector, and the contents of that track and sector.
* (We only use "catTrack" and "catSect" to fill out some fields.)
*/
DIError
DiskFSDOS33::ProcessCatalogSector(int catTrack, int catSect,
const unsigned char* sctBuf)
DIError DiskFSDOS33::ProcessCatalogSector(int catTrack, int catSect,
const uint8_t* sctBuf)
{
A2FileDOS* pFile;
const unsigned char* pEntry;
const uint8_t* pEntry;
int i;
pEntry = &sctBuf[kCatalogEntryOffset];
@ -862,7 +841,7 @@ DiskFSDOS33::ProcessCatalogSector(int catTrack, int catSect,
pFile->FixFilename();
pFile->fLengthInSectors = pEntry[0x21];
pFile->fLengthInSectors |= (unsigned short) pEntry[0x22] << 8;
pFile->fLengthInSectors |= (uint16_t) pEntry[0x22] << 8;
pFile->fCatTS.track = catTrack;
pFile->fCatTS.sector = catSect;
@ -888,8 +867,7 @@ DiskFSDOS33::ProcessCatalogSector(int catTrack, int catSect,
*
* Returns "true" if disk appears to be perfect, "false" otherwise.
*/
bool
DiskFSDOS33::CheckDiskIsGood(void)
bool DiskFSDOS33::CheckDiskIsGood(void)
{
DIError dierr;
const DiskImg* pDiskImg = GetDiskImg();
@ -994,8 +972,7 @@ bail:
* Run through our list of files, computing the lengths and marking file
* usage in the VolumeUsage object.
*/
DIError
DiskFSDOS33::GetFileLengths(void)
DIError DiskFSDOS33::GetFileLengths(void)
{
A2FileDOS* pFile;
TrackSector* tsList = NULL;
@ -1076,12 +1053,11 @@ DiskFSDOS33::GetFileLengths(void)
* pFile->fSparseLength
* pFile->fDataOffset
*/
DIError
DiskFSDOS33::ComputeLength(A2FileDOS* pFile, const TrackSector* tsList,
DIError DiskFSDOS33::ComputeLength(A2FileDOS* pFile, const TrackSector* tsList,
int tsCount)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
assert(pFile != NULL);
assert(tsList != NULL);
@ -1110,13 +1086,13 @@ DiskFSDOS33::ComputeLength(A2FileDOS* pFile, const TrackSector* tsList,
if (pFile->fFileType == A2FileDOS::kTypeBinary) {
pFile->fAuxType =
sctBuf[0x00] | (unsigned short) sctBuf[0x01] << 8;
sctBuf[0x00] | (uint16_t) sctBuf[0x01] << 8;
pFile->fLength =
sctBuf[0x02] | (unsigned short) sctBuf[0x03] << 8;
sctBuf[0x02] | (uint16_t) sctBuf[0x03] << 8;
pFile->fDataOffset = 4; // take the above into account
} else {
pFile->fLength =
sctBuf[0x00] | (unsigned short) sctBuf[0x01] << 8;
sctBuf[0x00] | (uint16_t) sctBuf[0x01] << 8;
pFile->fDataOffset = 2; // take the above into account
}
@ -1208,11 +1184,10 @@ bail:
* the body of the file. They're valid in the middle for random-access
* text files.
*/
DIError
DiskFSDOS33::TrimLastSectorUp(A2FileDOS* pFile, TrackSector lastTS)
DIError DiskFSDOS33::TrimLastSectorUp(A2FileDOS* pFile, TrackSector lastTS)
{
DIError dierr;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
int i;
if (lastTS.track == 0) {
@ -1242,8 +1217,7 @@ bail:
* Given lists of tracks and sector for data and TS index sectors, set the
* entries in the volume usage map.
*/
void
DiskFSDOS33::MarkFileUsage(A2FileDOS* pFile, TrackSector* tsList, int tsCount,
void DiskFSDOS33::MarkFileUsage(A2FileDOS* pFile, TrackSector* tsList, int tsCount,
TrackSector* indexList, int indexCount)
{
int i;
@ -1283,11 +1257,11 @@ DiskFSDOS33::MarkFileUsage(A2FileDOS* pFile, TrackSector* tsList, int tsCount,
* worthwhile given the otherwise flaky nature of DDD storage.
*/
DIError
DiskFSDOS33::TrimLastSectorDown(A2FileDOS* pFile, unsigned short* tsBuf,
DiskFSDOS33::TrimLastSectorDown(A2FileDOS* pFile, uint16_t* tsBuf,
int maxZeroCount)
{
DIError dierr;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
int i;
//LOGI(" DOS reading LAST file sector");
@ -1328,8 +1302,7 @@ bail:
*
* We modify the first "len" bytes of "buf" in place.
*/
/*static*/ void
DiskFSDOS33::LowerASCII(unsigned char* buf, long len)
/*static*/ void DiskFSDOS33::LowerASCII(uint8_t* buf, long len)
{
while (len--) {
if (*buf & 0x80) {
@ -1358,8 +1331,7 @@ DiskFSDOS33::LowerASCII(unsigned char* buf, long len)
* "invalid" character is a trailing space. Because we're using C-style
* strings, we implicitly ban the use of '\0' in the name.
*/
/*static*/ bool
DiskFSDOS33::IsValidFileName(const char* name)
/*static*/ bool DiskFSDOS33::IsValidFileName(const char* name)
{
bool nonSpace = false;
int len = 0;
@ -1387,8 +1359,7 @@ DiskFSDOS33::IsValidFileName(const char* name)
/*
* Determine whether "name" is a valid volume number.
*/
/*static*/ bool
DiskFSDOS33::IsValidVolumeName(const char* name)
/*static*/ bool DiskFSDOS33::IsValidVolumeName(const char* name)
{
long val;
char* endp;
@ -1418,11 +1389,10 @@ DiskFSDOS33::IsValidVolumeName(const char* name)
* some other path for specifying "add DOS image", I continue to use the
* defined ways of setting the volume number and abuse "volName" slightly.
*/
DIError
DiskFSDOS33::Format(DiskImg* pDiskImg, const char* volName)
DIError DiskFSDOS33::Format(DiskImg* pDiskImg, const char* volName)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[256];
uint8_t sctBuf[256];
bool addDOS = false;
if (pDiskImg->GetNumTracks() < kMinTracks ||
@ -1493,11 +1463,11 @@ DiskFSDOS33::Format(DiskImg* pDiskImg, const char* volName)
if (fpImg->GetDOSVolumeNum() == DiskImg::kVolumeNumNotSet)
fVTOC[0x06] = kDefaultVolumeNum; // VTOC volume number
else
fVTOC[0x06] = (unsigned char) fpImg->GetDOSVolumeNum();
fVTOC[0x06] = (uint8_t) fpImg->GetDOSVolumeNum();
fVTOC[0x27] = 122; // max T/S pairs
fVTOC[0x30] = kVTOCTrack+1; // last alloc
fVTOC[0x31] = 1; // ascending
fVTOC[0x34] = (unsigned char)fpImg->GetNumTracks(); // #of tracks
fVTOC[0x34] = (uint8_t)fpImg->GetNumTracks(); // #of tracks
fVTOC[0x35] = fpImg->GetNumSectPerTrack(); // #of sectors
fVTOC[0x36] = 0x00; // bytes/sector (lo)
fVTOC[0x37] = 0x01; // bytes/sector (hi)
@ -1554,12 +1524,11 @@ bail:
* out which version of DOS to write. This probably ought to be an enum so
* we can specify various versions of DOS.
*/
DIError
DiskFSDOS33::WriteDOSTracks(int sectPerTrack)
DIError DiskFSDOS33::WriteDOSTracks(int sectPerTrack)
{
DIError dierr = kDIErrNone;
long track, sector;
const unsigned char* buf = gDOS33Tracks;
const uint8_t* buf = gDOS33Tracks;
if (sectPerTrack == 13) {
LOGI(" DOS33 writing DOS 3.3 tracks");
@ -1604,8 +1573,7 @@ bail:
* "*pNormalizedBufLen" is used to pass in the length of the buffer and
* pass out the length of the string (should the buffer prove inadequate).
*/
DIError
DiskFSDOS33::NormalizePath(const char* path, char fssep,
DIError DiskFSDOS33::NormalizePath(const char* path, char fssep,
char* normalizedBuf, int* pNormalizedBufLen)
{
DIError dierr = kDIErrNone;
@ -1630,8 +1598,7 @@ DiskFSDOS33::NormalizePath(const char* path, char fssep,
*
* "outBuf" must be able to hold kMaxFileName+1 characters.
*/
void
DiskFSDOS33::DoNormalizePath(const char* name, char fssep, char* outBuf)
void DiskFSDOS33::DoNormalizePath(const char* name, char fssep, char* outBuf)
{
char* outp = outBuf;
const char* cp;
@ -1684,8 +1651,7 @@ DiskFSDOS33::DoNormalizePath(const char* name, char fssep, char* outBuf)
* sector of the file now, and modifying the Write() function to understand
* that the first block is already there. Need to do that someday.)
*/
DIError
DiskFSDOS33::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
DIError DiskFSDOS33::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
{
DIError dierr = kDIErrNone;
const bool createUnique = (GetParameter(kParm_CreateUnique) != 0);
@ -1730,7 +1696,7 @@ DiskFSDOS33::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
/*
* Allocate a directory entry and T/S list.
*/
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
TrackSector catSect;
TrackSector tsSect;
int catEntry;
@ -1764,7 +1730,7 @@ DiskFSDOS33::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
/* create the new dir entry at the specified location */
CreateDirEntry(sctBuf, catEntry, normalName, &tsSect,
(unsigned char) fileType, pParms->access);
(uint8_t) fileType, pParms->access);
/*
* Flush everything to disk.
@ -1796,7 +1762,7 @@ DiskFSDOS33::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
pNewFile->fCatTS.sector = catSect.sector;
pNewFile->fCatEntryNum = catEntry;
pNewFile->fAuxType = (unsigned short) pParms->auxType;
pNewFile->fAuxType = (uint16_t) pParms->auxType;
pNewFile->fDataOffset = 0;
switch (pNewFile->fFileType) {
case A2FileDOS::kTypeInteger:
@ -1843,8 +1809,7 @@ bail:
*
* Returns an error on failure, which should be impossible.
*/
DIError
DiskFSDOS33::MakeFileNameUnique(char* fileName)
DIError DiskFSDOS33::MakeFileNameUnique(char* fileName)
{
assert(fileName != NULL);
assert(strlen(fileName) <= A2FileDOS::kMaxFileName);
@ -1911,12 +1876,11 @@ DiskFSDOS33::MakeFileNameUnique(char* fileName)
*
* The contents of the catalog sector will be in "sctBuf".
*/
DIError
DiskFSDOS33::GetFreeCatalogEntry(TrackSector* pCatSect, int* pCatEntry,
unsigned char* sctBuf, A2FileDOS** ppPrevEntry)
DIError DiskFSDOS33::GetFreeCatalogEntry(TrackSector* pCatSect, int* pCatEntry,
uint8_t* sctBuf, A2FileDOS** ppPrevEntry)
{
DIError dierr = kDIErrNone;
unsigned char* pEntry;
uint8_t* pEntry;
int sct, ent;
bool found = false;
@ -1998,13 +1962,12 @@ bail:
/*
* Fill out the catalog entry in the location specified.
*/
void
DiskFSDOS33::CreateDirEntry(unsigned char* sctBuf, int catEntry,
const char* fileName, TrackSector* pTSSect, unsigned char fileType,
void DiskFSDOS33::CreateDirEntry(uint8_t* sctBuf, int catEntry,
const char* fileName, TrackSector* pTSSect, uint8_t fileType,
int access)
{
char highName[A2FileDOS::kMaxFileName+1];
unsigned char* pEntry;
uint8_t* pEntry;
pEntry = GetCatalogEntryPtr(sctBuf, catEntry);
if (pEntry[0x00] != 0x00 && pEntry[0x00] != kEntryDeleted) {
@ -2019,7 +1982,7 @@ DiskFSDOS33::CreateDirEntry(unsigned char* sctBuf, int catEntry,
pEntry[0x01] = pTSSect->sector;
pEntry[0x02] = fileType;
if ((access & A2FileProDOS::kAccessWrite) == 0)
pEntry[0x02] |= (unsigned char) A2FileDOS::kTypeLocked;
pEntry[0x02] |= (uint8_t) A2FileDOS::kTypeLocked;
memcpy(&pEntry[0x03], highName, A2FileDOS::kMaxFileName);
PutShortLE(&pEntry[0x21], 1); // assume file is 1 sector long
}
@ -2030,16 +1993,15 @@ DiskFSDOS33::CreateDirEntry(unsigned char* sctBuf, int catEntry,
* This entails freeing up the allocated sectors and changing a byte in
* the directory entry. We then remove it from the DiskFS file list.
*/
DIError
DiskFSDOS33::DeleteFile(A2File* pGenericFile)
DIError DiskFSDOS33::DeleteFile(A2File* pGenericFile)
{
DIError dierr = kDIErrNone;
A2FileDOS* pFile = (A2FileDOS*) pGenericFile;
TrackSector* tsList = NULL;
TrackSector* indexList = NULL;
int tsCount, indexCount;
unsigned char sctBuf[kSctSize];
unsigned char* pEntry;
uint8_t sctBuf[kSctSize];
uint8_t* pEntry;
if (pGenericFile == NULL) {
assert(false);
@ -2110,8 +2072,7 @@ bail:
/*
* Mark all of the track/sector entries in "pList" as free.
*/
void
DiskFSDOS33::FreeTrackSectors(TrackSector* pList, int count)
void DiskFSDOS33::FreeTrackSectors(TrackSector* pList, int count)
{
VolumeUsage::ChunkState cstate;
int i;
@ -2140,15 +2101,14 @@ DiskFSDOS33::FreeTrackSectors(TrackSector* pList, int count)
*
* "newName" must already be normalized.
*/
DIError
DiskFSDOS33::RenameFile(A2File* pGenericFile, const char* newName)
DIError DiskFSDOS33::RenameFile(A2File* pGenericFile, const char* newName)
{
DIError dierr = kDIErrNone;
A2FileDOS* pFile = (A2FileDOS*) pGenericFile;
char normalName[A2FileDOS::kMaxFileName+1];
char dosName[A2FileDOS::kMaxFileName+1];
unsigned char sctBuf[kSctSize];
unsigned char* pEntry;
uint8_t sctBuf[kSctSize];
uint8_t* pEntry;
if (pFile == NULL || newName == NULL)
return kDIErrInvalidArg;
@ -2185,7 +2145,7 @@ DiskFSDOS33::RenameFile(A2File* pGenericFile, const char* newName)
*/
char storedName[A2FileDOS::kMaxFileName+1];
strcpy(storedName, dosName);
LowerASCII((unsigned char*)storedName, A2FileDOS::kMaxFileName);
LowerASCII((uint8_t*)storedName, A2FileDOS::kMaxFileName);
A2FileDOS::TrimTrailingSpaces(storedName);
strcpy(pFile->fFileName, storedName);
@ -2205,8 +2165,7 @@ bail:
*
* Changing the aux type is only allowed for BIN files.
*/
DIError
DiskFSDOS33::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
DIError DiskFSDOS33::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
long accessFlags)
{
DIError dierr = kDIErrNone;
@ -2249,8 +2208,8 @@ DiskFSDOS33::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
*/
if (nowLocked != pFile->fLocked || typeChanged) {
A2FileDOS::FileType newFileType;
unsigned char sctBuf[kSctSize];
unsigned char* pEntry;
uint8_t sctBuf[kSctSize];
uint8_t* pEntry;
LOGI("Updating file '%s'", pFile->GetPathName());
@ -2262,7 +2221,7 @@ DiskFSDOS33::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
pEntry = GetCatalogEntryPtr(sctBuf, pFile->fCatEntryNum);
newFileType = A2FileDOS::ConvertFileType(fileType, 0);
pEntry[0x02] = (unsigned char) newFileType;
pEntry[0x02] = (uint8_t) newFileType;
if (nowLocked)
pEntry[0x02] |= 0x80;
@ -2297,8 +2256,8 @@ DiskFSDOS33::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
* On top of all this, if we changed the file type at all then we need to
* re-scan the file length and "data offset" value.
*/
unsigned short newAuxType;
newAuxType = (unsigned short) auxType;
uint16_t newAuxType;
newAuxType = (uint16_t) auxType;
dierr = pFile->LoadTSList(&tsList, &tsCount);
if (dierr != kDIErrNone) {
@ -2307,7 +2266,7 @@ DiskFSDOS33::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
}
if (fileType == 0x06 && tsCount > 0) {
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
dierr = fpImg->ReadTrackSector(tsList[0].track,
tsList[0].sector, sctBuf);
@ -2366,11 +2325,10 @@ bail:
* We can't change the 2MG header, and we can't change the values embedded
* in the sector headers, so all we do is change the VTOC entry.
*/
DIError
DiskFSDOS33::RenameVolume(const char* newName)
DIError DiskFSDOS33::RenameVolume(const char* newName)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
long newNumber;
char* endp;
@ -2386,7 +2344,7 @@ DiskFSDOS33::RenameVolume(const char* newName)
if (dierr != kDIErrNone)
goto bail;
sctBuf[0x06] = (unsigned char) newNumber;
sctBuf[0x06] = (uint8_t) newNumber;
dierr = fpImg->WriteTrackSector(kVTOCTrack, kVTOCSector, sctBuf);
if (dierr != kDIErrNone)
@ -2453,8 +2411,7 @@ A2FileDOS::~A2FileDOS(void)
* because I can't find any information on the REL format. However, Copy ][+
* does convert to REL, and the Binary ][ standard says I should as well.
*/
long
A2FileDOS::GetFileType(void) const
long A2FileDOS::GetFileType(void) const
{
long retval;
@ -2491,8 +2448,8 @@ A2FileDOS::GetFileType(void) const
* be hoped. We can make life a little less confusing for the caller by
* using type 'S' for any unknown type.
*/
/*static*/ A2FileDOS::FileType
A2FileDOS::ConvertFileType(long prodosType, di_off_t fileLen)
/*static*/ A2FileDOS::FileType A2FileDOS::ConvertFileType(long prodosType,
di_off_t fileLen)
{
const long kMaxBinary = 65535;
FileType newType;
@ -2524,8 +2481,7 @@ A2FileDOS::ConvertFileType(long prodosType, di_off_t fileLen)
/*
* Determine whether the specified type has a valid DOS mapping.
*/
/*static*/ bool
A2FileDOS::IsValidType(long prodosType)
/*static*/ bool A2FileDOS::IsValidType(long prodosType)
{
switch (prodosType) {
case 0xb0: // SRC
@ -2546,8 +2502,7 @@ A2FileDOS::IsValidType(long prodosType)
/*
* Match the ProDOS equivalents of "locked" and "unlocked".
*/
long
A2FileDOS::GetAccess(void) const
long A2FileDOS::GetAccess(void) const
{
if (fLocked)
return DiskFS::kFileAccessLocked; // 0x01 read
@ -2559,10 +2514,9 @@ A2FileDOS::GetAccess(void) const
* "Fix" a DOS3.3 filename. Convert DOS-ASCII to normal ASCII, and strip
* trailing spaces.
*/
void
A2FileDOS::FixFilename(void)
void A2FileDOS::FixFilename(void)
{
DiskFSDOS33::LowerASCII((unsigned char*)fFileName, kMaxFileName);
DiskFSDOS33::LowerASCII((uint8_t*)fFileName, kMaxFileName);
TrimTrailingSpaces(fFileName);
}
@ -2571,8 +2525,7 @@ A2FileDOS::FixFilename(void)
*
* Assumes the filename has already been converted to low ASCII.
*/
/*static*/ void
A2FileDOS::TrimTrailingSpaces(char* filename)
/*static*/ void A2FileDOS::TrimTrailingSpaces(char* filename)
{
char* lastspc = filename + strlen(filename);
@ -2593,8 +2546,7 @@ A2FileDOS::TrimTrailingSpaces(char* filename)
*
* "buf" must be able to hold kMaxFileName+1 chars.
*/
/*static*/ void
A2FileDOS::MakeDOSName(char* buf, const char* name)
/*static*/ void A2FileDOS::MakeDOSName(char* buf, const char* name)
{
for (int i = 0; i < kMaxFileName; i++) {
if (*name == '\0')
@ -2609,8 +2561,7 @@ A2FileDOS::MakeDOSName(char* buf, const char* name)
/*
* Set up state for this file.
*/
DIError
A2FileDOS::Open(A2FileDescr** ppOpenFile, bool readOnly,
DIError A2FileDOS::Open(A2FileDescr** ppOpenFile, bool readOnly,
bool rsrcFork /*=false*/)
{
DIError dierr = kDIErrNone;
@ -2656,8 +2607,7 @@ bail:
/*
* Dump the contents of an A2FileDOS.
*/
void
A2FileDOS::Dump(void) const
void A2FileDOS::Dump(void) const
{
LOGI("A2FileDOS '%s'", fFileName);
LOGI(" TS T=%-2d S=%-2d", fTSListTrack, fTSListSector);
@ -2690,8 +2640,7 @@ A2FileDOS::Dump(void) const
* impossible. Currently this isn't a problem, but for e.g. T/S lists
* with garbage at the end would could deal with the problem more generally.
*/
DIError
A2FileDOS::LoadTSList(TrackSector** pTSList, int* pTSCount,
DIError A2FileDOS::LoadTSList(TrackSector** pTSList, int* pTSCount,
TrackSector** pIndexList, int* pIndexCount)
{
DIError dierr = kDIErrNone;
@ -2702,7 +2651,7 @@ A2FileDOS::LoadTSList(TrackSector** pTSList, int* pTSCount,
TrackSector* indexList = NULL;
int tsCount, tsAlloc;
int indexCount, indexAlloc;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
int track, sector, iterations;
LOGI("--- DOS loading T/S list for '%s'", GetPathName());
@ -2742,7 +2691,7 @@ A2FileDOS::LoadTSList(TrackSector** pTSList, int* pTSCount,
*/
iterations = 0;
do {
unsigned short sectorOffset;
uint16_t sectorOffset;
int lastNonZero;
/*
@ -2875,13 +2824,12 @@ bail:
* entries have been copied. If it looks to be partially valid, only the
* valid parts are copied out, with the rest zeroed.
*/
DIError
A2FileDOS::ExtractTSPairs(const unsigned char* sctBuf, TrackSector* tsList,
DIError A2FileDOS::ExtractTSPairs(const uint8_t* sctBuf, TrackSector* tsList,
int* pLastNonZero)
{
DIError dierr = kDIErrNone;
const DiskImg* pDiskImg = fpDiskFS->GetDiskImg();
const unsigned char* ptr;
const uint8_t* ptr;
int i, track, sector;
*pLastNonZero = -1;
@ -2935,8 +2883,7 @@ bail:
* Files read back as they would from ProDOS, i.e. if you read a binary
* file you won't see the 4 bytes of length and address.
*/
DIError
A2FDDOS::Read(void* buf, size_t len, size_t* pActual)
DIError A2FDDOS::Read(void* buf, size_t len, size_t* pActual)
{
LOGI(" DOS reading %d bytes from '%s' (offset=%ld)",
len, fpFile->GetPathName(), (long) fOffset);
@ -2958,7 +2905,7 @@ A2FDDOS::Read(void* buf, size_t len, size_t* pActual)
long incrLen = len;
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
di_off_t actualOffset = fOffset + pFile->fDataOffset; // adjust for embedded len
int tsIndex = (int) (actualOffset / kSctSize);
int bufOffset = (int) (actualOffset % kSctSize); // (& 0xff)
@ -3023,13 +2970,12 @@ A2FDDOS::Read(void* buf, size_t len, size_t* pActual)
*
* Modifies fOpenEOF, fOpenSectorsUsed, and sets fModified.
*/
DIError
A2FDDOS::Write(const void* buf, size_t len, size_t* pActual)
DIError A2FDDOS::Write(const void* buf, size_t len, size_t* pActual)
{
DIError dierr = kDIErrNone;
A2FileDOS* pFile = (A2FileDOS*) fpFile;
DiskFSDOS33* pDiskFS = (DiskFSDOS33*) fpFile->GetDiskFS();
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
LOGI(" DOS Write len=%u %s", len, pFile->GetPathName());
@ -3117,10 +3063,10 @@ A2FDDOS::Write(const void* buf, size_t len, size_t* pActual)
/*
* Write the sectors into the T/S list.
*/
const unsigned char* curPtr;
const uint8_t* curPtr;
int sectorIdx;
curPtr = (const unsigned char*) buf;
curPtr = (const uint8_t*) buf;
sectorIdx = 0;
if (pFile->fDataOffset > 0) {
@ -3229,8 +3175,7 @@ bail:
/*
* Seek to the specified offset.
*/
DIError
A2FDDOS::Seek(di_off_t offset, DIWhence whence)
DIError A2FDDOS::Seek(di_off_t offset, DIWhence whence)
{
//di_off_t fileLength = fpFile->GetDataLength();
@ -3265,8 +3210,7 @@ A2FDDOS::Seek(di_off_t offset, DIWhence whence)
/*
* Return current offset.
*/
di_off_t
A2FDDOS::Tell(void)
di_off_t A2FDDOS::Tell(void)
{
return fOffset;
}
@ -3285,16 +3229,15 @@ A2FDDOS::Tell(void)
* Most applications don't check the value of "Close", or call it from a
* destructor, so we call CloseDescr whether we succeed or not.
*/
DIError
A2FDDOS::Close(void)
DIError A2FDDOS::Close(void)
{
DIError dierr = kDIErrNone;
if (fModified) {
DiskFSDOS33* pDiskFS = (DiskFSDOS33*) fpFile->GetDiskFS();
A2FileDOS* pFile = (A2FileDOS*) fpFile;
unsigned char sctBuf[kSctSize];
unsigned char* pEntry;
uint8_t sctBuf[kSctSize];
uint8_t* pEntry;
/*
* Fill in the length and address, if needed for this type of file.
@ -3307,30 +3250,30 @@ A2FDDOS::Close(void)
assert(pFile->fDataOffset > 0);
//assert(fOpenEOF < 65536);
if (fOpenEOF > 65535) {
LOGI("WARNING: DOS Close trimming A/I/B file from %ld to 65535",
LOGW("WARNING: DOS Close trimming A/I/B file from %ld to 65535",
(long) fOpenEOF);
fOpenEOF = 65535;
}
dierr = pDiskFS->GetDiskImg()->ReadTrackSector(fTSList[0].track,
fTSList[0].sector, sctBuf);
if (dierr != kDIErrNone) {
LOGI("DOS Close: unable to get first sector of file");
LOGW("DOS Close: unable to get first sector of file");
goto bail;
}
if (pFile->fFileType == A2FileDOS::kTypeInteger ||
pFile->fFileType == A2FileDOS::kTypeApplesoft)
{
PutShortLE(&sctBuf[0x00], (unsigned short) fOpenEOF);
PutShortLE(&sctBuf[0x00], (uint16_t) fOpenEOF);
} else {
PutShortLE(&sctBuf[0x00], pFile->fAuxType);
PutShortLE(&sctBuf[0x02], (unsigned short) fOpenEOF);
PutShortLE(&sctBuf[0x02], (uint16_t) fOpenEOF);
}
dierr = pDiskFS->GetDiskImg()->WriteTrackSector(fTSList[0].track,
fTSList[0].sector, sctBuf);
if (dierr != kDIErrNone) {
LOGI("DOS Close: unable to write first sector of file");
LOGW("DOS Close: unable to write first sector of file");
goto bail;
}
} else if (pFile->fFileType == A2FileDOS::kTypeText) {
@ -3358,7 +3301,7 @@ A2FDDOS::Close(void)
*/
pFile->fLength = fOpenEOF;
pFile->fSparseLength = pFile->fLength;
pFile->fLengthInSectors = (unsigned short) fOpenSectorsUsed;
pFile->fLengthInSectors = (uint16_t) fOpenSectorsUsed;
/*
* Update the sector count in the directory entry.
@ -3384,13 +3327,12 @@ bail:
/*
* Return the #of sectors/blocks in the file.
*/
long
A2FDDOS::GetSectorCount(void) const
long A2FDDOS::GetSectorCount(void) const
{
return fTSCount;
}
long
A2FDDOS::GetBlockCount(void) const
long A2FDDOS::GetBlockCount(void) const
{
return (fTSCount+1)/2;
}
@ -3400,8 +3342,7 @@ A2FDDOS::GetBlockCount(void) const
*
* Returns (0,0) for a sparse sector.
*/
DIError
A2FDDOS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
DIError A2FDDOS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
{
if (sectorIdx < 0 || sectorIdx >= fTSCount)
return kDIErrInvalidIndex;
@ -3415,8 +3356,7 @@ A2FDDOS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
* in 512-byte blocks, we're reduced to finding storage at (tsIndex*2) and
* converting it to a block number.
*/
DIError
A2FDDOS::GetStorage(long blockIdx, long* pBlock) const
DIError A2FDDOS::GetStorage(long blockIdx, long* pBlock) const
{
long sectorIdx = blockIdx * 2;
if (sectorIdx < 0 || sectorIdx >= fTSCount)
@ -3433,8 +3373,7 @@ A2FDDOS::GetStorage(long blockIdx, long* pBlock) const
/*
* Dump the T/S list for an open file.
*/
void
A2FDDOS::DumpTSList(void) const
void A2FDDOS::DumpTSList(void) const
{
//A2FileDOS* pFile = (A2FileDOS*) fpFile;
LOGI(" DOS T/S list for '%s' (count=%d)",

View File

@ -18,7 +18,7 @@ namespace DiskImgLib {
* Obtained from tracks 0-2 of a newly-formatted disk created
* by "INIT HELLO" after booting the DOS 3.3 system master.
*/
/*static*/ const unsigned char DiskFSDOS33::gDOS33Tracks[16 * 3 * 256] = {
/*static*/ const uint8_t DiskFSDOS33::gDOS33Tracks[16 * 3 * 256] = {
0x01, 0xa5, 0x27, 0xc9, 0x09, 0xd0, 0x18, 0xa5,
0x2b, 0x4a, 0x4a, 0x4a, 0x4a, 0x09, 0xc0, 0x85,
0x3f, 0xa9, 0x5c, 0x85, 0x3e, 0x18, 0xad, 0xfe,
@ -1612,7 +1612,7 @@ namespace DiskImgLib {
* Obtained from the DOS 3.2.1 system master. The last two sectors of
* track 2 were unreadable, and have been zeroed out here.
*/
/*static*/ const unsigned char DiskFSDOS33::gDOS32Tracks[13 * 3 * 256] = {
/*static*/ const uint8_t DiskFSDOS33::gDOS32Tracks[13 * 3 * 256] = {
0xf0, 0x4a, 0x99, 0xff, 0xff, 0x03, 0x3c, 0xad,
0xff, 0xff, 0xff, 0x26, 0xb3, 0xff, 0xff, 0x4d,
0x4a, 0x10, 0xff, 0xff, 0x3d, 0x4a, 0xca, 0xff,
@ -2901,5 +2901,4 @@ namespace DiskImgLib {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}; // namespace DiskImgLib
} // namespace DiskImgLib

View File

@ -21,8 +21,7 @@
*
* Refuse to "improve" the quality level of a file.
*/
void
A2File::SetQuality(FileQuality quality)
void A2File::SetQuality(FileQuality quality)
{
if (quality == kQualityGood &&
(fFileQuality == kQualitySuspicious || fFileQuality == kQualityDamaged))
@ -41,8 +40,7 @@ A2File::SetQuality(FileQuality quality)
/*
* Reset the quality level after making repairs.
*/
void
A2File::ResetQuality(void)
void A2File::ResetQuality(void)
{
fFileQuality = kQualityGood;
}
@ -59,8 +57,7 @@ A2File::ResetQuality(void)
* so that it can be sure there are no DiskFS objects left dangling when the
* DiskImg is deleted.
*/
void
DiskFS::SetDiskImg(DiskImg* pImg)
void DiskFS::SetDiskImg(DiskImg* pImg)
{
if (pImg == NULL && fpImg == NULL) {
LOGI("SetDiskImg: no-op (both NULL)");
@ -80,8 +77,7 @@ DiskFS::SetDiskImg(DiskImg* pImg)
/*
* Flush changes to disk.
*/
DIError
DiskFS::Flush(DiskImg::FlushMode mode)
DIError DiskFS::Flush(DiskImg::FlushMode mode)
{
SubVolume* pSubVol = GetNextSubVolume(NULL);
DIError dierr;
@ -106,8 +102,7 @@ DiskFS::Flush(DiskImg::FlushMode mode)
/*
* Set the "read only" flag on our DiskImg and those of our sub-volumes.
*/
void
DiskFS::SetAllReadOnly(bool val)
void DiskFS::SetAllReadOnly(bool val)
{
SubVolume* pSubVol = GetNextSubVolume(NULL);
@ -161,8 +156,7 @@ DiskFS::SetAllReadOnly(bool val)
/*
* Add a file to the end of our list.
*/
void
DiskFS::AddFileToList(A2File* pFile)
void DiskFS::AddFileToList(A2File* pFile)
{
assert(pFile->GetNext() == NULL);
@ -193,8 +187,7 @@ DiskFS::AddFileToList(A2File* pFile)
* but odds are that there isn't a "next" entry if we're busily creating
* files.)
*/
void
DiskFS::InsertFileInList(A2File* pFile, A2File* pPrev)
void DiskFS::InsertFileInList(A2File* pFile, A2File* pPrev)
{
assert(pFile->GetNext() == NULL);
@ -228,8 +221,7 @@ DiskFS::InsertFileInList(A2File* pFile, A2File* pPrev)
*
* The return value is the very last entry in the subdir.
*/
A2File*
DiskFS::SkipSubdir(A2File* pSubdir)
A2File* DiskFS::SkipSubdir(A2File* pSubdir)
{
if (pSubdir->GetNext() == NULL)
return pSubdir; // end of list reached -- subdir is empty
@ -262,8 +254,7 @@ DiskFS::SkipSubdir(A2File* pSubdir)
*
* We're currently singly-linked, making this rather expensive.
*/
void
DiskFS::DeleteFileFromList(A2File* pFile)
void DiskFS::DeleteFileFromList(A2File* pFile)
{
if (fpA2Head == pFile) {
/* delete the head of the list */
@ -296,8 +287,7 @@ DiskFS::DeleteFileFromList(A2File* pFile)
* Because we apparently can't declare an anonymous class as a friend
* in MSVC++6.0, this can't be an inline function.
*/
A2File*
DiskFS::GetNextFile(A2File* pFile) const
A2File* DiskFS::GetNextFile(A2File* pFile) const
{
if (pFile == NULL)
return fpA2Head;
@ -311,8 +301,7 @@ DiskFS::GetNextFile(A2File* pFile) const
* Right now the only code that calls this is the disk info panel in
* CiderPress, so we don't need it to be efficient.
*/
long
DiskFS::GetFileCount(void) const
long DiskFS::GetFileCount(void) const
{
long count = 0;
@ -328,8 +317,7 @@ DiskFS::GetFileCount(void) const
/*
* Delete all entries in the list.
*/
void
DiskFS::DeleteFileList(void)
void DiskFS::DeleteFileList(void)
{
A2File* pFile;
A2File* pNext;
@ -345,8 +333,7 @@ DiskFS::DeleteFileList(void)
/*
* Dump file list.
*/
void
DiskFS::DumpFileList(void)
void DiskFS::DumpFileList(void)
{
A2File* pFile;
@ -367,8 +354,7 @@ DiskFS::DumpFileList(void)
* e.g. by prepending the sub-volume's volume name to the filename. May
* be best to let the application dig for the sub-volume.
*/
A2File*
DiskFS::GetFileByName(const char* fileName, StringCompareFunc func)
A2File* DiskFS::GetFileByName(const char* fileName, StringCompareFunc func)
{
A2File* pFile;
@ -395,8 +381,7 @@ DiskFS::GetFileByName(const char* fileName, StringCompareFunc func)
*
* Note this happens AFTER the disk has been scanned.
*/
void
DiskFS::AddSubVolumeToList(DiskImg* pDiskImg, DiskFS* pDiskFS)
void DiskFS::AddSubVolumeToList(DiskImg* pDiskImg, DiskFS* pDiskFS)
{
SubVolume* pSubVol;
@ -458,8 +443,7 @@ DiskFS::AddSubVolumeToList(DiskImg* pDiskImg, DiskFS* pDiskFS)
/*
* Copy parameters to a sub-volume.
*/
void
DiskFS::CopyInheritables(DiskFS* pNewFS)
void DiskFS::CopyInheritables(DiskFS* pNewFS)
{
for (int i = 0; i < (int) NELEM(fParmTable); i++)
pNewFS->fParmTable[i] = fParmTable[i];
@ -481,8 +465,7 @@ DiskFS::CopyInheritables(DiskFS* pNewFS)
* Because we apparently can't declare an anonymous class as a friend
* in MSVC++6.0, this can't be an inline function.
*/
DiskFS::SubVolume*
DiskFS::GetNextSubVolume(const SubVolume* pSubVol) const
DiskFS::SubVolume* DiskFS::GetNextSubVolume(const SubVolume* pSubVol) const
{
if (pSubVol == NULL)
return fpSubVolumeHead;
@ -493,8 +476,7 @@ DiskFS::GetNextSubVolume(const SubVolume* pSubVol) const
/*
* Delete all entries in the list.
*/
void
DiskFS::DeleteSubVolumeList(void)
void DiskFS::DeleteSubVolumeList(void)
{
SubVolume* pSubVol;
SubVolume* pNext;
@ -511,8 +493,7 @@ DiskFS::DeleteSubVolumeList(void)
/*
* Get a parameter.
*/
long
DiskFS::GetParameter(DiskFSParameter parm)
long DiskFS::GetParameter(DiskFSParameter parm)
{
assert(parm > kParmUnknown && parm < kParmMax);
return fParmTable[parm];
@ -523,8 +504,7 @@ DiskFS::GetParameter(DiskFSParameter parm)
*
* The setting propagates to all sub-volumes.
*/
void
DiskFS::SetParameter(DiskFSParameter parm, long val)
void DiskFS::SetParameter(DiskFSParameter parm, long val)
{
assert(parm > kParmUnknown && parm < kParmMax);
fParmTable[parm] = val;
@ -540,8 +520,7 @@ DiskFS::SetParameter(DiskFSParameter parm, long val)
/*
* Scan for damaged or suspicious files.
*/
void
DiskFS::ScanForDamagedFiles(bool* pDamaged, bool* pSuspicious)
void DiskFS::ScanForDamagedFiles(bool* pDamaged, bool* pSuspicious)
{
A2File* pFile;

View File

@ -270,8 +270,7 @@ DiskImg::~DiskImg(void)
/*
* Set the nibble descr pointer.
*/
void
DiskImg::SetNibbleDescr(int idx)
void DiskImg::SetNibbleDescr(int idx)
{
assert(idx >= 0 && idx < kNibbleDescrMAX);
fpNibbleDescr = &fpNibbleDescrTable[idx];
@ -280,8 +279,7 @@ DiskImg::SetNibbleDescr(int idx)
/*
* Set up a custom nibble descriptor.
*/
void
DiskImg::SetCustomNibbleDescr(const NibbleDescr* pDescr)
void DiskImg::SetCustomNibbleDescr(const NibbleDescr* pDescr)
{
if (pDescr == NULL) {
fpNibbleDescr = NULL;
@ -301,8 +299,7 @@ DiskImg::SetCustomNibbleDescr(const NibbleDescr* pDescr)
* For Windows, we need to handle logical/physical volumes specially. If
* the filename matches the appropriate pattern, use a different GFD.
*/
DIError
DiskImg::OpenImage(const char* pathName, char fssep, bool readOnly)
DIError DiskImg::OpenImage(const char* pathName, char fssep, bool readOnly)
{
DIError dierr = kDIErrNone;
bool isWinDevice = false;
@ -393,11 +390,10 @@ DIError DiskImg::OpenImageFromBufferRW(uint8_t* buffer, long length) {
* Open from a buffer, which could point to unadorned ready-to-go content
* or to a preloaded image file.
*/
DIError
DiskImg::OpenImageFromBuffer(uint8_t* buffer, long length, bool readOnly)
DIError DiskImg::OpenImageFromBuffer(uint8_t* buffer, long length, bool readOnly)
{
if (fpDataGFD != NULL) {
LOGI(" DI already open!");
LOGW(" DI already open!");
return kDIErrAlreadyOpen;
}
LOGI(" DI OpenImage %08lx %ld ro=%d", (long) buffer, length, readOnly);
@ -440,13 +436,12 @@ DiskImg::OpenImageFromBuffer(uint8_t* buffer, long length, bool readOnly)
* ProDOS-ordered blocks, so it works out okay, but the "linear" requirement
* above goes beyond just having contiguous blocks.
*/
DIError
DiskImg::OpenImage(DiskImg* pParent, long firstBlock, long numBlocks)
DIError DiskImg::OpenImage(DiskImg* pParent, long firstBlock, long numBlocks)
{
LOGI(" DI OpenImage parent=0x%08lx %ld %ld", (long) pParent, firstBlock,
numBlocks);
if (fpDataGFD != NULL) {
LOGI(" DI already open!");
LOGI(" DW already open!");
return kDIErrAlreadyOpen;
}
@ -487,14 +482,14 @@ DiskImg::OpenImage(DiskImg* pParent, long firstBlock, long numBlocks)
return dierr;
}
DIError
DiskImg::OpenImage(DiskImg* pParent, long firstTrack, long firstSector,
DIError DiskImg::OpenImage(DiskImg* pParent, long firstTrack, long firstSector,
long numSectors)
{
LOGI(" DI OpenImage parent=0x%08lx %ld %ld %ld", (long) pParent,
firstTrack, firstSector, numSectors);
if (fpDataGFD != NULL) {
LOGI(" DI already open!");
LOGW(" DI already open!");
return kDIErrAlreadyOpen;
}
@ -547,8 +542,7 @@ DiskImg::OpenImage(DiskImg* pParent, long firstTrack, long firstSector,
/*
* Enable sector pairing. Useful for OzDOS.
*/
void
DiskImg::SetPairedSectors(bool enable, int idx)
void DiskImg::SetPairedSectors(bool enable, int idx)
{
fSectorPairing = enable;
fSectorPairOffset = idx;
@ -571,8 +565,7 @@ DiskImg::SetPairedSectors(bool enable, int idx)
* image creation instead of completing it. That's a higher-level decision
* though. ++ATM 20040506 ]
*/
DIError
DiskImg::CloseImage(void)
DIError DiskImg::CloseImage(void)
{
DIError dierr;
@ -580,7 +573,7 @@ DiskImg::CloseImage(void)
/* check for DiskFS objects that still point to us */
if (fDiskFSRefCnt != 0) {
LOGI("ERROR: CloseImage: fDiskFSRefCnt=%d", fDiskFSRefCnt);
LOGE("ERROR: CloseImage: fDiskFSRefCnt=%d", fDiskFSRefCnt);
assert(false); //DebugBreak();
}
@ -640,8 +633,7 @@ DiskImg::CloseImage(void)
* changed" to "what's in the file and what's in memory differ". I want it
* to be a "dirty" flag.
*/
DIError
DiskImg::FlushImage(FlushMode mode)
DIError DiskImg::FlushImage(FlushMode mode)
{
DIError dierr = kDIErrNone;
@ -726,7 +718,6 @@ DiskImg::FlushImage(FlushMode mode)
}
/*
* Given the filename extension and a GFD, figure out what's inside.
*
@ -773,8 +764,7 @@ DiskImg::FlushImage(FlushMode mode)
* This may set fReadOnly if one of the wrappers looks okay but is reporting
* a bad checksum.
*/
DIError
DiskImg::AnalyzeImageFile(const char* pathName, char fssep)
DIError DiskImg::AnalyzeImageFile(const char* pathName, char fssep)
{
DIError dierr = kDIErrNone;
FileFormat probableFormat;
@ -800,7 +790,7 @@ DiskImg::AnalyzeImageFile(const char* pathName, char fssep)
fLength = -1;
dierr = fpWrapperGFD->Seek(0, kSeekEnd);
if (dierr != kDIErrNone) {
LOGI(" DI Couldn't seek to end of wrapperGFD");
LOGW(" DI Couldn't seek to end of wrapperGFD");
goto bail;
}
fWrappedLength = fOuterLength = fpWrapperGFD->Tell();
@ -878,7 +868,7 @@ DiskImg::AnalyzeImageFile(const char* pathName, char fssep)
dierr = fpOuterWrapper->Load(fpWrapperGFD, fOuterLength, fReadOnly,
&fWrappedLength, &pNewGFD);
if (dierr != kDIErrNone) {
LOGI(" DI outer prep failed");
LOGI(" DW outer prep failed");
/* extensions are "reliable", so failure is unavoidable */
goto bail;
}
@ -1161,8 +1151,7 @@ bail:
* fFileSysOrder is set
* fpNibbleDescr will be set for nibble images
*/
DIError
DiskImg::AnalyzeImage(void)
DIError DiskImg::AnalyzeImage(void)
{
assert(fLength >= 0);
assert(fpDataGFD != NULL);
@ -1329,8 +1318,7 @@ DiskImg::AnalyzeImage(void)
*
* Sets fFormat, fOrder, and fFileSysOrder.
*/
void
DiskImg::AnalyzeImageFS(void)
void DiskImg::AnalyzeImageFS(void)
{
/*
* In some circumstances it would be useful to have a set describing
@ -1438,8 +1426,7 @@ DiskImg::AnalyzeImageFS(void)
* structure, the "unadorned" format should be specified, and the contents
* identified by the PhysicalFormat.
*/
DIError
DiskImg::OverrideFormat(PhysicalFormat physical, FSFormat format,
DIError DiskImg::OverrideFormat(PhysicalFormat physical, FSFormat format,
SectorOrder order)
{
DIError dierr = kDIErrNone;
@ -1568,8 +1555,7 @@ bail:
* NOTE: this table is redundant with some knowledge embedded in the
* individual "TestFS" functions.
*/
DiskImg::SectorOrder
DiskImg::CalcFSSectorOrder(void) const
DiskImg::SectorOrder DiskImg::CalcFSSectorOrder(void) const
{
/* in the absence of information, just leave it alone */
if (fFormat == kFormatUnknown || fOrder == kSectorOrderUnknown) {
@ -1624,8 +1610,7 @@ DiskImg::CalcFSSectorOrder(void) const
* Based on the disk format, figure out if we should prefer blocks or
* sectors when examining disk contents.
*/
bool
DiskImg::ShowAsBlocks(void) const
bool DiskImg::ShowAsBlocks(void) const
{
if (!fHasBlocks)
return false;
@ -1678,8 +1663,7 @@ DiskImg::ShowAsBlocks(void) const
* Format an image with the requested fileystem format. This only works if
* the matching DiskFS supports formatting of disks.
*/
DIError
DiskImg::FormatImage(FSFormat format, const char* volName)
DIError DiskImg::FormatImage(FSFormat format, const char* volName)
{
DIError dierr = kDIErrNone;
DiskFS* pDiskFS = NULL;
@ -1724,11 +1708,10 @@ bail:
* optimized path that just writes to the GFD or something. Maybe even just
* a "ZeroBlock" instead of "WriteBlock" so we can memset instead of memcpy?
*/
DIError
DiskImg::ZeroImage(void)
DIError DiskImg::ZeroImage(void)
{
DIError dierr = kDIErrNone;
unsigned char blkBuf[kBlockSize];
uint8_t blkBuf[kBlockSize];
long block;
LOGI(" DI ZeroImage (%ld blocks)", GetNumBlocks());
@ -1749,8 +1732,7 @@ DiskImg::ZeroImage(void)
*
* We want to use the same function for our sub-volumes too.
*/
void
DiskImg::SetScanProgressCallback(ScanProgressCallback func, void* cookie)
void DiskImg::SetScanProgressCallback(ScanProgressCallback func, void* cookie)
{
if (fpParentImg != NULL) {
/* unexpected, but perfectly okay */
@ -1768,8 +1750,7 @@ DiskImg::SetScanProgressCallback(ScanProgressCallback func, void* cookie)
* Update the progress. Call with a string at the start of a volume, then
* call with a NULL pointer every time we add a file.
*/
bool
DiskImg::UpdateScanProgress(const char* newStr)
bool DiskImg::UpdateScanProgress(const char* newStr)
{
ScanProgressCallback func = fpScanProgressCallback;
DiskImg* pImg = this;
@ -1815,8 +1796,7 @@ DiskImg::UpdateScanProgress(const char* newStr)
/*
* Handle sector order conversions.
*/
DIError
DiskImg::CalcSectorAndOffset(long track, int sector, SectorOrder imageOrder,
DIError DiskImg::CalcSectorAndOffset(long track, int sector, SectorOrder imageOrder,
SectorOrder fsOrder, di_off_t* pOffset, int* pNewSector)
{
if (!fHasSectors)
@ -1967,8 +1947,7 @@ DiskImg::CalcSectorAndOffset(long track, int sector, SectorOrder imageOrder,
* The "imageOrder" argument usually comes from fOrder, and "fsOrder"
* comes from "fFileSysOrder".
*/
inline bool
DiskImg::IsLinearBlocks(SectorOrder imageOrder, SectorOrder fsOrder)
inline bool DiskImg::IsLinearBlocks(SectorOrder imageOrder, SectorOrder fsOrder)
{
/*
* Any time fOrder==fFileSysOrder, we know that we have a linear
@ -1987,8 +1966,7 @@ DiskImg::IsLinearBlocks(SectorOrder imageOrder, SectorOrder fsOrder)
*
* Returns 0 on success, nonzero on failure.
*/
DIError
DiskImg::ReadTrackSectorSwapped(long track, int sector, void* buf,
DIError DiskImg::ReadTrackSectorSwapped(long track, int sector, void* buf,
SectorOrder imageOrder, SectorOrder fsOrder)
{
DIError dierr;
@ -2041,8 +2019,7 @@ DiskImg::ReadTrackSectorSwapped(long track, int sector, void* buf,
*
* Returns 0 on success, nonzero on failure.
*/
DIError
DiskImg::WriteTrackSector(long track, int sector, const void* buf)
DIError DiskImg::WriteTrackSector(long track, int sector, const void* buf)
{
DIError dierr;
di_off_t offset;
@ -2093,8 +2070,7 @@ DiskImg::WriteTrackSector(long track, int sector, const void* buf)
*
* Copies 512 bytes into "*buf".
*/
DIError
DiskImg::ReadBlockSwapped(long block, void* buf, SectorOrder imageOrder,
DIError DiskImg::ReadBlockSwapped(long block, void* buf, SectorOrder imageOrder,
SectorOrder fsOrder)
{
if (!fHasBlocks)
@ -2146,8 +2122,7 @@ bail:
* probably not contain data from all readable sectors. The application is
* expected to retry the blocks individually.
*/
DIError
DiskImg::ReadBlocks(long startBlock, int numBlocks, void* buf)
DIError DiskImg::ReadBlocks(long startBlock, int numBlocks, void* buf)
{
DIError dierr = kDIErrNone;
@ -2182,7 +2157,7 @@ DiskImg::ReadBlocks(long startBlock, int numBlocks, void* buf)
if (dierr != kDIErrNone)
goto bail;
startBlock++;
buf = (unsigned char*)buf + kBlockSize;
buf = (uint8_t*)buf + kBlockSize;
}
} else {
if (startBlock == 0) {
@ -2204,8 +2179,7 @@ bail:
*
* Returns "true" if we found bad blocks, "false" if not.
*/
bool
DiskImg::CheckForBadBlocks(long startBlock, int numBlocks)
bool DiskImg::CheckForBadBlocks(long startBlock, int numBlocks)
{
int i;
@ -2225,8 +2199,7 @@ DiskImg::CheckForBadBlocks(long startBlock, int numBlocks)
* Returns immediately when a block write fails. Does not try to write all
* blocks before returning failure.
*/
DIError
DiskImg::WriteBlock(long block, const void* buf)
DIError DiskImg::WriteBlock(long block, const void* buf)
{
if (!fHasBlocks)
return kDIErrUnsupportedAccess;
@ -2265,8 +2238,7 @@ DiskImg::WriteBlock(long block, const void* buf)
/*
* Write multiple blocks.
*/
DIError
DiskImg::WriteBlocks(long startBlock, int numBlocks, const void* buf)
DIError DiskImg::WriteBlocks(long startBlock, int numBlocks, const void* buf)
{
DIError dierr = kDIErrNone;
@ -2295,7 +2267,7 @@ DiskImg::WriteBlocks(long startBlock, int numBlocks, const void* buf)
if (dierr != kDIErrNone)
goto bail;
startBlock++;
buf = (unsigned char*)buf + kBlockSize;
buf = (uint8_t*)buf + kBlockSize;
}
} else {
if (startBlock == 0) {
@ -2315,8 +2287,7 @@ bail:
*
* (This is the lowest-level read routine in this class.)
*/
DIError
DiskImg::CopyBytesOut(void* buf, di_off_t offset, int size) const
DIError DiskImg::CopyBytesOut(void* buf, di_off_t offset, int size) const
{
DIError dierr;
@ -2343,8 +2314,7 @@ DiskImg::CopyBytesOut(void* buf, di_off_t offset, int size) const
*
* (This is the lowest-level write routine in DiskImg.)
*/
DIError
DiskImg::CopyBytesIn(const void* buf, di_off_t offset, int size)
DIError DiskImg::CopyBytesIn(const void* buf, di_off_t offset, int size)
{
DIError dierr;
@ -2389,8 +2359,7 @@ DiskImg::CopyBytesIn(const void* buf, di_off_t offset, int size)
*
* "storageName" and "pNibbleDescr" may be NULL.
*/
DIError
DiskImg::CreateImage(const char* pathName, const char* storageName,
DIError DiskImg::CreateImage(const char* pathName, const char* storageName,
OuterFormat outerFormat, FileFormat fileFormat, PhysicalFormat physical,
const NibbleDescr* pNibbleDescr, SectorOrder order,
FSFormat format, long numBlocks, bool skipFormat)
@ -2415,8 +2384,8 @@ DiskImg::CreateImage(const char* pathName, const char* storageName,
return CreateImageCommon(pathName, storageName, skipFormat);
}
DIError
DiskImg::CreateImage(const char* pathName, const char* storageName,
DIError DiskImg::CreateImage(const char* pathName, const char* storageName,
OuterFormat outerFormat, FileFormat fileFormat, PhysicalFormat physical,
const NibbleDescr* pNibbleDescr, SectorOrder order,
FSFormat format, long numTracks, long numSectPerTrack, bool skipFormat)
@ -2458,8 +2427,7 @@ DiskImg::CreateImage(const char* pathName, const char* storageName,
/*
* Do the actual disk image creation.
*/
DIError
DiskImg::CreateImageCommon(const char* pathName, const char* storageName,
DIError DiskImg::CreateImageCommon(const char* pathName, const char* storageName,
bool skipFormat)
{
DIError dierr;
@ -2722,8 +2690,7 @@ bail:
* to call AnalyzeImage later on to set the actual FS once data has
* been written.
*/
DIError
DiskImg::ValidateCreateFormat(void) const
DIError DiskImg::ValidateCreateFormat(void) const
{
/*
* Check for invalid arguments.
@ -2916,8 +2883,7 @@ DiskImg::ValidateCreateFormat(void) const
* If "quickFormat" is set, only the very last sector is written (to set
* the EOF on the file).
*/
DIError
DiskImg::FormatSectors(GenericFD* pGFD, bool quickFormat) const
DIError DiskImg::FormatSectors(GenericFD* pGFD, bool quickFormat) const
{
DIError dierr = kDIErrNone;
char sctBuf[kSectorSize];
@ -3010,8 +2976,7 @@ DiskImg::FormatBlocks(GenericFD* pGFD) const
*
* The maximum length of a single note is set by the size of "buf".
*/
void
DiskImg::AddNote(NoteType type, const char* fmt, ...)
void DiskImg::AddNote(NoteType type, const char* fmt, ...)
{
char buf[512];
char* cp = buf;
@ -3055,12 +3020,12 @@ DiskImg::AddNote(NoteType type, const char* fmt, ...)
len++;
}
LOGI("+++ adding note '%s'", buf);
LOGD("+++ adding note '%s'", buf);
if (fNotes == NULL) {
fNotes = new char[len +1];
if (fNotes == NULL) {
LOGI("Unable to create notes[%d]", len+1);
LOGW("Unable to create notes[%d]", len+1);
assert(false);
return;
}
@ -3069,7 +3034,7 @@ DiskImg::AddNote(NoteType type, const char* fmt, ...)
int existingLen = strlen(fNotes);
char* newNotes = new char[existingLen + len +1];
if (newNotes == NULL) {
LOGI("Unable to create newNotes[%d]", existingLen+len+1);
LOGW("Unable to create newNotes[%d]", existingLen+len+1);
assert(false);
return;
}
@ -3083,8 +3048,7 @@ DiskImg::AddNote(NoteType type, const char* fmt, ...)
/*
* Return a string with the notes in it.
*/
const char*
DiskImg::GetNotes(void) const
const char* DiskImg::GetNotes(void) const
{
if (fNotes == NULL)
return "";
@ -3097,14 +3061,13 @@ DiskImg::GetNotes(void) const
* Get length and offset of tracks in a nibble image. This is necessary
* because of formats with variable-length tracks (e.g. TrackStar).
*/
int
DiskImg::GetNibbleTrackLength(long track) const
int DiskImg::GetNibbleTrackLength(long track) const
{
assert(fpImageWrapper != NULL);
return fpImageWrapper->GetNibbleTrackLength(fPhysical, track);
}
int
DiskImg::GetNibbleTrackOffset(long track) const
int DiskImg::GetNibbleTrackOffset(long track) const
{
assert(fpImageWrapper != NULL);
return fpImageWrapper->GetNibbleTrackOffset(fPhysical, track);
@ -3121,8 +3084,7 @@ DiskImg::GetNibbleTrackOffset(long track) const
* This doesn't inspire the DiskFS to do any processing, just creates the
* new object.
*/
DiskFS*
DiskImg::OpenAppropriateDiskFS(bool allowUnknown)
DiskFS* DiskImg::OpenAppropriateDiskFS(bool allowUnknown)
{
DiskFS* pDiskFS = NULL;
@ -3203,8 +3165,8 @@ DiskImg::OpenAppropriateDiskFS(bool allowUnknown)
*
* "orderArray" must have kSectorOrderMax elements.
*/
/*static*/ void
DiskImg::GetSectorOrderArray(SectorOrder* orderArray, SectorOrder first)
/*static*/ void DiskImg::GetSectorOrderArray(SectorOrder* orderArray,
SectorOrder first)
{
// init array
for (int i = 0; i < kSectorOrderMax; i++)
@ -3226,9 +3188,8 @@ DiskImg::GetSectorOrderArray(SectorOrder* orderArray, SectorOrder first)
*
* These are semi-duplicated in ImageFormatDialog.cpp in CiderPress.
*/
/*static*/ const char*
DiskImg::ToStringCommon(int format, const ToStringLookup* pTable,
int tableSize)
/*static*/ const char* DiskImg::ToStringCommon(int format,
const ToStringLookup* pTable, int tableSize)
{
for (int i = 0; i < tableSize; i++) {
if (pTable[i].format == format)
@ -3239,8 +3200,7 @@ DiskImg::ToStringCommon(int format, const ToStringLookup* pTable,
return "(unknown)";
}
/*static*/ const char*
DiskImg::ToString(OuterFormat format)
/*static*/ const char* DiskImg::ToString(OuterFormat format)
{
static const ToStringLookup kOuterFormats[] = {
{ DiskImg::kOuterFormatUnknown, "Unknown format" },
@ -3253,8 +3213,8 @@ DiskImg::ToString(OuterFormat format)
return ToStringCommon(format, kOuterFormats, NELEM(kOuterFormats));
}
/*static*/ const char*
DiskImg::ToString(FileFormat format)
/*static*/ const char* DiskImg::ToString(FileFormat format)
{
static const ToStringLookup kFileFormats[] = {
{ DiskImg::kFileFormatUnknown, "Unknown format" },
@ -3273,8 +3233,8 @@ DiskImg::ToString(FileFormat format)
return ToStringCommon(format, kFileFormats, NELEM(kFileFormats));
};
/*static*/ const char*
DiskImg::ToString(PhysicalFormat format)
/*static*/ const char* DiskImg::ToString(PhysicalFormat format)
{
static const ToStringLookup kPhysicalFormats[] = {
{ DiskImg::kPhysicalFormatUnknown, "Unknown format" },
@ -3286,8 +3246,8 @@ DiskImg::ToString(PhysicalFormat format)
return ToStringCommon(format, kPhysicalFormats, NELEM(kPhysicalFormats));
};
/*static*/ const char*
DiskImg::ToString(SectorOrder format)
/*static*/ const char* DiskImg::ToString(SectorOrder format)
{
static const ToStringLookup kSectorOrders[] = {
{ DiskImg::kSectorOrderUnknown, "Unknown ordering" },
@ -3299,8 +3259,8 @@ DiskImg::ToString(SectorOrder format)
return ToStringCommon(format, kSectorOrders, NELEM(kSectorOrders));
};
/*static*/ const char*
DiskImg::ToString(FSFormat format)
/*static*/ const char* DiskImg::ToString(FSFormat format)
{
static const ToStringLookup kFSFormats[] = {
{ DiskImg::kFormatUnknown, "Unknown" },
@ -3337,8 +3297,7 @@ DiskImg::ToString(FSFormat format)
/*
* strerror() equivalent for DiskImg errors.
*/
const char*
DiskImgLib::DIStrError(DIError dierr)
const char* DiskImgLib::DIStrError(DIError dierr)
{
if (dierr > 0) {
const char* msg;
@ -3517,7 +3476,7 @@ DiskImgLib::DIStrError(DIError dierr)
* blurry PDF or a pair of GIFs created with small fonts, but I think I
* have mostly captured it.
*/
/*static*/ const unsigned char DiskImg::kMacHighASCII[128+1] =
/*static*/ const uint8_t DiskImg::kMacHighASCII[128+1] =
"AACENOUaaaaaaceeeeiiiinooooouuuu" // 0x80 - 0x9f
"tocL$oPBrct'.=AO%+<>YudsPpSaoOao" // 0xa0 - 0xbf
"?!-vf=d<>. AAOOo--\"\"''/oyY/o<> f" // 0xc0 - 0xdf

View File

@ -43,8 +43,8 @@
namespace DiskImgLib {
/* compiled-against versions; call DiskImg::GetVersion for linked-against */
#define kDiskImgVersionMajor 4
#define kDiskImgVersionMinor 6
#define kDiskImgVersionMajor 5
#define kDiskImgVersionMinor 0
#define kDiskImgVersionBug 0
@ -346,7 +346,7 @@ public:
kFormatMacPart = 44, // Macintosh-style partitioned disk
kFormatMicroDrive = 45, // ///SHH Systeme's MicroDrive format
kFormatFocusDrive = 46, // Parsons Engineering FocusDrive format
kFormatGutenberg = 47, // Gutenberg word processor format
kFormatGutenberg = 47, // Gutenberg word processor format
// try to keep this in an unsigned char, e.g. for CP clipboard
} FSFormat;
@ -379,16 +379,16 @@ public:
char description[32];
short numSectors; // 13 or 16 (or 18?)
unsigned char addrProlog[kNibbleAddrPrologLen];
unsigned char addrEpilog[kNibbleAddrEpilogLen];
unsigned char addrChecksumSeed;
uint8_t addrProlog[kNibbleAddrPrologLen];
uint8_t addrEpilog[kNibbleAddrEpilogLen];
uint8_t addrChecksumSeed;
bool addrVerifyChecksum;
bool addrVerifyTrack;
int addrEpilogVerifyCount;
unsigned char dataProlog[kNibbleDataPrologLen];
unsigned char dataEpilog[kNibbleDataEpilogLen];
unsigned char dataChecksumSeed;
uint8_t dataProlog[kNibbleDataPrologLen];
uint8_t dataEpilog[kNibbleDataEpilogLen];
uint8_t dataChecksumSeed;
bool dataVerifyChecksum;
int dataEpilogVerifyCount;
@ -522,10 +522,10 @@ public:
virtual DIError WriteBlocks(long startBlock, int numBlocks, const void* buf);
// read an entire nibblized track
virtual DIError ReadNibbleTrack(long track, unsigned char* buf,
virtual DIError ReadNibbleTrack(long track, uint8_t* buf,
long* pTrackLen);
// write a track; trackLen must be <= those in image
virtual DIError WriteNibbleTrack(long track, const unsigned char* buf,
virtual DIError WriteNibbleTrack(long track, const uint8_t* buf,
long trackLen);
// save the current image as a 2MG file
@ -632,8 +632,8 @@ public:
// calculate block number from cyl/head/sect on 3.5" disk
static int CylHeadSect35ToBlock(int cyl, int head, int sect);
// unpack nibble data from a 3.5" disk track
static DIError UnpackNibbleTrack35(const unsigned char* nibbleBuf,
long nibbleLen, unsigned char* outputBuf, int cyl, int head,
static DIError UnpackNibbleTrack35(const uint8_t* nibbleBuf,
long nibbleLen, uint8_t* outputBuf, int cyl, int head,
LinearBitmap* pBadBlockMap);
// compute the #of sectors per track for cylinder N (0-79)
static int SectorsPerTrack35(int cylinder);
@ -642,7 +642,7 @@ public:
static void GetSectorOrderArray(SectorOrder* orderArray, SectorOrder first);
// utility function used by HFS filename normalizer; available to apps
static inline unsigned char MacToASCII(unsigned char uch) {
static inline uint8_t MacToASCII(uint8_t uch) {
if (uch < 0x20)
return '?';
else if (uch < 0x80)
@ -722,7 +722,7 @@ private:
int fNumSectPerTrack; // (ditto)
long fNumBlocks; // for 512-byte block-addressable images
unsigned char* fNibbleTrackBuf; // allocated on heap
uint8_t* fNibbleTrackBuf; // allocated on heap
int fNibbleTrackLoaded; // track currently in buffer
int fNuFXCompressType; // used when compressing a NuFX image
@ -824,24 +824,24 @@ private:
int track, int sector, const NibbleDescr* pNibbleDescr, int* pVol);
void DecodeAddr(const CircularBufferAccess& buffer, int offset,
short* pVol, short* pTrack, short* pSector, short* pChksum);
inline unsigned int ConvFrom44(unsigned char val1, unsigned char val2) {
inline uint16_t ConvFrom44(uint8_t val1, uint8_t val2) {
return ((val1 << 1) | 0x01) & val2;
}
DIError DecodeNibbleData(const CircularBufferAccess& buffer, int idx,
unsigned char* sctBuf, const NibbleDescr* pNibbleDescr);
uint8_t* sctBuf, const NibbleDescr* pNibbleDescr);
void EncodeNibbleData(const CircularBufferAccess& buffer, int idx,
const unsigned char* sctBuf, const NibbleDescr* pNibbleDescr) const;
const uint8_t* sctBuf, const NibbleDescr* pNibbleDescr) const;
DIError DecodeNibble62(const CircularBufferAccess& buffer, int idx,
unsigned char* sctBuf, const NibbleDescr* pNibbleDescr);
uint8_t* sctBuf, const NibbleDescr* pNibbleDescr);
void EncodeNibble62(const CircularBufferAccess& buffer, int idx,
const unsigned char* sctBuf, const NibbleDescr* pNibbleDescr) const;
const uint8_t* sctBuf, const NibbleDescr* pNibbleDescr) const;
DIError DecodeNibble53(const CircularBufferAccess& buffer, int idx,
unsigned char* sctBuf, const NibbleDescr* pNibbleDescr);
uint8_t* sctBuf, const NibbleDescr* pNibbleDescr);
void EncodeNibble53(const CircularBufferAccess& buffer, int idx,
const unsigned char* sctBuf, const NibbleDescr* pNibbleDescr) const;
const uint8_t* sctBuf, const NibbleDescr* pNibbleDescr) const;
int TestNibbleTrack(int track, const NibbleDescr* pNibbleDescr, int* pVol);
DIError AnalyzeNibbleData(void);
inline unsigned char Conv44(unsigned short val, bool first) const {
inline uint8_t Conv44(uint16_t val, bool first) const {
if (first)
return (val >> 1) | 0xaa;
else
@ -849,7 +849,7 @@ private:
}
DIError FormatNibbles(GenericFD* pGFD) const;
static const unsigned char kMacHighASCII[];
static const uint8_t kMacHighASCII[];
/*
* 3.5" nibble access
@ -857,18 +857,18 @@ private:
static int FindNextSector35(const CircularBufferAccess& buffer, int start,
int cyl, int head, int* pSector);
static bool DecodeNibbleSector35(const CircularBufferAccess& buffer,
int start, unsigned char* sectorBuf, unsigned char* readChecksum,
unsigned char* calcChecksum);
int start, uint8_t* sectorBuf, uint8_t* readChecksum,
uint8_t* calcChecksum);
static bool UnpackChecksum35(const CircularBufferAccess& buffer,
int offset, unsigned char* checksumBuf);
static void EncodeNibbleSector35(const unsigned char* sectorData,
unsigned char* outBuf);
int offset, uint8_t* checksumBuf);
static void EncodeNibbleSector35(const uint8_t* sectorData,
uint8_t* outBuf);
/* static data tables */
static unsigned char kDiskBytes53[32];
static unsigned char kDiskBytes62[64];
static unsigned char kInvDiskBytes53[256];
static unsigned char kInvDiskBytes62[256];
static uint8_t kDiskBytes53[32];
static uint8_t kDiskBytes62[64];
static uint8_t kInvDiskBytes53[256];
static uint8_t kInvDiskBytes62[256];
enum { kInvInvalidValue = 0xff };
private: // some C++ stuff to block behavior we don't support
@ -1035,7 +1035,7 @@ public:
long fTotalChunks;
long fNumSectors; // only valid if !fByBlocks
//long fFreeChunks;
unsigned char* fList;
uint8_t* fList;
int fListSize;
}; // end of VolumeUsage class
@ -1661,6 +1661,6 @@ private:
void* fProgressUpdateState;
};
}; // namespace DiskImgLib
} // namespace DiskImgLib
#endif /*DISKIMG_DISKIMG_H*/

File diff suppressed because it is too large Load Diff

View File

@ -96,11 +96,11 @@ bool IsWin9x(void);
*/
class CircularBufferAccess {
public:
CircularBufferAccess(unsigned char* buf, long len) :
CircularBufferAccess(uint8_t* buf, long len) :
fBuf(buf), fLen(len)
{ assert(fLen > 0); assert(fBuf != NULL); }
CircularBufferAccess(const unsigned char* buf, long len) :
fBuf(const_cast<unsigned char*>(buf)), fLen(len)
CircularBufferAccess(const uint8_t* buf, long len) :
fBuf(const_cast<uint8_t*>(buf)), fLen(len)
{ assert(fLen > 0); assert(fBuf != NULL); }
~CircularBufferAccess(void) {}
@ -108,7 +108,7 @@ public:
* Be circular. Assume that we won't stray far past the end, so
* it's cheaper to subtract than mod.
*/
unsigned char& operator[](int idx) const {
uint8_t& operator[](int idx) const {
if (idx < 0) {
assert(false);
}
@ -117,7 +117,7 @@ public:
return fBuf[idx];
}
//unsigned char* GetPointer(int idx) const {
//uint8_t* GetPointer(int idx) const {
// while (idx >= fLen)
// idx -= fLen;
// return &fBuf[idx];
@ -134,8 +134,8 @@ public:
}
private:
unsigned char* fBuf;
long fLen;
uint8_t* fBuf;
long fLen;
};
/*
@ -152,7 +152,7 @@ private:
class BitOutputBuffer {
public:
/* pass in the output buffer and the output buffer's size */
BitOutputBuffer(unsigned char* buf, int size) {
BitOutputBuffer(uint8_t* buf, int size) {
fBufStart = fBuf = buf;
fBufSize = size;
fBitMask = 0x80;
@ -204,12 +204,12 @@ public:
}
private:
unsigned char* fBufStart;
unsigned char* fBuf;
int fBufSize;
unsigned char fBitMask;
unsigned char fByte;
bool fOverflow;
uint8_t* fBufStart;
uint8_t* fBuf;
int fBufSize;
uint8_t fBitMask;
uint8_t fByte;
bool fOverflow;
};
/*
@ -217,7 +217,7 @@ private:
*/
class BitInputBuffer {
public:
BitInputBuffer(const unsigned char* buf, int bitCount) {
BitInputBuffer(const uint8_t* buf, int bitCount) {
fBufStart = fBuf = buf;
fBitCount = bitCount;
fCurrentBit = 0;
@ -233,8 +233,8 @@ public:
* non-null, set "*pWrap". (This does *not* set it to "false" if we
* don't wrap.)
*/
unsigned char GetBit(bool* pWrap) {
unsigned char val;
uint8_t GetBit(bool* pWrap) {
uint8_t val;
//assert(fBitPosn == 7 - (fCurrentBit & 0x07));
@ -264,8 +264,8 @@ public:
/*
* Get the next 8 bits.
*/
unsigned char GetByte(bool* pWrap) {
unsigned char val;
uint8_t GetByte(bool* pWrap) {
uint8_t val;
int i;
if (true || fCurrentBit > fBitCount-8) {
@ -295,12 +295,12 @@ public:
int GetBitsConsumed(void) const { return fBitsConsumed; }
private:
const unsigned char* fBufStart;
const unsigned char* fBuf;
const uint8_t* fBufStart;
const uint8_t* fBuf;
int fBitCount; // #of bits in buffer
int fCurrentBit; // where we are in buffer
int fBitPosn; // which bit to access within byte
//unsigned char fByte;
//uint8_t fByte;
int fBitsConsumed; // sanity check - all bits used?
};
@ -312,7 +312,7 @@ class LinearBitmap {
public:
LinearBitmap(int numBits) {
assert(numBits > 0);
fBits = new unsigned char[(numBits + 7) / 8];
fBits = new uint8_t[(numBits + 7) / 8];
memset(fBits, 0, (numBits + 7) / 8);
fNumBits = numBits;
}
@ -333,12 +333,12 @@ public:
}
private:
unsigned char* fBits;
int fNumBits;
uint8_t* fBits;
int fNumBits;
};
} // namespace DiskImgLib
} // namespace DiskImgLib
/*
* Most of the code needs these.

View File

@ -22,23 +22,23 @@
const int kBlkSize = 512;
const long kBootBlock = 0;
const unsigned short kSignature = 0xaa55; // MBR or boot sector
const uint16_t kSignature = 0xaa55; // MBR or boot sector
const int kSignatureOffset = 0x1fe;
const unsigned char kOpcodeMumble = 0x33; // seen on 2nd drive
const unsigned char kOpcodeBranch = 0xeb;
const unsigned char kOpcodeSetInt = 0xfa;
const uint8_t kOpcodeMumble = 0x33; // seen on 2nd drive
const uint8_t kOpcodeBranch = 0xeb;
const uint8_t kOpcodeSetInt = 0xfa;
typedef struct PartitionTableEntry {
unsigned char driveNum; // dl (0x80 or 0x00)
unsigned char startHead; // dh
unsigned char startSector; // cl (&0x3f=sector, +two hi bits cyl)
unsigned char startCylinder; // ch (low 8 bits of 10-bit cylinder)
unsigned char type; // partition type
unsigned char endHead; // dh
unsigned char endSector; // cl
unsigned char endCylinder; // ch
unsigned long startLBA; // in blocks
unsigned long size; // in blocks
uint8_t driveNum; // dl (0x80 or 0x00)
uint8_t startHead; // dh
uint8_t startSector; // cl (&0x3f=sector, +two hi bits cyl)
uint8_t startCylinder; // ch (low 8 bits of 10-bit cylinder)
uint8_t type; // partition type
uint8_t endHead; // dh
uint8_t endSector; // cl
uint8_t endCylinder; // ch
uint32_t startLBA; // in blocks
uint32_t size; // in blocks
} PartitionTableEntry;
/*
@ -49,7 +49,7 @@ typedef struct DiskFSFAT::MasterBootRecord {
* Begins immediately with code, usually 0xfa (set interrupt flag) or
* 0xeb (relative branch).
*/
unsigned char firstByte;
uint8_t firstByte;
/*
* Partition table starts at 0x1be. Four entries, each 16 bytes.
@ -65,20 +65,20 @@ typedef struct DiskFSFAT::BootSector {
* The first few bytes of the boot sector is called the BIOS Parameter
* Block, or BPB.
*/
unsigned char jump[3]; // usually EB XX 90
unsigned char oemName[8]; // e.g. "MSWIN4.1" or "MSDOS5.0"
unsigned short bytesPerSector; // usually (always?) 512
unsigned char sectPerCluster;
unsigned short reservedSectors;
unsigned char numFAT;
unsigned short numRootDirEntries;
unsigned short numSectors; // if set, ignore numSectorsHuge
unsigned char mediaType;
unsigned short numFATSectors;
unsigned short sectorsPerTrack;
unsigned short numHeads;
unsigned long numHiddenSectors;
unsigned long numSectorsHuge; // only if numSectors==0
uint8_t jump[3]; // usually EB XX 90
uint8_t oemName[8]; // e.g. "MSWIN4.1" or "MSDOS5.0"
uint16_t bytesPerSector; // usually (always?) 512
uint8_t sectPerCluster;
uint16_t reservedSectors;
uint8_t numFAT;
uint16_t numRootDirEntries;
uint16_t numSectors; // if set, ignore numSectorsHuge
uint8_t mediaType;
uint16_t numFATSectors;
uint16_t sectorsPerTrack;
uint16_t numHeads;
uint32_t numHiddenSectors;
uint32_t numSectorsHuge; // only if numSectors==0
/*
* This next part can start immediately after the above (at 0x24) for
* FAT12/FAT16, or somewhat later (0x42) for FAT32. It doesn't seem
@ -88,12 +88,12 @@ typedef struct DiskFSFAT::BootSector {
* partition type, but if this is our block 0 then we can't know what
* that is.
*/
unsigned char driveNum;
unsigned char reserved;
unsigned char signature; // 0x29
unsigned long volumeID;
unsigned char volumeLabel[11]; // e.g. "FUBAR "
unsigned char fileSysType[8]; // e.g. "FAT12 "
uint8_t driveNum;
uint8_t reserved;
uint8_t signature; // 0x29
uint32_t volumeID;
uint8_t volumeLabel[11]; // e.g. "FUBAR "
uint8_t fileSysType[8]; // e.g. "FAT12 "
/*
* Code follows. Signature 0xaa55 in the last two bytes.
@ -114,10 +114,9 @@ enum MediaType {
*
* Returns "true" if this looks like an MBR, "false" otherwise.
*/
/*static*/ bool
DiskFSFAT::UnpackMBR(const unsigned char* buf, MasterBootRecord* pOut)
/*static*/ bool DiskFSFAT::UnpackMBR(const uint8_t* buf, MasterBootRecord* pOut)
{
const unsigned char* ptr;
const uint8_t* ptr;
int i;
pOut->firstByte = buf[0x00];
@ -160,8 +159,7 @@ DiskFSFAT::UnpackMBR(const unsigned char* buf, MasterBootRecord* pOut)
*
* Returns "true" if this looks like a boot sector, "false" otherwise.
*/
/*static*/ bool
DiskFSFAT::UnpackBootSector(const unsigned char* buf, BootSector* pOut)
/*static*/ bool DiskFSFAT::UnpackBootSector(const uint8_t* buf, BootSector* pOut)
{
memcpy(pOut->jump, &buf[0x00], sizeof(pOut->jump));
memcpy(pOut->oemName, &buf[0x03], sizeof(pOut->oemName));
@ -188,11 +186,10 @@ DiskFSFAT::UnpackBootSector(const unsigned char* buf, BootSector* pOut)
/*
* See if this looks like a FAT volume.
*/
/*static*/ DIError
DiskFSFAT::TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
/*static*/ DIError DiskFSFAT::TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
{
DIError dierr = kDIErrNone;
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
MasterBootRecord mbr;
BootSector bs;
@ -244,8 +241,7 @@ bail:
/*
* Test to see if the image is a FAT disk.
*/
/*static*/ DIError
DiskFSFAT::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSFAT::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
/* must be block format, should be at least 360K */
@ -275,8 +271,7 @@ DiskFSFAT::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*
* Get things rolling.
*/
DIError
DiskFSFAT::Initialize(void)
DIError DiskFSFAT::Initialize(void)
{
DIError dierr = kDIErrNone;
@ -297,8 +292,7 @@ DiskFSFAT::Initialize(void)
/*
* Blank out the volume usage map.
*/
void
DiskFSFAT::SetVolumeUsageMap(void)
void DiskFSFAT::SetVolumeUsageMap(void)
{
VolumeUsage::ChunkState cstate;
long block;
@ -317,8 +311,7 @@ DiskFSFAT::SetVolumeUsageMap(void)
/*
* Fill a buffer with some interesting stuff, and add it to the file list.
*/
void
DiskFSFAT::CreateFakeFile(void)
void DiskFSFAT::CreateFakeFile(void)
{
A2FileFAT* pFile;
char buf[768]; // currently running about 430
@ -340,7 +333,7 @@ DiskFSFAT::CreateFakeFile(void)
capacity = fTotalBlocks;
memset(buf, 0, sizeof(buf));
sprintf(buf, kFormatMsg,
snprintf(buf, NELEM(buf), kFormatMsg,
fVolumeName,
capacity,
(double) capacity / 2048.0);
@ -362,17 +355,15 @@ DiskFSFAT::CreateFakeFile(void)
/*
* Dump the contents of the A2File structure.
*/
void
A2FileFAT::Dump(void) const
void A2FileFAT::Dump(void) const
{
LOGI("A2FileFAT '%s'", fFileName);
LOGD("A2FileFAT '%s'", fFileName);
}
/*
* Not a whole lot to do.
*/
DIError
A2FileFAT::Open(A2FileDescr** ppOpenFile, bool readOnly,
DIError A2FileFAT::Open(A2FileDescr** ppOpenFile, bool readOnly,
bool rsrcFork /*=false*/)
{
A2FDFAT* pOpenFile = NULL;
@ -401,10 +392,9 @@ A2FileFAT::Open(A2FileDescr** ppOpenFile, bool readOnly,
/*
* Read a chunk of data from the fake file.
*/
DIError
A2FDFAT::Read(void* buf, size_t len, size_t* pActual)
DIError A2FDFAT::Read(void* buf, size_t len, size_t* pActual)
{
LOGI(" FAT reading %d bytes from '%s' (offset=%ld)",
LOGD(" FAT reading %d bytes from '%s' (offset=%ld)",
len, fpFile->GetPathName(), (long) fOffset);
A2FileFAT* pFile = (A2FileFAT*) fpFile;
@ -428,8 +418,7 @@ A2FDFAT::Read(void* buf, size_t len, size_t* pActual)
/*
* Write data at the current offset.
*/
DIError
A2FDFAT::Write(const void* buf, size_t len, size_t* pActual)
DIError A2FDFAT::Write(const void* buf, size_t len, size_t* pActual)
{
return kDIErrNotSupported;
}
@ -437,8 +426,7 @@ A2FDFAT::Write(const void* buf, size_t len, size_t* pActual)
/*
* Seek to a new offset.
*/
DIError
A2FDFAT::Seek(di_off_t offset, DIWhence whence)
DIError A2FDFAT::Seek(di_off_t offset, DIWhence whence)
{
di_off_t fileLen = ((A2FileFAT*) fpFile)->fLength;
@ -473,8 +461,7 @@ A2FDFAT::Seek(di_off_t offset, DIWhence whence)
/*
* Return current offset.
*/
di_off_t
A2FDFAT::Tell(void)
di_off_t A2FDFAT::Tell(void)
{
return fOffset;
}
@ -482,8 +469,7 @@ A2FDFAT::Tell(void)
/*
* Release file state, and tell our parent to destroy us.
*/
DIError
A2FDFAT::Close(void)
DIError A2FDFAT::Close(void)
{
fpFile->CloseDescr(this);
return kDIErrNone;
@ -492,14 +478,13 @@ A2FDFAT::Close(void)
/*
* Return the #of sectors/blocks in the file.
*/
long
A2FDFAT::GetSectorCount(void) const
long A2FDFAT::GetSectorCount(void) const
{
A2FileFAT* pFile = (A2FileFAT*) fpFile;
return (long) ((pFile->fLength+255) / 256);
}
long
A2FDFAT::GetBlockCount(void) const
long A2FDFAT::GetBlockCount(void) const
{
A2FileFAT* pFile = (A2FileFAT*) fpFile;
return (long) ((pFile->fLength+511) / 512);
@ -508,16 +493,15 @@ A2FDFAT::GetBlockCount(void) const
/*
* Return the Nth track/sector in this file.
*/
DIError
A2FDFAT::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
DIError A2FDFAT::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
{
return kDIErrNotSupported;
}
/*
* Return the Nth 512-byte block in this file.
*/
DIError
A2FDFAT::GetStorage(long blockIdx, long* pBlock) const
DIError A2FDFAT::GetStorage(long blockIdx, long* pBlock) const
{
return kDIErrNotSupported;
}

View File

@ -33,8 +33,7 @@
/*
* Pack a disk image with FDI.
*/
DIError
WrapperFDI::PackDisk(GenericFD* pSrcGFD, GenericFD* pWrapperGFD)
DIError WrapperFDI::PackDisk(GenericFD* pSrcGFD, GenericFD* pWrapperGFD)
{
DIError dierr = kDIErrGeneric; // not yet
return dierr;
@ -57,13 +56,12 @@ WrapperFDI::PackDisk(GenericFD* pSrcGFD, GenericFD* pWrapperGFD)
*
* Fills in "fNibbleTrackInfo".
*/
DIError
WrapperFDI::UnpackDisk525(GenericFD* pGFD, GenericFD* pNewGFD, int numCyls,
int numHeads)
DIError WrapperFDI::UnpackDisk525(GenericFD* pGFD, GenericFD* pNewGFD,
int numCyls, int numHeads)
{
DIError dierr = kDIErrNone;
unsigned char nibbleBuf[kNibbleBufLen];
unsigned char* inputBuf = NULL;
uint8_t nibbleBuf[kNibbleBufLen];
uint8_t* inputBuf = NULL;
bool goodTracks[kMaxNibbleTracks525];
int inputBufLen = -1;
int badTracks = 0;
@ -91,7 +89,7 @@ WrapperFDI::UnpackDisk525(GenericFD* pGFD, GenericFD* pNewGFD, int numCyls,
/* allocate or increase the size of the input buffer */
delete[] inputBuf;
inputBufLen = length256 * 256;
inputBuf = new unsigned char[inputBufLen];
inputBuf = new uint8_t[inputBufLen];
if (inputBuf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -223,14 +221,13 @@ bail:
* We also need to set up a "bad block" map to identify parts that we had
* trouble unpacking.
*/
DIError
WrapperFDI::UnpackDisk35(GenericFD* pGFD, GenericFD* pNewGFD, int numCyls,
DIError WrapperFDI::UnpackDisk35(GenericFD* pGFD, GenericFD* pNewGFD, int numCyls,
int numHeads, LinearBitmap* pBadBlockMap)
{
DIError dierr = kDIErrNone;
unsigned char nibbleBuf[kNibbleBufLen];
unsigned char* inputBuf = NULL;
unsigned char outputBuf[kMaxSectors35 * kBlockSize]; // 6KB
uint8_t nibbleBuf[kNibbleBufLen];
uint8_t* inputBuf = NULL;
uint8_t outputBuf[kMaxSectors35 * kBlockSize]; // 6KB
int inputBufLen = -1;
int badTracks = 0;
int trk, type, length256;
@ -258,7 +255,7 @@ WrapperFDI::UnpackDisk35(GenericFD* pGFD, GenericFD* pNewGFD, int numCyls,
/* allocate or increase the size of the input buffer */
delete[] inputBuf;
inputBufLen = length256 * 256;
inputBuf = new unsigned char[inputBufLen];
inputBuf = new uint8_t[inputBufLen];
if (inputBuf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -344,8 +341,7 @@ bail:
/*
* Return the approximate bit rate for the specified cylinder, in bits/sec.
*/
int
WrapperFDI::BitRate35(int cyl)
int WrapperFDI::BitRate35(int cyl)
{
if (cyl >= 0 && cyl <= 15)
return 375000; // 394rpm
@ -374,8 +370,7 @@ WrapperFDI::BitRate35(int cyl)
* (We could be more rigorous and test against valid disk bytes, but that's
* probably excessive.)
*/
void
WrapperFDI::FixBadNibbles(unsigned char* nibbleBuf, long nibbleLen)
void WrapperFDI::FixBadNibbles(uint8_t* nibbleBuf, long nibbleLen)
{
int badCount = 0;
@ -399,10 +394,9 @@ WrapperFDI::FixBadNibbles(unsigned char* nibbleBuf, long nibbleLen)
*
* Returns the track type and amount of data (/256).
*/
void
WrapperFDI::GetTrackInfo(int trk, int* pType, int* pLength256)
void WrapperFDI::GetTrackInfo(int trk, int* pType, int* pLength256)
{
unsigned short trackDescr;
uint16_t trackDescr;
trackDescr = fHeaderBuf[kTrackDescrOffset + trk * 2] << 8 |
fHeaderBuf[kTrackDescrOffset + trk * 2 +1];
@ -457,15 +451,14 @@ WrapperFDI::GetTrackInfo(int trk, int* pType, int* pLength256)
*
* Returns "true" on success, "false" on failure.
*/
bool
WrapperFDI::DecodePulseTrack(const unsigned char* inputBuf, long inputLen,
int bitRate, unsigned char* nibbleBuf, long* pNibbleLen)
bool WrapperFDI::DecodePulseTrack(const uint8_t* inputBuf, long inputLen,
int bitRate, uint8_t* nibbleBuf, long* pNibbleLen)
{
const int kSizeValueMask = 0x003fffff;
const int kSizeCompressMask = 0x00c00000;
const int kSizeCompressShift = 22;
PulseIndexHeader hdr;
unsigned long val;
uint32_t val;
bool result = false;
memset(&hdr, 0, sizeof(hdr));
@ -502,7 +495,7 @@ WrapperFDI::DecodePulseTrack(const unsigned char* inputBuf, long inputLen,
/*
* Uncompress or endian-swap the pulse streams.
*/
hdr.avgStream = new unsigned long[hdr.numPulses];
hdr.avgStream = new uint32_t[hdr.numPulses];
if (hdr.avgStream == NULL)
goto bail;
if (!UncompressPulseStream(inputBuf, hdr.avgStreamLen, hdr.avgStream,
@ -513,7 +506,7 @@ WrapperFDI::DecodePulseTrack(const unsigned char* inputBuf, long inputLen,
inputBuf += hdr.avgStreamLen;
if (hdr.minStreamLen > 0) {
hdr.minStream = new unsigned long[hdr.numPulses];
hdr.minStream = new uint32_t[hdr.numPulses];
if (hdr.minStream == NULL)
goto bail;
if (!UncompressPulseStream(inputBuf, hdr.minStreamLen, hdr.minStream,
@ -524,7 +517,7 @@ WrapperFDI::DecodePulseTrack(const unsigned char* inputBuf, long inputLen,
inputBuf += hdr.minStreamLen;
}
if (hdr.maxStreamLen > 0) {
hdr.maxStream = new unsigned long[hdr.numPulses];
hdr.maxStream = new uint32_t[hdr.numPulses];
if (!UncompressPulseStream(inputBuf, hdr.maxStreamLen, hdr.maxStream,
hdr.numPulses, hdr.maxStreamCompression, 4))
{
@ -533,7 +526,7 @@ WrapperFDI::DecodePulseTrack(const unsigned char* inputBuf, long inputLen,
inputBuf += hdr.maxStreamLen;
}
if (hdr.idxStreamLen > 0) {
hdr.idxStream = new unsigned long[hdr.numPulses];
hdr.idxStream = new uint32_t[hdr.numPulses];
if (!UncompressPulseStream(inputBuf, hdr.idxStreamLen, hdr.idxStream,
hdr.numPulses, hdr.idxStreamCompression, 2))
{
@ -575,9 +568,8 @@ bail:
* Returns "true" if all went well, "false" if we hit something that we
* couldn't handle.
*/
bool
WrapperFDI::UncompressPulseStream(const unsigned char* inputBuf, long inputLen,
unsigned long* outputBuf, long numPulses, int format, int bytesPerPulse)
bool WrapperFDI::UncompressPulseStream(const uint8_t* inputBuf, long inputLen,
uint32_t* outputBuf, long numPulses, int format, int bytesPerPulse)
{
assert(bytesPerPulse == 2 || bytesPerPulse == 4);
@ -590,7 +582,7 @@ WrapperFDI::UncompressPulseStream(const unsigned char* inputBuf, long inputLen,
if (format == kCompUncompressed) {
int i;
LOGI("NOT TESTED"); // remove this when we've tested it
LOGE("NOT TESTED"); // remove this when we've tested it
if (inputLen != numPulses * bytesPerPulse) {
LOGI(" FDI: got unc inputLen=%ld, outputLen=%ld",
@ -630,18 +622,17 @@ WrapperFDI::UncompressPulseStream(const unsigned char* inputBuf, long inputLen,
*
* This implementation is based on the fdi2raw code.
*/
bool
WrapperFDI::ExpandHuffman(const unsigned char* inputBuf, long inputLen,
unsigned long* outputBuf, long numPulses)
bool WrapperFDI::ExpandHuffman(const uint8_t* inputBuf, long inputLen,
uint32_t* outputBuf, long numPulses)
{
HuffNode root;
const unsigned char* origInputBuf = inputBuf;
const uint8_t* origInputBuf = inputBuf;
bool signExtend, sixteenBits;
int i, subStreamShift;
unsigned char bits;
unsigned char bitMask;
uint8_t bits;
uint8_t bitMask;
memset(outputBuf, 0, numPulses * sizeof(unsigned long));
memset(outputBuf, 0, numPulses * sizeof(uint32_t));
subStreamShift = 1;
while (subStreamShift != 0) {
@ -683,7 +674,7 @@ WrapperFDI::ExpandHuffman(const unsigned char* inputBuf, long inputLen,
/* decode the data over all pulses */
bitMask = 0;
for (i = 0; i < numPulses; i++) {
unsigned long outVal;
uint32_t outVal;
const HuffNode* pCurrent = &root;
/* chase down the tree until we hit a leaf */
@ -732,11 +723,10 @@ WrapperFDI::ExpandHuffman(const unsigned char* inputBuf, long inputLen,
/*
* Recursively extract the Huffman tree structure for this sub-stream.
*/
const unsigned char*
WrapperFDI::HuffExtractTree(const unsigned char* inputBuf, HuffNode* pNode,
unsigned char* pBits, unsigned char* pBitMask)
const uint8_t* WrapperFDI::HuffExtractTree(const uint8_t* inputBuf,
HuffNode* pNode, uint8_t* pBits, uint8_t* pBitMask)
{
unsigned char val;
uint8_t val;
if (*pBitMask == 0) {
*pBits = *inputBuf++;
@ -764,8 +754,8 @@ WrapperFDI::HuffExtractTree(const unsigned char* inputBuf, HuffNode* pNode,
/*
* Recursively get the 16-bit values for our Huffman tree from the stream.
*/
const unsigned char*
WrapperFDI::HuffExtractValues16(const unsigned char* inputBuf, HuffNode* pNode)
const uint8_t* WrapperFDI::HuffExtractValues16(const uint8_t* inputBuf,
HuffNode* pNode)
{
if (pNode->left == NULL) {
pNode->val = (*inputBuf++) << 8;
@ -780,8 +770,8 @@ WrapperFDI::HuffExtractValues16(const unsigned char* inputBuf, HuffNode* pNode)
/*
* Recursively get the 8-bit values for our Huffman tree from the stream.
*/
const unsigned char*
WrapperFDI::HuffExtractValues8(const unsigned char* inputBuf, HuffNode* pNode)
const uint8_t* WrapperFDI::HuffExtractValues8(const uint8_t* inputBuf,
HuffNode* pNode)
{
if (pNode->left == NULL) {
pNode->val = *inputBuf++;
@ -795,8 +785,7 @@ WrapperFDI::HuffExtractValues8(const unsigned char* inputBuf, HuffNode* pNode)
/*
* Recursively free up the current node and all nodes beneath it.
*/
void
WrapperFDI::HuffFreeNodes(HuffNode* pNode)
void WrapperFDI::HuffFreeNodes(HuffNode* pNode)
{
if (pNode != NULL) {
HuffFreeNodes(pNode->left);
@ -809,8 +798,7 @@ WrapperFDI::HuffFreeNodes(HuffNode* pNode)
/*
* Sign-extend a 16-bit value to 32 bits.
*/
unsigned long
WrapperFDI::HuffSignExtend16(unsigned long val)
uint32_t WrapperFDI::HuffSignExtend16(uint32_t val)
{
if (val & 0x8000)
val |= 0xffff0000;
@ -820,8 +808,7 @@ WrapperFDI::HuffSignExtend16(unsigned long val)
/*
* Sign-extend an 8-bit value to 32 bits.
*/
unsigned long
WrapperFDI::HuffSignExtend8(unsigned long val)
uint32_t WrapperFDI::HuffSignExtend8(uint32_t val)
{
if (val & 0x80)
val |= 0xffffff00;
@ -843,21 +830,20 @@ WrapperFDI::HuffSignExtend8(unsigned long val)
* "*pNibbleLen" should hold the maximum size of the buffer. On success,
* it will hold the actual number of bytes used.
*/
bool
WrapperFDI::ConvertPulseStreamsToNibbles(PulseIndexHeader* pHdr, int bitRate,
unsigned char* nibbleBuf, long* pNibbleLen)
bool WrapperFDI::ConvertPulseStreamsToNibbles(PulseIndexHeader* pHdr, int bitRate,
uint8_t* nibbleBuf, long* pNibbleLen)
{
unsigned long* fakeIdxStream = NULL;
uint32_t* fakeIdxStream = NULL;
bool result = false;
int i;
/*
* Stream pointers. If we don't have a stream, fake it.
*/
unsigned long* avgStream;
unsigned long* minStream;
unsigned long* maxStream;
unsigned long* idxStream;
uint32_t* avgStream;
uint32_t* minStream;
uint32_t* maxStream;
uint32_t* idxStream;
avgStream = pHdr->avgStream;
if (pHdr->minStream != NULL && pHdr->maxStream != NULL) {
@ -885,7 +871,7 @@ WrapperFDI::ConvertPulseStreamsToNibbles(PulseIndexHeader* pHdr, int bitRate,
*/
LOGI(" FDI: HEY: using fake index stream");
DebugBreak();
fakeIdxStream = new unsigned long[pHdr->numPulses];
fakeIdxStream = new uint32_t[pHdr->numPulses];
if (fakeIdxStream == NULL) {
LOGI(" FDI: unable to alloc fake idx stream");
goto bail;
@ -900,11 +886,11 @@ WrapperFDI::ConvertPulseStreamsToNibbles(PulseIndexHeader* pHdr, int bitRate,
/*
* Compute a value for maxIndex.
*/
unsigned long maxIndex;
uint32_t maxIndex;
maxIndex = 0;
for (i = 0; i < pHdr->numPulses; i++) {
unsigned long sum;
uint32_t sum;
/* add up the two single-byte values in the index stream */
sum = ZeroStateCount(idxStream[i]) + OneStateCount(idxStream[i]);
@ -946,7 +932,7 @@ WrapperFDI::ConvertPulseStreamsToNibbles(PulseIndexHeader* pHdr, int bitRate,
* Compute totalAvg and weakBits, and rewrite idxStream.
* (We don't actually use weakBits.)
*/
unsigned long totalAvg;
uint32_t totalAvg;
int weakBits;
totalAvg = weakBits = 0;
@ -968,7 +954,7 @@ WrapperFDI::ConvertPulseStreamsToNibbles(PulseIndexHeader* pHdr, int bitRate,
* Take our altered stream values and the stuff we've calculated,
* and convert the pulse values into bits.
*/
unsigned char bitBuffer[kBitBufferSize];
uint8_t bitBuffer[kBitBufferSize];
int bitCount;
bitCount = kBitBufferSize;
@ -1013,8 +999,8 @@ bail:
const int kPulseLimitVal = 15; /* "tolerance of 15%" */
typedef struct PulseSamples {
unsigned long size;
int numBits;
uint32_t size;
int numBits;
} PulseSamples;
class PulseSampleCollection {
@ -1041,7 +1027,7 @@ public:
assert(fTotalDiv != 0);
}
unsigned long GetTotal(void) const { return fTotal; }
uint32_t GetTotal(void) const { return fTotal; }
int GetTotalDiv(void) const { return fTotalDiv; }
void AdjustTotal(long val) { fTotal += val; }
@ -1063,7 +1049,7 @@ public:
private:
PulseSamples fArray[kSampleArrayMax];
int fArrayIndex;
unsigned long fTotal;
uint32_t fTotal;
int fTotalDiv;
};
@ -1080,8 +1066,7 @@ private:
*/
#undef RAND_MAX
#define RAND_MAX 32767
int
WrapperFDI::MyRand(void)
int WrapperFDI::MyRand(void)
{
const int kNumStates = 31;
const int kQuantum = RAND_MAX / (kNumStates+1);
@ -1108,18 +1093,17 @@ WrapperFDI::MyRand(void)
* This is a fairly direct conversion from the sample code. There's a lot
* here that I haven't taken the time to figure out.
*/
bool
WrapperFDI::ConvertPulsesToBits(const unsigned long* avgStream,
const unsigned long* minStream, const unsigned long* maxStream,
const unsigned long* idxStream, int numPulses, int maxIndex,
int indexOffset, unsigned long totalAvg, int bitRate,
unsigned char* outputBuf, int* pOutputLen)
bool WrapperFDI::ConvertPulsesToBits(const uint32_t* avgStream,
const uint32_t* minStream, const uint32_t* maxStream,
const uint32_t* idxStream, int numPulses, int maxIndex,
int indexOffset, uint32_t totalAvg, int bitRate,
uint8_t* outputBuf, int* pOutputLen)
{
PulseSampleCollection samples;
BitOutputBuffer bitOutput(outputBuf, *pOutputLen);
/* magic numbers, from somewhere */
const unsigned long kStdMFM2BitCellSize = (totalAvg * 5) / bitRate;
const unsigned long kStdMFM8BitCellSize = (totalAvg * 20) / bitRate;
const uint32_t kStdMFM2BitCellSize = (totalAvg * 5) / bitRate;
const uint32_t kStdMFM8BitCellSize = (totalAvg * 20) / bitRate;
int mfmMagic = 0; // if set to 1, decode as MFM rather than GCR
bool result = false;
int i;
@ -1134,15 +1118,15 @@ WrapperFDI::ConvertPulsesToBits(const unsigned long* avgStream,
*/
i = 1;
while (i < numPulses &&
(idxStream[i] < (unsigned long) maxIndex ||
idxStream[i-1] < (unsigned long) maxIndex ||
(idxStream[i] < (uint32_t) maxIndex ||
idxStream[i-1] < (uint32_t) maxIndex ||
minStream[i] < (kStdMFM2BitCellSize - (kStdMFM2BitCellSize / 4))
))
{
i++;
}
if (i == numPulses) {
LOGI(" FDI: no stable and long-enough pulse in track");
LOGW(" FDI: no stable and long-enough pulse in track");
goto bail;
}
@ -1150,7 +1134,7 @@ WrapperFDI::ConvertPulsesToBits(const unsigned long* avgStream,
* Set up some variables.
*/
int nextI, endOfData, adjust, bitOffset, step;
unsigned long refPulse;
uint32_t refPulse;
long jitter;
samples.Create(kStdMFM2BitCellSize, 1 + mfmMagic);
@ -1174,7 +1158,7 @@ WrapperFDI::ConvertPulsesToBits(const unsigned long* avgStream,
* Calculates the current average bit rate from previously
* decoded data.
*/
unsigned long avgSize;
uint32_t avgSize;
int kCell8Limit = (kPulseLimitVal * kStdMFM8BitCellSize) / 100;
/* this is the new average size for one MFM bit */
@ -1195,11 +1179,11 @@ WrapperFDI::ConvertPulsesToBits(const unsigned long* avgStream,
/*
* Get the next long-enough pulse (may require more than one pulse).
*/
unsigned long pulse;
uint32_t pulse;
pulse = 0;
while (pulse < ((avgSize / 4) - (avgSize / 16))) {
unsigned long avgPulse, minPulse, maxPulse;
uint32_t avgPulse, minPulse, maxPulse;
/* advance i */
i++;
@ -1212,10 +1196,10 @@ WrapperFDI::ConvertPulsesToBits(const unsigned long* avgStream,
nextI++;
if (nextI >= numPulses)
nextI = 0;
} while (idxStream[nextI] < (unsigned long) maxIndex);
} while (idxStream[nextI] < (uint32_t) maxIndex);
}
if (idxStream[i] >= (unsigned long) maxIndex) {
if (idxStream[i] >= (uint32_t) maxIndex) {
/* stable pulse */
avgPulse = avgStream[i] - jitter;
minPulse = minStream[i];
@ -1279,7 +1263,7 @@ WrapperFDI::ConvertPulsesToBits(const unsigned long* avgStream,
*/
if (i == endOfData)
step++;
} else if ((unsigned long) rand() <= (idxStream[i] * RAND_MAX) / maxIndex) {
} else if ((uint32_t) rand() <= (idxStream[i] * RAND_MAX) / maxIndex) {
/* futz with it */
int randVal;
@ -1324,7 +1308,7 @@ WrapperFDI::ConvertPulsesToBits(const unsigned long* avgStream,
* "realSize" will end up holding the number of bits we're going
* to output for this pulse.
*/
unsigned long adjustedPulse;
uint32_t adjustedPulse;
int realSize;
adjustedPulse = pulse;
@ -1448,7 +1432,6 @@ bail:
}
/*
* Convert a stream of GCR bits into nibbles.
*
@ -1463,15 +1446,14 @@ bail:
* "*pNibbleLen" should hold the maximum size of the buffer. On success,
* it will hold the actual number of bytes used.
*/
bool
WrapperFDI::ConvertBitsToNibbles(const unsigned char* bitBuffer, int bitCount,
unsigned char* nibbleBuf, long* pNibbleLen)
bool WrapperFDI::ConvertBitsToNibbles(const uint8_t* bitBuffer, int bitCount,
uint8_t* nibbleBuf, long* pNibbleLen)
{
BitInputBuffer inputBuffer(bitBuffer, bitCount);
const unsigned char* nibbleBufStart = nibbleBuf;
const uint8_t* nibbleBufStart = nibbleBuf;
long outputBufSize = *pNibbleLen;
bool result = false;
unsigned char val;
uint8_t val;
bool wrap;
/*
@ -1508,11 +1490,11 @@ WrapperFDI::ConvertBitsToNibbles(const unsigned char* bitBuffer, int bitCount,
if ((val & 0x80) == 0)
val = (val << 1) | inputBuffer.GetBit(&wrap);
if ((val & 0x80) == 0) {
LOGI(" FDI: WARNING: more than 2 consecutive zeroes (read)");
LOGW(" FDI: WARNING: more than 2 consecutive zeroes (read)");
}
if (nibbleBuf - nibbleBufStart >= outputBufSize) {
LOGI(" FDI: bits overflowed nibble buffer");
LOGW(" FDI: bits overflowed nibble buffer");
goto bail;
}
*nibbleBuf++ = val;
@ -1524,7 +1506,7 @@ WrapperFDI::ConvertBitsToNibbles(const unsigned char* bitBuffer, int bitCount,
if (inputBuffer.GetBitsConsumed() != bitCount) {
/* we dropped some or double-counted some */
LOGI(" FDI: WARNING: consumed %d of %d bits",
LOGW(" FDI: WARNING: consumed %d of %d bits",
inputBuffer.GetBitsConsumed(), bitCount);
}
@ -1538,4 +1520,3 @@ WrapperFDI::ConvertBitsToNibbles(const unsigned char* bitBuffer, int bitCount,
bail:
return result;
}

View File

@ -28,16 +28,16 @@ const int kSignatureLen = 14;
* We also make space here for the partition names, which live on blocks 1+2.
*/
typedef struct DiskFSFocusDrive::PartitionMap {
unsigned char signature[kSignatureLen];
unsigned char unknown1;
unsigned char partCount; // could be ushort, combined w/unknown1
unsigned char unknown2[16];
uint8_t signature[kSignatureLen];
uint8_t unknown1;
uint8_t partCount; // could be ushort, combined w/unknown1
uint8_t unknown2[16];
struct Entry {
unsigned long startBlock;
unsigned long blockCount;
unsigned long unknown1;
unsigned long unknown2;
unsigned char name[kPartNameLen+1];
uint32_t startBlock;
uint32_t blockCount;
uint32_t unknown1;
uint32_t unknown2;
uint8_t name[kPartNameLen+1];
} entry[kMaxPartitions];
} PartitionMap;
@ -48,11 +48,11 @@ typedef struct DiskFSFocusDrive::PartitionMap {
* The "imageOrder" parameter has no use here, because (in the current
* version) embedded parent volumes are implicitly ProDOS-ordered.
*/
/*static*/ DIError
DiskFSFocusDrive::TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
/*static*/ DIError DiskFSFocusDrive::TestImage(DiskImg* pImg,
DiskImg::SectorOrder imageOrder)
{
DIError dierr = kDIErrNone;
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
int partCount;
/*
@ -83,16 +83,14 @@ bail:
return dierr;
}
/*
* Unpack a partition map block into a partition map data structure.
*/
/*static*/ void
DiskFSFocusDrive::UnpackPartitionMap(const unsigned char* buf,
const unsigned char* nameBuf, PartitionMap* pMap)
/*static*/ void DiskFSFocusDrive::UnpackPartitionMap(const uint8_t* buf,
const uint8_t* nameBuf, PartitionMap* pMap)
{
const unsigned char* ptr;
const unsigned char* namePtr;
const uint8_t* ptr;
const uint8_t* namePtr;
int i;
memcpy(pMap->signature, &buf[0x00], kSignatureLen);
@ -121,8 +119,7 @@ DiskFSFocusDrive::UnpackPartitionMap(const unsigned char* buf,
/*
* Debug: dump the contents of the partition map.
*/
/*static*/ void
DiskFSFocusDrive::DumpPartitionMap(const PartitionMap* pMap)
/*static*/ void DiskFSFocusDrive::DumpPartitionMap(const PartitionMap* pMap)
{
int i;
@ -133,12 +130,10 @@ DiskFSFocusDrive::DumpPartitionMap(const PartitionMap* pMap)
}
}
/*
* Open up a sub-volume.
*/
DIError
DiskFSFocusDrive::OpenSubVolume(long startBlock, long numBlocks,
DIError DiskFSFocusDrive::OpenSubVolume(long startBlock, long numBlocks,
const char* name)
{
DIError dierr = kDIErrNone;
@ -248,8 +243,7 @@ bail:
/*
* Check to see if this is a FocusDrive volume.
*/
/*static*/ DIError
DiskFSFocusDrive::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSFocusDrive::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
if (pImg->GetNumBlocks() < kMinInterestingBlocks)
@ -272,8 +266,7 @@ DiskFSFocusDrive::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*
* Prep the FocusDrive "container" for use.
*/
DIError
DiskFSFocusDrive::Initialize(void)
DIError DiskFSFocusDrive::Initialize(void)
{
DIError dierr = kDIErrNone;
@ -296,12 +289,11 @@ DiskFSFocusDrive::Initialize(void)
/*
* Find the various sub-volumes and open them.
*/
DIError
DiskFSFocusDrive::FindSubVolumes(void)
DIError DiskFSFocusDrive::FindSubVolumes(void)
{
DIError dierr = kDIErrNone;
unsigned char buf[kBlkSize];
unsigned char nameBuf[kBlkSize*2];
uint8_t buf[kBlkSize];
uint8_t nameBuf[kBlkSize*2];
PartitionMap map;
int i;
@ -332,8 +324,7 @@ bail:
* Open the volume. If it fails, open a placeholder instead. (If *that*
* fails, return with an error.)
*/
DIError
DiskFSFocusDrive::OpenVol(int idx, long startBlock, long numBlocks,
DIError DiskFSFocusDrive::OpenVol(int idx, long startBlock, long numBlocks,
const char* name)
{
DIError dierr;

View File

@ -22,23 +22,22 @@
* If "pCRC" is non-NULL, this computes a CRC32 as it goes, using the zlib
* library function.
*/
/*static*/ DIError
GenericFD::CopyFile(GenericFD* pDst, GenericFD* pSrc, di_off_t length,
unsigned long* pCRC)
/*static*/ DIError GenericFD::CopyFile(GenericFD* pDst, GenericFD* pSrc,
di_off_t length, uint32_t* pCRC)
{
DIError dierr = kDIErrNone;
const int kCopyBufSize = 32768;
unsigned char* copyBuf = NULL;
uint8_t* copyBuf = NULL;
int copySize;
LOGI("+++ CopyFile: %ld bytes", (long) length);
LOGD("+++ CopyFile: %ld bytes", (long) length);
if (pDst == NULL || pSrc == NULL || length < 0)
return kDIErrInvalidArg;
if (length == 0)
return kDIErrNone;
copyBuf = new unsigned char[kCopyBufSize];
copyBuf = new uint8_t[kCopyBufSize];
if (copyBuf == NULL)
return kDIErrMalloc;
@ -86,11 +85,13 @@ bail:
* an off_t, so we can continue to use the FILE* functions there. Under
* Windows "lseek" takes a long, so we have to use their specific 64-bit
* variant.
*
* TODO: Visual Studio 2005 added _fseeki64. We should be able to merge
* the bulk of the implementation now.
*/
#ifdef HAVE_FSEEKO
DIError
GFDFile::Open(const char* filename, bool readOnly)
DIError GFDFile::Open(const char* filename, bool readOnly)
{
DIError dierr = kDIErrNone;
@ -119,8 +120,7 @@ GFDFile::Open(const char* filename, bool readOnly)
return dierr;
}
DIError
GFDFile::Read(void* buf, size_t length, size_t* pActual)
DIError GFDFile::Read(void* buf, size_t length, size_t* pActual)
{
DIError dierr = kDIErrNone;
size_t actual;
@ -152,8 +152,7 @@ GFDFile::Read(void* buf, size_t length, size_t* pActual)
return dierr;
}
DIError
GFDFile::Write(const void* buf, size_t length, size_t* pActual)
DIError GFDFile::Write(const void* buf, size_t length, size_t* pActual)
{
DIError dierr = kDIErrNone;
@ -170,8 +169,7 @@ GFDFile::Write(const void* buf, size_t length, size_t* pActual)
return dierr;
}
DIError
GFDFile::Seek(di_off_t offset, DIWhence whence)
DIError GFDFile::Seek(di_off_t offset, DIWhence whence)
{
DIError dierr = kDIErrNone;
//static const long kOneGB = 1024*1024*1024;
@ -189,8 +187,7 @@ GFDFile::Seek(di_off_t offset, DIWhence whence)
return dierr;
}
di_off_t
GFDFile::Tell(void)
di_off_t GFDFile::Tell(void)
{
DIError dierr = kDIErrNone;
di_off_t result;
@ -207,8 +204,7 @@ GFDFile::Tell(void)
return result;
}
DIError
GFDFile::Truncate(void)
DIError GFDFile::Truncate(void)
{
#if defined(HAVE_FTRUNCATE)
int cc;
@ -227,8 +223,7 @@ GFDFile::Truncate(void)
return kDIErrNone;
}
DIError
GFDFile::Close(void)
DIError GFDFile::Close(void)
{
if (fFp == NULL)
return kDIErrNotReady;
@ -241,8 +236,7 @@ GFDFile::Close(void)
#else /*HAVE_FSEEKO*/
DIError
GFDFile::Open(const char* filename, bool readOnly)
DIError GFDFile::Open(const char* filename, bool readOnly)
{
DIError dierr = kDIErrNone;
@ -271,8 +265,7 @@ GFDFile::Open(const char* filename, bool readOnly)
return dierr;
}
DIError
GFDFile::Read(void* buf, size_t length, size_t* pActual)
DIError GFDFile::Read(void* buf, size_t length, size_t* pActual)
{
DIError dierr;
ssize_t actual;
@ -301,8 +294,7 @@ GFDFile::Read(void* buf, size_t length, size_t* pActual)
return kDIErrNone;
}
DIError
GFDFile::Write(const void* buf, size_t length, size_t* pActual)
DIError GFDFile::Write(const void* buf, size_t length, size_t* pActual)
{
DIError dierr;
ssize_t actual;
@ -322,8 +314,7 @@ GFDFile::Write(const void* buf, size_t length, size_t* pActual)
return kDIErrNone;
}
DIError
GFDFile::Seek(di_off_t offset, DIWhence whence)
DIError GFDFile::Seek(di_off_t offset, DIWhence whence)
{
DIError dierr = kDIErrNone;
if (fFd < 0)
@ -340,16 +331,15 @@ GFDFile::Seek(di_off_t offset, DIWhence whence)
#endif
if (newPosn == kFailure) {
assert((unsigned long) offset != 0xccccccccUL); // uninitialized data!
assert((uint32_t) offset != 0xccccccccUL); // uninitialized data!
dierr = ErrnoOrGeneric();
LOGI(" GDFile Seek %ld-%lu failed (err=%d)",
(long) (offset >> 32), (unsigned long) offset, dierr);
(long) (offset >> 32), (uint32_t) offset, dierr);
}
return dierr;
}
di_off_t
GFDFile::Tell(void)
di_off_t GFDFile::Tell(void)
{
DIError dierr = kDIErrNone;
di_off_t result;
@ -371,8 +361,7 @@ GFDFile::Tell(void)
return result;
}
DIError
GFDFile::Truncate(void)
DIError GFDFile::Truncate(void)
{
#if defined(HAVE_FTRUNCATE)
int cc;
@ -390,8 +379,7 @@ GFDFile::Truncate(void)
return kDIErrNone;
}
DIError
GFDFile::Close(void)
DIError GFDFile::Close(void)
{
if (fFd < 0)
return kDIErrNotReady;
@ -410,9 +398,8 @@ GFDFile::Close(void)
* ===========================================================================
*/
DIError
GFDBuffer::Open(void* buffer, di_off_t length, bool doDelete, bool doExpand,
bool readOnly)
DIError GFDBuffer::Open(void* buffer, di_off_t length, bool doDelete,
bool doExpand, bool readOnly)
{
if (fBuffer != NULL)
return kDIErrAlreadyOpen;
@ -444,8 +431,7 @@ GFDBuffer::Open(void* buffer, di_off_t length, bool doDelete, bool doExpand,
return kDIErrNone;
}
DIError
GFDBuffer::Read(void* buf, size_t length, size_t* pActual)
DIError GFDBuffer::Read(void* buf, size_t length, size_t* pActual)
{
if (fBuffer == NULL)
return kDIErrNotReady;
@ -476,8 +462,7 @@ GFDBuffer::Read(void* buf, size_t length, size_t* pActual)
return kDIErrNone;
}
DIError
GFDBuffer::Write(const void* buf, size_t length, size_t* pActual)
DIError GFDBuffer::Write(const void* buf, size_t length, size_t* pActual)
{
if (fBuffer == NULL)
return kDIErrNotReady;
@ -527,8 +512,7 @@ GFDBuffer::Write(const void* buf, size_t length, size_t* pActual)
return kDIErrNone;
}
DIError
GFDBuffer::Seek(di_off_t offset, DIWhence whence)
DIError GFDBuffer::Seek(di_off_t offset, DIWhence whence)
{
if (fBuffer == NULL)
return kDIErrNotReady;
@ -561,16 +545,14 @@ GFDBuffer::Seek(di_off_t offset, DIWhence whence)
return kDIErrNone;
}
di_off_t
GFDBuffer::Tell(void)
di_off_t GFDBuffer::Tell(void)
{
if (fBuffer == NULL)
return (di_off_t) -1;
return fCurrentOffset;
}
DIError
GFDBuffer::Close(void)
DIError GFDBuffer::Close(void)
{
if (fBuffer == NULL)
return kDIErrNone;
@ -609,12 +591,11 @@ GFDBuffer::Close(void)
* must have the form "N:\" for a logical volume or "80:\" for a physical
* volume.
*/
DIError
GFDWinVolume::Open(const char* deviceName, bool readOnly)
DIError GFDWinVolume::Open(const char* deviceName, bool readOnly)
{
DIError dierr = kDIErrNone;
HANDLE handle = NULL;
//unsigned long kTwoGBBlocks;
//uint32_t kTwoGBBlocks;
if (fVolAccess.Ready())
return kDIErrAlreadyOpen;
@ -643,7 +624,7 @@ GFDWinVolume::Open(const char* deviceName, bool readOnly)
assert(fBlockSize > 0);
//kTwoGBBlocks = kTwoGB / fBlockSize;
unsigned long totalBlocks;
long totalBlocks;
totalBlocks = fVolAccess.GetTotalBlocks();
fVolumeEOF = (di_off_t)totalBlocks * fBlockSize;
@ -655,11 +636,10 @@ bail:
return dierr;
}
DIError
GFDWinVolume::Read(void* buf, size_t length, size_t* pActual)
DIError GFDWinVolume::Read(void* buf, size_t length, size_t* pActual)
{
DIError dierr = kDIErrNone;
unsigned char* blkBuf = NULL;
uint8_t* blkBuf = NULL;
//LOGI(" GFDWinVolume: reading %ld bytes from offset %ld", length,
// fCurrentOffset);
@ -680,7 +660,7 @@ GFDWinVolume::Read(void* buf, size_t length, size_t* pActual)
long advanceLen = length;
blkBuf = new unsigned char[fBlockSize]; // get this off the heap??
blkBuf = new uint8_t[fBlockSize]; // get this off the heap??
long blockIndex = (long) (fCurrentOffset / fBlockSize);
int bufOffset = (int) (fCurrentOffset % fBlockSize); // req power of 2
assert(blockIndex >= 0);
@ -739,11 +719,10 @@ bail:
return dierr;
}
DIError
GFDWinVolume::Write(const void* buf, size_t length, size_t* pActual)
DIError GFDWinVolume::Write(const void* buf, size_t length, size_t* pActual)
{
DIError dierr = kDIErrNone;
unsigned char* blkBuf = NULL;
uint8_t* blkBuf = NULL;
//LOGI(" GFDWinVolume: writing %ld bytes at offset %ld", length,
// fCurrentOffset);
@ -766,7 +745,7 @@ GFDWinVolume::Write(const void* buf, size_t length, size_t* pActual)
long advanceLen = length;
blkBuf = new unsigned char[fBlockSize]; // get this out of the heap??
blkBuf = new uint8_t[fBlockSize]; // get this out of the heap??
long blockIndex = (long) (fCurrentOffset / fBlockSize);
int bufOffset = (int) (fCurrentOffset % fBlockSize); // req power of 2
assert(blockIndex >= 0);
@ -829,8 +808,7 @@ bail:
return dierr;
}
DIError
GFDWinVolume::Seek(di_off_t offset, DIWhence whence)
DIError GFDWinVolume::Seek(di_off_t offset, DIWhence whence)
{
if (!fVolAccess.Ready())
return kDIErrNotReady;
@ -863,16 +841,14 @@ GFDWinVolume::Seek(di_off_t offset, DIWhence whence)
return kDIErrNone;
}
di_off_t
GFDWinVolume::Tell(void)
di_off_t GFDWinVolume::Tell(void)
{
if (!fVolAccess.Ready())
return (di_off_t) -1;
return fCurrentOffset;
}
DIError
GFDWinVolume::Close(void)
DIError GFDWinVolume::Close(void)
{
if (!fVolAccess.Ready())
return kDIErrNotReady;

View File

@ -133,7 +133,7 @@ public:
* be seeked to their initial positions. "length" bytes will be copied.
*/
static DIError CopyFile(GenericFD* pDst, GenericFD* pSrc, di_off_t length,
unsigned long* pCRC = NULL);
uint32_t* pCRC = NULL);
protected:
GenericFD& operator=(const GenericFD&);

View File

@ -21,8 +21,7 @@ const char* DiskImgLib::kASPIDev = "ASPI:";
/*
* Perform one-time DLL initialization.
*/
/*static*/ DIError
Global::AppInit(void)
/*static*/ DIError Global::AppInit(void)
{
NuError nerr;
long major, minor, bug;
@ -89,8 +88,7 @@ Global::AppInit(void)
/*
* Perform cleanup at application shutdown time.
*/
/*static*/ DIError
Global::AppCleanup(void)
/*static*/ DIError Global::AppCleanup(void)
{
LOGI("DiskImgLib cleanup");
delete fpASPI;
@ -125,8 +123,7 @@ Global::AppCleanup(void)
/*
* Return current library versions.
*/
/*static*/ void
Global::GetVersion(long* pMajor, long* pMinor, long* pBug)
/*static*/ void Global::GetVersion(long* pMajor, long* pMinor, long* pBug)
{
if (pMajor != NULL)
*pMajor = kDiskImgVersionMajor;
@ -145,8 +142,7 @@ Global::GetVersion(long* pMajor, long* pMinor, long* pBug)
/*
* Change the debug message handler. The previous handler is returned.
*/
Global::DebugMsgHandler
Global::SetDebugMsgHandler(DebugMsgHandler handler)
Global::DebugMsgHandler Global::SetDebugMsgHandler(DebugMsgHandler handler)
{
DebugMsgHandler oldHandler;
@ -161,8 +157,7 @@ Global::SetDebugMsgHandler(DebugMsgHandler handler)
* Even if _DEBUG_MSGS is disabled we can still get here from the NuFX error
* handler.
*/
/*static*/ void
Global::PrintDebugMsg(const char* file, int line, const char* fmt, ...)
/*static*/ void Global::PrintDebugMsg(const char* file, int line, const char* fmt, ...)
{
if (gDebugMsgHandler == NULL) {
/*

View File

@ -35,8 +35,7 @@ const int kMaxTSIterations = 32;
/*
* Get a pointer to the Nth entry in a catalog sector.
*/
static inline unsigned char*
GetCatalogEntryPtr(unsigned char* basePtr, int entryNum)
static inline uint8_t* GetCatalogEntryPtr(uint8_t* basePtr, int entryNum)
{
assert(entryNum >= 0 && entryNum < kCatalogEntriesPerSect);
return basePtr + kCatalogEntryOffset + entryNum * kCatalogEntrySize;
@ -47,11 +46,11 @@ GetCatalogEntryPtr(unsigned char* basePtr, int entryNum)
* Test this image for Gutenberg-ness.
*
*/
static DIError
TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder, int* pGoodCount)
static DIError TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder,
int* pGoodCount)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
// int numTracks, numSectors;
int catTrack = kVTOCTrack;
int catSect = kVTOCSector;
@ -106,8 +105,7 @@ bail:
/*
* Test to see if the image is a Gutenberg word processor data disk.
*/
/*static*/ DIError
DiskFSGutenberg::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSGutenberg::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
if (pImg->GetNumTracks() > kMaxInterestingTracks)
@ -155,8 +153,7 @@ DiskFSGutenberg::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
* on out must be handled somehow, possibly by claiming that the disk is
* completely full and has no files on it.
*/
DIError
DiskFSGutenberg::Initialize(InitMode initMode)
DIError DiskFSGutenberg::Initialize(InitMode initMode)
{
DIError dierr = kDIErrNone;
@ -185,8 +182,7 @@ bail:
/*
* Get the amount of free space remaining.
*/
DIError
DiskFSGutenberg::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
DIError DiskFSGutenberg::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
int* pUnitSize) const
{
*pTotalUnits = fpImg->GetNumTracks() * fpImg->GetNumSectPerTrack();
@ -195,16 +191,13 @@ DiskFSGutenberg::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
return kDIErrNone;
}
/*
* Read the disk's catalog.
*
*/
DIError
DiskFSGutenberg::ReadCatalog(void)
DIError DiskFSGutenberg::ReadCatalog(void)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
int catTrack, catSect;
int iterations;
@ -222,7 +215,7 @@ DiskFSGutenberg::ReadCatalog(void)
goto bail;
memcpy(fDiskVolumeName, &sctBuf[6], kMaxVolNameLen); // Copy out the volume name; it should be the same on all catalog sectors.
fDiskVolumeName[kMaxVolNameLen] = 0x00;
DiskFSGutenberg::LowerASCII((unsigned char*)fDiskVolumeName, kMaxVolNameLen);
DiskFSGutenberg::LowerASCII((uint8_t*)fDiskVolumeName, kMaxVolNameLen);
A2FileGutenberg::TrimTrailingSpaces(fDiskVolumeName);
dierr = ProcessCatalogSector(catTrack, catSect, sctBuf);
@ -253,12 +246,11 @@ bail:
* Pass in the track, sector, and the contents of that track and sector.
* (We only use "catTrack" and "catSect" to fill out some fields.)
*/
DIError
DiskFSGutenberg::ProcessCatalogSector(int catTrack, int catSect,
const unsigned char* sctBuf)
DIError DiskFSGutenberg::ProcessCatalogSector(int catTrack, int catSect,
const uint8_t* sctBuf)
{
A2FileGutenberg* pFile;
const unsigned char* pEntry;
const uint8_t* pEntry;
int i;
pEntry = &sctBuf[kCatalogEntryOffset];
@ -298,31 +290,27 @@ DiskFSGutenberg::ProcessCatalogSector(int catTrack, int catSect,
return kDIErrNone;
}
/*
* Perform consistency checks on the filesystem.
*
* Returns "true" if disk appears to be perfect, "false" otherwise.
*/
bool
DiskFSGutenberg::CheckDiskIsGood(void)
bool DiskFSGutenberg::CheckDiskIsGood(void)
{
bool result = true;
return result;
}
/*
* Run through our list of files, computing the lengths and marking file
* usage in the VolumeUsage object.
*/
DIError
DiskFSGutenberg::GetFileLengths(void)
DIError DiskFSGutenberg::GetFileLengths(void)
{
A2FileGutenberg* pFile;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
int tsCount = 0;
unsigned short currentTrack, currentSector;
uint16_t currentTrack, currentSector;
pFile = (A2FileGutenberg*) GetNextFile(NULL);
while (pFile != NULL) {
@ -352,7 +340,6 @@ bail:
return kDIErrNone;
}
/*
* Convert high ASCII to low ASCII.
*
@ -361,8 +348,7 @@ bail:
*
* We modify the first "len" bytes of "buf" in place.
*/
/*static*/ void
DiskFSGutenberg::LowerASCII(unsigned char* buf, long len)
/*static*/ void DiskFSGutenberg::LowerASCII(uint8_t* buf, long len)
{
while (len--) {
if (*buf & 0x80) {
@ -415,13 +401,11 @@ A2FileGutenberg::~A2FileGutenberg(void)
delete fpOpenFile;
}
/*
* Convert the filetype enum to a ProDOS type.
*
*/
long
A2FileGutenberg::GetFileType(void) const
long A2FileGutenberg::GetFileType(void) const
{
return 0x04; // TXT;
}
@ -430,10 +414,9 @@ A2FileGutenberg::GetFileType(void) const
* "Fix" a filename. Convert DOS-ASCII to normal ASCII, and strip
* trailing spaces.
*/
void
A2FileGutenberg::FixFilename(void)
void A2FileGutenberg::FixFilename(void)
{
DiskFSGutenberg::LowerASCII((unsigned char*)fFileName, kMaxFileName);
DiskFSGutenberg::LowerASCII((uint8_t*)fFileName, kMaxFileName);
TrimTrailingSpaces(fFileName);
}
@ -442,8 +425,7 @@ A2FileGutenberg::FixFilename(void)
*
* Assumes the filename has already been converted to low ASCII.
*/
/*static*/ void
A2FileGutenberg::TrimTrailingSpaces(char* filename)
/*static*/ void A2FileGutenberg::TrimTrailingSpaces(char* filename)
{
char* lastspc = filename + strlen(filename);
@ -464,8 +446,7 @@ A2FileGutenberg::TrimTrailingSpaces(char* filename)
*
* "buf" must be able to hold kMaxFileName+1 chars.
*/
/*static*/ void
A2FileGutenberg::MakeDOSName(char* buf, const char* name)
/*static*/ void A2FileGutenberg::MakeDOSName(char* buf, const char* name)
{
for (int i = 0; i < kMaxFileName; i++) {
if (*name == '\0')
@ -480,8 +461,7 @@ A2FileGutenberg::MakeDOSName(char* buf, const char* name)
/*
* Set up state for this file.
*/
DIError
A2FileGutenberg::Open(A2FileDescr** ppOpenFile, bool readOnly,
DIError A2FileGutenberg::Open(A2FileDescr** ppOpenFile, bool readOnly,
bool rsrcFork /*=false*/)
{
DIError dierr = kDIErrNone;
@ -520,8 +500,7 @@ bail:
/*
* Dump the contents of an A2FileGutenberg.
*/
void
A2FileGutenberg::Dump(void) const
void A2FileGutenberg::Dump(void) const
{
LOGI("A2FileGutenberg '%s'", fFileName);
LOGI(" TS T=%-2d S=%-2d", fTrack, fSector);
@ -542,8 +521,7 @@ A2FileGutenberg::Dump(void) const
* Read data from the current offset.
*
*/
DIError
A2FDGutenberg::Read(void* buf, size_t len, size_t* pActual)
DIError A2FDGutenberg::Read(void* buf, size_t len, size_t* pActual)
{
LOGI(" Gutenberg reading %d bytes from '%s' (offset=%ld)",
len, fpFile->GetPathName(), (long) fOffset);
@ -551,7 +529,7 @@ A2FDGutenberg::Read(void* buf, size_t len, size_t* pActual)
A2FileGutenberg* pFile = (A2FileGutenberg*) fpFile;
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
short currentTrack, currentSector;
di_off_t actualOffset = fOffset + pFile->fDataOffset; // adjust for embedded len
int bufOffset = 6;
@ -587,10 +565,8 @@ A2FDGutenberg::Read(void* buf, size_t len, size_t* pActual)
/*
* Writing Gutenberg files isn't supported.
*
*/
DIError
A2FDGutenberg::Write(const void* buf, size_t len, size_t* pActual)
DIError A2FDGutenberg::Write(const void* buf, size_t len, size_t* pActual)
{
return kDIErrNotSupported;
}
@ -598,8 +574,7 @@ A2FDGutenberg::Write(const void* buf, size_t len, size_t* pActual)
/*
* Seek to the specified offset.
*/
DIError
A2FDGutenberg::Seek(di_off_t offset, DIWhence whence)
DIError A2FDGutenberg::Seek(di_off_t offset, DIWhence whence)
{
return kDIErrNotSupported;
}
@ -607,8 +582,7 @@ A2FDGutenberg::Seek(di_off_t offset, DIWhence whence)
/*
* Return current offset.
*/
di_off_t
A2FDGutenberg::Tell(void)
di_off_t A2FDGutenberg::Tell(void)
{
return kDIErrNotSupported;
}
@ -627,8 +601,7 @@ A2FDGutenberg::Tell(void)
* Most applications don't check the value of "Close", or call it from a
* destructor, so we call CloseDescr whether we succeed or not.
*/
DIError
A2FDGutenberg::Close(void)
DIError A2FDGutenberg::Close(void)
{
DIError dierr = kDIErrNone;
@ -636,17 +609,15 @@ A2FDGutenberg::Close(void)
return dierr;
}
/*
* Return the #of sectors/blocks in the file.
*/
long
A2FDGutenberg::GetSectorCount(void) const
long A2FDGutenberg::GetSectorCount(void) const
{
return fTSCount;
}
long
A2FDGutenberg::GetBlockCount(void) const
long A2FDGutenberg::GetBlockCount(void) const
{
return (fTSCount+1)/2;
}
@ -656,16 +627,15 @@ A2FDGutenberg::GetBlockCount(void) const
*
* Returns (0,0) for a sparse sector.
*/
DIError
A2FDGutenberg::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
DIError A2FDGutenberg::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
{
return kDIErrInvalidIndex;
}
/*
* Unimplemented
*/
DIError
A2FDGutenberg::GetStorage(long blockIdx, long* pBlock) const
DIError A2FDGutenberg::GetStorage(long blockIdx, long* pBlock) const
{
return kDIErrInvalidIndex;
}

View File

@ -30,15 +30,15 @@
const int kBlkSize = 512;
const int kMasterDirBlock = 2; // also a copy in next-to-last block
const unsigned short kSignature = 0x4244; // or 0xd2d7 for MFS
const uint16_t kSignature = 0x4244; // or 0xd2d7 for MFS
const int kMaxDirectoryDepth = 128; // not sure what HFS limit is
//namespace DiskImgLib {
/* extent descriptor */
typedef struct ExtDescriptor {
unsigned short xdrStABN; // first allocation block
unsigned short xdrNumABlks; // #of allocation blocks
uint16_t xdrStABN; // first allocation block
uint16_t xdrNumABlks; // #of allocation blocks
} ExtDescriptor;
/* extent data record */
typedef struct ExtDataRec {
@ -50,36 +50,36 @@ typedef struct ExtDataRec {
* chapter 2 ("Data Organization on Volumes"), pages 2-60 to 2-62.
*/
typedef struct DiskFSHFS::MasterDirBlock {
unsigned short drSigWord; // volume signature
unsigned long drCrDate; // date/time of volume creation
unsigned long drLsMod; // date/time of last modification
unsigned short drAtrb; // volume attributes
unsigned short drNmPls; // #of files in root directory
unsigned short drVBMSt; // first block of volume bitmap
unsigned short drAllocPtr; // start of next allocation search
unsigned short drNmAlBlks; // number of allocation blocks in volume
unsigned long drAlBlkSiz; // size (bytes) of allocation blocks
unsigned long drClpSiz; // default clump size
unsigned short drAlBlSt; // first allocation block in volume
unsigned long drNxtCNID; // next unused catalog node ID
unsigned short drFreeBks; // number of unused allocation blocks
unsigned char drVN[28]; // volume name (pascal string)
unsigned long drVolBkUp; // date/time of last backup
unsigned short drVSeqNum; // volume backup sequence number
unsigned long drWrCnt; // volume write count
unsigned long drXTClpSiz; // clump size for extents overflow file
unsigned long drCTClpSiz; // clump size for catalog file
unsigned short drNmRtDirs; // #of directories in root directory
unsigned long drFilCnt; // #of files in volume
unsigned long drDirCnt; // #of directories in volume
unsigned long drFndrInfo[8]; // information used by the Finder
unsigned short drVCSize; // size (blocks) of volume cache
unsigned short drVBMCSize; // size (blocks) of volume bitmap cache
unsigned short drCtlCSize; // size (blocks) of common volume cache
unsigned long drXTFlSize; // size (bytes) of extents overflow file
ExtDataRec drXTExtRec; // extent record for extents overflow file
unsigned long drCTFlSize; // size (bytes) of catalog file
ExtDataRec drCTExtRec; // extent record for catalog file
uint16_t drSigWord; // volume signature
uint32_t drCrDate; // date/time of volume creation
uint32_t drLsMod; // date/time of last modification
uint16_t drAtrb; // volume attributes
uint16_t drNmPls; // #of files in root directory
uint16_t drVBMSt; // first block of volume bitmap
uint16_t drAllocPtr; // start of next allocation search
uint16_t drNmAlBlks; // number of allocation blocks in volume
uint32_t drAlBlkSiz; // size (bytes) of allocation blocks
uint32_t drClpSiz; // default clump size
uint16_t drAlBlSt; // first allocation block in volume
uint32_t drNxtCNID; // next unused catalog node ID
uint16_t drFreeBks; // number of unused allocation blocks
uint8_t drVN[28]; // volume name (pascal string)
uint32_t drVolBkUp; // date/time of last backup
uint16_t drVSeqNum; // volume backup sequence number
uint32_t drWrCnt; // volume write count
uint32_t drXTClpSiz; // clump size for extents overflow file
uint32_t drCTClpSiz; // clump size for catalog file
uint16_t drNmRtDirs; // #of directories in root directory
uint32_t drFilCnt; // #of files in volume
uint32_t drDirCnt; // #of directories in volume
uint32_t drFndrInfo[8]; // information used by the Finder
uint16_t drVCSize; // size (blocks) of volume cache
uint16_t drVBMCSize; // size (blocks) of volume bitmap cache
uint16_t drCtlCSize; // size (blocks) of common volume cache
uint32_t drXTFlSize; // size (bytes) of extents overflow file
ExtDataRec drXTExtRec; // extent record for extents overflow file
uint32_t drCTFlSize; // size (bytes) of catalog file
ExtDataRec drCTExtRec; // extent record for catalog file
} MasterDirBlock;
//}; // namespace DiskImgLib
@ -87,8 +87,7 @@ typedef struct DiskFSHFS::MasterDirBlock {
/*
* Extract fields from a Master Directory Block.
*/
/*static*/ void
DiskFSHFS::UnpackMDB(const unsigned char* buf, MasterDirBlock* pMDB)
/*static*/ void DiskFSHFS::UnpackMDB(const uint8_t* buf, MasterDirBlock* pMDB)
{
pMDB->drSigWord = GetShortBE(&buf[0x00]);
pMDB->drCrDate = GetLongBE(&buf[0x02]);
@ -129,12 +128,11 @@ DiskFSHFS::UnpackMDB(const unsigned char* buf, MasterDirBlock* pMDB)
*
* We test a few fields in the master directory block for validity.
*/
/*static*/ DIError
DiskFSHFS::TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
/*static*/ DIError DiskFSHFS::TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
{
DIError dierr = kDIErrNone;
MasterDirBlock mdb;
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
dierr = pImg->ReadBlockSwapped(kMasterDirBlock, blkBuf, imageOrder,
DiskImg::kSectorOrderProDOS);
@ -181,8 +179,7 @@ bail:
/*
* Test to see if the image is an HFS disk.
*/
/*static*/ DIError
DiskFSHFS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSHFS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
//return kDIErrFilesystemNotFound; // DEBUG DEBUG DEBUG
@ -209,16 +206,14 @@ DiskFSHFS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
return kDIErrFilesystemNotFound;
}
/*
* Load some stuff from the volume header.
*/
DIError
DiskFSHFS::LoadVolHeader(void)
DIError DiskFSHFS::LoadVolHeader(void)
{
DIError dierr = kDIErrNone;
MasterDirBlock mdb;
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
if (fLocalTimeOffset == -1) {
struct tm* ptm;
@ -264,7 +259,7 @@ DiskFSHFS::LoadVolHeader(void)
fAllocationBlockSize = mdb.drAlBlkSiz;
fTotalBlocks = fpImg->GetNumBlocks();
unsigned long minBlocks;
uint32_t minBlocks;
minBlocks = mdb.drNmAlBlks * (mdb.drAlBlkSiz / kBlkSize) + mdb.drAlBlSt + 2;
assert(fTotalBlocks >= minBlocks); // verified during fs tests
@ -319,8 +314,7 @@ bail:
/*
* Set the volume ID based on fVolumeName.
*/
void
DiskFSHFS::SetVolumeID(void)
void DiskFSHFS::SetVolumeID(void)
{
strcpy(fVolumeID, "HFS ");
strcat(fVolumeID, fVolumeName);
@ -329,8 +323,7 @@ DiskFSHFS::SetVolumeID(void)
/*
* Blank out the volume usage map. The HFS volume bitmap is not yet supported.
*/
void
DiskFSHFS::SetVolumeUsageMap(void)
void DiskFSHFS::SetVolumeUsageMap(void)
{
VolumeUsage::ChunkState cstate;
long block;
@ -345,12 +338,10 @@ DiskFSHFS::SetVolumeUsageMap(void)
fVolumeUsage.SetChunkState(block, &cstate);
}
/*
* Print some interesting fields to the debug log.
*/
void
DiskFSHFS::DumpVolHeader(void)
void DiskFSHFS::DumpVolHeader(void)
{
LOGI("HFS volume header read:");
LOGI(" volume name = '%s'", fVolumeName);
@ -376,8 +367,7 @@ DiskFSHFS::DumpVolHeader(void)
* on out must be handled somehow, possibly by claiming that the disk is
* completely full and has no files on it.
*/
DIError
DiskFSHFS::Initialize(InitMode initMode)
DIError DiskFSHFS::Initialize(InitMode initMode)
{
DIError dierr = kDIErrNone;
char msg[kMaxVolumeName + 32];
@ -443,8 +433,7 @@ bail:
*
* Returns -1 on failure.
*/
unsigned long
DiskFSHFS::LibHFSCB(void* vThis, int op, unsigned long arg1, void* arg2)
unsigned long DiskFSHFS::LibHFSCB(void* vThis, int op, unsigned long arg1, void* arg2)
{
DiskFSHFS* pThis = (DiskFSHFS*) vThis;
unsigned long result = (unsigned long) -1;
@ -492,12 +481,10 @@ DiskFSHFS::LibHFSCB(void* vThis, int op, unsigned long arg1, void* arg2)
return result;
}
/*
* Determine the amount of free space on the disk.
*/
DIError
DiskFSHFS::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
DIError DiskFSHFS::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
int* pUnitSize) const
{
assert(fHfsVol != NULL);
@ -516,8 +503,7 @@ DiskFSHFS::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
/*
* Recursively traverse the filesystem.
*/
DIError
DiskFSHFS::RecursiveDirAdd(A2File* pParent, const char* basePath, int depth)
DIError DiskFSHFS::RecursiveDirAdd(A2File* pParent, const char* basePath, int depth)
{
DIError dierr = kDIErrNone;
hfsdir* dir;
@ -609,14 +595,14 @@ void A2FileHFS::InitEntry(const hfsdirent* dirEntry)
fDataLength = 0;
fRsrcLength = -1;
} else {
unsigned char* pType;
uint8_t* pType;
fIsDir = false;
pType = (unsigned char*) dirEntry->u.file.type;
pType = (uint8_t*) dirEntry->u.file.type;
fType =
pType[0] << 24 | pType[1] << 16 | pType[2] << 8 | pType[3];
pType = (unsigned char*) dirEntry->u.file.creator;
pType = (uint8_t*) dirEntry->u.file.creator;
fCreator =
pType[0] << 24 | pType[1] << 16 | pType[2] << 8 | pType[3];
fDataLength = dirEntry->u.file.dsize;
@ -641,8 +627,7 @@ void A2FileHFS::InitEntry(const hfsdirent* dirEntry)
/*
* Return "true" if "name" is valid for use as an HFS volume name.
*/
/*static*/ bool
DiskFSHFS::IsValidVolumeName(const char* name)
/*static*/ bool DiskFSHFS::IsValidVolumeName(const char* name)
{
if (name == NULL)
return false;
@ -663,8 +648,7 @@ DiskFSHFS::IsValidVolumeName(const char* name)
/*
* Return "true" if "name" is valid for use as an HFS file name.
*/
/*static*/ bool
DiskFSHFS::IsValidFileName(const char* name)
/*static*/ bool DiskFSHFS::IsValidFileName(const char* name)
{
if (name == NULL)
return false;
@ -685,8 +669,7 @@ DiskFSHFS::IsValidFileName(const char* name)
/*
* Format the current volume with HFS.
*/
DIError
DiskFSHFS::Format(DiskImg* pDiskImg, const char* volName)
DIError DiskFSHFS::Format(DiskImg* pDiskImg, const char* volName)
{
assert(strlen(volName) > 0 && strlen(volName) <= kMaxVolumeName);
@ -712,7 +695,6 @@ DiskFSHFS::Format(DiskImg* pDiskImg, const char* volName)
return kDIErrNone;
}
/*
* Normalize an HFS path. Invokes DoNormalizePath and handles the buffer
* management (if the normalized path doesn't fit in "*pNormalizedBufLen"
@ -721,8 +703,7 @@ DiskFSHFS::Format(DiskImg* pDiskImg, const char* volName)
* This is invoked from the generalized "add" function in CiderPress, which
* doesn't want to understand the ins and outs of pathnames.
*/
DIError
DiskFSHFS::NormalizePath(const char* path, char fssep,
DIError DiskFSHFS::NormalizePath(const char* path, char fssep,
char* normalizedBuf, int* pNormalizedBufLen)
{
DIError dierr = kDIErrNone;
@ -760,8 +741,7 @@ bail:
*
* The caller must delete[] "*pNormalizedPath".
*/
DIError
DiskFSHFS::DoNormalizePath(const char* path, char fssep,
DIError DiskFSHFS::DoNormalizePath(const char* path, char fssep,
char** pNormalizedPath)
{
DIError dierr = kDIErrNone;
@ -876,11 +856,10 @@ bail:
* Returns <0, ==0, or >0 depending on whether sstr1 is lexically less than,
* equal to, or greater than sstr2.
*/
/*static*/ int
DiskFSHFS::CompareMacFileNames(const char* sstr1, const char* sstr2)
/*static*/ int DiskFSHFS::CompareMacFileNames(const char* sstr1, const char* sstr2)
{
const unsigned char* str1 = (const unsigned char*) sstr1;
const unsigned char* str2 = (const unsigned char*) sstr2;
const uint8_t* str1 = (const uint8_t*) sstr1;
const uint8_t* str2 = (const uint8_t*) sstr2;
int diff;
while (*str1 && *str2) {
@ -906,8 +885,7 @@ DiskFSHFS::CompareMacFileNames(const char* sstr1, const char* sstr2)
* but may require disk reads. We use the DiskFS interface, on the assumption
* that someday we'll switch the linear list to a tree structure.
*/
DIError
DiskFSHFS::MakeFileNameUnique(const char* pathName, char** pUniqueName)
DIError DiskFSHFS::MakeFileNameUnique(const char* pathName, char** pUniqueName)
{
A2File* pFile;
const int kMaxExtra = 3;
@ -984,7 +962,6 @@ DiskFSHFS::MakeFileNameUnique(const char* pathName, char** pUniqueName)
return kDIErrNone;
}
/*
* Create a new file or directory. Automatically creates the base path
* if necessary.
@ -993,8 +970,7 @@ DiskFSHFS::MakeFileNameUnique(const char* pathName, char** pUniqueName)
* a stronger set of utility functions in the parent class now that we have
* more than one hierarchical file system.
*/
DIError
DiskFSHFS::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
DIError DiskFSHFS::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
{
DIError dierr = kDIErrNone;
char typeStr[5], creatorStr[5];
@ -1317,8 +1293,7 @@ bail:
*
* We need to use a different call for file vs. directory.
*/
DIError
DiskFSHFS::DeleteFile(A2File* pGenericFile)
DIError DiskFSHFS::DeleteFile(A2File* pGenericFile)
{
DIError dierr = kDIErrNone;
char* pathName = NULL;
@ -1373,8 +1348,7 @@ bail:
* get fixed up when we copy them to a ProDOS disk, which is the only way
* 8-bit AppleWorks can get at them.
*/
DIError
DiskFSHFS::RenameFile(A2File* pGenericFile, const char* newName)
DIError DiskFSHFS::RenameFile(A2File* pGenericFile, const char* newName)
{
DIError dierr = kDIErrNone;
A2FileHFS* pFile = (A2FileHFS*) pGenericFile;
@ -1474,8 +1448,7 @@ bail:
* [This was lifted straight out of the ProDOS sources. It should probably
* be moved into generic DiskFS.]
*/
DIError
DiskFSHFS::RegeneratePathName(A2FileHFS* pFile)
DIError DiskFSHFS::RegeneratePathName(A2FileHFS* pFile)
{
A2FileHFS* pParent;
char* buf = NULL;
@ -1532,8 +1505,7 @@ DiskFSHFS::RegeneratePathName(A2FileHFS* pFile)
* Mac convention is to *not* start the volume name with a colon. In fact,
* the libhfs convention is to *end* the volume names with a colon.
*/
DIError
DiskFSHFS::RenameVolume(const char* newName)
DIError DiskFSHFS::RenameVolume(const char* newName)
{
DIError dierr = kDIErrNone;
A2FileHFS* pFile;
@ -1579,8 +1551,7 @@ bail:
/*
* Set file attributes.
*/
DIError
DiskFSHFS::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
DIError DiskFSHFS::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
long accessFlags)
{
DIError dierr = kDIErrNone;
@ -1616,12 +1587,12 @@ DiskFSHFS::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
else
dirEnt.flags &= ~HFS_ISLOCKED;
LOGI(" HFS setting '%s' to fdflags=0x%04x flags=0x%04x",
LOGD(" HFS setting '%s' to fdflags=0x%04x flags=0x%04x",
colonPath, dirEnt.fdflags, dirEnt.flags);
LOGI(" type=0x%08lx creator=0x%08lx", fileType, auxType);
LOGD(" type=0x%08lx creator=0x%08lx", fileType, auxType);
if (hfs_setattr(fHfsVol, colonPath, &dirEnt) != 0) {
LOGI(" HFS setattr '%s' failed: %s", colonPath, hfs_error);
LOGW(" HFS setattr '%s' failed: %s", colonPath, hfs_error);
dierr = kDIErrGeneric;
goto bail;
}
@ -1649,8 +1620,7 @@ bail:
/*
* Dump the contents of the A2File structure.
*/
void
A2FileHFS::Dump(void) const
void A2FileHFS::Dump(void) const
{
LOGI("A2FileHFS '%s'", fFileName);
}
@ -1701,7 +1671,7 @@ long A2FileHFS::GetFileType(void) const
return digit1 << 4 | digit2;
}
unsigned char flag = (unsigned char)(fType >> 24);
uint8_t flag = (uint8_t)(fType >> 24);
if (flag == 0x70) { // 'p'
/* type and aux embedded within */
return (fType >> 16) & 0xff;
@ -1718,7 +1688,7 @@ long A2FileHFS::GetFileType(void) const
else
return 0x00;
}
};
}
/*
* If this has a ProDOS aux type, convert it.
@ -1728,7 +1698,7 @@ long A2FileHFS::GetAuxType(void) const
if (fCreator != kPdosType)
return fCreator;
unsigned char flag = (unsigned char)(fType >> 24);
uint8_t flag = (uint8_t)(fType >> 24);
if (flag == 0x70) { // 'p'
/* type and aux embedded within */
return fType & 0xffff;
@ -1743,8 +1713,7 @@ long A2FileHFS::GetAuxType(void) const
*
* If we're in the volume directory, pass in "" for the base path (not NULL).
*/
void
A2FileHFS::SetPathName(const char* basePath, const char* fileName)
void A2FileHFS::SetPathName(const char* basePath, const char* fileName)
{
assert(basePath != NULL && fileName != NULL);
if (fPathName != NULL)
@ -1774,8 +1743,7 @@ A2FileHFS::SetPathName(const char* basePath, const char* fileName)
*
* The caller must delete[] the return value.
*/
char*
A2FileHFS::GetLibHFSPathName(void) const
char* A2FileHFS::GetLibHFSPathName(void) const
{
char* nameBuf;
@ -1794,8 +1762,7 @@ A2FileHFS::GetLibHFSPathName(void) const
* conversions discard the file's aux type and therefore are unsuitable,
* and the conversion of SRC throws away its identity.
*/
/*static*/ void
A2FileHFS::ConvertTypeToHFS(long fileType, long auxType,
/*static*/ void A2FileHFS::ConvertTypeToHFS(long fileType, long auxType,
char* pType, char* pCreator)
{
if (fileType == 0x00 && auxType == 0x0000) {
@ -1808,9 +1775,9 @@ A2FileHFS::ConvertTypeToHFS(long fileType, long auxType,
auxType >= 0 && auxType <= 0xffff)
{
pType[0] = 'p';
pType[1] = (unsigned char) fileType;
pType[2] = (unsigned char) (auxType >> 8);
pType[3] = (unsigned char) auxType;
pType[1] = (uint8_t) fileType;
pType[2] = (uint8_t) (auxType >> 8);
pType[3] = (uint8_t) auxType;
pType[4] = '\0';
pCreator[0] = 'p';
pCreator[1] = 'd';
@ -1818,15 +1785,15 @@ A2FileHFS::ConvertTypeToHFS(long fileType, long auxType,
pCreator[3] = 's';
pCreator[4] = '\0';
} else {
pType[0] = (unsigned char)(fileType >> 24);
pType[1] = (unsigned char)(fileType >> 16);
pType[2] = (unsigned char)(fileType >> 8);
pType[3] = (unsigned char) fileType;
pType[0] = (uint8_t)(fileType >> 24);
pType[1] = (uint8_t)(fileType >> 16);
pType[2] = (uint8_t)(fileType >> 8);
pType[3] = (uint8_t) fileType;
pType[4] = '\0';
pCreator[0] = (unsigned char)(auxType >> 24);
pCreator[1] = (unsigned char)(auxType >> 16);
pCreator[2] = (unsigned char)(auxType >> 8);
pCreator[3] = (unsigned char) auxType;
pCreator[0] = (uint8_t)(auxType >> 24);
pCreator[1] = (uint8_t)(auxType >> 16);
pCreator[2] = (uint8_t)(auxType >> 8);
pCreator[3] = (uint8_t) auxType;
pCreator[4] = '\0';
}
}
@ -1840,8 +1807,7 @@ A2FileHFS::ConvertTypeToHFS(long fileType, long auxType,
* by the rest of CiderPress (and most of the civilized world), so instead
* of storing the pathname that way we just tack it on here.
*/
DIError
A2FileHFS::Open(A2FileDescr** ppOpenFile, bool readOnly,
DIError A2FileHFS::Open(A2FileDescr** ppOpenFile, bool readOnly,
bool rsrcFork /*=false*/)
{
DIError dierr = kDIErrNone;
@ -1885,8 +1851,7 @@ bail:
/*
* Read a chunk of data from the fake file.
*/
DIError
A2FDHFS::Read(void* buf, size_t len, size_t* pActual)
DIError A2FDHFS::Read(void* buf, size_t len, size_t* pActual)
{
long result;
@ -1927,8 +1892,7 @@ A2FDHFS::Read(void* buf, size_t len, size_t* pActual)
* one piece. This function does work correctly with multiple smaller
* pieces though, because it lets libhfs do all the work.)
*/
DIError
A2FDHFS::Write(const void* buf, size_t len, size_t* pActual)
DIError A2FDHFS::Write(const void* buf, size_t len, size_t* pActual)
{
long result;
@ -1967,8 +1931,7 @@ A2FDHFS::Write(const void* buf, size_t len, size_t* pActual)
/*
* Seek to a new offset.
*/
DIError
A2FDHFS::Seek(di_off_t offset, DIWhence whence)
DIError A2FDHFS::Seek(di_off_t offset, DIWhence whence)
{
int hfsWhence;
unsigned long result;
@ -1993,8 +1956,7 @@ A2FDHFS::Seek(di_off_t offset, DIWhence whence)
/*
* Return current offset.
*/
di_off_t
A2FDHFS::Tell(void)
di_off_t A2FDHFS::Tell(void)
{
di_off_t offset;
@ -2006,8 +1968,7 @@ A2FDHFS::Tell(void)
/*
* Release file state, and tell our parent to destroy us.
*/
DIError
A2FDHFS::Close(void)
DIError A2FDHFS::Close(void)
{
hfsdirent dirEnt;
@ -2050,15 +2011,14 @@ A2FDHFS::Close(void)
* Return the #of sectors/blocks in the file. Not supported, but since HFS
* doesn't support "sparse" files we can fake it.
*/
long
A2FDHFS::GetSectorCount(void) const
long A2FDHFS::GetSectorCount(void) const
{
A2FileHFS* pFile = (A2FileHFS*) fpFile;
return (long) ((pFile->fDataLength+255) / 256 +
(pFile->fRsrcLength+255) / 256);
}
long
A2FDHFS::GetBlockCount(void) const
long A2FDHFS::GetBlockCount(void) const
{
A2FileHFS* pFile = (A2FileHFS*) fpFile;
return (long) ((pFile->fDataLength+511) / 512 +
@ -2068,16 +2028,15 @@ A2FDHFS::GetBlockCount(void) const
/*
* Return the Nth track/sector in this file. Not supported.
*/
DIError
A2FDHFS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
DIError A2FDHFS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
{
return kDIErrNotSupported;
}
/*
* Return the Nth 512-byte block in this file. Not supported.
*/
DIError
A2FDHFS::GetStorage(long blockIdx, long* pBlock) const
DIError A2FDHFS::GetStorage(long blockIdx, long* pBlock) const
{
return kDIErrNotSupported;
}
@ -2094,8 +2053,7 @@ A2FDHFS::GetStorage(long blockIdx, long* pBlock) const
* on out must be handled somehow, possibly by claiming that the disk is
* completely full and has no files on it.
*/
DIError
DiskFSHFS::Initialize(InitMode initMode)
DIError DiskFSHFS::Initialize(InitMode initMode)
{
DIError dierr = kDIErrNone;
@ -2112,12 +2070,10 @@ bail:
return dierr;
}
/*
* Fill a buffer with some interesting stuff, and add it to the file list.
*/
void
DiskFSHFS::CreateFakeFile(void)
void DiskFSHFS::CreateFakeFile(void)
{
A2FileHFS* pFile;
char buf[768]; // currently running about 475
@ -2156,7 +2112,7 @@ DiskFSHFS::CreateFakeFile(void)
dateBuf[len-1] = '\0';
memset(buf, 0, sizeof(buf));
sprintf(buf, kFormatMsg,
snprintf(buf, NELEM(buf), kFormatMsg,
fVolumeName,
capacity,
(double) capacity / 2048.0,
@ -2194,8 +2150,7 @@ DIError GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
/*
* Not a whole lot to do.
*/
DIError
A2FileHFS::Open(A2FileDescr** ppOpenFile, bool readOnly,
DIError A2FileHFS::Open(A2FileDescr** ppOpenFile, bool readOnly,
bool rsrcFork /*=false*/)
{
A2FDHFS* pOpenFile = NULL;
@ -2224,10 +2179,9 @@ A2FileHFS::Open(A2FileDescr** ppOpenFile, bool readOnly,
/*
* Read a chunk of data from the fake file.
*/
DIError
A2FDHFS::Read(void* buf, size_t len, size_t* pActual)
DIError A2FDHFS::Read(void* buf, size_t len, size_t* pActual)
{
LOGI(" HFS reading %d bytes from '%s' (offset=%ld)",
LOGD(" HFS reading %d bytes from '%s' (offset=%ld)",
len, fpFile->GetPathName(), (long) fOffset);
A2FileHFS* pFile = (A2FileHFS*) fpFile;
@ -2251,8 +2205,7 @@ A2FDHFS::Read(void* buf, size_t len, size_t* pActual)
/*
* Write data at the current offset.
*/
DIError
A2FDHFS::Write(const void* buf, size_t len, size_t* pActual)
DIError A2FDHFS::Write(const void* buf, size_t len, size_t* pActual)
{
return kDIErrNotSupported;
}
@ -2260,8 +2213,7 @@ A2FDHFS::Write(const void* buf, size_t len, size_t* pActual)
/*
* Seek to a new offset.
*/
DIError
A2FDHFS::Seek(di_off_t offset, DIWhence whence)
DIError A2FDHFS::Seek(di_off_t offset, DIWhence whence)
{
di_off_t fileLen = ((A2FileHFS*) fpFile)->fDataLength;
@ -2296,8 +2248,7 @@ A2FDHFS::Seek(di_off_t offset, DIWhence whence)
/*
* Return current offset.
*/
di_off_t
A2FDHFS::Tell(void)
di_off_t A2FDHFS::Tell(void)
{
return fOffset;
}
@ -2305,8 +2256,7 @@ A2FDHFS::Tell(void)
/*
* Release file state, and tell our parent to destroy us.
*/
DIError
A2FDHFS::Close(void)
DIError A2FDHFS::Close(void)
{
fpFile->CloseDescr(this);
return kDIErrNone;
@ -2315,14 +2265,13 @@ A2FDHFS::Close(void)
/*
* Return the #of sectors/blocks in the file.
*/
long
A2FDHFS::GetSectorCount(void) const
long A2FDHFS::GetSectorCount(void) const
{
A2FileHFS* pFile = (A2FileHFS*) fpFile;
return (long) ((pFile->fDataLength+255) / 256);
}
long
A2FDHFS::GetBlockCount(void) const
long A2FDHFS::GetBlockCount(void) const
{
A2FileHFS* pFile = (A2FileHFS*) fpFile;
return (long) ((pFile->fDataLength+511) / 512);
@ -2331,16 +2280,15 @@ A2FDHFS::GetBlockCount(void) const
/*
* Return the Nth track/sector in this file.
*/
DIError
A2FDHFS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
DIError A2FDHFS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
{
return kDIErrNotSupported;
}
/*
* Return the Nth 512-byte block in this file.
*/
DIError
A2FDHFS::GetStorage(long blockIdx, long* pBlock) const
DIError A2FDHFS::GetStorage(long blockIdx, long* pBlock) const
{
return kDIErrNotSupported;
}

View File

@ -42,8 +42,7 @@
* The easiest way to do that is to open up the header and see if
* it looks valid.
*/
/*static*/ DIError
Wrapper2MG::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*static*/ DIError Wrapper2MG::Test(GenericFD* pGFD, di_off_t wrappedLength)
{
TwoImgHeader header;
@ -62,8 +61,7 @@ Wrapper2MG::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*
* Get the header (again) and use it to locate the data.
*/
DIError
Wrapper2MG::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
DIError Wrapper2MG::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DiskImg::SectorOrder* pOrder, short* pDiskVolNum,
LinearBitmap** ppBadBlockMap, GenericFD** ppNewGFD)
@ -108,8 +106,7 @@ Wrapper2MG::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
/*
* Initialize fields for a new file.
*/
DIError
Wrapper2MG::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DIError Wrapper2MG::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DiskImg::SectorOrder order, short dosVolumeNum, GenericFD* pWrapperGFD,
di_off_t* pWrappedLength, GenericFD** pDataFD)
{
@ -185,8 +182,7 @@ Wrapper2MG::Create(di_off_t length, DiskImg::PhysicalFormat physical,
* Since there's no checksum, none of the header fields change, so we
* don't even deal with that.
*/
DIError
Wrapper2MG::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
DIError Wrapper2MG::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
di_off_t dataLen, di_off_t* pWrappedLen)
{
return kDIErrNone;
@ -207,8 +203,8 @@ Wrapper2MG::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
/*
* Display error messages... or not.
*/
/*static*/ NuResult
WrapperNuFX::ErrMsgHandler(NuArchive* /*pArchive*/, void* vErrorMessage)
/*static*/ NuResult WrapperNuFX::ErrMsgHandler(NuArchive* /*pArchive*/,
void* vErrorMessage)
{
const NuErrorMessage* pErrorMessage = (const NuErrorMessage*) vErrorMessage;
@ -229,8 +225,7 @@ WrapperNuFX::ErrMsgHandler(NuArchive* /*pArchive*/, void* vErrorMessage)
* On success, the NuArchive pointer and thread idx are set, and 0 is
* returned. Returns -1 on failure.
*/
/*static*/ DIError
WrapperNuFX::OpenNuFX(const char* pathName, NuArchive** ppArchive,
/*static*/ DIError WrapperNuFX::OpenNuFX(const char* pathName, NuArchive** ppArchive,
NuThreadIdx* pThreadIdx, long* pLength, bool readOnly)
{
NuError nerr = kNuErrNone;
@ -362,16 +357,15 @@ file_archive:
*
* Returns 0 on success, -1 on error.
*/
DIError
WrapperNuFX::GetNuFXDiskImage(NuArchive* pArchive, NuThreadIdx threadIdx,
DIError WrapperNuFX::GetNuFXDiskImage(NuArchive* pArchive, NuThreadIdx threadIdx,
long length, char** ppData)
{
NuError err;
NuDataSink* pDataSink = NULL;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
assert(length > 0);
buf = new unsigned char[length];
buf = new uint8_t[length];
if (buf == NULL)
return kDIErrMalloc;
@ -417,8 +411,7 @@ bail:
* Test to see if this is a single-record NuFX archive with a disk archive
* in it.
*/
/*static*/ DIError
WrapperNuFX::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*static*/ DIError WrapperNuFX::Test(GenericFD* pGFD, di_off_t wrappedLength)
{
DIError dierr;
NuArchive* pArchive = NULL;
@ -446,8 +439,7 @@ WrapperNuFX::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*
* Open the archive, extract the disk image into a memory buffer.
*/
DIError
WrapperNuFX::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
DIError WrapperNuFX::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DiskImg::SectorOrder* pOrder, short* pDiskVolNum,
LinearBitmap** ppBadBlockMap, GenericFD** ppNewGFD)
@ -511,8 +503,7 @@ bail:
*
* Returns a string allocated with new[].
*/
/*static*/ char*
WrapperNuFX::GenTempPath(const char* path)
/*static*/ char* WrapperNuFX::GenTempPath(const char* path)
{
static const char* kTmpTemplate = "DItmp_XXXXXX";
char* tmpPath;
@ -551,8 +542,7 @@ WrapperNuFX::GenTempPath(const char* path)
* recreating the underlying file. (If it doesn't have an underlying
* file, then we're hosed.)
*/
DIError
WrapperNuFX::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DIError WrapperNuFX::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DiskImg::SectorOrder order, short dosVolumeNum, GenericFD* pWrapperGFD,
di_off_t* pWrappedLength, GenericFD** pDataFD)
{
@ -563,7 +553,7 @@ WrapperNuFX::Create(di_off_t length, DiskImg::PhysicalFormat physical,
NuArchive* pArchive;
const char* imagePath;
char* tmpPath = NULL;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
NuError nerr;
/*
@ -594,7 +584,7 @@ WrapperNuFX::Create(di_off_t length, DiskImg::PhysicalFormat physical,
* Create a blank chunk of memory for the image.
*/
assert(length > 0);
buf = new unsigned char[(int) length];
buf = new uint8_t[(int) length];
if (buf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -625,8 +615,7 @@ bail:
/*
* Close the NuFX archive.
*/
DIError
WrapperNuFX::CloseNuFX(void)
DIError WrapperNuFX::CloseNuFX(void)
{
NuError nerr;
@ -650,8 +639,7 @@ WrapperNuFX::CloseNuFX(void)
* pWrapperGFD, we can't have a gzip wrapper, so there's no point in
* updating it.
*/
DIError
WrapperNuFX::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
DIError WrapperNuFX::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
di_off_t dataLen, di_off_t* pWrappedLen)
{
NuError nerr = kNuErrNone;
@ -727,7 +715,7 @@ WrapperNuFX::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
* feed the data into NufxLib.
*/
nerr = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, 0,
(const unsigned char*) ((GFDBuffer*) pDataGFD)->GetBuffer(),
(const uint8_t*) ((GFDBuffer*) pDataGFD)->GetBuffer(),
0, (long) dataLen, NULL, &pDataSource);
if (nerr != kNuErrNone) {
LOGI(" NuFX unable to create NufxLib data source (nerr=%d)", nerr);
@ -770,8 +758,7 @@ bail:
/*
* Common NuFX utility function. This ought to be in NufxLib.
*/
void
WrapperNuFX::UNIXTimeToDateTime(const time_t* pWhen, NuDateTime *pDateTime)
void WrapperNuFX::UNIXTimeToDateTime(const time_t* pWhen, NuDateTime *pDateTime)
{
struct tm* ptm;
@ -802,8 +789,7 @@ WrapperNuFX::UNIXTimeToDateTime(const time_t* pWhen, NuDateTime *pDateTime)
* runs of repeated bytes, which will be impossible in a DDD file because
* we compress runs of repeated bytes with RLE.
*/
/*static*/ DIError
WrapperDDD::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*static*/ DIError WrapperDDD::Test(GenericFD* pGFD, di_off_t wrappedLength)
{
DIError dierr;
GenericFD* pNewGFD = NULL;
@ -846,12 +832,11 @@ WrapperDDD::Test(GenericFD* pGFD, di_off_t wrappedLength)
* bytes of the file, because DOS DDD just fills it with junk, and it's
* possible that junk might have runs in it.
*/
/*static*/ DIError
WrapperDDD::CheckForRuns(GenericFD* pGFD)
/*static*/ DIError WrapperDDD::CheckForRuns(GenericFD* pGFD)
{
DIError dierr = kDIErrNone;
int kRunThreshold = 5;
unsigned char buf[8192];
uint8_t buf[8192];
size_t bufCount;
int runLen;
di_off_t fileLen;
@ -904,8 +889,7 @@ bail:
/*
* Prepping is much the same as testing, but we fill in a few more details.
*/
DIError
WrapperDDD::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
DIError WrapperDDD::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DiskImg::SectorOrder* pOrder, short* pDiskVolNum,
LinearBitmap** ppBadBlockMap, GenericFD** ppNewGFD)
@ -930,17 +914,17 @@ WrapperDDD::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
* Unpack a compressed disk image from "pGFD" to a new memory buffer
* created in "*ppNewGFD".
*/
/*static*/ DIError
WrapperDDD::Unpack(GenericFD* pGFD, GenericFD** ppNewGFD, short* pDiskVolNum)
/*static*/ DIError WrapperDDD::Unpack(GenericFD* pGFD, GenericFD** ppNewGFD,
short* pDiskVolNum)
{
DIError dierr;
GFDBuffer* pNewGFD = NULL;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
short diskVolNum;
pGFD->Rewind();
buf = new unsigned char[kNumTracks * kTrackLen];
buf = new uint8_t[kNumTracks * kTrackLen];
if (buf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -975,8 +959,7 @@ bail:
* Initialize stuff for a new file. There's no file header or other
* goodies, so we leave "pWrapperGFD" and "pWrappedLength" alone.
*/
DIError
WrapperDDD::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DIError WrapperDDD::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DiskImg::SectorOrder order, short dosVolumeNum, GenericFD* pWrapperGFD,
di_off_t* pWrappedLength, GenericFD** pDataFD)
{
@ -985,12 +968,12 @@ WrapperDDD::Create(di_off_t length, DiskImg::PhysicalFormat physical,
assert(order == DiskImg::kSectorOrderDOS);
DIError dierr;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
/*
* Create a blank chunk of memory for the image.
*/
buf = new unsigned char[(int) length];
buf = new uint8_t[(int) length];
if (buf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -1021,8 +1004,7 @@ bail:
/*
* Compress the disk image.
*/
DIError
WrapperDDD::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
DIError WrapperDDD::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
di_off_t dataLen, di_off_t* pWrappedLen)
{
DIError dierr;
@ -1061,14 +1043,14 @@ const int kDC42PrivateMagic = 0x100;
const int kDC42FakeTagLen = 19200; // add a "fake" tag to match Mac
typedef struct DiskImgLib::DC42Header {
char diskName[kDC42NameLen+1]; // from pascal string
long dataSize; // in bytes
long tagSize;
unsigned long dataChecksum;
unsigned long tagChecksum;
unsigned char diskFormat; // should be 1 for 800K
unsigned char formatByte; // should be $24, sometimes $22
unsigned short privateWord; // must be 0x0100
char diskName[kDC42NameLen+1]; // from pascal string
long dataSize; // in bytes
long tagSize;
uint32_t dataChecksum;
uint32_t tagChecksum;
uint8_t diskFormat; // should be 1 for 800K
uint8_t formatByte; // should be $24, sometimes $22
uint16_t privateWord; // must be 0x0100
// userData begins at +84
// tagData follows user data
} DC42Header;
@ -1076,8 +1058,7 @@ typedef struct DiskImgLib::DC42Header {
/*
* Dump the contents of a DC42Header.
*/
/*static*/ void
WrapperDiskCopy42::DumpHeader(const DC42Header* pHeader)
/*static*/ void WrapperDiskCopy42::DumpHeader(const DC42Header* pHeader)
{
LOGI("--- header contents:");
LOGI("\tdiskName = '%s'", pHeader->diskName);
@ -1094,8 +1075,7 @@ WrapperDiskCopy42::DumpHeader(const DC42Header* pHeader)
/*
* Init a DC42 header for an 800K ProDOS disk.
*/
void
WrapperDiskCopy42::InitHeader(DC42Header* pHeader)
void WrapperDiskCopy42::InitHeader(DC42Header* pHeader)
{
memset(pHeader, 0, sizeof(*pHeader));
if (fStorageName == NULL || strlen(fStorageName) == 0)
@ -1116,10 +1096,9 @@ WrapperDiskCopy42::InitHeader(DC42Header* pHeader)
*
* Returns 0 on success, -1 on error or invalid header.
*/
/*static*/ int
WrapperDiskCopy42::ReadHeader(GenericFD* pGFD, DC42Header* pHeader)
/*static*/ int WrapperDiskCopy42::ReadHeader(GenericFD* pGFD, DC42Header* pHeader)
{
unsigned char hdrBuf[kDC42DataOffset];
uint8_t hdrBuf[kDC42DataOffset];
if (pGFD->Read(hdrBuf, kDC42DataOffset) != kDIErrNone)
return -1;
@ -1153,10 +1132,9 @@ WrapperDiskCopy42::ReadHeader(GenericFD* pGFD, DC42Header* pHeader)
/*
* Write the header for a DC42 file.
*/
DIError
WrapperDiskCopy42::WriteHeader(GenericFD* pGFD, const DC42Header* pHeader)
DIError WrapperDiskCopy42::WriteHeader(GenericFD* pGFD, const DC42Header* pHeader)
{
unsigned char hdrBuf[kDC42DataOffset];
uint8_t hdrBuf[kDC42DataOffset];
pGFD->Rewind();
@ -1190,8 +1168,7 @@ WrapperDiskCopy42::WriteHeader(GenericFD* pGFD, const DC42Header* pHeader)
* about our interpretation of some of the header fields (e.g. we only
* recognize 800K disks) we should be okay.
*/
/*static*/ DIError
WrapperDiskCopy42::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*static*/ DIError WrapperDiskCopy42::Test(GenericFD* pGFD, di_off_t wrappedLength)
{
DC42Header header;
@ -1214,14 +1191,12 @@ WrapperDiskCopy42::Test(GenericFD* pGFD, di_off_t wrappedLength)
*
* Position "pGFD" at the start of data.
*/
/*static*/ DIError
WrapperDiskCopy42::ComputeChecksum(GenericFD* pGFD,
unsigned long* pChecksum)
/*static*/ DIError WrapperDiskCopy42::ComputeChecksum(GenericFD* pGFD, uint32_t* pChecksum)
{
DIError dierr = kDIErrNone;
unsigned char buf[512];
uint8_t buf[512];
long dataRem = 800 * 1024 /*pHeader->dataSize*/;
unsigned long checksum;
uint32_t checksum;
assert(dataRem % sizeof(buf) == 0);
assert((sizeof(buf) & 0x01) == 0); // we take it two bytes at a time
@ -1237,7 +1212,7 @@ WrapperDiskCopy42::ComputeChecksum(GenericFD* pGFD,
}
for (i = 0; i < (int) sizeof(buf); i += 2) {
unsigned short val = GetShortBE(buf+i);
uint16_t val = GetShortBE(buf+i);
checksum += val;
if (checksum & 0x01)
@ -1257,9 +1232,8 @@ WrapperDiskCopy42::ComputeChecksum(GenericFD* pGFD,
/*
* Prepare a DiskCopy image for use.
*/
DIError
WrapperDiskCopy42::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DIError WrapperDiskCopy42::Prep(GenericFD* pGFD, di_off_t wrappedLength,
bool readOnly, di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DiskImg::SectorOrder* pOrder, short* pDiskVolNum,
LinearBitmap** ppBadBlockMap, GenericFD** ppNewGFD)
{
@ -1274,7 +1248,7 @@ WrapperDiskCopy42::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
/*
* Verify checksum. File should already be seeked to appropriate place.
*/
unsigned long checksum;
uint32_t checksum;
dierr = ComputeChecksum(pGFD, &checksum);
if (dierr != kDIErrNone)
return dierr;
@ -1302,8 +1276,7 @@ WrapperDiskCopy42::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
/*
* Initialize fields for a new file.
*/
DIError
WrapperDiskCopy42::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DIError WrapperDiskCopy42::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DiskImg::SectorOrder order, short dosVolumeNum, GenericFD* pWrapperGFD,
di_off_t* pWrappedLength, GenericFD** pDataFD)
{
@ -1331,12 +1304,11 @@ WrapperDiskCopy42::Create(di_off_t length, DiskImg::PhysicalFormat physical,
* We only use GFDGFD, so there's no data to write. However, we do need
* to update the checksum, and append our "fake" tag section.
*/
DIError
WrapperDiskCopy42::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
DIError WrapperDiskCopy42::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
di_off_t dataLen, di_off_t* pWrappedLen)
{
DIError dierr;
unsigned long checksum;
uint32_t checksum;
/* compute the data checksum */
dierr = pWrapperGFD->Seek(kDC42DataOffset, kSeekSet);
@ -1411,8 +1383,7 @@ static const char* kSim2eID = "SIMSYSTEM_HDV";
* Test for a virtual hard-drive image. This is either a "raw" unadorned
* image, or one with a 15-byte "SimIIe" header on it.
*/
DIError
WrapperSim2eHDV::Test(GenericFD* pGFD, di_off_t wrappedLength)
DIError WrapperSim2eHDV::Test(GenericFD* pGFD, di_off_t wrappedLength)
{
char buf[kSim2eHeaderLen];
@ -1438,9 +1409,8 @@ WrapperSim2eHDV::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*
* These are always ProDOS volumes.
*/
DIError
WrapperSim2eHDV::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DIError WrapperSim2eHDV::Prep(GenericFD* pGFD, di_off_t wrappedLength,
bool readOnly, di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DiskImg::SectorOrder* pOrder, short* pDiskVolNum,
LinearBitmap** ppBadBlockMap, GenericFD** ppNewGFD)
{
@ -1455,12 +1425,11 @@ WrapperSim2eHDV::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
/*
* Initialize fields for a new file.
*/
DIError
WrapperSim2eHDV::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DIError WrapperSim2eHDV::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DiskImg::SectorOrder order, short dosVolumeNum, GenericFD* pWrapperGFD,
di_off_t* pWrappedLength, GenericFD** pDataFD)
{
unsigned char header[kSim2eHeaderLen];
uint8_t header[kSim2eHeaderLen];
long blocks = (long) (length / 512);
assert(physical == DiskImg::kPhysicalFormatSectors);
@ -1474,8 +1443,8 @@ WrapperSim2eHDV::Create(di_off_t length, DiskImg::PhysicalFormat physical,
blocks = 65535;
memcpy(header, kSim2eID, strlen(kSim2eID));
header[13] = (unsigned char) blocks;
header[14] = (unsigned char) ((blocks & 0xff00) >> 8);
header[13] = (uint8_t) blocks;
header[14] = (uint8_t) ((blocks & 0xff00) >> 8);
DIError dierr = pWrapperGFD->Write(header, kSim2eHeaderLen);
if (dierr != kDIErrNone) {
LOGI(" Sim2eHDV header write failed (err=%d)", dierr);
@ -1491,8 +1460,7 @@ WrapperSim2eHDV::Create(di_off_t length, DiskImg::PhysicalFormat physical,
/*
* We only use GFDGFD, so there's nothing to do here.
*/
DIError
WrapperSim2eHDV::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
DIError WrapperSim2eHDV::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
di_off_t dataLen, di_off_t* pWrappedLen)
{
return kDIErrNone;
@ -1553,8 +1521,7 @@ WrapperSim2eHDV::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
*
* There is currently no way for the API to set the number of tracks.
*/
/*static*/ DIError
WrapperTrackStar::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*static*/ DIError WrapperTrackStar::Test(GenericFD* pGFD, di_off_t wrappedLength)
{
DIError dierr = kDIErrNone;
LOGI("Testing for TrackStar");
@ -1571,7 +1538,7 @@ WrapperTrackStar::Test(GenericFD* pGFD, di_off_t wrappedLength)
LOGI(" Checking for %d-track image", numTracks);
/* verify each track */
unsigned char trackBuf[kFileTrackStorageLen];
uint8_t trackBuf[kFileTrackStorageLen];
pGFD->Rewind();
for (int trk = 0; trk < numTracks; trk++) {
dierr = pGFD->Read(trackBuf, sizeof(trackBuf));
@ -1590,8 +1557,7 @@ bail:
/*
* Check the format.
*/
/*static*/ DIError
WrapperTrackStar::VerifyTrack(int track, const unsigned char* trackBuf)
/*static*/ DIError WrapperTrackStar::VerifyTrack(int track, const uint8_t* trackBuf)
{
unsigned int dataLen;
@ -1628,9 +1594,8 @@ WrapperTrackStar::VerifyTrack(int track, const unsigned char* trackBuf)
/*
* Fill in some details.
*/
DIError
WrapperTrackStar::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DIError WrapperTrackStar::Prep(GenericFD* pGFD, di_off_t wrappedLength,
bool readOnly, di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DiskImg::SectorOrder* pOrder, short* pDiskVolNum,
LinearBitmap** ppBadBlockMap, GenericFD** ppNewGFD)
{
@ -1659,16 +1624,15 @@ WrapperTrackStar::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
* Unpack reverse-order nibbles from "pGFD" to a new memory buffer
* created in "*ppNewGFD".
*/
DIError
WrapperTrackStar::Unpack(GenericFD* pGFD, GenericFD** ppNewGFD)
DIError WrapperTrackStar::Unpack(GenericFD* pGFD, GenericFD** ppNewGFD)
{
DIError dierr;
GFDBuffer* pNewGFD = NULL;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
pGFD->Rewind();
buf = new unsigned char[kTrackStarNumTracks * kTrackAllocSize];
buf = new uint8_t[kTrackStarNumTracks * kTrackAllocSize];
if (buf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -1712,12 +1676,11 @@ bail:
*
* This fills out "fNibbleTrackInfo".
*/
DIError
WrapperTrackStar::UnpackDisk(GenericFD* pGFD, GenericFD* pNewGFD)
DIError WrapperTrackStar::UnpackDisk(GenericFD* pGFD, GenericFD* pNewGFD)
{
DIError dierr = kDIErrNone;
unsigned char inBuf[kFileTrackStorageLen];
unsigned char outBuf[kTrackAllocSize];
uint8_t inBuf[kFileTrackStorageLen];
uint8_t outBuf[kTrackAllocSize];
int i, trk;
assert(kTrackStarNumTracks <= kMaxNibbleTracks525);
@ -1768,8 +1731,7 @@ bail:
* Initialize stuff for a new file. There's no file header or other
* goodies, so we leave "pWrapperGFD" and "pWrappedLength" alone.
*/
DIError
WrapperTrackStar::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DIError WrapperTrackStar::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DiskImg::SectorOrder order, short dosVolumeNum, GenericFD* pWrapperGFD,
di_off_t* pWrappedLength, GenericFD** pDataFD)
{
@ -1779,7 +1741,7 @@ WrapperTrackStar::Create(di_off_t length, DiskImg::PhysicalFormat physical,
assert(order == DiskImg::kSectorOrderPhysical);
DIError dierr;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
int numTracks = (int) (length / kTrackLenTrackStar525);
int i;
@ -1798,7 +1760,7 @@ WrapperTrackStar::Create(di_off_t length, DiskImg::PhysicalFormat physical,
/*
* Create a blank chunk of memory for the image.
*/
buf = new unsigned char[(int) length];
buf = new uint8_t[(int) length];
if (buf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -1827,8 +1789,7 @@ bail:
* The source data is in "pDataGFD" in a layout described by fNibbleTrackInfo.
* We need to create the new file in "pWrapperGFD".
*/
DIError
WrapperTrackStar::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
DIError WrapperTrackStar::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
di_off_t dataLen, di_off_t* pWrappedLen)
{
DIError dierr = kDIErrNone;
@ -1839,8 +1800,8 @@ WrapperTrackStar::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
pDataGFD->Rewind();
unsigned char writeBuf[kFileTrackStorageLen];
unsigned char dataBuf[kTrackLenTrackStar525];
uint8_t writeBuf[kFileTrackStorageLen];
uint8_t dataBuf[kTrackLenTrackStar525];
int track, trackLen;
for (track = 0; track < kTrackStarNumTracks; track++) {
@ -1883,7 +1844,7 @@ WrapperTrackStar::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
if (trackLen == kMaxTrackLen)
PutShortLE(writeBuf + 0x19fe, 0);
else
PutShortLE(writeBuf + 0x19fe, (unsigned short) trackLen);
PutShortLE(writeBuf + 0x19fe, (uint16_t) trackLen);
dierr = pWrapperGFD->Write(writeBuf, sizeof(writeBuf));
if (dierr != kDIErrNone)
@ -1897,8 +1858,7 @@ bail:
return dierr;
}
void
WrapperTrackStar::SetNibbleTrackLength(int track, int length)
void WrapperTrackStar::SetNibbleTrackLength(int track, int length)
{
assert(track >= 0);
assert(length > 0 && length <= kMaxTrackLen);
@ -1930,11 +1890,10 @@ WrapperTrackStar::SetNibbleTrackLength(int track, int length)
/*
* Test to see if this is an FDI disk image.
*/
/*static*/ DIError
WrapperFDI::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*static*/ DIError WrapperFDI::Test(GenericFD* pGFD, di_off_t wrappedLength)
{
DIError dierr = kDIErrNone;
unsigned char headerBuf[kMinHeaderLen];
uint8_t headerBuf[kMinHeaderLen];
FDIHeader hdr;
LOGI("Testing for FDI");
@ -1961,8 +1920,7 @@ bail:
/*
* Unpack a 512-byte buffer with the FDI header into its components.
*/
/*static*/ void
WrapperFDI::UnpackHeader(const unsigned char* headerBuf, FDIHeader* pHdr)
/*static*/ void WrapperFDI::UnpackHeader(const uint8_t* headerBuf, FDIHeader* pHdr)
{
memcpy(pHdr->signature, &headerBuf[0], kSignatureLen);
pHdr->signature[kSignatureLen] = '\0';
@ -1985,8 +1943,7 @@ WrapperFDI::UnpackHeader(const unsigned char* headerBuf, FDIHeader* pHdr)
/*
* Dump the contents of an FDI header.
*/
/*static*/ void
WrapperFDI::DumpHeader(const FDIHeader* pHdr)
/*static*/ void WrapperFDI::DumpHeader(const FDIHeader* pHdr)
{
static const char* kTypes[] = {
"8\"", "5.25\"", "3.5\"", "3\""
@ -2019,8 +1976,7 @@ WrapperFDI::DumpHeader(const FDIHeader* pHdr)
/*
* Unpack the disk to heap storage.
*/
DIError
WrapperFDI::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
DIError WrapperFDI::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DiskImg::SectorOrder* pOrder, short* pDiskVolNum,
LinearBitmap** ppBadBlockMap, GenericFD** ppNewGFD)
@ -2113,13 +2069,12 @@ bail:
/*
* Unpack pulse timing values to nibbles.
*/
DIError
WrapperFDI::Unpack525(GenericFD* pGFD, GenericFD** ppNewGFD, int numCyls,
DIError WrapperFDI::Unpack525(GenericFD* pGFD, GenericFD** ppNewGFD, int numCyls,
int numHeads)
{
DIError dierr = kDIErrNone;
GFDBuffer* pNewGFD = NULL;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
int numTracks;
numTracks = numCyls * numHeads;
@ -2128,7 +2083,7 @@ WrapperFDI::Unpack525(GenericFD* pGFD, GenericFD** ppNewGFD, int numCyls,
pGFD->Rewind();
buf = new unsigned char[numTracks * kTrackAllocSize];
buf = new uint8_t[numTracks * kTrackAllocSize];
if (buf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -2161,17 +2116,16 @@ bail:
/*
* Unpack pulse timing values to fully-decoded blocks.
*/
DIError
WrapperFDI::Unpack35(GenericFD* pGFD, GenericFD** ppNewGFD, int numCyls,
DIError WrapperFDI::Unpack35(GenericFD* pGFD, GenericFD** ppNewGFD, int numCyls,
int numHeads, LinearBitmap** ppBadBlockMap)
{
DIError dierr = kDIErrNone;
GFDBuffer* pNewGFD = NULL;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
pGFD->Rewind();
buf = new unsigned char[800 * 1024];
buf = new uint8_t[800 * 1024];
if (buf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -2210,14 +2164,13 @@ bail:
* Initialize stuff for a new file. There's no file header or other
* goodies, so we leave "pWrapperGFD" and "pWrappedLength" alone.
*/
DIError
WrapperFDI::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DIError WrapperFDI::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DiskImg::SectorOrder order, short dosVolumeNum, GenericFD* pWrapperGFD,
di_off_t* pWrappedLength, GenericFD** pDataFD)
{
DIError dierr = kDIErrGeneric; // not yet
#if 0
unsigned char* buf = NULL;
uint8_t* buf = NULL;
int numTracks = (int) (length / kTrackLenTrackStar525);
int i;
@ -2241,7 +2194,7 @@ WrapperFDI::Create(di_off_t length, DiskImg::PhysicalFormat physical,
/*
* Create a blank chunk of memory for the image.
*/
buf = new unsigned char[(int) length];
buf = new uint8_t[(int) length];
if (buf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -2271,8 +2224,7 @@ bail:
* The source data is in "pDataGFD" in a layout described by fNibbleTrackInfo.
* We need to create the new file in "pWrapperGFD".
*/
DIError
WrapperFDI::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
DIError WrapperFDI::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
di_off_t dataLen, di_off_t* pWrappedLen)
{
DIError dierr = kDIErrGeneric; // not yet
@ -2284,8 +2236,8 @@ WrapperFDI::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
pDataGFD->Rewind();
unsigned char writeBuf[kFileTrackStorageLen];
unsigned char dataBuf[kTrackLenTrackStar525];
uint8_t writeBuf[kFileTrackStorageLen];
uint8_t dataBuf[kTrackLenTrackStar525];
int track, trackLen;
for (track = 0; track < kTrackStarNumTracks; track++) {
@ -2322,7 +2274,7 @@ WrapperFDI::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
if (trackLen == kMaxTrackLen)
PutShortLE(writeBuf + 0x19fe, 0);
else
PutShortLE(writeBuf + 0x19fe, (unsigned short) trackLen);
PutShortLE(writeBuf + 0x19fe, (uint16_t) trackLen);
dierr = pWrapperGFD->Write(writeBuf, sizeof(writeBuf));
if (dierr != kDIErrNone)
@ -2337,8 +2289,7 @@ bail:
return dierr;
}
void
WrapperFDI::SetNibbleTrackLength(int track, int length)
void WrapperFDI::SetNibbleTrackLength(int track, int length)
{
assert(false); // not yet
#if 0
@ -2361,8 +2312,8 @@ WrapperFDI::SetNibbleTrackLength(int track, int length)
/*
* See if this is unadorned nibble format.
*/
/*static*/ DIError
WrapperUnadornedNibble::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*static*/ DIError WrapperUnadornedNibble::Test(GenericFD* pGFD,
di_off_t wrappedLength)
{
LOGI("Testing for unadorned nibble");
@ -2375,7 +2326,7 @@ WrapperUnadornedNibble::Test(GenericFD* pGFD, di_off_t wrappedLength)
/* quick scan for invalid data */
const int kScanSize = 512;
unsigned char buf[kScanSize];
uint8_t buf[kScanSize];
pGFD->Rewind();
if (pGFD->Read(buf, sizeof(buf)) != kDIErrNone)
@ -2389,11 +2340,11 @@ WrapperUnadornedNibble::Test(GenericFD* pGFD, di_off_t wrappedLength)
*/
for (int i = 0; i < kScanSize; i++) {
if (buf[i] < 0x80) {
LOGI(" Disqualifying len=%ld from nibble, byte=0x%02x",
LOGD(" Disqualifying len=%ld from nibble, byte=0x%02x",
(long) wrappedLength, buf[i]);
return kDIErrGeneric;
} else if (buf[i] < 0x96) {
LOGI(" Warning: funky byte 0x%02x in file", buf[i]);
LOGD(" Warning: funky byte 0x%02x in file", buf[i]);
}
}
@ -2403,9 +2354,8 @@ WrapperUnadornedNibble::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*
* Prepare unadorned nibble for use. Not much to do here.
*/
DIError
WrapperUnadornedNibble::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DIError WrapperUnadornedNibble::Prep(GenericFD* pGFD, di_off_t wrappedLength,
bool readOnly, di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DiskImg::SectorOrder* pOrder, short* pDiskVolNum,
LinearBitmap** ppBadBlockMap, GenericFD** ppNewGFD)
{
@ -2433,9 +2383,9 @@ WrapperUnadornedNibble::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readO
/*
* Initialize fields for a new file.
*/
DIError
WrapperUnadornedNibble::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DiskImg::SectorOrder order, short dosVolumeNum, GenericFD* pWrapperGFD,
DIError WrapperUnadornedNibble::Create(di_off_t length,
DiskImg::PhysicalFormat physical, DiskImg::SectorOrder order,
short dosVolumeNum, GenericFD* pWrapperGFD,
di_off_t* pWrappedLength, GenericFD** pDataFD)
{
LOGI("Create unadorned nibble");
@ -2448,8 +2398,7 @@ WrapperUnadornedNibble::Create(di_off_t length, DiskImg::PhysicalFormat physical
/*
* We only use GFDGFD, so there's nothing to do here.
*/
DIError
WrapperUnadornedNibble::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
DIError WrapperUnadornedNibble::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
di_off_t dataLen, di_off_t* pWrappedLen)
{
return kDIErrNone;
@ -2473,11 +2422,10 @@ WrapperUnadornedNibble::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
* It also holds for 35-track 6656-byte unadorned nibble images, so we need
* to test for them first.
*/
/*static*/ DIError
WrapperUnadornedSector::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*static*/ DIError WrapperUnadornedSector::Test(GenericFD* pGFD, di_off_t wrappedLength)
{
LOGI("Testing for unadorned sector (wrappedLength=%ld/%lu)",
(long) (wrappedLength >> 32), (unsigned long) wrappedLength);
(long) (wrappedLength >> 32), (uint32_t) wrappedLength);
if (wrappedLength >= 1536 && (wrappedLength % 512) == 0)
return kDIErrNone;
if (wrappedLength == kD13Length) // 13-sector image?
@ -2489,9 +2437,8 @@ WrapperUnadornedSector::Test(GenericFD* pGFD, di_off_t wrappedLength)
/*
* Prepare unadorned sector for use. Not much to do here.
*/
DIError
WrapperUnadornedSector::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readOnly,
di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DIError WrapperUnadornedSector::Prep(GenericFD* pGFD, di_off_t wrappedLength,
bool readOnly, di_off_t* pLength, DiskImg::PhysicalFormat* pPhysical,
DiskImg::SectorOrder* pOrder, short* pDiskVolNum,
LinearBitmap** ppBadBlockMap, GenericFD** ppNewGFD)
{
@ -2508,8 +2455,7 @@ WrapperUnadornedSector::Prep(GenericFD* pGFD, di_off_t wrappedLength, bool readO
/*
* Initialize fields for a new file.
*/
DIError
WrapperUnadornedSector::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DIError WrapperUnadornedSector::Create(di_off_t length, DiskImg::PhysicalFormat physical,
DiskImg::SectorOrder order, short dosVolumeNum, GenericFD* pWrapperGFD,
di_off_t* pWrappedLength, GenericFD** pDataFD)
{
@ -2523,8 +2469,7 @@ WrapperUnadornedSector::Create(di_off_t length, DiskImg::PhysicalFormat physical
/*
* We only use GFDGFD, so there's nothing to do here.
*/
DIError
WrapperUnadornedSector::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
DIError WrapperUnadornedSector::Flush(GenericFD* pWrapperGFD, GenericFD* pDataGFD,
di_off_t dataLen, di_off_t* pWrappedLen)
{
return kDIErrNone;

View File

@ -21,43 +21,43 @@ const int kPartMapStart = 1; // start of partition map
* Format of DDR (block 0).
*/
typedef struct DiskFSMacPart::DriverDescriptorRecord {
unsigned short sbSig; // {device signature}
unsigned short sbBlkSize; // {block size of the device}
unsigned long sbBlkCount; // {number of blocks on the device}
unsigned short sbDevType; // {reserved}
unsigned short sbDevId; // {reserved}
unsigned long sbData; // {reserved}
unsigned short sbDrvrCount; // {number of driver descriptor entries}
unsigned short hiddenPad; // implicit in specification
unsigned long ddBlock; // {first driver's starting block}
unsigned short ddSize; // {size of the driver, in 512-byte blocks}
unsigned short ddType; // {operating system type (MacOS = 1)}
unsigned short ddPad[242]; // {additional drivers, if any}
uint16_t sbSig; // {device signature}
uint16_t sbBlkSize; // {block size of the device}
uint32_t sbBlkCount; // {number of blocks on the device}
uint16_t sbDevType; // {reserved}
uint16_t sbDevId; // {reserved}
uint32_t sbData; // {reserved}
uint16_t sbDrvrCount; // {number of driver descriptor entries}
uint16_t hiddenPad; // implicit in specification
uint32_t ddBlock; // {first driver's starting block}
uint16_t ddSize; // {size of the driver, in 512-byte blocks}
uint16_t ddType; // {operating system type (MacOS = 1)}
uint16_t ddPad[242]; // {additional drivers, if any}
} DriverDescriptorRecord;
/*
* Format of partition map blocks. The partition map is an array of these.
*/
typedef struct DiskFSMacPart::PartitionMap {
unsigned short pmSig; // {partition signature}
unsigned short pmSigPad; // {reserved}
unsigned long pmMapBlkCnt; // {number of blocks in partition map}
unsigned long pmPyPartStart; // {first physical block of partition}
unsigned long pmPartBlkCnt; // {number of blocks in partition}
unsigned char pmPartName[32]; // {partition name}
unsigned char pmParType[32]; // {partition type}
unsigned long pmLgDataStart; // {first logical block of data area}
unsigned long pmDataCnt; // {number of blocks in data area}
unsigned long pmPartStatus; // {partition status information}
unsigned long pmLgBootStart; // {first logical block of boot code}
unsigned long pmBootSize; // {size of boot code, in bytes}
unsigned long pmBootAddr; // {boot code load address}
unsigned long pmBootAddr2; // {reserved}
unsigned long pmBootEntry; // {boot code entry point}
unsigned long pmBootEntry2; // {reserved}
unsigned long pmBootCksum; // {boot code checksum}
unsigned char pmProcessor[16]; // {processor type}
unsigned short pmPad[188]; // {reserved}
uint16_t pmSig; // {partition signature}
uint16_t pmSigPad; // {reserved}
uint32_t pmMapBlkCnt; // {number of blocks in partition map}
uint32_t pmPyPartStart; // {first physical block of partition}
uint32_t pmPartBlkCnt; // {number of blocks in partition}
uint8_t pmPartName[32]; // {partition name}
uint8_t pmParType[32]; // {partition type}
uint32_t pmLgDataStart; // {first logical block of data area}
uint32_t pmDataCnt; // {number of blocks in data area}
uint32_t pmPartStatus; // {partition status information}
uint32_t pmLgBootStart; // {first logical block of boot code}
uint32_t pmBootSize; // {size of boot code, in bytes}
uint32_t pmBootAddr; // {boot code load address}
uint32_t pmBootAddr2; // {reserved}
uint32_t pmBootEntry; // {boot code entry point}
uint32_t pmBootEntry2; // {reserved}
uint32_t pmBootCksum; // {boot code checksum}
uint8_t pmProcessor[16]; // {processor type}
uint16_t pmPad[188]; // {reserved}
} PartitionMap;
@ -70,11 +70,11 @@ typedef struct DiskFSMacPart::PartitionMap {
* It would be difficult to guess the block order based on the partition
* structure, because the partition map entries can appear in any order.
*/
/*static*/ DIError
DiskFSMacPart::TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
/*static*/ DIError DiskFSMacPart::TestImage(DiskImg* pImg,
DiskImg::SectorOrder imageOrder)
{
DIError dierr = kDIErrNone;
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
DriverDescriptorRecord ddr;
long pmMapBlkCnt;
@ -146,8 +146,7 @@ bail:
/*
* Unpack a DDR disk block into a DDR data structure.
*/
/*static*/ void
DiskFSMacPart::UnpackDDR(const unsigned char* buf,
/*static*/ void DiskFSMacPart::UnpackDDR(const uint8_t* buf,
DriverDescriptorRecord* pDDR)
{
pDDR->sbSig = GetShortBE(&buf[0x00]);
@ -172,8 +171,7 @@ DiskFSMacPart::UnpackDDR(const unsigned char* buf,
/*
* Debug: dump the contents of the DDR.
*/
/*static*/ void
DiskFSMacPart::DumpDDR(const DriverDescriptorRecord* pDDR)
/*static*/ void DiskFSMacPart::DumpDDR(const DriverDescriptorRecord* pDDR)
{
LOGI(" MacPart driver descriptor record");
LOGI(" sbSig=0x%04x sbBlkSize=%d sbBlkCount=%ld",
@ -187,8 +185,7 @@ DiskFSMacPart::DumpDDR(const DriverDescriptorRecord* pDDR)
/*
* Unpack a partition map disk block into a partition map data structure.
*/
/*static*/ void
DiskFSMacPart::UnpackPartitionMap(const unsigned char* buf,
/*static*/ void DiskFSMacPart::UnpackPartitionMap(const uint8_t* buf,
PartitionMap* pMap)
{
pMap->pmSig = GetShortBE(&buf[0x00]);
@ -223,8 +220,7 @@ DiskFSMacPart::UnpackPartitionMap(const unsigned char* buf,
/*
* Debug: dump the contents of the partition map.
*/
/*static*/ void
DiskFSMacPart::DumpPartitionMap(long block, const PartitionMap* pMap)
/*static*/ void DiskFSMacPart::DumpPartitionMap(long block, const PartitionMap* pMap)
{
LOGI(" MacPart partition map: block=%ld", block);
LOGI(" pmSig=0x%04x (pad=0x%04x) pmMapBlkCnt=%ld",
@ -250,8 +246,7 @@ DiskFSMacPart::DumpPartitionMap(long block, const PartitionMap* pMap)
/*
* Open up a sub-volume.
*/
DIError
DiskFSMacPart::OpenSubVolume(const PartitionMap* pMap)
DIError DiskFSMacPart::OpenSubVolume(const PartitionMap* pMap)
{
DIError dierr = kDIErrNone;
DiskFS* pNewFS = NULL;
@ -380,8 +375,7 @@ bail:
/*
* Check to see if this is a MacPart volume.
*/
/*static*/ DIError
DiskFSMacPart::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSMacPart::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
if (pImg->GetNumBlocks() < kMinInterestingBlocks)
@ -400,12 +394,10 @@ DiskFSMacPart::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
return kDIErrFilesystemNotFound;
}
/*
* Prep the MacPart "container" for use.
*/
DIError
DiskFSMacPart::Initialize(void)
DIError DiskFSMacPart::Initialize(void)
{
DIError dierr = kDIErrNone;
@ -424,18 +416,16 @@ DiskFSMacPart::Initialize(void)
return dierr;
}
/*
* Find the various sub-volumes and open them.
*
* Because the partitions are explicitly typed, we don't need to probe
* their contents. But we do anyway.
*/
DIError
DiskFSMacPart::FindSubVolumes(void)
DIError DiskFSMacPart::FindSubVolumes(void)
{
DIError dierr = kDIErrNone;
unsigned char buf[kBlkSize];
uint8_t buf[kBlkSize];
PartitionMap map;
int i, numMapBlocks;

View File

@ -15,7 +15,7 @@
const int kBlkSize = 512;
const int kPartMapBlock = 0; // partition map lives here
const unsigned int kPartSizeMask = 0x00ffffff;
const uint32_t kPartSizeMask = 0x00ffffff;
/*
@ -45,24 +45,24 @@ const unsigned int kPartSizeMask = 0x00ffffff;
*/
const int kMaxNumParts = 8;
typedef struct DiskFSMicroDrive::PartitionMap {
unsigned short magic; // partition signature
unsigned short cylinders; // #of cylinders
unsigned short reserved1; // ??
unsigned short heads; // #of heads/cylinder
unsigned short sectors; // #of sectors/track
unsigned short reserved2; // ??
unsigned char numPart1; // #of partitions in first chunk
unsigned char numPart2; // #of partitions in second chunk
unsigned char reserved3[10]; // bytes 0x0e-0x17
unsigned short romVersion; // IIgs ROM01 or ROM03
unsigned char reserved4[6]; // bytes 0x1a-0x1f
unsigned long partitionStart1[kMaxNumParts]; // bytes 0x20-0x3f
unsigned long partitionLength1[kMaxNumParts]; // bytes 0x40-0x5f
unsigned char reserved5[32]; // bytes 0x60-0x7f
unsigned long partitionStart2[kMaxNumParts]; // bytes 0x80-0x9f
unsigned long partitionLength2[kMaxNumParts]; // bytes 0xa0-0xbf
uint16_t magic; // partition signature
uint16_t cylinders; // #of cylinders
uint16_t reserved1; // ??
uint16_t heads; // #of heads/cylinder
uint16_t sectors; // #of sectors/track
uint16_t reserved2; // ??
uint8_t numPart1; // #of partitions in first chunk
uint8_t numPart2; // #of partitions in second chunk
uint8_t reserved3[10]; // bytes 0x0e-0x17
uint16_t romVersion; // IIgs ROM01 or ROM03
uint8_t reserved4[6]; // bytes 0x1a-0x1f
uint32_t partitionStart1[kMaxNumParts]; // bytes 0x20-0x3f
uint32_t partitionLength1[kMaxNumParts]; // bytes 0x40-0x5f
uint8_t reserved5[32]; // bytes 0x60-0x7f
uint32_t partitionStart2[kMaxNumParts]; // bytes 0x80-0x9f
uint32_t partitionLength2[kMaxNumParts]; // bytes 0xa0-0xbf
unsigned char padding[320];
uint8_t padding[320];
} PartitionMap;
@ -72,11 +72,11 @@ typedef struct DiskFSMicroDrive::PartitionMap {
* The "imageOrder" parameter has no use here, because (in the current
* version) embedded parent volumes are implicitly ProDOS-ordered.
*/
/*static*/ DIError
DiskFSMicroDrive::TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
/*static*/ DIError DiskFSMicroDrive::TestImage(DiskImg* pImg,
DiskImg::SectorOrder imageOrder)
{
DIError dierr = kDIErrNone;
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
int partCount1, partCount2;
assert(sizeof(PartitionMap) == kBlkSize);
@ -119,8 +119,7 @@ bail:
/*
* Unpack a partition map block into a partition map data structure.
*/
/*static*/ void
DiskFSMicroDrive::UnpackPartitionMap(const unsigned char* buf,
/*static*/ void DiskFSMicroDrive::UnpackPartitionMap(const uint8_t* buf,
PartitionMap* pMap)
{
pMap->magic = GetShortLE(&buf[0x00]);
@ -148,8 +147,7 @@ DiskFSMicroDrive::UnpackPartitionMap(const unsigned char* buf,
/*
* Debug: dump the contents of the partition map.
*/
/*static*/ void
DiskFSMicroDrive::DumpPartitionMap(const PartitionMap* pMap)
/*static*/ void DiskFSMicroDrive::DumpPartitionMap(const PartitionMap* pMap)
{
LOGI(" MicroDrive partition map:");
LOGI(" cyls=%d res1=%d heads=%d sects=%d",
@ -178,8 +176,7 @@ DiskFSMicroDrive::DumpPartitionMap(const PartitionMap* pMap)
/*
* Open up a sub-volume.
*/
DIError
DiskFSMicroDrive::OpenSubVolume(long startBlock, long numBlocks)
DIError DiskFSMicroDrive::OpenSubVolume(long startBlock, long numBlocks)
{
DIError dierr = kDIErrNone;
DiskFS* pNewFS = NULL;
@ -289,8 +286,7 @@ bail:
/*
* Check to see if this is a MicroDrive volume.
*/
/*static*/ DIError
DiskFSMicroDrive::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSMicroDrive::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
if (pImg->GetNumBlocks() < kMinInterestingBlocks)
@ -313,8 +309,7 @@ DiskFSMicroDrive::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*
* Prep the MicroDrive "container" for use.
*/
DIError
DiskFSMicroDrive::Initialize(void)
DIError DiskFSMicroDrive::Initialize(void)
{
DIError dierr = kDIErrNone;
@ -337,11 +332,10 @@ DiskFSMicroDrive::Initialize(void)
/*
* Find the various sub-volumes and open them.
*/
DIError
DiskFSMicroDrive::FindSubVolumes(void)
DIError DiskFSMicroDrive::FindSubVolumes(void)
{
DIError dierr = kDIErrNone;
unsigned char buf[kBlkSize];
uint8_t buf[kBlkSize];
PartitionMap map;
int i;
@ -375,8 +369,7 @@ bail:
* Open the volume. If it fails, open a placeholder instead. (If *that*
* fails, return with an error.)
*/
DIError
DiskFSMicroDrive::OpenVol(int idx, long startBlock, long numBlocks)
DIError DiskFSMicroDrive::OpenVol(int idx, long startBlock, long numBlocks)
{
DIError dierr;
@ -387,13 +380,13 @@ DiskFSMicroDrive::OpenVol(int idx, long startBlock, long numBlocks)
DiskFS* pNewFS = NULL;
DiskImg* pNewImg = NULL;
LOGI(" MicroDrive failed opening sub-volume %d", idx);
LOGW(" MicroDrive failed opening sub-volume %d", idx);
dierr = CreatePlaceholder(startBlock, numBlocks, NULL, NULL,
&pNewImg, &pNewFS);
if (dierr == kDIErrNone) {
AddSubVolumeToList(pNewImg, pNewFS);
} else {
LOGI(" MicroDrive unable to create placeholder (err=%d)",
LOGE(" MicroDrive unable to create placeholder (err=%d)",
dierr);
// fall out with error
}

View File

@ -19,13 +19,13 @@
* ===========================================================================
*/
/*static*/ unsigned char DiskImg::kDiskBytes53[32] = {
/*static*/ uint8_t DiskImg::kDiskBytes53[32] = {
0xab, 0xad, 0xae, 0xaf, 0xb5, 0xb6, 0xb7, 0xba,
0xbb, 0xbd, 0xbe, 0xbf, 0xd6, 0xd7, 0xda, 0xdb,
0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xed, 0xee, 0xef,
0xf5, 0xf6, 0xf7, 0xfa, 0xfb, 0xfd, 0xfe, 0xff
};
/*static*/ unsigned char DiskImg::kDiskBytes62[64] = {
/*static*/ uint8_t DiskImg::kDiskBytes62[64] = {
0x96, 0x97, 0x9a, 0x9b, 0x9d, 0x9e, 0x9f, 0xa6,
0xa7, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb2, 0xb3,
0xb4, 0xb5, 0xb6, 0xb7, 0xb9, 0xba, 0xbb, 0xbc,
@ -35,16 +35,15 @@
0xed, 0xee, 0xef, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
0xf7, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
/*static*/ unsigned char DiskImg::kInvDiskBytes53[256]; // all values are 0-31
/*static*/ unsigned char DiskImg::kInvDiskBytes62[256]; // all values are 0-63
/*static*/ uint8_t DiskImg::kInvDiskBytes53[256]; // all values are 0-31
/*static*/ uint8_t DiskImg::kInvDiskBytes62[256]; // all values are 0-63
/*
* Compute tables to convert disk bytes back to values.
*
* Should be called once, at DLL initialization time.
*/
/*static*/ void
DiskImg::CalcNibbleInvTables(void)
/*static*/ void DiskImg::CalcNibbleInvTables(void)
{
unsigned int i;
@ -66,8 +65,7 @@ DiskImg::CalcNibbleInvTables(void)
*
* Returns the index start on success or -1 on failure.
*/
int
DiskImg::FindNibbleSectorStart(const CircularBufferAccess& buffer, int track,
int DiskImg::FindNibbleSectorStart(const CircularBufferAccess& buffer, int track,
int sector, const NibbleDescr* pNibbleDescr, int* pVol)
{
const int kMaxDataReach = 48; // fairly arbitrary
@ -178,8 +176,7 @@ DiskImg::FindNibbleSectorStart(const CircularBufferAccess& buffer, int track,
/*
* Decode the values in the address field.
*/
void
DiskImg::DecodeAddr(const CircularBufferAccess& buffer, int offset,
void DiskImg::DecodeAddr(const CircularBufferAccess& buffer, int offset,
short* pVol, short* pTrack, short* pSector, short* pChksum)
{
//unsigned int vol, track, sector, chksum;
@ -195,9 +192,8 @@ DiskImg::DecodeAddr(const CircularBufferAccess& buffer, int offset,
* This invokes the appropriate function (e.g. 5&3 or 6&2) to decode the
* data into a 256-byte sector.
*/
DIError
DiskImg::DecodeNibbleData(const CircularBufferAccess& buffer, int idx,
unsigned char* sctBuf, const NibbleDescr* pNibbleDescr)
DIError DiskImg::DecodeNibbleData(const CircularBufferAccess& buffer, int idx,
uint8_t* sctBuf, const NibbleDescr* pNibbleDescr)
{
switch (pNibbleDescr->encoding) {
case kNibbleEnc62:
@ -215,9 +211,8 @@ DiskImg::DecodeNibbleData(const CircularBufferAccess& buffer, int idx,
* This invokes the appropriate function (e.g. 5&3 or 6&2) to encode the
* data from a 256-byte sector.
*/
void
DiskImg::EncodeNibbleData(const CircularBufferAccess& buffer, int idx,
const unsigned char* sctBuf, const NibbleDescr* pNibbleDescr) const
void DiskImg::EncodeNibbleData(const CircularBufferAccess& buffer, int idx,
const uint8_t* sctBuf, const NibbleDescr* pNibbleDescr) const
{
switch (pNibbleDescr->encoding) {
case kNibbleEnc62:
@ -235,13 +230,12 @@ DiskImg::EncodeNibbleData(const CircularBufferAccess& buffer, int idx,
/*
* Decode 6&2 encoding.
*/
DIError
DiskImg::DecodeNibble62(const CircularBufferAccess& buffer, int idx,
unsigned char* sctBuf, const NibbleDescr* pNibbleDescr)
DIError DiskImg::DecodeNibble62(const CircularBufferAccess& buffer, int idx,
uint8_t* sctBuf, const NibbleDescr* pNibbleDescr)
{
unsigned char twos[kChunkSize62 * 3]; // 258
uint8_t twos[kChunkSize62 * 3]; // 258
int chksum = pNibbleDescr->dataChecksumSeed;
unsigned char decodedVal;
uint8_t decodedVal;
int i;
/*
@ -294,12 +288,11 @@ DiskImg::DecodeNibble62(const CircularBufferAccess& buffer, int idx,
/*
* Encode 6&2 encoding.
*/
void
DiskImg::EncodeNibble62(const CircularBufferAccess& buffer, int idx,
const unsigned char* sctBuf, const NibbleDescr* pNibbleDescr) const
void DiskImg::EncodeNibble62(const CircularBufferAccess& buffer, int idx,
const uint8_t* sctBuf, const NibbleDescr* pNibbleDescr) const
{
unsigned char top[256];
unsigned char twos[kChunkSize62];
uint8_t top[256];
uint8_t twos[kChunkSize62];
int twoPosn, twoShift;
int i;
@ -338,14 +331,13 @@ DiskImg::EncodeNibble62(const CircularBufferAccess& buffer, int idx,
/*
* Decode 5&3 encoding.
*/
DIError
DiskImg::DecodeNibble53(const CircularBufferAccess& buffer, int idx,
unsigned char* sctBuf, const NibbleDescr* pNibbleDescr)
DIError DiskImg::DecodeNibble53(const CircularBufferAccess& buffer, int idx,
uint8_t* sctBuf, const NibbleDescr* pNibbleDescr)
{
unsigned char base[256];
unsigned char threes[kThreeSize];
uint8_t base[256];
uint8_t threes[kThreeSize];
int chksum = pNibbleDescr->dataChecksumSeed;
unsigned char decodedVal;
uint8_t decodedVal;
int i;
/*
@ -391,7 +383,7 @@ DiskImg::DecodeNibble53(const CircularBufferAccess& buffer, int idx,
/*
* Convert this pile of stuff into 256 data bytes.
*/
unsigned char* bufPtr;
uint8_t* bufPtr;
bufPtr = sctBuf;
for (i = kChunkSize53-1; i >= 0; i--) {
@ -422,12 +414,11 @@ DiskImg::DecodeNibble53(const CircularBufferAccess& buffer, int idx,
/*
* Encode 5&3 encoding.
*/
void
DiskImg::EncodeNibble53(const CircularBufferAccess& buffer, int idx,
const unsigned char* sctBuf, const NibbleDescr* pNibbleDescr) const
void DiskImg::EncodeNibble53(const CircularBufferAccess& buffer, int idx,
const uint8_t* sctBuf, const NibbleDescr* pNibbleDescr) const
{
unsigned char top[kChunkSize53 * 5 +1]; // (255 / 0xff) +1
unsigned char threes[kChunkSize53 * 3 +1]; // (153 / 0x99) +1
uint8_t top[kChunkSize53 * 5 +1]; // (255 / 0xff) +1
uint8_t threes[kChunkSize53 * 3 +1]; // (153 / 0x99) +1
int i, chunk;
/*
@ -500,8 +491,7 @@ DiskImg::EncodeNibble53(const CircularBufferAccess& buffer, int idx,
*
* "buf" must be able to hold (num * 3) characters.
*/
static void
DumpBytes(const unsigned char* bytes, unsigned int num, char* buf)
static void DumpBytes(const uint8_t* bytes, unsigned int num, char* buf)
{
sprintf(buf, "%02x", bytes[0]);
buf += 2;
@ -514,8 +504,7 @@ DumpBytes(const unsigned char* bytes, unsigned int num, char* buf)
*buf = '\0';
}
static inline const char*
VerifyStr(bool val)
static inline const char* VerifyStr(bool val)
{
return val ? "verify" : "ignore";
}
@ -523,8 +512,7 @@ VerifyStr(bool val)
/*
* Dump the contents of a NibbleDescr struct.
*/
void
DiskImg::DumpNibbleDescr(const NibbleDescr* pNibDescr) const
void DiskImg::DumpNibbleDescr(const NibbleDescr* pNibDescr) const
{
char outBuf1[48];
char outBuf2[48];
@ -560,8 +548,7 @@ DiskImg::DumpNibbleDescr(const NibbleDescr* pNibDescr) const
/*
* Load a nibble track into our track buffer.
*/
DIError
DiskImg::LoadNibbleTrack(long track, long* pTrackLen)
DIError DiskImg::LoadNibbleTrack(long track, long* pTrackLen)
{
DIError dierr = kDIErrNone;
long offset;
@ -586,7 +573,7 @@ DiskImg::LoadNibbleTrack(long track, long* pTrackLen)
/* alloc track buffer if needed */
if (fNibbleTrackBuf == NULL) {
fNibbleTrackBuf = new unsigned char[kTrackAllocSize];
fNibbleTrackBuf = new uint8_t[kTrackAllocSize];
if (fNibbleTrackBuf == NULL)
return kDIErrMalloc;
}
@ -606,8 +593,7 @@ DiskImg::LoadNibbleTrack(long track, long* pTrackLen)
/*
* Save the track buffer back to disk.
*/
DIError
DiskImg::SaveNibbleTrack(void)
DIError DiskImg::SaveNibbleTrack(void)
{
if (fNibbleTrackLoaded < 0) {
LOGI("ERROR: tried to save track without loading it first");
@ -630,8 +616,7 @@ DiskImg::SaveNibbleTrack(void)
* return it. If "pVol" is non-NULL, return the volume number from
* one of the readable sectors.
*/
int
DiskImg::TestNibbleTrack(int track, const NibbleDescr* pNibbleDescr,
int DiskImg::TestNibbleTrack(int track, const NibbleDescr* pNibbleDescr,
int* pVol)
{
long trackLen;
@ -655,7 +640,7 @@ DiskImg::TestNibbleTrack(int track, const NibbleDescr* pNibbleDescr,
if (pVol != NULL)
*pVol = vol;
unsigned char sctBuf[256];
uint8_t sctBuf[256];
if (DecodeNibbleData(buffer, sectorIdx, sctBuf, pNibbleDescr) == kDIErrNone)
count++;
}
@ -678,8 +663,7 @@ DiskImg::TestNibbleTrack(int track, const NibbleDescr* pNibbleDescr,
* fDOSVolumeNum holds a volume number from one of the tracks
* fNumTracks holds the number of tracks on the disk
*/
DIError
DiskImg::AnalyzeNibbleData(void)
DIError DiskImg::AnalyzeNibbleData(void)
{
assert(IsNibbleFormat(fPhysical));
@ -739,15 +723,13 @@ DiskImg::AnalyzeNibbleData(void)
return kDIErrNone;
}
/*
* Read a sector from a nibble image.
*
* While fNumTracks is valid, fNumSectPerTrack is a little flaky, because
* in theory each track could be formatted differently.
*/
DIError
DiskImg::ReadNibbleSector(long track, int sector, void* buf,
DIError DiskImg::ReadNibbleSector(long track, int sector, void* buf,
const NibbleDescr* pNibbleDescr)
{
if (pNibbleDescr == NULL) {
@ -782,7 +764,7 @@ DiskImg::ReadNibbleSector(long track, int sector, void* buf,
if (sectorIdx < 0)
return kDIErrSectorUnreadable;
dierr = DecodeNibbleData(buffer, sectorIdx, (unsigned char*) buf,
dierr = DecodeNibbleData(buffer, sectorIdx, (uint8_t*) buf,
pNibbleDescr);
return dierr;
@ -791,8 +773,7 @@ DiskImg::ReadNibbleSector(long track, int sector, void* buf,
/*
* Write a sector to a nibble image.
*/
DIError
DiskImg::WriteNibbleSector(long track, int sector, const void* buf,
DIError DiskImg::WriteNibbleSector(long track, int sector, const void* buf,
const NibbleDescr* pNibbleDescr)
{
assert(pNibbleDescr != NULL);
@ -817,7 +798,7 @@ DiskImg::WriteNibbleSector(long track, int sector, const void* buf,
if (sectorIdx < 0)
return kDIErrSectorUnreadable;
EncodeNibbleData(buffer, sectorIdx, (unsigned char*) buf, pNibbleDescr);
EncodeNibbleData(buffer, sectorIdx, (uint8_t*) buf, pNibbleDescr);
dierr = SaveNibbleTrack();
if (dierr != kDIErrNone) {
@ -828,14 +809,12 @@ DiskImg::WriteNibbleSector(long track, int sector, const void* buf,
return dierr;
}
/*
* Get the contents of the nibble track.
*
* "buf" must be able to hold kTrackAllocSize bytes.
*/
DIError
DiskImg::ReadNibbleTrack(long track, unsigned char* buf, long* pTrackLen)
DIError DiskImg::ReadNibbleTrack(long track, uint8_t* buf, long* pTrackLen)
{
DIError dierr;
@ -856,8 +835,7 @@ DiskImg::ReadNibbleTrack(long track, unsigned char* buf, long* pTrackLen)
* .nib. Fixed-length formats shouldn't be allowed to interact. Figure
* this out someday. For now, the higher-level code prevents it.
*/
DIError
DiskImg::WriteNibbleTrack(long track, const unsigned char* buf, long trackLen)
DIError DiskImg::WriteNibbleTrack(long track, const uint8_t* buf, long trackLen)
{
DIError dierr;
long oldTrackLen;
@ -889,7 +867,6 @@ DiskImg::WriteNibbleTrack(long track, const unsigned char* buf, long trackLen)
return kDIErrNone;
}
/*
* Create a blank nibble image, using fpNibbleDescr as the template.
* Sets "fLength".
@ -909,14 +886,13 @@ DiskImg::WriteNibbleTrack(long track, const unsigned char* buf, long trackLen)
* 48 + (14 + 6 + (6 + 1 + 342) + 27) * 16 = 6384
* 48 + (14 + 6 + (6 + 1 + 410) + 27) * 13 = 6080
*/
DIError
DiskImg::FormatNibbles(GenericFD* pGFD) const
DIError DiskImg::FormatNibbles(GenericFD* pGFD) const
{
assert(fHasNibbles);
assert(GetNumTracks() > 0);
DIError dierr = kDIErrNone;
unsigned char trackBuf[kTrackAllocSize];
uint8_t trackBuf[kTrackAllocSize];
/* these should be the same except for var-len images */
long trackAllocLen = GetNibbleTrackAllocLength();
long trackLen = GetNibbleTrackFormatLength();
@ -954,8 +930,8 @@ DiskImg::FormatNibbles(GenericFD* pGFD) const
* Create a prototype sector. The data for a sector full of zeroes
* is exactly the same; only the address header changes.
*/
unsigned char sampleSource[256];
unsigned char sampleBuf[512]; // must hold 5&3 and 6&2
uint8_t sampleSource[256];
uint8_t sampleBuf[512]; // must hold 5&3 and 6&2
CircularBufferAccess sample(sampleBuf, 512);
long dataLen;
@ -973,7 +949,7 @@ DiskImg::FormatNibbles(GenericFD* pGFD) const
*/
for (track = 0; track < GetNumTracks(); track++) {
//LOGI("Formatting track %d", track);
unsigned char* trackPtr = trackBuf;
uint8_t* trackPtr = trackBuf;
/*
* Fill with "self-sync" bytes.
@ -987,7 +963,7 @@ DiskImg::FormatNibbles(GenericFD* pGFD) const
/*
* Write address field.
*/
unsigned short hdrTrack, hdrSector, hdrVol, hdrChksum;
uint16_t hdrTrack, hdrSector, hdrVol, hdrChksum;
hdrTrack = track;
hdrSector = sector;
hdrVol = fDOSVolumeNum;
@ -1043,4 +1019,3 @@ DiskImg::FormatNibbles(GenericFD* pGFD) const
return dierr;
}

View File

@ -73,8 +73,7 @@ enum {
* There are 12 sectors per track for the first 16 cylinders, 11 sectors
* per track for the next 16, and so on until we're down to 8 per track.
*/
/*static*/ int
DiskImg::SectorsPerTrack35(int cylinder)
/*static*/ int DiskImg::SectorsPerTrack35(int cylinder)
{
return kMaxSectorsPerTrack - (cylinder / 16);
}
@ -82,8 +81,7 @@ DiskImg::SectorsPerTrack35(int cylinder)
/*
* Convert cylinder/head/sector to a block number on a 3.5" disk.
*/
/*static*/ int
DiskImg::CylHeadSect35ToBlock(int cyl, int head, int sect)
/*static*/ int DiskImg::CylHeadSect35ToBlock(int cyl, int head, int sect)
{
int i, block;
@ -108,16 +106,15 @@ DiskImg::CylHeadSect35ToBlock(int cyl, int head, int sect)
*
* "outputBuf" must be able to hold 512 * 12 sectors of decoded sector data.
*/
/*static*/ DIError
DiskImg::UnpackNibbleTrack35(const unsigned char* nibbleBuf,
long nibbleLen, unsigned char* outputBuf, int cyl, int head,
/*static*/ DIError DiskImg::UnpackNibbleTrack35(const uint8_t* nibbleBuf,
long nibbleLen, uint8_t* outputBuf, int cyl, int head,
LinearBitmap* pBadBlockMap)
{
CircularBufferAccess buffer(nibbleBuf, nibbleLen);
bool foundSector[kMaxSectorsPerTrack];
unsigned char sectorBuf[kSectorSize35];
unsigned char readSum[kDataChecksumLen];
unsigned char calcSum[kDataChecksumLen];
uint8_t sectorBuf[kSectorSize35];
uint8_t readSum[kDataChecksumLen];
uint8_t calcSum[kDataChecksumLen];
int i;
memset(&foundSector, 0, sizeof(foundSector));
@ -189,9 +186,8 @@ DiskImg::UnpackNibbleTrack35(const unsigned char* nibbleBuf,
/*
* Returns the offset of the next sector, or -1 if we went off the end.
*/
/*static*/ int
DiskImg::FindNextSector35(const CircularBufferAccess& buffer, int start,
int cyl, int head, int* pSector)
/*static*/ int DiskImg::FindNextSector35(const CircularBufferAccess& buffer,
int start, int cyl, int head, int* pSector)
{
int end = buffer.GetSize();
int i;
@ -275,16 +271,15 @@ DiskImg::FindNextSector35(const CircularBufferAccess& buffer, int start,
* not return false on a checksum mismatch -- it's up to the caller to
* verify the checksum if desired.
*/
/*static*/ bool
DiskImg::DecodeNibbleSector35(const CircularBufferAccess& buffer, int start,
unsigned char* sectorBuf, unsigned char* readChecksum,
unsigned char* calcChecksum)
/*static*/ bool DiskImg::DecodeNibbleSector35(const CircularBufferAccess& buffer,
int start, uint8_t* sectorBuf, uint8_t* readChecksum,
uint8_t* calcChecksum)
{
const int kMaxDataReach35 = 48; // fairly arbitrary
unsigned char* sectorBufStart = sectorBuf;
unsigned char part0[kChunkSize35], part1[kChunkSize35], part2[kChunkSize35];
uint8_t* sectorBufStart = sectorBuf;
uint8_t part0[kChunkSize35], part1[kChunkSize35], part2[kChunkSize35];
unsigned int chk0, chk1, chk2;
unsigned char val, nib0, nib1, nib2, twos;
uint8_t val, nib0, nib1, nib2, twos;
int i, off;
/*
@ -402,7 +397,7 @@ DiskImg::DecodeNibbleSector35(const CircularBufferAccess& buffer, int start,
//#define TEST_ENC_35
#ifdef TEST_ENC_35
{
unsigned char nibBuf[kNibblizedOutputLen];
uint8_t nibBuf[kNibblizedOutputLen];
memset(nibBuf, 0xcc, sizeof(nibBuf));
/* encode what we just decoded */
@ -416,7 +411,7 @@ DiskImg::DecodeNibbleSector35(const CircularBufferAccess& buffer, int start,
* two flaky bits.
*/
if (i == 696) {
unsigned char val1, val2;
uint8_t val1, val2;
val1 = kInvDiskBytes62[buffer[start + i]];
val2 = kInvDiskBytes62[nibBuf[i]];
if ((val1 & 0xfc) != (val2 & 0xfc)) {
@ -444,11 +439,10 @@ DiskImg::DecodeNibbleSector35(const CircularBufferAccess& buffer, int start,
*
* Returns "true" if all goes well, "false" otherwise.
*/
/*static*/ bool
DiskImg::UnpackChecksum35(const CircularBufferAccess& buffer, int offset,
unsigned char* checksumBuf)
/*static*/ bool DiskImg::UnpackChecksum35(const CircularBufferAccess& buffer,
int offset, uint8_t* checksumBuf)
{
unsigned char nib0, nib1, nib2, twos;
uint8_t nib0, nib1, nib2, twos;
twos = kInvDiskBytes62[buffer[offset++]];
nib2 = kInvDiskBytes62[buffer[offset++]];
@ -476,15 +470,14 @@ DiskImg::UnpackChecksum35(const CircularBufferAccess& buffer, int offset,
*
* "outBuf" must be able to hold kNibblizedOutputLen bytes.
*/
/*static*/ void
DiskImg::EncodeNibbleSector35(const unsigned char* sectorData,
unsigned char* outBuf)
/*static*/ void DiskImg::EncodeNibbleSector35(const uint8_t* sectorData,
uint8_t* outBuf)
{
const unsigned char* sectorDataStart = sectorData;
unsigned char* outBufStart = outBuf;
unsigned char part0[kChunkSize35], part1[kChunkSize35], part2[kChunkSize35];
const uint8_t* sectorDataStart = sectorData;
uint8_t* outBufStart = outBuf;
uint8_t part0[kChunkSize35], part1[kChunkSize35], part2[kChunkSize35];
unsigned int chk0, chk1, chk2;
unsigned char val, twos;
uint8_t val, twos;
int i;
/*

View File

@ -34,11 +34,10 @@
* to be "helpful" and reads the file whether it's in gz format or not.
* Some days I could do with a little less "help".
*/
/*static*/ DIError
OuterGzip::Test(GenericFD* pGFD, di_off_t outerLength)
/*static*/ DIError OuterGzip::Test(GenericFD* pGFD, di_off_t outerLength)
{
const int kGzipMagic = 0x8b1f; // 0x1f 0x8b
unsigned short magic, magicBuf;
uint16_t magic, magicBuf;
const char* imagePath;
LOGI("Testing for gzip");
@ -54,7 +53,7 @@ OuterGzip::Test(GenericFD* pGFD, di_off_t outerLength)
if (pGFD->Read(&magicBuf, 2) != kDIErrNone)
return kDIErrGeneric;
magic = GetShortLE((unsigned char*) &magicBuf);
magic = GetShortLE((uint8_t*) &magicBuf);
if (magic == kGzipMagic)
return kDIErrNone;
@ -62,7 +61,6 @@ OuterGzip::Test(GenericFD* pGFD, di_off_t outerLength)
return kDIErrGeneric;
}
/*
* The gzip file format has a length embedded in the footer, but
* unfortunately there is no interface to access it. So, we have
@ -81,8 +79,7 @@ OuterGzip::Test(GenericFD* pGFD, di_off_t outerLength)
* to a temp file, or allowing the caller to specify what the largest
* size they can handle is.
*/
DIError
OuterGzip::ExtractGzipImage(gzFile gzfp, char** pBuf, di_off_t* pLength)
DIError OuterGzip::ExtractGzipImage(gzFile gzfp, char** pBuf, di_off_t* pLength)
{
DIError dierr = kDIErrNone;
const int kMinEmpty = 256 * 1024;
@ -222,8 +219,7 @@ bail:
/*
* Open the archive, and extract the disk image into a memory buffer.
*/
DIError
OuterGzip::Load(GenericFD* pOuterGFD, di_off_t outerLength, bool readOnly,
DIError OuterGzip::Load(GenericFD* pOuterGFD, di_off_t outerLength, bool readOnly,
di_off_t* pWrapperLength, GenericFD** ppWrapperGFD)
{
DIError dierr = kDIErrNone;
@ -285,8 +281,7 @@ bail:
* "pOuterGFD" isn't disturbed (same as Load). All we want is to get the
* filename and then do everything through gzio.
*/
DIError
OuterGzip::Save(GenericFD* pOuterGFD, GenericFD* pWrapperGFD,
DIError OuterGzip::Save(GenericFD* pOuterGFD, GenericFD* pWrapperGFD,
di_off_t wrapperLength)
{
DIError dierr = kDIErrNone;
@ -366,8 +361,7 @@ bail:
/*
* Test to see if this is a ZIP archive.
*/
/*static*/ DIError
OuterZip::Test(GenericFD* pGFD, di_off_t outerLength)
/*static*/ DIError OuterZip::Test(GenericFD* pGFD, di_off_t outerLength)
{
DIError dierr = kDIErrNone;
CentralDirEntry cde;
@ -410,14 +404,13 @@ bail:
/*
* Open the archive, and extract the disk image into a memory buffer.
*/
DIError
OuterZip::Load(GenericFD* pOuterGFD, di_off_t outerLength, bool readOnly,
DIError OuterZip::Load(GenericFD* pOuterGFD, di_off_t outerLength, bool readOnly,
di_off_t* pWrapperLength, GenericFD** ppWrapperGFD)
{
DIError dierr = kDIErrNone;
GFDBuffer* pNewGFD = NULL;
CentralDirEntry cde;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
di_off_t length = -1;
const char* pExt;
@ -471,8 +464,7 @@ bail:
* Save the contents of "pWrapperGFD" to the file pointed to by
* "pOuterGFD".
*/
DIError
OuterZip::Save(GenericFD* pOuterGFD, GenericFD* pWrapperGFD,
DIError OuterZip::Save(GenericFD* pOuterGFD, GenericFD* pWrapperGFD,
di_off_t wrapperLength)
{
DIError dierr = kDIErrNone;
@ -527,7 +519,7 @@ OuterZip::Save(GenericFD* pOuterGFD, GenericFD* pWrapperGFD,
/*
* Write the compressed data.
*/
unsigned long crc;
uint32_t crc;
di_off_t compressedLen;
if (lfh.fCompressionMethod == kCompressDeflated) {
dierr = DeflateGFDToGFD(pOuterGFD, pWrapperGFD, wrapperLength,
@ -556,8 +548,8 @@ OuterZip::Save(GenericFD* pOuterGFD, GenericFD* pWrapperGFD,
* local file header is easy enough.
*/
lfh.fCRC32 = crc;
lfh.fCompressedSize = (unsigned long) compressedLen;
lfh.fUncompressedSize = (unsigned long) wrapperLength;
lfh.fCompressedSize = (uint32_t) compressedLen;
lfh.fUncompressedSize = (uint32_t) wrapperLength;
di_off_t curPos;
curPos = pOuterGFD->Tell();
@ -590,7 +582,7 @@ OuterZip::Save(GenericFD* pOuterGFD, GenericFD* pWrapperGFD,
cde.fUncompressedSize = lfh.fUncompressedSize;
assert(lfh.fExtraFieldLength == 0 && cde.fExtraFieldLength == 0);
cde.fExternalAttrs = 0x81b60020; // matches what WinZip does
cde.fLocalHeaderRelOffset = (unsigned long) lfhOffset;
cde.fLocalHeaderRelOffset = (uint32_t) lfhOffset;
cde.SetFileName(fStoredFileName);
dierr = cde.Write(pOuterGFD);
if (dierr != kDIErrNone)
@ -603,8 +595,8 @@ OuterZip::Save(GenericFD* pOuterGFD, GenericFD* pWrapperGFD,
*/
eocd.fNumEntries = 1;
eocd.fTotalNumEntries = 1;
eocd.fCentralDirSize = (unsigned long) (cdeFinish - cdeStart);
eocd.fCentralDirOffset = (unsigned long) cdeStart;
eocd.fCentralDirSize = (uint32_t) (cdeFinish - cdeStart);
eocd.fCentralDirOffset = (uint32_t) cdeStart;
assert(eocd.fCentralDirSize >= EndOfCentralDir::kEOCDLen);
dierr = eocd.Write(pOuterGFD);
if (dierr != kDIErrNone)
@ -619,18 +611,15 @@ bail:
return dierr;
}
/*
* Track the name of the file stored in the ZIP archive.
*/
void
OuterZip::SetStoredFileName(const char* name)
void OuterZip::SetStoredFileName(const char* name)
{
delete[] fStoredFileName;
fStoredFileName = StrcpyNew(name);
}
/*
* Find the central directory and read the contents.
*
@ -651,13 +640,12 @@ OuterZip::SetStoredFileName(const char* name)
* area, we're hosed. This appears to be the way that the Info-ZIP guys
* do it though, so we're in pretty good company if this fails.
*/
/*static*/ DIError
OuterZip::ReadCentralDir(GenericFD* pGFD, di_off_t outerLength,
/*static*/ DIError OuterZip::ReadCentralDir(GenericFD* pGFD, di_off_t outerLength,
CentralDirEntry* pDirEntry)
{
DIError dierr = kDIErrNone;
EndOfCentralDir eocd;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
di_off_t seekStart;
long readAmount;
int i;
@ -666,7 +654,7 @@ OuterZip::ReadCentralDir(GenericFD* pGFD, di_off_t outerLength,
if (outerLength < EndOfCentralDir::kEOCDLen + 4)
return kDIErrGeneric;
buf = new unsigned char[kMaxEOCDSearch];
buf = new uint8_t[kMaxEOCDSearch];
if (buf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -745,7 +733,7 @@ OuterZip::ReadCentralDir(GenericFD* pGFD, di_off_t outerLength,
pDirEntry->Dump();
{
unsigned char checkBuf[4];
uint8_t checkBuf[4];
dierr = pGFD->Read(checkBuf, 4);
if (dierr != kDIErrNone)
goto bail;
@ -763,18 +751,16 @@ bail:
return dierr;
}
/*
* The central directory tells us where to find the local header. We
* have to skip over that to get to the start of the data.s
* have to skip over that to get to the start of the data.
*/
DIError
OuterZip::ExtractZipEntry(GenericFD* pOuterGFD, CentralDirEntry* pCDE,
unsigned char** pBuf, di_off_t* pLength)
DIError OuterZip::ExtractZipEntry(GenericFD* pOuterGFD, CentralDirEntry* pCDE,
uint8_t** pBuf, di_off_t* pLength)
{
DIError dierr = kDIErrNone;
LocalFileHeader lfh;
unsigned char* buf = NULL;
uint8_t* buf = NULL;
/* seek to the start of the local header */
dierr = pOuterGFD->Seek(pCDE->fLocalHeaderRelOffset, kSeekSet);
@ -795,7 +781,7 @@ OuterZip::ExtractZipEntry(GenericFD* pOuterGFD, CentralDirEntry* pCDE,
/* we should now be pointing at the data */
LOGI("File offset is 0x%08lx", (long) pOuterGFD->Tell());
buf = new unsigned char[pCDE->fUncompressedSize];
buf = new uint8_t[pCDE->fUncompressedSize];
if (buf == NULL) {
/* a very real possibility */
LOGI(" ZIP unable to allocate buffer of %lu bytes",
@ -821,7 +807,7 @@ OuterZip::ExtractZipEntry(GenericFD* pOuterGFD, CentralDirEntry* pCDE,
}
/* check the CRC32 */
unsigned long crc;
uint32_t crc;
crc = crc32(0L, Z_NULL, 0);
crc = crc32(crc, buf, pCDE->fUncompressedSize);
@ -849,18 +835,17 @@ bail:
*
* "buf" must be able to hold "uncompSize" bytes.
*/
DIError
OuterZip::InflateGFDToBuffer(GenericFD* pGFD, unsigned long compSize,
unsigned long uncompSize, unsigned char* buf)
DIError OuterZip::InflateGFDToBuffer(GenericFD* pGFD, unsigned long compSize,
unsigned long uncompSize, uint8_t* buf)
{
DIError dierr = kDIErrNone;
const unsigned long kReadBufSize = 65536;
unsigned char* readBuf = NULL;
const size_t kReadBufSize = 65536;
uint8_t* readBuf = NULL;
z_stream zstream;
int zerr;
unsigned long compRemaining;
readBuf = new unsigned char[kReadBufSize];
readBuf = new uint8_t[kReadBufSize];
if (readBuf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -949,12 +934,10 @@ bail:
return dierr;
}
/*
* Get the current date/time, in MS-DOS format.
*/
void
OuterZip::GetMSDOSTime(unsigned short* pDate, unsigned short* pTime)
void OuterZip::GetMSDOSTime(uint16_t* pDate, uint16_t* pTime)
{
#if 0
/* this gets gmtime; we want localtime */
@ -976,8 +959,7 @@ OuterZip::GetMSDOSTime(unsigned short* pDate, unsigned short* pTime)
/*
* Convert a time_t to MS-DOS date and time values.
*/
void
OuterZip::DOSTime(time_t when, unsigned short* pDate, unsigned short* pTime)
void OuterZip::DOSTime(time_t when, uint16_t* pDate, uint16_t* pTime)
{
time_t even;
@ -1000,27 +982,25 @@ OuterZip::DOSTime(time_t when, unsigned short* pDate, unsigned short* pTime)
*pTime = ptm->tm_hour << 11 | ptm->tm_min << 5 | ptm->tm_sec >> 1;
}
/*
* Compress "length" bytes of data from "pSrc" to "pDst".
*/
DIError
OuterZip::DeflateGFDToGFD(GenericFD* pDst, GenericFD* pSrc, di_off_t srcLen,
di_off_t* pCompLength, unsigned long* pCRC)
DIError OuterZip::DeflateGFDToGFD(GenericFD* pDst, GenericFD* pSrc,
di_off_t srcLen, di_off_t* pCompLength, uint32_t* pCRC)
{
DIError dierr = kDIErrNone;
const unsigned long kBufSize = 32768;
unsigned char* inBuf = NULL;
unsigned char* outBuf = NULL;
const size_t kBufSize = 32768;
uint8_t* inBuf = NULL;
uint8_t* outBuf = NULL;
z_stream zstream;
unsigned long crc;
uint32_t crc;
int zerr;
/*
* Create an input buffer and an output buffer.
*/
inBuf = new unsigned char[kBufSize];
outBuf = new unsigned char[kBufSize];
inBuf = new uint8_t[kBufSize];
outBuf = new uint8_t[kBufSize];
if (inBuf == NULL || outBuf == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -1126,8 +1106,7 @@ bail:
/*
* Set the "fExtension" field.
*/
void
OuterZip::SetExtension(const char* ext)
void OuterZip::SetExtension(const char* ext)
{
delete[] fExtension;
fExtension = StrcpyNew(ext);
@ -1146,11 +1125,10 @@ OuterZip::SetExtension(const char* ext)
* On entry, "pGFD" points to the signature at the start of the header.
* On exit, "pGFD" points to the start of data.
*/
DIError
OuterZip::LocalFileHeader::Read(GenericFD* pGFD)
DIError OuterZip::LocalFileHeader::Read(GenericFD* pGFD)
{
DIError dierr = kDIErrNone;
unsigned char buf[kLFHLen];
uint8_t buf[kLFHLen];
dierr = pGFD->Read(buf, kLFHLen);
if (dierr != kDIErrNone)
@ -1176,7 +1154,7 @@ OuterZip::LocalFileHeader::Read(GenericFD* pGFD)
/* grab filename */
if (fFileNameLength != 0) {
assert(fFileName == NULL);
fFileName = new unsigned char[fFileNameLength+1];
fFileName = new uint8_t[fFileNameLength+1];
if (fFileName == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -1199,11 +1177,10 @@ bail:
/*
* Write a local file header.
*/
DIError
OuterZip::LocalFileHeader::Write(GenericFD* pGFD)
DIError OuterZip::LocalFileHeader::Write(GenericFD* pGFD)
{
DIError dierr = kDIErrNone;
unsigned char buf[kLFHLen];
uint8_t buf[kLFHLen];
PutLongLE(&buf[0x00], kSignature);
PutShortLE(&buf[0x04], fVersionToExtract);
@ -1236,8 +1213,7 @@ bail:
/*
* Change the filename field.
*/
void
OuterZip::LocalFileHeader::SetFileName(const char* name)
void OuterZip::LocalFileHeader::SetFileName(const char* name)
{
delete[] fFileName;
fFileName = NULL;
@ -1245,15 +1221,15 @@ OuterZip::LocalFileHeader::SetFileName(const char* name)
if (name != NULL) {
fFileNameLength = strlen(name);
fFileName = new unsigned char[fFileNameLength+1];
fFileName = new uint8_t[fFileNameLength+1];
if (fFileName == NULL) {
LOGI("Malloc failure in SetFileName %u", fFileNameLength);
LOGW("Malloc failure in SetFileName %u", fFileNameLength);
fFileName = NULL;
fFileNameLength = 0;
} else {
memcpy(fFileName, name, fFileNameLength);
fFileName[fFileNameLength] = '\0';
LOGI("+++ OuterZip LFH filename set to '%s'", fFileName);
LOGD("+++ OuterZip LFH filename set to '%s'", fFileName);
}
}
}
@ -1261,8 +1237,7 @@ OuterZip::LocalFileHeader::SetFileName(const char* name)
/*
* Dump the contents of a LocalFileHeader object.
*/
void
OuterZip::LocalFileHeader::Dump(void) const
void OuterZip::LocalFileHeader::Dump(void) const
{
LOGI(" LocalFileHeader contents:");
LOGI(" versToExt=%u gpBits=0x%04x compression=%u",
@ -1289,11 +1264,10 @@ OuterZip::LocalFileHeader::Dump(void) const
* entry. On exit, "pGFD" will point at the signature word for the next
* entry or for the EOCD.
*/
DIError
OuterZip::CentralDirEntry::Read(GenericFD* pGFD)
DIError OuterZip::CentralDirEntry::Read(GenericFD* pGFD)
{
DIError dierr = kDIErrNone;
unsigned char buf[kCDELen];
uint8_t buf[kCDELen];
dierr = pGFD->Read(buf, kCDELen);
if (dierr != kDIErrNone)
@ -1325,7 +1299,7 @@ OuterZip::CentralDirEntry::Read(GenericFD* pGFD)
/* grab filename */
if (fFileNameLength != 0) {
assert(fFileName == NULL);
fFileName = new unsigned char[fFileNameLength+1];
fFileName = new uint8_t[fFileNameLength+1];
if (fFileName == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -1345,7 +1319,7 @@ OuterZip::CentralDirEntry::Read(GenericFD* pGFD)
/* grab comment, if any */
if (fFileCommentLength != 0) {
assert(fFileComment == NULL);
fFileComment = new unsigned char[fFileCommentLength+1];
fFileComment = new uint8_t[fFileCommentLength+1];
if (fFileComment == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -1364,11 +1338,10 @@ bail:
/*
* Write a central dir entry.
*/
DIError
OuterZip::CentralDirEntry::Write(GenericFD* pGFD)
DIError OuterZip::CentralDirEntry::Write(GenericFD* pGFD)
{
DIError dierr = kDIErrNone;
unsigned char buf[kCDELen];
uint8_t buf[kCDELen];
PutLongLE(&buf[0x00], kSignature);
PutShortLE(&buf[0x04], fVersionMadeBy);
@ -1408,8 +1381,7 @@ bail:
/*
* Change the filename field.
*/
void
OuterZip::CentralDirEntry::SetFileName(const char* name)
void OuterZip::CentralDirEntry::SetFileName(const char* name)
{
delete[] fFileName;
fFileName = NULL;
@ -1417,7 +1389,7 @@ OuterZip::CentralDirEntry::SetFileName(const char* name)
if (name != NULL) {
fFileNameLength = strlen(name);
fFileName = new unsigned char[fFileNameLength+1];
fFileName = new uint8_t[fFileNameLength+1];
if (fFileName == NULL) {
LOGI("Malloc failure in SetFileName %u", fFileNameLength);
fFileName = NULL;
@ -1430,12 +1402,10 @@ OuterZip::CentralDirEntry::SetFileName(const char* name)
}
}
/*
* Dump the contents of a CentralDirEntry object.
*/
void
OuterZip::CentralDirEntry::Dump(void) const
void OuterZip::CentralDirEntry::Dump(void) const
{
LOGI(" CentralDirEntry contents:");
LOGI(" versMadeBy=%u versToExt=%u gpBits=0x%04x compression=%u",
@ -1470,8 +1440,7 @@ OuterZip::CentralDirEntry::Dump(void) const
*
* "buf" should be positioned at the EOCD signature.
*/
DIError
OuterZip::EndOfCentralDir::ReadBuf(const unsigned char* buf, int len)
DIError OuterZip::EndOfCentralDir::ReadBuf(const uint8_t* buf, int len)
{
if (len < kEOCDLen) {
/* looks like ZIP file got truncated */
@ -1497,11 +1466,10 @@ OuterZip::EndOfCentralDir::ReadBuf(const unsigned char* buf, int len)
/*
* Write an end-of-central-directory section.
*/
DIError
OuterZip::EndOfCentralDir::Write(GenericFD* pGFD)
DIError OuterZip::EndOfCentralDir::Write(GenericFD* pGFD)
{
DIError dierr = kDIErrNone;
unsigned char buf[kEOCDLen];
uint8_t buf[kEOCDLen];
PutLongLE(&buf[0x00], kSignature);
PutShortLE(&buf[0x04], fDiskNumber);
@ -1521,6 +1489,7 @@ OuterZip::EndOfCentralDir::Write(GenericFD* pGFD)
bail:
return dierr;
}
/*
* Dump the contents of an EndOfCentralDir object.
*/

View File

@ -40,9 +40,8 @@ const int kMaxCatalogIterations = 64;
* Read a track/sector, adjusting for 32-sector disks being treated as
* if they were 16-sector.
*/
static DIError
ReadTrackSectorAdjusted(DiskImg* pImg, int track, int sector,
int sectorOffset, unsigned char* buf, DiskImg::SectorOrder imageOrder)
static DIError ReadTrackSectorAdjusted(DiskImg* pImg, int track, int sector,
int sectorOffset, uint8_t* buf, DiskImg::SectorOrder imageOrder)
{
track *= 4;
sector = sector * 2 + sectorOffset;
@ -57,11 +56,11 @@ ReadTrackSectorAdjusted(DiskImg* pImg, int track, int sector,
/*
* Test for presence of 400K OzDOS 3.3 volumes.
*/
static DIError
TestImageHalf(DiskImg* pImg, int sectorOffset, DiskImg::SectorOrder imageOrder)
static DIError TestImageHalf(DiskImg* pImg, int sectorOffset,
DiskImg::SectorOrder imageOrder)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
int numTracks, numSectors;
int catTrack, catSect;
int foundGood = 0;
@ -129,8 +128,7 @@ bail:
/*
* Test both of the DOS partitions.
*/
static DIError
TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
static DIError TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
{
DIError dierr;
@ -150,8 +148,7 @@ TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
/*
* Test to see if the image is a OzDOS volume.
*/
/*static*/ DIError
DiskFSOzDOS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSOzDOS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
/* only on 800K disks (at the least, insist on numTracks being even) */
@ -189,8 +186,8 @@ DiskFSOzDOS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
* Test to see if the image is a 'wide' (32-sector) DOS3.3 volume, i.e.
* half of a OzDOS volume.
*/
/*static*/ DIError
DiskFS::TestOzWideDOS33(const DiskImg* pImg, DiskImg::SectorOrder* pOrder)
/*static*/ DIError DiskFS::TestOzWideDOS33(const DiskImg* pImg,
DiskImg::SectorOrder* pOrder)
{
DIError dierr = kDIErrNone;
@ -224,8 +221,7 @@ DiskFS::TestOzWideDOS33(const DiskImg* pImg, DiskImg::SectorOrder* pOrder)
/*
* Set up our sub-volumes.
*/
DIError
DiskFSOzDOS::Initialize(void)
DIError DiskFSOzDOS::Initialize(void)
{
DIError dierr = kDIErrNone;
@ -249,8 +245,7 @@ DiskFSOzDOS::Initialize(void)
/*
* Open up one of the DOS 3.3 sub-volumes.
*/
DIError
DiskFSOzDOS::OpenSubVolume(int idx)
DIError DiskFSOzDOS::OpenSubVolume(int idx)
{
DIError dierr = kDIErrNone;
DiskFS* pNewFS = NULL;

View File

@ -30,12 +30,11 @@ static const char* kInvalidNameChars = "$=?,[#:";
*
* We test a few fields in the volume directory for validity.
*/
static DIError
TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
static DIError TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder)
{
DIError dierr = kDIErrNone;
unsigned char blkBuf[512];
unsigned char volName[DiskFSPascal::kMaxVolumeName+1];
uint8_t blkBuf[512];
uint8_t volName[DiskFSPascal::kMaxVolumeName+1];
dierr = pImg->ReadBlockSwapped(kVolHeaderBlock, blkBuf, imageOrder,
DiskImg::kSectorOrderProDOS);
@ -66,8 +65,7 @@ bail:
/*
* Test to see if the image is a Pascal disk.
*/
/*static*/ DIError
DiskFSPascal::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSPascal::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
DiskImg::SectorOrder ordering[DiskImg::kSectorOrderMax];
@ -95,8 +93,7 @@ DiskFSPascal::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
* on out must be handled somehow, possibly by claiming that the disk is
* completely full and has no files on it.
*/
DIError
DiskFSPascal::Initialize(void)
DIError DiskFSPascal::Initialize(void)
{
DIError dierr = kDIErrNone;
@ -138,11 +135,10 @@ bail:
/*
* Read some interesting fields from the volume header.
*/
DIError
DiskFSPascal::LoadVolHeader(void)
DIError DiskFSPascal::LoadVolHeader(void)
{
DIError dierr = kDIErrNone;
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
int nameLen, maxFiles;
dierr = fpImg->ReadBlock(kVolHeaderBlock, blkBuf);
@ -198,8 +194,7 @@ bail:
/*
* Set the volume ID field.
*/
void
DiskFSPascal::SetVolumeID(void)
void DiskFSPascal::SetVolumeID(void)
{
sprintf(fVolumeID, "Pascal %s:", fVolumeName);
}
@ -207,8 +202,7 @@ DiskFSPascal::SetVolumeID(void)
/*
* Dump what we pulled out of the volume header.
*/
void
DiskFSPascal::DumpVolHeader(void)
void DiskFSPascal::DumpVolHeader(void)
{
time_t access, dateSet;
@ -237,11 +231,10 @@ DiskFSPascal::DumpVolHeader(void)
*
* Sets "fDirectory".
*/
DIError
DiskFSPascal::LoadCatalog(void)
DIError DiskFSPascal::LoadCatalog(void)
{
DIError dierr = kDIErrNone;
unsigned char* dirPtr;
uint8_t* dirPtr;
int block, numBlocks;
assert(fDirectory == NULL);
@ -252,7 +245,7 @@ DiskFSPascal::LoadCatalog(void)
goto bail;
}
fDirectory = new unsigned char[kBlkSize * numBlocks];
fDirectory = new uint8_t[kBlkSize * numBlocks];
if (fDirectory == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -280,11 +273,10 @@ bail:
/*
* Write our copy of the catalog back out to disk.
*/
DIError
DiskFSPascal::SaveCatalog(void)
DIError DiskFSPascal::SaveCatalog(void)
{
DIError dierr = kDIErrNone;
unsigned char* dirPtr;
uint8_t* dirPtr;
int block, numBlocks;
assert(fDirectory != NULL);
@ -308,8 +300,7 @@ bail:
/*
* Free the catalog storage.
*/
void
DiskFSPascal::FreeCatalog(void)
void DiskFSPascal::FreeCatalog(void)
{
delete[] fDirectory;
fDirectory = NULL;
@ -319,14 +310,13 @@ DiskFSPascal::FreeCatalog(void)
/*
* Process the catalog into A2File structures.
*/
DIError
DiskFSPascal::ProcessCatalog(void)
DIError DiskFSPascal::ProcessCatalog(void)
{
DIError dierr = kDIErrNone;
int i, nameLen;
A2FilePascal* pFile;
const unsigned char* dirPtr;
unsigned short prevNextBlock = fNextBlock;
const uint8_t* dirPtr;
uint16_t prevNextBlock = fNextBlock;
dierr = LoadCatalog();
if (dierr != kDIErrNone)
@ -398,8 +388,7 @@ bail:
* Create the volume usage map. Since UCSD Pascal volumes have neither
* in-use maps nor index blocks, this is pretty straightforward.
*/
DIError
DiskFSPascal::ScanFileUsage(void)
DIError DiskFSPascal::ScanFileUsage(void)
{
int block;
@ -426,8 +415,7 @@ DiskFSPascal::ScanFileUsage(void)
/*
* Update an entry in the volume usage map.
*/
void
DiskFSPascal::SetBlockUsage(long block, VolumeUsage::ChunkPurpose purpose)
void DiskFSPascal::SetBlockUsage(long block, VolumeUsage::ChunkPurpose purpose)
{
VolumeUsage::ChunkState cstate;
@ -450,8 +438,7 @@ DiskFSPascal::SetBlockUsage(long block, VolumeUsage::ChunkPurpose purpose)
* Volume names can only be 7 characters long, but otherwise obey the same
* rules as file names.
*/
/*static*/ bool
DiskFSPascal::IsValidVolumeName(const char* name)
/*static*/ bool DiskFSPascal::IsValidVolumeName(const char* name)
{
if (name == NULL) {
assert(false);
@ -471,8 +458,7 @@ DiskFSPascal::IsValidVolumeName(const char* name)
* (,[#:). It also converts all alpha characters to upper case, but we can
* take care of that later.
*/
/*static*/ bool
DiskFSPascal::IsValidFileName(const char* name)
/*static*/ bool DiskFSPascal::IsValidFileName(const char* name)
{
assert(name != NULL);
@ -499,11 +485,10 @@ DiskFSPascal::IsValidFileName(const char* name)
/*
* Put a Pascal filesystem image on the specified DiskImg.
*/
DIError
DiskFSPascal::Format(DiskImg* pDiskImg, const char* volName)
DIError DiskFSPascal::Format(DiskImg* pDiskImg, const char* volName)
{
DIError dierr = kDIErrNone;
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
long formatBlocks;
if (!IsValidVolumeName(volName))
@ -552,7 +537,7 @@ DiskFSPascal::Format(DiskImg* pDiskImg, const char* volName)
PutShortLE(&blkBuf[0x04], 0); // "file" type
blkBuf[0x06] = strlen(volName);
memcpy(&blkBuf[0x07], volName, strlen(volName));
PutShortLE(&blkBuf[0x0e], (unsigned short) pDiskImg->GetNumBlocks());
PutShortLE(&blkBuf[0x0e], (uint16_t) pDiskImg->GetNumBlocks());
PutShortLE(&blkBuf[0x10], 0); // num files
PutShortLE(&blkBuf[0x12], 0); // last access date
PutShortLE(&blkBuf[0x14], 0xa87b); // last date set (Nov 7 1984)
@ -580,7 +565,7 @@ bail:
* Blocks 0 and 1 of a 5.25" bootable Pascal disk, formatted by
* APPLE3:FORMATTER from Pascal v1.3.
*/
const unsigned char gPascal525Block0[] = {
const uint8_t gPascal525Block0[] = {
0x01, 0xe0, 0x70, 0xb0, 0x04, 0xe0, 0x40, 0xb0, 0x39, 0xbd, 0x88, 0xc0,
0x20, 0x20, 0x08, 0xa2, 0x00, 0xbd, 0x25, 0x08, 0x09, 0x80, 0x20, 0xfd,
0xfb, 0xe8, 0xe0, 0x1d, 0xd0, 0xf3, 0xf0, 0xfe, 0xa9, 0x0a, 0x4c, 0x24,
@ -625,7 +610,7 @@ const unsigned char gPascal525Block0[] = {
0xf4, 0xea, 0xbd, 0x8c, 0xc0, 0x10, 0xfb, 0xc9, 0xaa, 0xd0, 0xf2, 0xa0,
0x56, 0xbd, 0x8c, 0xc0, 0x10, 0xfb, 0xc9, 0xad
};
const unsigned char gPascal525Block1[] = {
const uint8_t gPascal525Block1[] = {
0xd0, 0xe7, 0xa9, 0x00, 0x88, 0x84, 0x26, 0xbc, 0x8c, 0xc0, 0x10, 0xfb,
0x59, 0xd6, 0x02, 0xa4, 0x26, 0x99, 0x00, 0x03, 0xd0, 0xee, 0x84, 0x26,
0xbc, 0x8c, 0xc0, 0x10, 0xfb, 0x59, 0xd6, 0x02, 0xa4, 0x26, 0x99, 0x00,
@ -675,7 +660,7 @@ const unsigned char gPascal525Block1[] = {
* Block 0 of a 3.5" bootable Pascal disk, formatted by
* APPLE3:FORMATTER from Pascal v1.3. Block 1 is zeroed out.
*/
unsigned char gPascal35Block0[] = {
const uint8_t gPascal35Block0[] = {
0x01, 0xe0, 0x70, 0xb0, 0x04, 0xe0, 0x40, 0xb0, 0x39, 0xbd, 0x88, 0xc0,
0x20, 0x20, 0x08, 0xa2, 0x00, 0xbd, 0x25, 0x08, 0x09, 0x80, 0x20, 0xfd,
0xfb, 0xe8, 0xe0, 0x1d, 0xd0, 0xf3, 0xf0, 0xfe, 0xa9, 0x0a, 0x4c, 0x24,
@ -724,12 +709,11 @@ unsigned char gPascal35Block0[] = {
/*
* Write the Pascal boot blocks onto the disk image.
*/
DIError
DiskFSPascal::WriteBootBlocks(void)
DIError DiskFSPascal::WriteBootBlocks(void)
{
DIError dierr;
unsigned char block0[512];
unsigned char block1[512];
uint8_t block0[512];
uint8_t block1[512];
bool is525 = false;
assert(fpImg->GetHasBlocks());
@ -765,7 +749,6 @@ DiskFSPascal::WriteBootBlocks(void)
return kDIErrNone;
}
/*
* Scan for damaged files and conflicting file allocation entries.
*
@ -774,8 +757,7 @@ DiskFSPascal::WriteBootBlocks(void)
*
* Returns "true" if disk appears to be perfect, "false" otherwise.
*/
bool
DiskFSPascal::CheckDiskIsGood(void)
bool DiskFSPascal::CheckDiskIsGood(void)
{
//DIError dierr;
bool result = true;
@ -809,13 +791,12 @@ DiskFSPascal::CheckDiskIsGood(void)
/*
* Run through the list of files and count up the free blocks.
*/
DIError
DiskFSPascal::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
DIError DiskFSPascal::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
int* pUnitSize) const
{
A2FilePascal* pFile;
long freeBlocks = 0;
unsigned short prevNextBlock = fNextBlock;
uint16_t prevNextBlock = fNextBlock;
pFile = (A2FilePascal*) GetNextFile(NULL);
while (pFile != NULL) {
@ -840,8 +821,7 @@ DiskFSPascal::GetFreeSpaceCount(long* pTotalUnits, long* pFreeUnits,
* "*pNormalizedBufLen" is used to pass in the length of the buffer and
* pass out the length of the string (should the buffer prove inadequate).
*/
DIError
DiskFSPascal::NormalizePath(const char* path, char fssep,
DIError DiskFSPascal::NormalizePath(const char* path, char fssep,
char* normalizedBuf, int* pNormalizedBufLen)
{
DIError dierr = kDIErrNone;
@ -866,8 +846,7 @@ DiskFSPascal::NormalizePath(const char* path, char fssep,
*
* "outBuf" must be able to hold kMaxFileName+1 characters.
*/
void
DiskFSPascal::DoNormalizePath(const char* name, char fssep, char* outBuf)
void DiskFSPascal::DoNormalizePath(const char* name, char fssep, char* outBuf)
{
char* outp = outBuf;
const char* cp;
@ -912,8 +891,7 @@ DiskFSPascal::DoNormalizePath(const char* name, char fssep, char* outBuf)
* we create here are expected to be written to, not used as filler, so
* this behavior is actually a *good* thing.
*/
DIError
DiskFSPascal::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
DIError DiskFSPascal::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
{
DIError dierr = kDIErrNone;
const bool createUnique = (GetParameter(kParm_CreateUnique) != 0);
@ -1015,12 +993,12 @@ DiskFSPascal::CreateFile(const CreateParms* pParms, A2File** ppNewFile)
/*
* Fill the hole.
*/
unsigned char* dirPtr;
uint8_t* dirPtr;
dirPtr = fDirectory + (prevIdx+1) * kDirectoryEntryLen;
PutShortLE(&dirPtr[0x00], pNewFile->fStartBlock);
PutShortLE(&dirPtr[0x02], pNewFile->fNextBlock);
PutShortLE(&dirPtr[0x04], (unsigned short) pNewFile->fFileType);
dirPtr[0x06] = (unsigned char) strlen(pNewFile->fFileName);
PutShortLE(&dirPtr[0x04], (uint16_t) pNewFile->fFileType);
dirPtr[0x06] = (uint8_t) strlen(pNewFile->fFileName);
memcpy(&dirPtr[0x07], pNewFile->fFileName, A2FilePascal::kMaxFileName);
PutShortLE(&dirPtr[0x16], pNewFile->fBytesRemaining);
PutShortLE(&dirPtr[0x18], pNewFile->fModWhen);
@ -1065,8 +1043,7 @@ bail:
*
* Returns an error on failure, which should be impossible.
*/
DIError
DiskFSPascal::MakeFileNameUnique(char* fileName)
DIError DiskFSPascal::MakeFileNameUnique(char* fileName)
{
assert(fileName != NULL);
assert(strlen(fileName) <= A2FilePascal::kMaxFileName);
@ -1135,12 +1112,11 @@ DiskFSPascal::MakeFileNameUnique(char* fileName)
*
* If there's no free space left, returns kDIErrDiskFull.
*/
DIError
DiskFSPascal::FindLargestFreeArea(int *pPrevIdx, A2FilePascal** ppPrevFile)
DIError DiskFSPascal::FindLargestFreeArea(int *pPrevIdx, A2FilePascal** ppPrevFile)
{
A2FilePascal* pFile;
A2FilePascal* pPrevFile;
unsigned short prevNextBlock = fNextBlock;
uint16_t prevNextBlock = fNextBlock;
int gapSize, maxGap, maxIndex, idx;
maxIndex = -1;
@ -1181,17 +1157,15 @@ DiskFSPascal::FindLargestFreeArea(int *pPrevIdx, A2FilePascal** ppPrevFile)
return kDIErrNone;
}
/*
* Delete a file. Because Pascal doesn't have a block allocation map, this
* is a simple matter of crunching the directory entry out.
*/
DIError
DiskFSPascal::DeleteFile(A2File* pGenericFile)
DIError DiskFSPascal::DeleteFile(A2File* pGenericFile)
{
DIError dierr = kDIErrNone;
A2FilePascal* pFile = (A2FilePascal*) pGenericFile;
unsigned char* pEntry;
uint8_t* pEntry;
int dirLen, offsetToNextEntry;
if (pGenericFile == NULL) {
@ -1247,13 +1221,12 @@ bail:
/*
* Rename a file.
*/
DIError
DiskFSPascal::RenameFile(A2File* pGenericFile, const char* newName)
DIError DiskFSPascal::RenameFile(A2File* pGenericFile, const char* newName)
{
DIError dierr = kDIErrNone;
A2FilePascal* pFile = (A2FilePascal*) pGenericFile;
char normalName[A2FilePascal::kMaxFileName+1];
unsigned char* pEntry;
uint8_t* pEntry;
if (pFile == NULL || newName == NULL)
return kDIErrInvalidArg;
@ -1302,13 +1275,12 @@ bail:
* but we don't allow the full range of ProDOS types. Attempting to change
* to an unsupported type results in "PDA" being used.
*/
DIError
DiskFSPascal::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
DIError DiskFSPascal::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
long accessFlags)
{
DIError dierr = kDIErrNone;
A2FilePascal* pFile = (A2FilePascal*) pGenericFile;
unsigned char* pEntry;
uint8_t* pEntry;
if (pFile == NULL)
return kDIErrInvalidArg;
@ -1334,7 +1306,7 @@ DiskFSPascal::SetFileInfo(A2File* pGenericFile, long fileType, long auxType,
A2FilePascal::FileType newType;
newType = A2FilePascal::ConvertFileType(fileType);
PutShortLE(&pEntry[0x04], (unsigned short) newType);
PutShortLE(&pEntry[0x04], (uint16_t) newType);
dierr = SaveCatalog();
if (dierr != kDIErrNone)
@ -1351,8 +1323,7 @@ bail:
/*
* Change the Pascal volume name.
*/
DIError
DiskFSPascal::RenameVolume(const char* newName)
DIError DiskFSPascal::RenameVolume(const char* newName)
{
DIError dierr = kDIErrNone;
char normalName[A2FilePascal::kMaxFileName+1];
@ -1387,10 +1358,9 @@ bail:
/*
* Find "pFile" in "fDirectory".
*/
unsigned char*
DiskFSPascal::FindDirEntry(A2FilePascal* pFile)
uint8_t* DiskFSPascal::FindDirEntry(A2FilePascal* pFile)
{
unsigned char* ptr;
uint8_t* ptr;
int i;
assert(fDirectory != NULL);
@ -1423,8 +1393,7 @@ DiskFSPascal::FindDirEntry(A2FilePascal* pFile)
/*
* Convert Pascal file type to ProDOS file type.
*/
long
A2FilePascal::GetFileType(void) const
long A2FilePascal::GetFileType(void) const
{
switch (fFileType) {
case kTypeUntyped: return 0x00; // NON
@ -1445,8 +1414,7 @@ A2FilePascal::GetFileType(void) const
/*
* Convert a ProDOS file type to a Pascal file type.
*/
/*static*/ A2FilePascal::FileType
A2FilePascal::ConvertFileType(long prodosType)
/*static*/ A2FilePascal::FileType A2FilePascal::ConvertFileType(long prodosType)
{
FileType newType;
@ -1483,8 +1451,7 @@ A2FilePascal::ConvertFileType(long prodosType)
* the year 100, it will assume that the file was created shortly before the
* system crashed, and will remove the file.
*/
/*static*/ time_t
A2FilePascal::ConvertPascalDate(PascalDate pascalDate)
/*static*/ time_t A2FilePascal::ConvertPascalDate(PascalDate pascalDate)
{
int year, month, day;
@ -1524,10 +1491,9 @@ A2FilePascal::ConvertPascalDate(PascalDate pascalDate)
*
* CiderPress uses kDateInvalid==-1 and kDateNone==-2.
*/
/*static*/ A2FilePascal::PascalDate
A2FilePascal::ConvertPascalDate(time_t unixDate)
/*static*/ A2FilePascal::PascalDate A2FilePascal::ConvertPascalDate(time_t unixDate)
{
unsigned long date, year;
uint32_t date, year;
struct tm* ptm;
if (unixDate == 0 || unixDate == -1 || unixDate == -2)
@ -1541,7 +1507,7 @@ A2FilePascal::ConvertPascalDate(time_t unixDate)
if (year >= 100)
year -= 100;
if (year < 0 || year >= 100) {
LOGI("WHOOPS: got year %lu from %d", year, ptm->tm_year);
LOGW("WHOOPS: got year %lu from %d", year, ptm->tm_year);
year = 70;
}
date = year << 9 | (ptm->tm_mon+1) | ptm->tm_mday << 4;
@ -1552,8 +1518,7 @@ A2FilePascal::ConvertPascalDate(time_t unixDate)
/*
* Return the file modification date.
*/
time_t
A2FilePascal::GetModWhen(void) const
time_t A2FilePascal::GetModWhen(void) const
{
return ConvertPascalDate(fModWhen);
}
@ -1561,8 +1526,7 @@ A2FilePascal::GetModWhen(void) const
/*
* Dump the contents of the A2File structure.
*/
void
A2FilePascal::Dump(void) const
void A2FilePascal::Dump(void) const
{
LOGI("A2FilePascal '%s'", fFileName);
LOGI(" start=%d next=%d type=%d",
@ -1574,8 +1538,7 @@ A2FilePascal::Dump(void) const
/*
* Not a whole lot to do, since there's no fancy index blocks.
*/
DIError
A2FilePascal::Open(A2FileDescr** ppOpenFile, bool readOnly,
DIError A2FilePascal::Open(A2FileDescr** ppOpenFile, bool readOnly,
bool rsrcFork /*=false*/)
{
A2FDPascal* pOpenFile = NULL;
@ -1614,8 +1577,7 @@ A2FilePascal::Open(A2FileDescr** ppOpenFile, bool readOnly,
/*
* Read a chunk of data from the current offset.
*/
DIError
A2FDPascal::Read(void* buf, size_t len, size_t* pActual)
DIError A2FDPascal::Read(void* buf, size_t len, size_t* pActual)
{
LOGI(" Pascal reading %d bytes from '%s' (offset=%ld)",
len, fpFile->GetPathName(), (long) fOffset);
@ -1633,7 +1595,7 @@ A2FDPascal::Read(void* buf, size_t len, size_t* pActual)
long incrLen = len;
DIError dierr = kDIErrNone;
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
long block = pFile->fStartBlock + (long) (fOffset / kBlkSize);
int bufOffset = (long) (fOffset % kBlkSize); // (& 0x01ff)
size_t thisCount;
@ -1674,13 +1636,12 @@ A2FDPascal::Read(void* buf, size_t len, size_t* pActual)
* and writing all data in one shot. On a Pascal disk, that makes this
* process almost embarrassingly simple.
*/
DIError
A2FDPascal::Write(const void* buf, size_t len, size_t* pActual)
DIError A2FDPascal::Write(const void* buf, size_t len, size_t* pActual)
{
DIError dierr = kDIErrNone;
A2FilePascal* pFile = (A2FilePascal*) fpFile;
DiskFSPascal* pDiskFS = (DiskFSPascal*) fpFile->GetDiskFS();
unsigned char blkBuf[kBlkSize];
uint8_t blkBuf[kBlkSize];
size_t origLen = len;
LOGI(" DOS Write len=%u %s", len, pFile->GetPathName());
@ -1726,7 +1687,7 @@ A2FDPascal::Write(const void* buf, size_t len, size_t* pActual)
goto bail;
len -= kBlkSize;
buf = (unsigned char*) buf + kBlkSize;
buf = (uint8_t*) buf + kBlkSize;
} else {
/* partial block write */
memset(blkBuf, 0, sizeof(blkBuf));
@ -1756,8 +1717,7 @@ bail:
/*
* Seek to a new offset.
*/
DIError
A2FDPascal::Seek(di_off_t offset, DIWhence whence)
DIError A2FDPascal::Seek(di_off_t offset, DIWhence whence)
{
//di_off_t fileLen = ((A2FilePascal*) fpFile)->fLength;
@ -1792,8 +1752,7 @@ A2FDPascal::Seek(di_off_t offset, DIWhence whence)
/*
* Return current offset.
*/
di_off_t
A2FDPascal::Tell(void)
di_off_t A2FDPascal::Tell(void)
{
return fOffset;
}
@ -1804,15 +1763,14 @@ A2FDPascal::Tell(void)
* Most applications don't check the value of "Close", or call it from a
* destructor, so we call CloseDescr whether we succeed or not.
*/
DIError
A2FDPascal::Close(void)
DIError A2FDPascal::Close(void)
{
DIError dierr = kDIErrNone;
DiskFSPascal* pDiskFS = (DiskFSPascal*) fpFile->GetDiskFS();
if (fModified) {
A2FilePascal* pFile = (A2FilePascal*) fpFile;
unsigned char* pEntry;
uint8_t* pEntry;
dierr = pDiskFS->LoadCatalog();
if (dierr != kDIErrNone)
@ -1822,7 +1780,7 @@ A2FDPascal::Close(void)
* Update our internal copies of stuff.
*/
pFile->fLength = fOpenEOF;
pFile->fNextBlock = pFile->fStartBlock + (unsigned short) fOpenBlocksUsed;
pFile->fNextBlock = pFile->fStartBlock + (uint16_t) fOpenBlocksUsed;
pFile->fModWhen = A2FilePascal::ConvertPascalDate(time(NULL));
/*
@ -1838,8 +1796,8 @@ A2FDPascal::Close(void)
dierr = kDIErrInternal;
goto bail;
}
unsigned short bytesInLastBlock;
bytesInLastBlock = (unsigned short)pFile->fLength % kBlkSize;
uint16_t bytesInLastBlock;
bytesInLastBlock = (uint16_t)pFile->fLength % kBlkSize;
if (bytesInLastBlock == 0)
bytesInLastBlock = 512; // exactly filled out last block
@ -1861,14 +1819,13 @@ bail:
/*
* Return the #of sectors/blocks in the file.
*/
long
A2FDPascal::GetSectorCount(void) const
long A2FDPascal::GetSectorCount(void) const
{
A2FilePascal* pFile = (A2FilePascal*) fpFile;
return (pFile->fNextBlock - pFile->fStartBlock) * 2;
}
long
A2FDPascal::GetBlockCount(void) const
long A2FDPascal::GetBlockCount(void) const
{
A2FilePascal* pFile = (A2FilePascal*) fpFile;
return pFile->fNextBlock - pFile->fStartBlock;
@ -1877,8 +1834,7 @@ A2FDPascal::GetBlockCount(void) const
/*
* Return the Nth track/sector in this file.
*/
DIError
A2FDPascal::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
DIError A2FDPascal::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
{
A2FilePascal* pFile = (A2FilePascal*) fpFile;
long pascalIdx = sectorIdx / 2;
@ -1890,11 +1846,11 @@ A2FDPascal::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
BlockToTrackSector(pascalBlock, (sectorIdx & 0x01) != 0, pTrack, pSector);
return kDIErrNone;
}
/*
* Return the Nth 512-byte block in this file.
*/
DIError
A2FDPascal::GetStorage(long blockIdx, long* pBlock) const
DIError A2FDPascal::GetStorage(long blockIdx, long* pBlock) const
{
A2FilePascal* pFile = (A2FilePascal*) fpFile;
long pascalBlock = pFile->fStartBlock + blockIdx;

File diff suppressed because it is too large Load Diff

View File

@ -49,12 +49,11 @@ const int kNumDirEntryPerSect = (256 / kDirectoryEntryLen); // 8
* The initial value of "pFormatFound" is ignored, because we can reliably
* detect which variant we're looking at.
*/
static DIError
TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder,
static DIError TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder,
DiskImg::FSFormat* pFormatFound)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
if (pImg->GetNumSectPerTrack() == 13) {
@ -106,7 +105,7 @@ TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder,
*/
{
int track, sector, offset;
unsigned char orMask;
uint8_t orMask;
static const char* kCompare = "<NAME>";
DiskImg::SectorOrder order;
@ -133,7 +132,7 @@ TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder,
int i;
for (i = strlen(kCompare)-1; i >= 0; i--) {
if (sctBuf[offset+i] != ((unsigned char)kCompare[i] | orMask))
if (sctBuf[offset+i] != ((uint8_t)kCompare[i] | orMask))
break;
}
if (i >= 0) {
@ -153,8 +152,7 @@ bail:
/*
* Common RDOS test code.
*/
/*static*/ DIError
DiskFSRDOS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSRDOS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
if (!pImg->GetHasSectors()) {
@ -190,8 +188,7 @@ DiskFSRDOS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*
* Test to see if the image is an RDOS 3.3 disk.
*/
/*static*/ DIError
DiskFSRDOS::TestFS33(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSRDOS::TestFS33(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
FSLeniency leniency)
{
DIError dierr;
@ -211,8 +208,7 @@ DiskFSRDOS::TestFS33(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*
* Test to see if the image is an RDOS 3.2 disk.
*/
/*static*/ DIError
DiskFSRDOS::TestFS32(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSRDOS::TestFS32(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
FSLeniency leniency)
{
DIError dierr;
@ -232,8 +228,7 @@ DiskFSRDOS::TestFS32(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*
* Test to see if the image is an RDOS 3 (cracked 3.2) disk.
*/
/*static*/ DIError
DiskFSRDOS::TestFS3(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSRDOS::TestFS3(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
FSLeniency leniency)
{
DIError dierr;
@ -259,8 +254,7 @@ DiskFSRDOS::TestFS3(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
* on out must be handled somehow, possibly by claiming that the disk is
* completely full and has no files on it.
*/
DIError
DiskFSRDOS::Initialize(void)
DIError DiskFSRDOS::Initialize(void)
{
DIError dierr = kDIErrNone;
const char* volStr;
@ -314,15 +308,14 @@ bail:
*
* To make life easy we slurp the whole thing into memory.
*/
DIError
DiskFSRDOS::ReadCatalog(void)
DIError DiskFSRDOS::ReadCatalog(void)
{
DIError dierr = kDIErrNone;
unsigned char* dir = NULL;
unsigned char* dirPtr;
uint8_t* dir = NULL;
uint8_t* dirPtr;
int track, sector;
dir = new unsigned char[kSctSize * kNumCatSectors];
dir = new uint8_t[kSctSize * kNumCatSectors];
if (dir == NULL) {
dierr = kDIErrMalloc;
goto bail;
@ -391,8 +384,7 @@ bail:
* Create the volume usage map. Since RDOS volumes have neither
* in-use maps nor index blocks, this is pretty straightforward.
*/
DIError
DiskFSRDOS::ScanFileUsage(void)
DIError DiskFSRDOS::ScanFileUsage(void)
{
int track, sector, block, count;
@ -419,8 +411,7 @@ DiskFSRDOS::ScanFileUsage(void)
/*
* Update an entry in the usage map.
*/
void
DiskFSRDOS::SetSectorUsage(long track, long sector,
void DiskFSRDOS::SetSectorUsage(long track, long sector,
VolumeUsage::ChunkPurpose purpose)
{
VolumeUsage::ChunkState cstate;
@ -447,8 +438,7 @@ DiskFSRDOS::SetSectorUsage(long track, long sector,
/*
* Convert RDOS file type to ProDOS file type.
*/
long
A2FileRDOS::GetFileType(void) const
long A2FileRDOS::GetFileType(void) const
{
long retval;
@ -463,12 +453,10 @@ A2FileRDOS::GetFileType(void) const
return retval;
}
/*
* Dump the contents of the A2File structure.
*/
void
A2FileRDOS::Dump(void) const
void A2FileRDOS::Dump(void) const
{
LOGI("A2FileRDOS '%s' (type=%d)", fFileName, fFileType);
LOGI(" start=%d num=%d len=%d addr=0x%04x",
@ -484,10 +472,9 @@ A2FileRDOS::Dump(void) const
* low-ASCII. The inverse-mode correction turns it into punctuation, but
* I don't see a good way around it. Or any particular need to fix it.
*/
void
A2FileRDOS::FixFilename(void)
void A2FileRDOS::FixFilename(void)
{
DiskFSDOS33::LowerASCII((unsigned char*)fFileName, kMaxFileName);
DiskFSDOS33::LowerASCII((uint8_t*)fFileName, kMaxFileName);
TrimTrailingSpaces(fFileName);
}
@ -496,8 +483,7 @@ A2FileRDOS::FixFilename(void)
*
* Assumes the filename has already been converted to low ASCII.
*/
void
A2FileRDOS::TrimTrailingSpaces(char* filename)
void A2FileRDOS::TrimTrailingSpaces(char* filename)
{
char* lastspc = filename + strlen(filename);
@ -511,12 +497,10 @@ A2FileRDOS::TrimTrailingSpaces(char* filename)
*(lastspc+1) = '\0';
}
/*
* Not a whole lot to do, since there's no fancy index blocks.
*/
DIError
A2FileRDOS::Open(A2FileDescr** ppOpenFile, bool readOnly,
DIError A2FileRDOS::Open(A2FileDescr** ppOpenFile, bool readOnly,
bool rsrcFork /*=false*/)
{
if (fpOpenFile != NULL)
@ -547,8 +531,7 @@ A2FileRDOS::Open(A2FileDescr** ppOpenFile, bool readOnly,
/*
* Read a chunk of data from the current offset.
*/
DIError
A2FDRDOS::Read(void* buf, size_t len, size_t* pActual)
DIError A2FDRDOS::Read(void* buf, size_t len, size_t* pActual)
{
LOGI(" RDOS reading %d bytes from '%s' (offset=%ld)",
len, fpFile->GetPathName(), (long) fOffset);
@ -568,7 +551,7 @@ A2FDRDOS::Read(void* buf, size_t len, size_t* pActual)
long incrLen = len;
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
long block = pFile->fStartSector + (long) (fOffset / kSctSize);
int bufOffset = (int) (fOffset % kSctSize); // (& 0xff)
int ourSectPerTrack = GetOurSectPerTrack();
@ -611,8 +594,7 @@ A2FDRDOS::Read(void* buf, size_t len, size_t* pActual)
/*
* Write data at the current offset.
*/
DIError
A2FDRDOS::Write(const void* buf, size_t len, size_t* pActual)
DIError A2FDRDOS::Write(const void* buf, size_t len, size_t* pActual)
{
//if (!fOpen)
// return kDIErrNotReady;
@ -622,8 +604,7 @@ A2FDRDOS::Write(const void* buf, size_t len, size_t* pActual)
/*
* Seek to a new offset.
*/
DIError
A2FDRDOS::Seek(di_off_t offset, DIWhence whence)
DIError A2FDRDOS::Seek(di_off_t offset, DIWhence whence)
{
//if (!fOpen)
// return kDIErrNotReady;
@ -661,8 +642,7 @@ A2FDRDOS::Seek(di_off_t offset, DIWhence whence)
/*
* Return current offset.
*/
di_off_t
A2FDRDOS::Tell(void)
di_off_t A2FDRDOS::Tell(void)
{
//if (!fOpen)
// return kDIErrNotReady;
@ -673,8 +653,7 @@ A2FDRDOS::Tell(void)
/*
* Release file state, such as it is.
*/
DIError
A2FDRDOS::Close(void)
DIError A2FDRDOS::Close(void)
{
fpFile->CloseDescr(this);
return kDIErrNone;
@ -683,15 +662,14 @@ A2FDRDOS::Close(void)
/*
* Return the #of sectors/blocks in the file.
*/
long
A2FDRDOS::GetSectorCount(void) const
long A2FDRDOS::GetSectorCount(void) const
{
//if (!fOpen)
// return kDIErrNotReady;
return ((A2FileRDOS*) fpFile)->fNumSectors;
}
long
A2FDRDOS::GetBlockCount(void) const
long A2FDRDOS::GetBlockCount(void) const
{
//if (!fOpen)
// return kDIErrNotReady;
@ -701,8 +679,7 @@ A2FDRDOS::GetBlockCount(void) const
/*
* Return the Nth track/sector in this file.
*/
DIError
A2FDRDOS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
DIError A2FDRDOS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
{
//if (!fOpen)
// return kDIErrNotReady;
@ -717,11 +694,11 @@ A2FDRDOS::GetStorage(long sectorIdx, long* pTrack, long* pSector) const
return kDIErrNone;
}
/*
* Return the Nth 512-byte block in this file.
*/
DIError
A2FDRDOS::GetStorage(long blockIdx, long* pBlock) const
DIError A2FDRDOS::GetStorage(long blockIdx, long* pBlock) const
{
//if (!fOpen)
// return kDIErrNotReady;

View File

@ -20,12 +20,11 @@
*
* Returns the LBA of the last valid block and the device's block size.
*/
/*static*/ DIError
SPTI::GetDeviceCapacity(HANDLE handle, unsigned long* pLastBlock,
unsigned long* pBlockSize)
/*static*/ DIError SPTI::GetDeviceCapacity(HANDLE handle, uint32_t* pLastBlock,
uint32_t* pBlockSize)
{
SCSI_PASS_THROUGH_DIRECT sptd;
unsigned long lba, blockLen;
uint32_t lba, blockLen;
CDB_ReadCapacityData dataBuf;
DWORD cb;
BOOL status;
@ -54,7 +53,7 @@ SPTI::GetDeviceCapacity(HANDLE handle, unsigned long* pLastBlock,
if (!status) {
DWORD lastError = ::GetLastError();
LOGI("DeviceIoControl(SCSI READ CAPACITY) failed, err=%ld",
LOGE("DeviceIoControl(SCSI READ CAPACITY) failed, err=%ld",
::GetLastError());
if (lastError == ERROR_IO_DEVICE) // no disc in drive
return kDIErrDeviceNotReady;
@ -62,14 +61,14 @@ SPTI::GetDeviceCapacity(HANDLE handle, unsigned long* pLastBlock,
return kDIErrSPTIFailure;
}
lba = (unsigned long) dataBuf.logicalBlockAddr0 << 24 |
(unsigned long) dataBuf.logicalBlockAddr1 << 16 |
(unsigned long) dataBuf.logicalBlockAddr2 << 8 |
(unsigned long) dataBuf.logicalBlockAddr3;
blockLen = (unsigned long) dataBuf.bytesPerBlock0 << 24 |
(unsigned long) dataBuf.bytesPerBlock1 << 16 |
(unsigned long) dataBuf.bytesPerBlock2 << 8 |
(unsigned long) dataBuf.bytesPerBlock3;
lba = (uint32_t) dataBuf.logicalBlockAddr0 << 24 |
(uint32_t) dataBuf.logicalBlockAddr1 << 16 |
(uint32_t) dataBuf.logicalBlockAddr2 << 8 |
(uint32_t) dataBuf.logicalBlockAddr3;
blockLen = (uint32_t) dataBuf.bytesPerBlock0 << 24 |
(uint32_t) dataBuf.bytesPerBlock1 << 16 |
(uint32_t) dataBuf.bytesPerBlock2 << 8 |
(uint32_t) dataBuf.bytesPerBlock3;
*pLastBlock = lba;
*pBlockSize = blockLen;
@ -83,9 +82,8 @@ SPTI::GetDeviceCapacity(HANDLE handle, unsigned long* pLastBlock,
*
* "buf" must be able to hold (numBlocks * blockSize) bytes.
*/
/*static*/ DIError
SPTI::ReadBlocks(HANDLE handle, long startBlock, short numBlocks,
long blockSize, void* buf)
/*static*/ DIError SPTI::ReadBlocks(HANDLE handle, long startBlock,
short numBlocks, long blockSize, void* buf)
{
SCSI_PASS_THROUGH_DIRECT sptd;
DWORD cb;
@ -95,7 +93,7 @@ SPTI::ReadBlocks(HANDLE handle, long startBlock, short numBlocks,
assert(numBlocks > 0);
assert(buf != NULL);
//LOGI(" SPTI phys read block (%ld) %d", startBlock, numBlocks);
LOGD(" SPTI phys read block (%ld) %d", startBlock, numBlocks);
memset(&sptd, 0, sizeof(sptd));
sptd.Length = sizeof(sptd); // size of struct (+ request-sense buffer)
@ -113,23 +111,23 @@ SPTI::ReadBlocks(HANDLE handle, long startBlock, short numBlocks,
CDB10* pCdb = (CDB10*) &sptd.Cdb;
pCdb->operationCode = kScsiOpRead;
pCdb->logicalBlockAddr0 = (unsigned char) (startBlock >> 24); // MSB
pCdb->logicalBlockAddr1 = (unsigned char) (startBlock >> 16);
pCdb->logicalBlockAddr2 = (unsigned char) (startBlock >> 8);
pCdb->logicalBlockAddr3 = (unsigned char) startBlock; // LSB
pCdb->transferLength0 = (unsigned char) (numBlocks >> 8); // MSB
pCdb->transferLength1 = (unsigned char) numBlocks; // LSB
pCdb->logicalBlockAddr0 = (uint8_t) (startBlock >> 24); // MSB
pCdb->logicalBlockAddr1 = (uint8_t) (startBlock >> 16);
pCdb->logicalBlockAddr2 = (uint8_t) (startBlock >> 8);
pCdb->logicalBlockAddr3 = (uint8_t) startBlock; // LSB
pCdb->transferLength0 = (uint8_t) (numBlocks >> 8); // MSB
pCdb->transferLength1 = (uint8_t) numBlocks; // LSB
status = ::DeviceIoControl(handle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
&sptd, sizeof(sptd), NULL, 0, &cb, NULL);
if (!status) {
LOGI("DeviceIoControl(SCSI READ(10)) failed, err=%ld",
LOGE("DeviceIoControl(SCSI READ(10)) failed, err=%ld",
::GetLastError());
return kDIErrReadFailed; // close enough
}
if (sptd.ScsiStatus != 0) {
LOGI("SCSI READ(10) failed, status=%d", sptd.ScsiStatus);
LOGE("SCSI READ(10) failed, status=%d", sptd.ScsiStatus);
return kDIErrReadFailed;
}

View File

@ -25,15 +25,15 @@ public:
// Get the capacity, expressed as the highest-available LBA and the device
// block size.
static DIError GetDeviceCapacity(HANDLE handle, unsigned long* pLastBlock,
unsigned long* pBlockSize);
static DIError GetDeviceCapacity(HANDLE handle, uint32_t* pLastBlock,
uint32_t* pBlockSize);
private:
SPTI(void) {}
~SPTI(void) {}
};
} // namespace DiskImgLib
} // namespace DiskImgLib
#endif /*_WIN32*/

View File

@ -63,6 +63,7 @@ typedef unsigned int ssize_t;
#define HAVE__VSNPRINTF
#define strcasecmp stricmp
#define snprintf _snprintf
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

View File

@ -25,10 +25,10 @@
*
* Returns 0 on success, -1 if one of the arguments was bad.
*/
int
TwoImgHeader::InitHeader(int imageFormat, long imageSize, long imageBlockCount)
int TwoImgHeader::InitHeader(int imageFormat, uint32_t imageSize,
uint32_t imageBlockCount)
{
if (imageSize <= 0)
if (imageSize == 0)
return -1;
if (imageFormat < kImageFormatDOS || imageFormat > kImageFormatNibble)
return -1;
@ -36,7 +36,7 @@ TwoImgHeader::InitHeader(int imageFormat, long imageSize, long imageBlockCount)
if (imageFormat != kImageFormatNibble &&
imageSize != imageBlockCount * 512)
{
LOGI("2MG InitHeader: bad sizes %d %ld %ld", imageFormat,
LOGW("2MG InitHeader: bad sizes %d %ld %ld", imageFormat,
imageSize, imageBlockCount);
return -1;
}
@ -70,8 +70,7 @@ TwoImgHeader::InitHeader(int imageFormat, long imageSize, long imageBlockCount)
* default volume number. For the way we currently make use of this, this
* makes the most sense.
*/
short
TwoImgHeader::GetDOSVolumeNum(void) const
int16_t TwoImgHeader::GetDOSVolumeNum(void) const
{
assert(fFlags & kDOSVolumeSet);
return fDOSVolumeNum;
@ -80,8 +79,7 @@ TwoImgHeader::GetDOSVolumeNum(void) const
/*
* Set the DOS volume number.
*/
void
TwoImgHeader::SetDOSVolumeNum(short dosVolumeNum)
void TwoImgHeader::SetDOSVolumeNum(short dosVolumeNum)
{
assert(dosVolumeNum >= 0 && dosVolumeNum < 256);
fFlags |= dosVolumeNum;
@ -91,8 +89,7 @@ TwoImgHeader::SetDOSVolumeNum(short dosVolumeNum)
/*
* Set the comment.
*/
void
TwoImgHeader::SetComment(const char* comment)
void TwoImgHeader::SetComment(const char* comment)
{
delete[] fComment;
if (comment == NULL) {
@ -120,8 +117,7 @@ TwoImgHeader::SetComment(const char* comment)
/*
* Set the creator chunk.
*/
void
TwoImgHeader::SetCreatorChunk(const void* chunk, long len)
void TwoImgHeader::SetCreatorChunk(const void* chunk, long len)
{
assert(len >= 0);
@ -155,10 +151,9 @@ TwoImgHeader::SetCreatorChunk(const void* chunk, long len)
*
* Returns 0 on success, nonzero on error or invalid header.
*/
int
TwoImgHeader::ReadHeader(FILE* fp, long totalLength)
int TwoImgHeader::ReadHeader(FILE* fp, uint32_t totalLength)
{
unsigned char buf[kOurHeaderLen];
uint8_t buf[kOurHeaderLen];
fread(buf, kOurHeaderLen, 1, fp);
if (ferror(fp))
@ -205,11 +200,10 @@ TwoImgHeader::ReadHeader(FILE* fp, long totalLength)
*
* Returns 0 on success, nonzero on error or invalid header.
*/
int
TwoImgHeader::ReadHeader(GenericFD* pGFD, long totalLength)
int TwoImgHeader::ReadHeader(GenericFD* pGFD, uint32_t totalLength)
{
DIError dierr;
unsigned char buf[kOurHeaderLen];
uint8_t buf[kOurHeaderLen];
dierr = pGFD->Read(buf, kOurHeaderLen);
if (dierr != kDIErrNone)
@ -254,8 +248,7 @@ TwoImgHeader::ReadHeader(GenericFD* pGFD, long totalLength)
/*
* Grab a chunk of data from a relative offset.
*/
int
TwoImgHeader::GetChunk(GenericFD* pGFD, di_off_t relOffset, long len,
int TwoImgHeader::GetChunk(GenericFD* pGFD, di_off_t relOffset, long len,
void** pBuf)
{
DIError dierr;
@ -295,8 +288,7 @@ TwoImgHeader::GetChunk(GenericFD* pGFD, di_off_t relOffset, long len,
/*
* Grab a chunk of data from a relative offset.
*/
int
TwoImgHeader::GetChunk(FILE* fp, di_off_t relOffset, long len,
int TwoImgHeader::GetChunk(FILE* fp, di_off_t relOffset, long len,
void** pBuf)
{
long curPos;
@ -340,8 +332,7 @@ TwoImgHeader::GetChunk(FILE* fp, di_off_t relOffset, long len,
*
* Performs some sanity checks. Returns 0 on success, -1 on failure.
*/
int
TwoImgHeader::UnpackHeader(const unsigned char* buf, long totalLength)
int TwoImgHeader::UnpackHeader(const uint8_t* buf, uint32_t totalLength)
{
fMagic = GetLongBE(&buf[0x00]);
fCreator = GetLongBE(&buf[0x04]);
@ -378,7 +369,7 @@ TwoImgHeader::UnpackHeader(const unsigned char* buf, long totalLength)
}
if (fVersion > 1) {
LOGI("ERROR: unsupported version=%d", fVersion);
LOGW("ERROR: unsupported version=%d", fVersion);
return -1; // bad header until I hear otherwise
}
@ -402,22 +393,22 @@ TwoImgHeader::UnpackHeader(const unsigned char* buf, long totalLength)
if (fImageFormat != kImageFormatNibble &&
fNumBlocks * kBlockSize != fDataLen)
{
LOGI("numBlocks/dataLen mismatch (%ld vs %ld)",
LOGW("numBlocks/dataLen mismatch (%ld vs %ld)",
fNumBlocks * kBlockSize, fDataLen);
return -1;
}
if (fDataLen + fDataOffset > totalLength) {
LOGI("Invalid dataLen/offset/fileLength (dl=%ld, off=%ld, tlen=%ld)",
LOGW("Invalid dataLen/offset/fileLength (dl=%ld, off=%ld, tlen=%ld)",
fDataLen, fDataOffset, totalLength);
return -1;
}
if (fImageFormat < kImageFormatDOS || fImageFormat > kImageFormatNibble) {
LOGI("Invalid image format %ld", fImageFormat);
LOGW("Invalid image format %ld", fImageFormat);
return -1;
}
if (fCmtOffset > 0 && fCmtOffset < fDataOffset + fDataLen) {
LOGI("2MG comment is inside the data section (off=%ld, data end=%ld)",
LOGW("2MG comment is inside the data section (off=%ld, data end=%ld)",
fCmtOffset, fDataOffset+fDataLen);
DebugBreak();
// ignore the comment
@ -425,10 +416,10 @@ TwoImgHeader::UnpackHeader(const unsigned char* buf, long totalLength)
fCmtLen = 0;
}
if (fCreatorOffset > 0 && fCreatorLen > 0) {
long prevEnd = fDataOffset + fDataLen + fCmtLen;
uint32_t prevEnd = fDataOffset + fDataLen + fCmtLen;
if (fCreatorOffset < prevEnd) {
LOGI("2MG creator chunk is inside prev data (off=%ld, data end=%ld)",
LOGW("2MG creator chunk is inside prev data (off=%ld, data end=%ld)",
fCreatorOffset, prevEnd);
DebugBreak();
// ignore the creator chunk
@ -448,7 +439,7 @@ TwoImgHeader::UnpackHeader(const unsigned char* buf, long totalLength)
int
TwoImgHeader::WriteHeader(FILE* fp) const
{
unsigned char buf[kOurHeaderLen];
uint8_t buf[kOurHeaderLen];
PackHeader(buf);
if (fwrite(buf, kOurHeaderLen, 1, fp) != 1)
@ -464,7 +455,7 @@ TwoImgHeader::WriteHeader(FILE* fp) const
int
TwoImgHeader::WriteHeader(GenericFD* pGFD) const
{
unsigned char buf[kOurHeaderLen];
uint8_t buf[kOurHeaderLen];
PackHeader(buf);
@ -519,7 +510,7 @@ TwoImgHeader::WriteFooter(GenericFD* pGFD) const
* Pack the header values into a 64-byte buffer.
*/
void
TwoImgHeader::PackHeader(unsigned char* buf) const
TwoImgHeader::PackHeader(uint8_t* buf) const
{
if (fCmtLen > 0 && fCmtOffset == 0) {
assert(false);

View File

@ -42,20 +42,20 @@ public:
*/
//char fMagic[4];
//char fCreator[4];
unsigned long fMagic;
unsigned long fCreator;
short fHeaderLen;
short fVersion;
long fImageFormat;
unsigned long fFlags; // may include DOS volume num
long fNumBlocks; // 512-byte blocks
long fDataOffset;
long fDataLen;
long fCmtOffset;
long fCmtLen;
long fCreatorOffset;
long fCreatorLen;
long fSpare[4];
uint32_t fMagic;
uint32_t fCreator;
uint16_t fHeaderLen;
uint16_t fVersion;
uint32_t fImageFormat;
uint32_t fFlags; // may include DOS volume num
uint32_t fNumBlocks; // 512-byte blocks
uint32_t fDataOffset;
uint32_t fDataLen;
uint32_t fCmtOffset;
uint32_t fCmtLen;
uint32_t fCreatorOffset;
uint32_t fCreatorLen;
uint32_t fSpare[4];
/*
* Related constants.
@ -93,9 +93,9 @@ public:
* end of the data section. This is done in case the file has some
* sort of wrapper outside the 2MG header.
*/
int InitHeader(int imageFormat, long imageSize, long imageBlockCount);
int ReadHeader(FILE* fp, long totalLength);
int ReadHeader(GenericFD* pGFD, long totalLength);
int InitHeader(int imageFormat, uint32_t imageSize, uint32_t imageBlockCount);
int ReadHeader(FILE* fp, uint32_t totalLength);
int ReadHeader(GenericFD* pGFD, uint32_t totalLength);
int WriteHeader(FILE* fp) const;
int WriteHeader(GenericFD* pGFD) const;
int WriteFooter(FILE* fp) const;
@ -108,7 +108,7 @@ public:
const char* GetMagicStr(void) const { return fMagicStr; }
const char* GetCreatorStr(void) const { return fCreatorStr; }
short GetDOSVolumeNum(void) const;
int16_t GetDOSVolumeNum(void) const;
void SetDOSVolumeNum(short dosVolumeNum);
const char* GetComment(void) const { return fComment; }
void SetComment(const char* comment);
@ -116,14 +116,12 @@ public:
void SetCreatorChunk(const void* creatorBlock, long len);
private:
int UnpackHeader(const unsigned char* buf, long totalLength);
void PackHeader(unsigned char* buf) const;
int GetChunk(GenericFD* pGFD, di_off_t relOffset, long len,
void** pBuf);
int GetChunk(FILE* fp, di_off_t relOffset, long len,
void** pBuf);
int UnpackHeader(const uint8_t* buf, uint32_t totalLength);
void PackHeader(uint8_t* buf) const;
int GetChunk(GenericFD* pGFD, di_off_t relOffset, long len, void** pBuf);
int GetChunk(FILE* fp, di_off_t relOffset, long len, void** pBuf);
int fDOSVolumeNum;
int16_t fDOSVolumeNum; // 8-bit volume number, or -1
char fMagicStr[5];
char fCreatorStr[5];
@ -131,6 +129,6 @@ private:
char* fCreatorChunk;
};
} // namespace DiskImgLib
} // namespace DiskImgLib
#endif /*DISKIMG_TWOIMG_H*/

View File

@ -44,9 +44,8 @@ const int kMaxCatalogIterations = 64;
* Read a track/sector, adjusting for 32-sector disks being treated as
* if they were 16-sector.
*/
static DIError
ReadTrackSectorAdjusted(DiskImg* pImg, int track, int sector,
int trackOffset, unsigned char* buf, DiskImg::SectorOrder imageOrder)
static DIError ReadTrackSectorAdjusted(DiskImg* pImg, int track, int sector,
int trackOffset, uint8_t* buf, DiskImg::SectorOrder imageOrder)
{
track += trackOffset;
track *= 2;
@ -61,12 +60,11 @@ ReadTrackSectorAdjusted(DiskImg* pImg, int track, int sector,
/*
* Test for presence of 400K DOS 3.3 volumes.
*/
static DIError
TestImageHalf(DiskImg* pImg, int trackOffset, DiskImg::SectorOrder imageOrder,
int* pGoodCount)
static DIError TestImageHalf(DiskImg* pImg, int trackOffset,
DiskImg::SectorOrder imageOrder, int* pGoodCount)
{
DIError dierr = kDIErrNone;
unsigned char sctBuf[kSctSize];
uint8_t sctBuf[kSctSize];
int numTracks, numSectors;
int catTrack, catSect;
int foundGood = 0;
@ -140,8 +138,8 @@ bail:
/*
* Test both of the DOS partitions.
*/
static DIError
TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder, int* pGoodCount)
static DIError TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder,
int* pGoodCount)
{
DIError dierr;
int goodCount1, goodCount2;
@ -169,8 +167,7 @@ TestImage(DiskImg* pImg, DiskImg::SectorOrder imageOrder, int* pGoodCount)
/*
* Test to see if the image is a UNIDOS volume.
*/
/*static*/ DIError
DiskFSUNIDOS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSUNIDOS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
/* only on 800K disks (at the least, insist on numTracks being even) */
@ -219,8 +216,7 @@ DiskFSUNIDOS::TestFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
* swap can return a "good" value of 7 (much less than the expected 30, but
* above a threshold of reasonableness).
*/
/*static*/ DIError
DiskFSUNIDOS::TestWideFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*static*/ DIError DiskFSUNIDOS::TestWideFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
DiskImg::FSFormat* pFormat, FSLeniency leniency)
{
/* only on 400K "disks" */
@ -269,8 +265,7 @@ DiskFSUNIDOS::TestWideFS(DiskImg* pImg, DiskImg::SectorOrder* pOrder,
/*
* Set up our sub-volumes.
*/
DIError
DiskFSUNIDOS::Initialize(void)
DIError DiskFSUNIDOS::Initialize(void)
{
DIError dierr = kDIErrNone;
@ -294,8 +289,7 @@ DiskFSUNIDOS::Initialize(void)
/*
* Open up one of the DOS 3.3 sub-volumes.
*/
DIError
DiskFSUNIDOS::OpenSubVolume(int idx)
DIError DiskFSUNIDOS::OpenSubVolume(int idx)
{
DIError dierr = kDIErrNone;
DiskFS* pNewFS = NULL;

View File

@ -13,8 +13,7 @@
/*
* Initialize structures for a block-structured disk.
*/
DIError
DiskFS::VolumeUsage::Create(long numBlocks)
DIError DiskFS::VolumeUsage::Create(long numBlocks)
{
if (numBlocks <= 0 || numBlocks > 32*1024*1024) // 16GB
return kDIErrInvalidArg;
@ -35,8 +34,7 @@ DiskFS::VolumeUsage::Create(long numBlocks)
/*
* Initialize structures for a track/sector-structured disk.
*/
DIError
DiskFS::VolumeUsage::Create(long numTracks, long numSectors)
DIError DiskFS::VolumeUsage::Create(long numTracks, long numSectors)
{
long count = numTracks * numSectors;
if (numTracks <= 0 || count <= 0 || count > 32*1024*1024)
@ -58,15 +56,14 @@ DiskFS::VolumeUsage::Create(long numTracks, long numSectors)
/*
* Return the state of a particular chunk.
*/
DIError
DiskFS::VolumeUsage::GetChunkState(long block, ChunkState* pState) const
DIError DiskFS::VolumeUsage::GetChunkState(long block, ChunkState* pState) const
{
if (!fByBlocks)
return kDIErrInvalidArg;
return GetChunkStateIdx(block, pState);
}
DIError
DiskFS::VolumeUsage::GetChunkState(long track, long sector,
DIError DiskFS::VolumeUsage::GetChunkState(long track, long sector,
ChunkState* pState) const
{
if (fByBlocks)
@ -75,8 +72,8 @@ DiskFS::VolumeUsage::GetChunkState(long track, long sector,
return kDIErrInvalidArg;
return GetChunkStateIdx(track * fNumSectors + sector, pState);
}
DIError
DiskFS::VolumeUsage::GetChunkStateIdx(int idx, ChunkState* pState) const
DIError DiskFS::VolumeUsage::GetChunkStateIdx(int idx, ChunkState* pState) const
{
if (fList == NULL || idx < 0 || idx >= fListSize) {
assert(false);
@ -94,15 +91,14 @@ DiskFS::VolumeUsage::GetChunkStateIdx(int idx, ChunkState* pState) const
/*
* Set the state of a particular chunk.
*/
DIError
DiskFS::VolumeUsage::SetChunkState(long block, const ChunkState* pState)
DIError DiskFS::VolumeUsage::SetChunkState(long block, const ChunkState* pState)
{
if (!fByBlocks)
return kDIErrInvalidArg;
return SetChunkStateIdx(block, pState);
}
DIError
DiskFS::VolumeUsage::SetChunkState(long track, long sector,
DIError DiskFS::VolumeUsage::SetChunkState(long track, long sector,
const ChunkState* pState)
{
if (fByBlocks)
@ -111,8 +107,8 @@ DiskFS::VolumeUsage::SetChunkState(long track, long sector,
return kDIErrInvalidArg;
return SetChunkStateIdx(track * fNumSectors + sector, pState);
}
DIError
DiskFS::VolumeUsage::SetChunkStateIdx(int idx, const ChunkState* pState)
DIError DiskFS::VolumeUsage::SetChunkStateIdx(int idx, const ChunkState* pState)
{
if (fList == NULL || idx < 0 || idx >= fListSize) {
assert(false);
@ -136,12 +132,10 @@ DiskFS::VolumeUsage::SetChunkStateIdx(int idx, const ChunkState* pState)
return kDIErrNone;
}
/*
* Count up the #of free chunks.
*/
long
DiskFS::VolumeUsage::GetActualFreeChunks(void) const
long DiskFS::VolumeUsage::GetActualFreeChunks(void) const
{
ChunkState cstate; // could probably do this bitwise...
int freeCount = 0;
@ -170,7 +164,6 @@ DiskFS::VolumeUsage::GetActualFreeChunks(void) const
return freeCount;
}
/*
* Convert a ChunkState into a single, hopefully meaningful, character.
*
@ -183,8 +176,7 @@ DiskFS::VolumeUsage::GetActualFreeChunks(void) const
* 'I' - inuse, marked, used by file structure (index block)
* 'F' - inuse, marked, used by file
*/
inline char
DiskFS::VolumeUsage::StateToChar(ChunkState* pState) const
char DiskFS::VolumeUsage::StateToChar(ChunkState* pState) const
{
if (!pState->isUsed && !pState->isMarkedUsed)
return '.';
@ -217,8 +209,7 @@ DiskFS::VolumeUsage::StateToChar(ChunkState* pState) const
/*
* Dump the list.
*/
void
DiskFS::VolumeUsage::Dump(void) const
void DiskFS::VolumeUsage::Dump(void) const
{
#define kMapInit "--------------------------------"
if (fList == NULL) {

View File

@ -43,8 +43,7 @@
/*
* Open a logical volume.
*/
DIError
Win32VolumeAccess::Open(const WCHAR* deviceName, bool readOnly)
DIError Win32VolumeAccess::Open(const WCHAR* deviceName, bool readOnly)
{
DIError dierr = kDIErrNone;
@ -107,8 +106,7 @@ bail:
/*
* Close the device.
*/
void
Win32VolumeAccess::Close(void)
void Win32VolumeAccess::Close(void)
{
if (fpBlockAccess != NULL) {
DIError dierr;
@ -130,7 +128,6 @@ Win32VolumeAccess::Close(void)
}
}
/*
* Read a range of blocks from the device.
*
@ -142,8 +139,7 @@ Win32VolumeAccess::Close(void)
*
* Returns with an error if any of the blocks could not be read.
*/
DIError
Win32VolumeAccess::ReadBlocks(long startBlock, short blockCount,
DIError Win32VolumeAccess::ReadBlocks(long startBlock, short blockCount,
void* buf)
{
DIError dierr = kDIErrNone;
@ -192,15 +188,13 @@ bail:
return dierr;
}
/*
* Write a range of blocks to the device. For the most part this just
* writes to the cache.
*
* Returns with an error if any of the blocks could not be read.
*/
DIError
Win32VolumeAccess::WriteBlocks(long startBlock, short blockCount,
DIError Win32VolumeAccess::WriteBlocks(long startBlock, short blockCount,
const void* buf)
{
DIError dierr = kDIErrNone;
@ -242,7 +236,6 @@ bail:
return dierr;
}
/*
* Write all blocks in the cache to disk if any of them are dirty. In some
* ways this is wasteful -- we could be writing stuff that isn't dirty,
@ -255,8 +248,7 @@ bail:
*
* If "purge" is set, we discard the blocks after writing them.
*/
DIError
Win32VolumeAccess::FlushCache(bool purge)
DIError Win32VolumeAccess::FlushCache(bool purge)
{
DIError dierr = kDIErrNone;
@ -305,8 +297,7 @@ bail:
*
* On success, "*pNumBlocks" gets the number of 512-byte blocks.
*/
DIError
Win32VolumeAccess::BlockAccess::DetectCapacitySPTI(HANDLE handle,
DIError Win32VolumeAccess::BlockAccess::DetectCapacitySPTI(HANDLE handle,
bool isCDROM, long* pNumBlocks)
{
#ifndef HAVE_WINDOWS_CDROM
@ -315,17 +306,17 @@ Win32VolumeAccess::BlockAccess::DetectCapacitySPTI(HANDLE handle,
#endif
DIError dierr = kDIErrNone;
unsigned long lba, blockLen;
uint32_t lba, blockLen;
dierr = SPTI::GetDeviceCapacity(handle, &lba, &blockLen);
if (dierr != kDIErrNone)
goto bail;
LOGI("READ CAPACITY reports lba=%lu blockLen=%lu (total=%lu)",
LOGI("READ CAPACITY reports lba=%u blockLen=%u (total=%u)",
lba, blockLen, lba*blockLen);
if (isCDROM && blockLen != kCDROMSectorSize) {
LOGI("Unacceptable CD-ROM blockLen=%ld, bailing", blockLen);
LOGW("Unacceptable CD-ROM blockLen=%ld, bailing", blockLen);
dierr = kDIErrReadFailed;
goto bail;
}
@ -351,8 +342,8 @@ bail:
* This sets "*pNumBlocks" on success. The largest size this will detect
* is currently 8GB.
*/
/*static*/ DIError
Win32VolumeAccess::BlockAccess::ScanCapacity(BlockAccess* pThis, long* pNumBlocks)
/*static*/ DIError Win32VolumeAccess::BlockAccess::ScanCapacity(BlockAccess* pThis,
long* pNumBlocks)
{
DIError dierr = kDIErrNone;
// max out at 8GB (-1 block)
@ -441,11 +432,11 @@ bail:
/*
* Figure out if the block at "blockNum" exists.
*/
/*static*/ bool
Win32VolumeAccess::BlockAccess::CanReadBlock(BlockAccess* pThis, long blockNum)
/*static*/ bool Win32VolumeAccess::BlockAccess::CanReadBlock(BlockAccess* pThis,
long blockNum)
{
DIError dierr;
unsigned char buf[BlockAccess::kBlockSize];
uint8_t buf[BlockAccess::kBlockSize];
dierr = pThis->ReadBlocks(blockNum, 1, buf);
if (dierr == kDIErrNone) {
@ -515,8 +506,8 @@ typedef struct _DRIVEMAPINFO {
*
* Pass in the vwin32 handle.
*/
/*static*/ DIError
Win32VolumeAccess::BlockAccess::GetInt13Unit(HANDLE handle, int driveNum, int* pInt13Unit)
/*static*/ DIError Win32VolumeAccess::BlockAccess::GetInt13Unit(HANDLE handle,
int driveNum, int* pInt13Unit)
{
DIError dierr = kDIErrNone;
BOOL result;
@ -606,8 +597,7 @@ bail:
* is returned, "*pNumTracks", "*pNumHeads", and "*pNumSectors" will receive
* values if the pointers are non-NULL.
*/
/*static*/ bool
Win32VolumeAccess::BlockAccess::LookupFloppyGeometry(long totalBlocks,
/*static*/ bool Win32VolumeAccess::BlockAccess::LookupFloppyGeometry(long totalBlocks,
DiskGeometry* pGeometry)
{
static const struct {
@ -661,8 +651,7 @@ Win32VolumeAccess::BlockAccess::LookupFloppyGeometry(long totalBlocks,
*
* Returns "true" on success, "false" on failure.
*/
/*static*/ bool
Win32VolumeAccess::BlockAccess::BlockToCylinderHeadSector(long blockNum,
/*static*/ bool Win32VolumeAccess::BlockAccess::BlockToCylinderHeadSector(long blockNum,
const DiskGeometry* pGeometry, int* pCylinder, int* pHead,
int* pSector, long* pLastBlockOnTrack)
{
@ -696,9 +685,8 @@ Win32VolumeAccess::BlockAccess::BlockToCylinderHeadSector(long blockNum,
/*
* Get the floppy drive kind (*not* the media kind) using Int13h func 8.
*/
/*static*/ DIError
Win32VolumeAccess::BlockAccess::GetFloppyDriveKind(HANDLE handle, int unitNum,
FloppyKind* pKind)
/*static*/ DIError Win32VolumeAccess::BlockAccess::GetFloppyDriveKind(HANDLE handle,
int unitNum, FloppyKind* pKind)
{
DIOC_REGISTERS reg = {0};
DWORD cb;
@ -740,9 +728,8 @@ Win32VolumeAccess::BlockAccess::GetFloppyDriveKind(HANDLE handle, int unitNum,
* Returns 0 on success, the status code from AH on failure. If the call
* fails but AH is zero, -1 is returned.
*/
/*static*/ int
Win32VolumeAccess::BlockAccess::ReadBlocksInt13h(HANDLE handle, int unitNum,
int cylinder, int head, int sector, short blockCount, void* buf)
/*static*/ int Win32VolumeAccess::BlockAccess::ReadBlocksInt13h(HANDLE handle,
int unitNum, int cylinder, int head, int sector, short blockCount, void* buf)
{
DIOC_REGISTERS reg = {0};
DWORD cb;
@ -787,7 +774,6 @@ Win32VolumeAccess::BlockAccess::ReadBlocksInt13h(HANDLE handle, int unitNum,
return 0;
}
/*
* Read one or more blocks using Int13h services. This only works on
* floppy drives due to Win9x limitations.
@ -796,9 +782,8 @@ Win32VolumeAccess::BlockAccess::ReadBlocksInt13h(HANDLE handle, int unitNum,
* reasons. Because this is fairly "raw", we have to retry it 3x before
* giving up.
*/
/*static*/ DIError
Win32VolumeAccess::BlockAccess::ReadBlocksInt13h(HANDLE handle, int unitNum,
const DiskGeometry* pGeometry, long startBlock, short blockCount,
/*static*/ DIError Win32VolumeAccess::BlockAccess::ReadBlocksInt13h(HANDLE handle,
int unitNum, const DiskGeometry* pGeometry, long startBlock, short blockCount,
void* buf)
{
int cylinder, head, sector;
@ -861,9 +846,8 @@ Win32VolumeAccess::BlockAccess::ReadBlocksInt13h(HANDLE handle, int unitNum,
* reasons. Because this is fairly "raw", we have to retry it 3x before
* giving up.
*/
/*static*/ int
Win32VolumeAccess::BlockAccess::WriteBlocksInt13h(HANDLE handle, int unitNum,
int cylinder, int head, int sector, short blockCount,
/*static*/ int Win32VolumeAccess::BlockAccess::WriteBlocksInt13h(HANDLE handle,
int unitNum, int cylinder, int head, int sector, short blockCount,
const void* buf)
{
DIOC_REGISTERS reg = {0};
@ -910,9 +894,8 @@ Win32VolumeAccess::BlockAccess::WriteBlocksInt13h(HANDLE handle, int unitNum,
*
* Returns "true" on success, "false" on failure.
*/
/*static*/ DIError
Win32VolumeAccess::BlockAccess::WriteBlocksInt13h(HANDLE handle, int unitNum,
const DiskGeometry* pGeometry, long startBlock, short blockCount,
/*static*/ DIError Win32VolumeAccess::BlockAccess::WriteBlocksInt13h(HANDLE handle,
int unitNum, const DiskGeometry* pGeometry, long startBlock, short blockCount,
const void* buf)
{
int cylinder, head, sector;
@ -962,16 +945,14 @@ Win32VolumeAccess::BlockAccess::WriteBlocksInt13h(HANDLE handle, int unitNum,
return kDIErrNone;
}
/*
* Read blocks from a Win9x logical volume, using Int21h func 7305h. Pass in
* a handle to vwin32 and the logical drive number (A=1, B=2, etc).
*
* Works on Win95 OSR2 and later. Earlier versions require Int25 or Int13.
*/
/*static*/ DIError
Win32VolumeAccess::BlockAccess::ReadBlocksInt21h(HANDLE handle, int driveNum,
long startBlock, short blockCount, void* buf)
/*static*/ DIError Win32VolumeAccess::BlockAccess::ReadBlocksInt21h(HANDLE handle,
int driveNum, long startBlock, short blockCount, void* buf)
{
#if 0
assert(false); // discouraged
@ -1040,9 +1021,8 @@ Win32VolumeAccess::BlockAccess::ReadBlocksInt21h(HANDLE handle, int driveNum,
*
* Works on Win95 OSR2 and later. Earlier versions require Int26 or Int13.
*/
/*static*/ DIError
Win32VolumeAccess::BlockAccess::WriteBlocksInt21h(HANDLE handle, int driveNum,
long startBlock, short blockCount, const void* buf)
/*static*/ DIError Win32VolumeAccess::BlockAccess::WriteBlocksInt21h(HANDLE handle,
int driveNum, long startBlock, short blockCount, const void* buf)
{
BOOL result;
DWORD cb;
@ -1076,12 +1056,10 @@ Win32VolumeAccess::BlockAccess::WriteBlocksInt21h(HANDLE handle, int driveNum,
return kDIErrNone;
}
/*
* Read blocks from a Win2K logical or physical volume.
*/
/*static*/ DIError
Win32VolumeAccess::BlockAccess::ReadBlocksWin2K(HANDLE handle,
/*static*/ DIError Win32VolumeAccess::BlockAccess::ReadBlocksWin2K(HANDLE handle,
long startBlock, short blockCount, void* buf)
{
/*
@ -1122,12 +1100,10 @@ Win32VolumeAccess::BlockAccess::ReadBlocksWin2K(HANDLE handle,
return kDIErrNone;
}
/*
* Write blocks to a Win2K logical or physical volume.
*/
/*static*/ DIError
Win32VolumeAccess::BlockAccess::WriteBlocksWin2K(HANDLE handle,
/*static*/ DIError Win32VolumeAccess::BlockAccess::WriteBlocksWin2K(HANDLE handle,
long startBlock, short blockCount, const void* buf)
{
DWORD posn, actual;
@ -1165,8 +1141,8 @@ Win32VolumeAccess::BlockAccess::WriteBlocksWin2K(HANDLE handle,
/*
* Open a logical device. The device name should be of the form "A:\".
*/
DIError
Win32VolumeAccess::LogicalBlockAccess::Open(const WCHAR* deviceName, bool readOnly)
DIError Win32VolumeAccess::LogicalBlockAccess::Open(const WCHAR* deviceName,
bool readOnly)
{
DIError dierr = kDIErrNone;
const bool kPreferASPI = true;
@ -1307,8 +1283,7 @@ bail:
/*
* Close the device handle.
*/
DIError
Win32VolumeAccess::LogicalBlockAccess::Close(void)
DIError Win32VolumeAccess::LogicalBlockAccess::Close(void)
{
if (fHandle != NULL) {
::CloseHandle(fHandle);
@ -1317,12 +1292,10 @@ Win32VolumeAccess::LogicalBlockAccess::Close(void)
return kDIErrNone;
}
/*
* Read 512-byte blocks from CD-ROM media using SPTI calls.
*/
DIError
Win32VolumeAccess::LogicalBlockAccess::ReadBlocksCDROM(HANDLE handle,
DIError Win32VolumeAccess::LogicalBlockAccess::ReadBlocksCDROM(HANDLE handle,
long startBlock, short blockCount, void* buf)
{
#ifdef HAVE_WINDOWS_CDROM
@ -1337,7 +1310,7 @@ Win32VolumeAccess::LogicalBlockAccess::ReadBlocksCDROM(HANDLE handle,
/* alloc sector buffer on first use */
if (fLastSectorCache == NULL) {
fLastSectorCache = new unsigned char[kCDROMSectorSize];
fLastSectorCache = new uint8_t[kCDROMSectorSize];
if (fLastSectorCache == NULL)
return kDIErrMalloc;
assert(fLastSectorNum == -1);
@ -1384,7 +1357,7 @@ Win32VolumeAccess::LogicalBlockAccess::ReadBlocksCDROM(HANDLE handle,
thisNumBlocks * kBlockSize);
blockCount -= thisNumBlocks;
buf = (unsigned char*) buf + (thisNumBlocks * kBlockSize);
buf = (uint8_t*) buf + (thisNumBlocks * kBlockSize);
sectorOffset = 0;
sectorIndex++;
@ -1402,7 +1375,7 @@ Win32VolumeAccess::LogicalBlockAccess::ReadBlocksCDROM(HANDLE handle,
return dierr;
blockCount -= numSectors * kFactor;
buf = (unsigned char*) buf + (numSectors * kCDROMSectorSize);
buf = (uint8_t*) buf + (numSectors * kCDROMSectorSize);
sectorIndex += numSectors;
}
@ -1425,8 +1398,8 @@ Win32VolumeAccess::LogicalBlockAccess::ReadBlocksCDROM(HANDLE handle,
/*
* Open a physical device. The device name should be of the form "80:\".
*/
DIError
Win32VolumeAccess::PhysicalBlockAccess::Open(const WCHAR* deviceName, bool readOnly)
DIError Win32VolumeAccess::PhysicalBlockAccess::Open(const WCHAR* deviceName,
bool readOnly)
{
DIError dierr = kDIErrNone;
@ -1537,8 +1510,7 @@ bail:
*
* Sets "fFloppyKind" and "fGeometry".
*/
DIError
Win32VolumeAccess::PhysicalBlockAccess::DetectFloppyGeometry(void)
DIError Win32VolumeAccess::PhysicalBlockAccess::DetectFloppyGeometry(void)
{
DIError dierr = kDIErrNone;
static const struct {
@ -1552,7 +1524,7 @@ Win32VolumeAccess::PhysicalBlockAccess::DetectFloppyGeometry(void)
{ kFloppy35_1440, { 80, 2, 18, 1440*2 } },
{ kFloppy35_2880, { 80, 2, 36, 2880*2 } }
};
unsigned char buf[kBlockSize];
uint8_t buf[kBlockSize];
FloppyKind driveKind;
int status;
@ -1631,8 +1603,7 @@ bail:
/*
* Flush the system disk cache.
*/
DIError
Win32VolumeAccess::PhysicalBlockAccess::FlushBlockDevice(void)
DIError Win32VolumeAccess::PhysicalBlockAccess::FlushBlockDevice(void)
{
DIError dierr = kDIErrNone;
@ -1649,8 +1620,7 @@ Win32VolumeAccess::PhysicalBlockAccess::FlushBlockDevice(void)
/*
* Close the device handle.
*/
DIError
Win32VolumeAccess::PhysicalBlockAccess::Close(void)
DIError Win32VolumeAccess::PhysicalBlockAccess::Close(void)
{
if (fHandle != NULL) {
::CloseHandle(fHandle);
@ -1671,8 +1641,8 @@ Win32VolumeAccess::PhysicalBlockAccess::Close(void)
* Unpack device name and verify that the device is a CD-ROM drive or
* direct-access storage device.
*/
DIError
Win32VolumeAccess::ASPIBlockAccess::Open(const char* deviceName, bool readOnly)
DIError Win32VolumeAccess::ASPIBlockAccess::Open(const char* deviceName,
bool readOnly)
{
DIError dierr = kDIErrNone;
@ -1708,7 +1678,7 @@ Win32VolumeAccess::ASPIBlockAccess::Open(const char* deviceName, bool readOnly)
fTarget = target;
fLun = lun;
unsigned char deviceType;
uint8_t deviceType;
dierr = fpASPI->GetDeviceType(fAdapter, fTarget, fLun, &deviceType);
if (dierr != kDIErrNone ||
(deviceType != kScsiDevTypeCDROM && deviceType != kScsiDevTypeDASD))
@ -1738,8 +1708,7 @@ bail:
*
* Returns 0 on success, -1 on failure.
*/
int
Win32VolumeAccess::ASPIBlockAccess::ExtractInt(const char** pStr, int* pResult)
int Win32VolumeAccess::ASPIBlockAccess::ExtractInt(const char** pStr, int* pResult)
{
char* end = NULL;
@ -1763,8 +1732,7 @@ Win32VolumeAccess::ASPIBlockAccess::ExtractInt(const char** pStr, int* pResult)
*
* Sets fChunkSize as a side-effect.
*/
DIError
Win32VolumeAccess::ASPIBlockAccess::DetectCapacity(long* pNumBlocks)
DIError Win32VolumeAccess::ASPIBlockAccess::DetectCapacity(long* pNumBlocks)
{
DIError dierr = kDIErrNone;
unsigned long lba, blockLen;
@ -1801,9 +1769,8 @@ bail:
* SCSI doesn't promise it'll be in a chunk size we like, but it's pretty
* safe to assume that it'll be at least 512 bytes, and divisible by 512.
*/
DIError
Win32VolumeAccess::ASPIBlockAccess::ReadBlocks(long startBlock, short blockCount,
void* buf)
DIError Win32VolumeAccess::ASPIBlockAccess::ReadBlocks(long startBlock,
short blockCount, void* buf)
{
DIError dierr;
@ -1813,7 +1780,7 @@ Win32VolumeAccess::ASPIBlockAccess::ReadBlocks(long startBlock, short blockCount
/* alloc chunk buffer on first use */
if (fLastChunkCache == NULL) {
fLastChunkCache = new unsigned char[fChunkSize];
fLastChunkCache = new uint8_t[fChunkSize];
if (fLastChunkCache == NULL)
return kDIErrMalloc;
assert(fLastChunkNum == -1);
@ -1859,7 +1826,7 @@ Win32VolumeAccess::ASPIBlockAccess::ReadBlocks(long startBlock, short blockCount
thisNumBlocks * kBlockSize);
blockCount -= thisNumBlocks;
buf = (unsigned char*) buf + (thisNumBlocks * kBlockSize);
buf = (uint8_t*) buf + (thisNumBlocks * kBlockSize);
chunkOffset = 0;
chunkIndex++;
@ -1877,7 +1844,7 @@ Win32VolumeAccess::ASPIBlockAccess::ReadBlocks(long startBlock, short blockCount
return dierr;
blockCount -= numChunks * kFactor;
buf = (unsigned char*) buf + (numChunks * fChunkSize);
buf = (uint8_t*) buf + (numChunks * fChunkSize);
chunkIndex += numChunks;
}
@ -1892,9 +1859,8 @@ Win32VolumeAccess::ASPIBlockAccess::ReadBlocks(long startBlock, short blockCount
* SCSI doesn't promise it'll be in a chunk size we like, but it's pretty
* safe to assume that it'll be at least 512 bytes, and divisible by 512.
*/
DIError
Win32VolumeAccess::ASPIBlockAccess::WriteBlocks(long startBlock, short blockCount,
const void* buf)
DIError Win32VolumeAccess::ASPIBlockAccess::WriteBlocks(long startBlock,
short blockCount, const void* buf)
{
DIError dierr;
@ -1942,7 +1908,7 @@ Win32VolumeAccess::ASPIBlockAccess::WriteBlocks(long startBlock, short blockCoun
thisNumBlocks * kBlockSize);
blockCount -= thisNumBlocks;
buf = (const unsigned char*) buf + (thisNumBlocks * kBlockSize);
buf = (const uint8_t*) buf + (thisNumBlocks * kBlockSize);
chunkOffset = 0;
chunkIndex++;
@ -1958,7 +1924,7 @@ Win32VolumeAccess::ASPIBlockAccess::WriteBlocks(long startBlock, short blockCoun
return dierr;
blockCount -= numChunks * kFactor;
buf = (const unsigned char*) buf + (numChunks * fChunkSize);
buf = (const uint8_t*) buf + (numChunks * fChunkSize);
chunkIndex += numChunks;
}
@ -1988,8 +1954,7 @@ Win32VolumeAccess::ASPIBlockAccess::Close(void)
/*
* Determine whether we're holding a block in the cache.
*/
bool
CBCache::IsBlockInCache(long blockNum) const
bool CBCache::IsBlockInCache(long blockNum) const
{
if (fFirstBlock == kEmpty)
return false;
@ -2004,8 +1969,7 @@ CBCache::IsBlockInCache(long blockNum) const
/*
* Retrieve a single block from the cache.
*/
DIError
CBCache::GetFromCache(long blockNum, void* buf)
DIError CBCache::GetFromCache(long blockNum, void* buf)
{
if (!IsBlockInCache(blockNum)) {
assert(false);
@ -2025,8 +1989,7 @@ CBCache::GetFromCache(long blockNum, void* buf)
* criteria: (1) there must actually be room at the end, and (2) the
* block in question must be the next consecutive block.
*/
bool
CBCache::IsRoomInCache(long blockNum) const
bool CBCache::IsRoomInCache(long blockNum) const
{
if (fFirstBlock == kEmpty)
return true;
@ -2055,8 +2018,7 @@ CBCache::IsRoomInCache(long blockNum) const
* they're trying to overwrite dirty cached data with the result of a new
* read, which is a bug. Trap it here.
*/
DIError
CBCache::PutInCache(long blockNum, const void* buf, bool isDirty)
DIError CBCache::PutInCache(long blockNum, const void* buf, bool isDirty)
{
int blockOffset = -1;
if (!IsRoomInCache(blockNum)) {
@ -2101,8 +2063,7 @@ CBCache::PutInCache(long blockNum, const void* buf, bool isDirty)
/*
* Determine whether there are any dirty blocks in the cache.
*/
bool
CBCache::IsDirty(void) const
bool CBCache::IsDirty(void) const
{
if (fFirstBlock == kEmpty)
return false;
@ -2123,8 +2084,7 @@ CBCache::IsDirty(void) const
* Return a pointer to the cache goodies, so that the object sitting
* on the disk hardware can write our stuff.
*/
void
CBCache::GetCachePointer(long* pFirstBlock, int* pNumBlocks, void** pBuf) const
void CBCache::GetCachePointer(long* pFirstBlock, int* pNumBlocks, void** pBuf) const
{
assert(fFirstBlock != kEmpty); // not essential, but why call here if not?
@ -2136,8 +2096,7 @@ CBCache::GetCachePointer(long* pFirstBlock, int* pNumBlocks, void** pBuf) const
/*
* Clear all the dirty flags.
*/
void
CBCache::Scrub(void)
void CBCache::Scrub(void)
{
if (fFirstBlock == kEmpty)
return;
@ -2149,15 +2108,14 @@ CBCache::Scrub(void)
/*
* Trash all of our entries. If any are dirty, scream bloody murder.
*/
void
CBCache::Purge(void)
void CBCache::Purge(void)
{
if (fFirstBlock == kEmpty)
return;
if (IsDirty()) {
// Should only happen after a write failure causes us to clean up.
LOGI("HEY: CBCache purging dirty blocks!");
LOGE("HEY: CBCache purging dirty blocks!");
//assert(false);
}
Scrub();
@ -2166,5 +2124,4 @@ CBCache::Purge(void)
fNumBlocks = 0;
}
#endif /*_WIN32*/

View File

@ -45,13 +45,13 @@
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>false</LinkIncremental>
<TargetName>diskimg4</TargetName>
<TargetName>diskimg5</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<IntDir>$(Configuration)\</IntDir>
<LinkIncremental>true</LinkIncremental>
<TargetName>diskimg4</TargetName>
<TargetName>diskimg5</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>

View File

@ -599,7 +599,8 @@ MainWindow::ScanDiskImage(const WCHAR* pathName, ScanOpts* pScanOpts)
ext.Delete(0, 1);
}
dierr = diskImg.OpenImage(pathName, '\\', true);
CStringA pathNameA(pathName);
dierr = diskImg.OpenImage(pathNameA, '\\', true);
if (dierr != kDIErrNone) {
errMsg.Format(L"Unable to open '%ls': %hs", pathName,
DiskImgLib::DIStrError(dierr));