More filesystem work.

This commit is contained in:
Charles Betros 2015-11-14 21:41:30 -06:00
parent 75f681c175
commit a391864356
7 changed files with 392 additions and 101 deletions

View file

@ -33,6 +33,42 @@ namespace Cosmos.Kernel.Tests.Fat
bool xTest;
string xContents;
mDebugger.Send("Get parent:");
var xParent = Directory.GetParent(@"0:\test");
Assert.IsTrue(xParent.Name == @"0:\", "Failed to get directory parent.");
mDebugger.Send("Create directory:");
var xDirectory = Directory.CreateDirectory(@"0:\test2");
bool xExists = Directory.Exists(@"0:\test2");
Assert.IsTrue(xExists, "Failed to create a new directory.");
//mDebugger.Send("Get files:");
//var xFiles = Directory.GetFiles(@"0:\");
//mDebugger.Send("Found " + xFiles.Length + " files.");
//if (xFiles.Length > 0)
//{
// mDebugger.Send("-- File list --");
// for (int i = 0; i < xFiles.Length; i++)
// {
// mDebugger.Send("File: " + xFiles[i]);
// }
//}
//Assert.IsTrue(xFiles.Length > 0, "Failed to get files from the directory.");
//mDebugger.Send("Get directories:");
//var xDirectories = Directory.GetDirectories(@"0:\");
//mDebugger.Send("Found " + xDirectories.Length + " directories.");
//if (xDirectories.Length > 0)
//{
// mDebugger.Send("-- Directory list --");
// for (int i = 0; i < xDirectories.Length; i++)
// {
// mDebugger.Send("Directory: " + xDirectories[i]);
// }
//}
//Assert.IsTrue(xDirectories.Length > 0, "Failed to get directories from the directory.");
//Assert.IsTrue(Path.GetDirectoryName(@"0:\test") == @"0:\", @"Path.GetDirectoryName(@'0:\test') == @'0:\'");
//Assert.IsTrue(Path.GetFileName(@"0:\test") == @"test", @"Path.GetFileName(@'0:\test') == @'test'");
@ -70,26 +106,26 @@ namespace Cosmos.Kernel.Tests.Fat
//mDebugger.Send(xContents);
//Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!");
using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create))
{
mDebugger.Send("Start writing");
var xStr = "Test FAT Write.";
var xBuff = xStr.GetUtf8Bytes(0, (uint)xStr.Length);
xFS.Write(xBuff, 0, xBuff.Length);
mDebugger.Send("---- Data written");
xFS.Position = 0;
xFS.Read(xBuff, 0, xBuff.Length);
mDebugger.Send(xBuff.GetUtf8String(0, (uint)xBuff.Length));
}
//using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create))
//{
// mDebugger.Send("Start writing");
// var xStr = "Test FAT Write.";
// var xBuff = xStr.GetUtf8Bytes(0, (uint)xStr.Length);
// xFS.Write(xBuff, 0, xBuff.Length);
// mDebugger.Send("---- Data written");
// xFS.Position = 0;
// xFS.Read(xBuff, 0, xBuff.Length);
// mDebugger.Send(xBuff.GetUtf8String(0, (uint)xBuff.Length));
//}
//mDebugger.Send("Write to file now");
//File.WriteAllText(@"0:\Kudzu.txt", "Test FAT write.");
//mDebugger.Send("Text written");
xContents = File.ReadAllText(@"0:\Kudzu.txt");
mDebugger.Send("Contents retrieved after writing");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "Test FAT write.", "Contents of Kudzu.txt was written incorrectly!");
//xContents = File.ReadAllText(@"0:\Kudzu.txt");
//mDebugger.Send("Contents retrieved after writing");
//mDebugger.Send(xContents);
//Assert.IsTrue(xContents == "Test FAT write.", "Contents of Kudzu.txt was written incorrectly!");
TestController.Completed();
}

View file

@ -41,8 +41,8 @@ namespace Cosmos.TestRunner.Core
//engine.AddKernel(typeof(Cosmos.Compiler.Tests.MultidimensionalArrays.Kernel).Assembly.Location);
// Experimental stuff:
//engine.AddKernel(typeof(Cosmos.Kernel.Tests.Fat.Kernel).Assembly.Location);
engine.AddKernel(typeof(Cosmos.Kernel.Tests.FileSystemPlugs.Kernel).Assembly.Location);
engine.AddKernel(typeof(Cosmos.Kernel.Tests.Fat.Kernel).Assembly.Location);
//engine.AddKernel(typeof(Cosmos.Kernel.Tests.FileSystemPlugs.Kernel).Assembly.Location);
// end of known bugs

View file

@ -1,13 +1,14 @@
using System;
using System.IO;
using System.Collections.Generic;
using Cosmos.IL2CPU.Plugs;
using Cosmos.System.FileSystem;
using Cosmos.System.FileSystem.Listing;
using Cosmos.System.FileSystem.VFS;
namespace Cosmos.System.Plugs.System.IO
{
using Cosmos.System.FileSystem;
[Plug(Target = typeof(Directory))]
public static class DirectoryImpl
{
@ -16,28 +17,46 @@ namespace Cosmos.System.Plugs.System.IO
public static string GetCurrentDirectory()
{
FatHelpers.Debug("-- Directory.GetCurrentDirectory --");
return mCurrentDirectory;
}
public static void SetCurrentDirectory(string aPath)
{
FatHelpers.Debug("-- Directory.SetCurrentDirectory --");
mCurrentDirectory = aPath;
}
public static bool Exists(string aPath)
{
FatHelpers.Debug("-- Directory.Exists --");
return VFSManager.DirectoryExists(aPath);
}
public static DirectoryInfo CreateDirectory(string aPath)
{
FatHelpers.Debug("-- Directory.CreateDirectory --");
if (aPath == null)
{
throw new ArgumentNullException("aPath");
}
if (aPath.Length == 0)
{
throw new ArgumentException("Path must not be empty.", "aPath");
}
var xEntry = VFSManager.CreateDirectory(aPath);
if (xEntry == null)
{
return null;
}
return new DirectoryInfo(aPath);
}
public static DirectoryInfo GetParent(string aPath)
{
FatHelpers.Debug("-- Directory.GetParent --");
if (aPath == null)
{
throw new ArgumentNullException("aPath");
@ -55,7 +74,50 @@ namespace Cosmos.System.Plugs.System.IO
return null;
}
return new DirectoryInfo(xName);
return new DirectoryInfo(xFullPath);
}
public static string[] GetDirectories(string aPath)
{
FatHelpers.Debug("-- Directory.GetDirectories --");
if (aPath == null)
{
throw new ArgumentNullException(aPath);
}
var xDirectories = new List<string>();
var xEntries = VFSManager.GetDirectoryListing(aPath);
for (int i = 0; i < xEntries.Count; i++)
{
if (xEntries[i].EntryType == DirectoryEntryTypeEnum.Directory)
{
xDirectories.Add(xEntries[i].Name);
}
}
return xDirectories.ToArray();
}
public static string[] GetFiles(string aPath)
{
FatHelpers.Debug("-- Directory.GetFiles --");
if (aPath == null)
{
throw new ArgumentNullException(aPath);
}
var xFiles = new List<string>();
var xEntries = VFSManager.GetDirectoryListing(aPath);
for (int i = 0; i < xEntries.Count; i++)
{
if (xEntries[i].EntryType == DirectoryEntryTypeEnum.File)
{
xFiles.Add(xEntries[i].Name);
}
}
return xFiles.ToArray();
}
}
}

View file

@ -6,82 +6,302 @@ using Cosmos.System.FileSystem.VFS;
namespace Cosmos.System.Plugs.System.IO
{
using Cosmos.System.FileSystem;
using global::System;
using global::System.Collections.Generic;
[Plug(Target = typeof(DirectoryInfo))]
[PlugField(FieldId = "$$Storage$$", FieldType = typeof(DirectoryEntry))]
[PlugField(FieldId = "$$FullPath$$", FieldType = typeof(string))]
public static class DirectoryInfoImpl
{
[PlugMethod(/*Signature = "System_Void__System_IO_DirectoryInfo__ctor_System_String_"*/)]
public static void Ctor(DirectoryInfo aThis, string aPath)
public static void Ctor(DirectoryInfo aThis, string aPath,
[FieldAccess(Name = "$$Storage$$")] ref DirectoryEntry aStorage,
[FieldAccess(Name = "$$FullPath$$")] ref string aFullPath)
{
//if (aPath == null)
// throw new ArgumentNullException("aPath is null in DirectoryInfo ctor");
if (aPath == null)
{
throw new ArgumentNullException("aPath is null in DirectoryInfo ctor");
}
////Search for directory
////if (!VFSManager.DirectoryExists(aPath))
//// throw new DirectoryNotFoundException("Unable to find directory " + aPath);
if (!VFSManager.DirectoryExists(aPath))
{
throw new DirectoryNotFoundException("Unable to find directory " + aPath);
}
////If it exists, then get the directory as a FilesystemEntry
//aStorage = VFSManager.GetDirectoryEntry(aPath);
//aFullPath = aPath;
aStorage = VFSManager.GetDirectory(aPath);
aFullPath = aPath;
}
public static string get_Name(DirectoryInfo aThis, [FieldAccess(Name = "$$Storage$$")] ref DirectoryEntry aStorage)
{
FatHelpers.Debug("-- DirectoryInfo.get_Name --");
throw new NotImplementedException();
}
public static DirectoryInfo get_Parent(DirectoryInfo aThis)
{
FatHelpers.Debug("-- DirectoryInfo.get_Parent --");
throw new NotImplementedException();
}
public static DirectoryInfo get_Root(DirectoryInfo aThis)
{
FatHelpers.Debug("-- DirectoryInfo.get_Root --");
throw new NotImplementedException();
}
public static bool get_Exists(DirectoryInfo aThis, [FieldAccess(Name = "$$Storage$$")] ref DirectoryEntry aStorage)
{
FatHelpers.Debug("-- DirectoryInfo.get_Exists --");
return VFSManager.DirectoryExists(aStorage);
}
//public static string FullName
//{
// get
// {
// return ".FullName isn't implemented yet";
// }
//}
//public static string get_FullName(DirectoryInfo aThis, [FieldAccess(Name = "$$FullPath$$")] String aFullPath)
//{
// //TODO: return FULL name
// return aFullPath;
//}
public static string get_Name(DirectoryInfo aThis, [FieldAccess(Name = "$$Storage$$")] ref DirectoryEntry aStorage)
public static FileInfo[] GetFiles(DirectoryInfo aThis, string searchPattern, [FieldAccess(Name = "$$Storage$$")] ref DirectoryEntry aStorage)
{
return aStorage.Name;
if (searchPattern == null)
{
throw new ArgumentNullException("searchPattern");
}
throw new NotImplementedException();
}
public static FileInfo[] GetFiles(DirectoryInfo aThis, string searchPattern, SearchOption searchOption, [FieldAccess(Name = "$$Storage$$")] ref DirectoryEntry aStorage)
{
if (searchPattern == null)
{
throw new ArgumentNullException("searchPattern");
}
if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories))
{
throw new ArgumentOutOfRangeException("searchOption", "Argument is out of range.");
}
throw new NotImplementedException();
}
public static FileInfo[] GetFiles(DirectoryInfo aThis, [FieldAccess(Name = "$$Storage$$")] ref DirectoryEntry aStorage)
{
return null;
}
/*
List<FileInfo> xFiles = new List<FileInfo>();
var xEntries = VFSManager.GetFiles(aStorage);
foreach (FileSystem.Listing.Base xEntry in xEntries)
public static DirectoryInfo CreateSubdirectory(DirectoryInfo aThis, string path, [FieldAccess(Name = "$$Storage$$")] ref DirectoryEntry aStorage)
{
if (path == null)
{
xFiles.Add(new FileInfo(xEntry.Name));
throw new ArgumentNullException("path");
}
return xFiles.ToArray();
//Alternative implementation
//var xEntries = VFSManager.GetFiles(aStorage);
//FileInfo[] files = new FileInfo[xEntries.Length];
//for (int i = 0; i < xEntries.Length; i++)
//{
// files[i] = new FileInfo(xEntries[i].Name);
//}
//return files;
*/
throw new NotImplementedException();
}
public static string ToString([FieldAccess(Name = "$$Path$$")] ref string aPath)
{
return "DirectoryInfo.ToString() not yet implemented";
}
//public static void Create()
//{
//}
//public static DirectoryInfo[] GetDirectories()
//{
// throw new NotImplementedException();
//}
//public static FileSystemInfo[] GetFileSystemInfos(String searchPattern)
//{
// if (searchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// throw new NotImplementedException();
//}
//public static FileSystemInfo[] GetFileSystemInfos(String searchPattern, SearchOption searchOption)
//{
// if (searchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories))
// {
// throw new ArgumentOutOfRangeException("searchOption", "Argument is out of range.");
// }
// throw new NotImplementedException();
//}
//public static FileSystemInfo[] GetFileSystemInfos()
//{
// throw new NotImplementedException();
//}
//public static DirectoryInfo[] GetDirectories(String searchPattern)
//{
// if (searchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// throw new NotImplementedException();
//}
//public static DirectoryInfo[] GetDirectories(String searchPattern, SearchOption searchOption)
//{
// if (searchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories))
// {
// throw new ArgumentOutOfRangeException("searchOption", "Argument is out of range.");
// }
// throw new NotImplementedException();
//}
//public static IEnumerable<DirectoryInfo> EnumerateDirectories()
//{
// throw new NotImplementedException();
//}
//public static IEnumerable<DirectoryInfo> EnumerateDirectories(String searchPattern)
//{
// if (searchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// throw new NotImplementedException();
//}
//public static IEnumerable<DirectoryInfo> EnumerateDirectories(String searchPattern, SearchOption searchOption)
//{
// if (searchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories))
// {
// throw new ArgumentOutOfRangeException("searchOption", "Argument is out of range.");
// }
// throw new NotImplementedException();
//}
//public static IEnumerable<FileInfo> EnumerateFiles()
//{
// throw new NotImplementedException();
//}
//public static IEnumerable<FileInfo> EnumerateFiles(String searchPattern)
//{
// if (searchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// throw new NotImplementedException();
//}
//public static IEnumerable<FileInfo> EnumerateFiles(String searchPattern, SearchOption searchOption)
//{
// if (searchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories))
// {
// throw new ArgumentOutOfRangeException("searchOption", "Argument is out of range.");
// }
// throw new NotImplementedException();
//}
//public static IEnumerable<FileSystemInfo> EnumerateFileSystemInfos()
//{
// throw new NotImplementedException();
//}
//public static IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(String searchPattern)
//{
// if (searchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// throw new NotImplementedException();
//}
//public static IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(string aSearchPattern, SearchOption aSearchOption)
//{
// if (aSearchPattern == null)
// {
// throw new ArgumentNullException("searchPattern");
// }
// if ((aSearchOption != SearchOption.TopDirectoryOnly) && (aSearchOption != SearchOption.AllDirectories))
// {
// throw new ArgumentOutOfRangeException("searchOption", "Argument is out of range.");
// }
// throw new NotImplementedException();
//}
//public static void MoveTo(String destDirName)
//{
// if (destDirName == null)
// {
// throw new ArgumentNullException("destDirName");
// }
// if (destDirName.Length == 0)
// {
// throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destDirName");
// }
// String fullDestDirName = Path.GetFullPathInternal(destDirName);
// if (!fullDestDirName.EndsWith(Path.DirectorySeparatorChar))
// fullDestDirName = fullDestDirName + Path.DirectorySeparatorChar;
// String fullSourcePath;
// if (FullPath.EndsWith(Path.DirectorySeparatorChar))
// fullSourcePath = FullPath;
// else
// fullSourcePath = FullPath + Path.DirectorySeparatorChar;
// if (String.Compare(fullSourcePath, fullDestDirName, StringComparison.OrdinalIgnoreCase) == 0)
// throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustBeDifferent"));
// String sourceRoot = Path.GetPathRoot(fullSourcePath);
// String destinationRoot = Path.GetPathRoot(fullDestDirName);
// if (String.Compare(sourceRoot, destinationRoot, StringComparison.OrdinalIgnoreCase) != 0)
// throw new IOException(Environment.GetResourceString("IO.IO_SourceDestMustHaveSameRoot"));
// // TODO: Do the move
// FullPath = fullDestDirName;
// OriginalPath = destDirName;
// DisplayPath = GetDisplayName(OriginalPath, FullPath);
//}
//public static void Delete()
//{
// throw new NotImplementedException();
// //Directory.Delete(FullPath, OriginalPath, false, true);
//}
//public static void Delete(bool recursive)
//{
// throw new NotImplementedException();
// //Directory.Delete(FullPath, OriginalPath, recursive, true);
//}
}
}

View file

@ -250,13 +250,6 @@ namespace Cosmos.System.Plugs.System.IO
{
FatHelpers.Debug("-- Path.GetFullPath --");
return GetFullPathInternal(aPath);
}
public static string GetFullPathInternal(string aPath)
{
FatHelpers.Debug("-- Path.GetFullPathInternal --");
if (aPath == null)
{
throw new ArgumentNullException("aPath");

View file

@ -9,32 +9,10 @@ using Cosmos.System.FileSystem.VFS;
namespace Cosmos.System.FileSystem
{
[Serializable]
public struct KVP<TKey, TValue>
{
private readonly TKey key;
private readonly TValue value;
public KVP(TKey key, TValue value)
{
this.key = key;
this.value = value;
}
public TKey Key
{
get { return key; }
}
public TValue Value
{
get { return value; }
}
}
public class CosmosVFS : VFSBase
{
private List<Partition> mPartitions;
private List<FileSystem> mFileSystems;
public override void Initialize()
@ -164,6 +142,7 @@ namespace Cosmos.System.FileSystem
string xMessage = string.Concat("Initialized ", mFileSystems.Count, "filesystem(s)...");
global::System.Console.WriteLine(xMessage);
mFileSystems[i].DisplayFileSystemInfo();
Directory.SetCurrentDirectory(xRootPath);
}
else
{
@ -237,6 +216,6 @@ namespace Cosmos.System.FileSystem
{
return aFS.GetRootDirectory();
}
}
}
}
}

View file

@ -387,6 +387,7 @@ namespace Cosmos.System.FileSystem.VFS
{
xPath = xEntry + xEntry.Name;
xEntry = aEntry.Parent;
FatHelpers.Debug("-- VFSManager.GetFullPath : xPath = " + xPath + " --");
}
return Path.GetFullPath(xPath);