Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ext2fs

balena-io48.3kApache-2.04.2.5

WASM bindings to libext2fs for cross-platform ext filesystem handling

extfs, ext, ext2, ext3, ext4, filesystem, fs

readme

node-ext2fs

WASM bindings to the linux ext{2,3,4} filesystem library

node-ext2fs uses the e2fsprogs project to provide access to ext filesystem from javascript. It is a WebAssembly module built with emscripten.

Some things you can do with this module:

  • Read/write files in a filesystem image directly without mounting
  • Use familiar APIs, node-ext2fs has the exact same interface as node's fs module
  • Combine node-ext2fs filesystem streams with host filesystem streams (e.g copy files)
  • Create a tar archive from a filesystem image
  • Perform a TRIM operation to obtain discard regions of a filesystem

Installation

Simply install node-ext2fs using npm:

$ npm install ext2fs

Development

Just run:

$ cd ./node-ext2fs
$ npm install

If installation fails due to missing executables, see ./install-toolchain.sh for help on installing the toolchain.

Usage

Mount a disk image and use the returned fs object. The fs returned object behaves like node's fs except it doesn't provide any xxxxSync method. You can also issue DISCARD requests using the fs async trim() method.

See the example below.

Example

const { withMountedDisk } = require('ext2fs');
const { FileDisk, withOpenFile } = require('file-disk');

async function main() {
  const diskImage = '/some/disk.image';
  const offset = 272629760;  // offset of the ext partition you want to mount in that disk image
  try {
    await withOpenFile(diskImage, 'r', async (handle) => {
      const disk = new FileDisk(handle);
      await withMountedDisk(disk, offset, async ({promises:fs}) => {
        // List files
        console.log('readdir', await fs.readdir('/'));
        await fs.trim();
        // Show discarded regions
        console.log('discarded', disk.getDiscardedChunks());
        // Show ranges of useful data aligned to 1MiB
        console.log('ranges', await disk.getRanges(1024 ** 2));
      });
    });
  } catch (error) {
    console.error(error);
  }
}

Building

  • Prerequisites
    • git
    • make
    • NodeJS >=v12

Enter that directory

cd emsdk

Download and install the latest SDK tools.

./emsdk install latest

Make the "latest" SDK "active" for the current user. (writes .emscripten file)

./emsdk activate latest

Activate PATH and other environment variables in the current terminal

source ./emsdk_env.sh


- Clone recursively

You must clone recursively in order to get the dependency

git clone --recursive https://github.com/balena-io-modules/node-ext2fs


- Build

cd node-ext2fs npm i npm run build `

Support

If you're having any problems, please raise an issue on GitHub.

License

node-ext2fs is free software, and may be redistributed under the terms specified in the license.

changelog

Change Log

All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to Semantic Versioning.

v4.2.5

(2025-03-25)

  • Update dependency mocha to v11 [balena-renovate[bot]]

v4.2.4

(2025-02-20)

  • Fix fs.stat for large file sizes [Ryan Cooke]

v4.2.3

(2023-12-19)

  • Remove repo config from flowzone.yml [Kyle Harding]

v4.2.2

(2023-08-29)

  • Update dependency prettier to v3 [Self-hosted Renovate Bot]

v4.2.1

(2023-01-20)

  • Fix packaging [Akis Kesoglou]

v4.2.0

(2023-01-20)

  • Pin emscripten toolchain version [Akis Kesoglou]
  • Add support for Node 18 [Akis Kesoglou]

v4.1.7

(2023-01-05)

  • Generate version [ab77]
  • Update dependencies [ab77]

v4.1.6

(2022-12-28)

  • Update dependency mocha to 10.2.0 [Renovate Bot]

v4.1.5

(2022-12-28)

  • Update dependency eslint to 8.30.0 [Renovate Bot]

v4.1.4

(2022-12-28)

  • Add missing condition [ab77]

v4.1.3

(2022-12-28)

  • change functions to use async directly instead of asyncify [Zane Hitchcox]

v4.1.2

(2022-12-28)

  • switch to flowzone [Zane Hitchcox]

v4.1.1

(2022-07-22)

  • Fixed memory leak in js_zeroout_entry [Simon Kadisch]

v4.1.0

(2022-07-18)

  • Fix breaking change with promises [Zane Hitchcox]

v4.0.1

(2022-07-17)

  • support node 12 [Zane Hitchcox]

v4.0.0

(2022-07-17)

  • Add fsPromises to API [Zane Hitchcox]

v3.1.1

(2022-07-07)

  • add lstat support [Zane Hitchcox]

v3.1.0

(2022-06-14)

  • add symlink support [Zane Hitchcox]

v3.0.5

(2020-12-02)

  • Fix reading and discarding with offsets > 32 bits [Alexis Svinartchouk]

v3.0.4

(2020-11-26)

  • Add versionbot changelog [Alexis Svinartchouk]

v3.0.3

(2020-11-05)

  • Nothing [Alexis Svinartchouk]

v3.0.2

(2020-11-05)

  • Nothing [Alexis Svinartchouk]

v3.0.1

(2020-11-05)

  • Nothing [Alexis Svinartchouk]

v3.0.0

(2020-11-05)

  • Use a pool for object ids [Alexis Svinartchouk]
  • Remove unused parts of fs.js [Alexis Svinartchouk]
  • Update mocha to ^8.2.1 [Alexis Svinartchouk]
  • Remove trailing slashes in paths + test [Alexis Svinartchouk]
  • Test mounting partition at an offset [Alexis Svinartchouk]
  • Test that disk errors are bubbling up [Alexis Svinartchouk]
  • Use async/await in tests [Alexis Svinartchouk]
  • Test removing a file in a directory [Alexis Svinartchouk]
  • Build with emscripten instead of a native node module [Alexis Svinartchouk]

v2.0.5

(2020-09-14)

  • Put libext2fs.a in $(ARCH) named folder [Alexis Svinartchouk]

v2.0.4

(2020-09-01)

  • Detect host arch if no target arch is given on Windows [Alexis Svinartchouk]

v2.0.3

(2020-09-01)

  • Fix compiling for 32bit Windows on 64bit Windows [Alexis Svinartchouk]

v2.0.2

(2020-08-28)

  • Update example in the README [Alexis Svinartchouk]

v2.0.1

(2020-07-31)

  • Remove async dependency [Alexis Svinartchouk]

v2.0.0

(2020-07-27)

  • Update eslint to ^7.5.0 [Alexis Svinartchouk]
  • Update file-disk to ^8, bluebird is only a dev dependency [Alexis Svinartchouk]

1.0.31 - 2019-12-04

  • Fix build for electron7 [Alexis Svinartchouk]
  • Update nan to ^2.14 [Alexis Svinartchouk]

1.0.30 - 2019-10-17

  • Ext2fs: patch ext2fs.h for glibc 2.30 compatibility [Matthew McGinn]

1.0.29 - 2019-06-08

  • Add config for armv7l [Alexis Svinartchouk]

1.0.28 - 2019-05-02

  • Update interface for node 12 interface changes [Gergely Imreh]

1.0.27 - 2019-03-01

  • Add config for arm64 [Alexis Svinartchouk]

1.0.26 - 2019-01-28

  • Add arm config for native builds [Theodor Gherzan]

1.0.25 - 2019-01-25

  • Fix build on latest xcode [Alexis Svinartchouk]

1.0.24 - 2018-12-18

  • Pin nan to 2.11.1 to avoid a build issue on node 10.4 [Alexis Svinartchouk]

1.0.23 - 2018-11-29

  • Disable use of secure_getenv on linux x64 systems [Alexis Svinartchouk]
  • Update file-disk to 5.0.0 and make it a devDependency [Alexis Svinartchouk]

1.0.22 - 2018-11-20

  • Fix organization name in travis.yml [Alexis Svinartchouk]

1.0.21 - 2018-11-19

  • Rename resin -> balena [Alexis Svinartchouk]
  • Update requirements [Alexis Svinartchouk]

1.0.20 - 2018-11-14

  • Disable use of secure_getenv on linux ia32 systems [Alexis Svinartchouk]

1.0.19 - 2018-11-14

  • Fix unresolved symbol ext2fs_open_file [Alexis Svinartchouk]

v1.0.18 - 2018-10-24

  • Stop building for now-unsupported node 7 & 9, add node 11 [Tim Perry]
  • Pin windows build tools to a version that works with Node 6 [Tim Perry]
  • Build for Windows with VS 2017 to hopefully fix deploys [Tim Perry]

v1.0.17 - 2018-10-02

  • Fix integer overflow [Theodor Gherzan]

v1.0.16 - 2018-10-02

  • Fix(publish) Fix publish on resinCI [Alexis Svinartchouk]

v1.0.15 - 2018-08-07

  • Fix(build) Fix the build on ia32 #45 [Alexis Svinartchouk]

v1.0.14 - 2018-08-03

  • Add x86 config for GNU/Linux #29 [Juan Cruz Viotti]

v1.0.13 - 2018-07-16

  • Fix(package): Add upload-electron-win script #40 [Jonas Hermsmeier]

v1.0.12 - 2018-07-13

  • Fix(package): Fix prebuild include-regex argument on Windows #39 [Jonas Hermsmeier]

v1.0.11 - 2018-07-13

  • Fix(bindings): Fix 64bit -> 32bit casts in fs.stat #36 [Jonas Hermsmeier]

v1.0.10 - 2018-07-13

  • Fix(appveyor): Fix batch condition for electron prebuilds #38 [Jonas Hermsmeier]

v1.0.9 - 2018-07-10

  • Fix(ci): Fix cross-env not converting lowercase var #33 [Jonas Hermsmeier]

v1.0.8 - 2018-07-10

  • Chore(package): Prebuild against Electron runtime #32 [Jonas Hermsmeier]

v1.0.7 - 2018-05-24

  • Handle all request types in DiskWrapper.request. #28 [Alexis Svinartchouk]
  • Fix some deprecation warnings in node_ext2fs.cc #28 [Alexis Svinartchouk]
  • Bluebird is a dependency, not a dev dependency #28 [Alexis Svinartchouk]

v1.0.6 - 2018-04-30

  • Build, test & release for node 10 #27 [Tim Perry]

v1.0.5 - 2018-04-27

  • Move eslint to dev dependencies #25 [Tim Perry]

v1.0.4 - 2018-04-25

  • Use fs's blocksize instead of hardcoded 1024 in ReadDirWorker #24 [Alexis Svinartchouk]

v1.0.3 - 2018-03-30

  • Only include the bindings.node file in prebuilds #21 [Alexis Svinartchouk]

v1.0.2 - 2018-03-30

  • Use cross-env so the upload script works on windows #19 [Alexis Svinartchouk]
  • Replace node-pre-gyp with prebuild #19 [Alexis Svinartchouk]

v1.0.1 - 2018-03-28

  • Update node-pre-gyp to 0.9.0 #17 [Alexis Svinartchouk]

v1.0.0 - 2018-03-27

  • Update file-disk to ^4.1.1 #15 [Alexis Svinartchouk]
  • Update e2fsprogs to v1.44.1 #15 [Alexis Svinartchouk]

v0.1.1 - 2017-11-21

  • Ensure pre-gyp releases use the existing versionbot tag (not a new one) #13 [Tim Perry]

v0.1.0 - 2017-11-21

  • Add clock_gettime implementation so this works on OSX < 10.11 #11 [Tim Perry]
  • Automatically release built binaries to github for pre-gyp #11 [Tim Perry]
  • Use pre-gyp-github to automatically install prebuilt binaries when available #11 [Tim Perry]
  • Add a changelog so we can set up versionbot #11 [Tim Perry]
  • Add Windows tests with appveyor #11 [Tim Perry]
  • Update e2fsprogs #11 [Tim Perry]

v0.0.15 - 2017-11-02

  • Capable of mounting and using a real ext filesystem