Annotation of 43BSDReno/sys/ufs/ufs_subr.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution is only permitted until one year after the first shipment
        !             6:  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
        !             7:  * binary forms are permitted provided that: (1) source distributions retain
        !             8:  * this entire copyright notice and comment, and (2) distributions including
        !             9:  * binaries display the following acknowledgement:  This product includes
        !            10:  * software developed by the University of California, Berkeley and its
        !            11:  * contributors'' in the documentation or other materials provided with the
        !            12:  * distribution and in all advertising materials mentioning features or use
        !            13:  * of this software.  Neither the name of the University nor the names of
        !            14:  * its contributors may be used to endorse or promote products derived from
        !            15:  * this software without specific prior written permission.
        !            16:  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            17:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            18:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            19:  *
        !            20:  *     @(#)ufs_subr.c  7.13 (Berkeley) 6/28/90
        !            21:  */
        !            22: 
        !            23: #ifdef KERNEL
        !            24: #include "param.h"
        !            25: #include "../ufs/fs.h"
        !            26: #else
        !            27: #include <sys/param.h>
        !            28: #include <ufs/fs.h>
        !            29: #endif
        !            30: 
        !            31: extern int around[9];
        !            32: extern int inside[9];
        !            33: extern u_char *fragtbl[];
        !            34: 
        !            35: /*
        !            36:  * Update the frsum fields to reflect addition or deletion 
        !            37:  * of some frags.
        !            38:  */
        !            39: fragacct(fs, fragmap, fraglist, cnt)
        !            40:        struct fs *fs;
        !            41:        int fragmap;
        !            42:        long fraglist[];
        !            43:        int cnt;
        !            44: {
        !            45:        int inblk;
        !            46:        register int field, subfield;
        !            47:        register int siz, pos;
        !            48: 
        !            49:        inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1;
        !            50:        fragmap <<= 1;
        !            51:        for (siz = 1; siz < fs->fs_frag; siz++) {
        !            52:                if ((inblk & (1 << (siz + (fs->fs_frag % NBBY)))) == 0)
        !            53:                        continue;
        !            54:                field = around[siz];
        !            55:                subfield = inside[siz];
        !            56:                for (pos = siz; pos <= fs->fs_frag; pos++) {
        !            57:                        if ((fragmap & field) == subfield) {
        !            58:                                fraglist[siz] += cnt;
        !            59:                                pos += siz;
        !            60:                                field <<= siz;
        !            61:                                subfield <<= siz;
        !            62:                        }
        !            63:                        field <<= 1;
        !            64:                        subfield <<= 1;
        !            65:                }
        !            66:        }
        !            67: }
        !            68: 
        !            69: /*
        !            70:  * block operations
        !            71:  *
        !            72:  * check if a block is available
        !            73:  */
        !            74: isblock(fs, cp, h)
        !            75:        struct fs *fs;
        !            76:        unsigned char *cp;
        !            77:        daddr_t h;
        !            78: {
        !            79:        unsigned char mask;
        !            80: 
        !            81:        switch ((int)fs->fs_frag) {
        !            82:        case 8:
        !            83:                return (cp[h] == 0xff);
        !            84:        case 4:
        !            85:                mask = 0x0f << ((h & 0x1) << 2);
        !            86:                return ((cp[h >> 1] & mask) == mask);
        !            87:        case 2:
        !            88:                mask = 0x03 << ((h & 0x3) << 1);
        !            89:                return ((cp[h >> 2] & mask) == mask);
        !            90:        case 1:
        !            91:                mask = 0x01 << (h & 0x7);
        !            92:                return ((cp[h >> 3] & mask) == mask);
        !            93:        default:
        !            94:                panic("isblock");
        !            95:                return (NULL);
        !            96:        }
        !            97: }
        !            98: 
        !            99: /*
        !           100:  * take a block out of the map
        !           101:  */
        !           102: clrblock(fs, cp, h)
        !           103:        struct fs *fs;
        !           104:        u_char *cp;
        !           105:        daddr_t h;
        !           106: {
        !           107: 
        !           108:        switch ((int)fs->fs_frag) {
        !           109:        case 8:
        !           110:                cp[h] = 0;
        !           111:                return;
        !           112:        case 4:
        !           113:                cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2));
        !           114:                return;
        !           115:        case 2:
        !           116:                cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1));
        !           117:                return;
        !           118:        case 1:
        !           119:                cp[h >> 3] &= ~(0x01 << (h & 0x7));
        !           120:                return;
        !           121:        default:
        !           122:                panic("clrblock");
        !           123:        }
        !           124: }
        !           125: 
        !           126: /*
        !           127:  * put a block into the map
        !           128:  */
        !           129: setblock(fs, cp, h)
        !           130:        struct fs *fs;
        !           131:        unsigned char *cp;
        !           132:        daddr_t h;
        !           133: {
        !           134: 
        !           135:        switch ((int)fs->fs_frag) {
        !           136: 
        !           137:        case 8:
        !           138:                cp[h] = 0xff;
        !           139:                return;
        !           140:        case 4:
        !           141:                cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
        !           142:                return;
        !           143:        case 2:
        !           144:                cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
        !           145:                return;
        !           146:        case 1:
        !           147:                cp[h >> 3] |= (0x01 << (h & 0x7));
        !           148:                return;
        !           149:        default:
        !           150:                panic("setblock");
        !           151:        }
        !           152: }
        !           153: 
        !           154: #if (!defined(vax) && !defined(tahoe) && !defined(hp300)) \
        !           155:        || defined(VAX630) || defined(VAX650)
        !           156: /*
        !           157:  * C definitions of special instructions.
        !           158:  * Normally expanded with inline.
        !           159:  */
        !           160: scanc(size, cp, table, mask)
        !           161:        u_int size;
        !           162:        register u_char *cp, table[];
        !           163:        register u_char mask;
        !           164: {
        !           165:        register u_char *end = &cp[size];
        !           166: 
        !           167:        while (cp < end && (table[*cp] & mask) == 0)
        !           168:                cp++;
        !           169:        return (end - cp);
        !           170: }
        !           171: #endif
        !           172: 
        !           173: #if !defined(vax) && !defined(tahoe) && !defined(hp300)
        !           174: skpc(mask, size, cp)
        !           175:        register u_char mask;
        !           176:        u_int size;
        !           177:        register u_char *cp;
        !           178: {
        !           179:        register u_char *end = &cp[size];
        !           180: 
        !           181:        while (cp < end && *cp == mask)
        !           182:                cp++;
        !           183:        return (end - cp);
        !           184: }
        !           185: 
        !           186: locc(mask, size, cp)
        !           187:        register u_char mask;
        !           188:        u_int size;
        !           189:        register u_char *cp;
        !           190: {
        !           191:        register u_char *end = &cp[size];
        !           192: 
        !           193:        while (cp < end && *cp != mask)
        !           194:                cp++;
        !           195:        return (end - cp);
        !           196: }
        !           197: #endif

unix.superglobalmegacorp.com

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