1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1980, 1986, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 #if 0 33 #ifndef lint 34 static const char sccsid[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95"; 35 #endif /* not lint */ 36 #endif 37 #include <sys/cdefs.h> 38 __FBSDID("$FreeBSD$"); 39 40 #define IN_RTLD /* So we pickup the P_OSREL defines */ 41 #include <sys/param.h> 42 #include <sys/sysctl.h> 43 44 #include <ufs/ufs/dinode.h> 45 #include <ufs/ffs/fs.h> 46 47 #include <err.h> 48 #include <inttypes.h> 49 #include <limits.h> 50 #include <string.h> 51 #include <libufs.h> 52 53 #include "fsck.h" 54 55 static void check_maps(u_char *, u_char *, int, ufs2_daddr_t, const char *, 56 int *, int, int, int); 57 static void clear_blocks(ufs2_daddr_t start, ufs2_daddr_t end); 58 59 void 60 pass5(void) 61 { 62 int c, i, j, blk, frags, basesize, mapsize; 63 int inomapsize, blkmapsize; 64 struct fs *fs = &sblock; 65 ufs2_daddr_t d, dbase, dmax, start; 66 int rewritecg = 0, cgckadd = 0; 67 struct csum *cs; 68 struct csum_total cstotal; 69 struct inodesc idesc[3]; 70 char buf[MAXBSIZE]; 71 struct cg *cg, *newcg = (struct cg *)buf; 72 struct bufarea *cgbp; 73 74 inoinfo(UFS_WINO)->ino_state = USTATE; 75 memset(newcg, 0, (size_t)fs->fs_cgsize); 76 newcg->cg_niblk = fs->fs_ipg; 77 if (preen == 0 && yflag == 0 && fs->fs_magic == FS_UFS2_MAGIC && 78 fswritefd != -1 && (fs->fs_metackhash & CK_CYLGRP) == 0 && 79 getosreldate() >= P_OSREL_CK_CYLGRP && 80 reply("ADD CYLINDER GROUP CHECKSUM PROTECTION") != 0) { 81 fs->fs_metackhash |= CK_CYLGRP; 82 rewritecg = 1; 83 cgckadd = 1; 84 sbdirty(); 85 } 86 if (cvtlevel >= 3) { 87 if (fs->fs_maxcontig < 2 && fs->fs_contigsumsize > 0) { 88 if (preen) 89 pwarn("DELETING CLUSTERING MAPS\n"); 90 if (preen || reply("DELETE CLUSTERING MAPS")) { 91 fs->fs_contigsumsize = 0; 92 rewritecg = 1; 93 sbdirty(); 94 } 95 } 96 if (fs->fs_maxcontig > 1) { 97 const char *doit = NULL; 98 99 if (fs->fs_contigsumsize < 1) { 100 doit = "CREAT"; 101 } else if (fs->fs_contigsumsize < fs->fs_maxcontig && 102 fs->fs_contigsumsize < FS_MAXCONTIG) { 103 doit = "EXPAND"; 104 } 105 if (doit) { 106 i = fs->fs_contigsumsize; 107 fs->fs_contigsumsize = 108 MIN(fs->fs_maxcontig, FS_MAXCONTIG); 109 if (CGSIZE(fs) > (u_int)fs->fs_bsize) { 110 pwarn("CANNOT %s CLUSTER MAPS\n", doit); 111 fs->fs_contigsumsize = i; 112 } else if (preen || 113 reply("CREATE CLUSTER MAPS")) { 114 if (preen) 115 pwarn("%sING CLUSTER MAPS\n", 116 doit); 117 fs->fs_cgsize = 118 fragroundup(fs, CGSIZE(fs)); 119 rewritecg = 1; 120 sbdirty(); 121 } 122 } 123 } 124 } 125 basesize = &newcg->cg_space[0] - (u_char *)(&newcg->cg_firstfield); 126 if (sblock.fs_magic == FS_UFS2_MAGIC) { 127 newcg->cg_iusedoff = basesize; 128 } else { 129 /* 130 * We reserve the space for the old rotation summary 131 * tables for the benefit of old kernels, but do not 132 * maintain them in modern kernels. In time, they can 133 * go away. 134 */ 135 newcg->cg_old_btotoff = basesize; 136 newcg->cg_old_boff = newcg->cg_old_btotoff + 137 fs->fs_old_cpg * sizeof(int32_t); 138 newcg->cg_iusedoff = newcg->cg_old_boff + 139 fs->fs_old_cpg * fs->fs_old_nrpos * sizeof(u_int16_t); 140 memset(&newcg->cg_space[0], 0, newcg->cg_iusedoff - basesize); 141 } 142 inomapsize = howmany(fs->fs_ipg, CHAR_BIT); 143 newcg->cg_freeoff = newcg->cg_iusedoff + inomapsize; 144 blkmapsize = howmany(fs->fs_fpg, CHAR_BIT); 145 newcg->cg_nextfreeoff = newcg->cg_freeoff + blkmapsize; 146 if (fs->fs_contigsumsize > 0) { 147 newcg->cg_clustersumoff = newcg->cg_nextfreeoff - 148 sizeof(u_int32_t); 149 newcg->cg_clustersumoff = 150 roundup(newcg->cg_clustersumoff, sizeof(u_int32_t)); 151 newcg->cg_clusteroff = newcg->cg_clustersumoff + 152 (fs->fs_contigsumsize + 1) * sizeof(u_int32_t); 153 newcg->cg_nextfreeoff = newcg->cg_clusteroff + 154 howmany(fragstoblks(fs, fs->fs_fpg), CHAR_BIT); 155 } 156 newcg->cg_magic = CG_MAGIC; 157 mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff; 158 memset(&idesc[0], 0, sizeof idesc); 159 for (i = 0; i < 3; i++) 160 idesc[i].id_type = ADDR; 161 memset(&cstotal, 0, sizeof(struct csum_total)); 162 dmax = blknum(fs, fs->fs_size + fs->fs_frag - 1); 163 for (d = fs->fs_size; d < dmax; d++) 164 setbmap(d); 165 for (c = 0; c < fs->fs_ncg; c++) { 166 if (got_siginfo) { 167 printf("%s: phase 5: cyl group %d of %d (%d%%)\n", 168 cdevname, c, sblock.fs_ncg, 169 c * 100 / sblock.fs_ncg); 170 got_siginfo = 0; 171 } 172 if (got_sigalarm) { 173 setproctitle("%s p5 %d%%", cdevname, 174 c * 100 / sblock.fs_ncg); 175 got_sigalarm = 0; 176 } 177 cgbp = cglookup(c); 178 cg = cgbp->b_un.b_cg; 179 if (!cg_chkmagic(cg)) 180 pfatal("CG %d: BAD MAGIC NUMBER\n", c); 181 if ((fs->fs_metackhash & CK_CYLGRP) != 0 && cgckadd == 0) { 182 uint32_t ckhash, thishash; 183 184 ckhash = cg->cg_ckhash; 185 cg->cg_ckhash = 0; 186 thishash = calculate_crc32c(~0L, cg, fs->fs_cgsize); 187 if (ckhash != thishash) 188 pwarn("CG %d: BAD CHECKSUM %#x vs %#x", c, ckhash, thishash); 189 cg->cg_ckhash = ckhash; 190 } 191 newcg->cg_time = cg->cg_time; 192 newcg->cg_old_time = cg->cg_old_time; 193 newcg->cg_unrefs = cg->cg_unrefs; 194 newcg->cg_cgx = c; 195 dbase = cgbase(fs, c); 196 dmax = dbase + fs->fs_fpg; 197 if (dmax > fs->fs_size) 198 dmax = fs->fs_size; 199 newcg->cg_ndblk = dmax - dbase; 200 if (fs->fs_magic == FS_UFS1_MAGIC) { 201 if (c == fs->fs_ncg - 1) 202 newcg->cg_old_ncyl = howmany(newcg->cg_ndblk, 203 fs->fs_fpg / fs->fs_old_cpg); 204 else 205 newcg->cg_old_ncyl = fs->fs_old_cpg; 206 newcg->cg_old_niblk = fs->fs_ipg; 207 newcg->cg_niblk = 0; 208 } 209 if (fs->fs_contigsumsize > 0) 210 newcg->cg_nclusterblks = newcg->cg_ndblk / fs->fs_frag; 211 newcg->cg_cs.cs_ndir = 0; 212 newcg->cg_cs.cs_nffree = 0; 213 newcg->cg_cs.cs_nbfree = 0; 214 newcg->cg_cs.cs_nifree = fs->fs_ipg; 215 if (cg->cg_rotor >= 0 && cg->cg_rotor < newcg->cg_ndblk) 216 newcg->cg_rotor = cg->cg_rotor; 217 else 218 newcg->cg_rotor = 0; 219 if (cg->cg_frotor >= 0 && cg->cg_frotor < newcg->cg_ndblk) 220 newcg->cg_frotor = cg->cg_frotor; 221 else 222 newcg->cg_frotor = 0; 223 if (cg->cg_irotor >= 0 && cg->cg_irotor < fs->fs_ipg) 224 newcg->cg_irotor = cg->cg_irotor; 225 else 226 newcg->cg_irotor = 0; 227 if (fs->fs_magic == FS_UFS1_MAGIC) { 228 newcg->cg_initediblk = 0; 229 } else { 230 if ((unsigned)cg->cg_initediblk > fs->fs_ipg) 231 newcg->cg_initediblk = fs->fs_ipg; 232 else 233 newcg->cg_initediblk = cg->cg_initediblk; 234 } 235 memset(&newcg->cg_frsum[0], 0, sizeof newcg->cg_frsum); 236 memset(cg_inosused(newcg), 0, (size_t)(mapsize)); 237 j = fs->fs_ipg * c; 238 for (i = 0; i < inostathead[c].il_numalloced; j++, i++) { 239 switch (inoinfo(j)->ino_state) { 240 241 case USTATE: 242 break; 243 244 case DSTATE: 245 case DCLEAR: 246 case DFOUND: 247 case DZLINK: 248 newcg->cg_cs.cs_ndir++; 249 /* FALLTHROUGH */ 250 251 case FSTATE: 252 case FCLEAR: 253 case FZLINK: 254 newcg->cg_cs.cs_nifree--; 255 setbit(cg_inosused(newcg), i); 256 break; 257 258 default: 259 if (j < (int)UFS_ROOTINO) 260 break; 261 errx(EEXIT, "BAD STATE %d FOR INODE I=%d", 262 inoinfo(j)->ino_state, j); 263 } 264 } 265 if (c == 0) 266 for (i = 0; i < (int)UFS_ROOTINO; i++) { 267 setbit(cg_inosused(newcg), i); 268 newcg->cg_cs.cs_nifree--; 269 } 270 start = -1; 271 for (i = 0, d = dbase; 272 d < dmax; 273 d += fs->fs_frag, i += fs->fs_frag) { 274 frags = 0; 275 for (j = 0; j < fs->fs_frag; j++) { 276 if (testbmap(d + j)) { 277 if ((Eflag || Zflag) && start != -1) { 278 clear_blocks(start, d + j - 1); 279 start = -1; 280 } 281 continue; 282 } 283 if (start == -1) 284 start = d + j; 285 setbit(cg_blksfree(newcg), i + j); 286 frags++; 287 } 288 if (frags == fs->fs_frag) { 289 newcg->cg_cs.cs_nbfree++; 290 if (fs->fs_contigsumsize > 0) 291 setbit(cg_clustersfree(newcg), 292 i / fs->fs_frag); 293 } else if (frags > 0) { 294 newcg->cg_cs.cs_nffree += frags; 295 blk = blkmap(fs, cg_blksfree(newcg), i); 296 ffs_fragacct(fs, blk, newcg->cg_frsum, 1); 297 } 298 } 299 if ((Eflag || Zflag) && start != -1) 300 clear_blocks(start, d - 1); 301 if (fs->fs_contigsumsize > 0) { 302 int32_t *sump = cg_clustersum(newcg); 303 u_char *mapp = cg_clustersfree(newcg); 304 int map = *mapp++; 305 int bit = 1; 306 int run = 0; 307 308 for (i = 0; i < newcg->cg_nclusterblks; i++) { 309 if ((map & bit) != 0) { 310 run++; 311 } else if (run != 0) { 312 if (run > fs->fs_contigsumsize) 313 run = fs->fs_contigsumsize; 314 sump[run]++; 315 run = 0; 316 } 317 if ((i & (CHAR_BIT - 1)) != (CHAR_BIT - 1)) { 318 bit <<= 1; 319 } else { 320 map = *mapp++; 321 bit = 1; 322 } 323 } 324 if (run != 0) { 325 if (run > fs->fs_contigsumsize) 326 run = fs->fs_contigsumsize; 327 sump[run]++; 328 } 329 } 330 if ((fs->fs_metackhash & CK_CYLGRP) != 0) { 331 newcg->cg_ckhash = 0; 332 newcg->cg_ckhash = 333 calculate_crc32c(~0L, (void *)newcg, fs->fs_cgsize); 334 } 335 336 if (bkgrdflag != 0) { 337 cstotal.cs_nffree += cg->cg_cs.cs_nffree; 338 cstotal.cs_nbfree += cg->cg_cs.cs_nbfree; 339 cstotal.cs_nifree += cg->cg_cs.cs_nifree; 340 cstotal.cs_ndir += cg->cg_cs.cs_ndir; 341 } else { 342 cstotal.cs_nffree += newcg->cg_cs.cs_nffree; 343 cstotal.cs_nbfree += newcg->cg_cs.cs_nbfree; 344 cstotal.cs_nifree += newcg->cg_cs.cs_nifree; 345 cstotal.cs_ndir += newcg->cg_cs.cs_ndir; 346 } 347 cs = &fs->fs_cs(fs, c); 348 if (cursnapshot == 0 && 349 memcmp(&newcg->cg_cs, cs, sizeof *cs) != 0 && 350 dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) { 351 memmove(cs, &newcg->cg_cs, sizeof *cs); 352 sbdirty(); 353 } 354 if (rewritecg) { 355 memmove(cg, newcg, (size_t)fs->fs_cgsize); 356 dirty(cgbp); 357 continue; 358 } 359 if (cursnapshot == 0 && 360 memcmp(newcg, cg, basesize) != 0 && 361 dofix(&idesc[2], "SUMMARY INFORMATION BAD")) { 362 memmove(cg, newcg, (size_t)basesize); 363 dirty(cgbp); 364 } 365 if (bkgrdflag != 0 || usedsoftdep || debug) 366 update_maps(cg, newcg, bkgrdflag); 367 if (cursnapshot == 0 && 368 memcmp(cg_inosused(newcg), cg_inosused(cg), mapsize) != 0 && 369 dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) { 370 memmove(cg_inosused(cg), cg_inosused(newcg), 371 (size_t)mapsize); 372 dirty(cgbp); 373 } 374 } 375 if (cursnapshot == 0 && 376 memcmp(&cstotal, &fs->fs_cstotal, sizeof cstotal) != 0 377 && dofix(&idesc[0], "SUMMARY BLK COUNT(S) WRONG IN SUPERBLK")) { 378 memmove(&fs->fs_cstotal, &cstotal, sizeof cstotal); 379 fs->fs_ronly = 0; 380 fs->fs_fmod = 0; 381 sbdirty(); 382 } 383 384 /* 385 * When doing background fsck on a snapshot, figure out whether 386 * the superblock summary is inaccurate and correct it when 387 * necessary. 388 */ 389 if (cursnapshot != 0) { 390 cmd.size = 1; 391 392 cmd.value = cstotal.cs_ndir - fs->fs_cstotal.cs_ndir; 393 if (cmd.value != 0) { 394 if (debug) 395 printf("adjndir by %+" PRIi64 "\n", cmd.value); 396 if (bkgrdsumadj == 0 || sysctl(adjndir, MIBSIZE, 0, 0, 397 &cmd, sizeof cmd) == -1) 398 rwerror("ADJUST NUMBER OF DIRECTORIES", cmd.value); 399 } 400 401 cmd.value = cstotal.cs_nbfree - fs->fs_cstotal.cs_nbfree; 402 if (cmd.value != 0) { 403 if (debug) 404 printf("adjnbfree by %+" PRIi64 "\n", cmd.value); 405 if (bkgrdsumadj == 0 || sysctl(adjnbfree, MIBSIZE, 0, 0, 406 &cmd, sizeof cmd) == -1) 407 rwerror("ADJUST NUMBER OF FREE BLOCKS", cmd.value); 408 } 409 410 cmd.value = cstotal.cs_nifree - fs->fs_cstotal.cs_nifree; 411 if (cmd.value != 0) { 412 if (debug) 413 printf("adjnifree by %+" PRIi64 "\n", cmd.value); 414 if (bkgrdsumadj == 0 || sysctl(adjnifree, MIBSIZE, 0, 0, 415 &cmd, sizeof cmd) == -1) 416 rwerror("ADJUST NUMBER OF FREE INODES", cmd.value); 417 } 418 419 cmd.value = cstotal.cs_nffree - fs->fs_cstotal.cs_nffree; 420 if (cmd.value != 0) { 421 if (debug) 422 printf("adjnffree by %+" PRIi64 "\n", cmd.value); 423 if (bkgrdsumadj == 0 || sysctl(adjnffree, MIBSIZE, 0, 0, 424 &cmd, sizeof cmd) == -1) 425 rwerror("ADJUST NUMBER OF FREE FRAGS", cmd.value); 426 } 427 428 cmd.value = cstotal.cs_numclusters - fs->fs_cstotal.cs_numclusters; 429 if (cmd.value != 0) { 430 if (debug) 431 printf("adjnumclusters by %+" PRIi64 "\n", cmd.value); 432 if (bkgrdsumadj == 0 || sysctl(adjnumclusters, MIBSIZE, 0, 0, 433 &cmd, sizeof cmd) == -1) 434 rwerror("ADJUST NUMBER OF FREE CLUSTERS", cmd.value); 435 } 436 } 437 } 438 439 /* 440 * Compare the original cylinder group inode and block bitmaps with the 441 * updated cylinder group inode and block bitmaps. Free inodes and blocks 442 * that have been added. Complain if any previously freed inodes blocks 443 * are now allocated. 444 */ 445 void 446 update_maps( 447 struct cg *oldcg, /* cylinder group of claimed allocations */ 448 struct cg *newcg, /* cylinder group of determined allocations */ 449 int usesysctl) /* 1 => use sysctl interface to update maps */ 450 { 451 int inomapsize, excessdirs; 452 struct fs *fs = &sblock; 453 454 inomapsize = howmany(fs->fs_ipg, CHAR_BIT); 455 excessdirs = oldcg->cg_cs.cs_ndir - newcg->cg_cs.cs_ndir; 456 if (excessdirs < 0) { 457 pfatal("LOST %d DIRECTORIES\n", -excessdirs); 458 excessdirs = 0; 459 } 460 if (excessdirs > 0) 461 check_maps(cg_inosused(newcg), cg_inosused(oldcg), inomapsize, 462 oldcg->cg_cgx * (ufs2_daddr_t)fs->fs_ipg, "DIR", freedirs, 463 0, excessdirs, usesysctl); 464 check_maps(cg_inosused(newcg), cg_inosused(oldcg), inomapsize, 465 oldcg->cg_cgx * (ufs2_daddr_t)fs->fs_ipg, "FILE", freefiles, 466 excessdirs, fs->fs_ipg, usesysctl); 467 check_maps(cg_blksfree(oldcg), cg_blksfree(newcg), 468 howmany(fs->fs_fpg, CHAR_BIT), 469 oldcg->cg_cgx * (ufs2_daddr_t)fs->fs_fpg, "FRAG", 470 freeblks, 0, fs->fs_fpg, usesysctl); 471 } 472 473 static void 474 check_maps( 475 u_char *map1, /* map of claimed allocations */ 476 u_char *map2, /* map of determined allocations */ 477 int mapsize, /* size of above two maps */ 478 ufs2_daddr_t startvalue, /* resource value for first element in map */ 479 const char *name, /* name of resource found in maps */ 480 int *opcode, /* sysctl opcode to free resource */ 481 int skip, /* number of entries to skip before starting to free */ 482 int limit, /* limit on number of entries to free */ 483 int usesysctl) /* 1 => use sysctl interface to update maps */ 484 { 485 # define BUFSIZE 16 486 char buf[BUFSIZE]; 487 long i, j, k, l, m, size; 488 ufs2_daddr_t n, astart, aend, ustart, uend; 489 void (*msg)(const char *fmt, ...); 490 491 if (usesysctl) 492 msg = pfatal; 493 else 494 msg = pwarn; 495 astart = ustart = aend = uend = -1; 496 for (i = 0; i < mapsize; i++) { 497 j = *map1++; 498 k = *map2++; 499 if (j == k) 500 continue; 501 for (m = 0, l = 1; m < CHAR_BIT; m++, l <<= 1) { 502 if ((j & l) == (k & l)) 503 continue; 504 n = startvalue + i * CHAR_BIT + m; 505 if ((j & l) != 0) { 506 if (astart == -1) { 507 astart = aend = n; 508 continue; 509 } 510 if (aend + 1 == n) { 511 aend = n; 512 continue; 513 } 514 if (astart == aend) 515 (*msg)("ALLOCATED %s %" PRId64 516 " MARKED FREE\n", 517 name, astart); 518 else 519 (*msg)("%s %sS %" PRId64 "-%" PRId64 520 " MARKED FREE\n", 521 "ALLOCATED", name, astart, aend); 522 astart = aend = n; 523 } else { 524 if (ustart == -1) { 525 ustart = uend = n; 526 continue; 527 } 528 if (uend + 1 == n) { 529 uend = n; 530 continue; 531 } 532 size = uend - ustart + 1; 533 if (size <= skip) { 534 skip -= size; 535 ustart = uend = n; 536 continue; 537 } 538 if (skip > 0) { 539 ustart += skip; 540 size -= skip; 541 skip = 0; 542 } 543 if (size > limit) 544 size = limit; 545 if (debug && size == 1) 546 pwarn("%s %s %" PRId64 547 " MARKED USED\n", 548 "UNALLOCATED", name, ustart); 549 else if (debug) 550 pwarn("%s %sS %" PRId64 "-%" PRId64 551 " MARKED USED\n", 552 "UNALLOCATED", name, ustart, 553 ustart + size - 1); 554 if (usesysctl != 0) { 555 cmd.value = ustart; 556 cmd.size = size; 557 if (sysctl(opcode, MIBSIZE, 0, 0, 558 &cmd, sizeof cmd) == -1) { 559 snprintf(buf, BUFSIZE, 560 "FREE %s", name); 561 rwerror(buf, cmd.value); 562 } 563 } 564 limit -= size; 565 if (limit <= 0) 566 return; 567 ustart = uend = n; 568 } 569 } 570 } 571 if (astart != -1) { 572 if (astart == aend) 573 (*msg)("ALLOCATED %s %" PRId64 574 " MARKED FREE\n", name, astart); 575 else 576 (*msg)("ALLOCATED %sS %" PRId64 "-%" PRId64 577 " MARKED FREE\n", 578 name, astart, aend); 579 } 580 if (ustart != -1) { 581 size = uend - ustart + 1; 582 if (size <= skip) 583 return; 584 if (skip > 0) { 585 ustart += skip; 586 size -= skip; 587 } 588 if (size > limit) 589 size = limit; 590 if (debug) { 591 if (size == 1) 592 pwarn("UNALLOCATED %s %" PRId64 593 " MARKED USED\n", 594 name, ustart); 595 else 596 pwarn("UNALLOCATED %sS %" PRId64 "-%" PRId64 597 " MARKED USED\n", 598 name, ustart, ustart + size - 1); 599 } 600 if (usesysctl != 0) { 601 cmd.value = ustart; 602 cmd.size = size; 603 if (sysctl(opcode, MIBSIZE, 0, 0, &cmd, 604 sizeof cmd) == -1) { 605 snprintf(buf, BUFSIZE, "FREE %s", name); 606 rwerror(buf, cmd.value); 607 } 608 } 609 } 610 } 611 612 static void 613 clear_blocks(ufs2_daddr_t start, ufs2_daddr_t end) 614 { 615 616 if (debug) 617 printf("Zero frags %jd to %jd\n", start, end); 618 if (Zflag) 619 blzero(fswritefd, fsbtodb(&sblock, start), 620 lfragtosize(&sblock, end - start + 1)); 621 if (Eflag) 622 blerase(fswritefd, fsbtodb(&sblock, start), 623 lfragtosize(&sblock, end - start + 1)); 624 } 625