Annotation of driverkit/tests/write.m, revision 1.1.1.1

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:  * write.c.
                     26:  */
                     27: 
                     28: #import <bsd/sys/types.h> 
                     29: #import <ansi/stdio.h>
                     30: #import <mach/kern_return.h>
                     31: #import <mach/mach.h>
                     32: #import <ansi/stdlib.h>
                     33: #import "defaults.h"
                     34: #import "buflib.h"
                     35: #import <remote/NXConnection.h>
                     36: #import <driverkit/IODisk.h>
                     37: #import <driverkit/IODiskRwDistributed.h>
                     38: 
                     39: void usage(char **argv);
                     40: void exit(int exitcode);
                     41: void fill_buf(u_char *p, int size, char d);
                     42: void mach_error(char *c, kern_return_t e);
                     43: 
                     44: int main(int argc, char **argv) {
                     45: 
                     46:        int             arg;
                     47:        char            c;
                     48:        id              targetId;
                     49:        IOReturn        rtn;
                     50:        IOData          *wdata;
                     51:        u_int           bytes_xfr;
                     52:        const char      *outstr;
                     53:        
                     54:        /*
                     55:         * user-spec'd variables 
                     56:         */
                     57:        u_int           byte_count=BYTE_COUNT_DEFAULT;  /* bytes to write */
                     58:        u_int           block_num=0;            
                     59:        char            *hostname=HOST_DEFAULT;
                     60:        char            *devname=DEVICE_DEFAULT;
                     61:        char            data_patt = 'z';
                     62:        
                     63:        /*
                     64:         * Get standard defaults from environment or defaults.h
                     65:         */
                     66:        get_default("byte_count", &byte_count, BYTE_COUNT_DEFAULT);
                     67:        get_default_t("hostname", &hostname, HOST_DEFAULT);
                     68:        get_default_t("devname", &devname, DEVICE_DEFAULT);
                     69: 
                     70:        for(arg=1; arg<argc; arg++) {
                     71:                c = argv[arg][0];
                     72:                switch(c) {
                     73:                    case 'y':
                     74:                        byte_count = atoi(&argv[arg][2]);
                     75:                        break;
                     76:                    case 'h':
                     77:                        hostname = &argv[arg][2];
                     78:                        break;
                     79:                    case 'd':
                     80:                        devname = &argv[arg][2];
                     81:                        break;
                     82:                    case 'b':
                     83:                        block_num = atoi(&argv[arg][2]);
                     84:                        break;
                     85:                    case 'p':
                     86:                        data_patt = argv[arg][2];
                     87:                        break;
                     88:                    default:
                     89:                        usage(argv);
                     90:                }
                     91:        }
                     92: #if    IOSERVER
                     93:        rtn = [IOClient clientOpen:devname 
                     94:                hostName:hostname
                     95:                intentions:IO_INT_WRITE
                     96:                idp:&targetId];
                     97:        if(rtn) {
                     98:                [IOClient ioError:rtn 
                     99:                          logString:"clientOpen"
                    100:                          outString:outstr];
                    101:                printf(outstr);
                    102:                exit(1);
                    103:        }
                    104: #else  IOSERVER
                    105:        /*
                    106:         * RO way...
                    107:         */
                    108:        targetId = [NXConnection connectToName:devname
                    109:                                         onHost:hostname];
                    110:        if(targetId == nil) {
                    111:                printf("connectToName:%s failed\n", devname);
                    112:                exit(1);
                    113:        }
                    114: #endif IOSERVER
                    115:        wdata = [[IOData alloc] initWithSize:byte_count];
                    116:        [wdata setFreeFlag:YES];
                    117:        fill_buf((u_char *)[wdata data], (int)byte_count, data_patt);
                    118:        rtn = [targetId writeAt:block_num
                    119:                        length:byte_count
                    120:                        data:wdata
                    121:                        actualLength:&bytes_xfr];
                    122:        if(rtn != IO_R_SUCCESS) {
                    123:                outstr = [targetId stringFromReturn:rtn];
                    124:                printf("write: %s\n", outstr);
                    125:                exit(1);
                    126:        }
                    127:        if(bytes_xfr != byte_count) {
                    128:                printf("bytes_xfr = %d; expected %d\n", bytes_xfr, byte_count);
                    129:        }       
                    130:        else
                    131:                printf("...ok\n");
                    132:        exit(0);
                    133: 
                    134: } /* main() */
                    135: 
                    136: void usage(char **argv) {
                    137:        printf("usage: %s [y=byte_count] [b=block_num] [p={z,1,i,d}] [h=hostname] [d=devname]\n", argv[0]);
                    138:        exit(1);
                    139: }
                    140: 
                    141: void fill_buf(u_char *buf, int size, char data_patt) {
                    142: 
                    143:        int i;
                    144:        
                    145:        for(i=0; i<size; i++) {
                    146:                switch(data_patt) {
                    147:                    case 'z':
                    148:                        *buf++ = 0;
                    149:                        break;
                    150:                    case '1':
                    151:                        *buf++ = 0xff;
                    152:                        break;
                    153:                    case 'i':
                    154:                        *buf++ = (u_char)i;
                    155:                        break;
                    156:                    case 'd':
                    157:                        *buf++ = 0xff - (u_char)i;
                    158:                        break;
                    159:                    default:
                    160:                        printf("bogus data_patt (%c) in fill_buf()\n", 
                    161:                                data_patt);
                    162:                        exit(1);
                    163:                }
                    164:        }
                    165: } /* fill_buf() */
                    166: 
                    167: 
                    168: 
                    169: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.