Package detail

partitioninfo

balena-io-modules36.2kMIT6.0.3

Get information about a partition from an image file

partition, image, information, info

readme

partitioninfo

Get information about a partition from an image file.

npm version dependencies Build Status

Installation

Install partitioninfo by running:

$ npm install --save partitioninfo

Documentation

partitioninfo~get(image, number) ⇒ Promise.<Object>

Kind: inner method of partitioninfo
Summary: Get information from a partition
Returns: Promise.<Object> - partition information
Access: public

Param Type Description
image String \ Buffer \ filedisk.Disk image path or buffer or filedisk.Disk instance
number Object partition number

Example

partitioninfo.get('foo/bar.img', 5)
.then (information) ->
    console.log(information.offset)
    console.log(information.size)
    console.log(information.type)
    console.log(information.index)

partitioninfo~getPartitions(image, options) ⇒ Promise.<Object>

getPartitions() returns an Array. getPartitions(image)[N - 1] may not be equal to get(image, N) For example on a disk with no primary partitions and one extended partition containing a logical one, getPartitions(image) would return an array of 2 partitions (the extended then the logical one), get(image, 1) would return the extended partition and get(image, 5) would return the logical partition. All other numbers would throw an error. Partition numbers for get(image, N) are like Linux's /dev/sdaN.

The array returned by getPartitions() contains primary (or extended) partitions first then the logical ones. This is true even if the extended partition is not the last one of the disk image. Order will always be 1, [2, 3, 4, 5, 6, 7] even if the logical partitions 5, 6 and 7 are physically contained in partiton 1, 2 or 3.

Kind: inner method of partitioninfo
Summary: Read all partition tables from a disk image recursively.
Returns: Promise.<Object> - partitions information
Throws:

  • Error if there is no such partition

Access: public

Param Type Default Description
image String \ Buffer \ filedisk.Disk image path or buffer or filedisk.Disk instance
options Object
[options.offset] Number 0 where the first partition table will be read from, in bytes
[options.includeExtended] Boolean true whether to include extended partitions or not (only for MBR partition tables)
[options.getLogical] Boolean true whether to include logical partitions or not (only for MBR partition tables)

Example

partitioninfo.getPartitions('foo/bar.img')
.then (information) ->
    console.log(information.type)
    for partition in information.partitions
        console.log(partition.offset)
        console.log(partition.size)
        console.log(partition.type)
        console.log(partition.index)

Support

If you're having any problem, please raise an issue on GitHub and the balena.io team will be happy to help.

Tests

Run the test suite by doing:

$ npm test

Contribute

Before submitting a PR, please make sure that you include tests, and that balena-lint runs without any warning:

$ npm run lint

License

The project is licensed under the MIT 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.

6.0.3 - 2022-05-16

  • Update dev dependencies [Zane Hitchcox]

6.0.2 - 2020-11-27

<summary> Update file-disk from 8.0.0 to 8.0.1 [Alexis Svinartchouk] </summary> > ### file-disk-8.0.1 - 2020-11-26 > > * Add versionbot changelog [Alexis Svinartchouk] >
  • Add versionbot changelog [Alexis Svinartchouk]

v6.0.1

(2020-07-27)

  • Nothing [Alexis Svinartchouk]
  • Resin.io -> balena.io [Alexis Svinartchouk]
  • Remove bluebird dependency, update file-disk [Alexis Svinartchouk]

v6.0.0

(2020-07-24)

  • Target es2018 [Alexis Svinartchouk]
  • Update file-disk to ^7.0.1 [Alexis Svinartchouk]

v5.3.6

(2020-07-14)

  • Don't version generated files [Alexis Svinartchouk]
  • Use tslib [Alexis Svinartchouk]
  • Use strict typescript flag [Alexis Svinartchouk]
  • Update dependencies [Alexis Svinartchouk]

v5.3.5

(2020-06-22)

  • Run travis tests with node 10 and 12 [Alexis Svinartchouk]
  • Remove appveyor link [Alexis Svinartchouk]
  • Remove gitter link [Alexis Svinartchouk]
  • Rename resin -> balena [Alexis Svinartchouk]
  • Update resin-lint to @balena/lint [Alexis Svinartchouk]
  • Fix GPT detection when the protective MBR has more than one partition [Alexis Svinartchouk]
  • Add @types/bluebird to dev dependencies [Alexis Svinartchouk]

5.3.4 - 2019-04-17

  • Switch back to the original node-gpt [Alexis Svinartchouk]

5.3.3 - 2019-04-16

  • Use balena-io-module's node-gpt [Alexis Svinartchouk]

5.3.2 - 2019-04-04

  • Update file-disk to ^6.0.0 [Alexis Svinartchouk]
  • Update README [Alexis Svinartchouk]

5.3.1 - 2019-03-21

  • Update resin-lint to ^3.0.1 [Alexis Svinartchouk]

5.3.0 - 2019-01-16

  • Include guid and name for gpt partitions [Alexis Svinartchouk]

5.2.0 - 2019-01-14

  • Detect gpt partition tables at different offsets [Alexis Svinartchouk]

5.1.0 - 2018-12-21

  • Get and getPartitions now accept Buffers as first parameter [Alexis Svinartchouk]

5.0.0 - 2018-12-21

  • Switch to typescript [Alexis Svinartchouk]

4.0.3 - 2018-11-29

  • Change licence to Apache 2 [Alexis Svinartchouk]
  • Update file-disk to 5.0.0 [Alexis Svinartchouk]

v4.0.2 - 2018-07-06

  • Update node-mbr to 1.1.3 #34 [Alexis Svinartchouk]

v4.0.1 - 2018-06-08

  • Update gpt to 2.0.0 #33 [Alexis Svinartchouk]

v4.0.0 - 2018-03-27

  • Only test with node 6 and 8 #32 [Alexis Svinartchouk]
  • Update file-disk to v4.1.1 #32 [Alexis Svinartchouk]
  • Lint with resin-lint, don't publish .coffee files #32 [Alexis Svinartchouk]

v3.0.1 - 2018-02-09

  • Fix get(disk, index) for logical partitions that are inside an extended partition with LBA #30 [Alexis Svinartchouk]

v3.0.0 - 2017-10-10

  • Support GPT partition tables #28 [Alexis Svinartchouk]

v2.2.1 - 2017-10-09

  • Update built js files and README #27 [Alexis Svinartchouk]

v2.2.0 - 2017-10-09

  • Add index property to each returned partition #24 [Alexis Svinartchouk]

v2.1.0 - 2017-07-25

Added

  • getPartitions now accepts an optional includeExtended argument (default true)

Changed

  • Fixed get() and getPartitions() behaviour when the extended partition is not the last one

v2.0.1 - 2017-06-23

Changed

  • Updated file-disk to ^1.0.1

v2.0.0 - 2017-06-19

Changed

  • Use the partition number instead of {primary: X, logical: Y}, like Linux's /dev/sdaX

v1.3.0 - 2017-06-09

Changed

  • Fix logical partitions listing.

v1.2.0 - 2017-06-02

Changed

  • Accept filedisk.Disk instances as well as file paths.
  • partitioninfo.get result includes the partition type.

v1.1.1 - 2015-04-10

Changed

  • Remove unnecessary write fs open flag.

v1.1.0 - 2015-04-04

Added

  • Implement .getPartitions().

v1.0.2 - 2015-11-24

Changed

  • Upgrade tmp to v0.0.28.

v1.0.1 - 2015-07-27

Changed

  • Add lodash to the dependencies list.