5

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.

jviotti
  • 17,881
  • 26
  • 89
  • 148
  • If the command works when called from command line, then you can run it without the `node-blockdevice` module altogether with [child process spawn](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options). If this approach does not work, then please update your question with content of `stdout` and `stderr`. – artur grzesiak Dec 30 '14 at 21:14
  • @arturgrzesiak That'd require me to ship the dd for windows binary with my package, which is what I'm trying to avoid. – jviotti Dec 31 '14 at 01:33
  • http://stackoverflow.com/questions/8694713/createfile-direct-write-operation-to-raw-disk-access-is-denied-vista-win7 – Hans Passant Jan 02 '15 at 15:57
  • And you successfully read the boot sector from the drive :) – Hans Passant Jan 03 '15 at 00:45
  • @HansPassant I've read the same device's MBR on OS X, but it's different from the one I've read from W8. – jviotti Jan 04 '15 at 19:47
  • check this link may help u https://github.com/jhermsmeier/node-blockdevice/issues/1 – Divyang Shah Jan 05 '15 at 13:21
  • @DivyangShah I opened that issue myself, and also linked it in the question :) – jviotti Jan 05 '15 at 17:13
  • oh, ok than ignore it. – Divyang Shah Jan 06 '15 at 06:02

0 Answers0