Naraeon SSD Tools internals – 3. Physical drive abstraction

Necessity

Physical drives have various features. From these features, TPhysicalDrive abstracts some of them those are needed to Naraeon SSD Tools. Internally, the object just passes the request to right object. There are objects process these requests. Firstly, there is an object that issue adequate command to the bus directly(ATA, SCSI, NVMe, …).  And there is another object that has functions can be done with other ioctls. Former one is TBusPhysicalDrive, and latter one is TOSPhysicalDrive.

Why interface?

In whole code, this object is used in IPhysicalDrive interface form, not TPhysicalDrive object form. Because in Delphi, inteface has reference counting based resource management feature. This project uses interface only by that reason.

But when not directly inherited TInterfacedObject, reference counting feature must be implemented manually. And Delphi doesn’t support multiple inheritance. So I just copied+pasted the implementation from VCL source. Delphi users have rights to use VCL source legally. When implementing the same thing in other languages, just use smart pointers.

Commands that can be issued only with low-level ioctls: TBusPhysicalDrive

TBusPhysicalDrive gets basic things of the drive. For example, model, serial, capacity, SMART values, SATA speed, etc. In fact, TCommandSet issues the command and TBufferInterpreter translates the buffer into readable form. But information about them will be written in future.

Information from Identify command

Information from SMART command

When low-level passthrough isn’t neccessary: TOSPhysicalDrive

TOSPhysicalDrive gets information that can be got from simple OS request. Like availability, user size, partition list, NCQ availability. OS can quickly and easily give us these information.

TDriveAvailabilityGetter gets availability of the drive. This validates the handle and use IOCTL_STORAGE_CHECK_VERIFY ioctl code to further check.

TDiskGeometryGetter gets size of the drive. Done with IOCTL_DISK_GET_DRIVE_GEOMETRY_EX ioctl code.

TPartitionListGetter gets partition list of the drive. Firstly get fixed drives with GetLogicalDriveStrings, and find partitions in the drive with the Extent of each partition.

TNCQAvailabilityGetter gets NCQ availability of the drive. It uses IOCTL_STORAGE_QUERY_PROPERTY ioctl code. Internally it uses BusType and CommandQueueing to decide whether NCQ is available or not. The condition is got from test result of drivers at that time.