1/* 2 * Copyright (c) 2008 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28#ifndef _KEXTD_MAIN_H 29#define _KEXTD_MAIN_H 30 31#include <CoreFoundation/CoreFoundation.h> 32#include <IOKit/kext/OSKext.h> 33 34#include <getopt.h> 35#include <sysexits.h> 36 37#include "kext_tools_util.h" 38 39 40#pragma mark Basic Types & Constants 41/******************************************************************************* 42* Basic Types & Constants 43*******************************************************************************/ 44enum { 45 kKextdExitOK = EX_OK, 46 kKextdExitError, 47 kKextdExitSigterm, 48 49 // don't actually exit with this, it's just a sentinel value 50 kKextdExitHelp = 33 51}; 52 53typedef struct { 54 mach_msg_header_t header; 55 int signum; 56} kextd_mach_msg_signal_t; 57 58 59#define kAppleSetupDonePath "/var/db/.AppleSetupDone" 60#define kKextcacheDelayStandard (60) 61#define kKextcacheDelayFirstBoot (60 * 5) 62 63#define kReleaseKextsDelay (30) 64 65#pragma mark Command-line Option Definitions 66/******************************************************************************* 67* Command-line options. This data is used by getopt_long_only(). 68* 69* Options common to all kext tools are in kext_tools_util.h. 70*******************************************************************************/ 71 72#define kOptNameNoCaches "no-caches" 73#define kOptNameDebug "debug" 74#define kOptNameNoJettison "no-jettison" 75 76#define kOptNoCaches 'c' 77#define kOptDebug 'd' 78#define kOptSafeBoot 'x' 79 80#define kOptChars "cdhqvx" 81 82/* Options with no single-letter variant. */ 83// Do not use -1, that's getopt() end-of-args return value 84// and can cause confusion 85#define kLongOptLongindexHack (-2) 86 87#pragma mark Tool Args Structure 88/******************************************************************************* 89* Tool Args Structure 90*******************************************************************************/ 91typedef struct { 92 Boolean useRepositoryCaches; 93 Boolean debugMode; 94 Boolean safeBootMode; // actual or simulated 95 96 Boolean firstBoot; 97} KextdArgs; 98 99extern CFArrayRef gRepositoryURLs; 100 101#pragma mark Function Prototypes 102/******************************************************************************* 103* Function Prototypes 104*******************************************************************************/ 105ExitStatus readArgs(int argc, char * const * argv, KextdArgs * toolArgs); 106 107void checkStartupMkext(KextdArgs * toolArgs); 108Boolean isNetboot(void); 109void sendActiveToKernel(void); 110void sendFinishedToKernel(void); 111ExitStatus setUpServer(KextdArgs * toolArgs); 112 113bool isBootRootActive(void); 114 115void handleSignal(int signum); 116void handleSignalInRunloop( 117 CFMachPortRef port, 118 void * msg, 119 CFIndex size, 120 void * info); 121 122void readExtensions(void); 123void scheduleReleaseExtensions(void); 124void releaseExtensions(CFRunLoopTimerRef timer, void * context); 125void rescanExtensions(void); 126 127void usage(UsageLevel usageLevel); 128 129#endif /* _KEXTD_MAIN_H */ 130