Annotation of driverkit/notes/LogicalDisk_revisited, revision 1.1.1.1

1.1       root        1:                    LogicalDisk and NXDisk notes
                      2:        
                      3:            
                      4: r/w
                      5:    device:     raw, block - _blockSize = dtp->d_secsize
                      6:                live - _blockSize = physical block size
                      7:    limitations:        works on live as long as disk is formatted (checked by
                      8:                        phys device)
                      9:                works on raw and block only when label valid (checked by
                     10:                        NXDisk)
                     11:    effects:    faults in non-present disk (by LogicalDisk)
                     12:                
                     13: read label
                     14:    device:     raw (any partition?)
                     15:    limitations:        physDev must be formatted (checked by NXDisk)
                     16:    effects:    faults in non-present disk (by NXDisk)
                     17:    
                     18: write label
                     19:    device:     raw (any partition?)
                     20:    limitations: physDev must be formatted (checked by NXDisk)
                     21:                no block devices must be open (currently, maybe this won't
                     22:                        work...)
                     23:    effects:    frees all block devices
                     24:                does a _probeLabel:, possibly creating new instances
                     25:                
                     26: eject
                     27:    device:     raw
                     28:    limitations:        rejected by IODiskDevice ejectDisk if:
                     29:                        -- not removable
                     30:                        -- any block devices are open
                     31:                        -- physDevice and any logical disks attached
                     32:                rejected by NXDisk devEjectDisk if not raw device
                     33:    effects:    formatted = 0 by [IODiskDevice ejectDisk]
                     34:                all block devices freed by {NXDisk devEjectDisk]
                     35:                label invalid by [NXDisk devEjectDisk]
                     36:    
                     37: set formatted
                     38:    device:     raw
                     39:    limitations:        no logical disks upstream can be open (checked in
                     40:                        IODiskDevice's setFormatted:)
                     41:    effects:    calls getPhysParams if setting formatted true
                     42:                calls setFormattedInt - this frees all block devices and
                     43:                        negates labelValid in NXDisk
                     44:    
                     45: faulting in non-present disk
                     46:    device:     live, raw partition 0 (other raw partitions non-existent
                     47:                        when no disk present)
                     48:    limitations: none
                     49:    effects:    NXDiskProbe invoked by volCheck thread. This reads a label
                     50:                        and creates NXDisk partition instances per label info.
                     51:                        volCheck thread blocks the whole time NXDiskProbe
                     52:                        is running.
                     53:                        
                     54: NXDiskProbe
                     55:    device:     none - NXDisk factory method, operates on physDevice
                     56:    limitations: none - called ragardless of physDev state
                     57:    effects:    AS IS:
                     58:                        creates raw device if one doesn't exist
                     59:                        registerUnixDisk for both physDev and raw device
                     60:                        check ready loop, init lastReadyState
                     61:                        getPhysParams if newly ready
                     62:                        if not formatted or not ready, done
                     63:                        read a label
                     64:                        if good, probeLabel:
                     65:    
                     66: probeLabel
                     67:    device:     raw
                     68:    limitations:        assumes that label is good and disk is present
                     69:    effects:    updates state of raw dev params per label
                     70:                creates and inits one block device per partition
                     71:                
                     72: .............
                     73: Changes:
                     74: 
                     75: Instead of "are any logical disks upstream open" ([IOLoogicalDisk isOpen]) we really need "are any other logical disks in the chain other than me". This is for hazardous ops on the raw device like eject and setFormatted which require this to be the only open device.
                     76: 
                     77: IOLogicalDisk anyOtherOpen
                     78: {
                     79:        logicalDisk = [physDev logicalDisk];
                     80:        while(logicalDisk) {
                     81:                if(logicalDisk != self) {
                     82:                        if([logicalDisk diskIsOpen]
                     83:                                return 1;
                     84:                }
                     85:                logicalDisk = [logicalDisk logicalDisk];
                     86:        }
                     87: }
                     88: ................
                     89: 
                     90: Just have one NXDisk instance per partition. At the NXDisk level there is almost no difference between a block device and a raw device. Change "_diskIsOpen" to "blockDevOpen" and "RawDevOpen". Sometime we only care if any block devices are open (like when writing a label or ejecting); sometimes we want to know if ANY "other" devices are open (use anyOtherOpen).
                     91: ................
                     92: setting the formatted flag - current implementation is hosed.
                     93: Sould be:
                     94: 
                     95:    device:     NXDisk (though has to work properly on live device!)
                     96:    limitations:        no other logical disks can be open
                     97:                no block devices can be open 
                     98:                (Both checked in [IODiskDevice setFormatted]
                     99:    effects:    invalidates label
                    100:                frees all NXDisks except for first one
                    101:                updates physParams for physDevice of setting formatted TRUE
                    102:    
                    103: /*
                    104:  * Public version for physDevice.
                    105:  */
                    106: IODiskDevice setFormatted
                    107: {
                    108:        if ANY logical disks open
                    109:                abort
                    110:        update _formatted;
                    111:        if setting true, [self getPhysParams]
                    112:        if logicalDisk {
                    113:                [logicalDisk setFormattedInt]
                    114:        }
                    115: }
                    116: 
                    117: /*
                    118:  * Public version for NXDisk.
                    119:  */
                    120: NXDisk setFormatted
                    121: {
                    122:        if any block devices open
                    123:                abort
                    124:        if any other logical devices open 
                    125:                abort
                    126:        [physDev setFormattedInt]
                    127:        if setting true
                    128:                [physDev getPhysParams]
                    129:        [self setFormattedInt]
                    130: }
                    131: 
                    132: /*
                    133:  * Internal version for physDevice.
                    134:  */
                    135: IODiskDevice setFormattedInt
                    136: {
                    137:        update _formatted;
                    138: }
                    139: 
                    140: /*
                    141:  * Internal version for NXDisk.
                    142:  */
                    143: NXDisk setFormattedInt
                    144: {
                    145:        free NXDisks other than partition 0
                    146:        mark label invalid and update _formatted;
                    147: }
                    148: 
                    149: ............
                    150: 
                    151: other new restrictions:
                    152: 
                    153: anything that blows away NXDisk instances (write label, eject, setFormatted) must be done on the 'a' partition since that's the only one which survives. I think this should be reasonable restriction....
                    154: .............
                    155: 
                    156: ejecting - kind of like setFormatted...
                    157: 
                    158: IODiskDevice ejectDisk
                    159: {
                    160:        if ANY logical disks attached
                    161:                abort
                    162:        [self devEjectDisk];    // to subclass, like SCSIDisk...
                    163:        _formatted = 0;
                    164: }
                    165: 
                    166: NXDisk ejectDisk
                    167: {
                    168:        if any block devices open
                    169:                abort
                    170:        if any other logical devices open 
                    171:                abort
                    172:        if this not partition 0
                    173:                abort
                    174:        [physDev devEjectDisk]
                    175:        invalidate label
                    176:        freePartitions
                    177: }
                    178: 
                    179: IODiskDevice devEjectDisk
                    180: {
                    181:        ...implemented by subclass...
                    182: }

unix.superglobalmegacorp.com

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