1/* 2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23#include <libc.h> 24#include <DiskArbitration/DiskArbitration.h> 25#include <DiskArbitration/DiskArbitrationPrivate.h> 26#include <err.h> 27#include "UtilitiesCFPrettyPrint.h" 28 29// cc -o testdadisk testdadisk.c UtilitiesCFPrettyPrint.c -framework CoreFoundation -framework DiskArbitration 30 31 32int main(int argc, char *argv[]) { 33 34 char *dev = NULL; 35 DADiskRef disk = NULL; 36 DASessionRef session = NULL; 37 CFDictionaryRef props = NULL; 38 39 40 if(argc != 2) { 41 fprintf(stderr, "Usage: %s disk1s2\n", getprogname()); 42 exit(1); 43 } 44 45 dev = argv[1]; 46 47 session = DASessionCreate(kCFAllocatorDefault); 48 if(session == NULL) 49 errx(1, "DASessionCreate"); 50 51 if (1) { 52 CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, 53 dev, 54 strlen(dev), 55 false); 56 disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, url); 57 58 CFRelease(url); 59 } else { 60 61 disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, dev); 62 } 63 if(disk == NULL) { 64 CFRelease(session); 65 errx(1, "DADiskCreateFromBSDName"); 66 } 67 68 props = DADiskCopyDescription(disk); 69 if(props == NULL) { 70 CFRelease(session); 71 CFRelease(disk); 72 errx(1, "DADiskCopyDescription"); 73 } 74 75 TAOCFPrettyPrint(disk); 76 TAOCFPrettyPrint(props); 77 78 printf("Options: %lu\n", DADiskGetOptions(disk)); 79 80 CFRelease(session); 81 CFRelease(disk); 82 CFRelease(props); 83 84 return 0; 85} 86