diff --git a/Build/VMWare/Workstation/Filesystem.vmdk b/Build/VMWare/Workstation/Filesystem.vmdk index efd0caba0..0d9535331 100644 Binary files a/Build/VMWare/Workstation/Filesystem.vmdk and b/Build/VMWare/Workstation/Filesystem.vmdk differ diff --git a/Users/Sentinel/SentinelKernel/Kernel.cs b/Users/Sentinel/SentinelKernel/Kernel.cs index 6a44e4332..9ad5faec5 100644 --- a/Users/Sentinel/SentinelKernel/Kernel.cs +++ b/Users/Sentinel/SentinelKernel/Kernel.cs @@ -29,6 +29,15 @@ namespace SentinelKernel if (xTest) { Console.WriteLine("Folder exists!"); + xTest = Directory.Exists("0:\\test\\DirInTest"); + if (xTest) + { + Console.WriteLine("Subfolder exists as well!"); + } + else + { + Console.WriteLine("Subfolder doesn't exist!"); + } } else { diff --git a/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatFileSystem.cs b/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatFileSystem.cs index db9266182..a237c4f33 100644 --- a/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatFileSystem.cs +++ b/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatFileSystem.cs @@ -33,7 +33,7 @@ namespace SentinelKernel.System.FileSystem.FAT public enum FatTypeEnum { Unknown, Fat12, Fat16, Fat32 } readonly public FatTypeEnum FatType = FatTypeEnum.Unknown; - Cosmos.HAL.BlockDevice.BlockDevice mDevice; + BlockDevice mDevice; public void ReadFatTableSector(UInt64 xSectorNum, byte[] aData) { @@ -96,7 +96,7 @@ namespace SentinelKernel.System.FileSystem.FAT } } - public FatFileSystem(Cosmos.HAL.BlockDevice.BlockDevice aDevice) + public FatFileSystem(BlockDevice aDevice) { mDevice = aDevice; @@ -196,10 +196,8 @@ namespace SentinelKernel.System.FileSystem.FAT oOffset = (UInt32)(xOffset % BytesPerSector); } - public List 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)