에서 설명하는 IORegistry입니다. IOKit
문서는 매우 자세하고 유용합니다. IOKit Fundamentals으로 시작한 다음 Accessing Hardware from Applications을 누르고, BSD 방식으로 정보를 얻으려면 Device File Access Guide for Storage Devices을 확인하십시오.
이 경우 디스크 중재 프레임 워크에서 IO 레지스트리를 쿼리하고 알림을 등록하는 작업을 수행 할 수 있습니다. 이렇게하면 코드가 많이 절약되지만 원하는 모든 작업을 수행하려면 결국 IOMedia
객체 (DADiskCopyIOMedia()
참조)와 함께 IOKit
함수를 사용해야합니다.
IO 레지스트리에서 디스크를 나타내는 IOMedia
개체 주위에 Cocoa 래퍼를 쉽게 작성한 다음 개체 컨트롤러를 사용하여 속성을 UI에 바인딩 할 수 있습니다. 여기
당신이 시작하는 디스크 중재 프레임 워크를 통해 디스크 모양 알림에 등록의 예 :
// gcc -Wall -framework Foundation -framework DiskArbitration disk_arbiter.m -o disk_arbiter
/* @file disk_arbiter.m
* @author Jeremy W. Sherman
* @date 2009-10-03
*
* Demonstrates registering for disk appeared notifications from
* the DiskArbitration framework.
*
* Note that disk appeared notifications are delivered for all
* already-appeared disks at the time of registration, and then
* trickle in as the events actually happen thereafter.
*/
#import <Foundation/Foundation.h>
#import <DiskArbitration/DiskArbitration.h>
#import <signal.h>
sig_atomic_t sShouldExit = 0;
static void RegisterInterruptHandler(void);
static void HandleInterrupt(int);
static void OnDiskAppeared(DADiskRef disk, void *__attribute__((__unused__)));
int
main(void) {
CFStringRef const kDARunLoopMode = kCFRunLoopDefaultMode;
RegisterInterruptHandler();
// Set up session.
DASessionRef session = DASessionCreate(kCFAllocatorDefault);
DARegisterDiskAppearedCallback(session, NULL/*all disks*/, OnDiskAppeared, (void *)NULL);
DASessionScheduleWithRunLoop(session, CFRunLoopGetCurrent(), kDARunLoopMode);
// Run event loop.
printf("Starting...\n(Press Ctrl-C to exit.)\n\n");
const Boolean kAndReturnAfterHandlingSource = TRUE;
const CFTimeInterval kForOneSecond = 1.0;
while (!sShouldExit)
(void)CFRunLoopRunInMode(kCFRunLoopDefaultMode,
kForOneSecond, kAndReturnAfterHandlingSource);
// Tear down and exit.
printf("\nExiting...\n");
DASessionUnscheduleFromRunLoop(session, CFRunLoopGetCurrent(), kDARunLoopMode);
CFRelease(session);
exit(EXIT_SUCCESS);
return EXIT_SUCCESS;
}
static void
RegisterInterruptHandler(void) {
struct sigaction sigact;
sigact.sa_handler = HandleInterrupt;
(void)sigaction(SIGINT, &sigact, NULL/*discard previous handler*/);
}
static void
HandleInterrupt(int __attribute__((__unused__)) signo) {
sShouldExit = 1;
RegisterInterruptHandler();
}
static void
OnDiskAppeared(DADiskRef disk, void *__attribute__((__unused__)) ctx) {
printf("Lo, a disk appears!\n");
CFShow(disk);
}
그리고 여기 샘플 실행의 출력입니다 : 단지
$ ./disk_arbiter
Starting...
(Press Ctrl-C to exit.)
Lo, a disk appears!
<DADisk 0x104f80 [0xa01c01a0]>{id = /dev/disk3}
Lo, a disk appears!
<DADisk 0x105b40 [0xa01c01a0]>{id = /dev/disk2s1}
Lo, a disk appears!
<DADisk 0x105ae0 [0xa01c01a0]>{id = /dev/disk2s2}
Lo, a disk appears!
<DADisk 0x105b60 [0xa01c01a0]>{id = /dev/disk2}
Lo, a disk appears!
<DADisk 0x105950 [0xa01c01a0]>{id = /dev/disk1}
Lo, a disk appears!
<DADisk 0x105bc0 [0xa01c01a0]>{id = /dev/disk1s1}
Lo, a disk appears!
<DADisk 0x105540 [0xa01c01a0]>{id = /dev/disk0}
Lo, a disk appears!
<DADisk 0x105660 [0xa01c01a0]>{id = /dev/disk0s1}
Lo, a disk appears!
<DADisk 0x1054a0 [0xa01c01a0]>{id = /dev/disk0s2}
^C
Exiting...
아마도 'mount'의 목록과 유사할까요? 그렇다면 이것이 정확히 내가했던 것일 지 확신하지 못한다 :'devfs'와 같은 것들을 나열 할 것이다. 반대로 디스크 유틸리티는 OS X가 그들을 가리키는 것처럼 "볼륨"만을 나열한다. 어쩌면 ..? 그러나 이것은 아마도 내가 원했던 것을 위해 작동 할 것이고, 확실히 유용한 대답입니다 - 감사합니다! – dbr