]>
git.saurik.com Git - apple/hfs.git/blob - mount_hfs/optical.c
2 * Copyright (c) 2007 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
28 #include <CoreFoundation/CoreFoundation.h>
29 #include <IOKit/IOKitLib.h>
30 #include <IOKit/storage/IOMedia.h>
31 #include <IOKit/storage/IOBDMedia.h>
32 #include <IOKit/storage/IOCDMedia.h>
33 #include <IOKit/storage/IODVDMedia.h>
36 __io_media_copy_whole_media(io_service_t media
)
41 IOObjectRetain(media
);
44 if (IOObjectConformsTo(media
, kIOMediaClass
)) {
45 property
= IORegistryEntryCreateCFProperty(media
, CFSTR(kIOMediaWholeKey
), kCFAllocatorDefault
, 0);
48 if (property
== kCFBooleanTrue
)
52 parent
= IO_OBJECT_NULL
;
53 IORegistryEntryGetParentEntry(media
, kIOServicePlane
, &parent
);
54 IOObjectRelease(media
);
62 __io_media_create_from_bsd_name(const char *name
)
64 if (!strncmp(_PATH_DEV
, name
, strlen(_PATH_DEV
)))
65 name
+= strlen(_PATH_DEV
);
67 return IOServiceGetMatchingService(kIOMasterPortDefault
, IOBSDNameMatching(kIOMasterPortDefault
, 0, name
));
71 __io_media_is_writable(io_service_t media
)
76 property
= IORegistryEntryCreateCFProperty(media
, CFSTR(kIOMediaWritableKey
), kCFAllocatorDefault
, 0);
79 if (property
== kCFBooleanTrue
) {
80 writable
= _OPTICAL_WRITABLE_SECTOR
;
82 if (IOObjectConformsTo(media
, kIOBDMediaClass
)) {
83 property
= IORegistryEntryCreateCFProperty(media
, CFSTR(kIOBDMediaTypeKey
), kCFAllocatorDefault
, 0);
85 if (CFEqual(property
, CFSTR(kIOBDMediaTypeR
)))
86 writable
= _OPTICAL_WRITABLE_PACKET
| _OPTICAL_WRITABLE_ONCE
; /* BD-R */
87 else if (CFEqual(property
, CFSTR(kIOBDMediaTypeRE
)))
88 writable
= _OPTICAL_WRITABLE_PACKET
; /* BD-RE */
91 } else if (IOObjectConformsTo(media
, kIOCDMediaClass
)) {
92 property
= IORegistryEntryCreateCFProperty(media
, CFSTR(kIOCDMediaTypeKey
), kCFAllocatorDefault
, 0);
94 if (CFEqual(property
, CFSTR(kIOCDMediaTypeR
)))
95 writable
= _OPTICAL_WRITABLE_PACKET
| _OPTICAL_WRITABLE_ONCE
; /* CD-R */
96 else if (CFEqual(property
, CFSTR(kIOCDMediaTypeRW
)))
97 writable
= _OPTICAL_WRITABLE_PACKET
; /* CD-RW */
101 } else if (IOObjectConformsTo(media
, kIODVDMediaClass
)) {
102 property
= IORegistryEntryCreateCFProperty(media
, CFSTR(kIODVDMediaTypeKey
), kCFAllocatorDefault
, 0);
104 if (CFEqual(property
, CFSTR(kIODVDMediaTypeR
)))
105 writable
= _OPTICAL_WRITABLE_PACKET
| _OPTICAL_WRITABLE_ONCE
; /* DVD-R */
106 else if (CFEqual(property
, CFSTR(kIODVDMediaTypeRW
)))
107 writable
= _OPTICAL_WRITABLE_PACKET
; /* DVD-RW */
108 else if (CFEqual(property
, CFSTR(kIODVDMediaTypePlusR
)))
109 writable
= _OPTICAL_WRITABLE_PACKET
| _OPTICAL_WRITABLE_ONCE
; /* DVD+R */
110 else if (CFEqual(property
, CFSTR(kIODVDMediaTypePlusRW
)))
111 writable
= _OPTICAL_WRITABLE_PACKET
; /* DVD+RW */
112 else if (CFEqual(property
, CFSTR(kIODVDMediaTypeHDR
)))
113 writable
= _OPTICAL_WRITABLE_PACKET
| _OPTICAL_WRITABLE_ONCE
; /* HD DVD-R */
125 _optical_is_writable(const char *dev
)
131 media
= __io_media_create_from_bsd_name(dev
);
133 writable
= __io_media_is_writable(media
);
135 whole
= __io_media_copy_whole_media(media
);
137 writable
= __io_media_is_writable(whole
);
139 IOObjectRelease(whole
);
142 IOObjectRelease(media
);