Annotation of driverkit/tests/fd_lib.m, revision 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:  * fd_lib.m - library routines for floppy tests
        !            26:  */
        !            27:  
        !            28: #import <bsd/fcntl.h>
        !            29: #import <ansi/stdio.h>
        !            30: #import <bsd/sys/types.h>
        !            31: #import <bsd/sys/param.h>
        !            32: #import <mach/boolean.h>
        !            33: #import <bsd/dev/fd_extern.h>
        !            34: #import <bsd/libc.h>
        !            35: #import <objc/Object.h>
        !            36: #import "fd_lib.h"
        !            37: #import <bsd/dev/disk.h>
        !            38: #import <bsd/dev/FloppyDisk.h>
        !            39: #import <bsd/dev/FloppyCntPublic.h>
        !            40: #import <driverkit/IODiskPartition.h>
        !            41: #import <mach/cthreads.h>
        !            42: 
        !            43: /*
        !            44:  * Execute a command specified in fdIoReq.
        !            45:  */
        !            46: int do_ioc(id fd, 
        !            47:        fdIoReq_t *fdIoReq, 
        !            48:        int verbose)
        !            49: {      
        !            50:        IOReturn rtn;
        !            51:        
        !            52:        fdIoReq->status = FDR_SUCCESS;
        !            53:        rtn = [fd fdCmdXfr:fdIoReq];
        !            54:        if(rtn) {
        !            55:                pr_iortn_text(fd, "fdCmdXfr", rtn);
        !            56:                rtn = 1;
        !            57:                goto check_status;
        !            58:        }
        !            59:        if(fdIoReq->num_cmd_bytes != fdIoReq->cmd_bytes_xfr) {
        !            60:                printf("Expected cmd byte count = 0x%x\n",
        !            61:                        fdIoReq->num_cmd_bytes);
        !            62:                printf("received cmd byte count = 0x%x\n",
        !            63:                        fdIoReq->cmd_bytes_xfr);
        !            64:                rtn = 1;
        !            65:                goto check_status;
        !            66:        }
        !            67:        if(fdIoReq->num_stat_bytes != fdIoReq->stat_bytes_xfr) {
        !            68:                printf("Expected cmd byte count = 0x%x\n", 
        !            69:                        fdIoReq->num_stat_bytes);
        !            70:                printf("received cmd byte count = 0x%x\n", 
        !            71:                        fdIoReq->stat_bytes_xfr);
        !            72:                rtn = 1;
        !            73:                goto check_status;
        !            74:        }
        !            75:        if(fdIoReq->byte_count != fdIoReq->bytes_xfr) {
        !            76:                printf("Expected byte count = 0x%x\n", fdIoReq->byte_count);
        !            77:                printf("received byte count = 0x%x\n", fdIoReq->bytes_xfr);
        !            78:                rtn = 1;
        !            79:                goto check_status;
        !            80:        }
        !            81:        else if(fdIoReq->bytes_xfr && verbose)
        !            82:                printf("0x%x bytes transferred\n",fdIoReq->bytes_xfr);
        !            83: check_status:
        !            84:        if(fdIoReq->status != FDR_SUCCESS) {
        !            85:                rtn = 1;
        !            86:                if(verbose) 
        !            87:                        pr_fdstat_text(fd, "fdCmdXfr", fdIoReq->status);
        !            88:        }
        !            89:        return(rtn);
        !            90: }
        !            91: 
        !            92: int seek_com(id fd, 
        !            93:        int track, 
        !            94:        struct fd_format_info *finfop, 
        !            95:        int verbose,
        !            96:        int density)
        !            97: {
        !            98:        fdIoReq_t ioreq;
        !            99:        struct fd_seek_cmd *cmdp = (struct fd_seek_cmd *)ioreq.cmd_blk;
        !           100:        
        !           101:        bzero(&ioreq, sizeof(fdIoReq_t));
        !           102:        cmdp->opcode = FCCMD_SEEK;
        !           103:        cmdp->hds = track % finfop->disk_info.tracks_per_cyl;
        !           104:        cmdp->cyl = track / finfop->disk_info.tracks_per_cyl;
        !           105:        ioreq.timeout = 2000;
        !           106:        ioreq.density = density;
        !           107:        ioreq.command = FDCMD_CMD_XFR;
        !           108:        ioreq.num_cmd_bytes = SIZEOF_SEEK_CMD;
        !           109:        ioreq.num_stat_bytes = sizeof(struct fd_int_stat);
        !           110:        if(do_ioc(fd, &ioreq, verbose))
        !           111:                return(1);
        !           112:        return(0);
        !           113: }
        !           114: 
        !           115: void pr_fdstat_text(id controller, char *op, int io_stat)
        !           116: {
        !           117:        printf("%s: fd I/O status = %s\n", 
        !           118:                op, IOFindNameForValue(io_stat, fdrValues));
        !           119: }
        !           120: 
        !           121: void pr_iortn_text(id controller, char *op, IOReturn rtn)
        !           122: {
        !           123:        printf("%s: ioReturn status = %s\n", 
        !           124:                op, [controller stringFromReturn:rtn]);
        !           125: }
        !           126: 
        !           127: 
        !           128: int fd_rw(id fd,
        !           129:        int block,
        !           130:        int block_count,
        !           131:        u_char *addrs,
        !           132:        boolean_t read_flag,
        !           133:        int lblocksize,
        !           134:        boolean_t io_trace)
        !           135: {
        !           136:        IOReturn rtn;
        !           137:        u_int length = lblocksize * block_count;
        !           138:        u_int actualLength;
        !           139:        char *read_str;
        !           140:        
        !           141:        read_str = read_flag ? "read " : "write";
        !           142:        if(io_trace)
        !           143:                printf("......%s(%d @ %d)\n", read_str, block_count, block);
        !           144:        if(read_flag) {
        !           145:                rtn = [fd readAt:block
        !           146:                        length:length
        !           147:                        buffer:addrs
        !           148:                        actualLength:&actualLength];
        !           149:        }
        !           150:        else {
        !           151:                rtn = [fd writeAt:block
        !           152:                        length:length
        !           153:                        buffer:addrs
        !           154:                        actualLength:&actualLength];
        !           155:        }
        !           156:        if(rtn) {
        !           157:                pr_iortn_text(fd, read_str, rtn);
        !           158:                return(1);
        !           159:        }                       
        !           160:        if(actualLength != length) {
        !           161:                printf("...%s(0x%x) transferred 0x%x bytes, expected 0x%x\n", 
        !           162:                        read_str, actualLength, length);
        !           163:                return(1);
        !           164:        }
        !           165:        return(0);
        !           166: } /* fd_rw() */
        !           167: 
        !           168: #ifdef notdef
        !           169: int check_mnt_ent(char *device)
        !           170: {
        !           171:        /*
        !           172:         * device is of the form "sd1", "fd0", etc. Returns 1 if an partition
        !           173:         * on device is currently mounted, else returns 0.
        !           174:         */
        !           175:        FILE *mounted;
        !           176:        struct mntent *mnt;
        !           177:        char block_device_name[40];
        !           178:        char raw_device_name[40];
        !           179:        
        !           180:        sprintf(block_device_name, "%/dev/%s", device);
        !           181:        sprintf(raw_device_name, "%/dev/r%s", device);
        !           182:        mounted = setmntent(MOUNTED, "r");
        !           183:        if (mounted == NULL) {
        !           184:                perror("setmntent");
        !           185:                return(1);
        !           186:        }
        !           187:        while ((mnt = getmntent(mounted)) != NULL) {
        !           188:                if(strncmp(raw_device_name, mnt->mnt_fsname,
        !           189:                    strlen(raw_device_name)) == 0)
        !           190:                        return(1);
        !           191:                if(strncmp(block_device_name, mnt->mnt_fsname,
        !           192:                    strlen(block_device_name)) == 0)
        !           193:                        return(1);
        !           194:        }
        !           195:        endmntent (mounted);
        !           196:        return(0);
        !           197: }
        !           198: #endif notdef
        !           199: 
        !           200: int get_drive_params(id fd, 
        !           201:        int *end_sect, 
        !           202:        int *sectsize,
        !           203:        int *blocks_per_xfr,
        !           204:        boolean_t read_only)
        !           205: {
        !           206:        struct  disk_label label;
        !           207:        int     label_valid = 0;
        !           208:        IOReturn rtn;
        !           209:        struct  fd_format_info  format_info;
        !           210:        char    c[80];
        !           211:        id      logicalId;
        !           212:        
        !           213:        /*
        !           214:         * See if there is an IODiskPartition attached, and if it has a valid label.
        !           215:         */
        !           216:        logicalId = [fd logicalDisk];
        !           217:        if(logicalId != nil) {
        !           218:                rtn = [fd readLabel:&label];
        !           219:                if(rtn == IO_R_SUCCESS) {
        !           220:                        if(!read_only)
        !           221:                        {
        !           222:                                printf("Disk Has Valid Label. Continue "
        !           223:                                        "(Y/anything)? ");
        !           224:                                gets(c);
        !           225:                                if(c[0] != 'Y')
        !           226:                                        return(1);
        !           227:                        }
        !           228:                        label_valid = 1;
        !           229:                }
        !           230:        }
        !           231: 
        !           232:        /*
        !           233:         * get physical device info
        !           234:         */
        !           235:        rtn = [fd fdGetFormatInfo:&format_info];
        !           236:        if(rtn) {
        !           237:                pr_iortn_text(fd, "getFormatInfo", rtn);
        !           238:                return(1);
        !           239:        }
        !           240:        if(!(format_info.flags & FFI_FORMATTED)) {
        !           241:                printf("Disk Not Formatted; aborting.\n");
        !           242:                return(1);
        !           243:        }
        !           244:        if(label_valid && !read_only) {
        !           245:                /*
        !           246:                 * Mark label invalid. We're about to blow it away.
        !           247:                 */
        !           248:                rtn = [fd fdSetSectSize:format_info.sectsize_info.sect_size];
        !           249:                if(rtn) {
        !           250:                        pr_iortn_text(fd, "setSectSize", rtn);
        !           251:                        return(1);
        !           252:                }
        !           253:        }
        !           254:        *sectsize = format_info.sectsize_info.sect_size;
        !           255:        if(*end_sect == 0)
        !           256:                *end_sect = format_info.total_sects - 1;
        !           257:        else if(*end_sect > format_info.total_sects - 1) {
        !           258:                printf("Disk capacity %d sectors; end_sect %d "
        !           259:                        "specified. ABORTING.\n", 
        !           260:                        format_info.total_sects, end_sect);
        !           261:                return(1);
        !           262:        }
        !           263:        if(*blocks_per_xfr == 0) {
        !           264:                *blocks_per_xfr = 
        !           265:                        format_info.sectsize_info.sects_per_trk;
        !           266:        }
        !           267:        return(0);
        !           268: }

unix.superglobalmegacorp.com

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