How to get volume information

  • 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!
  • 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 cocoadev ! Get Yourself a cool, short @in.com Email ID now!
  • Look at the Disk Arbitration framework.

    - Gary L. Wade (Sent from my iPhone)

    On Feb 14, 2011, at 5:46 AM, "Abhijeet Singh" <abhi_707...> 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 cocoadev ! Get Yourself a cool, short @in.com Email ID now!
  • On Feb 14, 2011, at 7:46 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()?)

    Volume serial numbers, as such, are a Windows-specific concept.

    Mac OS X supports the notion of a volume UUID, but not all file systems support it.  It should be supported for a CD or a hard disk, though.

    There are a couple of APIs that can obtain that.  As mentioned, Disk Arbitration is one.  The getattrlist() function is another.

    Regards,
    Ken
  • 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\n" 234881026
    0xe000002

    where 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.

    Aaron

    On 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!
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • 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"< <aaron.burghardt...> >Date: 21 Feb 11 02:48:33Subject: 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:$ s
    tat f "%d" /234881026$ printf "%#x
    " 2348810260xe000002where 0xe is the BSD Major, and 0x2 is BSD Minor. Create an I/O Kit matching dictionary that matchesthe 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 usesa 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!> > MacOSXdev mailing list> <MacOSXdev...> http://www.omnigroup.com/mailman/listinfo/macosxdevGet Yourself a cool, short @in.com Email ID now!
  • Hi,

    Sorry, didn't see your reply.  st_dev 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 st_dev field.

    Once you have the DADisk, use DADiskCopyDescription to get a dictionary of properties, in which you will find the UUID with the key kDADiskDescriptionMediaUUIDKey (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.

    Aaron

    On 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 st_dev. 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 & Regards
    > Abhijeet
    >
    > ---------- Original message ----------
    > From:"Aaron Burghardt"< <aaron.burghardt...> >
    > Date: 21 Feb 11 02:48:33
    > Subject: Re: how to get volume information
    > To:
    > Cc: "macosx-dev" <macosx-dev...>
    >
    > 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 " 234881026
    > 0xe000002
    >
    > where 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.
    >
    > Aaron
    >
    >
    > On Feb 14, 2011, at 8:45 AM, Abhijeet Singh wrote:
    >
    >> Hi,In my application 1. I want to check whether my application is runn ing 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!
    >> _______________________________________________
previous month february 2011 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28            
Go to today