-
Notifications
You must be signed in to change notification settings - Fork 14
/
inspect.js
81 lines (61 loc) · 1.65 KB
/
inspect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var fs = require( 'fs' )
var MBR = require( 'mbr' )
var GPT = require( '..' )
var inspect = require( '../test/inspect' )
var utils = require( './utils' )
var argv = process.argv.slice( 2 )
var devicePath = argv.shift()
if( !devicePath ) {
console.error(`
Usage: node example/inspect <device>
Examples:
- Linux / Mac OS: node example/inspect /dev/rdisk2
- Windows: node example/inspect \\.\PhysicalDrive0
NOTE: This assumes a block size of 512 bytes
`)
process.exit(1)
}
console.log( '' )
var blockSize = 512
var fd = null
try {
fd = fs.openSync( devicePath, 'r' )
} catch( error ) {
console.error( 'Couldn\'t open device for reading:\n', error.message )
process.exit( 1 )
}
var mbr = null
try {
mbr = utils.readMBR( fd, blockSize )
} catch( error ) {
console.log( 'No Master Boot Record found:\n', error.message )
process.exit( 1 )
}
console.log( 'Master Boot Record:', inspect( mbr ) )
console.log( '' )
var efiPart = mbr.getEFIPart()
if( efiPart == null ) {
console.error( 'No EFI partition found' )
process.exit( 1 )
}
console.log( 'EFI Partition:', inspect( efiPart ) )
console.log( '' )
var primaryGPT = null
try {
primaryGPT = utils.readPrimaryGPT( fd, blockSize, efiPart )
} catch( error ) {
console.error( 'No GUID Partition Table found:\n', error.message )
process.exit( 1 )
}
console.log( 'Primary GPT:', inspect( primaryGPT ) )
console.log( '' )
var backupGPT = null
try {
backupGPT = utils.readBackupGPT( fd, primaryGPT )
} catch( error ) {
console.error( 'Couldn\'t parse backup GPT:\n', error.message )
process.exit( 1 )
}
console.log( 'Backup GPT:', inspect( backupGPT ) )
console.log( '' )
fs.closeSync( fd )