losetup
Losetup library for node.js.
Allows attaching, detaching, and listing loop devices in a Linux system.
Installation
$ npm install losetup
Documentation
- losetup.LoopDevice
- losetup.errors
- losetup.isLoopDevice(path)
- losetup.getLoopDevice(path)
- losetup.listAll(path = "/dev")
- losetup.listUsed(path = "/dev")
- losetup.findUnused(path = "/dev/")
- losetup.attach(loopDevice, path, opts = {})
- losetup.detach(loopDevice)
- losetup.reloadPartitionTable(loopDevice)
losetup.LoopDevice(path, isUsed, device, inode, fileName)
Class describing a loop device.
Properties:
losetup.errors
Contains all the exported error classes:
- LosetupError: All errors inherit from this class.
- NotLoopDeviceError: The device is not a loop device.
- LoopDeviceBusyError: The device is busy (already attached).
- LoopDeviceNotUsedError: The device was expected to be attached, but isn't.
- LoopDeviceNotFoundError: The device does not exist at all.
losetup.isLoopDevice(String path) => Promise Boolean
Promise resolves to true if path is a loop device.
losetup.getLoopDevice(String path) => Promise LoopDevice
Resolves to a LoopDevice describing the device in path.
losetup.listAll(String path = "/dev") => Promise [LoopDevice]
Resolves to a list of LoopDevice for all the loop devices in path.
losetup.listUsed(String path = "/dev") => Promise [LoopDevice]
List all the loop devices in path that are currently attached to a file.
losetup.findUnused(String path = "/dev") => Promise LoopDevice
Finds the first loop device in path that is currently not used.
losetup.attach(LoopDevice dev, String path, Object opts = {}) => Promise LoopDevice
Attaches the loop device dev to the file in path.
Result promise resolves to an updated loop device description. Does not alter the input object.
The third argument defines additional options:
- partscan: Enable partition scanning on device. Boolean, defaults to false.
- offset: Attach to an offset in the file, in bytes. Number, defaults to 0.
losetup.detach(LoopDevice dev) => Promise LoopDevice
Detaches any files from loop device dev.
Result promise resolves to an updated loop device description. Does not alter the input object.
losetup.reloadPartitionTable(LoopDevice dev) => Promise
Forces the operating system to reload partition table for device.
Uses BLKRRPART ioctl command.
If device /dev/loopX is a disk with many partitions, then after calling this function, the operating system will create /dev/loopXpY for each partition of the disk.
To make sure the operating system will scan the partition table, attach the device with partscan option enabled.
Support
If you're having any problem, please raise an issue on GitHub.
Contribute
- Issue Tracker: github.com/abresas/losetup-js/issues
- Source Code: github.com/abresas/losetup-js
License
The project is licensed under the Apache License 2.0.