forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multi-cluster allocation when writing using fatstream.
- Loading branch information
1 parent
169dc5e
commit b9307ac
Showing
18 changed files
with
361 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Text; | ||
using Cosmos.HAL.BlockDevice; | ||
using Cosmos.System.FileSystem; | ||
using Cosmos.System.FileSystem.FAT; | ||
using NUnit.Framework; | ||
|
||
namespace Cosmos.System.Tests | ||
{ | ||
public class FatFileSystem_Should | ||
{ | ||
private FatFileSystem mFS; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
var xDevice = new TestBlockDevice(); | ||
var xPartition = new Partition(xDevice, 0, xDevice.BlockCount); | ||
var xFactory = new FatFileSystemFactory(); | ||
mFS = (FatFileSystem) xFactory.Create(xPartition, "0:\\", (long) (xPartition.BlockSize * xPartition.BlockCount)); | ||
} | ||
|
||
[Test] | ||
public void Load_Root_Directory_Entry() | ||
{ | ||
var xRootDirectory = mFS.GetRootDirectory(); | ||
Assert.NotNull(xRootDirectory); | ||
} | ||
|
||
[Test] | ||
public void Create_A_Directory_Entry() | ||
{ | ||
string xNewDirectoryEntryName = "NEW"; | ||
|
||
var xRootDirectory = mFS.GetRootDirectory(); | ||
Assert.NotNull(xRootDirectory); | ||
|
||
var xRootDirectoryListing = mFS.GetDirectoryListing(xRootDirectory); | ||
Assert.AreEqual(xRootDirectoryListing.Count, 0); | ||
|
||
mFS.CreateDirectory(xRootDirectory, xNewDirectoryEntryName); | ||
|
||
xRootDirectoryListing = mFS.GetDirectoryListing(xRootDirectory); | ||
Assert.AreEqual(xRootDirectoryListing.Count, 1); | ||
|
||
var xNewDirectoryEntry = xRootDirectoryListing[0]; | ||
Assert.AreEqual(xNewDirectoryEntry.mName, xNewDirectoryEntryName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Cosmos.HAL.BlockDevice; | ||
using Cosmos.System.FileSystem; | ||
using Cosmos.System.FileSystem.FAT; | ||
using NUnit.Framework; | ||
|
||
namespace Cosmos.System.Tests | ||
{ | ||
public class Fat_Should | ||
{ | ||
private FatFileSystem mFS; | ||
private FatFileSystem.Fat mFat; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
var xDevice = new TestBlockDevice(); | ||
var xPartition = new Partition(xDevice, 0, xDevice.BlockCount); | ||
var xFactory = new FatFileSystemFactory(); | ||
mFS = (FatFileSystem)xFactory.Create(xPartition, "0:\\", (long)(xPartition.BlockSize * xPartition.BlockCount)); | ||
mFat = mFS.GetFat(0); | ||
} | ||
|
||
[Test] | ||
public void Add_New_Clusters_To_Chain_When_Needed() | ||
{ | ||
uint xStartCluster = mFS.RootCluster; | ||
mFat.SetFatEntry(xStartCluster, mFat.FatEntryEofValue()); | ||
mFat.SetFatEntry(xStartCluster + 2, mFat.FatEntryEofValue()); | ||
mFat.SetFatEntry(xStartCluster + 5, mFat.FatEntryEofValue()); | ||
|
||
uint[] xChain = mFat.GetFatChain(xStartCluster, mFS.BytesPerCluster); | ||
Assert.AreEqual(xChain.Length, 1); | ||
|
||
xChain = mFat.GetFatChain(xStartCluster, mFS.BytesPerCluster * 3); | ||
Assert.AreEqual(3, xChain.Length); | ||
Assert.AreEqual(2, xChain[0]); | ||
Assert.AreEqual(3, xChain[1]); | ||
Assert.AreEqual(5, xChain[2]); | ||
|
||
xChain = mFat.GetFatChain(xStartCluster, mFS.BytesPerCluster * 5); | ||
Assert.AreEqual(5, xChain.Length); | ||
Assert.AreEqual(2, xChain[0]); | ||
Assert.AreEqual(3, xChain[1]); | ||
Assert.AreEqual(5, xChain[2]); | ||
Assert.AreEqual(6, xChain[3]); | ||
Assert.AreEqual(8, xChain[4]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Cosmos.HAL.BlockDevice; | ||
|
||
namespace Cosmos.System.Tests | ||
{ | ||
class TestBlockDevice : BlockDevice | ||
{ | ||
private byte[] mData; | ||
|
||
public TestBlockDevice() | ||
{ | ||
LoadTestData(); | ||
|
||
mBlockSize = 512; | ||
mBlockCount = (ulong) (mData.Length / (int) mBlockSize); | ||
} | ||
|
||
private void LoadTestData() | ||
{ | ||
var xList = new List<byte>(); | ||
|
||
using (var xReader = new StreamReader("../../../../Data/disk.txt")) | ||
{ | ||
while (!xReader.EndOfStream) | ||
{ | ||
string xLine = xReader.ReadLine(); | ||
if (!string.IsNullOrWhiteSpace(xLine)) | ||
{ | ||
xLine = xLine.Replace(" ", ""); | ||
xList.AddRange(StringToByteArray(xLine)); | ||
} | ||
} | ||
xReader.Close(); | ||
} | ||
|
||
for (int i = 0; i < 534610432 - xList.Count; i++) | ||
{ | ||
xList.Add(0x00); | ||
} | ||
|
||
mData = xList.ToArray(); | ||
} | ||
|
||
private static byte[] StringToByteArray(string hex) | ||
{ | ||
int NumberChars = hex.Length; | ||
byte[] bytes = new byte[NumberChars / 2]; | ||
for (int i = 0; i < NumberChars; i += 2) | ||
{ | ||
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); | ||
} | ||
|
||
return bytes; | ||
} | ||
|
||
public override void ReadBlock(ulong aBlockNo, ulong aBlockCount, ref byte[] aData) | ||
{ | ||
aData = NewBlockArray((uint) aBlockCount); | ||
Array.Copy(mData, (long) (aBlockNo * BlockSize), aData, 0, (long) (aBlockCount * BlockSize)); | ||
} | ||
|
||
public override void WriteBlock(ulong aBlockNo, ulong aBlockCount, ref byte[] aData) | ||
{ | ||
Array.Copy(aData, 0, mData, (long)(aBlockNo * BlockSize), (long)(aBlockCount * BlockSize)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
EB 58 90 4D 53 44 4F 53 35 2E 30 00 02 08 18 18 | ||
02 00 00 00 00 F8 00 00 3F 00 10 00 3F 00 00 00 | ||
C2 EE 0F 00 F4 03 00 00 00 00 00 00 02 00 00 00 | ||
01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
80 00 29 79 5D 0F 04 4E 4F 20 4E 41 4D 45 20 20 | ||
20 20 46 41 54 33 32 20 20 20 33 C9 8E D1 BC F4 | ||
7B 8E C1 8E D9 BD 00 7C 88 4E 02 8A 56 40 B4 41 | ||
BB AA 55 CD 13 72 10 81 FB 55 AA 75 0A F6 C1 01 | ||
74 05 FE 46 02 EB 2D 8A 56 40 B4 08 CD 13 73 05 | ||
B9 FF FF 8A F1 66 0F B6 C6 40 66 0F B6 D1 80 E2 | ||
3F F7 E2 86 CD C0 ED 06 41 66 0F B7 C9 66 F7 E1 | ||
66 89 46 F8 83 7E 16 00 75 38 83 7E 2A 00 77 32 | ||
66 8B 46 1C 66 83 C0 0C BB 00 80 B9 01 00 E8 2B | ||
00 E9 2C 03 A0 FA 7D B4 7D 8B F0 AC 84 C0 74 17 | ||
3C FF 74 09 B4 0E BB 07 00 CD 10 EB EE A0 FB 7D | ||
EB E5 A0 F9 7D EB E0 98 CD 16 CD 19 66 60 80 7E | ||
02 00 0F 84 20 00 66 6A 00 66 50 06 53 66 68 10 | ||
00 01 00 B4 42 8A 56 40 8B F4 CD 13 66 58 66 58 | ||
66 58 66 58 EB 33 66 3B 46 F8 72 03 F9 EB 2A 66 | ||
33 D2 66 0F B7 4E 18 66 F7 F1 FE C2 8A CA 66 8B | ||
D0 66 C1 EA 10 F7 76 1A 86 D6 8A 56 40 8A E8 C0 | ||
E4 06 0A CC B8 01 02 CD 13 66 61 0F 82 75 FF 81 | ||
C3 00 02 66 40 49 75 94 C3 42 4F 4F 54 4D 47 52 | ||
20 20 20 20 00 00 00 00 00 00 00 00 00 00 00 00 | ||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ||
00 00 00 00 00 00 00 00 00 00 00 00 0D 0A 52 65 | ||
6D 6F 76 65 20 64 69 73 6B 73 20 6F 72 20 6F 74 | ||
68 65 72 20 6D 65 64 69 61 2E FF 0D 0A 44 69 73 | ||
6B 20 65 72 72 6F 72 FF 0D 0A 50 72 65 73 73 20 | ||
61 6E 79 20 6B 65 79 20 74 6F 20 72 65 73 74 61 | ||
72 74 0D 0A 00 00 00 00 00 AC CB D8 00 00 55 AA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.