NodeJS: Unable to write to Windows 8 block device

459 views Asked by At

I'm looking forward to write directly to a raw windows block device.

I can successfully do so with dd for windows:

> dd.exe if=myData.dat of=\\.\PhysicalDrive1

However I'm unable to do so using NodeJS. I'm using node-blockdevice in the following manner:

var device = new BlockDevice({
  path: '\\\\.\\PhysicalDrive1',
  mode: 'w+',
  size: 512
});

device.write(0, myBuffer, callback);

device.write correctly returns the amount of bytes written, however it's not actually writing anything to the device.

Notice that the exact code works successfully in Mac OS X (substituting \\\\.\\PhysicalDrive1 with /dev/diskN of course): it writes my data and I can view it without any problem in Windows 8.

What am I doing wrong?

I also tried:

  • Not escaping the backslashes (\\.\PhysicalDrive1) but that results in a EINV error.
  • Using the logical name: \\\\.\\E:.
  • Unmounting the volume with mountvol X: /D before attempting to read/write.

I can correctly confirm the id of the device I want to write to with:

wmic diskdrive list brief

I've also tried setting the mode to rs+. The read operation seemed to work, however the saved data contained the following failure-related data:

�X�MSDOS5.0�
�?����:�)?�xNO NAME    FAT32   3ɎѼ�{��ٽ|�V@�N�V@�A��U�r��U�u
��t�F�-�V@�s�����f��@f������Af��f��f�F�~u9�~*w3f�Ff��
                                                        ����,���}��|���t<�t   ������}��}��ߘ��f`�~� fjfPSfh�B�V@���fXfXfXfX�3f;F�r��*f3�f�Nf����f��f���v�֊V@����
 ̸�fa�t���f@Iu��BOOTMGR
Disk error�
Press any key to restart
��U�%

EDIT: A github issue thread describing more things I've tried: https://github.com/jhermsmeier/node-blockdevice/issues/1.

EDIT: All approaches mentioned were tested with admin privileges.

EDIT: I'm using device.close(callback), but omitted in the example for simplicity.

0

There are 0 answers