1/* 2 * Copyright (c) 2001-2007 Apple 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/* 24 * minibless.c 25 * bless 26 * 27 * Created by Shantonu Sen <ssen@apple.com> on Mon Aug 25 2003. 28 * Copyright (c) 2003-2007 Apple Inc. All Rights Reserved. 29 * 30 * $Id: minibless.c,v 1.12 2006/07/18 22:09:51 ssen Exp $ 31 * 32 */ 33 34#include <stdlib.h> 35#include <stdio.h> 36#include <string.h> 37#include <stdarg.h> 38#include <unistd.h> 39#include <sys/stat.h> 40#include <sys/mount.h> 41#include <err.h> 42 43#include "bless.h" 44#include "bless_private.h" 45#include "protos.h" 46 47void miniusage(char *program); 48 49int main(int argc, char *argv[]) { 50 51 char *mountpath = NULL; 52 char *device = NULL; 53 struct statfs sb; 54 55 56 if(argc != 2) 57 miniusage(argv[0]); 58 59 mountpath = argv[1]; 60 61 if(0 != statfs(mountpath, &sb)) { 62 err(1, "Can't access %s", mountpath); 63 } 64 65 device = sb.f_mntfromname; 66 67 // normally i would object to using preprocessor macros for harware 68 // tests on principle. in this case, we do this so that IOKit 69 // features and stuff that only apply to 10.4 and greater are only 70 // linked in for the i386 side, for instance if we were to use per-arch 71 // SDKs in the future. 72#ifdef __ppc__ 73 if(!BLIsOpenFirmwarePresent(NULL)) { 74 errx(1, "OpenFirmware not present"); 75 } 76 77 if(0 != BLSetOpenFirmwareBootDevice(NULL, device)) { 78 errx(1, "Can't set OpenFirmware"); 79 } 80#else 81#if defined(__i386__) || defined(__x86_64__) 82 if(0 != setefidevice(NULL, device + 5 /* strlen("/dev/") */, 83 0, 84 0, 85 NULL, 86 NULL, 87 false)) { 88 errx(1, "Can't set EFI"); 89 } 90 91#else 92#error wha????? 93#endif 94#endif 95 96 return 0; 97} 98 99void miniusage(char *program) 100{ 101 FILE *mystderr = fdopen(STDERR_FILENO, "w"); 102 103 if(mystderr == NULL) 104 err(1, "Can't open stderr"); 105 106 fprintf(mystderr, "Usage: %s mountpoint\n", program); 107 exit(1); 108} 109 110// we don't implement output 111int blesscontextprintf(BLContextPtr context, int loglevel, char const *fmt, ...) { 112 return 0; 113} 114