Mount/umount devices from node.js
Really works on linux, may work on OS X, and will never work on windows.
##Examples Mount Tmpfs:
var mount = require("mount");
mount.mount('tmpDir', 'tmpfs', function(err) {
if(err){
return;
}
// Tmpfs mounted successfully
});
Mount DVD:
var mount = require("mount");
mount.mount('myDir', 'iso9660', {devFile: '/dev/sr0'}, function(err) {
if(err){
return;
}
//
});
Mount ReadOnly+Remount (easy)
var mount = require("mount");
mount.mount('tmpdir', 'tmpfs', ['remount', 'readonly'], function(err) {
if(err){
return;
}
//
});
Mount ReadOnly+Remount (flags)
var mount = require("mount");
mount.mount('tmpdir', 'tmpfs', mount.MS_REMOUNT | mount.MS_RDONLY,
function(err) {
if(err){
return;
}
//
});
Umount after successful mount:
var mount = requrie("mount");
mount.umount('myDir', function(err) {
if(err){
console.log("Umount went wrong: " + err);
return;
}
//
});
##Installation This package is not featured in NPM (yet), so you have to add this dependency line to your package.json file:
Part of package.json:
{
"name" : "myproject",
"version" : "1.0",
...
...
"dependencies" : {
"mount" : "git+ssh://[email protected]:hertzg/node-mount.git"
}
}
This module provides functionality to mount and unmount devices to and from specific targets. Module exports asynchronous and synchronous variants.
Most of the explanations here are from mount(2)
and umount(2)
WARNING: Using synchronous methods may block the process for along time. (ex: Mounting scratched CD/DVD/BD, Network shares.. etc..)
Attaches the file system specified by source
(which is often a device name,
but can also be a directory name or a dummy) to the directory specified by
target
.
Appropriate privilege is required to mount file systems.
target
-{String}
- Directory to mount the device to.fsType
-{String}
- Filesystem identificator (one of /proc/filesystems).options
-{Array}|{Number}
- Number describing mount flags or an Array containing String options described below:bind
- Perform a bind mount, making a file or a directory subtree visible at another point within a file system. Bind mounts may cross file system boundaries and span chroot(2) jails. Thefstype
anddataStr
arguments are ignored.readonly
- Mount file system read-only.remount
- Remount an existing mount. This allows you to change theoptions
anddataStr
of an existing mount without having to unmount and remount the file system.target
should be the same value specified in the initialmount()
call;source
andfsType
are ignored.noexec
- Do not allow programs to be executed from this file system.
dataStr
- Thedata
argument is interpreted by the different file systems. Typically it is a string of comma-separated options or an options bag understood by this file system.devFile
option can be used to define the Device-File being mounted (located in /dev).callback
- Function called after the mount operation finishes. Receives only one argumenterr
.err
- Isnull
if mount succeeded orError
object similar to ones generated byfs
module in case of failure.
Values for the fstype
argument supported by the kernel are listed in
/proc/filesystems
(e.g., "minix", "ext2", "ext3", "jfs", "xfs", "reiserfs",
"msdos", "proc", "nfs", "iso9660"). It can be auto
, too.
Removes the attachment of the (topmost) file system mounted on target
.
Appropriate privilege is required to unmount file systems.
target
-{String}
- Directory to unmount.callback
- Function called after the mount operation finishes. Receives only one argumenterr
.err
-null
if umount succeeded orError
object similar to ones generated byfs
module in case of failure.
Returns undefined
Synchronous variant of mount.mount()
Returns: true
if mount succeeded or throws Error
object similar to ones
generated by fs
module in case of failure.
Synchronous variant of mount.umount()
Returns: true
if umount succeeded or throws Error
object similar to ones
generated by fs
module in case of failure.
This function is deprecated; please use mount.umount()
instead.
Alias of mount.umount()
This function is deprecated; please use mount.umountSync()
instead.
Alias of mount.umountSync()
Constants for easy mount
flags
bitmask manipulation.
- umount2 - force force unmounting
- Directly forked from magicpat`s repository
- magicpat forked from Stackdot`s repository
- Stackdot forked this from Maciej Małecki`s repository