node-disk icon indicating copy to clipboard operation
node-disk copied to clipboard

Support mounting of file systems

Open jhermsmeier opened this issue 9 years ago • 0 comments

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 ) {
    // ...
  })
})

jhermsmeier avatar Jan 14 '17 17:01 jhermsmeier