simulator: Implement Simulator.dumpFiles to easily inspect the in-memory file system's state
This commit is contained in:
@@ -414,3 +414,23 @@ pub fn fileSize(self: *FileSystem, open_file: *OpenFile) usize {
|
|||||||
_ = self;
|
_ = self;
|
||||||
return open_file.entity.bytes.items.len;
|
return open_file.entity.bytes.items.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dumpEntity(entity: *Entity, depth: u32) void {
|
||||||
|
if (entity.is_dir) {
|
||||||
|
for (entity.children.items) |item| {
|
||||||
|
for (0..depth) |_|
|
||||||
|
std.debug.print(" ", .{});
|
||||||
|
std.debug.print("{s}\n", .{ item.getName() });
|
||||||
|
dumpEntity(item.addr, depth+1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (0..depth) |_|
|
||||||
|
std.debug.print(" ", .{});
|
||||||
|
std.debug.print("[{s}]", .{ entity.bytes.items });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dump(self: *FileSystem) void {
|
||||||
|
dumpEntity(self.root, 0);
|
||||||
|
std.debug.print("\n", .{});
|
||||||
|
}
|
||||||
|
|||||||
@@ -381,3 +381,7 @@ pub fn closeSocket(self: *Node, handle: Handle) HandleError!void {
|
|||||||
}
|
}
|
||||||
desc.kind = .unused;
|
desc.kind = .unused;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dumpFiles(self: *Node) void {
|
||||||
|
self.file_system.dump();
|
||||||
|
}
|
||||||
|
|||||||
@@ -77,6 +77,12 @@ pub fn scheduleOne(self: *Simulator) bool {
|
|||||||
return self.scheduler.scheduleOne();
|
return self.scheduler.scheduleOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dumpFiles(self: *Simulator) void {
|
||||||
|
for (self.nodes.items) |node| {
|
||||||
|
node.dumpFiles();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reads the first word of a command
|
// Reads the first word of a command
|
||||||
// "program arg1 arg2 arg3" -> "program"
|
// "program arg1 arg2 arg3" -> "program"
|
||||||
fn extractProgramNameFromCommand(command: []const u8) ?[]const u8 {
|
fn extractProgramNameFromCommand(command: []const u8) ?[]const u8 {
|
||||||
|
|||||||
Reference in New Issue
Block a user