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

unix.superglobalmegacorp.com

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