partitioninfo
Advanced tools
Comparing version 2.2.1 to 3.0.0
@@ -1,2 +0,2 @@ | ||
var BOOT_RECORD_SIZE, MBR, MBR_EXTENDED_PARTITION_TYPE, MBR_FIRST_LOGICAL_PARTITION, MBR_LAST_PRIMARY_PARTITION, Promise, _, callWithDisk, filedisk, get, getLogicalPartitions, getPartitions, getPartitionsFromMBRBuf, partitionDict, partitionNotFoundError, readMbr, | ||
var GPT, GPT_PROTECTIVE_MBR, GPT_SIZE, MBR, MBR_EXTENDED_PARTITION_TYPE, MBR_FIRST_LOGICAL_PARTITION, MBR_LAST_PRIMARY_PARTITION, MBR_SIZE, Promise, _, callWithDisk, filedisk, get, getLogicalPartitions, getPartitions, getPartitionsFromMBRBuf, gptPartitionDict, mbrPartitionDict, partitionNotFoundError, readFromDisk, | ||
slice = [].slice; | ||
@@ -10,2 +10,4 @@ | ||
GPT = require('gpt'); | ||
Promise = require('bluebird'); | ||
@@ -18,4 +20,8 @@ | ||
BOOT_RECORD_SIZE = 512; | ||
MBR_SIZE = 512; | ||
GPT_SIZE = 512 * 33; | ||
GPT_PROTECTIVE_MBR = 0xee; | ||
MBR_LAST_PRIMARY_PARTITION = 4; | ||
@@ -27,3 +33,3 @@ | ||
partitionDict = function(p, offset, index) { | ||
mbrPartitionDict = function(p, offset, index) { | ||
return { | ||
@@ -37,2 +43,11 @@ offset: offset + p.byteOffset(), | ||
gptPartitionDict = function(gpt, p, index) { | ||
return { | ||
offset: p.firstLBA * gpt.blockSize, | ||
size: (p.lastLBA - p.firstLBA + 1) * gpt.blockSize, | ||
type: p.type.toString(), | ||
index: index | ||
}; | ||
}; | ||
getPartitionsFromMBRBuf = function(buf) { | ||
@@ -42,6 +57,6 @@ return (new MBR(buf)).partitions.filter(_.property('type')); | ||
readMbr = function(disk, offset) { | ||
readFromDisk = function(disk, offset, size) { | ||
var buf; | ||
buf = Buffer.allocUnsafe(BOOT_RECORD_SIZE); | ||
return disk.readAsync(buf, 0, BOOT_RECORD_SIZE, offset)["return"](buf); | ||
buf = Buffer.alloc(size); | ||
return disk.readAsync(buf, 0, size, offset)["return"](buf); | ||
}; | ||
@@ -61,3 +76,3 @@ | ||
} | ||
return readMbr(disk, offset).then(function(buf) { | ||
return readFromDisk(disk, offset, MBR_SIZE).then(function(buf) { | ||
var i, len, logicalPartitionsPromise, p, ref; | ||
@@ -68,3 +83,3 @@ ref = getPartitionsFromMBRBuf(buf); | ||
if (!MBR.Partition.isExtended(p.type)) { | ||
result.push(partitionDict(p, offset, index)); | ||
result.push(mbrPartitionDict(p, offset, index)); | ||
} else if (limit > 0) { | ||
@@ -88,24 +103,39 @@ logicalPartitionsPromise = getLogicalPartitions(disk, index + 1, extendedPartitionOffset + p.byteOffset(), extendedPartitionOffset, limit - 1); | ||
disk = Promise.promisifyAll(disk); | ||
result = []; | ||
result = {}; | ||
extended = null; | ||
return readMbr(disk, options.offset).then(function(buf) { | ||
var i, index, len, p, ref; | ||
ref = getPartitionsFromMBRBuf(buf); | ||
for (index = i = 0, len = ref.length; i < len; index = ++i) { | ||
p = ref[index]; | ||
if (MBR.Partition.isExtended(p.type)) { | ||
extended = p; | ||
if (options.includeExtended) { | ||
result.push(partitionDict(p, options.offset, index + 1)); | ||
return readFromDisk(disk, options.offset, MBR_SIZE).then(function(mbrBuf) { | ||
var i, index, len, p, partitions; | ||
partitions = getPartitionsFromMBRBuf(mbrBuf); | ||
if (partitions.length === 1 && partitions[0].type === GPT_PROTECTIVE_MBR) { | ||
result.type = 'gpt'; | ||
return readFromDisk(disk, MBR_SIZE, GPT_SIZE).then(function(gptBuf) { | ||
var gpt; | ||
gpt = GPT.parse(gptBuf); | ||
result.partitions = gpt.partitions.map(function(partition, index) { | ||
return gptPartitionDict(gpt, partition, index + 1); | ||
}); | ||
return result; | ||
}); | ||
} else { | ||
result.partitions = []; | ||
result.type = 'mbr'; | ||
for (index = i = 0, len = partitions.length; i < len; index = ++i) { | ||
p = partitions[index]; | ||
if (MBR.Partition.isExtended(p.type)) { | ||
extended = p; | ||
if (options.includeExtended) { | ||
result.partitions.push(mbrPartitionDict(p, options.offset, index + 1)); | ||
} | ||
} else { | ||
result.partitions.push(mbrPartitionDict(p, options.offset, index + 1)); | ||
} | ||
} else { | ||
result.push(partitionDict(p, options.offset, index + 1)); | ||
} | ||
if ((extended != null) && options.getLogical) { | ||
return getLogicalPartitions(disk, MBR_FIRST_LOGICAL_PARTITION, extended.byteOffset()).then(function(logicalPartitions) { | ||
var ref; | ||
(ref = result.partitions).push.apply(ref, logicalPartitions); | ||
return result; | ||
}); | ||
} | ||
} | ||
if (extended !== null && options.getLogical) { | ||
return getLogicalPartitions(disk, MBR_FIRST_LOGICAL_PARTITION, extended.byteOffset()).then(function(logicalPartitions) { | ||
result.push.apply(result, logicalPartitions); | ||
return result; | ||
}); | ||
} | ||
return result; | ||
@@ -127,7 +157,14 @@ }); | ||
getLogical: false | ||
}).then(function(partitions) { | ||
}).then(function(info) { | ||
var extended, logicalPartitionPosition; | ||
if (info.type === 'gpt') { | ||
if (info.partitions.length < number) { | ||
partitionNotFoundError(number); | ||
} else { | ||
return info.partitions[number - 1]; | ||
} | ||
} | ||
if (number <= MBR_LAST_PRIMARY_PARTITION) { | ||
if (number <= partitions.length) { | ||
return partitions[number - 1]; | ||
if (number <= info.partitions.length) { | ||
return info.partitions[number - 1]; | ||
} else { | ||
@@ -137,3 +174,3 @@ return partitionNotFoundError(number); | ||
} else { | ||
extended = _.find(partitions, function(p) { | ||
extended = _.find(info.partitions, function(p) { | ||
return p.type === MBR_EXTENDED_PARTITION_TYPE; | ||
@@ -218,7 +255,8 @@ }); | ||
* @param {Number} [options.offset=0] - where the first partition table will be read from, in bytes | ||
* @param {Number} [options.includeExtended=true] - whether to include extended partitions or not | ||
* @param {Boolean} [options.includeExtended=true] - whether to include extended partitions or not (only for MBR partition tables) | ||
* @param {Boolean} [options.getLogical=true] - whether to include logical partitions or not (only for MBR partition tables) | ||
* | ||
* @throws {Error} if there is no such partition | ||
* | ||
* @returns {Promise<Array<Object>>} partitions information | ||
* @returns {Promise<Object>} partitions information | ||
* | ||
@@ -228,3 +266,4 @@ * @example | ||
* .then (information) -> | ||
* for partition in information | ||
console.log(information.type) | ||
* for partition in information.partitions | ||
* console.log(partition.offset) | ||
@@ -231,0 +270,0 @@ * console.log(partition.size) |
@@ -7,2 +7,6 @@ # Change Log | ||
## v3.0.0 - 2017-10-10 | ||
* Support GPT partition tables #28 [Alexis Svinartchouk] | ||
## v2.2.1 - 2017-10-09 | ||
@@ -9,0 +13,0 @@ |
{ | ||
"name": "partitioninfo", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"description": "Get information about a partition from an image file", | ||
@@ -46,4 +46,5 @@ "main": "build/partitioninfo.js", | ||
"file-disk": "^1.0.1", | ||
"gpt": "^1.0.0", | ||
"mbr": "^0.4.4" | ||
} | ||
} |
@@ -27,3 +27,3 @@ partitioninfo | ||
* [.get(image, number)](#module_partitioninfo.get) ⇒ <code>Promise.<Object></code> | ||
* [.getPartitions(image, options)](#module_partitioninfo.getPartitions) ⇒ <code>Promise.<Array.<Object>></code> | ||
* [.getPartitions(image, options)](#module_partitioninfo.getPartitions) ⇒ <code>Promise.<Object></code> | ||
@@ -54,3 +54,3 @@ <a name="module_partitioninfo.get"></a> | ||
### partitioninfo.getPartitions(image, options) ⇒ <code>Promise.<Array.<Object>></code> | ||
### partitioninfo.getPartitions(image, options) ⇒ <code>Promise.<Object></code> | ||
`getPartitions()` returns an Array. | ||
@@ -72,3 +72,3 @@ `getPartitions(image)[N - 1]` may not be equal to `get(image, N)` | ||
**Summary**: Read all partition tables from a disk image recursively. | ||
**Returns**: <code>Promise.<Array.<Object>></code> - partitions information | ||
**Returns**: <code>Promise.<Object></code> - partitions information | ||
**Throws**: | ||
@@ -85,3 +85,4 @@ | ||
| [options.offset] | <code>Number</code> | <code>0</code> | where the first partition table will be read from, in bytes | | ||
| [options.includeExtended] | <code>Number</code> | <code>true</code> | whether to include extended partitions or not | | ||
| [options.includeExtended] | <code>Boolean</code> | <code>true</code> | whether to include extended partitions or not (only for MBR partition tables) | | ||
| [options.getLogical] | <code>Boolean</code> | <code>true</code> | whether to include logical partitions or not (only for MBR partition tables) | | ||
@@ -92,3 +93,4 @@ **Example** | ||
.then (information) -> | ||
for partition in information | ||
console.log(information.type) | ||
for partition in information.partitions | ||
console.log(partition.offset) | ||
@@ -95,0 +97,0 @@ console.log(partition.size) |
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
26259660
19
369
127
4
4
+ Addedgpt@^1.0.0
+ Addedbuffer-crc32@0.2.13(transitive)
+ Addedgpt@1.0.0(transitive)