Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jp2masa committed Nov 3, 2016
1 parent 1a7aed0 commit a8dca0d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 20 deletions.
2 changes: 0 additions & 2 deletions source/Cosmos.System.Plugs/System/DecimalImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Text;
using System.Threading.Tasks;

using System;

using Cosmos.IL2CPU.Plugs;

namespace Cosmos.System.Plugs.System
Expand Down
4 changes: 3 additions & 1 deletion source/Cosmos.System.Plugs/System/IO/DirectoryImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ public static DirectoryInfo CreateDirectory(string aPath)
}

Global.mFileSystemDebugger.SendInternal($"Directory.CreateDirectory : aPath = {aPath}");

var xEntry = VFSManager.CreateDirectory(aPath);

if (xEntry == null)
{
return null;
}

return new DirectoryInfo(aPath);
}

Expand Down
5 changes: 5 additions & 0 deletions source/Cosmos.System/FileSystem/CosmosVFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,29 @@ public override DirectoryEntry CreateDirectory(string aPath)
Global.mFileSystemDebugger.SendInternal("Path already exists.");
return GetDirectory(aPath);
}

Global.mFileSystemDebugger.SendInternal("Path doesn't exist.");

string xDirectoryToCreate = Path.GetFileName(aPath);

Global.mFileSystemDebugger.SendInternal("After GetFileName");
Global.mFileSystemDebugger.SendInternal("xDirectoryToCreate =");
Global.mFileSystemDebugger.SendInternal(xDirectoryToCreate);

string xParentDirectory = aPath.Remove(aPath.Length - xDirectoryToCreate.Length);

Global.mFileSystemDebugger.SendInternal("After removing last path part");
Global.mFileSystemDebugger.SendInternal("xParentDirectory =");
Global.mFileSystemDebugger.SendInternal(xParentDirectory);

DirectoryEntry xParentEntry = GetDirectory(xParentDirectory);

if (xParentEntry == null)
{
Global.mFileSystemDebugger.SendInternal("Parent directory doesn't exist.");
xParentEntry = CreateDirectory(xParentDirectory);
}

Global.mFileSystemDebugger.SendInternal("Parent directory exists.");

var xFS = GetFileSystemFromPath(xParentDirectory);
Expand Down
13 changes: 7 additions & 6 deletions source/Cosmos.System/FileSystem/FAT/FatFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public uint GetNextUnallocatedFatEntry()

throw new Exception("Failed to find an unallocated FAT entry.");
}

/// <summary>
/// Clears a fat entry.
/// </summary>
Expand Down Expand Up @@ -476,18 +476,19 @@ internal void Write(long aCluster, byte[] aData, long aSize = 0, long aOffset =
aSize = BytesPerCluster;
}

byte[] xTempData;
Read(aCluster, out xTempData);
Array.Copy(aData, 0, xTempData, (long)aOffset, aData.Length);
byte[] xData;

Read(aCluster, out xData);
Array.Copy(aData, 0, xData, aOffset, aData.Length);

if (mFatType == FatTypeEnum.Fat32)
{
long xSector = DataSector + (aCluster - RootCluster) * SectorsPerCluster;
mDevice.WriteBlock((ulong) xSector, SectorsPerCluster, aData);
mDevice.WriteBlock((ulong) xSector, SectorsPerCluster, xData);
}
else
{
mDevice.WriteBlock((ulong) aCluster, RootSectorCount, aData);
mDevice.WriteBlock((ulong) aCluster, RootSectorCount, xData);
}
}

Expand Down
45 changes: 37 additions & 8 deletions source/Cosmos.System/FileSystem/FAT/Listing/FatDiretoryEntry.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//#define COSMOSDEBUG

using System;
using System.Collections.Generic;

using Cosmos.Common.Extensions;
using Cosmos.System.FileSystem.Listing;

using global::System;
using global::System.Collections.Generic;

namespace Cosmos.System.FileSystem.FAT.Listing
{
using global::System.IO;
Expand Down Expand Up @@ -114,9 +114,14 @@ public override void SetSize(long aSize)

private void AllocateDirectoryEntry()
{
// TODO: Deal with short and long name.
Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.AllocateDirectoryEntry --");

// TODO: Deal with short and long name.
if (mName.Length > 12)
{
throw new Exception("FatDirectoryEntry: Long Names not supported in new Directory Entries");
}

char[] xName =
{
(char)0x20, (char)0x20, (char)0x20, (char)0x20, (char)0x20, (char)0x20, (char)0x20,
Expand Down Expand Up @@ -151,11 +156,11 @@ private void AllocateDirectoryEntry()
SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata.FirstClusterHigh, (uint)(mFirstClusterNum >> 16));
SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata.FirstClusterLow, (uint)(mFirstClusterNum & 0xFFFF));

byte[] xData = GetDirectoryEntryData();
//byte[] xData = GetDirectoryEntryData();

SetDirectoryEntryData(xData);
//SetDirectoryEntryData(xData);
}

public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum aType)
{
Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.AddDirectoryEntry --");
Expand All @@ -182,6 +187,7 @@ public FatDirectoryEntry AddDirectoryEntry(string aName, DirectoryEntryTypeEnum

return xNewEntry;
}

throw new ArgumentOutOfRangeException(nameof(aType), "Unknown directory entry type.");
}

Expand All @@ -190,9 +196,28 @@ public void DeleteDirectoryEntry()
if (mEntryType == DirectoryEntryTypeEnum.Unknown)
throw new NotImplementedException();

if (mParent != null)
{
var xData = ((FatDirectoryEntry)mParent).GetDirectoryEntryData();

var xEntryOffset = mEntryHeaderDataOffset - 32;

while (xData[xEntryOffset + 11] == FatDirectoryEntryAttributeConsts.LongName)
{
xData[xEntryOffset] = FatDirectoryEntryAttributeConsts.UnusedOrDeletedEntry;
xEntryOffset -= 32;
}

((FatDirectoryEntry)mParent).SetDirectoryEntryData(xData);
}

SetDirectoryEntryMetadataValue(FatDirectoryEntryMetadata.FirstByte, FatDirectoryEntryAttributeConsts.UnusedOrDeletedEntry);
}

/// <summary>
/// Retrieves a <see cref="List{T}"/> of <see cref="FatDirectoryEntry"/> objects that represent the Directory Entries inside this Directory
/// </summary>
/// <returns>Returns a <see cref="List{T}"/> of the Directory Entries inside this Directory</returns>
public List<FatDirectoryEntry> ReadDirectoryContents()
{
Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.ReadDirectoryContents --");
Expand Down Expand Up @@ -357,6 +382,10 @@ public List<FatDirectoryEntry> ReadDirectoryContents()
return xResult;
}

/// <summary>
/// Tries to find an empty space for a directory entry and returns the offset to that space if successful, otherwise throws an exception.
/// </summary>
/// <returns>Returns the offset to the next unallocated directory entry.</returns>
private uint GetNextUnallocatedDirectoryEntry()
{
Global.mFileSystemDebugger.SendInternal("-- FatDirectoryEntry.GetNextUnallocatedDirectoryEntry --");
Expand All @@ -376,7 +405,7 @@ private uint GetNextUnallocatedDirectoryEntry()
}
}

// TODO: What should we return if no available entry is found.
// TODO: What should we return if no available entry is found. - Update Method description above.
throw new Exception("Failed to find an unallocated directory entry.");
}

Expand Down
6 changes: 3 additions & 3 deletions source/Cosmos.System/FileSystem/VFS/VFSManager.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//#define COSMOSDEBUG

using global::System;
using global::System.Collections.Generic;
using global::System.IO;
using System;
using System.Collections.Generic;
using System.IO;

using Cosmos.System.FileSystem.Listing;

Expand Down

0 comments on commit a8dca0d

Please sign in to comment.