Some VFS changes

This commit is contained in:
Scalpel_cp 2008-08-17 01:37:11 +00:00
parent bf15e65b09
commit 2ce8daa496
6 changed files with 85 additions and 25 deletions

View file

@ -97,13 +97,13 @@ namespace Cosmos.Sys {
// return false;
//}
/// <summary>
/// Get a single directory from the given path.
/// </summary>
/// <param name="aPath"></param>
/// <param name="aPath">Absolute path</param>
/// <returns></returns>
public static FilesystemEntry GetDirectoryEntry(string aPath) {
Cosmos.Hardware.DebugUtil.SendMessage("GetDirectoryEntry", "Searching for " + aPath);
//if (String.IsNullOrEmpty(aPath)) {
// throw new ArgumentNullException("aPath");
//}
@ -115,9 +115,12 @@ namespace Cosmos.Sys {
return null;
} else {
string[] xPathParts = SplitPath(aPath);
// first get the correct FS
Cosmos.Hardware.DebugUtil.SendMessage("GetDirectoryEntry", "Searching for filesystem");
var xFS = GetFileSystemFromPath(xPathParts[0], 0);
//var xFS = mFilesystems[ParseStringToInt(xPathParts[0], 0)];
var xCurrentFSEntryId = xFS.RootId;
Cosmos.Hardware.DebugUtil.SendMessage("GetDirectoryEntry", "Found filesystem " + xCurrentFSEntryId);
@ -156,7 +159,7 @@ namespace Cosmos.Sys {
/// <param name="aPath">Directory to search in. Can be absolute and relative.</param>
/// <returns>All Directories and Files in the given path.</returns>
public static FilesystemEntry[] GetDirectoryListing(string aPath) {
if (String.IsNullOrEmpty(aPath)) {
throw new ArgumentNullException("aPath is null in GetDirectoryListing");
}
@ -197,6 +200,24 @@ namespace Cosmos.Sys {
}
/// <summary>
/// Get a single volume
/// </summary>
public static FilesystemEntry GetVolumeEntry(int volumeId)
{
var xFS = GetFileSystemFromPath(volumeId.ToString(), 0);
return new FilesystemEntry()
{
Name = volumeId.ToString(),
Filesystem = xFS,
IsDirectory = true,
IsReadonly = true,
Id = (ulong)volumeId
};
}
private static FilesystemEntry[] GetVolumes()
{
//if (aFilesystems == null)
@ -206,13 +227,7 @@ namespace Cosmos.Sys {
var xResult = new FilesystemEntry[mFilesystems.Count];
for (int i = 0; i < mFilesystems.Count; i++)
{
xResult[i] = new FilesystemEntry()
{
Id = (ulong)i,
IsDirectory = true,
IsReadonly = true,
Name = i.ToString() //Volume number
};
xResult[i] = GetVolumeEntry(i);
}
return xResult;
}
@ -426,7 +441,11 @@ namespace Cosmos.Sys {
List<FilesystemEntry> xDirectories = new List<FilesystemEntry>();
Cosmos.Hardware.DebugUtil.SendMessage("GetDirectories", "About to GetDirectoryListing");
var xEntries = VFSManager.GetDirectoryListing(Path.GetDirectoryName(aDir));
var xDir = VFSManager.GetDirectoryEntry(Path.GetDirectoryName(aDir));
Cosmos.Hardware.DebugUtil.SendMessage("GetDirectories", xDir.Name + " with ID " + xDir.Id.ToString());
var xEntries = VFSManager.GetDirectoryListing(xDir);
//var xEntries = VFSManager.GetDirectoryListing(Path.GetDirectoryName(aDir));
foreach (FilesystemEntry entry in xEntries)
if (entry.IsDirectory)
@ -508,7 +527,7 @@ namespace Cosmos.Sys {
// throw new DirectoryNotFoundException("Unable to find directory " + aDir);
List<FilesystemEntry> xFiles = new List<FilesystemEntry>();
var xEntries = GetDirectoryListing(Path.GetDirectoryName(aDir));
var xEntries = VFSManager.GetDirectoryListing(Path.GetDirectoryName(aDir));
foreach (FilesystemEntry entry in xEntries)
if (!entry.IsDirectory)

View file

@ -30,7 +30,7 @@ namespace FrodeTest.Application
//TODO: Use DirectoryInfo.GetParent
string xCurDir = Directory.GetCurrentDirectory();
xCurDir = xCurDir.TrimEnd(Path.DirectorySeparatorChar);
//EnvironmentVariables.GetCurrent().CurrentDirectory = xCurDir.Substring(0, xCurDir.LastIndexOf(Path.DirectorySeparatorChar));
Directory.SetCurrentDirectory(
Directory.GetCurrentDirectory().Substring(
0,
@ -41,16 +41,14 @@ namespace FrodeTest.Application
return 0;
}
string xNewPath = Directory.GetCurrentDirectory() + args[0] + "/"; //EnvironmentVariables.GetCurrent().CurrentDirectory + args[0] + "/";
string xNewPath = Directory.GetCurrentDirectory() + args[0] + "/";
DebugUtil.SendMessage("cd.cs", "Checking path " + xNewPath);
if (Directory.Exists(xNewPath))
{
//EnvironmentVariables.GetCurrent().CurrentDirectory = xNewPath;
Directory.SetCurrentDirectory(xNewPath);
}
else if (Directory.Exists(args[0] + "/"))
{
//EnvironmentVariables.GetCurrent().CurrentDirectory += args[0] + "/";
Directory.SetCurrentDirectory(Directory.GetCurrentDirectory() + args[0] + "/");
}
else

View file

@ -16,25 +16,32 @@ namespace FrodeTest.Application
{
try
{
//Get current directory
//Get directory
string xDir = string.Empty;
if (args[0] != null)
xDir = args[0];
else
xDir = Directory.GetCurrentDirectory();
//xDir= EnvironmentVariables.GetCurrent().CurrentDirectory; //HACK
Console.WriteLine(" Directory of " + xDir);
if (!Directory.Exists(xDir))
{
Console.WriteLine("No such directory: " + xDir);
return -1;
}
else
{
Console.WriteLine(" Directory of " + xDir);
foreach (string xDirectory in Directory.GetDirectories(xDir))
Console.WriteLine("<DIR>\t" + xDirectory);
foreach (string xDirectory in Directory.GetDirectories(xDir))
Console.WriteLine("<DIR>\t" + xDirectory);
foreach (string xFile in Directory.GetFiles(xDir))
Console.WriteLine("\t\t" + xFile);
foreach (string xFile in Directory.GetFiles(xDir))
Console.WriteLine("\t\t" + xFile);
}
}
catch (Exception e)
{
Console.WriteLine("ERROR: " + e.Message);
Console.WriteLine("ERROR in dir command: " + e.Message);
}
return 0;
}

View file

@ -70,6 +70,7 @@
<Compile Include="Test\BinaryHelperTest.cs" />
<Compile Include="Test\BoolTest.cs" />
<Compile Include="Test\DirectoryInfoTest.cs" />
<Compile Include="Test\DirectoryTest.cs" />
<Compile Include="Test\Ethernet2FrameTest.cs" />
<Compile Include="Test\ExceptionTest.cs" />
<Compile Include="Test\ExtensionMethodsTest.cs" />

View file

@ -66,7 +66,8 @@ namespace FrodeTest
//Test.ExceptionTest.RunTest();
//Test.FilesystemEntryTest.RunTest();
//Test.VirtualFileSystemTest.RunTest();
Test.DirectoryInfoTest.RunTest();
Test.DirectoryTest.RunTest();
//Test.DirectoryInfoTest.RunTest();
//Test.FileInfoTest.RunTest();
//Tests ready for Matthijs to fix ;)

View file

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace FrodeTest.Test
{
public class DirectoryTest
{
public static void RunTest()
{
Check.Text = "Exists";
Check.Validate(Directory.Exists("/0/"));
Check.Validate(Directory.Exists("/0/Alfa/"));
Check.Validate(Directory.Exists("/0/Alfa/Bravo/"));
Check.Validate(!Directory.Exists("/0/InvalidDir/"));
Check.Text = "GetDirectories";
Check.Validate(Directory.GetDirectories("/0/").Length == 3);
Check.Validate(Directory.GetDirectories("/0/Alfa/").Length == 1);
Check.Text = "GetFiles";
Check.Validate(Directory.GetFiles("/0/Alfa/").Length == 0);
Check.Validate(Directory.GetFiles("/0/Alfa/Bravo/").Length == 1);
Check.Text = "GetLogicalDrives";
Check.Validate(Directory.GetLogicalDrives().Length == 2);
Check.Text = "GetParent";
Check.Validate(Directory.GetParent("/0/Alfa/Bravo/") == "/0/Alfa/");
}
}
}