mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add support for Human68k 18.3 filenames in FAT.
This commit is contained in:
@@ -221,7 +221,8 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
Nt,
|
||||
Lfn,
|
||||
Os2,
|
||||
Ecs
|
||||
Ecs,
|
||||
Human
|
||||
}
|
||||
|
||||
[Flags]
|
||||
|
||||
@@ -211,6 +211,26 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
if(extension != "") filename = name + "." + extension;
|
||||
else filename = name;
|
||||
|
||||
if(@namespace == Namespace.Human)
|
||||
{
|
||||
HumanDirectoryEntry humanEntry =
|
||||
Marshal.ByteArrayToStructureLittleEndian<HumanDirectoryEntry>(directoryBuffer, pos,
|
||||
Marshal
|
||||
.SizeOf<HumanDirectoryEntry
|
||||
>());
|
||||
|
||||
completeEntry.HumanDirent = humanEntry;
|
||||
|
||||
name = StringHandlers.CToString(humanEntry.name1, Encoding).TrimEnd();
|
||||
extension = StringHandlers.CToString(humanEntry.extension, Encoding).TrimEnd();
|
||||
string name2 = StringHandlers.CToString(humanEntry.name2, Encoding).TrimEnd();
|
||||
|
||||
if(extension != "") filename = name + name2 + "." + extension;
|
||||
else filename = name + name2;
|
||||
|
||||
completeEntry.HumanName = filename;
|
||||
}
|
||||
|
||||
// Using array accessor ensures that repeated entries just get substituted.
|
||||
// Repeated entries are not allowed but some bad implementations (e.g. FAT32.IFS)allow to create them
|
||||
// when using spaces
|
||||
|
||||
@@ -133,11 +133,14 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
Length = entry.size,
|
||||
Inode = (ulong)(fat32 ? (entry.ea_handle << 16) + entry.start_cluster : entry.start_cluster),
|
||||
Links = 1,
|
||||
CreationTime = DateHandlers.DosToDateTime(entry.cdate, entry.ctime),
|
||||
LastWriteTime = DateHandlers.DosToDateTime(entry.mdate, entry.mtime)
|
||||
CreationTime = DateHandlers.DosToDateTime(entry.cdate, entry.ctime)
|
||||
};
|
||||
|
||||
if(@namespace != Namespace.Human)
|
||||
{
|
||||
stat.LastWriteTime = DateHandlers.DosToDateTime(entry.mdate, entry.mtime);
|
||||
stat.CreationTime = stat.CreationTime?.AddMilliseconds(entry.ctime_ms * 10);
|
||||
}
|
||||
|
||||
if(entry.size % bytesPerCluster > 0) stat.Blocks++;
|
||||
|
||||
|
||||
@@ -867,6 +867,22 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
public readonly uint size;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct HumanDirectoryEntry
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
|
||||
public readonly byte[] name1;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
||||
public readonly byte[] extension;
|
||||
public readonly FatAttributes attributes;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
|
||||
public readonly byte[] name2;
|
||||
public readonly ushort mtime;
|
||||
public readonly ushort mdate;
|
||||
public readonly ushort start_cluster;
|
||||
public readonly uint size;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct LfnEntry
|
||||
{
|
||||
@@ -899,6 +915,8 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
{
|
||||
public DirectoryEntry Dirent;
|
||||
public DirectoryEntry Fat32Ea;
|
||||
public HumanDirectoryEntry HumanDirent;
|
||||
public string HumanName;
|
||||
public string Lfn;
|
||||
public string Longname;
|
||||
public string Shortname;
|
||||
@@ -908,6 +926,9 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
// This ensures LFN takes preference when eCS is in use
|
||||
if(!string.IsNullOrEmpty(Lfn)) return Lfn;
|
||||
|
||||
// This ensures Humans takes preference when present
|
||||
if(!string.IsNullOrEmpty(HumanName)) return HumanName;
|
||||
|
||||
return !string.IsNullOrEmpty(Longname) ? Longname : Shortname;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
|
||||
Dictionary<string, string> options, string @namespace)
|
||||
{
|
||||
Encoding = encoding ?? Encoding.GetEncoding("IBM437");
|
||||
XmlFsType = new FileSystemType();
|
||||
if(options == null) options = GetDefaultOptions();
|
||||
if(options.TryGetValue("debug", out string debugString)) bool.TryParse(debugString, out debug);
|
||||
@@ -85,6 +84,9 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
case "lfn":
|
||||
this.@namespace = Namespace.Lfn;
|
||||
break;
|
||||
case "human":
|
||||
this.@namespace = Namespace.Human;
|
||||
break;
|
||||
default: return Errno.InvalidArgument;
|
||||
}
|
||||
|
||||
@@ -227,10 +229,21 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
}
|
||||
|
||||
case BpbKind.Human:
|
||||
// If not debug set Human68k namespace and ShiftJIS codepage as defaults
|
||||
if(!debug)
|
||||
{
|
||||
this.@namespace = Namespace.Human;
|
||||
encoding = Encoding.GetEncoding("shift_jis");
|
||||
}
|
||||
|
||||
XmlFsType.Bootable = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Encoding = encoding ?? (bpbKind == BpbKind.Human
|
||||
? Encoding.GetEncoding("shift_jis")
|
||||
: Encoding.GetEncoding("IBM437"));
|
||||
|
||||
ulong firstRootSector = 0;
|
||||
|
||||
if(!fat32)
|
||||
@@ -527,6 +540,26 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
|
||||
completeEntry.Shortname = filename;
|
||||
|
||||
if(this.@namespace == Namespace.Human)
|
||||
{
|
||||
HumanDirectoryEntry humanEntry =
|
||||
Marshal.ByteArrayToStructureLittleEndian<HumanDirectoryEntry>(rootDirectory, i,
|
||||
Marshal
|
||||
.SizeOf<HumanDirectoryEntry
|
||||
>());
|
||||
|
||||
completeEntry.HumanDirent = humanEntry;
|
||||
|
||||
name = StringHandlers.CToString(humanEntry.name1, Encoding).TrimEnd();
|
||||
extension = StringHandlers.CToString(humanEntry.extension, Encoding).TrimEnd();
|
||||
string name2 = StringHandlers.CToString(humanEntry.name2, Encoding).TrimEnd();
|
||||
|
||||
if(extension != "") filename = name + name2 + "." + extension;
|
||||
else filename = name + name2;
|
||||
|
||||
completeEntry.HumanName = filename;
|
||||
}
|
||||
|
||||
if(!fat32 && filename == "EA DATA. SF")
|
||||
{
|
||||
eaDirEntry = entry;
|
||||
@@ -699,8 +732,6 @@ namespace DiscImageChef.Filesystems.FAT
|
||||
}
|
||||
}
|
||||
|
||||
System.Console.WriteLine("First cluster sector: {0}", firstClusterSector);
|
||||
System.Console.WriteLine("Sectors per cluster: {0}", sectorsPerCluster);
|
||||
mounted = true;
|
||||
return Errno.NoError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user