Skip to content

Commit d49f3c9

Browse files
committed
Merge pull request #1 from kungfux/feature_v11
Version 1.1
2 parents c8cee31 + b620c93 commit d49f3c9

File tree

12 files changed

+238
-215
lines changed

12 files changed

+238
-215
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# EFS (Eat Free Space)
1+
# ffs-util
22

3-
EFS is utility to fill up all available free space on the drive.
3+
FFS (Fill Free Space) is an utility to fill up all available free space on the drive.
44
This utility is created to be used for testing purposes (e.g. resilience testing).
55

66
## How it works?
7-
EFS creates the empty file with defined file length. So, this file will be just a file declaration for file system. Such file can be created very quickly and there is no need to write some data to the file, so hard disk health is not suffering.
7+
FFS creates empty file with defined file length. So, this file will be just a file declaration for the file system. Such file can be created very quickly and there is no need to write some data to the file, so hard disk health is not suffering.
88

99
### Requirements:
1010

11-
.NET 4.5 is required to build the project.
11+
.NET Framework 2.0 is required to build the project.

project/App.config

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5-
</startup>
6-
</configuration>
4+
<supportedRuntime version="v2.0.50727"/></startup>
5+
</configuration>

project/Drive.cs

Lines changed: 0 additions & 83 deletions
This file was deleted.

project/DriveSpaceInfo.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.IO;
3+
4+
namespace ffs_util
5+
{
6+
internal class DriveSpaceInfo
7+
{
8+
private enum ESpaceSize
9+
{
10+
Bytes = 1,
11+
KB = 2,
12+
MB = 4,
13+
GB = 8,
14+
TB = 16
15+
}
16+
17+
private string _driveName = "";
18+
19+
20+
public DriveSpaceInfo(string DriveName)
21+
{
22+
_driveName = DriveName;
23+
}
24+
25+
26+
public long GetFreeSpaceAsLong()
27+
{
28+
try
29+
{
30+
DriveInfo dinfo = new DriveInfo(_driveName);
31+
return dinfo.AvailableFreeSpace;
32+
}
33+
catch (Exception ex)
34+
{
35+
Message.Instance.PrintError(ex.Message);
36+
Environment.Exit(1);
37+
return -1;
38+
}
39+
}
40+
41+
42+
public string GetFreeSpaceAsString()
43+
{
44+
long space = GetFreeSpaceAsLong();
45+
long[] result = ConvertBytes(space, 1, 16);
46+
return string.Format("{0} {1}", result[0].ToString(), (ESpaceSize)result[1]);
47+
}
48+
49+
50+
private long[] ConvertBytes(long bytes, int minEnum, int maxEnum)
51+
{
52+
int value = 1024;
53+
int sizeName = 1;
54+
double size = bytes;
55+
while ((size > value && sizeName < maxEnum) || sizeName < minEnum)
56+
{
57+
size = size / 1024;
58+
sizeName = sizeName * 2;
59+
}
60+
return new long[] { (long)Math.Round(size, 0), sizeName };
61+
}
62+
}
63+
}

project/EMessageType.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

project/EatFreeSpace.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

project/FillFreeSpace.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.IO;
3+
4+
namespace ffs_util
5+
{
6+
internal class FillFreeSpace
7+
{
8+
private const string _pieFile = "pie.ffs";
9+
10+
/// <summary>
11+
/// Fill available free space using temporary file declaration with defined length
12+
/// </summary>
13+
public void FillFreeSpaceWithEmptyFileOrDelete(string DriveName)
14+
{
15+
DriveSpaceInfo drive = new DriveSpaceInfo(DriveName);
16+
17+
string pieFileFullName = DriveName + @":\" + _pieFile;
18+
19+
if (File.Exists(pieFileFullName))
20+
{
21+
DeletePieFile(pieFileFullName);
22+
return;
23+
}
24+
25+
CreatePieFile(pieFileFullName, drive.GetFreeSpaceAsLong(), drive.GetFreeSpaceAsString());
26+
}
27+
28+
29+
private void CreatePieFile(string PieFileFullName, long DriveFreeSpace, string DriveFreeSpaceAsString)
30+
{
31+
if (DriveFreeSpace <= 0)
32+
{
33+
Message.Instance.PrintError("There is no free space available. Operation is aborted.");
34+
return;
35+
}
36+
37+
Message.Instance.PrintMessage(
38+
string.Format("Creating file {0} with size of {1}...",
39+
PieFileFullName, DriveFreeSpaceAsString)
40+
);
41+
42+
try
43+
{
44+
using (var fs = new FileStream(PieFileFullName, FileMode.CreateNew, FileAccess.Write))
45+
{
46+
fs.SetLength(DriveFreeSpace);
47+
fs.Close();
48+
Message.Instance.PrintMessage("Done.");
49+
}
50+
}
51+
catch(Exception ex)
52+
{
53+
Message.Instance.PrintError(ex.Message);
54+
}
55+
}
56+
57+
58+
private void DeletePieFile(string PieFileFullName)
59+
{
60+
Message.Instance.PrintMessage("Temporary file already exists. Removing...");
61+
62+
try
63+
{
64+
File.Delete(PieFileFullName);
65+
Message.Instance.PrintMessage("Done.");
66+
}
67+
catch (Exception ex)
68+
{
69+
Message.Instance.PrintError(ex.Message);
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)