-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
113 lines (104 loc) · 3.86 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using IO = System.IO;
using System.CodeDom.Compiler;
namespace UnixV6FsTools
{
class Program
{
static void Main(string[] args)
{
foreach (var file in IO.Directory.GetFiles("Images", "*.dsk"))
{
Console.WriteLine("Unpacking {0}...", file);
unpack(file, file + "_unpack");
}
}
static void unpack(string imageFile, string targetPath)
{
Console.WriteLine("Unpacking filesystem...");
//read the complete file system to memory
var fs = FileSystem.Create(new FileStream(imageFile, FileMode.Open));
PrintTree(fs.RootDirectory, new IndentedTextWriter(Console.Out));
DirectoryInfo targetDir = new DirectoryInfo(targetPath);
if (targetDir.Exists) //kill directory if exists
targetDir.Delete(true);
targetDir.Create();
IO.File.WriteAllBytes(Path.Combine(targetDir.FullName, "block0.bin"), fs.BootBlock);
unpackDir(fs.RootDirectory, targetDir);
}
static void unpackDir(Directory dir, DirectoryInfo target)
{
foreach (var entry in dir.Entries)
{
if (entry.File.IsDirectory)
{
var newDir = target.CreateSubdirectory(entry.Name);
unpackDir((Directory)entry.File, newDir);
}
else if (entry.File.IsSpecial)
{
var special = (SpecialFile)entry.File;
string specialType;
switch (special.Type)
{
case SpecialFileType.Char:
specialType = "CharSpecial";
break;
case SpecialFileType.Block:
specialType = "BlockSpecial";
break;
default:
specialType = "???";
break;
}
IO.File.WriteAllText(Path.Combine(target.FullName, entry.Name),
string.Format("{0} {1}/{2}", specialType, special.MajorDeviceId, special.MinorDeviceId));
}
else
{
IO.File.WriteAllBytes(Path.Combine(target.FullName, entry.Name), entry.File.Content);
}
}
}
static void PrintTree(Directory dir, IndentedTextWriter writer)
{
foreach (var entry in dir.Entries)
{
writer.WriteLine(entry.Name);
writer.Indent++;
if (entry.File.IsDirectory)
{
PrintTree((Directory)entry.File, writer);
}
else if (entry.File.IsSpecial)
{
var special = (SpecialFile)entry.File;
string specialType;
switch (special.Type)
{
case SpecialFileType.Char:
specialType = "CharSpecial";
break;
case SpecialFileType.Block:
specialType = "BlockSpecial";
break;
default:
specialType = "???";
break;
}
writer.WriteLine("{0} {1}/{2}", specialType, special.MajorDeviceId, special.MinorDeviceId);
}
else
{
//nothing, name is enough
}
writer.Indent--;
}
}
}
}