Erase MBR before rescanning

This commit is contained in:
Juan Cruz Viotti 2015-01-28 14:51:11 -04:00
parent 8b0ce36955
commit 320981770e

View File

@ -13,6 +13,32 @@ exports.rescanDrives = (callback) ->
console.log("DISKPART RESULT: #{arguments}")
return callback(error)
exports.eraseMBR = (devicePath, callback) ->
return callback() if not IS_WINDOWS
bufferSize = 512
async.waterfall([
(callback) ->
fs.open(devicePath, 'rs+', null, callback)
(fd, callback) ->
buffer = new Buffer(bufferSize)
buffer.fill(0)
fs.write fd, buffer, 0, bufferSize, 0, (error, bytesWritten) ->
return callback(error) if error?
return callback(null, bytesWritten, fd)
(bytesWritten, fd, callback) ->
if bytesWritten isnt bufferSize
error = "Bytes written: #{bytesWritten}, expected #{bufferSize}"
return callback(error)
fs.close(fd, callback)
], callback)
exports.writeImage = (devicePath, imagePath, options = {}, callback = _.noop) ->
if not fs.existsSync(imagePath)
@ -39,6 +65,9 @@ exports.writeImage = (devicePath, imagePath, options = {}, callback = _.noop) ->
async.waterfall([
(callback) ->
exports.eraseMBR(devicePath, callback)
(callback) ->
exports.rescanDrives(callback)