+ request = nsize;
+ if (fs->fs_minfree < 5 ||
+ fs->fs_cstotal.cs_nffree >
+ fs->fs_dsize * fs->fs_minfree / (2 * 100))
+ break;
+ log(LOG_NOTICE, "%s: optimization changed from SPACE to TIME\n",
+ fs->fs_fsmnt);
+ fs->fs_optim = FS_OPTTIME;
+ break;
+ case FS_OPTTIME:
+ /*
+ * At this point we have discovered a file that is trying
+ * to grow a small fragment to a larger fragment. To save
+ * time, we allocate a full sized block, then free the
+ * unused portion. If the file continues to grow, the
+ * `fragextend' call above will be able to grow it in place
+ * without further copying. If aberrant programs cause
+ * disk fragmentation to grow within 2% of the free reserve,
+ * we choose to begin optimizing for space.
+ */
+ request = fs->fs_bsize;
+ if (fs->fs_cstotal.cs_nffree <
+ fs->fs_dsize * (fs->fs_minfree - 2) / 100)
+ break;
+ log(LOG_NOTICE, "%s: optimization changed from TIME to SPACE\n",
+ fs->fs_fsmnt);
+ fs->fs_optim = FS_OPTSPACE;
+ break;
+ default:
+ printf("dev = 0x%x, optim = %d, fs = %s\n",
+ ip->i_dev, fs->fs_optim, fs->fs_fsmnt);
+ panic("realloccg: bad optim");
+ /* NOTREACHED */
+ }
+ bno = (daddr_t)hashalloc(ip, cg, (long)bpref, request,
+ (u_long (*)())alloccg);
+ if (bno > 0) {
+#ifdef SECSIZE
+ obp = bread(ip->i_dev, fsbtodb(fs, bprev), osize,
+ fs->fs_dbsize);
+#else SECSIZE
+ error = bread(ip->i_devvp, fsbtodb(fs, bprev),
+ osize, NOCRED, &obp);
+ if (error) {
+ brelse(obp);
+ return (error);
+ }
+ bn = fsbtodb(fs, bno);
+#ifdef SECSIZE
+ bp = getblk(ip->i_dev, bn, nsize, fs->fs_dbsize);
+#else SECSIZE
+ bp = getblk(ip->i_devvp, bn, nsize);
+#endif SECSIZE
+ bcopy(obp->b_un.b_addr, bp->b_un.b_addr, (u_int)osize);
+ count = howmany(osize, CLBYTES);
+ for (i = 0; i < count; i++)
+#ifdef SECSIZE
+ munhash(ip->i_dev, bn + i * CLBYTES / fs->fs_dbsize);
+#else SECSIZE
+ munhash(ip->i_dev, bn + i * CLBYTES / DEV_BSIZE);
+#endif SECSIZE
+ bzero(bp->b_un.b_addr + osize, (unsigned)nsize - osize);
+ if (obp->b_flags & B_DELWRI) {
+ obp->b_flags &= ~B_DELWRI;
+ u.u_ru.ru_oublock--; /* delete charge */
+ }