dmolony-DiskBrowser/src/com/bytezone/diskbrowser/dos/DeletedCatalogEntry.java

133 lines
4.0 KiB
Java
Raw Permalink Normal View History

2015-06-01 09:35:51 +00:00
package com.bytezone.diskbrowser.dos;
import com.bytezone.diskbrowser.applefile.DefaultAppleFile;
2019-01-25 21:57:35 +00:00
import com.bytezone.diskbrowser.disk.AppleDiskAddress;
2015-06-01 09:35:51 +00:00
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.gui.DataSource;
2020-02-08 08:28:22 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
class DeletedCatalogEntry extends AbstractCatalogEntry
2020-02-08 08:28:22 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
boolean allSectorsAvailable = true;
boolean debug = false;
2020-02-08 08:28:22 +00:00
// ---------------------------------------------------------------------------------//
DeletedCatalogEntry (DosDisk dosDisk, DiskAddress catalogSector, byte[] entryBuffer,
int dosVersion)
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
super (dosDisk, catalogSector, entryBuffer);
2019-01-25 21:57:35 +00:00
2015-06-01 09:35:51 +00:00
if (debug)
{
System.out.println ("Deleted file : " + name);
System.out.printf ("Reported size : %d%n", reportedSize);
}
2019-01-25 21:57:35 +00:00
DiskAddress da = null;
// Get address of first TS-list sector
if (dosVersion >= 0x41)
{
int track = entryBuffer[0] & 0x3F;
int sector = entryBuffer[1] & 0x1F;
da = disk.getDiskAddress (track, sector);
}
else
{
int track = entryBuffer[32] & 0xFF;
int sector = entryBuffer[1] & 0xFF;
da = disk.getDiskAddress (track, sector);
}
int totalBlocks = 0;
2020-04-10 23:47:52 +00:00
if (reportedSize <= 1 || !disk.isValidAddress (da.getTrackNo (), da.getSectorNo ()))
2015-06-01 09:35:51 +00:00
{
if (debug)
System.out.println ("invalid catalog entry");
allSectorsAvailable = false;
return;
}
// Loop through all TS-list sectors
2020-05-10 11:28:01 +00:00
loop: while (!da.isZero () || ((AppleDiskAddress) da).zeroFlag ())
2015-06-01 09:35:51 +00:00
{
if (!dosDisk.stillAvailable (da))
{
allSectorsAvailable = false;
break;
}
tsSectors.add (da);
totalBlocks++;
2020-12-12 09:53:45 +00:00
DiskAddress sectorDA = da;
2020-04-10 23:47:52 +00:00
byte[] sectorBuffer = disk.readBlock (da);
2015-06-01 09:35:51 +00:00
for (int i = 12, max = disk.getBlockSize (); i < max; i += 2)
{
da = getValidAddress (sectorBuffer, i);
if (da == null)
break loop;
2020-05-10 11:28:01 +00:00
if (!da.isZero () && debug)
2015-06-01 09:35:51 +00:00
System.out.println (da);
2020-05-10 11:28:01 +00:00
if (!da.isZero () || ((AppleDiskAddress) da).zeroFlag ())
2015-06-01 09:35:51 +00:00
{
if (!dosDisk.stillAvailable (da))
{
allSectorsAvailable = false;
break loop;
}
dataSectors.add (da);
totalBlocks++;
}
}
2020-12-12 09:53:45 +00:00
DiskAddress nextDa = getValidAddress (sectorBuffer, 1);
2015-06-01 09:35:51 +00:00
2020-12-12 09:53:45 +00:00
if (nextDa == null)
2015-06-01 09:35:51 +00:00
{
2020-12-12 09:53:45 +00:00
System.out.printf ("Next T/S list in sector %s is invalid : %02X, %02X%n",
sectorDA, sectorBuffer[1], sectorBuffer[2]);
2015-06-01 09:35:51 +00:00
break;
}
2020-12-12 09:53:45 +00:00
da = nextDa;
2015-06-01 09:35:51 +00:00
}
2020-12-12 09:53:45 +00:00
2015-06-01 09:35:51 +00:00
if (debug)
System.out.printf ("Total blocks recoverable : %d%n", totalBlocks);
if (totalBlocks != reportedSize)
allSectorsAvailable = false;
}
2020-02-08 08:28:22 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
@Override
public String getUniqueName ()
2020-02-08 08:28:22 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
// name might not be unique if the file has been deleted
return "!" + name;
}
2020-02-08 08:28:22 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
@Override
public DataSource getDataSource ()
2020-02-08 08:28:22 +00:00
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
if (!allSectorsAvailable && appleFile == null)
{
DefaultAppleFile daf = new DefaultAppleFile (name, null);
daf.setText ("This file cannot be recovered");
appleFile = daf;
}
return super.getDataSource ();
}
2020-02-08 08:28:22 +00:00
// ---------------------------------------------------------------------------------//
String getDetails ()
// ---------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2019-01-25 21:57:35 +00:00
return String.format ("%-30s %s", name,
allSectorsAvailable ? "Recoverable" : "Not recoverable");
2015-06-01 09:35:51 +00:00
}
}