Annotation of driverkit/Examples/UnixDisk/FloppyDisk.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: /*     FloppyDisk.m    1.0     01/02/91        (c) 1991 NeXT   
                     25:  *
                     26:  * FloppyDisk.m - Implementation for Floppy Disk class. 
                     27:  *
                     28:  * HISTORY
                     29:  * 01-Feb-91    Doug Mitchell at NeXT
                     30:  *      Created. 
                     31:  */
                     32:  
                     33: #import "FloppyDisk.h"
                     34: #import <bsd/sys/types.h>
                     35: #import <bsd/dev/fd_extern.h>
                     36: #import <bsd/libc.h>
                     37: #import <bsd/sys/file.h>
                     38: #import <bsd/dev/disk.h>
                     39: #import <errno.h>
                     40: #import "unixDiskUxpr.h"
                     41: #import <driverkit/volCheck.h>
                     42: 
                     43: #define NUM_FLOPPY_THREADS     2
                     44: #define FLOPPY_RAW_NAME                "fd"
                     45: 
                     46: @implementation FloppyDisk
                     47: 
                     48: /*
                     49:  * Probe hardware to determine how many instances to alloc and init. This 
                     50:  * is a hard coded kludge for now.
                     51:  */
                     52: #if    0
                     53: + (void)IOProbe:serverId
                     54: {
                     55:        int     floppy_unit;
                     56:        id      floppyId = nil;
                     57:        
                     58:        /*
                     59:         * Attempt to instantiate and init each possible floppy disk.
                     60:         */
                     61:        for(floppy_unit=FLOPPY_UNIT_MIN; 
                     62:            floppy_unit<=FLOPPY_UNIT_MAX; 
                     63:            floppy_unit++) {
                     64:                if(floppyId == nil)
                     65:                        floppyId = [self alloc];
                     66:                
                     67:                /*
                     68:                 * Avoid free/alloc if this init fails.
                     69:                 */
                     70:                if([floppyId floppyInit:floppy_unit 
                     71:                    sender:serverId] == nil) 
                     72:                        continue;
                     73:                else {
                     74:                        /*
                     75:                         * Success. Have DiskObject superclass take care of 
                     76:                         * the rest.
                     77:                         */
                     78:                        [floppyId registerDevice];
                     79:                        [floppyId registerDisk];
                     80:                        floppyId = nil;
                     81:                }
                     82:        }
                     83:        if(floppyId)
                     84:                [floppyId free];
                     85: }
                     86: #endif 0
                     87: 
                     88: /*
                     89:  * init one instance for specified disk.
                     90:  */
                     91: - floppyInit:(int)diskNum
                     92: {
                     93:        char *name;
                     94:        int thread_num;
                     95:        
                     96:        xpr_ud("FloppyDisk : init: unit %d\n", diskNum, 2,3,4,5);
                     97:        
                     98:        [self setUnit:diskNum];
                     99:        name = malloc(10);
                    100:        sprintf(name, "%s%d", FLOPPY_RAW_NAME, diskNum);
                    101:        [self setName:(const char *)name];
                    102:        [self setDeviceKind:"Unix Floppy Disk"];
                    103:        [self setLocation:NULL];
                    104:        [self setDriveName:"Sony Floppy"];
                    105:        [self setDiskType:PR_DRIVE_FLOPPY];
                    106:        [self setWriteProtected:0];
                    107:        
                    108:        /*
                    109:         * Do a unix open  for each thread. All I/O here goes thru the live 
                    110:         * partition.
                    111:         */
                    112:        sprintf(unix_name, "/dev/rfd%db", diskNum);
                    113:        for(thread_num=0; thread_num<NUM_FLOPPY_THREADS; thread_num++) {
                    114:                unix_fd[thread_num] = open(unix_name, O_RDWR, 0);
                    115:                if(unix_fd[thread_num] < 0) {
                    116:                
                    117:                        /*
                    118:                         * Maybe it's read-only.
                    119:                         */
                    120:                        unix_fd[thread_num] = open(unix_name, O_RDONLY, 0);
                    121:                        if(unix_fd[thread_num] < 0) {
                    122:                                perror("floppyInit open()");
                    123:                                return(nil);
                    124:                        }
                    125:                        [self setWriteProtected:1];
                    126:                }
                    127:        }
                    128:        
                    129:        /*
                    130:         * Let superclass take care of initializing inherited instance
                    131:         * variables.
                    132:         */
                    133:        [self unixInit:NUM_FLOPPY_THREADS];
                    134:        if([self updatePhysicalParameters])
                    135:                return nil;
                    136:        return self;
                    137: }
                    138: 
                    139: /*
                    140:  * Get physical parameters (dev_size, block_size, etc.) from new disk.
                    141:  */
                    142: - (IOReturn)updatePhysicalParameters
                    143: {
                    144:        struct fd_format_info format_info;
                    145:        int rtn;
                    146:                
                    147:        /*
                    148:         * try to get format info of the drive.
                    149:         */
                    150:        [self setFormattedInternal:0];
                    151:        [self setRemovable:1];
                    152:        rtn = ioctl(unix_fd[0], FDIOCGFORM, &format_info);
                    153:        if(rtn) {
                    154:                xpr_ud("FloppyDisk FDIOCGFORM: errno %d\n", errno, 2,3,4,5);
                    155:                return(IO_R_IO);
                    156:        }
                    157:        if(!(format_info.flags & FFI_FORMATTED)) {
                    158:                xpr_ud("FloppyDisk Unformatted\n", errno, 2,3,4,5);
                    159:                [self setBlockSize:-1];
                    160:                [self setDiskSize:0];   
                    161:        }
                    162:        else {
                    163:                [self setFormattedInternal:1];
                    164:                [self setBlockSize:format_info.sectsize_info.sect_size];
                    165:                [self setDiskSize:format_info.total_sects];
                    166:        }
                    167:        if(format_info.flags & FFI_WRITEPROTECT) {
                    168:                [self setWriteProtected:1];
                    169:        }
                    170:        else {
                    171:                [self setWriteProtected:0];
                    172:        }
                    173:        return(IO_R_SUCCESS);
                    174: }
                    175: 

unix.superglobalmegacorp.com

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