mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
* LICENSE.LGPL: Added LICENSE files for LGPL and MIT licenses. * DiscImageChef.Devices/Enums.cs: * DiscImageChef.Partitions/MBR.cs: * DiscImageChef.Partitions/RDB.cs: * DiscImageChef.DiscImages/GDI.cs: * DiscImageChef.Partitions/Sun.cs: * DiscImageChef.DiscImages/VHD.cs: * DiscImageChef.Partitions/GPT.cs: * DiscImageChef.Filesystems/FFS.cs: * DiscImageChef.Filesystems/FAT.cs: * DiscImageChef.Partitions/NeXT.cs: * DiscImageChef.Devices/Command.cs: * DiscImageChef.DiscImages/Nero.cs: * DiscImageChef.Decoders/CD/PMA.cs: * DiscImageChef.Decoders/CD/TOC.cs: * DiscImageChef.Filesystems/BFS.cs: * DiscImageChef.Filesystems/ODS.cs: * DiscImageChef.Helpers/PrintHex.cs: * DiscImageChef.Helpers/Swapping.cs: * DiscImageChef.Decoders/DVD/PRI.cs: * DiscImageChef.Decoders/DVD/DMI.cs: * DiscImageChef.Decoders/DVD/DDS.cs: * DiscImageChef.Decoders/DVD/RMD.cs: * DiscImageChef.Decoders/DVD/UDI.cs: * DiscImageChef.Partitions/Atari.cs: * DiscImageChef.Decoders/DVD/BCA.cs: * DiscImageChef.Filesystems/SysV.cs: * DiscImageChef.Filesystems/HPFS.cs: * DiscImageChef.Filesystems/NTFS.cs: * DiscImageChef.Filesystems/APFS.cs: * DiscImageChef.Decoders/DVD/PFI.cs: * DiscImageChef.Decoders/CD/ATIP.cs: * DiscImageChef.Filesystems/Acorn.cs: * DiscImageChef.DiscImages/CDRWin.cs: * DiscImageChef.DiscImages/CDRDAO.cs: * DiscImageChef.Filesystems/BTRFS.cs: * DiscImageChef.Decoders/Xbox/DMI.cs: * DiscImageChef.Helpers/ArrayFill.cs: * DiscImageChef.Settings/Settings.cs: * DiscImageChef.Filesystems/Opera.cs: * DiscImageChef.Filesystems/extFS.cs: * DiscImageChef.Decoders/DVD/CPRM.cs: * DiscImageChef.Decoders/DVD/ADIP.cs: * DiscImageChef.Decoders/CD/Enums.cs: * DiscImageChef.Decoders/DVD/AACS.cs: * DiscImageChef.Decoders/SCSI/EVPD.cs: * DiscImageChef.Filesystems/ProDOS.cs: * DiscImageChef.Metadata/MediaType.cs: * DiscImageChef.Console/DicConsole.cs: * DiscImageChef.Decoders/DVD/Spare.cs: * DiscImageChef.Filesystems/ext2FS.cs: * DiscImageChef.Decoders/DVD/Enums.cs: * DiscImageChef.Filesystems/Symbian.cs: * DiscImageChef.Decoders/SCSI/Types.cs: * DiscImageChef.Filesystems/UNIXBFS.cs: * DiscImageChef.DiscImages/TeleDisk.cs: * DiscImageChef.Decoders/SCSI/Sense.cs: * DiscImageChef.Decoders/CD/FullTOC.cs: * DiscImageChef.Decoders/Blu-ray/DI.cs: * DiscImageChef.Decoders/ATA/Errors.cs: * DiscImageChef.Filesystems/ISO9660.cs: * DiscImageChef.Filesystems/MinixFS.cs: * DiscImageChef.Devices/Linux/Enums.cs: * DiscImageChef.Filesystems/SolarFS.cs: * DiscImageChef.Filesystems/Structs.cs: * DiscImageChef.DiscImages/Apple2MG.cs: * DiscImageChef.Decoders/SCSI/Modes.cs: * DiscImageChef.Metadata/Dimensions.cs: * DiscImageChef.Partitions/AppleMap.cs: * DiscImageChef.Decoders/Floppy/ISO.cs: * DiscImageChef.Decoders/DVD/Layers.cs: * DiscImageChef.Decoders/CD/Session.cs: * DiscImageChef.Decoders/SCSI/Enums.cs: * DiscImageChef.Filesystems/Nintendo.cs: * DiscImageChef.Helpers/DateHandlers.cs: * DiscImageChef.Filesystems/AmigaDOS.cs: * DiscImageChef.DiscImages/ImageInfo.cs: * DiscImageChef.Checksums/MD5Context.cs: * DiscImageChef.Devices/Linux/Extern.cs: * DiscImageChef.Filesystems/AppleHFS.cs: * DiscImageChef.Filesystems/AppleMFS.cs: * DiscImageChef.Helpers/ArrayIsEmpty.cs: * DiscImageChef.Decoders/Blu-ray/BCA.cs: * DiscImageChef.Decoders/Blu-ray/DDS.cs: * DiscImageChef.Filesystems/PCEngine.cs: * DiscImageChef.Decoders/ATA/Identify.cs: * DiscImageChef.Devices/Linux/Command.cs: * DiscImageChef.Devices/FreeBSD/Enums.cs: * DiscImageChef.Decoders/SCSI/Inquiry.cs: * DiscImageChef.Metadata/DeviceReport.cs: * DiscImageChef.Decoders/Floppy/Amiga.cs: * DiscImageChef.Devices/Linux/Structs.cs: * DiscImageChef.Devices/Windows/Enums.cs: * DiscImageChef.Decoders/DVD/CSS&CPRM.cs: * DiscImageChef.Checksums/SHA1Context.cs: * DiscImageChef.DiscImages/DiskCopy42.cs: * DiscImageChef.Partitions/PartPlugin.cs: * DiscImageChef.CommonTypes/Partition.cs: * DiscImageChef.Decoders/Floppy/Enums.cs: * DiscImageChef.CommonTypes/MediaType.cs: * DiscImageChef.Decoders/Floppy/Apple2.cs: * DiscImageChef.Devices/Windows/Extern.cs: * DiscImageChef.Decoders/SCSI/MMC/CPRM.cs: * DiscImageChef.Helpers/StringHandlers.cs: * DiscImageChef.DiscImages/ImagePlugin.cs: * DiscImageChef.Checksums/CRC64Context.cs: * DiscImageChef.Checksums/CRC32Context.cs: * DiscImageChef.DiscImages/ZZZRawImage.cs: * DiscImageChef.Checksums/CRC16Context.cs: * DiscImageChef.Filesystems/LisaFS/Dir.cs: * DiscImageChef.Decoders/DVD/Cartridge.cs: * DiscImageChef.Decoders/Blu-ray/Spare.cs: * DiscImageChef.Filesystems/Filesystem.cs: * DiscImageChef.Decoders/SCSI/MMC/AACS.cs: * DiscImageChef.Devices/FreeBSD/Extern.cs: * DiscImageChef.Devices/Device/Commands.cs: * DiscImageChef.Checksums/SHA384Context.cs: * DiscImageChef.Devices/FreeBSD/Command.cs: * DiscImageChef.Checksums/SHA512Context.cs: * DiscImageChef.Decoders/SCSI/MMC/Enums.cs: * DiscImageChef.Devices/Windows/Command.cs: * DiscImageChef.Devices/FreeBSD/Structs.cs: * DiscImageChef.Devices/Windows/Structs.cs: * DiscImageChef.Filesystems/LisaFS/Info.cs: * DiscImageChef.Checksums/SHA256Context.cs: * DiscImageChef.Filesystems/LisaFS/File.cs: * DiscImageChef.Filesystems/AppleHFSPlus.cs: * DiscImageChef.Filesystems/LisaFS/Super.cs: * DiscImageChef.Filesystems/LisaFS/Xattr.cs: * DiscImageChef.Checksums/Adler32Context.cs: * DiscImageChef.Decoders/Floppy/System34.cs: * DiscImageChef.Checksums/SpamSumContext.cs: * DiscImageChef.Decoders/SCSI/MMC/Hybrid.cs: * DiscImageChef.Devices/Device/Variables.cs: * DiscImageChef.Filesystems/LisaFS/Consts.cs: * DiscImageChef.Filesystems/LisaFS/LisaFS.cs: * DiscImageChef.Decoders/Floppy/Commodore.cs: * DiscImageChef.Checksums/FletcherContext.cs: * DiscImageChef.Filesystems/LisaFS/Extent.cs: * DiscImageChef.Devices/Device/Destructor.cs: * DiscImageChef.Decoders/Floppy/AppleSony.cs: * DiscImageChef.Filesystems/LisaFS/Structs.cs: * DiscImageChef.Decoders/SCSI/VendorString.cs: * DiscImageChef.Decoders/SCSI/MMC/Features.cs: * DiscImageChef.Devices/Device/Constructor.cs: * DiscImageChef.Checksums/RIPEMD160Context.cs: * DiscImageChef.Decoders/CD/CDTextOnLeadIn.cs: * DiscImageChef.Decoders/Blu-ray/Cartridge.cs: * DiscImageChef.Decoders/Floppy/System3740.cs: * DiscImageChef.Filesystems/LisaFS/Encoding.cs: * DiscImageChef.Decoders/SCSI/ModesEncoders.cs: * DiscImageChef.CommonTypes/MediaTypeFromSCSI.cs: * DiscImageChef.Helpers/BigEndianBitConverter.cs: * DiscImageChef.Decoders/Floppy/Perpendicular.cs: * DiscImageChef.Decoders/SCSI/SSC/BlockLimits.cs: * DiscImageChef.Decoders/SCSI/MMC/WriteProtect.cs: * DiscImageChef.Devices/Device/ScsiCommands/HP.cs: * DiscImageChef.Devices/Device/AtaCommands/Cfa.cs: * DiscImageChef.Devices/Device/ScsiCommands/NEC.cs: * DiscImageChef.Helpers/EndianAwareBinaryReader.cs: * DiscImageChef.Devices/Device/ScsiCommands/MMC.cs: * DiscImageChef.Devices/Device/AtaCommands/MCPT.cs: * DiscImageChef.Devices/Device/ScsiCommands/SSC.cs: * DiscImageChef.Devices/Device/ScsiCommands/SPC.cs: * DiscImageChef.Devices/Device/ScsiCommands/SMC.cs: * DiscImageChef.Devices/Device/ScsiCommands/SBC.cs: * DiscImageChef.Metadata/Properties/AssemblyInfo.cs: * DiscImageChef.Devices/Device/AtaCommands/Atapi.cs: * DiscImageChef.Devices/Device/AtaCommands/Ata28.cs: * DiscImageChef.Devices/Device/AtaCommands/Smart.cs: * DiscImageChef.Decoders/SCSI/SSC/DensitySupport.cs: * DiscImageChef.Devices/Device/AtaCommands/Ata48.cs: * DiscImageChef.Decoders/SCSI/MMC/DiscInformation.cs: * DiscImageChef.Devices/Device/AtaCommands/AtaCHS.cs: * DiscImageChef.Devices/Device/ScsiCommands/SyQuest.cs: * DiscImageChef.Devices/Device/ScsiCommands/Plextor.cs: * DiscImageChef.Devices/Device/ScsiCommands/Plasmon.cs: * DiscImageChef.Devices/Device/ScsiCommands/Pioneer.cs: * DiscImageChef.Devices/Device/ScsiCommands/Adaptec.cs: * DiscImageChef.Devices/Device/ScsiCommands/Fujitsu.cs: * DiscImageChef.Devices/Device/ScsiCommands/HL-DT-ST.cs: * DiscImageChef.Devices/Device/ScsiCommands/Certance.cs: * DiscImageChef.Decoders/SCSI/DiscStructureCapabilities.cs: * DiscImageChef.Devices/Device/ScsiCommands/ArchiveCorp.cs: Relicensed as LGPL. Updated standard header. * DiscImageChef/Main.cs: * DiscImageChef/Plugins.cs: * DiscImageChef/Options.cs: * DiscImageChef/Commands/Ls.cs: * DiscImageChef/Core/IBGLog.cs: * DiscImageChef/Core/MHDDLog.cs: * DiscImageChef/AssemblyInfo.cs: * DiscImageChef/Core/Checksum.cs: * DiscImageChef/Commands/Decode.cs: * DiscImageChef/Core/Statistics.cs: * DiscImageChef/Commands/Verify.cs: * DiscImageChef/Commands/Formats.cs: * DiscImageChef/Commands/Entropy.cs: * DiscImageChef/Commands/Compare.cs: * DiscImageChef.Interop/DetectOS.cs: * DiscImageChef/Commands/Analyze.cs: * DiscImageChef/Commands/Commands.cs: * DiscImageChef/Commands/PrintHex.cs: * DiscImageChef/Commands/Checksum.cs: * DiscImageChef/DetectImageFormat.cs: * DiscImageChef/Commands/DumpMedia.cs: * DiscImageChef/Commands/Benchmark.cs: * DiscImageChef/Commands/Configure.cs: * DiscImageChef/Commands/MediaInfo.cs: * DiscImageChef.Interop/PlatformID.cs: * DiscImageChef/Commands/MediaScan.cs: * DiscImageChef/Commands/Statistics.cs: * DiscImageChef/Commands/DeviceInfo.cs: * DiscImageChef.Checksums/ReedSolomon.cs: * DiscImageChef/Commands/DeviceReport.cs: * DiscImageChef/Commands/ExtractFiles.cs: * DiscImageChef.Checksums/CDChecksums.cs: * DiscImageChef/Commands/CreateSidecar.cs: Updated standard header. * DiscImageChef.Checksums/DiscImageChef.Checksums.csproj: Relicensed project as LGPL. Updated standard header. Embed license as resource. * DiscImageChef.Console/DiscImageChef.Console.csproj: * DiscImageChef.Devices/DiscImageChef.Devices.csproj: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: * DiscImageChef.Settings/DiscImageChef.Settings.csproj: * DiscImageChef.Decoders/DiscImageChef.Decoders.csproj: * DiscImageChef.Metadata/DiscImageChef.Metadata.csproj: * DiscImageChef.Partitions/DiscImageChef.Partitions.csproj: * DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj: * DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj: * DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj: Relicensed as LGPL. Updated standard header. Embed license as resource. * DiscImageChef/DiscImageChef.csproj: * DiscImageChef.Interop/DiscImageChef.Interop.csproj: Updated standard header. Embed license as resource.
533 lines
18 KiB
C#
533 lines
18 KiB
C#
// /***************************************************************************
|
|
// The Disc Image Chef
|
|
// ----------------------------------------------------------------------------
|
|
//
|
|
// Filename : File.cs
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
//
|
|
// Component : Apple Lisa filesystem plugin.
|
|
//
|
|
// --[ Description ] ----------------------------------------------------------
|
|
//
|
|
// Methods to handle files.
|
|
//
|
|
// --[ License ] --------------------------------------------------------------
|
|
//
|
|
// This library is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// This library is distributed in the hope that it will be useful, but
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
//
|
|
// ----------------------------------------------------------------------------
|
|
// Copyright © 2011-2016 Natalia Portillo
|
|
// ****************************************************************************/
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using DiscImageChef.ImagePlugins;
|
|
using System.Runtime.InteropServices;
|
|
using System.Collections.Generic;
|
|
using DiscImageChef.Console;
|
|
using System.IO;
|
|
|
|
namespace DiscImageChef.Filesystems.LisaFS
|
|
{
|
|
partial class LisaFS : Filesystem
|
|
{
|
|
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
|
{
|
|
Int16 fileId;
|
|
Errno error = LookupFileId(path, out fileId);
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
return GetAttributes(fileId, ref attributes);
|
|
}
|
|
|
|
public override Errno Read(string path, long offset, long size, ref byte[] buf)
|
|
{
|
|
if(size == 0)
|
|
{
|
|
buf = new byte[0];
|
|
return Errno.NoError;
|
|
}
|
|
|
|
if(offset < 0)
|
|
return Errno.InvalidArgument;
|
|
|
|
Int16 fileId;
|
|
bool isDir;
|
|
Errno error = LookupFileId(path, out fileId, out isDir);
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
byte[] tmp;
|
|
if(debug)
|
|
{
|
|
switch(fileId)
|
|
{
|
|
case FILEID_BOOT_SIGNED:
|
|
case FILEID_LOADER_SIGNED:
|
|
case (short)FILEID_MDDF:
|
|
case (short)FILEID_BITMAP:
|
|
case (short)FILEID_SRECORD:
|
|
case (short)FILEID_DIRECTORY:
|
|
error = ReadSystemFile(fileId, out tmp);
|
|
break;
|
|
default:
|
|
error = ReadFile(fileId, out tmp);
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
error = ReadFile(fileId, out tmp);
|
|
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
if(offset >= tmp.Length)
|
|
return Errno.EINVAL;
|
|
|
|
if(size + offset >= tmp.Length)
|
|
size = tmp.Length - offset;
|
|
|
|
buf = new byte[size];
|
|
Array.Copy(tmp, offset, buf, 0, size);
|
|
return Errno.NoError;
|
|
}
|
|
|
|
public override Errno Stat(string path, ref FileEntryInfo stat)
|
|
{
|
|
Int16 fileId;
|
|
Errno error = LookupFileId(path, out fileId);
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
return Stat(fileId, out stat);
|
|
}
|
|
|
|
Errno GetAttributes(Int16 fileId, ref FileAttributes attributes)
|
|
{
|
|
if(!mounted)
|
|
return Errno.AccessDenied;
|
|
|
|
if(fileId <= 4)
|
|
{
|
|
if(!debug || fileId == 0)
|
|
return Errno.NoSuchFile;
|
|
else
|
|
{
|
|
attributes = new FileAttributes();
|
|
attributes = FileAttributes.System;
|
|
attributes |= FileAttributes.Hidden;
|
|
|
|
if(fileId == 4)
|
|
attributes |= FileAttributes.Directory;
|
|
else
|
|
attributes |= FileAttributes.File;
|
|
|
|
return Errno.NoError;
|
|
}
|
|
}
|
|
|
|
ExtentFile extFile;
|
|
Errno error = ReadExtentsFile(fileId, out extFile);
|
|
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
attributes = new FileAttributes();
|
|
|
|
switch(extFile.ftype)
|
|
{
|
|
case FileType.Spool:
|
|
attributes |= FileAttributes.CharDevice;
|
|
break;
|
|
case FileType.UserCat:
|
|
case FileType.RootCat:
|
|
attributes |= FileAttributes.Directory;
|
|
break;
|
|
case FileType.Pipe:
|
|
attributes |= FileAttributes.Pipe;
|
|
break;
|
|
case FileType.Undefined:
|
|
break;
|
|
default:
|
|
attributes |= FileAttributes.File;
|
|
// Subcatalogs use extents?
|
|
attributes |= FileAttributes.Extents;
|
|
break;
|
|
}
|
|
|
|
if(extFile.protect > 0)
|
|
attributes |= FileAttributes.Immutable;
|
|
if(extFile.locked > 0)
|
|
attributes |= FileAttributes.ReadOnly;
|
|
if(extFile.password_valid > 0)
|
|
attributes |= FileAttributes.Password;
|
|
|
|
return Errno.NoError;
|
|
}
|
|
|
|
Errno ReadSystemFile(Int16 fileId, out byte[] buf)
|
|
{
|
|
return ReadSystemFile(fileId, out buf, false);
|
|
}
|
|
|
|
Errno ReadSystemFile(Int16 fileId, out byte[] buf, bool tags)
|
|
{
|
|
buf = null;
|
|
if(!mounted || !debug)
|
|
return Errno.AccessDenied;
|
|
|
|
if(fileId > 4 || fileId <= 0)
|
|
{
|
|
if(fileId != FILEID_BOOT_SIGNED && fileId != FILEID_LOADER_SIGNED)
|
|
return Errno.InvalidArgument;
|
|
}
|
|
|
|
if(systemFileCache.TryGetValue(fileId, out buf) && !tags)
|
|
return Errno.NoError;
|
|
|
|
int count = 0;
|
|
|
|
if(fileId == FILEID_SRECORD)
|
|
{
|
|
if(!tags)
|
|
{
|
|
buf = device.ReadSectors(mddf.mddf_block + volumePrefix + mddf.srec_ptr, mddf.srec_len);
|
|
systemFileCache.Add(fileId, buf);
|
|
return Errno.NoError;
|
|
}
|
|
else
|
|
{
|
|
buf = device.ReadSectorsTag(mddf.mddf_block + volumePrefix + mddf.srec_ptr, mddf.srec_len, SectorTagType.AppleSectorTag);
|
|
return Errno.NoError;
|
|
}
|
|
}
|
|
|
|
Tag sysTag;
|
|
|
|
// Should be enough to check 100 sectors?
|
|
for(ulong i = 0; i < 100; i++)
|
|
{
|
|
DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out sysTag);
|
|
|
|
if(sysTag.fileID == fileId)
|
|
count++;
|
|
}
|
|
|
|
if(count == 0)
|
|
return Errno.NoSuchFile;
|
|
|
|
if(!tags)
|
|
buf = new byte[count * device.GetSectorSize()];
|
|
else
|
|
buf = new byte[count * devTagSize];
|
|
|
|
// Should be enough to check 100 sectors?
|
|
for(ulong i = 0; i < 100; i++)
|
|
{
|
|
DecodeTag(device.ReadSectorTag(i, SectorTagType.AppleSectorTag), out sysTag);
|
|
|
|
if(sysTag.fileID == fileId)
|
|
{
|
|
byte[] sector;
|
|
|
|
if(!tags)
|
|
sector = device.ReadSector(i);
|
|
else
|
|
sector = device.ReadSectorTag(i, SectorTagType.AppleSectorTag);
|
|
|
|
// Relative block for $Loader starts at $Boot block
|
|
if(sysTag.fileID == FILEID_LOADER_SIGNED)
|
|
sysTag.relBlock--;
|
|
|
|
Array.Copy(sector, 0, buf, sector.Length * sysTag.relBlock, sector.Length);
|
|
}
|
|
}
|
|
|
|
if(!tags)
|
|
systemFileCache.Add(fileId, buf);
|
|
|
|
return Errno.NoError;
|
|
}
|
|
|
|
Errno Stat(Int16 fileId, out FileEntryInfo stat)
|
|
{
|
|
stat = null;
|
|
|
|
if(!mounted)
|
|
return Errno.AccessDenied;
|
|
|
|
Errno error;
|
|
ExtentFile file;
|
|
|
|
if(fileId <= 4)
|
|
{
|
|
if(!debug || fileId == 0)
|
|
return Errno.NoSuchFile;
|
|
else
|
|
{
|
|
stat = new FileEntryInfo();
|
|
stat.Attributes = new FileAttributes();
|
|
|
|
error = GetAttributes(fileId, ref stat.Attributes);
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
if(fileId < 0 && fileId != FILEID_BOOT_SIGNED && fileId != FILEID_LOADER_SIGNED)
|
|
{
|
|
error = ReadExtentsFile((short)(fileId * -1), out file);
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
stat.CreationTime = DateHandlers.LisaToDateTime(file.dtc);
|
|
stat.AccessTime = DateHandlers.LisaToDateTime(file.dta);
|
|
stat.BackupTime = DateHandlers.LisaToDateTime(file.dtb);
|
|
stat.LastWriteTime = DateHandlers.LisaToDateTime(file.dtm);
|
|
|
|
stat.Inode = (ulong)fileId;
|
|
stat.Mode = 0x124;
|
|
stat.Links = 0;
|
|
stat.UID = 0;
|
|
stat.GID = 0;
|
|
stat.DeviceNo = 0;
|
|
stat.Length = mddf.datasize;
|
|
stat.BlockSize = mddf.datasize;
|
|
stat.Blocks = 1;
|
|
}
|
|
else
|
|
{
|
|
byte[] buf;
|
|
error = ReadSystemFile(fileId, out buf);
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
if(fileId != 4)
|
|
stat.CreationTime = mddf.dtvc;
|
|
else
|
|
stat.CreationTime = mddf.dtcc;
|
|
|
|
stat.BackupTime = mddf.dtvb;
|
|
|
|
stat.Inode = (ulong)fileId;
|
|
stat.Mode = 0x124;
|
|
stat.Links = 0;
|
|
stat.UID = 0;
|
|
stat.GID = 0;
|
|
stat.DeviceNo = 0;
|
|
stat.Length = buf.Length;
|
|
stat.BlockSize = mddf.datasize;
|
|
stat.Blocks = buf.Length / mddf.datasize;
|
|
}
|
|
|
|
return Errno.NoError;
|
|
}
|
|
}
|
|
|
|
stat = new FileEntryInfo();
|
|
stat.Attributes = new FileAttributes();
|
|
error = GetAttributes(fileId, ref stat.Attributes);
|
|
if(error != Errno.NoError)
|
|
{
|
|
//DicConsole.ErrorWriteLine("Error {0} reading attributes for file {1}", error, fileId);
|
|
return error;
|
|
}
|
|
|
|
error = ReadExtentsFile(fileId, out file);
|
|
if(error != Errno.NoError)
|
|
{
|
|
//DicConsole.ErrorWriteLine("Error {0} reading extents for file {1}", error, fileId);
|
|
return error;
|
|
}
|
|
|
|
stat.CreationTime = DateHandlers.LisaToDateTime(file.dtc);
|
|
stat.AccessTime = DateHandlers.LisaToDateTime(file.dta);
|
|
stat.BackupTime = DateHandlers.LisaToDateTime(file.dtb);
|
|
stat.LastWriteTime = DateHandlers.LisaToDateTime(file.dtm);
|
|
|
|
stat.Inode = (ulong)fileId;
|
|
stat.Mode = 0x1B6;
|
|
stat.Links = 1;
|
|
stat.UID = 0;
|
|
stat.GID = 0;
|
|
stat.DeviceNo = 0;
|
|
int len;
|
|
if(!fileSizeCache.TryGetValue(fileId, out len))
|
|
stat.Length = srecords[fileId].filesize;
|
|
else
|
|
stat.Length = len;
|
|
stat.BlockSize = mddf.datasize;
|
|
stat.Blocks = file.length;
|
|
|
|
return Errno.NoError;
|
|
}
|
|
|
|
Errno ReadFile(Int16 fileId, out byte[] buf)
|
|
{
|
|
return ReadFile(fileId, out buf, false);
|
|
}
|
|
|
|
Errno ReadFile(Int16 fileId, out byte[] buf, bool tags)
|
|
{
|
|
buf = null;
|
|
if(!mounted)
|
|
return Errno.AccessDenied;
|
|
|
|
tags &= debug;
|
|
|
|
if(fileId < 4 || (fileId == 4 && (mddf.fsversion != LisaFSv2 && mddf.fsversion != LisaFSv1)))
|
|
return Errno.InvalidArgument;
|
|
|
|
if(!tags && fileCache.TryGetValue(fileId, out buf))
|
|
return Errno.NoError;
|
|
|
|
Errno error;
|
|
ExtentFile file;
|
|
|
|
error = ReadExtentsFile(fileId, out file);
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
int sectorSize;
|
|
if(tags)
|
|
sectorSize = devTagSize;
|
|
else
|
|
sectorSize = (int)device.GetSectorSize();
|
|
|
|
byte[] temp = new byte[file.length * sectorSize];
|
|
|
|
int offset = 0;
|
|
for(int i = 0; i < file.extents.Length; i++)
|
|
{
|
|
byte[] sector;
|
|
|
|
if(!tags)
|
|
sector = device.ReadSectors(((ulong)file.extents[i].start + mddf.mddf_block + volumePrefix), (uint)file.extents[i].length);
|
|
else
|
|
sector = device.ReadSectorsTag(((ulong)file.extents[i].start + mddf.mddf_block + volumePrefix), (uint)file.extents[i].length, SectorTagType.AppleSectorTag);
|
|
|
|
Array.Copy(sector, 0, temp, offset, sector.Length);
|
|
offset += sector.Length;
|
|
}
|
|
|
|
if(!tags)
|
|
{
|
|
int realSize;
|
|
if(fileSizeCache.TryGetValue(fileId, out realSize))
|
|
{
|
|
if(realSize > temp.Length)
|
|
DicConsole.ErrorWriteLine("File {0} gets truncated.", fileId);
|
|
}
|
|
buf = temp;
|
|
|
|
fileCache.Add(fileId, buf);
|
|
}
|
|
else
|
|
buf = temp;
|
|
|
|
return Errno.NoError;
|
|
}
|
|
|
|
Errno LookupFileId(string path, out Int16 fileId)
|
|
{
|
|
bool temp;
|
|
return LookupFileId(path, out fileId, out temp);
|
|
}
|
|
|
|
Errno LookupFileId(string path, out Int16 fileId, out bool isDir)
|
|
{
|
|
fileId = 0;
|
|
isDir = false;
|
|
|
|
if(!mounted)
|
|
return Errno.AccessDenied;
|
|
|
|
string[] pathElements = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if(pathElements.Length == 0)
|
|
{
|
|
fileId = (short)FILEID_DIRECTORY;
|
|
isDir = true;
|
|
return Errno.NoError;
|
|
}
|
|
|
|
// TODO: Subcatalogs
|
|
if(pathElements.Length > 1)
|
|
return Errno.NotImplemented;
|
|
|
|
if(debug)
|
|
{
|
|
if(String.Compare(pathElements[0], "$MDDF", StringComparison.InvariantCulture) == 0)
|
|
{
|
|
fileId = (short)FILEID_MDDF;
|
|
return Errno.NoError;
|
|
}
|
|
|
|
if(String.Compare(pathElements[0], "$Boot", StringComparison.InvariantCulture) == 0)
|
|
{
|
|
fileId = FILEID_BOOT_SIGNED;
|
|
return Errno.NoError;
|
|
}
|
|
|
|
if(String.Compare(pathElements[0], "$Loader", StringComparison.InvariantCulture) == 0)
|
|
{
|
|
fileId = FILEID_LOADER_SIGNED;
|
|
return Errno.NoError;
|
|
}
|
|
|
|
if(String.Compare(pathElements[0], "$Bitmap", StringComparison.InvariantCulture) == 0)
|
|
{
|
|
fileId = (short)FILEID_BITMAP;
|
|
return Errno.NoError;
|
|
}
|
|
|
|
if(String.Compare(pathElements[0], "$S-Record", StringComparison.InvariantCulture) == 0)
|
|
{
|
|
fileId = (short)FILEID_SRECORD;
|
|
return Errno.NoError;
|
|
}
|
|
|
|
if(String.Compare(pathElements[0], "$", StringComparison.InvariantCulture) == 0)
|
|
{
|
|
fileId = (short)FILEID_DIRECTORY;
|
|
isDir = true;
|
|
return Errno.NoError;
|
|
}
|
|
}
|
|
|
|
List<CatalogEntry> catalog;
|
|
|
|
Errno error = ReadCatalog((short)FILEID_DIRECTORY, out catalog);
|
|
if(error != Errno.NoError)
|
|
return error;
|
|
|
|
string wantedFilename = pathElements[0].Replace(':', '/');
|
|
|
|
foreach(CatalogEntry entry in catalog)
|
|
{
|
|
string filename = GetString(entry.filename);
|
|
// Should they be case sensitive?
|
|
if(String.Compare(wantedFilename, filename, StringComparison.InvariantCultureIgnoreCase) == 0)
|
|
{
|
|
fileId = entry.fileID;
|
|
isDir |= entry.fileType != 0x03;
|
|
return Errno.NoError;
|
|
}
|
|
}
|
|
|
|
return Errno.NoSuchFile;
|
|
}
|
|
}
|
|
}
|
|
|