Skip to content

Commit 833c5db

Browse files
authored
CX overlayDevice reference added (#220)
1 parent e224fae commit 833c5db

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

sites/cheerpx/src/content/docs/11-guides/File-System-support.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ await dataDevice.writeFile("/filename", "File content here");
185185

186186
## Block devices with ext2
187187

188-
CheerpX supports ext2 filesystems, which can be configured as an overlay device. This allows for a flexible setup that can combine different storage types.
188+
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.
189189

190190
### Usage
191191

192-
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.
192+
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.
193193

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

216216
1. [**HttpBytesDevice**](/docs/reference/httpBytesDevice): The default choice for loading filesystem images via HTTP. Suitable for most web-hosted files.
217217
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.
218-
3. **OverlayDevice**: `OverlayDevice` supports chaining, making it possible to efficiently "fork" disk images while only storing the changes from previous versions.
218+
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.
219219

220220
## Best practices
221221

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: create
3+
description: Create a writable persistent overlay device on top of another block device.
4+
---
5+
6+
```ts
7+
namespace CheerpX {
8+
class OverlayDevice {
9+
static async create(
10+
baseDevice: Device,
11+
overlayDevice: Device
12+
): Promise<OverlayDevice>;
13+
}
14+
}
15+
```
16+
17+
## Parameters
18+
19+
- **baseDevice (`Device`)** - The underlying device (e.g., [`HttpBytesDevice`](/docs/reference/httpBytesDevice), [`IDBDevice`](/docs/reference/CheerpX.IDBDevice)) that serves as the base layer for the filesystem.
20+
21+
- **overlayDevice (`Device`)** - The writable layer that will overlay the base device, enabling persistent changes.
22+
23+
## Returns
24+
25+
`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.
26+
27+
## Example
28+
29+
Create an `OverlayDevice` instance to combine a [`HttpBytesDevice`](/docs/reference/httpBytesDevice) for streaming data from an HTTP source and an [`IDBDevice`](/docs/reference/CheerpX.IDBDevice) for caching and persistent local storage.
30+
31+
```ts {8, 12}
32+
// Create a read-only HttpBytesDevice for streaming disk blocks via HTTP
33+
const httpDevice = await CheerpX.HttpBytesDevice.create("/cheerpXImage.ext2");
34+
35+
// Create an IDBDevice for local persistent storage
36+
const idbDevice = await CheerpX.IDBDevice.create("block_idbDevice");
37+
38+
// Create an OverlayDevice to combine the two devices
39+
const overlayDevice = await CheerpX.OverlayDevice.create(httpDevice, idbDevice);
40+
41+
// Mount the overlay device in the CheerpX environment as an ext2 filesystem
42+
const cx = await CheerpX.Linux.create({
43+
mounts: [{ type: "ext2", path: "/", dev: overlayDevice }],
44+
});
45+
```
46+
47+
In this example, the `OverlayDevice` provides a writable layer on top of the [`HttpBytesDevice`](/docs/reference/httpBytesDevice) (which serves as a read-only block device for streaming), allowing changes to be stored locally via the [`IDBDevice`](/docs/reference/CheerpX.IDBDevice).
48+
49+
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.
50+
51+
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

0 commit comments

Comments
 (0)