Annotation of driverkit/libDriver/i386/disk_label.c, 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: /* Copyright (c) 1992 by NeXT Computer, Inc.
                     25:  *
                     26:  *     File:   i386/disk_label.c - trivial native (i386) implementation
                     27:  *             of disk_label conversion API.
                     28:  *
                     29:  * HISTORY
                     30:  * 01-Apr-92  Doug Mitchell at NeXT
                     31:  *     Created.
                     32:  */
                     33:  
                     34: #import <bsd/dev/disk_label.h>
                     35: #import <driverkit/diskstruct.h>
                     36: #import <bsd/string.h>
                     37: #import <architecture/byte_order.h>
                     38: 
                     39: static inline void get_char(const char *src, char *dest)
                     40: {
                     41:        *dest = *src;
                     42: }
                     43: 
                     44: static inline void get_short(const char *src, char *dest)
                     45: {
                     46:        *((unsigned short *)dest) =
                     47:                        NXSwapBigShortToHost(*((unsigned short *)src));
                     48: }
                     49: 
                     50: static inline void get_word(const char *src, char *dest)
                     51: {
                     52:        *((unsigned int *)dest) =
                     53:                        NXSwapBigIntToHost(*((unsigned int *)src));
                     54: }
                     55: 
                     56: static inline void put_char(const char *src, char *dest)
                     57: {
                     58:        *dest = *src;
                     59: }
                     60: 
                     61: static inline void put_short(const char *src, char *dest)
                     62: {
                     63:        *((unsigned short *)dest) =
                     64:                        NXSwapHostShortToBig(*((unsigned short *)src));
                     65: }
                     66: 
                     67: static inline void put_word(const char *src, char *dest)
                     68: {
                     69:        *((unsigned int *)dest) =
                     70:                        NXSwapHostIntToBig(*((unsigned int *)src));
                     71: }
                     72: 
                     73: 
                     74: /*
                     75:  * Convert from native (m68k) disk structs to m88k. Used when reading
                     76:  * from disk.
                     77:  */
                     78: void get_partition(const char *source, partition_t *dest)
                     79: {
                     80:        get_word(source + PARTITION_P_BASE, (char *)&dest->p_base);
                     81:        get_word(source + PARTITION_P_SIZE, (char *)&dest->p_size);
                     82:        get_short(source + PARTITION_P_BSIZE, (char *)&dest->p_bsize);
                     83:        get_short(source + PARTITION_P_FSIZE, (char *)&dest->p_fsize);
                     84:        get_char(source + PARTITION_P_OPT, (char *)&dest->p_opt);
                     85:        get_short(source + PARTITION_P_CPG, (char *)&dest->p_cpg);
                     86:        get_short(source + PARTITION_P_DENSITY, (char *)&dest->p_density);
                     87:        get_char(source + PARTITION_P_MINFREE, (char *)&dest->p_minfree);
                     88:        get_char(source + PARTITION_P_NEWFS, (char *)&dest->p_newfs);
                     89:        bcopy(source + PARTITION_P_MOUNTPT, dest->p_mountpt, MAXMPTLEN);
                     90:        get_char(source + PARTITION_P_AUTOMNT, (char *)&dest->p_automnt);
                     91:        bcopy(source + PARTITION_P_TYPE, dest->p_type, MAXFSTLEN);
                     92: }
                     93: 
                     94: void get_disktab(const char *source, disktab_t *dest)
                     95: {
                     96:        int part_num;
                     97:        int i;
                     98:        unsigned char *bblk_src, *bblk_dst;
                     99:        
                    100:        bcopy(source + DISKTAB_D_NAME, dest->d_name, MAXDNMLEN);
                    101:        bcopy(source + DISKTAB_D_TYPE, dest->d_type, MAXTYPLEN);
                    102:        get_word(source + DISKTAB_D_SECSIZE, (char *)&dest->d_secsize);
                    103:        get_word(source + DISKTAB_D_NTRACKS, (char *)&dest->d_ntracks);
                    104:        get_word(source + DISKTAB_D_NSECTORS, (char *)&dest->d_nsectors);
                    105:        get_word(source + DISKTAB_D_NCYLINDERS, (char *)&dest->d_ncylinders);
                    106:        get_word(source + DISKTAB_D_RPM, (char *)&dest->d_rpm);
                    107:        get_short(source + DISKTAB_D_FRONT, (char *)&dest->d_front);
                    108:        get_short(source + DISKTAB_D_BACK, (char *)&dest->d_back);
                    109:        get_short(source + DISKTAB_D_NGROUPS, (char *)&dest->d_ngroups);
                    110:        get_short(source + DISKTAB_D_AG_SIZE, (char *)&dest->d_ag_size);
                    111:        get_short(source + DISKTAB_D_AG_ALTS, (char *)&dest->d_ag_alts);
                    112:        get_short(source + DISKTAB_D_AG_OFF, (char *)&dest->d_ag_off);
                    113:        if (NBOOTS){
                    114:                bblk_src = (unsigned char *)(source + DISKTAB_D_BOOT0_BLKNO);
                    115:                bblk_dst = (unsigned char *)&dest->d_boot0_blkno;
                    116:                for (i = 0; i < (NBOOTS) ; i++){
                    117:                        get_word(bblk_src, bblk_dst);
                    118:                        bblk_src += sizeof(int);
                    119:                        bblk_dst += sizeof(int);
                    120:                }
                    121:        }
                    122:        bcopy(source + DISKTAB_D_BOOTFILE, dest->d_bootfile, MAXBFLEN);
                    123:        bcopy(source + DISKTAB_D_HOSTNAME, dest->d_hostname, MAXHNLEN);
                    124:        get_char(source + DISKTAB_D_ROOTPARTITION, 
                    125:                 (char *)&dest->d_rootpartition);
                    126:        get_char(source + DISKTAB_D_RWPARTITION, (char *)&dest->d_rwpartition);
                    127:        for(part_num=0; part_num<NPART; part_num++) {
                    128:                get_partition(source + DISKTAB_D_PARTITIONS + 
                    129:                        (part_num * SIZEOF_PARTITION_T),
                    130:                        &dest->d_partitions[part_num]);
                    131:        }
                    132: }
                    133: 
                    134: void get_dl_un(const char *source, dl_un_t *dest)
                    135: {
                    136:        int i;
                    137:        
                    138:        for(i=0; i<NBAD; i++) {
                    139:                get_word(source, (char *)&dest->DL_bad[i]);
                    140:                source += sizeof(int);
                    141:        }
                    142: }
                    143: 
                    144: void get_disk_label(const char *source, disk_label_t *dest)
                    145: {
                    146:        get_word(source + DISK_LABEL_DL_VERSION, (char *)&dest->dl_version);
                    147:        get_word(source + DISK_LABEL_DL_LABEL_BLKNO, 
                    148:                (char *)&dest->dl_label_blkno);
                    149:        get_word(source + DISK_LABEL_DL_SIZE, (char *)&dest->dl_size);
                    150:        bcopy(source + DISK_LABEL_DL_LABEL, dest->dl_label, MAXLBLLEN);
                    151:        get_word(source + DISK_LABEL_DL_FLAGS, (char *)&dest->dl_flags);
                    152:        get_word(source + DISK_LABEL_DL_TAG, (char *)&dest->dl_tag);
                    153:        get_disktab(source + DISK_LABEL_DL_DT, &dest->dl_dt);
                    154:        get_dl_un(source + DISK_LABEL_DL_UN, &dest->dl_un);
                    155:        get_short(source + DISK_LABEL_DL_CHECKSUM, (char *)&dest->dl_checksum);
                    156:        get_short(source + DISK_LABEL_DL_UN, (char *)&dest->dl_v3_checksum);
                    157: }
                    158: 
                    159: /*
                    160:  * Convert from m88k disk structs to native (m68k). Used when writing
                    161:  * to disk.
                    162:  */
                    163: void put_partition(const partition_t *source, char *dest)
                    164: {
                    165:        put_word((const char *)&source->p_base, dest + PARTITION_P_BASE);
                    166:        put_word((const char *)&source->p_size, dest + PARTITION_P_SIZE);
                    167:        put_short((const char *)&source->p_bsize, dest + PARTITION_P_BSIZE);
                    168:        put_short((const char *)&source->p_fsize, dest + PARTITION_P_FSIZE);
                    169:        put_char((const char *)&source->p_opt, dest + PARTITION_P_OPT);
                    170:        put_short((const char *)&source->p_cpg, dest + PARTITION_P_CPG);
                    171:        put_short((const char *)&source->p_density, dest + 
                    172:                PARTITION_P_DENSITY);
                    173:        put_char((const char *)&source->p_minfree, dest + PARTITION_P_MINFREE);
                    174:        put_char((const char *)&source->p_newfs, dest + PARTITION_P_NEWFS);
                    175:        bcopy(source->p_mountpt, dest + PARTITION_P_MOUNTPT, MAXMPTLEN);
                    176:        put_char((const char *)&source->p_automnt, dest + PARTITION_P_AUTOMNT);
                    177:        bcopy(source->p_type, dest + PARTITION_P_TYPE, MAXFSTLEN);
                    178: }
                    179: 
                    180: void put_disktab(const disktab_t *source, char *dest)
                    181: {
                    182:        int part_num;
                    183:        unsigned char *bblk_src, *bblk_dst;
                    184:        int i;
                    185:        
                    186:        bcopy(source->d_name, dest + DISKTAB_D_NAME, MAXDNMLEN);
                    187:        bcopy(source->d_type, dest + DISKTAB_D_TYPE, MAXTYPLEN);
                    188:        put_word((const char *)&source->d_secsize, dest + DISKTAB_D_SECSIZE);
                    189:        put_word((const char *)&source->d_ntracks, dest + DISKTAB_D_NTRACKS);
                    190:        put_word((const char *)&source->d_nsectors, dest + DISKTAB_D_NSECTORS);
                    191:        put_word((const char *)&source->d_ncylinders, dest + 
                    192:                DISKTAB_D_NCYLINDERS);
                    193:        put_word((const char *)&source->d_rpm, dest + DISKTAB_D_RPM);
                    194:        put_short((const char *)&source->d_front, dest + DISKTAB_D_FRONT);
                    195:        put_short((const char *)&source->d_back, dest + DISKTAB_D_BACK);
                    196:        put_short((const char *)&source->d_ngroups, dest + DISKTAB_D_NGROUPS);
                    197:        put_short((const char *)&source->d_ag_size, dest + DISKTAB_D_AG_SIZE);
                    198:        put_short((const char *)&source->d_ag_alts, dest + DISKTAB_D_AG_ALTS);
                    199:        put_short((const char *)&source->d_ag_off, dest + DISKTAB_D_AG_OFF);
                    200:        if (NBOOTS){
                    201:                bblk_dst = (unsigned char *)(dest + DISKTAB_D_BOOT0_BLKNO);
                    202:                bblk_src = (unsigned char *)&source->d_boot0_blkno;
                    203:                for (i = 0; i < (NBOOTS) ; i++){
                    204:                        put_word(bblk_src, bblk_dst);
                    205:                        bblk_src += sizeof(int);
                    206:                        bblk_dst += sizeof(int);
                    207:                }
                    208:        }
                    209:        bcopy(source->d_bootfile, dest + DISKTAB_D_BOOTFILE, MAXBFLEN);
                    210:        bcopy(source->d_hostname, dest + DISKTAB_D_HOSTNAME, MAXHNLEN);
                    211:        put_char((const char *)&source->d_rootpartition,
                    212:                 dest + DISKTAB_D_ROOTPARTITION);
                    213:        put_char((const char *)&source->d_rwpartition, 
                    214:                dest + DISKTAB_D_RWPARTITION);
                    215:        for(part_num=0; part_num<NPART; part_num++) {
                    216:                put_partition(&source->d_partitions[part_num],
                    217:                        dest + DISKTAB_D_PARTITIONS + 
                    218:                        (part_num * SIZEOF_PARTITION_T));
                    219:        }
                    220: }
                    221: 
                    222: /*
                    223:  * Warning - this doesn't copy checksum properly. Caller must do that.
                    224:  */
                    225: void put_dl_un(const dl_un_t *source, char *dest) 
                    226: {
                    227:        int i;
                    228:        
                    229:        for(i=0; i<NBAD; i++) {
                    230:                put_word((const char *)&source->DL_bad[i], dest);
                    231:                dest += sizeof(int);
                    232:        }
                    233: }
                    234: 
                    235: void put_disk_label(const disk_label_t *source, char *dest)
                    236: {
                    237:        put_word((const char *)&source->dl_version, 
                    238:                dest + DISK_LABEL_DL_VERSION);
                    239:        put_word((const char *)&source->dl_label_blkno,
                    240:                dest + DISK_LABEL_DL_LABEL_BLKNO);
                    241:        put_word((const char *)&source->dl_size, dest + DISK_LABEL_DL_SIZE);
                    242:        bcopy(source->dl_label, dest + DISK_LABEL_DL_LABEL, MAXLBLLEN);
                    243:        put_word((const char *)&source->dl_flags, dest + DISK_LABEL_DL_FLAGS);
                    244:        put_word((const char *)&source->dl_tag, dest + DISK_LABEL_DL_TAG);
                    245:        put_disktab(&source->dl_dt, dest + DISK_LABEL_DL_DT);
                    246:        put_dl_un(&source->dl_un, dest + DISK_LABEL_DL_UN);
                    247:        put_short((const char *)&source->dl_checksum, 
                    248:                dest + DISK_LABEL_DL_CHECKSUM);
                    249:        put_short((const char *)&source->dl_v3_checksum, 
                    250:                dest + DISK_LABEL_DL_UN);
                    251: }

unix.superglobalmegacorp.com

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