Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ await dataDevice.writeFile("/filename", "File content here");

## Block devices with ext2

CheerpX supports ext2 filesystems, which can be configured as an overlay device. This allows for a flexible setup that can combine different storage types.
CheerpX supports ext2 filesystems, which can be configured as an [`OverlayDevice`](/docs/reference/CheerpX.OverlayDevice). This allows for a flexible setup that can combine different storage types.

### Usage

Create an ext2 filesystem by combining a [`HttpBytesDevice`](/docs/reference/httpBytesDevice) to acess disk blocks, an [`IDBDevice`](/docs/reference/CheerpX.IDBDevice) to cache and persist data and a `OverlayDevice` to combine the two.
Create an ext2 filesystem by combining a [`HttpBytesDevice`](/docs/reference/httpBytesDevice) to acess disk blocks, an [`IDBDevice`](/docs/reference/CheerpX.IDBDevice) to cache and persist data and a [`OverlayDevice`](/docs/reference/CheerpX.OverlayDevice) to combine the two.

```javascript
// Create an HttpBytesDevice for streaming disk blocks via HTTP
Expand All @@ -215,7 +215,7 @@ CheerpX supports various types of devices that can be used in the OverlayDevice

1. [**HttpBytesDevice**](/docs/reference/httpBytesDevice): The default choice for loading filesystem images via HTTP. Suitable for most web-hosted files.
2. **GitHubDevice**: Ideal for projects forked from the [WebVM](https://github.com/leaningtech/webvm/) repository. The Integrated GitHub Action will take care of preparing disk chunks for efficient access.
3. **OverlayDevice**: `OverlayDevice` supports chaining, making it possible to efficiently "fork" disk images while only storing the changes from previous versions.
3. [**OverlayDevice**](/docs/reference/CheerpX.OverlayDevice): `OverlayDevice` supports chaining, making it possible to efficiently "fork" disk images while only storing the changes from previous versions.

## Best practices

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: create
description: Create a writable persistent overlay device on top of another block device.
---

```ts
namespace CheerpX {
class OverlayDevice {
static async create(
baseDevice: Device,
overlayDevice: Device
): Promise<OverlayDevice>;
}
}
```

## Parameters

- **baseDevice (`Device`)** - The underlying device (e.g., `HttpBytesDevice`, `IDBDevice`) that serves as the base layer for the filesystem.

- **overlayDevice (`Device`)** - The writable layer that will overlay the base device, enabling persistent changes.

## Returns

`CheerpX.OverlayDevice.create` returns a [Promise] that resolves to an instance of the `OverlayDevice`. The `OverlayDevice` allows you to overlay a writable layer on top of the base device, enabling persistent changes while still accessing the base data.

## Example

Create an `OverlayDevice` instance to combine a `HttpBytesDevice` for streaming data from an HTTP source and an `IDBDevice` for caching and persistent local storage.

```ts {8, 12}
// Create a read-only HttpBytesDevice for streaming disk blocks via HTTP
const httpDevice = await CheerpX.HttpBytesDevice.create("/cheerpXImage.ext2");

// Create an IDBDevice for local persistent storage
const idbDevice = await CheerpX.IDBDevice.create("block_idbDevice");

// Create an OverlayDevice to combine the two devices
const overlayDevice = await CheerpX.OverlayDevice.create(httpDevice, idbDevice);

// Mount the overlay device in the CheerpX environment as an ext2 filesystem
const cx = await CheerpX.Linux.create({
mounts: [{ type: "ext2", path: "/", dev: overlayDevice }],
});
```

In this example, the `OverlayDevice` provides a writable layer on top of the `HttpBytesDevice` (which serves as a read-only block device for streaming), allowing changes to be stored locally via the `IDBDevice`.

## Related sources

- [CheerpX.HttpBytesDevice](/docs/reference/httpBytesDevice)
- [CheerpX.IDBDevice](/docs/reference/CheerpX.IDBDevice)
- [CheerpX.Linux](/docs/reference/CheerpX.Linux)

For more information, please check out the [Files and File system guide](/docs/guides/File-System-support). This guide provides more details on how to work with files and directories in CheerpX.

[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise