mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Move common data structures for MFS, HFS and ISO9660 (Apple Extensions) to common class.
This commit is contained in:
@@ -35,6 +35,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DiscImageChef.CommonTypes.Structs;
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Helpers;
|
||||
|
||||
namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
@@ -44,9 +45,12 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
public Errno ReadDir(string path, out List<string> contents)
|
||||
{
|
||||
contents = null;
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
|
||||
if(!string.IsNullOrEmpty(path) && string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0)
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
if(!string.IsNullOrEmpty(path) &&
|
||||
string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0)
|
||||
return Errno.NotSupported;
|
||||
|
||||
contents = idToFilename.Select(kvp => kvp.Value).ToList();
|
||||
@@ -56,10 +60,13 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
contents.Add("$");
|
||||
contents.Add("$Bitmap");
|
||||
contents.Add("$MDB");
|
||||
if(bootBlocks != null) contents.Add("$Boot");
|
||||
|
||||
if(bootBlocks != null)
|
||||
contents.Add("$Boot");
|
||||
}
|
||||
|
||||
contents.Sort();
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -70,17 +77,22 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
filenameToId = new Dictionary<string, uint>();
|
||||
|
||||
int offset = 0;
|
||||
|
||||
while(offset + 51 < directoryBlocks.Length)
|
||||
{
|
||||
MFS_FileEntry entry = new MFS_FileEntry
|
||||
var entry = new MFS_FileEntry
|
||||
{
|
||||
flUsrWds = new byte[16], flFlags = (MFS_FileFlags)directoryBlocks[offset + 0]
|
||||
flFlags = (MFS_FileFlags)directoryBlocks[offset + 0]
|
||||
};
|
||||
|
||||
if(!entry.flFlags.HasFlag(MFS_FileFlags.Used)) break;
|
||||
if(!entry.flFlags.HasFlag(MFS_FileFlags.Used))
|
||||
break;
|
||||
|
||||
entry.flTyp = directoryBlocks[offset + 1];
|
||||
Array.Copy(directoryBlocks, offset + 2, entry.flUsrWds, 0, 16);
|
||||
|
||||
entry.flUsrWds =
|
||||
Marshal.ByteArrayToStructureBigEndian<AppleCommon.FInfo>(directoryBlocks, offset + 2, 16);
|
||||
|
||||
entry.flFlNum = BigEndianBitConverter.ToUInt32(directoryBlocks, offset + 18);
|
||||
entry.flStBlk = BigEndianBitConverter.ToUInt16(directoryBlocks, offset + 22);
|
||||
entry.flLgLen = BigEndianBitConverter.ToUInt32(directoryBlocks, offset + 24);
|
||||
@@ -92,31 +104,39 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
entry.flMdDat = BigEndianBitConverter.ToUInt32(directoryBlocks, offset + 46);
|
||||
entry.flNam = new byte[directoryBlocks[offset + 50] + 1];
|
||||
Array.Copy(directoryBlocks, offset + 50, entry.flNam, 0, entry.flNam.Length);
|
||||
string lowerFilename = StringHandlers
|
||||
.PascalToString(entry.flNam, Encoding).ToLowerInvariant().Replace('/', ':');
|
||||
|
||||
if(entry.flFlags.HasFlag(MFS_FileFlags.Used) && !idToFilename.ContainsKey(entry.flFlNum) &&
|
||||
!idToEntry.ContainsKey(entry.flFlNum) && !filenameToId.ContainsKey(lowerFilename) &&
|
||||
string lowerFilename = StringHandlers.
|
||||
PascalToString(entry.flNam, Encoding).ToLowerInvariant().Replace('/', ':');
|
||||
|
||||
if(entry.flFlags.HasFlag(MFS_FileFlags.Used) &&
|
||||
!idToFilename.ContainsKey(entry.flFlNum) &&
|
||||
!idToEntry.ContainsKey(entry.flFlNum) &&
|
||||
!filenameToId.ContainsKey(lowerFilename) &&
|
||||
entry.flFlNum > 0)
|
||||
{
|
||||
idToEntry.Add(entry.flFlNum, entry);
|
||||
|
||||
idToFilename.Add(entry.flFlNum,
|
||||
StringHandlers.PascalToString(entry.flNam, Encoding).Replace('/', ':'));
|
||||
|
||||
filenameToId.Add(lowerFilename, entry.flFlNum);
|
||||
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flFlags = {0}", entry.flFlags);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flTyp = {0}", entry.flTyp);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flFlNum = {0}", entry.flFlNum);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flStBlk = {0}", entry.flStBlk);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flLgLen = {0}", entry.flLgLen);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flPyLen = {0}", entry.flPyLen);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flFlags = {0}", entry.flFlags);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flTyp = {0}", entry.flTyp);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flFlNum = {0}", entry.flFlNum);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flStBlk = {0}", entry.flStBlk);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flLgLen = {0}", entry.flLgLen);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flPyLen = {0}", entry.flPyLen);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRStBlk = {0}", entry.flRStBlk);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRLgLen = {0}", entry.flRLgLen);
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRPyLen = {0}", entry.flRPyLen);
|
||||
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flCrDat = {0}",
|
||||
DateHandlers.MacToDateTime(entry.flCrDat));
|
||||
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flMdDat = {0}",
|
||||
DateHandlers.MacToDateTime(entry.flMdDat));
|
||||
|
||||
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flNam0 = {0}",
|
||||
StringHandlers.PascalToString(entry.flNam, Encoding));
|
||||
}
|
||||
@@ -124,7 +144,8 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
offset += 50 + entry.flNam.Length;
|
||||
|
||||
// "Entries are always an integral number of words"
|
||||
if(offset % 2 != 0) offset++;
|
||||
if(offset % 2 != 0)
|
||||
offset++;
|
||||
|
||||
// TODO: "Entries don't cross logical block boundaries"
|
||||
}
|
||||
|
||||
@@ -46,18 +46,27 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
deviceBlock = new long();
|
||||
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
if(pathElements.Length != 1) return Errno.NotSupported;
|
||||
string[] pathElements = path.Split(new[]
|
||||
{
|
||||
'/'
|
||||
}, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(pathElements.Length != 1)
|
||||
return Errno.NotSupported;
|
||||
|
||||
path = pathElements[0];
|
||||
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId)) return Errno.NoSuchFile;
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry)) return Errno.NoSuchFile;
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
if(fileBlock > entry.flPyLen / volMDB.drAlBlkSiz) return Errno.InvalidArgument;
|
||||
if(fileBlock > entry.flPyLen / volMDB.drAlBlkSiz)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
uint nextBlock = entry.flStBlk;
|
||||
long relBlock = 0;
|
||||
@@ -66,11 +75,14 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
if(relBlock == fileBlock)
|
||||
{
|
||||
deviceBlock = (nextBlock - 2) * sectorsPerBlock + volMDB.drAlBlSt + (long)partitionStart;
|
||||
deviceBlock = ((nextBlock - 2) * sectorsPerBlock) + volMDB.drAlBlSt + (long)partitionStart;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(blockMap[nextBlock] == BMAP_FREE || blockMap[nextBlock] == BMAP_LAST) break;
|
||||
if(blockMap[nextBlock] == BMAP_FREE ||
|
||||
blockMap[nextBlock] == BMAP_LAST)
|
||||
break;
|
||||
|
||||
nextBlock = blockMap[nextBlock];
|
||||
relBlock++;
|
||||
@@ -82,32 +94,60 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
public Errno GetAttributes(string path, out FileAttributes attributes)
|
||||
{
|
||||
attributes = new FileAttributes();
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
if(pathElements.Length != 1) return Errno.NotSupported;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[]
|
||||
{
|
||||
'/'
|
||||
}, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(pathElements.Length != 1)
|
||||
return Errno.NotSupported;
|
||||
|
||||
path = pathElements[0];
|
||||
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId)) return Errno.NoSuchFile;
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry)) return Errno.NoSuchFile;
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
MFS_FinderFlags fdFlags = (MFS_FinderFlags)BigEndianBitConverter.ToUInt16(entry.flUsrWds, 0x08);
|
||||
if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsAlias))
|
||||
attributes |= FileAttributes.Alias;
|
||||
|
||||
if(fdFlags.HasFlag(MFS_FinderFlags.kIsAlias)) attributes |= FileAttributes.Alias;
|
||||
if(fdFlags.HasFlag(MFS_FinderFlags.kHasBundle)) attributes |= FileAttributes.Bundle;
|
||||
if(fdFlags.HasFlag(MFS_FinderFlags.kHasBeenInited)) attributes |= FileAttributes.HasBeenInited;
|
||||
if(fdFlags.HasFlag(MFS_FinderFlags.kHasCustomIcon)) attributes |= FileAttributes.HasCustomIcon;
|
||||
if(fdFlags.HasFlag(MFS_FinderFlags.kHasNoINITs)) attributes |= FileAttributes.HasNoINITs;
|
||||
if(fdFlags.HasFlag(MFS_FinderFlags.kIsInvisible)) attributes |= FileAttributes.Hidden;
|
||||
if(entry.flFlags.HasFlag(MFS_FileFlags.Locked)) attributes |= FileAttributes.Immutable;
|
||||
if(fdFlags.HasFlag(MFS_FinderFlags.kIsOnDesk)) attributes |= FileAttributes.IsOnDesk;
|
||||
if(fdFlags.HasFlag(MFS_FinderFlags.kIsShared)) attributes |= FileAttributes.Shared;
|
||||
if(fdFlags.HasFlag(MFS_FinderFlags.kIsStationery)) attributes |= FileAttributes.Stationery;
|
||||
if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasBundle))
|
||||
attributes |= FileAttributes.Bundle;
|
||||
|
||||
if(!attributes.HasFlag(FileAttributes.Alias) && !attributes.HasFlag(FileAttributes.Bundle) &&
|
||||
!attributes.HasFlag(FileAttributes.Stationery)) attributes |= FileAttributes.File;
|
||||
if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasBeenInited))
|
||||
attributes |= FileAttributes.HasBeenInited;
|
||||
|
||||
if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasCustomIcon))
|
||||
attributes |= FileAttributes.HasCustomIcon;
|
||||
|
||||
if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasNoINITs))
|
||||
attributes |= FileAttributes.HasNoINITs;
|
||||
|
||||
if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsInvisible))
|
||||
attributes |= FileAttributes.Hidden;
|
||||
|
||||
if(entry.flFlags.HasFlag(MFS_FileFlags.Locked))
|
||||
attributes |= FileAttributes.Immutable;
|
||||
|
||||
if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsOnDesk))
|
||||
attributes |= FileAttributes.IsOnDesk;
|
||||
|
||||
if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsShared))
|
||||
attributes |= FileAttributes.Shared;
|
||||
|
||||
if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsStationery))
|
||||
attributes |= FileAttributes.Stationery;
|
||||
|
||||
if(!attributes.HasFlag(FileAttributes.Alias) &&
|
||||
!attributes.HasFlag(FileAttributes.Bundle) &&
|
||||
!attributes.HasFlag(FileAttributes.Stationery))
|
||||
attributes |= FileAttributes.File;
|
||||
|
||||
attributes |= FileAttributes.BlockUnits;
|
||||
|
||||
@@ -116,33 +156,40 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
|
||||
public Errno Read(string path, long offset, long size, ref byte[] buf)
|
||||
{
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
byte[] file;
|
||||
Errno error = Errno.NoError;
|
||||
|
||||
if(debug && string.Compare(path, "$", StringComparison.InvariantCulture) == 0) file = directoryBlocks;
|
||||
else if(debug && string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 &&
|
||||
bootBlocks != null)
|
||||
if(debug && string.Compare(path, "$", StringComparison.InvariantCulture) == 0)
|
||||
file = directoryBlocks;
|
||||
else if(debug &&
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 &&
|
||||
bootBlocks != null)
|
||||
file = bootBlocks;
|
||||
else if(debug && string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0)
|
||||
file = blockMapBytes;
|
||||
else if(debug && string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0) file = mdbBlocks;
|
||||
file = blockMapBytes;
|
||||
else if(debug && string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
|
||||
file = mdbBlocks;
|
||||
else
|
||||
error =
|
||||
ReadFile(path, out file, false, false);
|
||||
error = ReadFile(path, out file, false, false);
|
||||
|
||||
if(error != Errno.NoError) return error;
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
if(size == 0)
|
||||
{
|
||||
buf = new byte[0];
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(offset >= file.Length) return Errno.InvalidArgument;
|
||||
if(offset >= file.Length)
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
if(size + offset >= file.Length) size = file.Length - offset;
|
||||
if(size + offset >= file.Length)
|
||||
size = file.Length - offset;
|
||||
|
||||
buf = new byte[size];
|
||||
|
||||
@@ -154,18 +201,25 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
public Errno Stat(string path, out FileEntryInfo stat)
|
||||
{
|
||||
stat = null;
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
if(pathElements.Length != 1) return Errno.NotSupported;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[]
|
||||
{
|
||||
'/'
|
||||
}, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(pathElements.Length != 1)
|
||||
return Errno.NotSupported;
|
||||
|
||||
path = pathElements[0];
|
||||
|
||||
if(debug)
|
||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
|
||||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
stat = new FileEntryInfo
|
||||
{
|
||||
@@ -174,46 +228,50 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
|
||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
stat.Blocks = directoryBlocks.Length / stat.BlockSize + directoryBlocks.Length % stat.BlockSize;
|
||||
stat.Blocks = (directoryBlocks.Length / stat.BlockSize) +
|
||||
(directoryBlocks.Length % stat.BlockSize);
|
||||
|
||||
stat.Length = directoryBlocks.Length;
|
||||
}
|
||||
else if(string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
stat.Blocks = blockMapBytes.Length / stat.BlockSize + blockMapBytes.Length % stat.BlockSize;
|
||||
stat.Blocks = (blockMapBytes.Length / stat.BlockSize) + (blockMapBytes.Length % stat.BlockSize);
|
||||
stat.Length = blockMapBytes.Length;
|
||||
}
|
||||
else if(string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 && bootBlocks != null)
|
||||
else if(string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 &&
|
||||
bootBlocks != null)
|
||||
{
|
||||
stat.Blocks = bootBlocks.Length / stat.BlockSize + bootBlocks.Length % stat.BlockSize;
|
||||
stat.Blocks = (bootBlocks.Length / stat.BlockSize) + (bootBlocks.Length % stat.BlockSize);
|
||||
stat.Length = bootBlocks.Length;
|
||||
}
|
||||
else if(string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
stat.Blocks = mdbBlocks.Length / stat.BlockSize + mdbBlocks.Length % stat.BlockSize;
|
||||
stat.Blocks = (mdbBlocks.Length / stat.BlockSize) + (mdbBlocks.Length % stat.BlockSize);
|
||||
stat.Length = mdbBlocks.Length;
|
||||
}
|
||||
else return Errno.InvalidArgument;
|
||||
else
|
||||
return Errno.InvalidArgument;
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId)) return Errno.NoSuchFile;
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry)) return Errno.NoSuchFile;
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
Errno error = GetAttributes(path, out FileAttributes attr);
|
||||
if(error != Errno.NoError) return error;
|
||||
|
||||
if(error != Errno.NoError)
|
||||
return error;
|
||||
|
||||
stat = new FileEntryInfo
|
||||
{
|
||||
Attributes = attr,
|
||||
Blocks = entry.flLgLen / volMDB.drAlBlkSiz,
|
||||
Attributes = attr, Blocks = entry.flLgLen / volMDB.drAlBlkSiz,
|
||||
BlockSize = volMDB.drAlBlkSiz,
|
||||
CreationTime = DateHandlers.MacToDateTime(entry.flCrDat),
|
||||
Inode = entry.flFlNum,
|
||||
LastWriteTime = DateHandlers.MacToDateTime(entry.flMdDat),
|
||||
Length = entry.flPyLen,
|
||||
Links = 1
|
||||
CreationTime = DateHandlers.MacToDateTime(entry.flCrDat), Inode = entry.flFlNum,
|
||||
LastWriteTime = DateHandlers.MacToDateTime(entry.flMdDat), Length = entry.flPyLen, Links = 1
|
||||
};
|
||||
|
||||
return Errno.NoError;
|
||||
@@ -222,6 +280,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
public Errno ReadLink(string path, out string dest)
|
||||
{
|
||||
dest = null;
|
||||
|
||||
return Errno.NotImplemented;
|
||||
}
|
||||
|
||||
@@ -229,16 +288,24 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
buf = null;
|
||||
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
if(pathElements.Length != 1) return Errno.NotSupported;
|
||||
string[] pathElements = path.Split(new[]
|
||||
{
|
||||
'/'
|
||||
}, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(pathElements.Length != 1)
|
||||
return Errno.NotSupported;
|
||||
|
||||
path = pathElements[0];
|
||||
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId)) return Errno.NoSuchFile;
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry)) return Errno.NoSuchFile;
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
uint nextBlock;
|
||||
|
||||
@@ -247,6 +314,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
if(entry.flRPyLen == 0)
|
||||
{
|
||||
buf = new byte[0];
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -257,17 +325,19 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
if(entry.flPyLen == 0)
|
||||
{
|
||||
buf = new byte[0];
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
nextBlock = entry.flStBlk;
|
||||
}
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
var ms = new MemoryStream();
|
||||
|
||||
do
|
||||
{
|
||||
byte[] sectors;
|
||||
|
||||
if(tags)
|
||||
sectors =
|
||||
device.ReadSectorsTag((ulong)((nextBlock - 2) * sectorsPerBlock) + volMDB.drAlBlSt + partitionStart,
|
||||
@@ -282,18 +352,20 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
if(blockMap[nextBlock] == BMAP_FREE)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("File truncated at block {0}", nextBlock);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
nextBlock = blockMap[nextBlock];
|
||||
}
|
||||
while(nextBlock > BMAP_LAST);
|
||||
} while(nextBlock > BMAP_LAST);
|
||||
|
||||
if(tags) buf = ms.ToArray();
|
||||
if(tags)
|
||||
buf = ms.ToArray();
|
||||
else
|
||||
{
|
||||
if(resourceFork)
|
||||
if(ms.Length < entry.flRLgLen) buf = ms.ToArray();
|
||||
if(ms.Length < entry.flRLgLen)
|
||||
buf = ms.ToArray();
|
||||
else
|
||||
{
|
||||
buf = new byte[entry.flRLgLen];
|
||||
@@ -301,7 +373,8 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
}
|
||||
else
|
||||
{
|
||||
if(ms.Length < entry.flLgLen) buf = ms.ToArray();
|
||||
if(ms.Length < entry.flLgLen)
|
||||
buf = ms.ToArray();
|
||||
else
|
||||
{
|
||||
buf = new byte[entry.flLgLen];
|
||||
|
||||
@@ -82,31 +82,6 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
Locked = 0x01, Used = 0x80
|
||||
}
|
||||
|
||||
[Flags]
|
||||
enum MFS_FinderFlags : ushort
|
||||
{
|
||||
kIsOnDesk = 0x0001, kColor = 0x000E, kRequireSwitchLaunch = 0x0020,
|
||||
kIsShared = 0x0040, kHasNoINITs = 0x0080, kHasBeenInited = 0x0100,
|
||||
kHasCustomIcon = 0x0400, kLetter = 0x0200, kChanged = 0x0200,
|
||||
kIsStationery = 0x0800, kNameLocked = 0x1000, kHasBundle = 0x2000,
|
||||
kIsInvisible = 0x4000, kIsAlias = 0x8000
|
||||
}
|
||||
|
||||
struct MFS_Point
|
||||
{
|
||||
public short x;
|
||||
public short y;
|
||||
}
|
||||
|
||||
struct MFS_FinderInfo
|
||||
{
|
||||
public uint fdType;
|
||||
public uint fdCreator;
|
||||
public MFS_FinderFlags fdFlags;
|
||||
public MFS_Point fdLocation;
|
||||
public short fdFldr;
|
||||
}
|
||||
|
||||
struct MFS_FileEntry
|
||||
{
|
||||
/// <summary>0x00, Entry flags</summary>
|
||||
@@ -114,7 +89,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
/// <summary>0x01, Version number</summary>
|
||||
public byte flTyp;
|
||||
/// <summary>0x02, FinderInfo</summary>
|
||||
public byte[] flUsrWds;
|
||||
public AppleCommon.FInfo flUsrWds;
|
||||
/// <summary>0x12, file ID</summary>
|
||||
public uint flFlNum;
|
||||
/// <summary>0x16, first allocation block of data fork</summary>
|
||||
|
||||
@@ -35,6 +35,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using DiscImageChef.CommonTypes.Enums;
|
||||
using DiscImageChef.CommonTypes.Structs;
|
||||
using DiscImageChef.Helpers;
|
||||
|
||||
namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
@@ -44,20 +45,27 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
public Errno ListXAttr(string path, out List<string> xattrs)
|
||||
{
|
||||
xattrs = null;
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
if(pathElements.Length != 1) return Errno.NotSupported;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[]
|
||||
{
|
||||
'/'
|
||||
}, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(pathElements.Length != 1)
|
||||
return Errno.NotSupported;
|
||||
|
||||
path = pathElements[0];
|
||||
|
||||
xattrs = new List<string>();
|
||||
|
||||
if(debug)
|
||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
if(device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag))
|
||||
xattrs.Add("com.apple.macintosh.tags");
|
||||
@@ -65,20 +73,25 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId)) return Errno.NoSuchFile;
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry)) return Errno.NoSuchFile;
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
if(entry.flRLgLen > 0)
|
||||
{
|
||||
xattrs.Add("com.apple.ResourceFork");
|
||||
|
||||
if(debug && device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag))
|
||||
xattrs.Add("com.apple.ResourceFork.tags");
|
||||
}
|
||||
|
||||
if(!ArrayHelpers.ArrayIsNullOrEmpty(entry.flUsrWds)) xattrs.Add("com.apple.FinderInfo");
|
||||
xattrs.Add("com.apple.FinderInfo");
|
||||
|
||||
if(debug && device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) && entry.flLgLen > 0)
|
||||
if(debug &&
|
||||
device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) &&
|
||||
entry.flLgLen > 0)
|
||||
xattrs.Add("com.apple.macintosh.tags");
|
||||
|
||||
xattrs.Sort();
|
||||
@@ -88,18 +101,24 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
|
||||
public Errno GetXattr(string path, string xattr, ref byte[] buf)
|
||||
{
|
||||
if(!mounted) return Errno.AccessDenied;
|
||||
if(!mounted)
|
||||
return Errno.AccessDenied;
|
||||
|
||||
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
if(pathElements.Length != 1) return Errno.NotSupported;
|
||||
string[] pathElements = path.Split(new[]
|
||||
{
|
||||
'/'
|
||||
}, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(pathElements.Length != 1)
|
||||
return Errno.NotSupported;
|
||||
|
||||
path = pathElements[0];
|
||||
|
||||
if(debug)
|
||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
|
||||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
|
||||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
|
||||
if(device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) &&
|
||||
string.Compare(xattr, "com.apple.macintosh.tags", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
@@ -107,6 +126,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
buf = new byte[directoryTags.Length];
|
||||
Array.Copy(directoryTags, 0, buf, 0, buf.Length);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -114,6 +134,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
buf = new byte[bitmapTags.Length];
|
||||
Array.Copy(bitmapTags, 0, buf, 0, buf.Length);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -121,6 +142,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
buf = new byte[bootTags.Length];
|
||||
Array.Copy(bootTags, 0, buf, 0, buf.Length);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
@@ -128,6 +150,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
{
|
||||
buf = new byte[mdbTags.Length];
|
||||
Array.Copy(mdbTags, 0, buf, 0, buf.Length);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
}
|
||||
@@ -136,14 +159,17 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
|
||||
Errno error;
|
||||
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId)) return Errno.NoSuchFile;
|
||||
if(!filenameToId.TryGetValue(path.ToLowerInvariant(), out uint fileId))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry)) return Errno.NoSuchFile;
|
||||
if(!idToEntry.TryGetValue(fileId, out MFS_FileEntry entry))
|
||||
return Errno.NoSuchFile;
|
||||
|
||||
if(entry.flRLgLen > 0 &&
|
||||
string.Compare(xattr, "com.apple.ResourceFork", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
error = ReadFile(path, out buf, true, false);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -151,22 +177,24 @@ namespace DiscImageChef.Filesystems.AppleMFS
|
||||
string.Compare(xattr, "com.apple.ResourceFork.tags", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
error = ReadFile(path, out buf, true, true);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
if(!ArrayHelpers.ArrayIsNullOrEmpty(entry.flUsrWds) &&
|
||||
string.Compare(xattr, "com.apple.FinderInfo", StringComparison.InvariantCulture) == 0)
|
||||
if(string.Compare(xattr, "com.apple.FinderInfo", StringComparison.InvariantCulture) == 0)
|
||||
{
|
||||
buf = new byte[16];
|
||||
Array.Copy(entry.flUsrWds, 0, buf, 0, 16);
|
||||
buf = Marshal.StructureToByteArrayBigEndian(entry.flUsrWds);
|
||||
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
if(!debug || !device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) ||
|
||||
if(!debug ||
|
||||
!device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) ||
|
||||
string.Compare(xattr, "com.apple.macintosh.tags", StringComparison.InvariantCulture) != 0)
|
||||
return Errno.NoSuchExtendedAttribute;
|
||||
|
||||
error = ReadFile(path, out buf, false, true);
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user