Exemplo n.º 1
0
int main(int argc, const char *argv[])
{
	int argi;
	bool useConsole;

	for (argi = 1; argi < argc && argv[argi][0] == '-'; argi++) {
		if (!strcmp(argv[argi], "-quiet")) {
			quiet = true;
		} else {
			fprintf(stderr, "unknown parameter `%s'\n", argv[argi]);
		}
	}

	signal(SIGHUP,  signal_handler);
	signal(SIGTERM, signal_handler);
	signal(SIGINT,  signal_handler);
	signal(SIGQUIT, signal_handler);

	DAApprovalSessionRef session = DAApprovalSessionCreate(kCFAllocatorDefault);
	if (!session) {
		fprintf(stderr, "failed to create Disk Arbitration session\n");
	} else if (argc - argi <= 0) {
		fprintf(stderr, "usage: %s [-quiet] <name> ...\n", argv[0]);
	} else {
		CFStringRef cfStringNames[argc - argi];
		if(!quiet) fprintf(stderr, "blocking:\n");
		for(nameCount = 0; nameCount < argc - argi; nameCount++) {
			if(!quiet) fprintf(stderr, "(%d) `%s'\n", nameCount + 1, argv[nameCount + argi]);
			cfStringNames[nameCount] = CFStringCreateWithCStringNoCopy(NULL, 
						argv[nameCount + argi],
						kCFStringEncodingUTF8,
						kCFAllocatorNull);
		}
		names = cfStringNames;

		DARegisterDiskMountApprovalCallback(session, NULL, BlockMount, NULL);
		DAApprovalSessionScheduleWithRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

		while (run) {
			CFRunLoopRun();
		}

		DAApprovalSessionUnscheduleFromRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
		DAUnregisterApprovalCallback(session, BlockMount, NULL);
		CFRelease(session);
	}
	return 0;
}
Exemplo n.º 2
0
static int iokit_mount (MMCDEV *mmc) {
    if (0 == mmc->is_mounted) {
        if (mmc->disk && mmc->session) {
            DADiskMount (mmc->disk, NULL, kDADiskMountOptionDefault, iokit_mount_complete, mmc);

            CFRunLoopRunInMode (kCFRunLoopDefaultMode, 10, true);

            DAApprovalSessionUnscheduleFromRunLoop (mmc->session, CFRunLoopGetCurrent (),
                                                    kCFRunLoopDefaultMode);
        }

        if (mmc->disk) {
            CFRelease (mmc->disk);
            mmc->disk = NULL;
        }

        if (mmc->session) {
            CFRelease (mmc->session);
            mmc->session = NULL;
        }
    }

    return mmc->is_mounted ? 0 : -1;
}