Move common data structures for MFS, HFS and ISO9660 (Apple Extensions) to common class.

This commit is contained in:
2020-02-19 03:37:51 +00:00
parent 177031d7ac
commit 999657502b
14 changed files with 459 additions and 351 deletions

View File

@@ -45,5 +45,42 @@ namespace DiscImageChef.Filesystems
DoesNotNeedCache = 0x400, BootInconsistent = 0x800, ReusedIds = 0x1000, DoesNotNeedCache = 0x400, BootInconsistent = 0x800, ReusedIds = 0x1000,
Journaled = 0x2000, Inconsistent = 0x4000, SoftwareLock = 0x8000 Journaled = 0x2000, Inconsistent = 0x4000, SoftwareLock = 0x8000
} }
[Flags]
internal enum FinderFlags : ushort
{
/// <summary>Is on desktop.</summary>
kIsOnDesk = 0x0001,
/// <summary>Color mask.</summary>
kColor = 0x000E, kRequireSwitchLaunch = 0x0020,
/// <summary>If clear, the application needs to write to its resource fork, and therefore cannot be shared on a server.</summary>
kIsShared = 0x0040,
/// <summary>Extension or control panel with no INIT entries in resource fork.</summary>
kHasNoINITs = 0x0080,
/// <summary>
/// Clear if the file contains desktop database resources ('BNDL', 'FREF', 'open', 'kind'...) that have not been
/// added yet. Set only by the Finder. Reserved for folders - make sure this bit is cleared for folders.
/// </summary>
kHasBeenInited = 0x0100,
/// <summary>PowerTalk</summary>
kAOCE = 0x200, kChanged = 0x0200,
/// <summary>Has a custom icon in the resource fork.</summary>
kHasCustomIcon = 0x0400,
/// <summary>Is a stationery.</summary>
kIsStationery = 0x0800,
/// <summary>Cannot be renamed.</summary>
kNameLocked = 0x1000,
/// <summary>Indicates that a file has a BNDL resource or that a folder is displayed as a package.</summary>
kHasBundle = 0x2000,
/// <summary>Hidden.</summary>
kIsInvisible = 0x4000,
/// <summary>Is an alias</summary>
kIsAlias = 0x8000
}
internal enum FinderFolder : short
{
fTrash = -3, fDesktop = -2, fDisk = 0
}
} }
} }

View File

@@ -88,5 +88,25 @@ namespace DiscImageChef.Filesystems
/// <summary>0x090, Fraction of RAM for system heap</summary> /// <summary>0x090, Fraction of RAM for system heap</summary>
public readonly uint bbSysHeapFract; public readonly uint bbSysHeapFract;
} }
internal struct Point
{
public ushort v;
public ushort h;
}
internal struct FInfo
{
/// <summary>The type of the file.</summary>
public uint fdType;
/// <summary>The file's creator.</summary>
public uint fdCreator;
/// <summary>Flags.</summary>
public FinderFlags fdFlags;
/// <summary>File's location in the folder.</summary>
public Point fdLocation;
/// <summary>Folder file belongs to (used only in flat filesystems like MFS).</summary>
public FinderFolder fdFldr;
}
} }
} }

View File

@@ -34,82 +34,48 @@ using System;
namespace DiscImageChef.Filesystems namespace DiscImageChef.Filesystems
{ {
internal enum NodeType : sbyte public partial class AppleHFS
{ {
/// <summary>Index node</summary> internal enum NodeType : sbyte
ndIndxNode = 0, {
/// <summary>Header node</summary> /// <summary>Index node</summary>
ndHdrNode = 1, ndIndxNode = 0,
/// <summary>Map node</summary> /// <summary>Header node</summary>
ndMapNode = 2, ndHdrNode = 1,
/// <summary>Leaf node</summary> /// <summary>Map node</summary>
ndLeafNode = -1 ndMapNode = 2,
} /// <summary>Leaf node</summary>
ndLeafNode = -1
}
internal enum CatDataType : sbyte internal enum CatDataType : sbyte
{ {
/// <summary>Directory record</summary> /// <summary>Directory record</summary>
cdrDirRec = 1, cdrDirRec = 1,
/// <summary>File record</summary> /// <summary>File record</summary>
cdrFilRec = 2, cdrFilRec = 2,
/// <summary>Directory thread record</summary> /// <summary>Directory thread record</summary>
cdrThdRec = 3, cdrThdRec = 3,
/// <summary>File thread record</summary> /// <summary>File thread record</summary>
cdrFThdRec = 4 cdrFThdRec = 4
} }
internal enum ForkType : sbyte internal enum ForkType : sbyte
{ {
Data = 0, Resource = -1 Data = 0, Resource = -1
} }
[Flags] [Flags]
internal enum FinderFlags : ushort internal enum ExtendedFinderFlags : ushort
{ {
/// <summary>Is on desktop.</summary> /// <summary>If set the other extended flags are ignored.</summary>
kIsOnDesk = 0x0001, kExtendedFlagsAreInvalid = 0x8000,
/// <summary>Color mask.</summary> /// <summary>Set if the file or folder has a badge resource.</summary>
kColor = 0x000E, kRequireSwitchLaunch = 0x0020, kExtendedFlagHasCustomBadge = 0x0100,
/// <summary>If clear, the application needs to write to its resource fork, and therefore cannot be shared on a server.</summary> /// <summary>Set if the object is marked as busy/incomplete.</summary>
kIsShared = 0x0040, kExtendedFlagObjectIsBusy = 0x0080,
/// <summary>Extension or control panel with no INIT entries in resource fork.</summary> /// <summary>Set if the file contains routing info resource.</summary>
kHasNoINITs = 0x0080, kExtendedFlagHasRoutingInfo = 0x0004
/// <summary> }
/// Clear if the file contains desktop database resources ('BNDL', 'FREF', 'open', 'kind'...) that have not been
/// added yet. Set only by the Finder. Reserved for folders - make sure this bit is cleared for folders.
/// </summary>
kHasBeenInited = 0x0100,
/// <summary>PowerTalk</summary>
kAOCE = 0x200,
/// <summary>Has a custom icon in the resource fork.</summary>
kHasCustomIcon = 0x0400,
/// <summary>Is a stationery.</summary>
kIsStationery = 0x0800,
/// <summary>Cannot be renamed.</summary>
kNameLocked = 0x1000,
/// <summary>Indicates that a file has a BNDL resource or that a folder is displayed as a package.</summary>
kHasBundle = 0x2000,
/// <summary>Hidden.</summary>
kIsInvisible = 0x4000,
/// <summary>Is an alias</summary>
kIsAlias = 0x8000
}
[Flags]
internal enum ExtendedFinderFlags : ushort
{
/// <summary>If set the other extended flags are ignored.</summary>
kExtendedFlagsAreInvalid = 0x8000,
/// <summary>Set if the file or folder has a badge resource.</summary>
kExtendedFlagHasCustomBadge = 0x0100,
/// <summary>Set if the object is marked as busy/incomplete.</summary>
kExtendedFlagObjectIsBusy = 0x0080,
/// <summary>Set if the file contains routing info resource.</summary>
kExtendedFlagHasRoutingInfo = 0x0004
}
internal enum FinderFolder : short
{
fTrash = -3, fDesktop = -2, fDisk = 0
} }
} }

View File

@@ -233,7 +233,7 @@ namespace DiscImageChef.Filesystems
/// <summary>File type.</summary> /// <summary>File type.</summary>
public readonly sbyte filType; public readonly sbyte filType;
/// <summary>Finder information.</summary> /// <summary>Finder information.</summary>
public readonly FInfo filUsrWds; public readonly AppleCommon.FInfo filUsrWds;
/// <summary>File ID.</summary> /// <summary>File ID.</summary>
public readonly uint filFlNum; public readonly uint filFlNum;
/// <summary>First allocation block of data fork.</summary> /// <summary>First allocation block of data fork.</summary>
@@ -328,12 +328,6 @@ namespace DiscImageChef.Filesystems
public readonly ushort xkrFABN; public readonly ushort xkrFABN;
} }
struct Point
{
public ushort v;
public ushort h;
}
struct Rect struct Rect
{ {
public ushort top; public ushort top;
@@ -342,20 +336,6 @@ namespace DiscImageChef.Filesystems
public ushort right; public ushort right;
} }
struct FInfo
{
/// <summary>The type of the file.</summary>
public uint fdType;
/// <summary>The file's creator.</summary>
public uint fdCreator;
/// <summary>Flags.</summary>
public FinderFlags fdFlags;
/// <summary>File's location in the folder.</summary>
public Point fdLocation;
/// <summary>Folder file belongs to (used only in flat filesystems like MFS).</summary>
public FinderFolder fdFldr;
}
struct FXInfo struct FXInfo
{ {
/// <summary>Resource fork ID of file icon.</summary> /// <summary>Resource fork ID of file icon.</summary>
@@ -375,9 +355,9 @@ namespace DiscImageChef.Filesystems
/// <summary>Position and dimensions of the folder's window.</summary> /// <summary>Position and dimensions of the folder's window.</summary>
public Rect frRect; public Rect frRect;
/// <summary>Flags.</summary> /// <summary>Flags.</summary>
public FinderFlags frFlags; public AppleCommon.FinderFlags frFlags;
/// <summary>Folder's location in the parent folder.</summary> /// <summary>Folder's location in the parent folder.</summary>
public Point frLocation; public AppleCommon.Point frLocation;
/// <summary>Finder view selected for folder.</summary> /// <summary>Finder view selected for folder.</summary>
public ushort frView; public ushort frView;
} }
@@ -385,7 +365,7 @@ namespace DiscImageChef.Filesystems
struct DXInfo struct DXInfo
{ {
/// <summary>Scroll position for icon views.</summary> /// <summary>Scroll position for icon views.</summary>
public Point frScroll; public AppleCommon.Point frScroll;
/// <summary>Directory ID chain of open folders.</summary> /// <summary>Directory ID chain of open folders.</summary>
public uint frOpenChain; public uint frOpenChain;
/// <summary>Extended flags. If high-bit is set, most significant byte is script code and least significant byte are flags.</summary> /// <summary>Extended flags. If high-bit is set, most significant byte is script code and least significant byte are flags.</summary>

View File

@@ -35,6 +35,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using DiscImageChef.CommonTypes.Structs; using DiscImageChef.CommonTypes.Structs;
using DiscImageChef.Console; using DiscImageChef.Console;
using DiscImageChef.Helpers;
namespace DiscImageChef.Filesystems.AppleMFS namespace DiscImageChef.Filesystems.AppleMFS
{ {
@@ -44,9 +45,12 @@ namespace DiscImageChef.Filesystems.AppleMFS
public Errno ReadDir(string path, out List<string> contents) public Errno ReadDir(string path, out List<string> contents)
{ {
contents = null; 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; return Errno.NotSupported;
contents = idToFilename.Select(kvp => kvp.Value).ToList(); contents = idToFilename.Select(kvp => kvp.Value).ToList();
@@ -56,10 +60,13 @@ namespace DiscImageChef.Filesystems.AppleMFS
contents.Add("$"); contents.Add("$");
contents.Add("$Bitmap"); contents.Add("$Bitmap");
contents.Add("$MDB"); contents.Add("$MDB");
if(bootBlocks != null) contents.Add("$Boot");
if(bootBlocks != null)
contents.Add("$Boot");
} }
contents.Sort(); contents.Sort();
return Errno.NoError; return Errno.NoError;
} }
@@ -70,17 +77,22 @@ namespace DiscImageChef.Filesystems.AppleMFS
filenameToId = new Dictionary<string, uint>(); filenameToId = new Dictionary<string, uint>();
int offset = 0; int offset = 0;
while(offset + 51 < directoryBlocks.Length) 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]; 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.flFlNum = BigEndianBitConverter.ToUInt32(directoryBlocks, offset + 18);
entry.flStBlk = BigEndianBitConverter.ToUInt16(directoryBlocks, offset + 22); entry.flStBlk = BigEndianBitConverter.ToUInt16(directoryBlocks, offset + 22);
entry.flLgLen = BigEndianBitConverter.ToUInt32(directoryBlocks, offset + 24); entry.flLgLen = BigEndianBitConverter.ToUInt32(directoryBlocks, offset + 24);
@@ -92,31 +104,39 @@ namespace DiscImageChef.Filesystems.AppleMFS
entry.flMdDat = BigEndianBitConverter.ToUInt32(directoryBlocks, offset + 46); entry.flMdDat = BigEndianBitConverter.ToUInt32(directoryBlocks, offset + 46);
entry.flNam = new byte[directoryBlocks[offset + 50] + 1]; entry.flNam = new byte[directoryBlocks[offset + 50] + 1];
Array.Copy(directoryBlocks, offset + 50, entry.flNam, 0, entry.flNam.Length); 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) && string lowerFilename = StringHandlers.
!idToEntry.ContainsKey(entry.flFlNum) && !filenameToId.ContainsKey(lowerFilename) && 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) entry.flFlNum > 0)
{ {
idToEntry.Add(entry.flFlNum, entry); idToEntry.Add(entry.flFlNum, entry);
idToFilename.Add(entry.flFlNum, idToFilename.Add(entry.flFlNum,
StringHandlers.PascalToString(entry.flNam, Encoding).Replace('/', ':')); StringHandlers.PascalToString(entry.flNam, Encoding).Replace('/', ':'));
filenameToId.Add(lowerFilename, entry.flFlNum); filenameToId.Add(lowerFilename, entry.flFlNum);
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flFlags = {0}", entry.flFlags); 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.flTyp = {0}", entry.flTyp);
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flFlNum = {0}", entry.flFlNum); 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.flStBlk = {0}", entry.flStBlk);
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flLgLen = {0}", entry.flLgLen); 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.flPyLen = {0}", entry.flPyLen);
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRStBlk = {0}", entry.flRStBlk); 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.flRLgLen = {0}", entry.flRLgLen);
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRPyLen = {0}", entry.flRPyLen); DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flRPyLen = {0}", entry.flRPyLen);
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flCrDat = {0}", DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flCrDat = {0}",
DateHandlers.MacToDateTime(entry.flCrDat)); DateHandlers.MacToDateTime(entry.flCrDat));
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flMdDat = {0}", DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flMdDat = {0}",
DateHandlers.MacToDateTime(entry.flMdDat)); DateHandlers.MacToDateTime(entry.flMdDat));
DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flNam0 = {0}", DicConsole.DebugWriteLine("DEBUG (AppleMFS plugin)", "entry.flNam0 = {0}",
StringHandlers.PascalToString(entry.flNam, Encoding)); StringHandlers.PascalToString(entry.flNam, Encoding));
} }
@@ -124,7 +144,8 @@ namespace DiscImageChef.Filesystems.AppleMFS
offset += 50 + entry.flNam.Length; offset += 50 + entry.flNam.Length;
// "Entries are always an integral number of words" // "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" // TODO: "Entries don't cross logical block boundaries"
} }

View File

@@ -46,18 +46,27 @@ namespace DiscImageChef.Filesystems.AppleMFS
{ {
deviceBlock = new long(); deviceBlock = new long();
if(!mounted) return Errno.AccessDenied; if(!mounted)
return Errno.AccessDenied;
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); string[] pathElements = path.Split(new[]
if(pathElements.Length != 1) return Errno.NotSupported; {
'/'
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
path = pathElements[0]; 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; uint nextBlock = entry.flStBlk;
long relBlock = 0; long relBlock = 0;
@@ -66,11 +75,14 @@ namespace DiscImageChef.Filesystems.AppleMFS
{ {
if(relBlock == fileBlock) if(relBlock == fileBlock)
{ {
deviceBlock = (nextBlock - 2) * sectorsPerBlock + volMDB.drAlBlSt + (long)partitionStart; deviceBlock = ((nextBlock - 2) * sectorsPerBlock) + volMDB.drAlBlSt + (long)partitionStart;
return Errno.NoError; 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]; nextBlock = blockMap[nextBlock];
relBlock++; relBlock++;
@@ -82,32 +94,60 @@ namespace DiscImageChef.Filesystems.AppleMFS
public Errno GetAttributes(string path, out FileAttributes attributes) public Errno GetAttributes(string path, out FileAttributes attributes)
{ {
attributes = new FileAttributes(); attributes = new FileAttributes();
if(!mounted) return Errno.AccessDenied;
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); if(!mounted)
if(pathElements.Length != 1) return Errno.NotSupported; return Errno.AccessDenied;
string[] pathElements = path.Split(new[]
{
'/'
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
path = pathElements[0]; 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(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasBundle))
if(fdFlags.HasFlag(MFS_FinderFlags.kHasBundle)) attributes |= FileAttributes.Bundle; 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(!attributes.HasFlag(FileAttributes.Alias) && !attributes.HasFlag(FileAttributes.Bundle) && if(entry.flUsrWds.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasBeenInited))
!attributes.HasFlag(FileAttributes.Stationery)) attributes |= FileAttributes.File; 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; attributes |= FileAttributes.BlockUnits;
@@ -116,33 +156,40 @@ namespace DiscImageChef.Filesystems.AppleMFS
public Errno Read(string path, long offset, long size, ref byte[] buf) public Errno Read(string path, long offset, long size, ref byte[] buf)
{ {
if(!mounted) return Errno.AccessDenied; if(!mounted)
return Errno.AccessDenied;
byte[] file; byte[] file;
Errno error = Errno.NoError; Errno error = Errno.NoError;
if(debug && string.Compare(path, "$", StringComparison.InvariantCulture) == 0) file = directoryBlocks; if(debug && string.Compare(path, "$", StringComparison.InvariantCulture) == 0)
else if(debug && string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 && file = directoryBlocks;
bootBlocks != null) else if(debug &&
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 &&
bootBlocks != null)
file = bootBlocks; file = bootBlocks;
else if(debug && string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0) else if(debug && string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0)
file = blockMapBytes; file = blockMapBytes;
else if(debug && string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0) file = mdbBlocks; else if(debug && string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
file = mdbBlocks;
else else
error = error = ReadFile(path, out file, false, false);
ReadFile(path, out file, false, false);
if(error != Errno.NoError) return error; if(error != Errno.NoError)
return error;
if(size == 0) if(size == 0)
{ {
buf = new byte[0]; buf = new byte[0];
return Errno.NoError; 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]; buf = new byte[size];
@@ -154,18 +201,25 @@ namespace DiscImageChef.Filesystems.AppleMFS
public Errno Stat(string path, out FileEntryInfo stat) public Errno Stat(string path, out FileEntryInfo stat)
{ {
stat = null; stat = null;
if(!mounted) return Errno.AccessDenied;
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); if(!mounted)
if(pathElements.Length != 1) return Errno.NotSupported; return Errno.AccessDenied;
string[] pathElements = path.Split(new[]
{
'/'
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
path = pathElements[0]; path = pathElements[0];
if(debug) if(debug)
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 || if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 || string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$Bitmap", 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 stat = new FileEntryInfo
{ {
@@ -174,46 +228,50 @@ namespace DiscImageChef.Filesystems.AppleMFS
if(string.Compare(path, "$", StringComparison.InvariantCulture) == 0) 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; stat.Length = directoryBlocks.Length;
} }
else if(string.Compare(path, "$Bitmap", StringComparison.InvariantCulture) == 0) 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; 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; stat.Length = bootBlocks.Length;
} }
else if(string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0) 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; stat.Length = mdbBlocks.Length;
} }
else return Errno.InvalidArgument; else
return Errno.InvalidArgument;
return Errno.NoError; 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); Errno error = GetAttributes(path, out FileAttributes attr);
if(error != Errno.NoError) return error;
if(error != Errno.NoError)
return error;
stat = new FileEntryInfo stat = new FileEntryInfo
{ {
Attributes = attr, Attributes = attr, Blocks = entry.flLgLen / volMDB.drAlBlkSiz,
Blocks = entry.flLgLen / volMDB.drAlBlkSiz,
BlockSize = volMDB.drAlBlkSiz, BlockSize = volMDB.drAlBlkSiz,
CreationTime = DateHandlers.MacToDateTime(entry.flCrDat), CreationTime = DateHandlers.MacToDateTime(entry.flCrDat), Inode = entry.flFlNum,
Inode = entry.flFlNum, LastWriteTime = DateHandlers.MacToDateTime(entry.flMdDat), Length = entry.flPyLen, Links = 1
LastWriteTime = DateHandlers.MacToDateTime(entry.flMdDat),
Length = entry.flPyLen,
Links = 1
}; };
return Errno.NoError; return Errno.NoError;
@@ -222,6 +280,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
public Errno ReadLink(string path, out string dest) public Errno ReadLink(string path, out string dest)
{ {
dest = null; dest = null;
return Errno.NotImplemented; return Errno.NotImplemented;
} }
@@ -229,16 +288,24 @@ namespace DiscImageChef.Filesystems.AppleMFS
{ {
buf = null; buf = null;
if(!mounted) return Errno.AccessDenied; if(!mounted)
return Errno.AccessDenied;
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); string[] pathElements = path.Split(new[]
if(pathElements.Length != 1) return Errno.NotSupported; {
'/'
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
path = pathElements[0]; 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; uint nextBlock;
@@ -247,6 +314,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
if(entry.flRPyLen == 0) if(entry.flRPyLen == 0)
{ {
buf = new byte[0]; buf = new byte[0];
return Errno.NoError; return Errno.NoError;
} }
@@ -257,17 +325,19 @@ namespace DiscImageChef.Filesystems.AppleMFS
if(entry.flPyLen == 0) if(entry.flPyLen == 0)
{ {
buf = new byte[0]; buf = new byte[0];
return Errno.NoError; return Errno.NoError;
} }
nextBlock = entry.flStBlk; nextBlock = entry.flStBlk;
} }
MemoryStream ms = new MemoryStream(); var ms = new MemoryStream();
do do
{ {
byte[] sectors; byte[] sectors;
if(tags) if(tags)
sectors = sectors =
device.ReadSectorsTag((ulong)((nextBlock - 2) * sectorsPerBlock) + volMDB.drAlBlSt + partitionStart, device.ReadSectorsTag((ulong)((nextBlock - 2) * sectorsPerBlock) + volMDB.drAlBlSt + partitionStart,
@@ -282,18 +352,20 @@ namespace DiscImageChef.Filesystems.AppleMFS
if(blockMap[nextBlock] == BMAP_FREE) if(blockMap[nextBlock] == BMAP_FREE)
{ {
DicConsole.ErrorWriteLine("File truncated at block {0}", nextBlock); DicConsole.ErrorWriteLine("File truncated at block {0}", nextBlock);
break; break;
} }
nextBlock = blockMap[nextBlock]; nextBlock = blockMap[nextBlock];
} } while(nextBlock > BMAP_LAST);
while(nextBlock > BMAP_LAST);
if(tags) buf = ms.ToArray(); if(tags)
buf = ms.ToArray();
else else
{ {
if(resourceFork) if(resourceFork)
if(ms.Length < entry.flRLgLen) buf = ms.ToArray(); if(ms.Length < entry.flRLgLen)
buf = ms.ToArray();
else else
{ {
buf = new byte[entry.flRLgLen]; buf = new byte[entry.flRLgLen];
@@ -301,7 +373,8 @@ namespace DiscImageChef.Filesystems.AppleMFS
} }
else else
{ {
if(ms.Length < entry.flLgLen) buf = ms.ToArray(); if(ms.Length < entry.flLgLen)
buf = ms.ToArray();
else else
{ {
buf = new byte[entry.flLgLen]; buf = new byte[entry.flLgLen];

View File

@@ -82,31 +82,6 @@ namespace DiscImageChef.Filesystems.AppleMFS
Locked = 0x01, Used = 0x80 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 struct MFS_FileEntry
{ {
/// <summary>0x00, Entry flags</summary> /// <summary>0x00, Entry flags</summary>
@@ -114,7 +89,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
/// <summary>0x01, Version number</summary> /// <summary>0x01, Version number</summary>
public byte flTyp; public byte flTyp;
/// <summary>0x02, FinderInfo</summary> /// <summary>0x02, FinderInfo</summary>
public byte[] flUsrWds; public AppleCommon.FInfo flUsrWds;
/// <summary>0x12, file ID</summary> /// <summary>0x12, file ID</summary>
public uint flFlNum; public uint flFlNum;
/// <summary>0x16, first allocation block of data fork</summary> /// <summary>0x16, first allocation block of data fork</summary>

View File

@@ -35,6 +35,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using DiscImageChef.CommonTypes.Enums; using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Structs; using DiscImageChef.CommonTypes.Structs;
using DiscImageChef.Helpers;
namespace DiscImageChef.Filesystems.AppleMFS namespace DiscImageChef.Filesystems.AppleMFS
{ {
@@ -44,20 +45,27 @@ namespace DiscImageChef.Filesystems.AppleMFS
public Errno ListXAttr(string path, out List<string> xattrs) public Errno ListXAttr(string path, out List<string> xattrs)
{ {
xattrs = null; xattrs = null;
if(!mounted) return Errno.AccessDenied;
string[] pathElements = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); if(!mounted)
if(pathElements.Length != 1) return Errno.NotSupported; return Errno.AccessDenied;
string[] pathElements = path.Split(new[]
{
'/'
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
path = pathElements[0]; path = pathElements[0];
xattrs = new List<string>(); xattrs = new List<string>();
if(debug) 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, "$Bitmap", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 || string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0) string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
{ {
if(device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag)) if(device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag))
xattrs.Add("com.apple.macintosh.tags"); xattrs.Add("com.apple.macintosh.tags");
@@ -65,20 +73,25 @@ namespace DiscImageChef.Filesystems.AppleMFS
return Errno.NoError; 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) if(entry.flRLgLen > 0)
{ {
xattrs.Add("com.apple.ResourceFork"); xattrs.Add("com.apple.ResourceFork");
if(debug && device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag)) if(debug && device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag))
xattrs.Add("com.apple.ResourceFork.tags"); 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.Add("com.apple.macintosh.tags");
xattrs.Sort(); xattrs.Sort();
@@ -88,18 +101,24 @@ namespace DiscImageChef.Filesystems.AppleMFS
public Errno GetXattr(string path, string xattr, ref byte[] buf) 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); string[] pathElements = path.Split(new[]
if(pathElements.Length != 1) return Errno.NotSupported; {
'/'
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return Errno.NotSupported;
path = pathElements[0]; path = pathElements[0];
if(debug) 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, "$Bitmap", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 || string.Compare(path, "$Boot", StringComparison.InvariantCulture) == 0 ||
string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0) string.Compare(path, "$MDB", StringComparison.InvariantCulture) == 0)
if(device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) && if(device.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag) &&
string.Compare(xattr, "com.apple.macintosh.tags", StringComparison.InvariantCulture) == 0) string.Compare(xattr, "com.apple.macintosh.tags", StringComparison.InvariantCulture) == 0)
{ {
@@ -107,6 +126,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
{ {
buf = new byte[directoryTags.Length]; buf = new byte[directoryTags.Length];
Array.Copy(directoryTags, 0, buf, 0, buf.Length); Array.Copy(directoryTags, 0, buf, 0, buf.Length);
return Errno.NoError; return Errno.NoError;
} }
@@ -114,6 +134,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
{ {
buf = new byte[bitmapTags.Length]; buf = new byte[bitmapTags.Length];
Array.Copy(bitmapTags, 0, buf, 0, buf.Length); Array.Copy(bitmapTags, 0, buf, 0, buf.Length);
return Errno.NoError; return Errno.NoError;
} }
@@ -121,6 +142,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
{ {
buf = new byte[bootTags.Length]; buf = new byte[bootTags.Length];
Array.Copy(bootTags, 0, buf, 0, buf.Length); Array.Copy(bootTags, 0, buf, 0, buf.Length);
return Errno.NoError; return Errno.NoError;
} }
@@ -128,6 +150,7 @@ namespace DiscImageChef.Filesystems.AppleMFS
{ {
buf = new byte[mdbTags.Length]; buf = new byte[mdbTags.Length];
Array.Copy(mdbTags, 0, buf, 0, buf.Length); Array.Copy(mdbTags, 0, buf, 0, buf.Length);
return Errno.NoError; return Errno.NoError;
} }
} }
@@ -136,14 +159,17 @@ namespace DiscImageChef.Filesystems.AppleMFS
Errno error; 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 && if(entry.flRLgLen > 0 &&
string.Compare(xattr, "com.apple.ResourceFork", StringComparison.InvariantCulture) == 0) string.Compare(xattr, "com.apple.ResourceFork", StringComparison.InvariantCulture) == 0)
{ {
error = ReadFile(path, out buf, true, false); error = ReadFile(path, out buf, true, false);
return error; return error;
} }
@@ -151,22 +177,24 @@ namespace DiscImageChef.Filesystems.AppleMFS
string.Compare(xattr, "com.apple.ResourceFork.tags", StringComparison.InvariantCulture) == 0) string.Compare(xattr, "com.apple.ResourceFork.tags", StringComparison.InvariantCulture) == 0)
{ {
error = ReadFile(path, out buf, true, true); error = ReadFile(path, out buf, true, true);
return error; return error;
} }
if(!ArrayHelpers.ArrayIsNullOrEmpty(entry.flUsrWds) && if(string.Compare(xattr, "com.apple.FinderInfo", StringComparison.InvariantCulture) == 0)
string.Compare(xattr, "com.apple.FinderInfo", StringComparison.InvariantCulture) == 0)
{ {
buf = new byte[16]; buf = Marshal.StructureToByteArrayBigEndian(entry.flUsrWds);
Array.Copy(entry.flUsrWds, 0, buf, 0, 16);
return Errno.NoError; 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) string.Compare(xattr, "com.apple.macintosh.tags", StringComparison.InvariantCulture) != 0)
return Errno.NoSuchExtendedAttribute; return Errno.NoSuchExtendedAttribute;
error = ReadFile(path, out buf, false, true); error = ReadFile(path, out buf, false, true);
return error; return error;
} }
} }

View File

@@ -518,8 +518,9 @@ namespace DiscImageChef.Filesystems.ISO9660
{ {
int systemAreaOff = start; int systemAreaOff = start;
hasResourceFork = false; hasResourceFork = false;
bool continueSymlink = false; bool continueSymlink = false;
bool continueSymlinkComponent = false; bool continueSymlinkComponent = false;
AppleCommon.FInfo fInfo;
while(systemAreaOff + 2 <= end) while(systemAreaOff + 2 <= end)
{ {
@@ -563,10 +564,11 @@ namespace DiscImageChef.Filesystems.ISO9660
hasResourceFork = true; hasResourceFork = true;
entry.FinderInfo = new FinderInfo(); fInfo = new AppleCommon.FInfo();
entry.FinderInfo.fdCreator = appleHfsSystemUse.creator; fInfo.fdCreator = appleHfsSystemUse.creator;
entry.FinderInfo.fdFlags = (FinderFlags)appleHfsSystemUse.finder_flags; fInfo.fdFlags = appleHfsSystemUse.finder_flags;
entry.FinderInfo.fdType = appleHfsSystemUse.type; fInfo.fdType = appleHfsSystemUse.type;
entry.FinderInfo = fInfo;
break; break;
} }
@@ -606,9 +608,10 @@ namespace DiscImageChef.Filesystems.ISO9660
hasResourceFork = true; hasResourceFork = true;
entry.FinderInfo = new FinderInfo(); fInfo = new AppleCommon.FInfo();
entry.FinderInfo.fdCreator = appleHfsTypeCreatorSystemUse.creator; fInfo.fdCreator = appleHfsTypeCreatorSystemUse.creator;
entry.FinderInfo.fdType = appleHfsTypeCreatorSystemUse.type; fInfo.fdType = appleHfsTypeCreatorSystemUse.type;
entry.FinderInfo = fInfo;
systemAreaOff += Marshal.SizeOf<AppleHFSTypeCreatorSystemUse>(); systemAreaOff += Marshal.SizeOf<AppleHFSTypeCreatorSystemUse>();
@@ -624,10 +627,11 @@ namespace DiscImageChef.Filesystems.ISO9660
hasResourceFork = true; hasResourceFork = true;
entry.FinderInfo = new FinderInfo(); fInfo = new AppleCommon.FInfo();
entry.FinderInfo.fdCreator = appleHfsIconSystemUse.creator; fInfo.fdCreator = appleHfsIconSystemUse.creator;
entry.FinderInfo.fdType = appleHfsIconSystemUse.type; fInfo.fdType = appleHfsIconSystemUse.type;
entry.AppleIcon = appleHfsIconSystemUse.icon; entry.FinderInfo = fInfo;
entry.AppleIcon = appleHfsIconSystemUse.icon;
systemAreaOff += Marshal.SizeOf<AppleHFSIconSystemUse>(); systemAreaOff += Marshal.SizeOf<AppleHFSIconSystemUse>();
@@ -642,10 +646,11 @@ namespace DiscImageChef.Filesystems.ISO9660
hasResourceFork = true; hasResourceFork = true;
entry.FinderInfo = new FinderInfo(); fInfo = new AppleCommon.FInfo();
entry.FinderInfo.fdCreator = appleHfsSystemUse.creator; fInfo.fdCreator = appleHfsSystemUse.creator;
entry.FinderInfo.fdFlags = (FinderFlags)appleHfsSystemUse.finder_flags; fInfo.fdFlags = (AppleCommon.FinderFlags)appleHfsSystemUse.finder_flags;
entry.FinderInfo.fdType = appleHfsSystemUse.type; fInfo.fdType = appleHfsSystemUse.type;
entry.FinderInfo = fInfo;
systemAreaOff += Marshal.SizeOf<AppleHFSOldSystemUse>(); systemAreaOff += Marshal.SizeOf<AppleHFSOldSystemUse>();

View File

@@ -177,31 +177,33 @@ namespace DiscImageChef.Filesystems.ISO9660
if(entry.FinderInfo != null) if(entry.FinderInfo != null)
{ {
if(entry.FinderInfo.fdFlags.HasFlag(FinderFlags.kIsAlias)) AppleCommon.FInfo finderInfo = entry.FinderInfo.Value;
if(finderInfo.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsAlias))
stat.Attributes |= FileAttributes.Alias; stat.Attributes |= FileAttributes.Alias;
if(entry.FinderInfo.fdFlags.HasFlag(FinderFlags.kIsInvisible)) if(finderInfo.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsInvisible))
stat.Attributes |= FileAttributes.Hidden; stat.Attributes |= FileAttributes.Hidden;
if(entry.FinderInfo.fdFlags.HasFlag(FinderFlags.kHasBeenInited)) if(finderInfo.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasBeenInited))
stat.Attributes |= FileAttributes.HasBeenInited; stat.Attributes |= FileAttributes.HasBeenInited;
if(entry.FinderInfo.fdFlags.HasFlag(FinderFlags.kHasCustomIcon)) if(finderInfo.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasCustomIcon))
stat.Attributes |= FileAttributes.HasCustomIcon; stat.Attributes |= FileAttributes.HasCustomIcon;
if(entry.FinderInfo.fdFlags.HasFlag(FinderFlags.kHasNoINITs)) if(finderInfo.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasNoINITs))
stat.Attributes |= FileAttributes.HasNoINITs; stat.Attributes |= FileAttributes.HasNoINITs;
if(entry.FinderInfo.fdFlags.HasFlag(FinderFlags.kIsOnDesk)) if(finderInfo.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsOnDesk))
stat.Attributes |= FileAttributes.IsOnDesk; stat.Attributes |= FileAttributes.IsOnDesk;
if(entry.FinderInfo.fdFlags.HasFlag(FinderFlags.kIsShared)) if(finderInfo.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsShared))
stat.Attributes |= FileAttributes.Shared; stat.Attributes |= FileAttributes.Shared;
if(entry.FinderInfo.fdFlags.HasFlag(FinderFlags.kIsStationery)) if(finderInfo.fdFlags.HasFlag(AppleCommon.FinderFlags.kIsStationery))
stat.Attributes |= FileAttributes.Stationery; stat.Attributes |= FileAttributes.Stationery;
if(entry.FinderInfo.fdFlags.HasFlag(FinderFlags.kHasBundle)) if(finderInfo.fdFlags.HasFlag(AppleCommon.FinderFlags.kHasBundle))
stat.Attributes |= FileAttributes.Bundle; stat.Attributes |= FileAttributes.Bundle;
} }

View File

@@ -52,12 +52,12 @@ namespace DiscImageChef.Filesystems.ISO9660
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct AppleHFSSystemUse struct AppleHFSSystemUse
{ {
public readonly ushort signature; public readonly ushort signature;
public readonly byte length; public readonly byte length;
public readonly AppleId id; public readonly AppleId id;
public readonly uint type; public readonly uint type;
public readonly uint creator; public readonly uint creator;
public readonly FinderFlags finder_flags; public readonly AppleCommon.FinderFlags finder_flags;
} }
// Little-endian // Little-endian

View File

@@ -69,7 +69,7 @@ namespace DiscImageChef.Filesystems.ISO9660
public List<(uint extent, uint size)> Extents; public List<(uint extent, uint size)> Extents;
public string Filename; public string Filename;
public byte FileUnitSize; public byte FileUnitSize;
public FinderInfo FinderInfo; public AppleCommon.FInfo? FinderInfo;
public FileFlags Flags; public FileFlags Flags;
public byte Interleave; public byte Interleave;
public PosixAttributes? PosixAttributes; public PosixAttributes? PosixAttributes;
@@ -95,40 +95,6 @@ namespace DiscImageChef.Filesystems.ISO9660
public override string ToString() => Filename; public override string ToString() => Filename;
} }
[Flags]
enum 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 Point
{
public short x;
public short y;
}
class FinderInfo
{
public uint fdCreator;
public FinderFlags fdFlags;
public short fdFldr;
public Point fdLocation;
public uint fdType;
}
class PathTableEntryInternal class PathTableEntryInternal
{ {
public uint Extent; public uint Extent;

View File

@@ -34,6 +34,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using DiscImageChef.CommonTypes.Structs; using DiscImageChef.CommonTypes.Structs;
using DiscImageChef.Helpers;
namespace DiscImageChef.Filesystems.ISO9660 namespace DiscImageChef.Filesystems.ISO9660
{ {
@@ -42,21 +43,40 @@ namespace DiscImageChef.Filesystems.ISO9660
public Errno ListXAttr(string path, out List<string> xattrs) public Errno ListXAttr(string path, out List<string> xattrs)
{ {
xattrs = null; xattrs = null;
if(!mounted) return Errno.AccessDenied;
if(!mounted)
return Errno.AccessDenied;
Errno err = GetFileEntry(path, out DecodedDirectoryEntry entry); Errno err = GetFileEntry(path, out DecodedDirectoryEntry entry);
if(err != Errno.NoError) return err;
if(err != Errno.NoError)
return err;
xattrs = new List<string>(); xattrs = new List<string>();
if(entry.XattrLength > 0) xattrs.Add("org.iso.9660.ea"); if(entry.XattrLength > 0)
if(entry.AssociatedFile != null) xattrs.Add("org.iso.9660.AssociatedFile"); xattrs.Add("org.iso.9660.ea");
if(entry.AppleDosType != null) xattrs.Add("com.apple.dos.type");
if(entry.AppleProDosType != null) xattrs.Add("com.apple.prodos.type"); if(entry.AssociatedFile != null)
if(entry.ResourceFork != null) xattrs.Add("com.apple.ResourceFork"); xattrs.Add("org.iso.9660.AssociatedFile");
if(entry.FinderInfo != null) xattrs.Add("com.apple.FinderInfo");
if(entry.AppleIcon != null) xattrs.Add("com.apple.Macintosh.Icon"); if(entry.AppleDosType != null)
if(entry.AmigaComment != null) xattrs.Add("com.amiga.comments"); xattrs.Add("com.apple.dos.type");
if(entry.AppleProDosType != null)
xattrs.Add("com.apple.prodos.type");
if(entry.ResourceFork != null)
xattrs.Add("com.apple.ResourceFork");
if(entry.FinderInfo != null)
xattrs.Add("com.apple.FinderInfo");
if(entry.AppleIcon != null)
xattrs.Add("com.apple.Macintosh.Icon");
if(entry.AmigaComment != null)
xattrs.Add("com.amiga.comments");
return Errno.NoError; return Errno.NoError;
} }
@@ -64,20 +84,28 @@ namespace DiscImageChef.Filesystems.ISO9660
public Errno GetXattr(string path, string xattr, ref byte[] buf) public Errno GetXattr(string path, string xattr, ref byte[] buf)
{ {
buf = null; buf = null;
if(!mounted) return Errno.AccessDenied;
if(!mounted)
return Errno.AccessDenied;
Errno err = GetFileEntry(path, out DecodedDirectoryEntry entry); Errno err = GetFileEntry(path, out DecodedDirectoryEntry entry);
if(err != Errno.NoError) return err;
if(err != Errno.NoError)
return err;
switch(xattr) switch(xattr)
{ {
case "org.iso.9660.ea": case"org.iso.9660.ea":
if(entry.XattrLength == 0) return Errno.NoSuchExtendedAttribute; if(entry.XattrLength == 0)
return Errno.NoSuchExtendedAttribute;
if(entry.Extents is null) return Errno.InvalidArgument; if(entry.Extents is null)
return Errno.InvalidArgument;
uint eaSizeInSectors = (uint)(entry.XattrLength / 2048); uint eaSizeInSectors = (uint)(entry.XattrLength / 2048);
if(entry.XattrLength % 2048 > 0) eaSizeInSectors++;
if(entry.XattrLength % 2048 > 0)
eaSizeInSectors++;
byte[] ea = ReadSectors(entry.Extents[0].extent, eaSizeInSectors); byte[] ea = ReadSectors(entry.Extents[0].extent, eaSizeInSectors);
@@ -85,92 +113,99 @@ namespace DiscImageChef.Filesystems.ISO9660
Array.Copy(ea, 0, buf, 0, buf.LongLength); Array.Copy(ea, 0, buf, 0, buf.LongLength);
return Errno.NoError; return Errno.NoError;
case "org.iso.9660.AssociatedFile": case"org.iso.9660.AssociatedFile":
if(entry.AssociatedFile is null) return Errno.NoSuchExtendedAttribute; if(entry.AssociatedFile is null)
return Errno.NoSuchExtendedAttribute;
if(entry.AssociatedFile.Extents is null) return Errno.InvalidArgument; if(entry.AssociatedFile.Extents is null)
return Errno.InvalidArgument;
if(entry.AssociatedFile.Size == 0) if(entry.AssociatedFile.Size == 0)
{ {
buf = new byte[0]; buf = new byte[0];
return Errno.NoError; return Errno.NoError;
} }
if(entry.AssociatedFile.Extents.Count == 1) if(entry.AssociatedFile.Extents.Count == 1)
{ {
uint associatedFileSize = (uint)(entry.AssociatedFile.Size / 2048); uint associatedFileSize = (uint)(entry.AssociatedFile.Size / 2048);
if(entry.AssociatedFile.Size % 2048 > 0) associatedFileSize++;
if(entry.AssociatedFile.Size % 2048 > 0)
associatedFileSize++;
byte[] buffer = ReadSectors(entry.AssociatedFile.Extents[0].extent, associatedFileSize); byte[] buffer = ReadSectors(entry.AssociatedFile.Extents[0].extent, associatedFileSize);
buf = new byte[entry.AssociatedFile.Size]; buf = new byte[entry.AssociatedFile.Size];
Array.Copy(buffer, 0, buf, 0, buf.LongLength); Array.Copy(buffer, 0, buf, 0, buf.LongLength);
} }
else buf = ReadWithExtents(0, (long)entry.AssociatedFile.Size, entry.AssociatedFile.Extents); else
buf = ReadWithExtents(0, (long)entry.AssociatedFile.Size, entry.AssociatedFile.Extents);
return Errno.NoError; return Errno.NoError;
case "com.apple.dos.type": case"com.apple.dos.type":
if(entry.AppleDosType is null) return Errno.NoSuchExtendedAttribute; if(entry.AppleDosType is null)
return Errno.NoSuchExtendedAttribute;
buf = new byte[1]; buf = new byte[1];
buf[0] = entry.AppleDosType.Value; buf[0] = entry.AppleDosType.Value;
return Errno.NoError; return Errno.NoError;
case "com.apple.prodos.type": case"com.apple.prodos.type":
if(entry.AppleProDosType is null) return Errno.NoSuchExtendedAttribute; if(entry.AppleProDosType is null)
return Errno.NoSuchExtendedAttribute;
buf = BitConverter.GetBytes(entry.AppleProDosType.Value); buf = BitConverter.GetBytes(entry.AppleProDosType.Value);
return Errno.NoError; return Errno.NoError;
case "com.apple.ResourceFork": case"com.apple.ResourceFork":
if(entry.ResourceFork is null) return Errno.NoSuchExtendedAttribute; if(entry.ResourceFork is null)
return Errno.NoSuchExtendedAttribute;
if(entry.ResourceFork.Extents is null) return Errno.InvalidArgument; if(entry.ResourceFork.Extents is null)
return Errno.InvalidArgument;
if(entry.ResourceFork.Size == 0) if(entry.ResourceFork.Size == 0)
{ {
buf = new byte[0]; buf = new byte[0];
return Errno.NoError; return Errno.NoError;
} }
if(entry.ResourceFork.Extents.Count == 1) if(entry.ResourceFork.Extents.Count == 1)
{ {
uint rsrcSizeInSectors = (uint)(entry.ResourceFork.Size / 2048); uint rsrcSizeInSectors = (uint)(entry.ResourceFork.Size / 2048);
if(entry.AssociatedFile.Size % 2048 > 0) rsrcSizeInSectors++;
if(entry.AssociatedFile.Size % 2048 > 0)
rsrcSizeInSectors++;
byte[] buffer = ReadSectors(entry.ResourceFork.Extents[0].extent, rsrcSizeInSectors); byte[] buffer = ReadSectors(entry.ResourceFork.Extents[0].extent, rsrcSizeInSectors);
buf = new byte[entry.ResourceFork.Size]; buf = new byte[entry.ResourceFork.Size];
Array.Copy(buffer, 0, buf, 0, buf.LongLength); Array.Copy(buffer, 0, buf, 0, buf.LongLength);
} }
else buf = ReadWithExtents(0, (long)entry.ResourceFork.Size, entry.ResourceFork.Extents); else
buf = ReadWithExtents(0, (long)entry.ResourceFork.Size, entry.ResourceFork.Extents);
return Errno.NoError; return Errno.NoError;
case "com.apple.FinderInfo": case"com.apple.FinderInfo":
if(entry.FinderInfo is null) return Errno.NoSuchExtendedAttribute; if(entry.FinderInfo is null)
return Errno.NoSuchExtendedAttribute;
buf = new byte[16]; buf = Marshal.StructureToByteArrayBigEndian(entry.FinderInfo.Value);
byte[] tmp = BigEndianBitConverter.GetBytes(entry.FinderInfo.fdType);
Array.Copy(tmp, 0, buf, 0, tmp.Length);
tmp = BigEndianBitConverter.GetBytes(entry.FinderInfo.fdCreator);
Array.Copy(tmp, 0, buf, 4, tmp.Length);
tmp = BigEndianBitConverter.GetBytes((ushort)entry.FinderInfo.fdFlags);
Array.Copy(tmp, 0, buf, 8, tmp.Length);
tmp = BigEndianBitConverter.GetBytes(entry.FinderInfo.fdLocation.x);
Array.Copy(tmp, 0, buf, 10, tmp.Length);
tmp = BigEndianBitConverter.GetBytes(entry.FinderInfo.fdLocation.y);
Array.Copy(tmp, 0, buf, 12, tmp.Length);
tmp = BigEndianBitConverter.GetBytes(entry.FinderInfo.fdFldr);
Array.Copy(tmp, 0, buf, 14, tmp.Length);
return Errno.NoError; return Errno.NoError;
case "com.apple.Macintosh.Icon": case"com.apple.Macintosh.Icon":
if(entry.AppleIcon is null) return Errno.NoSuchExtendedAttribute; if(entry.AppleIcon is null)
return Errno.NoSuchExtendedAttribute;
buf = new byte[entry.AppleIcon.Length]; buf = new byte[entry.AppleIcon.Length];
Array.Copy(entry.AppleIcon, 0, buf, 0, entry.AppleIcon.Length); Array.Copy(entry.AppleIcon, 0, buf, 0, entry.AppleIcon.Length);
return Errno.NoError; return Errno.NoError;
case "com.amiga.comments": case"com.amiga.comments":
if(entry.AmigaComment is null) return Errno.NoSuchExtendedAttribute; if(entry.AmigaComment is null)
return Errno.NoSuchExtendedAttribute;
buf = new byte[entry.AmigaComment.Length]; buf = new byte[entry.AmigaComment.Length];
Array.Copy(entry.AmigaComment, 0, buf, 0, entry.AmigaComment.Length); Array.Copy(entry.AmigaComment, 0, buf, 0, entry.AmigaComment.Length);