Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mounting of file systems #6

Open
jhermsmeier opened this issue Jan 14, 2017 · 0 comments
Open

Support mounting of file systems #6

jhermsmeier opened this issue Jan 14, 2017 · 0 comments

Comments

@jhermsmeier
Copy link
Owner

jhermsmeier commented Jan 14, 2017

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 ) {
    // ...
  })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant