public void Format(string name) { byte[] data = new byte[512]; fixed(byte *ptr = data) { WitchHeader *header = (WitchHeader *)ptr; for (int i = 0; i < name.Length; i++) { header->name[i] = (byte)name[i]; } header->name[name.Length] = 0; for (int i = 0; i < home.Length; i++) { header->rootdir[i] = (byte)home[i]; } header->rootdir[home.Length] = 0; for (int i = 0; i < MountPoint.Length; i++) { header->mountpoint[i] = (byte)MountPoint[i]; } header->mountpoint[MountPoint.Length] = 0; header->firstblock = 2; } partition.WriteBlock(1, 1, data); Out.printf("Header created!\n"); Out.printf("Writing test file..."); WriteFile(2, 1, "HelloWorld", "Hello from WitchFS!"); }
public void Init() { Out.printf("Reading WitchFS header...\n"); byte[] data = new byte[512]; partition.ReadBlock(1, 1, data); Header = (WitchHeader *)Cosmos.Core.Heap.MemAlloc((uint)sizeof(WitchHeader)); fixed(byte *ptr = data) { Kernel.MemCopy((uint)ptr, (uint)Header, 0, (uint)sizeof(WitchHeader)); } Out.printf("Validating header...\n"); if (ByteToString(Header->name) != "WitchOS") { Out.printf("Invalid header!\n"); Out.printf("Rewriting header...\n"); Format("WitchOS"); } else { Out.printf("The WitchOS header is valid\n"); } Out.printf("Getting files..."); InitFiles(); Out.printf("Listing files..."); ListFiles(); }