tags:

views:

225

answers:

2

How can I programmatically determine which (if any) mounted volumes are a DVD?

I currently look for a directory with permissions 555 but I would prefer something a bit less hacky. Thanks!!

$ ls -l /Volumes/
total 12
dr-xr-xr-x  4 mh    gfx    136 Aug  3  2001 DQRMX2102
lrwxr-xr-x  1 root  admin    1 Apr  6 15:09 Macintosh HD -> /
drwxrwxr-x  9 mh    gfx    374 Feb  3 12:55 data
+4  A: 

What programming language/toolkit are you using?

If you're using Cocoa in Objective-C, you can NSWorkspace:

NSArray *volumes = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];

If you want to find out from the command line or a script or something, diskutil should come in handy.

$ diskutil info -plist /Volumes/Foobar
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
<plist version="1.0">
<dict>
...snip...
    <key>OpticalMediaType</key>
    <string>CD-ROM</string>
...snip...
</dict>
</plist>
Brian Campbell
+3  A: 

For Cocoa, you can use NSWorkspace mountedRemovableMedia: to get a list of volumes and the use NSWorkspace getFileSystemInfo:... to get more information about each mounted volume.

- (BOOL)getFileSystemInfoForPath:(NSString *)fullPath 
                     isRemovable:(BOOL *)removableFlag 
                      isWritable:(BOOL *)writableFlag 
                   isUnmountable:(BOOL *)unmountableFlag 
                     description:(NSString **)description 
                            type:(NSString **)fileSystemType

If you want to make system calls, you can use statfs at the same information.

int statfs(const char *path, struct statfs *buf);
jop