Sending ATA commands to SATA storage devices

29 views
Skip to first unread message

Gary....@hgst.com

unread,
Feb 14, 2013, 12:13:09 PM2/14/13
to ata-sc...@lists.apple.com

I introduced a version of this topic a few months ago and since then have been following the advice that I received at that time. I currently have a KEXT with a Client that loads via kextutil. Once loaded, "ioreg" shows my kext sitting between IOAHCIBlockStorageDevice and IOBlockStorageDriver, which sits on top of the two WDC hard drives to which I want to send ATA commands. After loading my kext with client, I can send commands down to the client using IOConnectCallStructMethod, and can tnen pass the data and structures to the kext. The kext simply returns a success to the client and then back up to the app.

My kext sits where I think it should, but I have been unable to fathom how to link or attach to the lower ecehlons, which I assume would be the IOBlockStorageDriver. Perhaps my thinking is to Windows-centric since I've done this same tasks dozens of times on Windows systems,  but when I attempt to take the IOService parameter and use OSDynamicCast to cast it to an IOATADevice pointer, I get a null returned. In my kext's attach method I have also attempted to simply cast the IOService* parameter to a IOATADevice* and then call (IOATADevie*)->getDeviceType(), but that simply returns kIOReturnUnsupported. I've also attempted to do the same kind of casting to IOBlockStorageDriver, as well attempted to use ATADeviceNub, but so far nothing works ... well there have been attempts the did indeed crash the test machines kernel, requiring a reboot call from gdb I had running on another Mac.

The kext currently has the following methods defined:

init()
start()
attach()
detach()

My system stats:
       2012 MacPro running Mountain Lion 10.8.3
               1 TB WDC formatted as Macintosh HDD
               1 TB WDC formatted but empty
               1 TB WDC FireWire, formatted for alternate boot
               Xcode 4.6
               MacPorts 2.1.3
               Boost 1.52.0


For testing I boot the test machine to the 10.8.3 installed on the FireWire 1 TB drive. I build my code on a development Mac-mini using Xcode 4.6, copy it to a directory on the test system, and then use "sudo cp -R myKext.kext /tmp/." to prepare it for kextutil.


HGST stands for Hitachi Global Storage Technologies, and is currently owned by Western Digital. We really really do want to be able to talk to our harddrives and other online storage media.

Gary G. Little
W (507) 322-2078
C (952) 454-4629

Stuart Smith

unread,
Feb 14, 2013, 6:03:03 PM2/14/13
to ata-sc...@lists.apple.com
You're not dealing with an IOATADevice.

If I take a look at the IOService plane on my Mac,
IOAHCIDevice (which is an IOService) attaches
-- AppleAHCIDiskDriver (which is an IOAHCIBlockStorageDriver, which is an
IOService), attaches
-- IOAHCIBlockStorageDevice (which is an IOBlockStorageDevice, which is
an IOService)

there's no IOATADevice here. That's why OSDynamicCast returns NULL. If you
cast to IOATADevice* nevertheless, you end up calling a function at some
offset from your pointer, which may or may not crash.

The IOAHCI* headers and sources are not public in the Darwin code.
The AppleAHCIDiskDriver is not intended to be subclassed.

You should ask DTS for help. They may not be able to. People have asked
this question numerous times on various Apple mailing lists and there has
never been an answer.


Stuart

On 2/14/13 12:00 PM, "ata-scsi-d...@lists.apple.com"
<ata-scsi-d...@lists.apple.com> wrote:

>Message: 1
>Date: Thu, 14 Feb 2013 11:13:09 -0600
>From: Gary....@hgst.com
>To: ata-sc...@lists.apple.com
>Subject: Sending ATA commands to SATA storage devices
>Message-ID:
> <OF684045E3.20D743ED-ON86257B...@hgst.com>
>Content-Type: text/plain; charset="utf-8"
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL:
><https://lists.apple.com/mailman/private/ata-scsi-dev/attachments/20130214
>/9a23d2d8/attachment.html>
>



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Ata-scsi-dev mailing list (Ata-sc...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/ata-scsi-dev/ata-scsi-dev-garchive-72467%40googlegroups.com

This email sent to ata-scsi-dev-...@googlegroups.com

Garth Cummings

unread,
Feb 15, 2013, 3:54:31 PM2/15/13
to ata-sc...@lists.apple.com
Hi Gary,

On Feb 14, 2013, at 3:03 PM, Stuart Smith <stu...@elgato.com> wrote:

> You're not dealing with an IOATADevice.
>
> If I take a look at the IOService plane on my Mac,
> IOAHCIDevice (which is an IOService) attaches
> -- AppleAHCIDiskDriver (which is an IOAHCIBlockStorageDriver, which is an
> IOService), attaches
> -- IOAHCIBlockStorageDevice (which is an IOBlockStorageDevice, which is
> an IOService)
>
> there's no IOATADevice here. That's why OSDynamicCast returns NULL. If you
> cast to IOATADevice* nevertheless, you end up calling a function at some
> offset from your pointer, which may or may not crash.
>
> The IOAHCI* headers and sources are not public in the Darwin code.
> The AppleAHCIDiskDriver is not intended to be subclassed.
>
> You should ask DTS for help. They may not be able to. People have asked
> this question numerous times on various Apple mailing lists and there has
> never been an answer.
>
>
> Stuart

Please file a bug report. DTS won't be able to help you here because IOAHCI* is not public API.

Thanks,
--gc
> https://lists.apple.com/mailman/options/ata-scsi-dev/gcummings%40apple.com
>
> This email sent to gcum...@apple.com

______________
Garth Cummings
Apple Developer Technical Support gcum...@apple.com

http://developer.apple.com/support/resources/technical-support.html

Gary Little

unread,
Feb 18, 2013, 10:14:01 AM2/18/13
to ata-sc...@lists.apple.com
Gentlemen,

Thank you for your replies. I have submitted a bug report to DTS.

Gary Little
ggli...@comcast.net
C 952-454-4629
H 952-223-1349
Tain't what you want that makes you fat, it's what you get.
> https://lists.apple.com/mailman/options/ata-scsi-dev/gglittle%40comcast.net
>
> This email sent to ggli...@comcast.net
Reply all
Reply to author
Forward
0 new messages