mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Implement Stat in Xbox FAT plugin.
This commit is contained in:
@@ -59,7 +59,7 @@ namespace DiscImageChef.Filesystems.FATX
|
|||||||
return Errno.NoError;
|
return Errno.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] pieces = cutPath.Split('/');
|
string[] pieces = cutPath.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
KeyValuePair<string, DirectoryEntry> entry =
|
KeyValuePair<string, DirectoryEntry> entry =
|
||||||
rootDirectory.FirstOrDefault(t => t.Key.ToLower(cultureInfo) == pieces[0]);
|
rootDirectory.FirstOrDefault(t => t.Key.ToLower(cultureInfo) == pieces[0]);
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using DiscImageChef.CommonTypes;
|
|
||||||
using DiscImageChef.CommonTypes.Interfaces;
|
using DiscImageChef.CommonTypes.Interfaces;
|
||||||
using DiscImageChef.CommonTypes.Structs;
|
using DiscImageChef.CommonTypes.Structs;
|
||||||
using Schemas;
|
using Schemas;
|
||||||
@@ -45,6 +44,7 @@ namespace DiscImageChef.Filesystems.FATX
|
|||||||
{
|
{
|
||||||
uint bytesPerCluster;
|
uint bytesPerCluster;
|
||||||
CultureInfo cultureInfo;
|
CultureInfo cultureInfo;
|
||||||
|
bool debug;
|
||||||
Dictionary<string, Dictionary<string, DirectoryEntry>> directoryCache;
|
Dictionary<string, Dictionary<string, DirectoryEntry>> directoryCache;
|
||||||
ushort[] fat16;
|
ushort[] fat16;
|
||||||
uint[] fat32;
|
uint[] fat32;
|
||||||
@@ -53,7 +53,6 @@ namespace DiscImageChef.Filesystems.FATX
|
|||||||
IMediaImage imagePlugin;
|
IMediaImage imagePlugin;
|
||||||
bool littleEndian;
|
bool littleEndian;
|
||||||
bool mounted;
|
bool mounted;
|
||||||
Partition partition;
|
|
||||||
Dictionary<string, DirectoryEntry> rootDirectory;
|
Dictionary<string, DirectoryEntry> rootDirectory;
|
||||||
uint sectorsPerCluster;
|
uint sectorsPerCluster;
|
||||||
FileSystemInfo stat;
|
FileSystemInfo stat;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using DiscImageChef.CommonTypes.Structs;
|
using DiscImageChef.CommonTypes.Structs;
|
||||||
|
|
||||||
namespace DiscImageChef.Filesystems.FATX
|
namespace DiscImageChef.Filesystems.FATX
|
||||||
@@ -66,7 +67,59 @@ namespace DiscImageChef.Filesystems.FATX
|
|||||||
stat = null;
|
stat = null;
|
||||||
if(!mounted) return Errno.AccessDenied;
|
if(!mounted) return Errno.AccessDenied;
|
||||||
|
|
||||||
throw new NotImplementedException();
|
if(debug && (string.IsNullOrEmpty(path) || path == "$" || path == "/"))
|
||||||
|
{
|
||||||
|
stat = new FileEntryInfo
|
||||||
|
{
|
||||||
|
Attributes = FileAttributes.Directory | FileAttributes.System | FileAttributes.Hidden,
|
||||||
|
Blocks = GetClusters(superblock.rootDirectoryCluster).Length,
|
||||||
|
BlockSize = bytesPerCluster,
|
||||||
|
DeviceNo = 0,
|
||||||
|
GID = 0,
|
||||||
|
Length = GetClusters(superblock.rootDirectoryCluster).Length * bytesPerCluster,
|
||||||
|
Inode = superblock.rootDirectoryCluster,
|
||||||
|
Links = 1,
|
||||||
|
Mode = 0x16D,
|
||||||
|
UID = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
return Errno.NoError;
|
||||||
|
}
|
||||||
|
|
||||||
|
Errno err = GetFileEntry(path, out DirectoryEntry entry);
|
||||||
|
if(err != Errno.NoError) return err;
|
||||||
|
|
||||||
|
stat = new FileEntryInfo
|
||||||
|
{
|
||||||
|
Attributes = new FileAttributes(),
|
||||||
|
Blocks = entry.length / bytesPerCluster,
|
||||||
|
BlockSize = bytesPerCluster,
|
||||||
|
DeviceNo = 0,
|
||||||
|
GID = 0,
|
||||||
|
Length = entry.length,
|
||||||
|
Inode = entry.firstCluster,
|
||||||
|
Links = 1,
|
||||||
|
Mode = (uint)(entry.attributes.HasFlag(Attributes.Directory) ? 0x16D : 0x124),
|
||||||
|
UID = 0,
|
||||||
|
CreationTime = DateHandlers.DosToDateTime(entry.creationDate, entry.creationTime).AddYears(20),
|
||||||
|
AccessTime = DateHandlers.DosToDateTime(entry.lastAccessDate, entry.lastAccessTime).AddYears(20),
|
||||||
|
LastWriteTime = DateHandlers.DosToDateTime(entry.lastWrittenDate, entry.lastWrittenTime)
|
||||||
|
.AddYears(20)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(entry.attributes.HasFlag(Attributes.Directory))
|
||||||
|
{
|
||||||
|
stat.Attributes |= FileAttributes.Directory;
|
||||||
|
stat.Blocks = GetClusters(entry.firstCluster).Length;
|
||||||
|
stat.Length = stat.Blocks * stat.BlockSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entry.attributes.HasFlag(Attributes.ReadOnly)) stat.Attributes |= FileAttributes.ReadOnly;
|
||||||
|
if(entry.attributes.HasFlag(Attributes.Hidden)) stat.Attributes |= FileAttributes.Hidden;
|
||||||
|
if(entry.attributes.HasFlag(Attributes.System)) stat.Attributes |= FileAttributes.System;
|
||||||
|
if(entry.attributes.HasFlag(Attributes.Archive)) stat.Attributes |= FileAttributes.Archive;
|
||||||
|
|
||||||
|
return Errno.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint[] GetClusters(uint startCluster)
|
uint[] GetClusters(uint startCluster)
|
||||||
@@ -98,5 +151,35 @@ namespace DiscImageChef.Filesystems.FATX
|
|||||||
|
|
||||||
return clusters.ToArray();
|
return clusters.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Errno GetFileEntry(string path, out DirectoryEntry entry)
|
||||||
|
{
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
|
||||||
|
string cutPath =
|
||||||
|
path.StartsWith("/") ? path.Substring(0).ToLower(cultureInfo) : path.ToLower(cultureInfo);
|
||||||
|
string[] pieces = cutPath.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
if(pieces.Length == 0) return Errno.InvalidArgument;
|
||||||
|
|
||||||
|
string parentPath = string.Join("/", pieces, 0, pieces.Length - 1);
|
||||||
|
|
||||||
|
Errno err = ReadDir(parentPath, out _);
|
||||||
|
|
||||||
|
if(err != Errno.NoError) return err;
|
||||||
|
|
||||||
|
Dictionary<string, DirectoryEntry> parent;
|
||||||
|
|
||||||
|
if(pieces.Length == 1) parent = rootDirectory;
|
||||||
|
else if(!directoryCache.TryGetValue(parentPath, out parent)) return Errno.InvalidArgument;
|
||||||
|
|
||||||
|
KeyValuePair<string, DirectoryEntry> dirent =
|
||||||
|
parent.FirstOrDefault(t => t.Key.ToLower(cultureInfo) == pieces[pieces.Length - 1]);
|
||||||
|
|
||||||
|
if(string.IsNullOrEmpty(dirent.Key)) return Errno.NoSuchFile;
|
||||||
|
|
||||||
|
entry = dirent.Value;
|
||||||
|
return Errno.NoError;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,8 @@ namespace DiscImageChef.Filesystems.FATX
|
|||||||
{
|
{
|
||||||
Encoding = Encoding.GetEncoding("iso-8859-15");
|
Encoding = Encoding.GetEncoding("iso-8859-15");
|
||||||
littleEndian = true;
|
littleEndian = true;
|
||||||
|
if(options == null) options = GetDefaultOptions();
|
||||||
|
if(options.TryGetValue("debug", out string debugString)) bool.TryParse(debugString, out debug);
|
||||||
|
|
||||||
if(imagePlugin.Info.SectorSize < 512) return Errno.InvalidArgument;
|
if(imagePlugin.Info.SectorSize < 512) return Errno.InvalidArgument;
|
||||||
|
|
||||||
@@ -157,7 +159,6 @@ namespace DiscImageChef.Filesystems.FATX
|
|||||||
}
|
}
|
||||||
|
|
||||||
sectorsPerCluster = (uint)(superblock.sectorsPerCluster * logicalSectorsPerPhysicalSectors);
|
sectorsPerCluster = (uint)(superblock.sectorsPerCluster * logicalSectorsPerPhysicalSectors);
|
||||||
this.partition = partition;
|
|
||||||
this.imagePlugin = imagePlugin;
|
this.imagePlugin = imagePlugin;
|
||||||
firstClusterSector = fatStartSector + fatSize;
|
firstClusterSector = fatStartSector + fatSize;
|
||||||
bytesPerCluster = sectorsPerCluster * imagePlugin.Info.SectorSize;
|
bytesPerCluster = sectorsPerCluster * imagePlugin.Info.SectorSize;
|
||||||
@@ -221,7 +222,6 @@ namespace DiscImageChef.Filesystems.FATX
|
|||||||
fat16 = null;
|
fat16 = null;
|
||||||
fat32 = null;
|
fat32 = null;
|
||||||
imagePlugin = null;
|
imagePlugin = null;
|
||||||
partition = new Partition();
|
|
||||||
mounted = false;
|
mounted = false;
|
||||||
|
|
||||||
return Errno.NoError;
|
return Errno.NoError;
|
||||||
|
|||||||
Reference in New Issue
Block a user