From 8c09908079eb897e7fe5aaedffc22d3527c7938e Mon Sep 17 00:00:00 2001 From: Matthijs ter Woord Date: Sat, 4 Jul 2015 17:09:46 +0200 Subject: [PATCH] Nested folders are now supported as well with Directory.Exists --- Build/VMWare/Workstation/Filesystem.vmdk | Bin 393216 -> 393216 bytes Users/Sentinel/SentinelKernel/Kernel.cs | 9 +++ .../FileSystem/FAT/FatFileSystem.cs | 67 +++++++++++++----- .../FileSystem/FAT/Listing/FatDirectory.cs | 7 +- .../FileSystem/VFS/VFSManager.cs | 1 + Users/Sentinel/SentinelSystem/SentinelVFS.cs | 4 -- 6 files changed, 65 insertions(+), 23 deletions(-) diff --git a/Build/VMWare/Workstation/Filesystem.vmdk b/Build/VMWare/Workstation/Filesystem.vmdk index efd0caba0e84782602b537ccd81a4efcbaec4620..0d95353311b8fc2ba9b64847554f8ca11e7b69e3 100644 GIT binary patch delta 469 zcmZo@kZ5R-*kHrNVUd(%X=!3^IoXA2u}@iMQAufHjz@S{YEf}!ex8D@f|8{YS4v8f zUQT{qx^sSBNorn+rwd5j(8R*bJSjQVAkn}uInl`6!q~{d($v@xZlFK2^JG(Ig~`&) z%9A;mg+&rm5(`RFi$W?3QbGDNQ&N?R2x^J#m|UrH*wTh%TvTUBmcvx?%&XJmb^tjt#8; zZLJ+$7%~}(7(5yB82A}xhcKiv6f=}CFfjc855oWdyLbk9`i0aPDkvxjFeI#~eB$=R zje%h$kY)!usFi=(I#%9#RB@ng1_nJnpbiK?)5ivucMJkrmB^67kPEc8IF&&UXln)7 zW{AB(u8uCgt_lhv5g`f;^{b%vZUE983>sh)5X9yW%q9F9AsLy)3Tc@+sS25S3OV`7 di6yBiAZAQSYH>-7OJt-2z2%hMF1e0m{kA( delta 237 zcmZo@kZ5R-*kHrNVQgw>o@ii{GTDV`u~1@4VnIo2QAlM$s)DV8Qf5l(z9+Cm+qXOSCX1n;^_iXWRz%ZV4i4Vl4xd>YMf}1YG7)dY@B473Nu)V zD GetRoot() + public List GetRoot() { - var xResult = new List(); - byte[] xData; if (FatType == FatTypeEnum.Fat32) { @@ -210,7 +208,38 @@ namespace SentinelKernel.System.FileSystem.FAT { xData = mDevice.NewBlockArray(RootSectorCount); mDevice.ReadBlock(RootSector, RootSectorCount, xData); + // todo: is this correct?? } + return ReadDirectoryContents(xData); + } + + public List GetDirectoryContents(FatDirectory directory) + { + if (directory == null) + { + throw new ArgumentNullException("directory"); + } + + byte[] xData; + if (FatType == FatTypeEnum.Fat32) + { + xData = NewClusterArray(); + ReadCluster(directory.FirstClusterNr, xData); + } + else + { + xData = mDevice.NewBlockArray(1); + mDevice.ReadBlock(directory.FirstClusterNr, RootSectorCount, xData); + } + // todo: what about larger directories? + + + return ReadDirectoryContents(xData); + } + + private List ReadDirectoryContents(byte[] xData) + { + var xResult = new List(); //TODO: Change xLongName to StringBuilder for (UInt32 i = 0; i < xData.Length; i = i + 32) { @@ -230,7 +259,6 @@ namespace SentinelKernel.System.FileSystem.FAT } if (xType == 0) { - if ((xOrd & 0x40) > 0) { xLongName = ""; @@ -272,7 +300,6 @@ namespace SentinelKernel.System.FileSystem.FAT } else if (xStatus >= 0x20) { - if (xLongName.Length > 0) { // Leading and trailing spaces are to be ignored according to spec. @@ -314,20 +341,25 @@ namespace SentinelKernel.System.FileSystem.FAT if (xTest == 0) { UInt32 xSize = xData.ToUInt32(i + 28); - xResult.Add(new Listing.FatFile(this, xName, xSize, xFirstCluster)); + if (xSize == 0 && xName.Length == 0) + { + continue; + } + xResult.Add(new FatFile(this, xName, xSize, xFirstCluster)); FatHelpers.Debug("Returning file '" + xName + "'"); } + else if (xTest == DirectoryEntryAttributeConsts.Directory || xAttrib == DirectoryEntryAttributeConsts.LongName) + { + UInt32 xSize = xData.ToUInt32(i + 28); + var xFatDirectory = new FatDirectory(this, xName, xFirstCluster); + FatHelpers.Debug("Returning directory '" + xFatDirectory.Name + "'"); + xResult.Add(xFatDirectory); + } else if (xTest == DirectoryEntryAttributeConsts.VolumeID) { FatHelpers.Debug("Directory entry is VolumeID"); // } - else if (xTest == DirectoryEntryAttributeConsts.Directory || xAttrib == DirectoryEntryAttributeConsts.LongName) - { - var xFatDirectory = new Listing.FatDirectory(this, xName); - FatHelpers.Debug("Returning directory '" + xName + "'"); - xResult.Add(xFatDirectory); - } else { FatHelpers.Debug("Not sure what to do!"); @@ -338,8 +370,6 @@ namespace SentinelKernel.System.FileSystem.FAT return xResult; } - - public static bool IsDeviceFAT(Partition aDevice) { byte[] xBPB = aDevice.NewBlockArray(1); @@ -359,7 +389,10 @@ namespace SentinelKernel.System.FileSystem.FAT // get root folder return GetRoot(); } - throw new NotImplementedException(); + else + { + return GetDirectoryContents((FatDirectory)baseDirectory); + } } } } diff --git a/Users/Sentinel/SentinelSystem/FileSystem/FAT/Listing/FatDirectory.cs b/Users/Sentinel/SentinelSystem/FileSystem/FAT/Listing/FatDirectory.cs index e32eaa0b5..d186b8704 100644 --- a/Users/Sentinel/SentinelSystem/FileSystem/FAT/Listing/FatDirectory.cs +++ b/Users/Sentinel/SentinelSystem/FileSystem/FAT/Listing/FatDirectory.cs @@ -7,9 +7,12 @@ namespace SentinelKernel.System.FileSystem.FAT.Listing { public class FatDirectory : System.FileSystem.Listing.Directory { - public FatDirectory(FileSystem aFileSystem, string aName) + public FatDirectory(FileSystem aFileSystem, string aName, uint firstCluster) : base(aFileSystem, aName) { + FirstClusterNr = firstCluster; } + + public uint FirstClusterNr; } -} \ No newline at end of file +} diff --git a/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSManager.cs b/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSManager.cs index 332034240..66086361e 100644 --- a/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSManager.cs +++ b/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSManager.cs @@ -284,6 +284,7 @@ namespace SentinelKernel.System.FileSystem.VFS { try { + FatHelpers.Debug("DirectoryExists. Path = '" + aPath + "'"); string xDir = aPath + VFSBase.DirectorySeparatorChar; //xDir = Path.GetDirectoryName(xDir); return (VFSManager.GetDirectory(xDir) != null); diff --git a/Users/Sentinel/SentinelSystem/SentinelVFS.cs b/Users/Sentinel/SentinelSystem/SentinelVFS.cs index a22598f0b..5e2fad0b6 100644 --- a/Users/Sentinel/SentinelSystem/SentinelVFS.cs +++ b/Users/Sentinel/SentinelSystem/SentinelVFS.cs @@ -243,10 +243,6 @@ namespace SentinelKernel.System.FileSystem.VFS for (int j = 0; j < xListing.Count; j++) { var xListingItem = xListing[j]; - Console.Write("xListingItem.Name: "); - Console.WriteLine(xListingItem.Name); - Console.Write("xPathPart: "); - Console.WriteLine(xPathPart); if (String.Equals(xListingItem.Name, xPathPart, StringComparison.OrdinalIgnoreCase)) { if (xListingItem is Listing.Directory)