Giter Site home page Giter Site logo

node-disk's Introduction

Disk

npm npm license npm downloads build status stability

Install via npm

$ npm install --save disk

Related Modules

Internals:

Block Devices:

  • VHD – Microsoft Virtual Hard Disk format
  • UDIF – Apple's DMG / UDIF (Universal Disk Image Format)
  • UDF – OSTA Universal Disk Format

File Systems:

  • FAT32 – FAT32/16/12 file system driver
  • ExFAT – ExFAT file system driver
  • HFSX – Apple HFS+ file system driver
  • NTFS – NTFS file system driver

Usage

var Disk = require( 'disk' )

Set up a device to work with. This can be anything with a blockdevice compatible API.

var device = new BlockDevice({
  path: BlockDevice.getPath( 0 )
})

Create a disk:

var disk = new Disk( device )

Open the device:

// This also attempts to detect it's block size if unspecified,
// as well as reading the MBR & GPT on the device
disk.open( function( error ) {})

Read or write the MBR (disk.mbr) from or to the device:

disk.readMBR( function( error, mbr ) {})
disk.writeMBR( function( error ) {})

Read or write the GPT (disk.gpt) from or to the device:

disk.readGPT( function( error, gpt ) {})
disk.writeGPT( function( error ) {})

Verify the backup GPT; NOTE: The callback will be called with an error and the backup GPT if it doesn't verify.

disk.verifyGPT( function( error, backupGPT ) {})

Close the device:

disk.close( function( error ) {})

API

Disk

  • Disk.MBR: See mbr
  • Disk.GPT: See gpt

new Disk( device )

Properties:

  • device
  • mbr
  • gpt

Methods:

  • open( callback )
  • close( callback )
  • getEFIPart()
  • readMBR( callback )
  • writeMBR( callback )
  • readGPT( callback )
  • writeGPT( callback )
  • writeGPT( callback ): Not implemented

node-disk's People

Contributors

jhermsmeier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-disk's Issues

Read extended / logical partitions

Attempt to read extended / logical partitions when reading a MBRs partition table, and the partition type indicates an extended partition (i.e. partition type 0x0F).

Support partition resizing

Add methods to resize partitions:

  • Support resizing extended / logical partitions
  • Bounds check on device size
  • Methods to resize the underlying device, when the device is an image file rather than a physical device (should probably left to be done by user?)

Use dynamic VHD images for tests

Use vhd to model entire disks including backup GPTs, file system VBRs, etc. without having image files getting too large by using sparse / dynamic VHDs

Support mounting of file systems

Specify & consolidate an API that file system drivers would implement to make them interoperate with node-disk, so that file systems could be automatically detected & mounted.

Prototype API Example:

var BlockDevice = require('blockdevice')
var Disk = require('disk')
var NTFS = require('ntfs')
var HFS = require('hfsp')
var ExFAT = require('exfat')

// Create the block device
var device = new BlockDevice({
  path: BlockDevice.getPath( 0 ),
})

// Create the disk
var disk = new Disk( device )

// Add file systems to use for auto-mounting, middleware-style
disk.use( NTFS )
disk.use( HFS )

// Auto-mount known file systems
// Note: would also need to introduce options in `disk.open()`
disk.open({ mount: true }, function( error ) {
  // Note: Iteration should be async, but kept simple here for the sake of demonstration 
  disk.partitions.forEach( function( partition ) {
    if( partition.volume ) {
      // partition.volume = partition.fs.create( partition, options )
      partition.volume.fs.readdir( function( error, ls ) {
        // ...
      })
    }
  })
})

// Don't auto-mount; but create a volume for the partition
disk.open({ mount: false }, function( error ) {
  disk.partitions.forEach( function( partition ) {
    if( partition.volume ) {
      // Manually mount the volume
      partition.volume.mount( function( error, fs ) {
        // ...
      })
    }
  })
})

// Or manually mount a file system on a given partition
disk.mount( disk.partitions[1], ExFAT, function( error, volume ) {
  // partition.volume === volume
  volume.fs.readdir( '/', function( error, ls ) {
    // ...
  })
})

Error: Invalid file descriptor at BlockDevice._read

Hi, do you know what the problem based on this code?
i always get error while reading MBR.
Thanks

var device = new BlockDevice({
    path: BlockDevice.getPath( 1 ),
    mode: 'r+',
})


var disk = new Disk( device );
disk.open( function( error ) {
    if(error) {
        console.log(error);
    }
    else
        console.log(disk);
})

disk.readMBR( function( error, mbr ){
    if(error) {
        console.log(error);
    }
    else {
        console.log(mbr);
    }
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.