partitioninfo
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,14 +0,13 @@ | ||
var MBR, Promise, _, bootRecord, getPartitions, partition; | ||
var BOOT_RECORD_SIZE, MBR, Promise, _, callWithDisk, filedisk, get, getLogicalPartitions, getPartitionFromList, getPartitions, getPartitionsFromMBRBuf, partitionDict, readMbr, | ||
slice = [].slice; | ||
Promise = require('bluebird'); | ||
_ = require('lodash'); | ||
filedisk = require('file-disk'); | ||
MBR = require('mbr'); | ||
partition = require('./partition'); | ||
Promise = require('bluebird'); | ||
bootRecord = require('./boot-record'); | ||
/** | ||
@@ -18,3 +17,114 @@ * @module partitioninfo | ||
BOOT_RECORD_SIZE = 512; | ||
partitionDict = function(p, offset) { | ||
return { | ||
offset: offset + p.byteOffset(), | ||
size: p.byteSize(), | ||
type: p.type | ||
}; | ||
}; | ||
getPartitionsFromMBRBuf = function(buf) { | ||
return (new MBR(buf)).partitions.filter(_.property('type')); | ||
}; | ||
readMbr = function(disk, offset) { | ||
var buf; | ||
buf = Buffer.allocUnsafe(BOOT_RECORD_SIZE); | ||
return disk.readAsync(buf, 0, BOOT_RECORD_SIZE, offset)["return"](buf); | ||
}; | ||
getLogicalPartitions = function(disk, offset, extendedPartitionOffset, limit) { | ||
var result; | ||
if (extendedPartitionOffset == null) { | ||
extendedPartitionOffset = offset; | ||
} | ||
if (limit == null) { | ||
limit = 2e308; | ||
} | ||
result = []; | ||
return readMbr(disk, offset).then(function(buf) { | ||
var i, len, logicalPartitionsPromise, p, ref; | ||
ref = getPartitionsFromMBRBuf(buf); | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
p = ref[i]; | ||
if (!MBR.Partition.isExtended(p.type)) { | ||
result.push(partitionDict(p, offset)); | ||
} else if (limit > 0) { | ||
logicalPartitionsPromise = getLogicalPartitions(disk, extendedPartitionOffset + p.byteOffset(), extendedPartitionOffset, limit - 1); | ||
return logicalPartitionsPromise.then(function(logicalPartitions) { | ||
result.push.apply(result, logicalPartitions); | ||
return result; | ||
}); | ||
} | ||
} | ||
return result; | ||
}); | ||
}; | ||
getPartitions = function(disk, offset, getLogical) { | ||
var result; | ||
if (getLogical == null) { | ||
getLogical = true; | ||
} | ||
disk = Promise.promisifyAll(disk); | ||
result = []; | ||
return readMbr(disk, offset).then(function(buf) { | ||
var i, len, p, ref; | ||
ref = getPartitionsFromMBRBuf(buf); | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
p = ref[i]; | ||
result.push(partitionDict(p, offset)); | ||
if (MBR.Partition.isExtended(p.type) && getLogical) { | ||
return getLogicalPartitions(disk, p.byteOffset()).then(function(logicalPartitions) { | ||
result.push.apply(result, logicalPartitions); | ||
return result; | ||
}); | ||
} | ||
} | ||
return result; | ||
}); | ||
}; | ||
getPartitionFromList = function(partitions, number) { | ||
var partition; | ||
partition = partitions[number - 1]; | ||
if (!partition) { | ||
throw new Error("Partition not found: " + number + "."); | ||
} | ||
return partition; | ||
}; | ||
get = function(disk, definition) { | ||
return getPartitions(disk, 0, false).then(function(partitions) { | ||
var primary; | ||
primary = getPartitionFromList(partitions, definition.primary); | ||
if (!definition.logical) { | ||
return primary; | ||
} else if (!MBR.Partition.isExtended(primary.type)) { | ||
throw new Error("Not an extended partition: " + definition.primary + "."); | ||
} else { | ||
return getLogicalPartitions(disk, primary.offset, primary.offset, definition.logical - 1).then(function(logicalPartitions) { | ||
return getPartitionFromList(logicalPartitions, definition.logical); | ||
}); | ||
} | ||
}); | ||
}; | ||
callWithDisk = function() { | ||
var args, fn, pathOrDisk; | ||
fn = arguments[0], pathOrDisk = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : []; | ||
if (pathOrDisk instanceof filedisk.Disk) { | ||
return fn.apply(null, [pathOrDisk].concat(slice.call(args))); | ||
} else { | ||
return Promise.using(filedisk.openFile(pathOrDisk, 'r'), function(fd) { | ||
var disk; | ||
disk = new filedisk.FileDisk(fd); | ||
return fn.apply(null, [disk].concat(slice.call(args))); | ||
}); | ||
} | ||
}; | ||
/** | ||
@@ -42,10 +152,4 @@ * @summary Get information from a partition | ||
exports.get = function(image, definition) { | ||
return partition.getPartitionFromDefinition(image, definition).then(function(parsedPartition) { | ||
return Promise.props({ | ||
offset: parsedPartition.byteOffset(), | ||
size: parsedPartition.byteSize(), | ||
type: parsedPartition.type | ||
}); | ||
}); | ||
exports.get = function(disk, definition) { | ||
return callWithDisk(get, disk, definition); | ||
}; | ||
@@ -73,25 +177,7 @@ | ||
exports.getPartitions = getPartitions = function(image, offset) { | ||
exports.getPartitions = function(disk, offset) { | ||
if (offset == null) { | ||
offset = 0; | ||
} | ||
return Promise["try"](function() { | ||
if (offset === 0) { | ||
return bootRecord.getMaster(image); | ||
} else { | ||
return bootRecord.getExtended(image, offset); | ||
} | ||
}).get('partitions').filter(_.property('type')).map(function(partition) { | ||
partition = { | ||
offset: offset + partition.byteOffset(), | ||
size: partition.byteSize(), | ||
type: partition.type | ||
}; | ||
if (!MBR.Partition.isExtended(partition.type)) { | ||
return [partition]; | ||
} | ||
return getPartitions(image, partition.offset).then(function(ps) { | ||
return [partition].concat(ps); | ||
}); | ||
}).then(_.flatten); | ||
return callWithDisk(getPartitions, disk, offset); | ||
}; |
@@ -6,2 +6,8 @@ # Change Log | ||
## [1.3.0] - 2017-06-09 | ||
### Changed | ||
- Fix logical partitions listing. | ||
## [1.2.0] - 2017-06-02 | ||
@@ -8,0 +14,0 @@ |
{ | ||
"name": "partitioninfo", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Get information about a partition from an image file", | ||
@@ -37,4 +37,3 @@ "main": "build/partitioninfo.js", | ||
"mocha": "^2.4.5", | ||
"mochainon": "^1.0.0", | ||
"mock-fs": "^3.8.0" | ||
"mochainon": "^1.0.0" | ||
}, | ||
@@ -44,5 +43,4 @@ "dependencies": { | ||
"file-disk": "0.0.11", | ||
"mbr": "^0.4.4", | ||
"tmp": "0.0.28" | ||
"mbr": "^0.4.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5275523
3
10
0
2
17
286
- Removedtmp@0.0.28
- Removedos-tmpdir@1.0.2(transitive)
- Removedtmp@0.0.28(transitive)