@@ -4,12 +4,17 @@ const bindings = require('bindings')('bindings');
44const binding = require ( './binding' ) ;
55
66const queue = require ( './queue' ) ;
7+ const constants = require ( './constants' ) ;
78
89const lkl = exports ;
910
1011lkl . fs = require ( './fs' ) ;
1112lkl . disk = require ( './disk' ) ;
1213
14+ const SUPPORTED_FILESYSTEMS = [ // TODO: get this list from lkl
15+ 'ext4' , 'ext3' , 'ext2' , 'btrfs' , 'xfs' , 'vfat'
16+ ] ;
17+
1318lkl . startKernelSync = function ( memory ) {
1419 bindings . startKernel ( memory ) ;
1520 binding . clock_settime ( null , function ( ) { } ) ;
@@ -39,6 +44,35 @@ function mount(diskId, opts, callback) {
3944 ) ;
4045}
4146
47+ function mountGuessFS ( disk , opts , callback , fsIndex ) {
48+ fsIndex = ( fsIndex === undefined ) ? 0 : fsIndex ;
49+ opts . filesystem = SUPPORTED_FILESYSTEMS [ fsIndex ] ;
50+ mount ( disk , opts , function ( err , mountpoint ) {
51+ if ( err ) {
52+ if (
53+ ( err . errno === constants . EINVAL ) &&
54+ ( fsIndex < SUPPORTED_FILESYSTEMS . length - 1 )
55+ ) {
56+ return mountGuessFS ( disk , opts , callback , fsIndex + 1 )
57+ }
58+ return callback ( err ) ;
59+ }
60+ return callback ( null , mountpoint ) ;
61+ } )
62+ } ;
63+
64+ lkl . mount = function ( disk , opts , callback ) {
65+ if ( ( callback === undefined ) && ( typeof opts === 'function' ) ) {
66+ callback = opts ;
67+ opts = { } ;
68+ }
69+ if ( SUPPORTED_FILESYSTEMS . indexOf ( opts . filesystem ) !== - 1 ) {
70+ queue . addOperation ( mount , [ disk , opts , callback ] ) ;
71+ } else {
72+ queue . addOperation ( mountGuessFS , [ disk , opts , callback ] ) ;
73+ }
74+ }
75+
4276function umount ( mountpoint , callback ) {
4377 const info = mounts [ mountpoint ] ;
4478 bindings . umount ( info . diskId , info . partition , function ( err ) {
@@ -50,6 +84,10 @@ function umount(mountpoint, callback) {
5084 } ) ;
5185}
5286
87+ lkl . umount = function ( mountpoint , callback ) {
88+ queue . addOperation ( umount , [ mountpoint , callback ] ) ;
89+ } ;
90+
5391lkl . diskAdd = function ( disk , callback ) {
5492 queue . addOperation (
5593 bindings . disk_add ,
@@ -61,12 +99,4 @@ lkl.diskRemove = function(diskId, callback) {
6199 queue . addOperation ( bindings . disk_remove , [ diskId , callback ] ) ;
62100} ;
63101
64- lkl . mount = function ( diskId , opts , callback ) {
65- queue . addOperation ( mount , [ diskId , opts , callback ] ) ;
66- } ;
67-
68- lkl . umount = function ( mountpoint , callback ) {
69- queue . addOperation ( umount , [ mountpoint , callback ] ) ;
70- } ;
71-
72102lkl . utils = require ( './utils' ) ;
0 commit comments