Support overlay-based filesystem root

This commit is contained in:
logan
2025-01-24 23:57:53 -08:00
parent 462ffcf2ab
commit b6a98a63b4
7 changed files with 56 additions and 3 deletions

View File

@@ -36,6 +36,9 @@ public final class FileSystems {
private static final Logger LOGGER = LogManager.getLogger();
private static final LayeredFileSystem LAYERED_FILE_SYSTEM = new LayeredFileSystem();
private static final Map<ResourceLocation, BlockDeviceData> BLOCK_DEVICE_DATA = new HashMap<>();
private static final Map<String, BlockDeviceData> blocksByName = new HashMap<>();
public static ResourceManager _resourceManager = null;
///////////////////////////////////////////////////////////////////
@@ -43,6 +46,10 @@ public final class FileSystems {
return LAYERED_FILE_SYSTEM;
}
public static BlockDeviceData getBlockByName(String name) {
return blocksByName.get(name);
}
public static ResourceLocation getKeyByValue(BlockDeviceData value) {
for (Map.Entry<ResourceLocation, BlockDeviceData> entry : BLOCK_DEVICE_DATA.entrySet()) {
if (Objects.equals(value, entry.getValue())) {
@@ -84,6 +91,7 @@ public final class FileSystems {
///////////////////////////////////////////////////////////////////
private static void reload(final ResourceManager resourceManager) {
_resourceManager = resourceManager;
reset();
LOGGER.info("Searching for datapack filesystems...");
@@ -141,6 +149,7 @@ public final class FileSystems {
LOGGER.info(" Adding block device [{}] with id [{}] and a size of [{}].", name, location, formatSize(data.getBlockDevice().getCapacity()));
BLOCK_DEVICE_DATA.put(location, data);
blocksByName.put(name, data);
}
default -> LOGGER.error("Unsupported file system type [{}].", type);
}

View File

@@ -14,6 +14,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import li.cil.oc2.common.bus.device.data.FileSystems;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -62,11 +63,12 @@ public final class Items {
public static final RegistryObject<HardDriveItem> HARD_DRIVE_MEDIUM = register("hard_drive_medium", () ->
new HardDriveItem(4 * Constants.MEGABYTE, DyeColor.GREEN));
public static final RegistryObject<HardDriveItem> HARD_DRIVE_LARGE = register("hard_drive_large", () ->
new HardDriveItem(8 * Constants.MEGABYTE, DyeColor.CYAN));
new HardDriveItem(4 * Constants.MEGABYTE, DyeColor.CYAN));
public static final RegistryObject<HardDriveItem> HARD_DRIVE_EXTRA_LARGE = register("hard_drive_extra_large", () ->
new HardDriveItem(16 * Constants.MEGABYTE, DyeColor.YELLOW));
public static final RegistryObject<HardDriveWithExternalDataItem> HARD_DRIVE_CUSTOM = register("hard_drive_custom", () ->
new HardDriveWithExternalDataItem(BlockDeviceDataRegistry.BUILDROOT.getId(), DyeColor.BROWN));
public static final RegistryObject<HardDriveWithExternalDataItem> HARD_DRIVE_CUSTOM = register
("hard_drive_custom", () ->
new HardDriveWithExternalDataItem(FileSystems.getKeyByValue(FileSystems.getBlockByName("rootfs")), DyeColor.BROWN));
public static final RegistryObject<CPUItem> CPU_TIER_1 = register("cpu_tier_1", () ->
new CPUItem(25_000_000));

View File

@@ -1,6 +1,10 @@
/* SPDX-License-Identifier: MIT */
package li.cil.oc2.common.vm;
import li.cil.oc2.api.bus.device.data.BlockDeviceData;
import java.io.IOException;
import net.minecraft.resources.ResourceLocation;
import li.cil.ceres.api.Serialized;
import li.cil.oc2.common.bus.device.data.FileSystems;
@@ -12,6 +16,13 @@ import li.cil.sedna.device.rtc.SystemTimeRealTimeCounter;
import li.cil.sedna.device.serial.UART16550A;
import li.cil.sedna.device.virtio.VirtIOConsoleDevice;
import li.cil.sedna.device.virtio.VirtIOFileSystemDevice;
import li.cil.sedna.device.virtio.VirtIOBlockDevice;
import li.cil.oc2.common.bus.device.data.ResourceBlockDeviceData;
import li.cil.sedna.api.device.BlockDevice;
import li.cil.sedna.buildroot.Buildroot;
import java.io.InputStream;
import li.cil.sedna.device.block.ByteBufferBlockDevice;
import java.util.function.Function;
@@ -21,6 +32,8 @@ public final class BuiltinDevices {
public static final int RPC_INTERRUPT = 0x3;
private static final int UART_INTERRUPT = 0x4;
private static final int VFS_INTERRUPT = 0x5;
private static final int BFS_INTERRUPT = 0x6;
private static final int RFS_INTERRUPT = 0x7;
///////////////////////////////////////////////////////////////////
@@ -31,6 +44,8 @@ public final class BuiltinDevices {
@Serialized public final VirtIOConsoleDevice rpcSerialDevice;
@Serialized public final UART16550A uart;
@Serialized public final VirtIOFileSystemDevice vfs;
@Serialized public VirtIOBlockDevice bfs;
@Serialized public VirtIOBlockDevice rfs;
///////////////////////////////////////////////////////////////////
@@ -40,6 +55,21 @@ public final class BuiltinDevices {
rpcSerialDevice = initialize(context, new VirtIOConsoleDevice(context.getMemoryMap()), RPC_INTERRUPT, VirtIOConsoleDevice::getInterrupt);
uart = initialize(context, new UART16550A(), UART_INTERRUPT, UART16550A::getInterrupt);
vfs = initialize(context, new VirtIOFileSystemDevice(context.getMemoryMap(), "builtin", FileSystems.getLayeredFileSystem()), VFS_INTERRUPT, VirtIOFileSystemDevice::getInterrupt);
InputStream ris = Buildroot.getRootFilesystem();
try {
var bfsd = FileSystems.getBlockByName("bootfs");
if (bfsd != null) {
bfs = initialize(context, new VirtIOBlockDevice(context.getMemoryMap(), bfsd.getBlockDevice()), BFS_INTERRUPT, VirtIOBlockDevice::getInterrupt);
}
else {
bfs = null;
}
rfs = initialize(context, new VirtIOBlockDevice(context.getMemoryMap(), ByteBufferBlockDevice.createFromStream(ris, true)), RFS_INTERRUPT, VirtIOBlockDevice::getInterrupt);
}
catch(final IOException e) {
System.out.println("Failed to load lower block device");
}
}
///////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,6 @@
{
"name": "bootfs",
"type": "block",
"order": 1,
"location": "oc2:file_systems/bootfs.squashfs"
}

Binary file not shown.

View File

@@ -0,0 +1,6 @@
{
"name": "rootfs",
"type": "block",
"order": 1,
"location": "oc2:file_systems/rootfs.dsk"
}