Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
sibvic committed Jan 9, 2019
1 parent 6888419 commit 09dc319
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions BadBlocksPlaceholder.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>
52 changes: 52 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.IO;

namespace BadBlocksPlaceholder
{
class Program
{
static void Main(string[] args)
{
var drive = new DriveInfo(args[0]);
int blockSize = int.Parse(args[1]) * 1024;
var block = new byte[blockSize];
var bbDir = Path.Combine(drive.RootDirectory.FullName, "BadBlockPlaceholders");
if (!Directory.Exists(bbDir))
Directory.CreateDirectory(bbDir);

var targetDir = Path.Combine(bbDir, DateTime.Now.ToString("yyyyMMdd"));
if (!Directory.Exists(targetDir))
Directory.CreateDirectory(targetDir);

int index = 0;
while (drive.AvailableFreeSpace > blockSize)
{
Console.WriteLine("Creating block #" + index);
var filename = Path.Combine(targetDir, index + ".bad");
++index;
using (var filestream = File.OpenWrite(filename))
{
filestream.Write(block, 0, blockSize);
filestream.Flush();
filestream.Close();
}
}

Console.WriteLine("Validating blocks");
foreach (var file in Directory.GetFiles(targetDir))
{
try
{
var res = File.ReadAllBytes(file);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
continue;
}
File.Delete(file);
}
Console.WriteLine("Done!");
}
}
}

0 comments on commit 09dc319

Please sign in to comment.