node-mount
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 = ;mount;
Mount DVD:
var mount = ;mount;
Mount ReadOnly+Remount (easy)
var mount = ;mount;
Mount ReadOnly+Remount (flags)
var mount = ;mount;
Umount after successful mount:
var mount = ;mount;
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:
API
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..)
mount.mount(source, target, fsType, [options], [dataStr], callback)
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.
mount.umount(target, callback)
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
mount.mountSync(source, target, fsType, [options], [dataStr])
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.
mount.umountSync(target)
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.
mount.unmount(target, callback)
This function is deprecated; please use mount.umount()
instead.
Alias of mount.umount()
mount.unmountSync(target)
This function is deprecated; please use mount.umountSync()
instead.
Alias of mount.umountSync()
mount.MS_*
Constants for easy mount
flags
bitmask manipulation.
TODO:
- umount2 - force force unmounting
Credits
- Directly forked from magicpat`s repository
- magicpat forked from Stackdot`s repository
- Stackdot forked this from Maciej Małecki`s repository