1*18307Sralph /* lfs_alloc.c 6.12 85/03/12 */ 24359Smckusick 317097Sbloom #include "param.h" 417097Sbloom #include "systm.h" 517097Sbloom #include "mount.h" 617097Sbloom #include "fs.h" 717097Sbloom #include "conf.h" 817097Sbloom #include "buf.h" 917097Sbloom #include "inode.h" 1017097Sbloom #include "dir.h" 1117097Sbloom #include "user.h" 1217097Sbloom #include "quota.h" 1317097Sbloom #include "kernel.h" 14*18307Sralph #include "syslog.h" 154359Smckusick 165212Smckusic extern u_long hashalloc(); 179163Ssam extern ino_t ialloccg(); 189163Ssam extern daddr_t alloccg(); 194651Smckusic extern daddr_t alloccgblk(); 204651Smckusic extern daddr_t fragextend(); 214651Smckusic extern daddr_t blkpref(); 224651Smckusic extern daddr_t mapsearch(); 234607Smckusic extern int inside[], around[]; 245322Smckusic extern unsigned char *fragtbl[]; 254359Smckusick 265375Smckusic /* 275375Smckusic * Allocate a block in the file system. 285375Smckusic * 295375Smckusic * The size of the requested block is given, which must be some 305375Smckusic * multiple of fs_fsize and <= fs_bsize. 315375Smckusic * A preference may be optionally specified. If a preference is given 325375Smckusic * the following hierarchy is used to allocate a block: 335375Smckusic * 1) allocate the requested block. 345375Smckusic * 2) allocate a rotationally optimal block in the same cylinder. 355375Smckusic * 3) allocate a block in the same cylinder group. 365375Smckusic * 4) quadradically rehash into other cylinder groups, until an 375375Smckusic * available block is located. 385375Smckusic * If no block preference is given the following heirarchy is used 395375Smckusic * to allocate a block: 405375Smckusic * 1) allocate a block in the cylinder group that contains the 415375Smckusic * inode for the file. 425375Smckusic * 2) quadradically rehash into other cylinder groups, until an 435375Smckusic * available block is located. 445375Smckusic */ 454359Smckusick struct buf * 465965Smckusic alloc(ip, bpref, size) 474463Smckusic register struct inode *ip; 484359Smckusick daddr_t bpref; 494359Smckusick int size; 504359Smckusick { 514359Smckusick daddr_t bno; 524359Smckusick register struct fs *fs; 534463Smckusic register struct buf *bp; 544359Smckusick int cg; 554359Smckusick 565965Smckusic fs = ip->i_fs; 576716Smckusick if ((unsigned)size > fs->fs_bsize || fragoff(fs, size) != 0) { 586716Smckusick printf("dev = 0x%x, bsize = %d, size = %d, fs = %s\n", 596716Smckusick ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt); 604463Smckusic panic("alloc: bad size"); 616716Smckusick } 625322Smckusic if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0) 634359Smckusick goto nospace; 6411638Ssam if (u.u_uid != 0 && freespace(fs, fs->fs_minfree) <= 0) 654792Smckusic goto nospace; 667650Ssam #ifdef QUOTA 6712643Ssam u.u_error = chkdq(ip, (long)btodb(size), 0); 6812643Ssam if (u.u_error) 6912643Ssam return (NULL); 707483Skre #endif 714948Smckusic if (bpref >= fs->fs_size) 724948Smckusic bpref = 0; 734359Smckusick if (bpref == 0) 745377Smckusic cg = itog(fs, ip->i_number); 754359Smckusick else 765377Smckusic cg = dtog(fs, bpref); 779163Ssam bno = (daddr_t)hashalloc(ip, cg, (long)bpref, size, 789163Ssam (u_long (*)())alloccg); 796567Smckusic if (bno <= 0) 804359Smckusick goto nospace; 8112643Ssam ip->i_blocks += btodb(size); 8212643Ssam ip->i_flag |= IUPD|ICHG; 835965Smckusic bp = getblk(ip->i_dev, fsbtodb(fs, bno), size); 844359Smckusick clrbuf(bp); 854359Smckusick return (bp); 864359Smckusick nospace: 874359Smckusick fserr(fs, "file system full"); 884359Smckusick uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt); 894359Smckusick u.u_error = ENOSPC; 904359Smckusick return (NULL); 914359Smckusick } 924359Smckusick 935375Smckusic /* 945375Smckusic * Reallocate a fragment to a bigger size 955375Smckusic * 965375Smckusic * The number and size of the old block is given, and a preference 975375Smckusic * and new size is also specified. The allocator attempts to extend 985375Smckusic * the original block. Failing that, the regular block allocator is 995375Smckusic * invoked to get an appropriate block. 1005375Smckusic */ 1014426Smckusic struct buf * 1025965Smckusic realloccg(ip, bprev, bpref, osize, nsize) 1035965Smckusic register struct inode *ip; 1044651Smckusic daddr_t bprev, bpref; 1054426Smckusic int osize, nsize; 1064426Smckusic { 1074426Smckusic daddr_t bno; 1084426Smckusic register struct fs *fs; 1094463Smckusic register struct buf *bp, *obp; 1104426Smckusic int cg; 1114426Smckusic 1125965Smckusic fs = ip->i_fs; 1135960Smckusic if ((unsigned)osize > fs->fs_bsize || fragoff(fs, osize) != 0 || 1146716Smckusick (unsigned)nsize > fs->fs_bsize || fragoff(fs, nsize) != 0) { 1156716Smckusick printf("dev = 0x%x, bsize = %d, osize = %d, nsize = %d, fs = %s\n", 1166716Smckusick ip->i_dev, fs->fs_bsize, osize, nsize, fs->fs_fsmnt); 1174463Smckusic panic("realloccg: bad size"); 1186716Smckusick } 11911638Ssam if (u.u_uid != 0 && freespace(fs, fs->fs_minfree) <= 0) 1204792Smckusic goto nospace; 1216716Smckusick if (bprev == 0) { 1226716Smckusick printf("dev = 0x%x, bsize = %d, bprev = %d, fs = %s\n", 1236716Smckusick ip->i_dev, fs->fs_bsize, bprev, fs->fs_fsmnt); 1244463Smckusic panic("realloccg: bad bprev"); 1256716Smckusick } 1267650Ssam #ifdef QUOTA 12712643Ssam u.u_error = chkdq(ip, (long)btodb(nsize - osize), 0); 12812643Ssam if (u.u_error) 12912643Ssam return (NULL); 1307483Skre #endif 1316294Smckusick cg = dtog(fs, bprev); 1325965Smckusic bno = fragextend(ip, cg, (long)bprev, osize, nsize); 1334463Smckusic if (bno != 0) { 1347187Sroot do { 1357187Sroot bp = bread(ip->i_dev, fsbtodb(fs, bno), osize); 1367187Sroot if (bp->b_flags & B_ERROR) { 1377187Sroot brelse(bp); 1387187Sroot return (NULL); 1397187Sroot } 1407187Sroot } while (brealloc(bp, nsize) == 0); 1417187Sroot bp->b_flags |= B_DONE; 1429163Ssam bzero(bp->b_un.b_addr + osize, (unsigned)nsize - osize); 14312643Ssam ip->i_blocks += btodb(nsize - osize); 14412643Ssam ip->i_flag |= IUPD|ICHG; 1454463Smckusic return (bp); 1464463Smckusic } 1474948Smckusic if (bpref >= fs->fs_size) 1484948Smckusic bpref = 0; 14917709Smckusick bno = (daddr_t)hashalloc(ip, cg, (long)bpref, fs->fs_bsize, 1509163Ssam (u_long (*)())alloccg); 1516567Smckusic if (bno > 0) { 1525965Smckusic obp = bread(ip->i_dev, fsbtodb(fs, bprev), osize); 1535960Smckusic if (obp->b_flags & B_ERROR) { 1545960Smckusic brelse(obp); 1556294Smckusick return (NULL); 1565960Smckusic } 15717658Smckusick bp = getblk(ip->i_dev, fsbtodb(fs, bno), nsize); 15817658Smckusick bcopy(obp->b_un.b_addr, bp->b_un.b_addr, (u_int)osize); 15917658Smckusick bzero(bp->b_un.b_addr + osize, (unsigned)nsize - osize); 16017658Smckusick if (obp->b_flags & B_DELWRI) { 16117658Smckusick obp->b_flags &= ~B_DELWRI; 16217658Smckusick u.u_ru.ru_oublock--; /* delete charge */ 16317658Smckusick } 1644463Smckusic brelse(obp); 1659163Ssam free(ip, bprev, (off_t)osize); 16617709Smckusick if (nsize < fs->fs_bsize) 16717709Smckusick free(ip, bno + numfrags(fs, nsize), 16817709Smckusick (off_t)(fs->fs_bsize - nsize)); 16912643Ssam ip->i_blocks += btodb(nsize - osize); 17012643Ssam ip->i_flag |= IUPD|ICHG; 1716294Smckusick return (bp); 1724463Smckusic } 1734792Smckusic nospace: 1744463Smckusic /* 1754463Smckusic * no space available 1764463Smckusic */ 1774426Smckusic fserr(fs, "file system full"); 1784426Smckusic uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt); 1794426Smckusic u.u_error = ENOSPC; 1804426Smckusic return (NULL); 1814426Smckusic } 1824426Smckusic 1835375Smckusic /* 1845375Smckusic * Allocate an inode in the file system. 1855375Smckusic * 1865375Smckusic * A preference may be optionally specified. If a preference is given 1875375Smckusic * the following hierarchy is used to allocate an inode: 1885375Smckusic * 1) allocate the requested inode. 1895375Smckusic * 2) allocate an inode in the same cylinder group. 1905375Smckusic * 3) quadradically rehash into other cylinder groups, until an 1915375Smckusic * available inode is located. 1925375Smckusic * If no inode preference is given the following heirarchy is used 1935375Smckusic * to allocate an inode: 1945375Smckusic * 1) allocate an inode in cylinder group 0. 1955375Smckusic * 2) quadradically rehash into other cylinder groups, until an 1965375Smckusic * available inode is located. 1975375Smckusic */ 1984359Smckusick struct inode * 1995965Smckusic ialloc(pip, ipref, mode) 2005965Smckusic register struct inode *pip; 2014359Smckusick ino_t ipref; 2024359Smckusick int mode; 2034359Smckusick { 2045212Smckusic ino_t ino; 2054359Smckusick register struct fs *fs; 2064359Smckusick register struct inode *ip; 2074359Smckusick int cg; 2084359Smckusick 2095965Smckusic fs = pip->i_fs; 2104792Smckusic if (fs->fs_cstotal.cs_nifree == 0) 2114359Smckusick goto noinodes; 2127650Ssam #ifdef QUOTA 21312643Ssam u.u_error = chkiq(pip->i_dev, (struct inode *)NULL, u.u_uid, 0); 21412643Ssam if (u.u_error) 21512643Ssam return (NULL); 2167483Skre #endif 2174948Smckusic if (ipref >= fs->fs_ncg * fs->fs_ipg) 2184948Smckusic ipref = 0; 2195377Smckusic cg = itog(fs, ipref); 2205965Smckusic ino = (ino_t)hashalloc(pip, cg, (long)ipref, mode, ialloccg); 2214359Smckusick if (ino == 0) 2224359Smckusick goto noinodes; 2235965Smckusic ip = iget(pip->i_dev, pip->i_fs, ino); 2244359Smckusick if (ip == NULL) { 22515120Skarels ifree(pip, ino, 0); 2264359Smckusick return (NULL); 2274359Smckusick } 2286716Smckusick if (ip->i_mode) { 2296716Smckusick printf("mode = 0%o, inum = %d, fs = %s\n", 2306716Smckusick ip->i_mode, ip->i_number, fs->fs_fsmnt); 2314359Smckusick panic("ialloc: dup alloc"); 2326716Smckusick } 23312643Ssam if (ip->i_blocks) { /* XXX */ 23412643Ssam printf("free inode %s/%d had %d blocks\n", 23512643Ssam fs->fs_fsmnt, ino, ip->i_blocks); 23612643Ssam ip->i_blocks = 0; 23712643Ssam } 2384359Smckusick return (ip); 2394359Smckusick noinodes: 2404359Smckusick fserr(fs, "out of inodes"); 2416294Smckusick uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt); 2424359Smckusick u.u_error = ENOSPC; 2434359Smckusick return (NULL); 2444359Smckusick } 2454359Smckusick 2464651Smckusic /* 2475375Smckusic * Find a cylinder to place a directory. 2485375Smckusic * 2495375Smckusic * The policy implemented by this algorithm is to select from 2505375Smckusic * among those cylinder groups with above the average number of 2515375Smckusic * free inodes, the one with the smallest number of directories. 2524651Smckusic */ 2539163Ssam ino_t 2545965Smckusic dirpref(fs) 2555965Smckusic register struct fs *fs; 2564359Smckusick { 2574651Smckusic int cg, minndir, mincg, avgifree; 2584359Smckusick 2594792Smckusic avgifree = fs->fs_cstotal.cs_nifree / fs->fs_ncg; 2604651Smckusic minndir = fs->fs_ipg; 2614359Smckusick mincg = 0; 2624651Smckusic for (cg = 0; cg < fs->fs_ncg; cg++) 2635322Smckusic if (fs->fs_cs(fs, cg).cs_ndir < minndir && 2645322Smckusic fs->fs_cs(fs, cg).cs_nifree >= avgifree) { 2654359Smckusick mincg = cg; 2665322Smckusic minndir = fs->fs_cs(fs, cg).cs_ndir; 2674359Smckusick } 2689163Ssam return ((ino_t)(fs->fs_ipg * mincg)); 2694359Smckusick } 2704359Smckusick 2714651Smckusic /* 2729163Ssam * Select the desired position for the next block in a file. The file is 2739163Ssam * logically divided into sections. The first section is composed of the 2749163Ssam * direct blocks. Each additional section contains fs_maxbpg blocks. 2759163Ssam * 2769163Ssam * If no blocks have been allocated in the first section, the policy is to 2779163Ssam * request a block in the same cylinder group as the inode that describes 2789163Ssam * the file. If no blocks have been allocated in any other section, the 2799163Ssam * policy is to place the section in a cylinder group with a greater than 2809163Ssam * average number of free blocks. An appropriate cylinder group is found 28117696Smckusick * by using a rotor that sweeps the cylinder groups. When a new group of 28217696Smckusick * blocks is needed, the sweep begins in the cylinder group following the 28317696Smckusick * cylinder group from which the previous allocation was made. The sweep 28417696Smckusick * continues until a cylinder group with greater than the average number 28517696Smckusick * of free blocks is found. If the allocation is for the first block in an 28617696Smckusick * indirect block, the information on the previous allocation is unavailable; 28717696Smckusick * here a best guess is made based upon the logical block number being 28817696Smckusick * allocated. 2899163Ssam * 2909163Ssam * If a section is already partially allocated, the policy is to 2919163Ssam * contiguously allocate fs_maxcontig blocks. The end of one of these 2929163Ssam * contiguous blocks and the beginning of the next is physically separated 2939163Ssam * so that the disk head will be in transit between them for at least 2949163Ssam * fs_rotdelay milliseconds. This is to allow time for the processor to 2959163Ssam * schedule another I/O transfer. 2964651Smckusic */ 2975212Smckusic daddr_t 2989163Ssam blkpref(ip, lbn, indx, bap) 2999163Ssam struct inode *ip; 3009163Ssam daddr_t lbn; 3019163Ssam int indx; 3029163Ssam daddr_t *bap; 3039163Ssam { 3045965Smckusic register struct fs *fs; 30517696Smckusick register int cg; 30617696Smckusick int avgbfree, startcg; 3079163Ssam daddr_t nextblk; 3084651Smckusic 3099163Ssam fs = ip->i_fs; 3109163Ssam if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) { 3119163Ssam if (lbn < NDADDR) { 3129163Ssam cg = itog(fs, ip->i_number); 3135322Smckusic return (fs->fs_fpg * cg + fs->fs_frag); 3144651Smckusic } 3159163Ssam /* 3169163Ssam * Find a cylinder with greater than average number of 3179163Ssam * unused data blocks. 3189163Ssam */ 31917696Smckusick if (indx == 0 || bap[indx - 1] == 0) 32017696Smckusick startcg = itog(fs, ip->i_number) + lbn / fs->fs_maxbpg; 32117696Smckusick else 32217696Smckusick startcg = dtog(fs, bap[indx - 1]) + 1; 32317696Smckusick startcg %= fs->fs_ncg; 3249163Ssam avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg; 32517696Smckusick for (cg = startcg; cg < fs->fs_ncg; cg++) 3269163Ssam if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) { 3279163Ssam fs->fs_cgrotor = cg; 3289163Ssam return (fs->fs_fpg * cg + fs->fs_frag); 3299163Ssam } 33017696Smckusick for (cg = 0; cg <= startcg; cg++) 3319163Ssam if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) { 3329163Ssam fs->fs_cgrotor = cg; 3339163Ssam return (fs->fs_fpg * cg + fs->fs_frag); 3349163Ssam } 3359163Ssam return (NULL); 3369163Ssam } 3379163Ssam /* 3389163Ssam * One or more previous blocks have been laid out. If less 3399163Ssam * than fs_maxcontig previous blocks are contiguous, the 3409163Ssam * next block is requested contiguously, otherwise it is 3419163Ssam * requested rotationally delayed by fs_rotdelay milliseconds. 3429163Ssam */ 3439163Ssam nextblk = bap[indx - 1] + fs->fs_frag; 3449163Ssam if (indx > fs->fs_maxcontig && 34511638Ssam bap[indx - fs->fs_maxcontig] + blkstofrags(fs, fs->fs_maxcontig) 3469163Ssam != nextblk) 3479163Ssam return (nextblk); 3489163Ssam if (fs->fs_rotdelay != 0) 3499163Ssam /* 3509163Ssam * Here we convert ms of delay to frags as: 3519163Ssam * (frags) = (ms) * (rev/sec) * (sect/rev) / 3529163Ssam * ((sect/frag) * (ms/sec)) 3539163Ssam * then round up to the next block. 3549163Ssam */ 3559163Ssam nextblk += roundup(fs->fs_rotdelay * fs->fs_rps * fs->fs_nsect / 3569163Ssam (NSPF(fs) * 1000), fs->fs_frag); 3579163Ssam return (nextblk); 3584651Smckusic } 3594651Smckusic 3605375Smckusic /* 3615375Smckusic * Implement the cylinder overflow algorithm. 3625375Smckusic * 3635375Smckusic * The policy implemented by this algorithm is: 3645375Smckusic * 1) allocate the block in its requested cylinder group. 3655375Smckusic * 2) quadradically rehash on the cylinder group number. 3665375Smckusic * 3) brute force search for a free block. 3675375Smckusic */ 3685212Smckusic /*VARARGS5*/ 3695212Smckusic u_long 3705965Smckusic hashalloc(ip, cg, pref, size, allocator) 3715965Smckusic struct inode *ip; 3724359Smckusick int cg; 3734359Smckusick long pref; 3744359Smckusick int size; /* size for data blocks, mode for inodes */ 3755212Smckusic u_long (*allocator)(); 3764359Smckusick { 3775965Smckusic register struct fs *fs; 3784359Smckusick long result; 3794359Smckusick int i, icg = cg; 3804359Smckusick 3815965Smckusic fs = ip->i_fs; 3824359Smckusick /* 3834359Smckusick * 1: preferred cylinder group 3844359Smckusick */ 3855965Smckusic result = (*allocator)(ip, cg, pref, size); 3864359Smckusick if (result) 3874359Smckusick return (result); 3884359Smckusick /* 3894359Smckusick * 2: quadratic rehash 3904359Smckusick */ 3914359Smckusick for (i = 1; i < fs->fs_ncg; i *= 2) { 3924359Smckusick cg += i; 3934359Smckusick if (cg >= fs->fs_ncg) 3944359Smckusick cg -= fs->fs_ncg; 3955965Smckusic result = (*allocator)(ip, cg, 0, size); 3964359Smckusick if (result) 3974359Smckusick return (result); 3984359Smckusick } 3994359Smckusick /* 4004359Smckusick * 3: brute force search 40110847Ssam * Note that we start at i == 2, since 0 was checked initially, 40210847Ssam * and 1 is always checked in the quadratic rehash. 4034359Smckusick */ 40410848Smckusick cg = (icg + 2) % fs->fs_ncg; 40510847Ssam for (i = 2; i < fs->fs_ncg; i++) { 4065965Smckusic result = (*allocator)(ip, cg, 0, size); 4074359Smckusick if (result) 4084359Smckusick return (result); 4094359Smckusick cg++; 4104359Smckusick if (cg == fs->fs_ncg) 4114359Smckusick cg = 0; 4124359Smckusick } 4136294Smckusick return (NULL); 4144359Smckusick } 4154359Smckusick 4165375Smckusic /* 4175375Smckusic * Determine whether a fragment can be extended. 4185375Smckusic * 4195375Smckusic * Check to see if the necessary fragments are available, and 4205375Smckusic * if they are, allocate them. 4215375Smckusic */ 4224359Smckusick daddr_t 4235965Smckusic fragextend(ip, cg, bprev, osize, nsize) 4245965Smckusic struct inode *ip; 4254426Smckusic int cg; 4264463Smckusic long bprev; 4274426Smckusic int osize, nsize; 4284426Smckusic { 4295965Smckusic register struct fs *fs; 4304463Smckusic register struct buf *bp; 4314463Smckusic register struct cg *cgp; 4324463Smckusic long bno; 4334463Smckusic int frags, bbase; 4344426Smckusic int i; 4354426Smckusic 4365965Smckusic fs = ip->i_fs; 43717224Smckusick if (fs->fs_cs(fs, cg).cs_nffree < numfrags(fs, nsize - osize)) 4386531Smckusick return (NULL); 4395960Smckusic frags = numfrags(fs, nsize); 44017224Smckusick bbase = fragnum(fs, bprev); 44117224Smckusick if (bbase > fragnum(fs, (bprev + frags - 1))) { 4424463Smckusic /* cannot extend across a block boundry */ 4436294Smckusick return (NULL); 4444463Smckusic } 44510278Smckusick bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize); 4466531Smckusick cgp = bp->b_un.b_cg; 4476531Smckusick if (bp->b_flags & B_ERROR || cgp->cg_magic != CG_MAGIC) { 4485960Smckusic brelse(bp); 4496294Smckusick return (NULL); 4505960Smckusic } 4518105Sroot cgp->cg_time = time.tv_sec; 4525377Smckusic bno = dtogd(fs, bprev); 4535960Smckusic for (i = numfrags(fs, osize); i < frags; i++) 4545361Smckusic if (isclr(cgp->cg_free, bno + i)) { 4555361Smckusic brelse(bp); 4566294Smckusick return (NULL); 4575361Smckusic } 4585361Smckusic /* 4595361Smckusic * the current fragment can be extended 4605361Smckusic * deduct the count on fragment being extended into 4615361Smckusic * increase the count on the remaining fragment (if any) 4625361Smckusic * allocate the extended piece 4635361Smckusic */ 4645361Smckusic for (i = frags; i < fs->fs_frag - bbase; i++) 4654463Smckusic if (isclr(cgp->cg_free, bno + i)) 4664463Smckusic break; 4675960Smckusic cgp->cg_frsum[i - numfrags(fs, osize)]--; 4685361Smckusic if (i != frags) 4695361Smckusic cgp->cg_frsum[i - frags]++; 4705960Smckusic for (i = numfrags(fs, osize); i < frags; i++) { 4715361Smckusic clrbit(cgp->cg_free, bno + i); 4725361Smckusic cgp->cg_cs.cs_nffree--; 4735361Smckusic fs->fs_cstotal.cs_nffree--; 4745361Smckusic fs->fs_cs(fs, cg).cs_nffree--; 4754463Smckusic } 4765361Smckusic fs->fs_fmod++; 4775361Smckusic bdwrite(bp); 4785361Smckusic return (bprev); 4794426Smckusic } 4804426Smckusic 4815375Smckusic /* 4825375Smckusic * Determine whether a block can be allocated. 4835375Smckusic * 4845375Smckusic * Check to see if a block of the apprpriate size is available, 4855375Smckusic * and if it is, allocate it. 4865375Smckusic */ 4879163Ssam daddr_t 4885965Smckusic alloccg(ip, cg, bpref, size) 4895965Smckusic struct inode *ip; 4904359Smckusick int cg; 4914359Smckusick daddr_t bpref; 4924359Smckusick int size; 4934359Smckusick { 4945965Smckusic register struct fs *fs; 4954463Smckusic register struct buf *bp; 4964463Smckusic register struct cg *cgp; 4974463Smckusic int bno, frags; 4984463Smckusic int allocsiz; 4994463Smckusic register int i; 5004359Smckusick 5015965Smckusic fs = ip->i_fs; 5025322Smckusic if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize) 5036294Smckusick return (NULL); 50410278Smckusick bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize); 5056531Smckusick cgp = bp->b_un.b_cg; 50615950Smckusick if (bp->b_flags & B_ERROR || cgp->cg_magic != CG_MAGIC || 50715950Smckusick (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) { 5085960Smckusic brelse(bp); 5096294Smckusick return (NULL); 5105960Smckusic } 5118105Sroot cgp->cg_time = time.tv_sec; 5125322Smckusic if (size == fs->fs_bsize) { 5135212Smckusic bno = alloccgblk(fs, cgp, bpref); 5144463Smckusic bdwrite(bp); 5154463Smckusic return (bno); 5164463Smckusic } 5174463Smckusic /* 5184463Smckusic * check to see if any fragments are already available 5194463Smckusic * allocsiz is the size which will be allocated, hacking 5204463Smckusic * it down to a smaller size if necessary 5214463Smckusic */ 5225960Smckusic frags = numfrags(fs, size); 5235322Smckusic for (allocsiz = frags; allocsiz < fs->fs_frag; allocsiz++) 5244463Smckusic if (cgp->cg_frsum[allocsiz] != 0) 5254463Smckusic break; 5265322Smckusic if (allocsiz == fs->fs_frag) { 5274463Smckusic /* 5284463Smckusic * no fragments were available, so a block will be 5294463Smckusic * allocated, and hacked up 5304463Smckusic */ 5314792Smckusic if (cgp->cg_cs.cs_nbfree == 0) { 5324463Smckusic brelse(bp); 5336294Smckusick return (NULL); 5344463Smckusic } 5355212Smckusic bno = alloccgblk(fs, cgp, bpref); 5365377Smckusic bpref = dtogd(fs, bno); 5375322Smckusic for (i = frags; i < fs->fs_frag; i++) 5384463Smckusic setbit(cgp->cg_free, bpref + i); 5395322Smckusic i = fs->fs_frag - frags; 5404792Smckusic cgp->cg_cs.cs_nffree += i; 5414792Smckusic fs->fs_cstotal.cs_nffree += i; 5425322Smckusic fs->fs_cs(fs, cg).cs_nffree += i; 5439762Ssam fs->fs_fmod++; 5444463Smckusic cgp->cg_frsum[i]++; 5454463Smckusic bdwrite(bp); 5464463Smckusic return (bno); 5474463Smckusic } 5484651Smckusic bno = mapsearch(fs, cgp, bpref, allocsiz); 54915950Smckusick if (bno < 0) { 55015950Smckusick brelse(bp); 5516294Smckusick return (NULL); 55215950Smckusick } 5534463Smckusic for (i = 0; i < frags; i++) 5544463Smckusic clrbit(cgp->cg_free, bno + i); 5554792Smckusic cgp->cg_cs.cs_nffree -= frags; 5564792Smckusic fs->fs_cstotal.cs_nffree -= frags; 5575322Smckusic fs->fs_cs(fs, cg).cs_nffree -= frags; 5589762Ssam fs->fs_fmod++; 5594463Smckusic cgp->cg_frsum[allocsiz]--; 5604463Smckusic if (frags != allocsiz) 5614463Smckusic cgp->cg_frsum[allocsiz - frags]++; 5624463Smckusic bdwrite(bp); 5634463Smckusic return (cg * fs->fs_fpg + bno); 5644463Smckusic } 5654463Smckusic 5665375Smckusic /* 5675375Smckusic * Allocate a block in a cylinder group. 5685375Smckusic * 5695375Smckusic * This algorithm implements the following policy: 5705375Smckusic * 1) allocate the requested block. 5715375Smckusic * 2) allocate a rotationally optimal block in the same cylinder. 5725375Smckusic * 3) allocate the next available block on the block rotor for the 5735375Smckusic * specified cylinder group. 5745375Smckusic * Note that this routine only allocates fs_bsize blocks; these 5755375Smckusic * blocks may be fragmented by the routine that allocates them. 5765375Smckusic */ 5774463Smckusic daddr_t 5785212Smckusic alloccgblk(fs, cgp, bpref) 5795965Smckusic register struct fs *fs; 5804463Smckusic register struct cg *cgp; 5814463Smckusic daddr_t bpref; 5824463Smckusic { 5834651Smckusic daddr_t bno; 5846294Smckusick int cylno, pos, delta; 5854651Smckusic short *cylbp; 5865361Smckusic register int i; 5874463Smckusic 5884651Smckusic if (bpref == 0) { 5894651Smckusic bpref = cgp->cg_rotor; 5905361Smckusic goto norot; 5915361Smckusic } 59217224Smckusick bpref = blknum(fs, bpref); 5935377Smckusic bpref = dtogd(fs, bpref); 5945361Smckusic /* 5955361Smckusic * if the requested block is available, use it 5965361Smckusic */ 59711638Ssam if (isblock(fs, cgp->cg_free, fragstoblks(fs, bpref))) { 5985361Smckusic bno = bpref; 5995361Smckusic goto gotit; 6005361Smckusic } 6015361Smckusic /* 6025361Smckusic * check for a block available on the same cylinder 6035361Smckusic */ 6045361Smckusic cylno = cbtocylno(fs, bpref); 6055375Smckusic if (cgp->cg_btot[cylno] == 0) 6065375Smckusic goto norot; 6075375Smckusic if (fs->fs_cpc == 0) { 6085375Smckusic /* 6095375Smckusic * block layout info is not available, so just have 6105375Smckusic * to take any block in this cylinder. 6115375Smckusic */ 6125375Smckusic bpref = howmany(fs->fs_spc * cylno, NSPF(fs)); 6135375Smckusic goto norot; 6145375Smckusic } 6155375Smckusic /* 6165361Smckusic * check the summary information to see if a block is 6175361Smckusic * available in the requested cylinder starting at the 6189163Ssam * requested rotational position and proceeding around. 6195361Smckusic */ 6209163Ssam cylbp = cgp->cg_b[cylno]; 6219163Ssam pos = cbtorpos(fs, bpref); 6225361Smckusic for (i = pos; i < NRPOS; i++) 6235361Smckusic if (cylbp[i] > 0) 6245361Smckusic break; 6255361Smckusic if (i == NRPOS) 6265361Smckusic for (i = 0; i < pos; i++) 6275361Smckusic if (cylbp[i] > 0) 6285361Smckusic break; 6295361Smckusic if (cylbp[i] > 0) { 6304651Smckusic /* 6315361Smckusic * found a rotational position, now find the actual 6325361Smckusic * block. A panic if none is actually there. 6334651Smckusic */ 6345361Smckusic pos = cylno % fs->fs_cpc; 6355361Smckusic bno = (cylno - pos) * fs->fs_spc / NSPB(fs); 6366716Smckusick if (fs->fs_postbl[pos][i] == -1) { 6376716Smckusick printf("pos = %d, i = %d, fs = %s\n", 6386716Smckusick pos, i, fs->fs_fsmnt); 6395361Smckusic panic("alloccgblk: cyl groups corrupted"); 6406716Smckusick } 6416294Smckusick for (i = fs->fs_postbl[pos][i];; ) { 6425361Smckusic if (isblock(fs, cgp->cg_free, bno + i)) { 64311638Ssam bno = blkstofrags(fs, (bno + i)); 6445361Smckusic goto gotit; 6455361Smckusic } 6466294Smckusick delta = fs->fs_rotbl[i]; 6476294Smckusick if (delta <= 0 || delta > MAXBPC - i) 6484651Smckusic break; 6496294Smckusick i += delta; 6504651Smckusic } 6516716Smckusick printf("pos = %d, i = %d, fs = %s\n", pos, i, fs->fs_fsmnt); 6525361Smckusic panic("alloccgblk: can't find blk in cyl"); 6534359Smckusick } 6545361Smckusic norot: 6555361Smckusic /* 6565361Smckusic * no blocks in the requested cylinder, so take next 6575361Smckusic * available one in this cylinder group. 6585361Smckusic */ 6598628Sroot bno = mapsearch(fs, cgp, bpref, (int)fs->fs_frag); 6606567Smckusic if (bno < 0) 6616294Smckusick return (NULL); 6624651Smckusic cgp->cg_rotor = bno; 6634359Smckusick gotit: 66411638Ssam clrblock(fs, cgp->cg_free, (long)fragstoblks(fs, bno)); 6654792Smckusic cgp->cg_cs.cs_nbfree--; 6664792Smckusic fs->fs_cstotal.cs_nbfree--; 6675322Smckusic fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--; 6685375Smckusic cylno = cbtocylno(fs, bno); 6695375Smckusic cgp->cg_b[cylno][cbtorpos(fs, bno)]--; 6705375Smckusic cgp->cg_btot[cylno]--; 6714359Smckusick fs->fs_fmod++; 6724651Smckusic return (cgp->cg_cgx * fs->fs_fpg + bno); 6734359Smckusick } 6744359Smckusick 6755375Smckusic /* 6765375Smckusic * Determine whether an inode can be allocated. 6775375Smckusic * 6785375Smckusic * Check to see if an inode is available, and if it is, 6795375Smckusic * allocate it using the following policy: 6805375Smckusic * 1) allocate the requested inode. 6815375Smckusic * 2) allocate the next available inode after the requested 6825375Smckusic * inode in the specified cylinder group. 6835375Smckusic */ 6849163Ssam ino_t 6855965Smckusic ialloccg(ip, cg, ipref, mode) 6865965Smckusic struct inode *ip; 6874359Smckusick int cg; 6884359Smckusick daddr_t ipref; 6894359Smckusick int mode; 6904359Smckusick { 6915965Smckusic register struct fs *fs; 6924463Smckusic register struct cg *cgp; 69316784Smckusick struct buf *bp; 69416784Smckusick int start, len, loc, map, i; 6954359Smckusick 6965965Smckusic fs = ip->i_fs; 6975322Smckusic if (fs->fs_cs(fs, cg).cs_nifree == 0) 6986294Smckusick return (NULL); 69910278Smckusick bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize); 7006531Smckusick cgp = bp->b_un.b_cg; 70115950Smckusick if (bp->b_flags & B_ERROR || cgp->cg_magic != CG_MAGIC || 70215950Smckusick cgp->cg_cs.cs_nifree == 0) { 7035960Smckusic brelse(bp); 7046294Smckusick return (NULL); 7055960Smckusic } 7068105Sroot cgp->cg_time = time.tv_sec; 7074359Smckusick if (ipref) { 7084359Smckusick ipref %= fs->fs_ipg; 7094359Smckusick if (isclr(cgp->cg_iused, ipref)) 7104359Smckusick goto gotit; 71116784Smckusick } 71216784Smckusick start = cgp->cg_irotor / NBBY; 71316784Smckusick len = howmany(fs->fs_ipg - cgp->cg_irotor, NBBY); 71416784Smckusick loc = skpc(0xff, len, &cgp->cg_iused[start]); 71516784Smckusick if (loc == 0) { 71617697Smckusick len = start + 1; 71717697Smckusick start = 0; 71817697Smckusick loc = skpc(0xff, len, &cgp->cg_iused[0]); 71917697Smckusick if (loc == 0) { 72017697Smckusick printf("cg = %s, irotor = %d, fs = %s\n", 72117697Smckusick cg, cgp->cg_irotor, fs->fs_fsmnt); 72217697Smckusick panic("ialloccg: map corrupted"); 72317697Smckusick /* NOTREACHED */ 72417697Smckusick } 72516784Smckusick } 72616784Smckusick i = start + len - loc; 72716784Smckusick map = cgp->cg_iused[i]; 72816784Smckusick ipref = i * NBBY; 72916784Smckusick for (i = 1; i < (1 << NBBY); i <<= 1, ipref++) { 73016784Smckusick if ((map & i) == 0) { 7314359Smckusick cgp->cg_irotor = ipref; 7324359Smckusick goto gotit; 7334359Smckusick } 7344359Smckusick } 73516784Smckusick printf("fs = %s\n", fs->fs_fsmnt); 73616784Smckusick panic("ialloccg: block not in map"); 73716784Smckusick /* NOTREACHED */ 7384359Smckusick gotit: 7394359Smckusick setbit(cgp->cg_iused, ipref); 7404792Smckusic cgp->cg_cs.cs_nifree--; 7414792Smckusic fs->fs_cstotal.cs_nifree--; 7425322Smckusic fs->fs_cs(fs, cg).cs_nifree--; 7434359Smckusick fs->fs_fmod++; 7444359Smckusick if ((mode & IFMT) == IFDIR) { 7454792Smckusic cgp->cg_cs.cs_ndir++; 7464792Smckusic fs->fs_cstotal.cs_ndir++; 7475322Smckusic fs->fs_cs(fs, cg).cs_ndir++; 7484359Smckusick } 7494359Smckusick bdwrite(bp); 7504359Smckusick return (cg * fs->fs_ipg + ipref); 7514359Smckusick } 7524359Smckusick 7535375Smckusic /* 7545375Smckusic * Free a block or fragment. 7555375Smckusic * 7565375Smckusic * The specified block or fragment is placed back in the 7575375Smckusic * free map. If a fragment is deallocated, a possible 7585375Smckusic * block reassembly is checked. 7595375Smckusic */ 7609163Ssam free(ip, bno, size) 7615965Smckusic register struct inode *ip; 7624359Smckusick daddr_t bno; 7635212Smckusic off_t size; 7644359Smckusick { 7654359Smckusick register struct fs *fs; 7664359Smckusick register struct cg *cgp; 7674359Smckusick register struct buf *bp; 7684463Smckusic int cg, blk, frags, bbase; 7694463Smckusic register int i; 7704359Smckusick 7715965Smckusic fs = ip->i_fs; 7726716Smckusick if ((unsigned)size > fs->fs_bsize || fragoff(fs, size) != 0) { 7736716Smckusick printf("dev = 0x%x, bsize = %d, size = %d, fs = %s\n", 7746716Smckusick ip->i_dev, fs->fs_bsize, size, fs->fs_fsmnt); 7754426Smckusic panic("free: bad size"); 7766716Smckusick } 7775377Smckusic cg = dtog(fs, bno); 7786567Smckusic if (badblock(fs, bno)) { 7796567Smckusic printf("bad block %d, ino %d\n", bno, ip->i_number); 7804359Smckusick return; 7816567Smckusic } 78210278Smckusick bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize); 7836531Smckusick cgp = bp->b_un.b_cg; 7846531Smckusick if (bp->b_flags & B_ERROR || cgp->cg_magic != CG_MAGIC) { 7855960Smckusic brelse(bp); 7864359Smckusick return; 7875960Smckusic } 7888105Sroot cgp->cg_time = time.tv_sec; 7895377Smckusic bno = dtogd(fs, bno); 7905322Smckusic if (size == fs->fs_bsize) { 79111638Ssam if (isblock(fs, cgp->cg_free, fragstoblks(fs, bno))) { 7926716Smckusick printf("dev = 0x%x, block = %d, fs = %s\n", 7936716Smckusick ip->i_dev, bno, fs->fs_fsmnt); 7944426Smckusic panic("free: freeing free block"); 7956567Smckusic } 79611638Ssam setblock(fs, cgp->cg_free, fragstoblks(fs, bno)); 7974792Smckusic cgp->cg_cs.cs_nbfree++; 7984792Smckusic fs->fs_cstotal.cs_nbfree++; 7995322Smckusic fs->fs_cs(fs, cg).cs_nbfree++; 8005375Smckusic i = cbtocylno(fs, bno); 8015375Smckusic cgp->cg_b[i][cbtorpos(fs, bno)]++; 8025375Smckusic cgp->cg_btot[i]++; 8034426Smckusic } else { 80417224Smckusick bbase = bno - fragnum(fs, bno); 8054463Smckusic /* 8064463Smckusic * decrement the counts associated with the old frags 8074463Smckusic */ 8086294Smckusick blk = blkmap(fs, cgp->cg_free, bbase); 8095322Smckusic fragacct(fs, blk, cgp->cg_frsum, -1); 8104463Smckusic /* 8114463Smckusic * deallocate the fragment 8124463Smckusic */ 8135960Smckusic frags = numfrags(fs, size); 8144463Smckusic for (i = 0; i < frags; i++) { 8156716Smckusick if (isset(cgp->cg_free, bno + i)) { 8166716Smckusick printf("dev = 0x%x, block = %d, fs = %s\n", 8176716Smckusick ip->i_dev, bno + i, fs->fs_fsmnt); 8184426Smckusic panic("free: freeing free frag"); 8196716Smckusick } 8204426Smckusic setbit(cgp->cg_free, bno + i); 8214426Smckusic } 8226294Smckusick cgp->cg_cs.cs_nffree += i; 8236294Smckusick fs->fs_cstotal.cs_nffree += i; 8246294Smckusick fs->fs_cs(fs, cg).cs_nffree += i; 8254463Smckusic /* 8264463Smckusic * add back in counts associated with the new frags 8274463Smckusic */ 8286294Smckusick blk = blkmap(fs, cgp->cg_free, bbase); 8295322Smckusic fragacct(fs, blk, cgp->cg_frsum, 1); 8304463Smckusic /* 8314463Smckusic * if a complete block has been reassembled, account for it 8324463Smckusic */ 83311638Ssam if (isblock(fs, cgp->cg_free, fragstoblks(fs, bbase))) { 8345322Smckusic cgp->cg_cs.cs_nffree -= fs->fs_frag; 8355322Smckusic fs->fs_cstotal.cs_nffree -= fs->fs_frag; 8365322Smckusic fs->fs_cs(fs, cg).cs_nffree -= fs->fs_frag; 8374792Smckusic cgp->cg_cs.cs_nbfree++; 8384792Smckusic fs->fs_cstotal.cs_nbfree++; 8395322Smckusic fs->fs_cs(fs, cg).cs_nbfree++; 8405375Smckusic i = cbtocylno(fs, bbase); 8415375Smckusic cgp->cg_b[i][cbtorpos(fs, bbase)]++; 8425375Smckusic cgp->cg_btot[i]++; 8434426Smckusic } 8444426Smckusic } 8454359Smckusick fs->fs_fmod++; 8464359Smckusick bdwrite(bp); 8474359Smckusick } 8484359Smckusick 8495375Smckusic /* 8505375Smckusic * Free an inode. 8515375Smckusic * 8525375Smckusic * The specified inode is placed back in the free map. 8535375Smckusic */ 8545965Smckusic ifree(ip, ino, mode) 8555965Smckusic struct inode *ip; 8564359Smckusick ino_t ino; 8574359Smckusick int mode; 8584359Smckusick { 8594359Smckusick register struct fs *fs; 8604359Smckusick register struct cg *cgp; 8614359Smckusick register struct buf *bp; 8624359Smckusick int cg; 8634359Smckusick 8645965Smckusic fs = ip->i_fs; 8656716Smckusick if ((unsigned)ino >= fs->fs_ipg*fs->fs_ncg) { 8666716Smckusick printf("dev = 0x%x, ino = %d, fs = %s\n", 8676716Smckusick ip->i_dev, ino, fs->fs_fsmnt); 8684359Smckusick panic("ifree: range"); 8696716Smckusick } 8705377Smckusic cg = itog(fs, ino); 87110278Smckusick bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize); 8726531Smckusick cgp = bp->b_un.b_cg; 8736531Smckusick if (bp->b_flags & B_ERROR || cgp->cg_magic != CG_MAGIC) { 8745960Smckusic brelse(bp); 8754359Smckusick return; 8765960Smckusic } 8778105Sroot cgp->cg_time = time.tv_sec; 8784359Smckusick ino %= fs->fs_ipg; 8796716Smckusick if (isclr(cgp->cg_iused, ino)) { 8806716Smckusick printf("dev = 0x%x, ino = %d, fs = %s\n", 8816716Smckusick ip->i_dev, ino, fs->fs_fsmnt); 8824359Smckusick panic("ifree: freeing free inode"); 8836716Smckusick } 8844359Smckusick clrbit(cgp->cg_iused, ino); 88516784Smckusick if (ino < cgp->cg_irotor) 88616784Smckusick cgp->cg_irotor = ino; 8874792Smckusic cgp->cg_cs.cs_nifree++; 8884792Smckusic fs->fs_cstotal.cs_nifree++; 8895322Smckusic fs->fs_cs(fs, cg).cs_nifree++; 8904359Smckusick if ((mode & IFMT) == IFDIR) { 8914792Smckusic cgp->cg_cs.cs_ndir--; 8924792Smckusic fs->fs_cstotal.cs_ndir--; 8935322Smckusic fs->fs_cs(fs, cg).cs_ndir--; 8944359Smckusick } 8954359Smckusick fs->fs_fmod++; 8964359Smckusick bdwrite(bp); 8974359Smckusick } 8984359Smckusick 8994463Smckusic /* 9005375Smckusic * Find a block of the specified size in the specified cylinder group. 9015375Smckusic * 9024651Smckusic * It is a panic if a request is made to find a block if none are 9034651Smckusic * available. 9044651Smckusic */ 9054651Smckusic daddr_t 9064651Smckusic mapsearch(fs, cgp, bpref, allocsiz) 9074651Smckusic register struct fs *fs; 9084651Smckusic register struct cg *cgp; 9094651Smckusic daddr_t bpref; 9104651Smckusic int allocsiz; 9114651Smckusic { 9124651Smckusic daddr_t bno; 9134651Smckusic int start, len, loc, i; 9144651Smckusic int blk, field, subfield, pos; 9154651Smckusic 9164651Smckusic /* 9174651Smckusic * find the fragment by searching through the free block 9184651Smckusic * map for an appropriate bit pattern 9194651Smckusic */ 9204651Smckusic if (bpref) 9215377Smckusic start = dtogd(fs, bpref) / NBBY; 9224651Smckusic else 9234651Smckusic start = cgp->cg_frotor / NBBY; 9245398Smckusic len = howmany(fs->fs_fpg, NBBY) - start; 92512755Ssam loc = scanc((unsigned)len, (caddr_t)&cgp->cg_free[start], 92612755Ssam (caddr_t)fragtbl[fs->fs_frag], 92712755Ssam (int)(1 << (allocsiz - 1 + (fs->fs_frag % NBBY)))); 9284651Smckusic if (loc == 0) { 9296531Smckusick len = start + 1; 9306531Smckusick start = 0; 93117697Smckusick loc = scanc((unsigned)len, (caddr_t)&cgp->cg_free[0], 93212755Ssam (caddr_t)fragtbl[fs->fs_frag], 93312755Ssam (int)(1 << (allocsiz - 1 + (fs->fs_frag % NBBY)))); 93416784Smckusick if (loc == 0) { 93516784Smckusick printf("start = %d, len = %d, fs = %s\n", 93616784Smckusick start, len, fs->fs_fsmnt); 93716784Smckusick panic("alloccg: map corrupted"); 93817697Smckusick /* NOTREACHED */ 93916784Smckusick } 9404651Smckusic } 9414651Smckusic bno = (start + len - loc) * NBBY; 9424651Smckusic cgp->cg_frotor = bno; 9434651Smckusic /* 9444651Smckusic * found the byte in the map 9454651Smckusic * sift through the bits to find the selected frag 9464651Smckusic */ 9476294Smckusick for (i = bno + NBBY; bno < i; bno += fs->fs_frag) { 9486294Smckusick blk = blkmap(fs, cgp->cg_free, bno); 9494651Smckusic blk <<= 1; 9504651Smckusic field = around[allocsiz]; 9514651Smckusic subfield = inside[allocsiz]; 9525322Smckusic for (pos = 0; pos <= fs->fs_frag - allocsiz; pos++) { 9536294Smckusick if ((blk & field) == subfield) 9546294Smckusick return (bno + pos); 9554651Smckusic field <<= 1; 9564651Smckusic subfield <<= 1; 9574651Smckusic } 9584651Smckusic } 9596716Smckusick printf("bno = %d, fs = %s\n", bno, fs->fs_fsmnt); 9604651Smckusic panic("alloccg: block not in map"); 9616531Smckusick return (-1); 9624651Smckusic } 9634651Smckusic 9644651Smckusic /* 9655375Smckusic * Fserr prints the name of a file system with an error diagnostic. 9665375Smckusic * 9675375Smckusic * The form of the error message is: 9684359Smckusick * fs: error message 9694359Smckusick */ 9704359Smckusick fserr(fs, cp) 9714359Smckusick struct fs *fs; 9724359Smckusick char *cp; 9734359Smckusick { 9744359Smckusick 975*18307Sralph log(KERN_FAIL, "%s: %s\n", fs->fs_fsmnt, cp); 9764359Smckusick } 977