|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: /* ! 25: * gparms.m ! 26: */ ! 27: ! 28: #import <bsd/sys/types.h> ! 29: #import <driverkit/IODisk.h> ! 30: #import <ansi/stdio.h> ! 31: #import <bsd/libc.h> ! 32: #import "defaults.h" ! 33: #import "buflib.h" ! 34: #import <bsd/dev/disk.h> ! 35: #import <remote/NXConnection.h> ! 36: #import <driverkit/IODisk.h> ! 37: #import <driverkit/IODiskRwDistributed.h> ! 38: #import <driverkit/IODiskPartition.h> ! 39: #import <objc/error.h> ! 40: #import <remote/NXProxy.h> ! 41: ! 42: void usage(char **argv); ! 43: void exit(int exitcode); ! 44: ! 45: int main(int argc, char **argv) { ! 46: ! 47: char *hostname=HOST_DEFAULT; ! 48: char *devname=DEVICE_DEFAULT; ! 49: int arg; ! 50: char c; ! 51: id targetId; ! 52: IOReturn rtn; ! 53: unsigned formatted, removable; ! 54: struct disk_label label; ! 55: unsigned blocksize, devsize; ! 56: ! 57: /* ! 58: * Get standard defaults from environment or defaults.h ! 59: */ ! 60: get_default_t("hostname", &hostname, HOST_DEFAULT); ! 61: get_default_t("devname", &devname, DEVICE_DEFAULT); ! 62: ! 63: for(arg=1; arg<argc; arg++) { ! 64: c = argv[arg][0]; ! 65: switch(c) { ! 66: case 'h': ! 67: hostname = &argv[arg][2]; ! 68: break; ! 69: case 'd': ! 70: devname = &argv[arg][2]; ! 71: break; ! 72: default: ! 73: usage(argv); ! 74: } ! 75: } ! 76: ! 77: targetId = [NXConnection connectToName:devname ! 78: onHost:hostname]; ! 79: if(targetId == nil) { ! 80: printf("connectToName:%s failed\n", devname); ! 81: exit(1); ! 82: } ! 83: removable = [targetId isRemovable]; ! 84: printf("removable : %s\n", removable ? "TRUE" : "FALSE"); ! 85: ! 86: /* ! 87: * Should do readLabel before getFormatted to fault in possible ! 88: * ejected disk. ! 89: */ ! 90: NX_DURING ! 91: rtn = [targetId readLabel:&label]; ! 92: NX_HANDLER ! 93: if(NXLocalHandler.code == NX_unknownMethodException) { ! 94: /* ! 95: * Not an IODiskPartition. This is OK. ! 96: */ ! 97: rtn = IO_R_NO_LABEL; ! 98: } ! 99: else { ! 100: printf("Unexpected exception (%d) on readLabel; aborting\n", ! 101: NXLocalHandler.code); ! 102: exit(1); ! 103: } ! 104: NX_ENDHANDLER ! 105: printf("labelValid: "); ! 106: switch(rtn) { ! 107: case IO_R_SUCCESS: ! 108: printf("TRUE\n"); ! 109: break; ! 110: case IO_R_NO_LABEL: ! 111: printf("FALSE\n"); ! 112: break; ! 113: default: ! 114: printf("***Unsupported Op***\n"); ! 115: break; ! 116: } ! 117: ! 118: formatted = [targetId isFormatted]; ! 119: printf("formatted : %s\n", formatted ? "TRUE" : "FALSE"); ! 120: blocksize = [targetId blockSize]; ! 121: devsize = [targetId diskSize]; ! 122: printf("blocksize : %d\n", blocksize); ! 123: printf("devsize : %d\n", devsize); ! 124: exit(0); ! 125: ! 126: } /* main() */ ! 127: ! 128: void usage(char **argv) { ! 129: printf("usage: %s [h=hostname] [d=devname]\n", argv[0]); ! 130: exit(1); ! 131: } ! 132: ! 133: ! 134: ! 135:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.