1 1.62 joerg /* $NetBSD: setup.c,v 1.62 2020/04/03 19:36:33 joerg Exp $ */ 2 1.1 perseant 3 1.13 perseant /*- 4 1.13 perseant * Copyright (c) 2003 The NetBSD Foundation, Inc. 5 1.13 perseant * All rights reserved. 6 1.13 perseant * 7 1.13 perseant * This code is derived from software contributed to The NetBSD Foundation 8 1.13 perseant * by Konrad E. Schroder <perseant (at) hhhh.org>. 9 1.13 perseant * 10 1.13 perseant * Redistribution and use in source and binary forms, with or without 11 1.13 perseant * modification, are permitted provided that the following conditions 12 1.13 perseant * are met: 13 1.13 perseant * 1. Redistributions of source code must retain the above copyright 14 1.13 perseant * notice, this list of conditions and the following disclaimer. 15 1.13 perseant * 2. Redistributions in binary form must reproduce the above copyright 16 1.13 perseant * notice, this list of conditions and the following disclaimer in the 17 1.13 perseant * documentation and/or other materials provided with the distribution. 18 1.13 perseant * 19 1.13 perseant * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.13 perseant * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.13 perseant * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.13 perseant * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.13 perseant * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.13 perseant * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.13 perseant * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.13 perseant * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.13 perseant * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.13 perseant * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.13 perseant * POSSIBILITY OF SUCH DAMAGE. 30 1.13 perseant */ 31 1.1 perseant /* 32 1.1 perseant * Copyright (c) 1980, 1986, 1993 33 1.1 perseant * The Regents of the University of California. All rights reserved. 34 1.1 perseant * 35 1.1 perseant * Redistribution and use in source and binary forms, with or without 36 1.1 perseant * modification, are permitted provided that the following conditions 37 1.1 perseant * are met: 38 1.1 perseant * 1. Redistributions of source code must retain the above copyright 39 1.1 perseant * notice, this list of conditions and the following disclaimer. 40 1.1 perseant * 2. Redistributions in binary form must reproduce the above copyright 41 1.1 perseant * notice, this list of conditions and the following disclaimer in the 42 1.1 perseant * documentation and/or other materials provided with the distribution. 43 1.17 agc * 3. Neither the name of the University nor the names of its contributors 44 1.1 perseant * may be used to endorse or promote products derived from this software 45 1.1 perseant * without specific prior written permission. 46 1.1 perseant * 47 1.1 perseant * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 48 1.1 perseant * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 1.1 perseant * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 1.1 perseant * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 1.1 perseant * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 1.1 perseant * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 1.1 perseant * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 1.1 perseant * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 1.1 perseant * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 1.1 perseant * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 1.1 perseant * SUCH DAMAGE. 58 1.1 perseant */ 59 1.1 perseant 60 1.1 perseant /* #define DKTYPENAMES */ 61 1.1 perseant #define FSTYPENAMES 62 1.13 perseant #include <sys/types.h> 63 1.1 perseant #include <sys/param.h> 64 1.1 perseant #include <sys/time.h> 65 1.13 perseant #include <sys/buf.h> 66 1.13 perseant #include <sys/mount.h> 67 1.13 perseant #include <sys/queue.h> 68 1.1 perseant #include <sys/stat.h> 69 1.1 perseant #include <sys/ioctl.h> 70 1.1 perseant #include <sys/disklabel.h> 71 1.37 mlelstv #include <sys/disk.h> 72 1.1 perseant #include <sys/file.h> 73 1.1 perseant 74 1.41 dholland #define vnode uvnode 75 1.1 perseant #include <ufs/lfs/lfs.h> 76 1.49 dholland #include <ufs/lfs/lfs_accessors.h> 77 1.43 dholland #include <ufs/lfs/lfs_inode.h> 78 1.13 perseant #undef vnode 79 1.1 perseant 80 1.1 perseant #include <ctype.h> 81 1.1 perseant #include <err.h> 82 1.1 perseant #include <errno.h> 83 1.1 perseant #include <stdio.h> 84 1.1 perseant #include <stdlib.h> 85 1.37 mlelstv #include <unistd.h> 86 1.1 perseant #include <string.h> 87 1.29 perseant #include <time.h> 88 1.32 christos #include <util.h> 89 1.1 perseant 90 1.13 perseant #include "bufcache.h" 91 1.26 christos #include "lfs_user.h" 92 1.13 perseant 93 1.1 perseant #include "fsck.h" 94 1.1 perseant #include "extern.h" 95 1.1 perseant #include "fsutil.h" 96 1.1 perseant 97 1.51 dholland static uint64_t calcmaxfilesize(unsigned); 98 1.1 perseant 99 1.59 dholland daddr_t *din_table; 100 1.13 perseant SEGUSE *seg_table; 101 1.4 perseant 102 1.1 perseant #ifdef DKTYPENAMES 103 1.13 perseant int useless(void); 104 1.1 perseant 105 1.1 perseant int 106 1.1 perseant useless(void) 107 1.1 perseant { 108 1.13 perseant char **foo = (char **) dktypenames; 109 1.13 perseant char **bar = (char **) fscknames; 110 1.1 perseant 111 1.5 perseant return foo - bar; 112 1.1 perseant } 113 1.1 perseant #endif 114 1.1 perseant 115 1.18 minoura /* 116 1.18 minoura * calculate the maximum file size allowed with the specified block shift. 117 1.18 minoura */ 118 1.18 minoura static uint64_t 119 1.51 dholland calcmaxfilesize(unsigned bshift) 120 1.18 minoura { 121 1.18 minoura uint64_t nptr; /* number of block pointers per block */ 122 1.18 minoura uint64_t maxblock; 123 1.18 minoura 124 1.60 dholland nptr = (1 << bshift) / LFS_BLKPTRSIZE(fs); 125 1.40 dholland maxblock = ULFS_NDADDR + nptr + nptr * nptr + nptr * nptr * nptr; 126 1.18 minoura 127 1.18 minoura return maxblock << bshift; 128 1.18 minoura } 129 1.20 perseant 130 1.20 perseant void 131 1.20 perseant reset_maxino(ino_t len) 132 1.20 perseant { 133 1.29 perseant if (debug) 134 1.29 perseant pwarn("maxino reset from %lld to %lld\n", (long long)maxino, 135 1.29 perseant (long long)len); 136 1.29 perseant 137 1.32 christos din_table = erealloc(din_table, len * sizeof(*din_table)); 138 1.32 christos statemap = erealloc(statemap, len * sizeof(char)); 139 1.32 christos typemap = erealloc(typemap, len * sizeof(char)); 140 1.32 christos lncntp = erealloc(lncntp, len * sizeof(int16_t)); 141 1.20 perseant 142 1.20 perseant memset(din_table + maxino, 0, (len - maxino) * sizeof(*din_table)); 143 1.29 perseant memset(statemap + maxino, USTATE, (len - maxino) * sizeof(char)); 144 1.20 perseant memset(typemap + maxino, 0, (len - maxino) * sizeof(char)); 145 1.20 perseant memset(lncntp + maxino, 0, (len - maxino) * sizeof(int16_t)); 146 1.20 perseant 147 1.24 perseant maxino = len; 148 1.24 perseant 149 1.29 perseant /* 150 1.29 perseant * We can't roll forward after allocating new inodes in previous 151 1.29 perseant * phases, or thy would conflict (lost+found, for example, might 152 1.29 perseant * disappear to be replaced by a file found in roll-forward). 153 1.29 perseant */ 154 1.29 perseant no_roll_forward = 1; 155 1.29 perseant 156 1.20 perseant return; 157 1.20 perseant } 158 1.29 perseant 159 1.1 perseant int 160 1.5 perseant setup(const char *dev) 161 1.1 perseant { 162 1.61 christos #ifndef VERBOSE_BLOCKMAP 163 1.13 perseant long bmapsize; 164 1.61 christos #endif 165 1.13 perseant struct stat statb; 166 1.13 perseant int doskipclean; 167 1.13 perseant u_int64_t maxfilesize; 168 1.13 perseant int open_flags; 169 1.13 perseant struct uvnode *ivp; 170 1.13 perseant struct ubuf *bp; 171 1.29 perseant int i, isdirty; 172 1.29 perseant long sn, curseg; 173 1.13 perseant SEGUSE *sup; 174 1.53 dholland size_t sumstart; 175 1.1 perseant 176 1.1 perseant havesb = 0; 177 1.1 perseant doskipclean = skipclean; 178 1.1 perseant if (stat(dev, &statb) < 0) { 179 1.29 perseant pfatal("Can't stat %s: %s\n", dev, strerror(errno)); 180 1.1 perseant return (0); 181 1.1 perseant } 182 1.29 perseant if (!S_ISCHR(statb.st_mode) && skipclean) { 183 1.1 perseant pfatal("%s is not a character device", dev); 184 1.1 perseant if (reply("CONTINUE") == 0) 185 1.1 perseant return (0); 186 1.1 perseant } 187 1.13 perseant if (nflag) 188 1.13 perseant open_flags = O_RDONLY; 189 1.13 perseant else 190 1.13 perseant open_flags = O_RDWR; 191 1.13 perseant 192 1.13 perseant if ((fsreadfd = open(dev, open_flags)) < 0) { 193 1.29 perseant pfatal("Can't open %s: %s\n", dev, strerror(errno)); 194 1.1 perseant return (0); 195 1.1 perseant } 196 1.13 perseant if (nflag) { 197 1.1 perseant if (preen) 198 1.1 perseant pfatal("NO WRITE ACCESS"); 199 1.21 perseant printf("** %s (NO WRITE)\n", dev); 200 1.21 perseant quiet = 0; 201 1.21 perseant } else if (!preen && !quiet) 202 1.21 perseant printf("** %s\n", dev); 203 1.21 perseant 204 1.1 perseant fsmodified = 0; 205 1.1 perseant lfdir = 0; 206 1.13 perseant 207 1.29 perseant /* Initialize time in case we have to write */ 208 1.29 perseant time(&write_time); 209 1.29 perseant 210 1.20 perseant bufinit(0); /* XXX we could make a better guess */ 211 1.19 perseant fs = lfs_init(fsreadfd, bflag, idaddr, 0, debug); 212 1.13 perseant if (fs == NULL) { 213 1.13 perseant if (preen) 214 1.13 perseant printf("%s: ", cdevname()); 215 1.34 lukem errexit("BAD SUPER BLOCK OR IFILE INODE NOT FOUND"); 216 1.13 perseant } 217 1.1 perseant 218 1.20 perseant /* Resize buffer cache now that we have a superblock to guess from. */ 219 1.47 dholland bufrehash((lfs_sb_getsegtabsz(fs) + maxino / lfs_sb_getifpb(fs)) << 4); 220 1.20 perseant 221 1.48 dholland if (lfs_sb_getpflags(fs) & LFS_PF_CLEAN) { 222 1.13 perseant if (doskipclean) { 223 1.21 perseant if (!quiet) 224 1.21 perseant pwarn("%sile system is clean; not checking\n", 225 1.21 perseant preen ? "f" : "** F"); 226 1.13 perseant return (-1); 227 1.1 perseant } 228 1.13 perseant if (!preen) 229 1.13 perseant pwarn("** File system is already clean\n"); 230 1.13 perseant } 231 1.9 perseant 232 1.29 perseant if (idaddr) { 233 1.29 perseant daddr_t tdaddr; 234 1.29 perseant SEGSUM *sp; 235 1.29 perseant FINFO *fp; 236 1.29 perseant int bc; 237 1.29 perseant 238 1.29 perseant if (debug) 239 1.51 dholland pwarn("adjusting offset, serial for -i 0x%jx\n", 240 1.51 dholland (uintmax_t)idaddr); 241 1.44 christos tdaddr = lfs_sntod(fs, lfs_dtosn(fs, idaddr)); 242 1.44 christos if (lfs_sntod(fs, lfs_dtosn(fs, tdaddr)) == tdaddr) { 243 1.48 dholland if (tdaddr == lfs_sb_gets0addr(fs)) 244 1.44 christos tdaddr += lfs_btofsb(fs, LFS_LABELPAD); 245 1.29 perseant for (i = 0; i < LFS_MAXNUMSB; i++) { 246 1.48 dholland if (lfs_sb_getsboff(fs, i) == tdaddr) 247 1.44 christos tdaddr += lfs_btofsb(fs, LFS_SBPAD); 248 1.48 dholland if (lfs_sb_getsboff(fs, i) > tdaddr) 249 1.29 perseant break; 250 1.29 perseant } 251 1.29 perseant } 252 1.47 dholland lfs_sb_setoffset(fs, tdaddr); 253 1.29 perseant if (debug) 254 1.47 dholland pwarn("begin with offset/serial 0x%jx/%jd\n", 255 1.47 dholland (uintmax_t)lfs_sb_getoffset(fs), 256 1.47 dholland (intmax_t)lfs_sb_getserial(fs)); 257 1.29 perseant while (tdaddr < idaddr) { 258 1.44 christos bread(fs->lfs_devvp, LFS_FSBTODB(fs, tdaddr), 259 1.48 dholland lfs_sb_getsumsize(fs), 260 1.45 chopps 0, &bp); 261 1.29 perseant sp = (SEGSUM *)bp->b_data; 262 1.53 dholland sumstart = lfs_ss_getsumstart(fs); 263 1.53 dholland if (lfs_ss_getsumsum(fs, sp) != 264 1.53 dholland cksum((char *)sp + sumstart, 265 1.53 dholland lfs_sb_getsumsize(fs) - sumstart)) { 266 1.33 ad brelse(bp, 0); 267 1.30 perseant if (debug) 268 1.51 dholland printf("bad cksum at %jx\n", 269 1.51 dholland (uintmax_t)tdaddr); 270 1.29 perseant break; 271 1.29 perseant } 272 1.53 dholland fp = SEGSUM_FINFOBASE(fs, sp); 273 1.53 dholland bc = howmany(lfs_ss_getninos(fs, sp), LFS_INOPB(fs)) << 274 1.52 dholland (lfs_sb_getversion(fs) > 1 ? lfs_sb_getffshift(fs) : 275 1.48 dholland lfs_sb_getbshift(fs)); 276 1.53 dholland for (i = 0; i < lfs_ss_getnfinfo(fs, sp); i++) { 277 1.54 dholland bc += lfs_fi_getlastlength(fs, fp) + ((lfs_fi_getnblocks(fs, fp) - 1) 278 1.48 dholland << lfs_sb_getbshift(fs)); 279 1.53 dholland fp = NEXT_FINFO(fs, fp); 280 1.29 perseant } 281 1.29 perseant 282 1.44 christos tdaddr += lfs_btofsb(fs, bc) + 1; 283 1.47 dholland lfs_sb_setoffset(fs, tdaddr); 284 1.53 dholland lfs_sb_setserial(fs, lfs_ss_getserial(fs, sp) + 1); 285 1.33 ad brelse(bp, 0); 286 1.29 perseant } 287 1.29 perseant 288 1.29 perseant /* 289 1.29 perseant * Set curseg, nextseg appropriately -- inlined from 290 1.29 perseant * lfs_newseg() 291 1.29 perseant */ 292 1.47 dholland curseg = lfs_dtosn(fs, lfs_sb_getoffset(fs)); 293 1.47 dholland lfs_sb_setcurseg(fs, lfs_sntod(fs, curseg)); 294 1.48 dholland for (sn = curseg + lfs_sb_getinterleave(fs);;) { 295 1.48 dholland sn = (sn + 1) % lfs_sb_getnseg(fs); 296 1.29 perseant if (sn == curseg) 297 1.29 perseant errx(1, "init: no clean segments"); 298 1.29 perseant LFS_SEGENTRY(sup, fs, sn, bp); 299 1.29 perseant isdirty = sup->su_flags & SEGUSE_DIRTY; 300 1.33 ad brelse(bp, 0); 301 1.29 perseant 302 1.29 perseant if (!isdirty) 303 1.29 perseant break; 304 1.29 perseant } 305 1.29 perseant 306 1.29 perseant /* Skip superblock if necessary */ 307 1.29 perseant for (i = 0; i < LFS_MAXNUMSB; i++) 308 1.48 dholland if (lfs_sb_getoffset(fs) == lfs_sb_getsboff(fs, i)) 309 1.47 dholland lfs_sb_addoffset(fs, lfs_btofsb(fs, LFS_SBPAD)); 310 1.29 perseant 311 1.29 perseant ++fs->lfs_nactive; 312 1.47 dholland lfs_sb_setnextseg(fs, lfs_sntod(fs, sn)); 313 1.29 perseant if (debug) { 314 1.51 dholland pwarn("offset = 0x%" PRIx64 ", serial = %" PRIu64 "\n", 315 1.47 dholland lfs_sb_getoffset(fs), lfs_sb_getserial(fs)); 316 1.51 dholland pwarn("curseg = %" PRIx64 ", nextseg = %" PRIx64 "\n", 317 1.47 dholland lfs_sb_getcurseg(fs), lfs_sb_getnextseg(fs)); 318 1.29 perseant } 319 1.29 perseant 320 1.29 perseant if (!nflag && !skipclean) { 321 1.47 dholland lfs_sb_setidaddr(fs, idaddr); 322 1.29 perseant fsmodified = 1; 323 1.29 perseant sbdirty(); 324 1.29 perseant } 325 1.29 perseant } 326 1.29 perseant 327 1.5 perseant if (debug) { 328 1.47 dholland pwarn("idaddr = 0x%jx\n", idaddr ? (uintmax_t)idaddr : 329 1.47 dholland (uintmax_t)lfs_sb_getidaddr(fs)); 330 1.29 perseant pwarn("dev_bsize = %lu\n", dev_bsize); 331 1.47 dholland pwarn("lfs_bsize = %lu\n", (unsigned long) lfs_sb_getbsize(fs)); 332 1.47 dholland pwarn("lfs_fsize = %lu\n", (unsigned long) lfs_sb_getfsize(fs)); 333 1.47 dholland pwarn("lfs_frag = %lu\n", (unsigned long) lfs_sb_getfrag(fs)); 334 1.48 dholland pwarn("lfs_inopb = %lu\n", (unsigned long) lfs_sb_getinopb(fs)); 335 1.13 perseant } 336 1.52 dholland if (lfs_sb_getversion(fs) == 1) 337 1.50 dholland maxfsblock = lfs_blkstofrags(fs, lfs_sb_getsize(fs)); 338 1.13 perseant else 339 1.47 dholland maxfsblock = lfs_sb_getsize(fs); 340 1.48 dholland maxfilesize = calcmaxfilesize(lfs_sb_getbshift(fs)); 341 1.47 dholland if (/* lfs_sb_getminfree(fs) < 0 || */ lfs_sb_getminfree(fs) > 99) { 342 1.47 dholland pfatal("IMPOSSIBLE MINFREE=%u IN SUPERBLOCK", 343 1.47 dholland lfs_sb_getminfree(fs)); 344 1.1 perseant if (reply("SET TO DEFAULT") == 1) { 345 1.47 dholland lfs_sb_setminfree(fs, 10); 346 1.1 perseant sbdirty(); 347 1.1 perseant } 348 1.1 perseant } 349 1.48 dholland if (lfs_sb_getbmask(fs) != lfs_sb_getbsize(fs) - 1) { 350 1.48 dholland pwarn("INCORRECT BMASK=0x%jx IN SUPERBLOCK (SHOULD BE 0x%x)", 351 1.48 dholland (uintmax_t)lfs_sb_getbmask(fs), 352 1.48 dholland lfs_sb_getbsize(fs) - 1); 353 1.48 dholland lfs_sb_setbmask(fs, lfs_sb_getbsize(fs) - 1); 354 1.1 perseant if (preen) 355 1.1 perseant printf(" (FIXED)\n"); 356 1.1 perseant if (preen || reply("FIX") == 1) { 357 1.1 perseant sbdirty(); 358 1.1 perseant } 359 1.1 perseant } 360 1.48 dholland if (lfs_sb_getffmask(fs) != lfs_sb_getfsize(fs) - 1) { 361 1.48 dholland pwarn("INCORRECT FFMASK=0x%jx IN SUPERBLOCK (SHOULD BE 0x%x)", 362 1.48 dholland (uintmax_t)lfs_sb_getffmask(fs), 363 1.48 dholland lfs_sb_getfsize(fs) - 1); 364 1.48 dholland lfs_sb_setffmask(fs, lfs_sb_getfsize(fs) - 1); 365 1.1 perseant if (preen) 366 1.1 perseant printf(" (FIXED)\n"); 367 1.1 perseant if (preen || reply("FIX") == 1) { 368 1.1 perseant sbdirty(); 369 1.1 perseant } 370 1.1 perseant } 371 1.48 dholland if (lfs_sb_getfbmask(fs) != (1U << lfs_sb_getfbshift(fs)) - 1) { 372 1.48 dholland pwarn("INCORRECT FBMASK=0x%jx IN SUPERBLOCK (SHOULD BE 0x%x)", 373 1.48 dholland (uintmax_t)lfs_sb_getfbmask(fs), 374 1.48 dholland (1U << lfs_sb_getfbshift(fs)) - 1); 375 1.48 dholland lfs_sb_setfbmask(fs, (1U << lfs_sb_getfbshift(fs)) - 1); 376 1.13 perseant if (preen) 377 1.13 perseant printf(" (FIXED)\n"); 378 1.13 perseant if (preen || reply("FIX") == 1) { 379 1.13 perseant sbdirty(); 380 1.13 perseant } 381 1.13 perseant } 382 1.48 dholland if (lfs_sb_getmaxfilesize(fs) != maxfilesize) { 383 1.8 lukem pwarn( 384 1.51 dholland "INCORRECT MAXFILESIZE=%ju IN SUPERBLOCK (SHOULD BE %ju WITH BSHIFT %u)", 385 1.51 dholland (uintmax_t) lfs_sb_getmaxfilesize(fs), 386 1.51 dholland (uintmax_t) maxfilesize, lfs_sb_getbshift(fs)); 387 1.5 perseant if (preen) 388 1.5 perseant printf(" (FIXED)\n"); 389 1.5 perseant if (preen || reply("FIX") == 1) { 390 1.48 dholland lfs_sb_setmaxfilesize(fs, maxfilesize); 391 1.5 perseant sbdirty(); 392 1.1 perseant } 393 1.5 perseant } 394 1.58 dholland if (lfs_sb_getmaxsymlinklen(fs) != LFS_MAXSYMLINKLEN(fs)) { 395 1.48 dholland pwarn("INCORRECT MAXSYMLINKLEN=%d IN SUPERBLOCK (SHOULD BE %zu)", 396 1.58 dholland lfs_sb_getmaxsymlinklen(fs), LFS_MAXSYMLINKLEN(fs)); 397 1.58 dholland lfs_sb_setmaxsymlinklen(fs, LFS_MAXSYMLINKLEN(fs)); 398 1.5 perseant if (preen) 399 1.5 perseant printf(" (FIXED)\n"); 400 1.5 perseant if (preen || reply("FIX") == 1) { 401 1.5 perseant sbdirty(); 402 1.1 perseant } 403 1.5 perseant } 404 1.13 perseant 405 1.13 perseant /* 406 1.13 perseant * Read in the Ifile; we'll be using it a lot. 407 1.13 perseant * XXX If the Ifile is corrupted we are in bad shape. We need to 408 1.13 perseant * XXX run through the segment headers of the entire disk to 409 1.13 perseant * XXX reconstruct the inode table, then pretend all segments are 410 1.13 perseant * XXX dirty while we do the rest. 411 1.13 perseant */ 412 1.13 perseant ivp = fs->lfs_ivnode; 413 1.56 dholland maxino = ((lfs_dino_getsize(fs, VTOI(ivp)->i_din) - (lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs)) 414 1.47 dholland * lfs_sb_getbsize(fs)) / lfs_sb_getbsize(fs)) * lfs_sb_getifpb(fs); 415 1.13 perseant if (debug) 416 1.29 perseant pwarn("maxino = %llu\n", (unsigned long long)maxino); 417 1.56 dholland for (i = 0; i < lfs_dino_getsize(fs, VTOI(ivp)->i_din); i += lfs_sb_getbsize(fs)) { 418 1.48 dholland bread(ivp, i >> lfs_sb_getbshift(fs), lfs_sb_getbsize(fs), 0, &bp); 419 1.13 perseant /* XXX check B_ERROR */ 420 1.33 ad brelse(bp, 0); 421 1.13 perseant } 422 1.13 perseant 423 1.1 perseant /* 424 1.1 perseant * allocate and initialize the necessary maps 425 1.1 perseant */ 426 1.32 christos din_table = ecalloc(maxino, sizeof(*din_table)); 427 1.48 dholland seg_table = ecalloc(lfs_sb_getnseg(fs), sizeof(SEGUSE)); 428 1.13 perseant /* Get segment flags */ 429 1.48 dholland for (i = 0; i < lfs_sb_getnseg(fs); i++) { 430 1.13 perseant LFS_SEGENTRY(sup, fs, i, bp); 431 1.13 perseant seg_table[i].su_flags = sup->su_flags & ~SEGUSE_ACTIVE; 432 1.14 perseant if (preen) 433 1.14 perseant seg_table[i].su_nbytes = sup->su_nbytes; 434 1.33 ad brelse(bp, 0); 435 1.13 perseant } 436 1.13 perseant 437 1.13 perseant /* Initialize Ifile entry */ 438 1.57 dholland din_table[LFS_IFILE_INUM] = lfs_sb_getidaddr(fs); 439 1.55 dholland seg_table[lfs_dtosn(fs, lfs_sb_getidaddr(fs))].su_nbytes += DINOSIZE(fs); 440 1.13 perseant 441 1.1 perseant #ifndef VERBOSE_BLOCKMAP 442 1.1 perseant bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t)); 443 1.32 christos blockmap = ecalloc(bmapsize, sizeof(char)); 444 1.1 perseant #else 445 1.32 christos blockmap = ecalloc(maxfsblock, sizeof(ino_t)); 446 1.1 perseant #endif 447 1.32 christos statemap = ecalloc(maxino, sizeof(char)); 448 1.32 christos typemap = ecalloc(maxino, sizeof(char)); 449 1.32 christos lncntp = ecalloc(maxino, sizeof(int16_t)); 450 1.14 perseant 451 1.14 perseant if (preen) { 452 1.47 dholland n_files = lfs_sb_getnfiles(fs); 453 1.47 dholland n_blks = lfs_sb_getdsize(fs) - lfs_sb_getbfree(fs); 454 1.14 perseant numdirs = maxino; 455 1.14 perseant inplast = 0; 456 1.14 perseant listmax = numdirs + 10; 457 1.32 christos inpsort = ecalloc(listmax, sizeof(struct inoinfo *)); 458 1.32 christos inphead = ecalloc(numdirs, sizeof(struct inoinfo *)); 459 1.14 perseant } 460 1.14 perseant 461 1.1 perseant return (1); 462 1.1 perseant 463 1.1 perseant ckfini(0); 464 1.1 perseant return (0); 465 1.1 perseant } 466 1.1 perseant 467