Discussion:
how to get volume information
Abhijeet Singh
2011-08-06 12:44:36 UTC
Permalink
Hi,Can you give me some more reference on I/O Kit. I just want to allow my application to be run from USB Jump drive or from CD/DVD. I dont want to allow user to run it from Hardisk.I am using getFileSystemInfoForPath of NSWorkspace class to retrieve the same information. It works fine with Jump drive or CD drive but when I create DMG file of my application and copy it on my hard disk and then run it from hard disk it let me run my application.Thanks & RegardsAbhijeet Original message From:"Aaron Burghardt"< ***@gmail.com >Date: 25 Feb 11 17:11:34Subject: Re: how to get volume informationTo: Cc: "macosxdev" Hi,Sorry, didn't see your reply.stdev is not a UUID, it is a reference that is valid only as long as the device is connected. I should have been more explicit in my command line example,but "stat f "%d" prints the stdev field.Once you have the DADisk, use DADiskCopyDescription to get a dictionary of properties, in which you will find the UUID with the key kDADi
skDescriptionMediaUUIDKey (see DADisk.h for other keys that may be of interest). Note, a DADisk is a wrapper around an IOMedia object and the description dictionary corresponds directly to the properties in the IOMedia object.Also, CFShow() is useful for printing the description dictionary to the console.AaronOn Feb 21, 2011, at 7:52 AM, Abhijeet Singh wrote:Hi,Thanks for the help. I finally used Disk Arbitration framework to find out whether program is running from removable media or not. But to get the identification number i don't find any method in Disk Arbitration framework. Is there any method that gives UUID in Disk Arbitration framework. I also checked stat structure. There is one field stdev. Can I use it as a identification number of a media. Because it always gives me a different number for different USB pen drive and same number for same drive.Thanks & RegardsAbhijeet Original message From:"Aaron Burghardt"< ***@gmail.com >Date: 21 Feb 11 02:48:33Subj
ect: Re: how to get volume informationTo: Cc: "macosxdev" I think the IOMedia objects in the I/O Kit registry will have what you are looking for. Use stat() to get the device ID of the disk that your app is on (i.e., stat() the path of the main bundle). The ID in the stat struct is a combination of the BSD Major and BSD Minor. For example, my boot drive is:$ stat f "%d" /234881026$ printf "%#x " 2348810260xe000002where 0xe is the BSD Major, and 0x2 is BSD Minor. Create an I/O Kit matching dictionary that matches the IOMedia class and the BSD Major and BSD Minor values you got from stat, then use it to get matching objects (for example, get an iterator and iterate its objects). If you need more references to working with I/O Kit, let me know. You should be able to determine from the IOMedia properties whether the device is optical or not (in fact, I think optical media uses a subclass of IOMedia). Depending on the file system on the media, there may be a UUID which satisfies
your second requirement.You can use the Disk Arbitration framework as an alternate way to get IOMedia objects, but I think the registration/callback design of that framework would make it more cumbersome for your task.AaronOn Feb 14, 2011, at 8:45 AM, Abhijeet Singh wrote:> Hi,In my application 1. I want to check whether my application is running from CD (removable media) or from hard disk.I dont want to allow my user to run my application from hard disk. 2. Same application i developed in windows. I used to store the volume serial number of the CD that was first time used to run my application. How can i get Volume Serial Number of the CD here?(I found stat() of BSD. It returns several volume information parameters. Can i get volume serial number from stat()?)Thanks & RegardsAbhijeetDear macosxdev ! Get Yourself a cool, short @in.com Email ID now!> Get Yourself a cool, short @in.com Email ID now!
Loading...