NBDServer icon indicating copy to clipboard operation
NBDServer copied to clipboard

Option -n all does not work as expected

Open PinkPandaKatie opened this issue 12 years ago • 5 comments

The -n all option does not serve up the entire disk; it only serves the first partition.

It looks like the code in main.cpp:305 attempts to detect the number of partitions using sizeof(), which is a compile-time constant. That causes it to always detect exactly one partition.

Instead of checking the drive partition layout, it should send either IOCTL_DISK_GET_LENGTH_INFO or IOCTL_DISK_GET_GEOMETRY_EX to get the length of the drive, and set foffset to 0.

Also, I think it would be a good idea to have a way to directly specify the offset and length.

Debug output (PHYSICALDRIVE0 has 4 partitions):

C:\users\jspenguin>NBDServer.exe -c 10.42.1.1 -f \\.\PHYSICALDRIVE0 -n all -d
[*] File opened, valid file
[*] Listening...
[*] Init socket loop
[+] Connection made with: 10.42.1.100
[*] Init socket loop
[*] opening read-only
[*] Partitions 1
[*] Gathered length from all partitions
[*] Partition -1 is of type 04
[*] Offset: 1048576 (100000)
[*] Length: 504406022144 (7570f11800)
[*] Negotiating...sending NBDMAGIC header
[*] Started!

PinkPandaKatie avatar Jul 16 '13 04:07 PinkPandaKatie

Interesting, thanks for the report. I know I've used it to image an entire disk with >1 partitions. I'm using sizeof/sizeof * which I think should report the correct size but I'd like to do some more testing and explore the other calls you mention. What windows version is this?

Good idea to allow additional options to directly set offset/length! I'll add that as well.

jeffbryner avatar Jul 16 '13 15:07 jeffbryner

Windows 7 Ultimate.

Any use of sizeof() is always a compile time constant. DRIVE_LAYOUT_INFORMATION is defined as

typedef struct _DRIVE_LAYOUT_INFORMATION {
  ULONG                 PartitionCount;
  ULONG                 Signature;
  PARTITION_INFORMATION PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION;

so sizeof(dli->PartitionEntry) / sizeof(*dli->PartitionEntry) is always 1.

Also, I'm not sure IOCTL_DISK_GET_DRIVE_LAYOUT supports GPT. I know IOCTL_DISK_GET_DRIVE_LAYOUT_EX supports it.

PinkPandaKatie avatar Jul 16 '13 15:07 PinkPandaKatie

Ahh, makes sense. I also think I see why my test cases always worked even with this bug. I'll play around with layout_ex and see what I can come up with.

jeffbryner avatar Jul 16 '13 20:07 jeffbryner

FYI: I've got a fix for this, just need to merge it into this project and test it a bit.

jeffbryner avatar Jul 24 '13 23:07 jeffbryner

Finally got a chance to test and commit a change to fix this. Do you mind testing as well?

jeffbryner avatar Jul 27 '13 21:07 jeffbryner