static void Main() { var fs = new Filesystem(); var output = new StringBuilder(); while (true) { var line = Console.ReadLine(); if (line == "exit") { break; } var strs = line.Split(' '); if (strs[0] == "append") { fs.Append(strs[1], strs[2]); } else if (strs[0] == "copy") { fs.Copy(strs[1], strs[2]); } else if (strs[0] == "cow") { fs.CoW(strs[1], strs[2]); } else if (strs[0] == "remove") { fs.Remove(strs[1]); } else if (strs[0] == "dedup") { fs.Dedup(); } else if (strs[0] == "usage") { var usage = fs.Usage(); output.AppendLine(string.Format("{0} blocks are currently in use.", usage)); } else if (strs[0] == "size") { var size = fs.Size(strs[1]); output.AppendLine(string.Format("{0} is {1} blocks large.", strs[1], size)); } else { throw new NotSupportedException("No such command " + line); } } Console.WriteLine(output.ToString().Trim()); }
public void Append(string filename, string content) { var blocks = Filesystem.SplitBlocks(content); File file; if (!this.files.TryGetValue(filename, out file)) { file = new File(); this.files[filename] = file; } file.Append(blocks); this.allocatedBlocksCount += blocks.Length; }