Skip to content

Commit

Permalink
Nested folders are now supported as well with Directory.Exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Jul 4, 2015
1 parent 7e481aa commit 8c09908
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 23 deletions.
Binary file modified Build/VMWare/Workstation/Filesystem.vmdk
Binary file not shown.
9 changes: 9 additions & 0 deletions Users/Sentinel/SentinelKernel/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ protected override void Run()
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
{
Expand Down
67 changes: 50 additions & 17 deletions Users/Sentinel/SentinelSystem/FileSystem/FAT/FatFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class FatFileSystem : FileSystem
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)
{
Expand Down Expand Up @@ -96,7 +96,7 @@ public UInt64 GetFatEntry(byte[] aSector, UInt64 aClusterNum, UInt64 aOffset)
}
}

public FatFileSystem(Cosmos.HAL.BlockDevice.BlockDevice aDevice)
public FatFileSystem(BlockDevice aDevice)
{

mDevice = aDevice;
Expand Down Expand Up @@ -196,10 +196,8 @@ public void GetFatTableSector(UInt64 aClusterNum, out UInt32 oSector, out UInt32
oOffset = (UInt32)(xOffset % BytesPerSector);
}

public List<System.FileSystem.Listing.Base> GetRoot()
public List<Base> GetRoot()
{
var xResult = new List<System.FileSystem.Listing.Base>();

byte[] xData;
if (FatType == FatTypeEnum.Fat32)
{
Expand All @@ -210,7 +208,38 @@ public void GetFatTableSector(UInt64 aClusterNum, out UInt32 oSector, out UInt32
{
xData = mDevice.NewBlockArray(RootSectorCount);
mDevice.ReadBlock(RootSector, RootSectorCount, xData);
// todo: is this correct??
}
return ReadDirectoryContents(xData);
}

public List<Base> 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<Base> ReadDirectoryContents(byte[] xData)
{
var xResult = new List<Base>();
//TODO: Change xLongName to StringBuilder
for (UInt32 i = 0; i < xData.Length; i = i + 32)
{
Expand All @@ -230,7 +259,6 @@ public void GetFatTableSector(UInt64 aClusterNum, out UInt32 oSector, out UInt32
}
if (xType == 0)
{

if ((xOrd & 0x40) > 0)
{
xLongName = "";
Expand Down Expand Up @@ -272,7 +300,6 @@ public void GetFatTableSector(UInt64 aClusterNum, out UInt32 oSector, out UInt32
}
else if (xStatus >= 0x20)
{

if (xLongName.Length > 0)
{
// Leading and trailing spaces are to be ignored according to spec.
Expand Down Expand Up @@ -314,20 +341,25 @@ public void GetFatTableSector(UInt64 aClusterNum, out UInt32 oSector, out UInt32
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!");
Expand All @@ -338,8 +370,6 @@ public void GetFatTableSector(UInt64 aClusterNum, out UInt32 oSector, out UInt32
return xResult;
}



public static bool IsDeviceFAT(Partition aDevice)
{
byte[] xBPB = aDevice.NewBlockArray(1);
Expand All @@ -359,7 +389,10 @@ public override List<Base> GetDirectoryListing(Directory baseDirectory)
// get root folder
return GetRoot();
}
throw new NotImplementedException();
else
{
return GetDirectoryContents((FatDirectory)baseDirectory);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
1 change: 1 addition & 0 deletions Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public static bool DirectoryExists(string aPath)
{
try
{
FatHelpers.Debug("DirectoryExists. Path = '" + aPath + "'");
string xDir = aPath + VFSBase.DirectorySeparatorChar;
//xDir = Path.GetDirectoryName(xDir);
return (VFSManager.GetDirectory(xDir) != null);
Expand Down
4 changes: 0 additions & 4 deletions Users/Sentinel/SentinelSystem/SentinelVFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ public override Listing.Directory GetDirectory(string aPath)
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)
Expand Down

0 comments on commit 8c09908

Please sign in to comment.