2 * Copyright (c) 1980, 1986 The Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 #include <afsconfig.h>
19 #include <afs/param.h>
26 #if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV)
33 #define msgprintf vfscklogprintf
34 extern vfscklogprintf();
38 #include <sys/param.h>
42 #include <sys/vnode.h>
43 #include <sys/mount.h>
44 #include <ufs/inode.h>
52 #else /* AFS_OSF_ENV */
53 #ifdef AFS_VFSINCL_ENV
54 #include <sys/vnode.h>
58 #include <sys/fs/ufs_inode.h>
59 #include <sys/fs/ufs_fs.h>
61 #include <sys/fs/ufs_fsdir.h>
63 #include <sys/fs/ufs_mount.h>
65 #include <ufs/inode.h>
68 #else /* AFS_VFSINCL_ENV */
69 #include <sys/inode.h>
72 #define LONGFILENAMES 1
73 #include <sys/sysmacros.h>
77 #endif /* AFS_VFSINCL_ENV */
78 #endif /* AFS_OSF_ENV */
81 #include <sys/ioctl.h>
85 #include <sys/mntent.h>
86 #include <sys/vfstab.h>
89 #include <afs/osi_inode.h>
95 #define altsblock (*asblk.b_un.b_fs)
96 #define POWEROF2(num) (((num) & ((num) - 1)) == 0)
99 * The size of a cylinder group is calculated by CGSIZE. The maximum size
100 * is limited by the fact that cylinder groups are at most one block.
101 * Its size is derived from the size of the maps maintained in the
102 * cylinder group and the (struct cg) size.
105 /* base cg */ (sizeof(struct cg) + \
106 /* blktot size */ (fs)->fs_cpg * sizeof(afs_int32) + \
107 /* blks size */ (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(short) + \
108 /* inode map */ howmany((fs)->fs_ipg, NBBY) + \
109 /* block map */ howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY))
111 char *malloc(), *calloc();
112 struct disklabel *getdisklabel();
118 long cg, size, asked, i, j;
120 struct disklabel *lp;
123 #if defined(AFS_SUN5_ENV)
124 static char sname[MAXPATHLEN];
127 /* reset static variables that may have been damaged by parent fork */
131 #if defined(ACLS) && defined(AFS_HPUX_ENV)
135 if (stat("/", &statb) < 0)
136 errexit("Can't stat root\n");
137 rootdev = statb.st_dev;
138 #if defined(AFS_SUN5_ENV)
139 strncpy(sname, dev, sizeof(sname));
141 if (stat(sname, &statb) < 0) {
143 msgprintf("Can't stat %s\n", sname);
145 if (stat(dev, &statb) < 0) {
147 printf("Can't stat %s\n", dev);
152 if ((statb.st_mode & S_IFMT) == S_IFDIR) {
156 if ((fp = fopen(VFSTAB, "r")) == NULL) {
157 pfatal("Can't open %s file\n", VFSTAB);
160 while (!getvfsent(fp, &vtab)) {
161 if (vtab.vfs_mountp && !strcmp(vtab.vfs_mountp, sname)) {
162 strcpy(sname, vtab.vfs_special);
164 char *s = vtab.vfs_fsckdev;
173 if ((statb.st_mode & S_IFMT) != S_IFBLK
174 && (statb.st_mode & S_IFMT) != S_IFCHR) {
175 pfatal("device is not a block or character device");
176 if (reply("file is not a block or character device; OK") == 0)
184 printf("%s is mounted, fsck on BLOCK device ignored\n", sname);
188 char bname[MAXPATHLEN], *tname;
190 strcpy(bname, sname);
191 tname = unrawname(bname);
192 if (stat(tname, &statb) < 0) {
193 pfatal("Can't stat %s\n", tname);
199 hotroot = is_hotroot(dev);
202 * The following code is added to improve usability of fsck.
203 * we need to give user a warning if the device being checked is
204 * a hotroot, a mounted file system, or a swap device.
206 * 1) if nflag is set, it's pretty safe to fsck the target dev
207 * 2) if the target device is a swap, exit
208 * 3) if hotroot is set, and "-F" is not specified prompt the
209 * user and wait for reply
210 * 4) if the target is a mounted file system, and "-F" is not
211 * specified, prompt the user and wait for reply
212 * 5) if the "-m" is specifed, do no prompting since only a sanity
213 * check is being done. important during booting
215 * Caveat: There is no way to tell the current run level, so we cannot
216 * tell whether or not we are in single user mode.
220 struct stat st_mounted;
224 mounted = is_mounted(dev, &st_mounted);
226 swap = is_swap(st_mounted.st_rdev);
235 msgprintf("fsck: %s: root file system", dev);
237 msgprintf(" (CONTINUING)\n");
239 if (!freply("continue (y/n)"))
242 } else if (mounted) {
243 msgprintf("fsck: %s: mounted file system", dev);
245 msgprintf(" (CONTINUING)\n");
247 if (!freply("continue (y/n)"))
251 msgprintf("fsck: %s: swap device\n", dev);
253 msgprintf(" (CONTINUING)\n");
255 if (!freply("continue (y/n)"))
261 if (rootdev == statb.st_rdev)
263 if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
265 msgprintf("Can't open %s\n", dev);
269 msgprintf("** %s", dev);
270 if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
272 msgprintf(" (NO WRITE)");
275 pfatal("NO WRITE ACCESS");
281 #if defined(AFS_HPUX101_ENV)
282 setup_all_block_seek();
286 printf(" pid %d\n", getpid());
287 if (debug && (hotroot || mountedfs)) {
288 printf("** %s", sname);
290 printf(" is root fs");
295 printf(" is mounted");
304 sblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
305 asblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
307 sblk.b_un.b_buf = malloc(SBSIZE);
308 asblk.b_un.b_buf = malloc(SBSIZE);
310 if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
311 errexit("cannot allocate space for superblock\n");
312 dev_bsize = secsize = DEV_BSIZE;
315 * Read in the superblock, looking for alternates if necessary
317 if (readsb(1) == 0) {
318 if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
320 if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
322 for (cg = 0; cg < proto.fs_ncg; cg++) {
323 bflag = fsbtodb(&proto, cgsblock(&proto, cg));
327 if (cg >= proto.fs_ncg) {
328 msgprintf("%s %s\n%s %s\n%s %s\n",
329 "SEARCH FOR ALTERNATE SUPER-BLOCK",
330 "FAILED. YOU MUST USE THE",
331 "-b OPTION TO FSCK TO SPECIFY THE",
332 "LOCATION OF AN ALTERNATE",
333 "SUPER-BLOCK TO SUPPLY NEEDED",
334 "INFORMATION; SEE fsck(8).");
337 pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
339 maxfsblock = sblock.fs_size;
340 maxino = sblock.fs_ncg * sblock.fs_ipg;
342 * Check and potentially fix certain fields in the super block.
344 if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) {
345 pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
346 if (reply("SET TO DEFAULT") == 1) {
347 sblock.fs_optim = FS_OPTTIME;
351 if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) {
352 pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", sblock.fs_minfree);
353 if (reply("SET TO DEFAULT") == 1) {
354 sblock.fs_minfree = 10;
360 * Do we need to continue ?
362 if (pclean && sblock.fs_clean == FS_CLEAN)
364 if (pclean && hotroot && sblock.fs_clean == FS_OK)
368 # ifndef AFS_SUN59_ENV
369 if (sblock.fs_interleave < 1) {
370 pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK", sblock.fs_interleave);
371 sblock.fs_interleave = 1;
373 msgprintf(" (FIXED)\n");
374 if (preen || reply("SET TO DEFAULT") == 1) {
379 # endif /* AFS_SUN59_ENV */
380 #endif /* AFS_NEWCG_ENV */
382 if (sblock.fs_npsect < sblock.fs_nsect) {
383 pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK", sblock.fs_npsect);
384 sblock.fs_npsect = sblock.fs_nsect;
386 msgprintf(" (FIXED)\n");
387 if (preen || reply("SET TO DEFAULT") == 1) {
392 #endif /* AFS_NEWCG_ENV */
395 if (sblock.fs_postblformat == FS_42POSTBLFMT) {
397 * Requested to convert from old format to new format
400 pwarn("CONVERTING TO NEW FILE SYSTEM FORMAT\n");
401 else if (!reply("CONVERT TO NEW FILE SYSTEM FORMAT"))
404 sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
406 sblock.fs_postbloff =
407 (char *)(&sblock.fs_opostbl[0][0]) -
408 (char *)(&sblock.fs_link);
410 &sblock.fs_space[0] - (u_char *) (&sblock.fs_link);
411 sblock.fs_cgsize = fragroundup(&sblock, CGSIZE(&sblock));
413 * Planning now for future expansion.
415 # if (BYTE_ORDER == BIG_ENDIAN)
416 sblock.fs_qbmask.val[0] = 0;
417 sblock.fs_qbmask.val[1] = ~sblock.fs_bmask;
418 sblock.fs_qfmask.val[0] = 0;
419 sblock.fs_qfmask.val[1] = ~sblock.fs_fmask;
420 # endif /* BIG_ENDIAN */
421 # if (BYTE_ORDER == LITTLE_ENDIAN)
422 sblock.fs_qbmask.val[0] = ~sblock.fs_bmask;
423 sblock.fs_qbmask.val[1] = 0;
424 sblock.fs_qfmask.val[0] = ~sblock.fs_fmask;
425 sblock.fs_qfmask.val[1] = 0;
426 # endif /* LITTLE_ENDIAN */
427 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
429 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
431 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
433 sblock.fs_clean = FSCLEAN;
437 } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) {
439 * Requested to convert from new format to old format
441 if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048
442 || sblock.fs_cpg > 32 || sblock.fs_cpc > 16) {
443 msgprintf("PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
444 msgprintf("ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n");
449 pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n");
450 else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT"))
453 sblock.fs_postblformat = FS_42POSTBLFMT;
456 sizeof(struct ocg) + howmany(sblock.fs_fpg,
458 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
460 sblock.fs_npsect = 0;
461 # ifndef AFS_SUN59_ENV
462 sblock.fs_interleave = 0;
464 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
466 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
468 sblock.fs_clean = FSCLEAN;
473 errexit("UNKNOWN FILE SYSTEM FORMAT\n");
476 #endif /* AFS_NEWCG_ENV */
478 memcpy((char *)&altsblock, (char *)&sblock, (int)sblock.fs_sbsize);
479 flush(fswritefd, &asblk);
482 * read in the summary info.
485 #if defined(AFS_SUN56_ENV)
488 sip = calloc(1, sblock.fs_cssize);
489 sblock.fs_u.fs_csp = (struct csum *)sip;
490 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
492 sblock.fs_cssize - i <
493 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
496 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
497 size) != 0 && !asked) {
498 pfatal("BAD SUMMARY INFORMATION");
499 if (reply("CONTINUE") == 0)
506 #else /* AFS_SUN56_ENV */
507 #if defined(AFS_HPUX110_ENV)
508 size = fragroundup(&sblock, sblock.fs_cssize);
509 sblock.fs_csp = (struct csum *)calloc(1, (unsigned)size);
511 (fsreadfd, (char *)sblock.fs_csp, fsbtodb(&sblock, sblock.fs_csaddr),
512 size) != 0) && !asked) {
513 pfatal("BAD SUMMARY INFORMATION");
514 if (reply("CONTINUE") == 0)
518 #else /* AFS_HPUX110_ENV */
519 #if defined(AFS_HPUX101_ENV)
522 size = fragroundup(&sblock, sblock.fs_cssize);
524 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
526 sblock.fs_cssize - i <
527 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
528 #endif /* AFS_HPUX101_ENV */
529 sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
531 (fsreadfd, (char *)sblock.fs_csp[j],
532 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
533 size) != 0 && !asked) {
534 pfatal("BAD SUMMARY INFORMATION");
535 if (reply("CONTINUE") == 0)
544 #endif /* else AFS_HPUX110_ENV */
545 #endif /* else AFS_SUN56_ENV */
547 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
549 * if not forced, preening, not converting, and is clean; stop checking
552 if ((fflag == 0) && preen && (isconvert == 0)
553 && (FSOKAY == (sblock.fs_state + sblock.fs_time)) &&
555 if (preen && (isconvert == 0)
556 && (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)) &&
558 ((sblock.fs_clean == FSCLEAN) || (sblock.fs_clean == FSSTABLE))) {
565 if (!fflag && !bflag && !nflag && !hotroot && sblock.fs_clean == FS_CLEAN
567 pwarn("Clean file system - skipping fsck\n");
570 #endif /* AFS_OSF_ENV */
573 * allocate and initialize the necessary maps
575 bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
576 blockmap = calloc((unsigned)bmapsize, sizeof(char));
577 if (blockmap == NULL) {
578 msgprintf("cannot alloc %d bytes for blockmap\n", bmapsize);
581 statemap = calloc((unsigned)(maxino + 1), sizeof(char));
582 if (statemap == NULL) {
583 msgprintf("cannot alloc %d bytes for statemap\n", maxino + 1);
586 lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
587 if (lncntp == NULL) {
588 msgprintf("cannot alloc %d bytes for lncntp\n",
589 (maxino + 1) * sizeof(short));
602 * Read in the super block and its summary info.
608 daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
609 #else /* AFS_NEWCG_ENV */
610 daddr_t super = bflag ? bflag : SBLOCK;
612 #endif /* AFS_NEWCG_ENV */
613 if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
616 sblk.b_size = SBSIZE;
618 * run a few consistency checks of the super block
621 #if defined(FD_FSMAGIC)
622 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN)
623 && (sblock.fs_magic != FD_FSMAGIC)
624 #if defined(AFS_HPUX101_ENV)
625 && (sblock.fs_magic != FD_FSMAGIC_2)
628 #else /* not new magic number */
629 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN))
630 #endif /* new magic number */
632 if (sblock.fs_magic != FS_MAGIC)
635 badsb(listerr, "MAGIC NUMBER WRONG");
638 if (sblock.fs_ncg < 1) {
639 badsb(listerr, "NCG OUT OF RANGE");
642 if (sblock.fs_cpg < 1) {
643 printf("fs_cpg= %d\n", sblock.fs_cpg);
644 badsb(listerr, "CPG OUT OF RANGE");
647 if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl
648 || (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) {
649 badsb(listerr, "NCYL LESS THAN NCG*CPG");
652 if (sblock.fs_sbsize > SBSIZE) {
653 badsb(listerr, "SIZE PREPOSTEROUSLY LARGE");
657 * Compute block size that the filesystem is based on,
658 * according to fsbtodb, and adjust superblock block number
659 * so we can tell if this is an alternate later.
662 dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
663 sblk.b_bno = super / dev_bsize;
665 * Set all possible fields that could differ, then do check
666 * of whole super block against an alternate super block.
667 * When an alternate super-block is specified this check is skipped.
669 getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
676 altsblock.fs_link = sblock.fs_link;
677 #ifdef STRUCT_FS_HAS_FS_ROLLED
678 altsblock.fs_rolled = sblock.fs_rolled;
680 altsblock.fs_rlink = sblock.fs_rlink;
682 altsblock.fs_time = sblock.fs_time;
683 altsblock.fs_cstotal = sblock.fs_cstotal;
684 altsblock.fs_cgrotor = sblock.fs_cgrotor;
685 altsblock.fs_fmod = sblock.fs_fmod;
687 altsblock.fs_clean = sblock.fs_clean;
688 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
690 altsblock.fs_state = sblock.fs_state;
692 fs_set_state(&altsblock, fs_get_state(&sblock));
695 altsblock.fs_ronly = sblock.fs_ronly;
696 altsblock.fs_flags = sblock.fs_flags;
697 altsblock.fs_maxcontig = sblock.fs_maxcontig;
698 altsblock.fs_minfree = sblock.fs_minfree;
699 altsblock.fs_optim = sblock.fs_optim;
700 altsblock.fs_rotdelay = sblock.fs_rotdelay;
701 altsblock.fs_maxbpg = sblock.fs_maxbpg;
702 #if !defined(__alpha) && !defined(AFS_SUN56_ENV)
703 #if !defined(AFS_HPUX110_ENV)
704 /* HPUX110 will use UpdateAlternateSuper() below */
705 memcpy((char *)altsblock.fs_csp, (char *)sblock.fs_csp,
706 sizeof sblock.fs_csp);
707 #endif /* ! AFS_HPUX110_ENV */
708 #endif /* ! __alpha */
709 #if defined(AFS_SUN56_ENV)
710 memcpy((char *)altsblock.fs_u.fs_csp_pad, (char *)sblock.fs_u.fs_csp_pad,
711 sizeof(sblock.fs_u.fs_csp_pad));
713 memcpy((char *)altsblock.fs_fsmnt, (char *)sblock.fs_fsmnt,
714 sizeof sblock.fs_fsmnt);
716 memcpy((char *)altsblock.fs_sparecon, (char *)sblock.fs_sparecon,
717 sizeof sblock.fs_sparecon);
720 * The following should not have to be copied.
722 altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
724 # if defined(AFS_SUN59_ENV) && defined(FS_SI_OK)
725 /* fs_interleave replaced with fs_si and FS_SI_OK defined in */
726 /* ufs_fs.h version 2.63 don't need to compare either */
727 altsblock.fs_si = sblock.fs_si;
729 altsblock.fs_interleave = sblock.fs_interleave;
731 altsblock.fs_npsect = sblock.fs_npsect;
732 altsblock.fs_nrpos = sblock.fs_nrpos;
733 #endif /* AFS_NEWCG_ENV */
734 #if defined(AFS_HPUX110_ENV)
735 UpdateAlternateSuper(&sblock, &altsblock);
736 #endif /* AFS_HPUX110_ENV */
737 if (memcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
740 ((char *)&sblock.fs_blank[0], (char *)&altsblock.fs_blank[0],
741 MAXCSBUFS * sizeof(int))) {
742 memset(sblock.fs_blank, 0, sizeof(sblock.fs_blank));
746 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
764 msgprintf("%s: ", devname);
765 pfatal("BAD SUPER BLOCK: %s\n", s);
767 pwarn("USE AN ALTERNATE SUPER-BLOCK TO SUPPLY NEEDED INFORMATION;\n");
768 pwarn("eg. fsck [-F ufs] -o b=# [special ...] \n");
769 pfatal("where # is the alternate super block. SEE fsck_ufs(1M). \n");
773 /* dummy function that fails if ever called */
774 calcsb(dev, devfd, fs)
782 #include <sys/ustat.h>
784 #include <sys/pstat.h>
786 #include <sys/errno.h>
790 is_mounted(device, dev_st)
794 char blockdev[BUFSIZ];
798 strcpy(blockdev, device);
799 if (stat(blockdev, dev_st) < 0)
802 if (is_pre_init(dev_st->st_rdev))
805 if ((dev_st->st_mode & S_IFMT) == S_IFCHR) {
806 dp = strrchr(blockdev, '/');
807 if (strncmp(dp, "/r", 2) != 0)
808 while (dp >= blockdev && *--dp != '/');
809 if (*(dp + 1) == 'r')
810 (void)strcpy(dp + 1, dp + 2);
811 if (stat(blockdev, dev_st) < 0)
814 if (ustat(dev_st->st_rdev, &ust) >= 0) {
815 /* make sure we are not in pre_init_rc. If we are 0 should be returned in here. */
816 if ((is_root(dev_st->st_rdev)) && is_roroot())
826 #ifdef AFS_HPUX102_ENV
827 #define PSTAT(P, N, I) pstat_getswap(P, sizeof(*P), (size_t)N, I)
829 #define PSTAT(P, N, I) pstat(PSTAT_SWAPINFO, P, sizeof(*P), (size_t)N, I)
834 struct pst_swapinfo pst[PS_BURST];
835 struct pst_swapinfo *psp = &pst[0];
836 int idx = 0, count, match = 0;
838 while ((count = PSTAT(psp, PS_BURST, idx) != 0)) {
839 idx = pst[count - 1].pss_idx + 1;
840 if ((psp->pss_flags & SW_BLOCK) && (psp->pss_major == major(devno))
841 && (psp->pss_minor == minor(devno))) {
849 #endif /* AFS_HPUX_ENV */
862 #ifndef UID_NO_CHANGE
865 if (stat("/", &stslash) < 0)
867 if (chown("/", stslash.st_uid, stslash.st_gid) == 0)
870 if (chown("/", UID_NO_CHANGE, GID_NO_CHANGE) == 0)
873 else if (errno != EROFS) {
874 printf("fsck: chown failed: %d\n", errno);
880 is_hotroot(fs_device)
883 struct stat stslash, stblock, stchar;
884 char blockdev[BUFSIZ];
886 strcpy(blockdev, fs_device);
887 if (stat("/", &stslash) < 0) {
888 pfatal("Can't stat root\n");
892 if (stat(blockdev, &stblock) < 0) {
893 pfatal("Can't stat %s\n", blockdev);
897 if (is_pre_init(stblock.st_rdev))
900 /* convert the device name to be block device name */
901 if ((stblock.st_mode & S_IFMT) == S_IFCHR) {
903 if (stat(blockdev, &stblock) < 0)
906 if ((stblock.st_mode & S_IFMT) != S_IFBLK)
908 if (stslash.st_dev != stblock.st_rdev)
910 /* is root file system mounted read only? */
921 if (stat("/", &stslash) < 0)
923 if (stslash.st_dev != rdev_num)
928 getline(fp, loc, maxlen)
936 lastloc = &p[maxlen - 1];
937 while ((n = getc(fp)) != '\n') {
940 if (!isspace(n) && p < lastloc)
948 * freply - prints the string, s, gets a reply fromterminal and returns
949 * 0 - no (don't continue), and 1 - yes (continue)
957 errexit("exiting\n");
959 if (getline(stdin, line, sizeof(line)) == EOF)
961 if (line[0] == 'y' || line[0] == 'Y')
967 #if defined(AFS_HPUX110_ENV)
969 * Refer to function compare_sblocks() in HP's fsck.c
972 * This routine will compare the primary superblock (PRIM_SBLOCK) to the
973 * alternate superblock (ALT_SBLOCK). This routine will take into account
974 * that certain fields in the alternate superblock could be different than
975 * in the primary superblock. This routine checks the "static" fields
976 * and ignores the "dynamic" fields. Superblocks with the same "static"
977 * fields are considered equivalent.
980 UpdateAlternateSuper(prim_sblock, alt_sblock)
981 struct fs *prim_sblock;
982 struct fs *alt_sblock; /* will be modified */
985 * Set all possible fields that could differ, then do check
986 * of whole super block against an alternate super block.
988 * Copy dynamic fields of prim_sblock into alt_sblock
990 alt_sblock->fs_time = prim_sblock->fs_time;
991 alt_sblock->fs_minfree = prim_sblock->fs_minfree;
992 alt_sblock->fs_rotdelay = prim_sblock->fs_rotdelay;
993 alt_sblock->fs_maxcontig = prim_sblock->fs_maxcontig;
994 alt_sblock->fs_maxbpg = prim_sblock->fs_maxbpg;
995 alt_sblock->fs_mirror = prim_sblock->fs_mirror;
996 alt_sblock->fs_cstotal = prim_sblock->fs_cstotal;
997 alt_sblock->fs_fmod = prim_sblock->fs_fmod;
998 alt_sblock->fs_clean = prim_sblock->fs_clean;
999 alt_sblock->fs_ronly = prim_sblock->fs_ronly;
1000 alt_sblock->fs_flags = prim_sblock->fs_flags;
1001 alt_sblock->fs_cgrotor = prim_sblock->fs_cgrotor;
1003 alt_sblock->fs_csp = prim_sblock->fs_csp;
1004 #else /* not __LP64__ */
1005 alt_sblock->fs_csp = prim_sblock->fs_csp;
1006 alt_sblock->fs_csp_pad = prim_sblock->fs_csp_pad;
1007 #endif /* not __LP64__ */
1008 memcpy((char *)alt_sblock->fs_fsmnt, (char *)prim_sblock->fs_fsmnt,
1009 sizeof prim_sblock->fs_fsmnt);
1010 memcpy((char *)alt_sblock->fs_fname, (char *)prim_sblock->fs_fname,
1011 sizeof prim_sblock->fs_fname);
1012 memcpy((char *)alt_sblock->fs_fpack, (char *)prim_sblock->fs_fpack,
1013 sizeof prim_sblock->fs_fpack);
1014 if (prim_sblock->fs_featurebits & FSF_LARGEUIDS)
1015 alt_sblock->fs_featurebits |= FSF_LARGEUIDS;
1017 alt_sblock->fs_featurebits &= ~FSF_LARGEUIDS;
1019 #endif /* AFS_HPUX110_ENV */