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>
28 #if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV)
35 #define msgprintf vfscklogprintf
36 extern vfscklogprintf();
40 #include <sys/param.h>
44 #include <sys/vnode.h>
45 #include <sys/mount.h>
46 #include <ufs/inode.h>
54 #else /* AFS_OSF_ENV */
55 #ifdef AFS_VFSINCL_ENV
56 #include <sys/vnode.h>
60 #include <sys/fs/ufs_inode.h>
61 #include <sys/fs/ufs_fs.h>
63 #include <sys/fs/ufs_fsdir.h>
65 #include <sys/fs/ufs_mount.h>
67 #include <ufs/inode.h>
70 #else /* AFS_VFSINCL_ENV */
71 #include <sys/inode.h>
74 #define LONGFILENAMES 1
75 #include <sys/sysmacros.h>
79 #endif /* AFS_VFSINCL_ENV */
80 #endif /* AFS_OSF_ENV */
83 #include <sys/ioctl.h>
87 #include <sys/mntent.h>
88 #include <sys/vfstab.h>
91 #include <afs/osi_inode.h>
97 #define altsblock (*asblk.b_un.b_fs)
98 #define POWEROF2(num) (((num) & ((num) - 1)) == 0)
101 * The size of a cylinder group is calculated by CGSIZE. The maximum size
102 * is limited by the fact that cylinder groups are at most one block.
103 * Its size is derived from the size of the maps maintained in the
104 * cylinder group and the (struct cg) size.
107 /* base cg */ (sizeof(struct cg) + \
108 /* blktot size */ (fs)->fs_cpg * sizeof(afs_int32) + \
109 /* blks size */ (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(short) + \
110 /* inode map */ howmany((fs)->fs_ipg, NBBY) + \
111 /* block map */ howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY))
113 char *malloc(), *calloc();
114 struct disklabel *getdisklabel();
120 long cg, size, asked, i, j;
122 struct disklabel *lp;
125 #if defined(AFS_SUN5_ENV)
126 static char sname[MAXPATHLEN];
129 /* reset static variables that may have been damaged by parent fork */
133 #if defined(ACLS) && defined(AFS_HPUX_ENV)
137 if (stat("/", &statb) < 0)
138 errexit("Can't stat root\n");
139 rootdev = statb.st_dev;
140 #if defined(AFS_SUN5_ENV)
141 strncpy(sname, dev, sizeof(sname));
143 if (stat(sname, &statb) < 0) {
145 msgprintf("Can't stat %s\n", sname);
147 if (stat(dev, &statb) < 0) {
149 printf("Can't stat %s\n", dev);
154 if ((statb.st_mode & S_IFMT) == S_IFDIR) {
158 if ((fp = fopen(VFSTAB, "r")) == NULL) {
159 pfatal("Can't open %s file\n", VFSTAB);
162 while (!getvfsent(fp, &vtab)) {
163 if (vtab.vfs_mountp && !strcmp(vtab.vfs_mountp, sname)) {
164 strcpy(sname, vtab.vfs_special);
166 char *s = vtab.vfs_fsckdev;
175 if ((statb.st_mode & S_IFMT) != S_IFBLK
176 && (statb.st_mode & S_IFMT) != S_IFCHR) {
177 pfatal("device is not a block or character device");
178 if (reply("file is not a block or character device; OK") == 0)
186 printf("%s is mounted, fsck on BLOCK device ignored\n", sname);
190 char bname[MAXPATHLEN], *tname;
192 strcpy(bname, sname);
193 tname = unrawname(bname);
194 if (stat(tname, &statb) < 0) {
195 pfatal("Can't stat %s\n", tname);
201 hotroot = is_hotroot(dev);
204 * The following code is added to improve usability of fsck.
205 * we need to give user a warning if the device being checked is
206 * a hotroot, a mounted file system, or a swap device.
208 * 1) if nflag is set, it's pretty safe to fsck the target dev
209 * 2) if the target device is a swap, exit
210 * 3) if hotroot is set, and "-F" is not specified prompt the
211 * user and wait for reply
212 * 4) if the target is a mounted file system, and "-F" is not
213 * specified, prompt the user and wait for reply
214 * 5) if the "-m" is specifed, do no prompting since only a sanity
215 * check is being done. important during booting
217 * Caveat: There is no way to tell the current run level, so we cannot
218 * tell whether or not we are in single user mode.
222 struct stat st_mounted;
226 mounted = is_mounted(dev, &st_mounted);
228 swap = is_swap(st_mounted.st_rdev);
237 msgprintf("fsck: %s: root file system", dev);
239 msgprintf(" (CONTINUING)\n");
241 if (!freply("continue (y/n)"))
244 } else if (mounted) {
245 msgprintf("fsck: %s: mounted file system", dev);
247 msgprintf(" (CONTINUING)\n");
249 if (!freply("continue (y/n)"))
253 msgprintf("fsck: %s: swap device\n", dev);
255 msgprintf(" (CONTINUING)\n");
257 if (!freply("continue (y/n)"))
263 if (rootdev == statb.st_rdev)
265 if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
267 msgprintf("Can't open %s\n", dev);
271 msgprintf("** %s", dev);
272 if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
274 msgprintf(" (NO WRITE)");
277 pfatal("NO WRITE ACCESS");
283 #if defined(AFS_HPUX101_ENV)
284 setup_all_block_seek();
288 printf(" pid %d\n", getpid());
289 if (debug && (hotroot || mountedfs)) {
290 printf("** %s", sname);
292 printf(" is root fs");
297 printf(" is mounted");
306 sblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
307 asblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
309 sblk.b_un.b_buf = malloc(SBSIZE);
310 asblk.b_un.b_buf = malloc(SBSIZE);
312 if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
313 errexit("cannot allocate space for superblock\n");
314 dev_bsize = secsize = DEV_BSIZE;
317 * Read in the superblock, looking for alternates if necessary
319 if (readsb(1) == 0) {
320 if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
322 if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
324 for (cg = 0; cg < proto.fs_ncg; cg++) {
325 bflag = fsbtodb(&proto, cgsblock(&proto, cg));
329 if (cg >= proto.fs_ncg) {
330 msgprintf("%s %s\n%s %s\n%s %s\n",
331 "SEARCH FOR ALTERNATE SUPER-BLOCK",
332 "FAILED. YOU MUST USE THE",
333 "-b OPTION TO FSCK TO SPECIFY THE",
334 "LOCATION OF AN ALTERNATE",
335 "SUPER-BLOCK TO SUPPLY NEEDED",
336 "INFORMATION; SEE fsck(8).");
339 pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
341 maxfsblock = sblock.fs_size;
342 maxino = sblock.fs_ncg * sblock.fs_ipg;
344 * Check and potentially fix certain fields in the super block.
346 if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) {
347 pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
348 if (reply("SET TO DEFAULT") == 1) {
349 sblock.fs_optim = FS_OPTTIME;
353 if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) {
354 pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", sblock.fs_minfree);
355 if (reply("SET TO DEFAULT") == 1) {
356 sblock.fs_minfree = 10;
362 * Do we need to continue ?
364 if (pclean && sblock.fs_clean == FS_CLEAN)
366 if (pclean && hotroot && sblock.fs_clean == FS_OK)
370 # ifndef AFS_SUN59_ENV
371 if (sblock.fs_interleave < 1) {
372 pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK", sblock.fs_interleave);
373 sblock.fs_interleave = 1;
375 msgprintf(" (FIXED)\n");
376 if (preen || reply("SET TO DEFAULT") == 1) {
381 # endif /* AFS_SUN59_ENV */
382 #endif /* AFS_NEWCG_ENV */
384 if (sblock.fs_npsect < sblock.fs_nsect) {
385 pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK", sblock.fs_npsect);
386 sblock.fs_npsect = sblock.fs_nsect;
388 msgprintf(" (FIXED)\n");
389 if (preen || reply("SET TO DEFAULT") == 1) {
394 #endif /* AFS_NEWCG_ENV */
397 if (sblock.fs_postblformat == FS_42POSTBLFMT) {
399 * Requested to convert from old format to new format
402 pwarn("CONVERTING TO NEW FILE SYSTEM FORMAT\n");
403 else if (!reply("CONVERT TO NEW FILE SYSTEM FORMAT"))
406 sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
408 sblock.fs_postbloff =
409 (char *)(&sblock.fs_opostbl[0][0]) -
410 (char *)(&sblock.fs_link);
412 &sblock.fs_space[0] - (u_char *) (&sblock.fs_link);
413 sblock.fs_cgsize = fragroundup(&sblock, CGSIZE(&sblock));
415 * Planning now for future expansion.
417 # if (BYTE_ORDER == BIG_ENDIAN)
418 sblock.fs_qbmask.val[0] = 0;
419 sblock.fs_qbmask.val[1] = ~sblock.fs_bmask;
420 sblock.fs_qfmask.val[0] = 0;
421 sblock.fs_qfmask.val[1] = ~sblock.fs_fmask;
422 # endif /* BIG_ENDIAN */
423 # if (BYTE_ORDER == LITTLE_ENDIAN)
424 sblock.fs_qbmask.val[0] = ~sblock.fs_bmask;
425 sblock.fs_qbmask.val[1] = 0;
426 sblock.fs_qfmask.val[0] = ~sblock.fs_fmask;
427 sblock.fs_qfmask.val[1] = 0;
428 # endif /* LITTLE_ENDIAN */
429 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
431 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
433 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
435 sblock.fs_clean = FSCLEAN;
439 } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) {
441 * Requested to convert from new format to old format
443 if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048
444 || sblock.fs_cpg > 32 || sblock.fs_cpc > 16) {
445 msgprintf("PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
446 msgprintf("ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n");
451 pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n");
452 else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT"))
455 sblock.fs_postblformat = FS_42POSTBLFMT;
458 sizeof(struct ocg) + howmany(sblock.fs_fpg,
460 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
462 sblock.fs_npsect = 0;
463 # ifndef AFS_SUN59_ENV
464 sblock.fs_interleave = 0;
466 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
468 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
470 sblock.fs_clean = FSCLEAN;
475 errexit("UNKNOWN FILE SYSTEM FORMAT\n");
478 #endif /* AFS_NEWCG_ENV */
480 memcpy((char *)&altsblock, (char *)&sblock, (int)sblock.fs_sbsize);
481 flush(fswritefd, &asblk);
484 * read in the summary info.
487 #if defined(AFS_SUN56_ENV)
490 sip = calloc(1, sblock.fs_cssize);
491 sblock.fs_u.fs_csp = (struct csum *)sip;
492 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
494 sblock.fs_cssize - i <
495 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
498 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
499 size) != 0 && !asked) {
500 pfatal("BAD SUMMARY INFORMATION");
501 if (reply("CONTINUE") == 0)
508 #else /* AFS_SUN56_ENV */
509 #if defined(AFS_HPUX110_ENV)
510 size = fragroundup(&sblock, sblock.fs_cssize);
511 sblock.fs_csp = (struct csum *)calloc(1, (unsigned)size);
513 (fsreadfd, (char *)sblock.fs_csp, fsbtodb(&sblock, sblock.fs_csaddr),
514 size) != 0) && !asked) {
515 pfatal("BAD SUMMARY INFORMATION");
516 if (reply("CONTINUE") == 0)
520 #else /* AFS_HPUX110_ENV */
521 #if defined(AFS_HPUX101_ENV)
524 size = fragroundup(&sblock, sblock.fs_cssize);
526 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
528 sblock.fs_cssize - i <
529 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
530 #endif /* AFS_HPUX101_ENV */
531 sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
533 (fsreadfd, (char *)sblock.fs_csp[j],
534 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
535 size) != 0 && !asked) {
536 pfatal("BAD SUMMARY INFORMATION");
537 if (reply("CONTINUE") == 0)
546 #endif /* else AFS_HPUX110_ENV */
547 #endif /* else AFS_SUN56_ENV */
549 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
551 * if not forced, preening, not converting, and is clean; stop checking
554 if ((fflag == 0) && preen && (isconvert == 0)
555 && (FSOKAY == (sblock.fs_state + sblock.fs_time)) &&
557 if (preen && (isconvert == 0)
558 && (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)) &&
560 ((sblock.fs_clean == FSCLEAN) || (sblock.fs_clean == FSSTABLE))) {
567 if (!fflag && !bflag && !nflag && !hotroot && sblock.fs_clean == FS_CLEAN
569 pwarn("Clean file system - skipping fsck\n");
572 #endif /* AFS_OSF_ENV */
575 * allocate and initialize the necessary maps
577 bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
578 blockmap = calloc((unsigned)bmapsize, sizeof(char));
579 if (blockmap == NULL) {
580 msgprintf("cannot alloc %d bytes for blockmap\n", bmapsize);
583 statemap = calloc((unsigned)(maxino + 1), sizeof(char));
584 if (statemap == NULL) {
585 msgprintf("cannot alloc %d bytes for statemap\n", maxino + 1);
588 lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
589 if (lncntp == NULL) {
590 msgprintf("cannot alloc %d bytes for lncntp\n",
591 (maxino + 1) * sizeof(short));
604 * Read in the super block and its summary info.
610 daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
611 #else /* AFS_NEWCG_ENV */
612 daddr_t super = bflag ? bflag : SBLOCK;
614 #endif /* AFS_NEWCG_ENV */
615 if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
618 sblk.b_size = SBSIZE;
620 * run a few consistency checks of the super block
623 #if defined(FD_FSMAGIC)
624 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN)
625 && (sblock.fs_magic != FD_FSMAGIC)
626 #if defined(AFS_HPUX101_ENV)
627 && (sblock.fs_magic != FD_FSMAGIC_2)
630 #else /* not new magic number */
631 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN))
632 #endif /* new magic number */
634 if (sblock.fs_magic != FS_MAGIC)
637 badsb(listerr, "MAGIC NUMBER WRONG");
640 if (sblock.fs_ncg < 1) {
641 badsb(listerr, "NCG OUT OF RANGE");
644 if (sblock.fs_cpg < 1) {
645 printf("fs_cpg= %d\n", sblock.fs_cpg);
646 badsb(listerr, "CPG OUT OF RANGE");
649 if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl
650 || (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) {
651 badsb(listerr, "NCYL LESS THAN NCG*CPG");
654 if (sblock.fs_sbsize > SBSIZE) {
655 badsb(listerr, "SIZE PREPOSTEROUSLY LARGE");
659 * Compute block size that the filesystem is based on,
660 * according to fsbtodb, and adjust superblock block number
661 * so we can tell if this is an alternate later.
664 dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
665 sblk.b_bno = super / dev_bsize;
667 * Set all possible fields that could differ, then do check
668 * of whole super block against an alternate super block.
669 * When an alternate super-block is specified this check is skipped.
671 getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
678 altsblock.fs_link = sblock.fs_link;
679 #ifdef STRUCT_FS_HAS_FS_ROLLED
680 altsblock.fs_rolled = sblock.fs_rolled;
682 altsblock.fs_rlink = sblock.fs_rlink;
684 altsblock.fs_time = sblock.fs_time;
685 altsblock.fs_cstotal = sblock.fs_cstotal;
686 altsblock.fs_cgrotor = sblock.fs_cgrotor;
687 altsblock.fs_fmod = sblock.fs_fmod;
689 altsblock.fs_clean = sblock.fs_clean;
690 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
692 altsblock.fs_state = sblock.fs_state;
694 fs_set_state(&altsblock, fs_get_state(&sblock));
697 altsblock.fs_ronly = sblock.fs_ronly;
698 altsblock.fs_flags = sblock.fs_flags;
699 altsblock.fs_maxcontig = sblock.fs_maxcontig;
700 altsblock.fs_minfree = sblock.fs_minfree;
701 altsblock.fs_optim = sblock.fs_optim;
702 altsblock.fs_rotdelay = sblock.fs_rotdelay;
703 altsblock.fs_maxbpg = sblock.fs_maxbpg;
704 #if !defined(__alpha) && !defined(AFS_SUN56_ENV)
705 #if !defined(AFS_HPUX110_ENV)
706 /* HPUX110 will use UpdateAlternateSuper() below */
707 memcpy((char *)altsblock.fs_csp, (char *)sblock.fs_csp,
708 sizeof sblock.fs_csp);
709 #endif /* ! AFS_HPUX110_ENV */
710 #endif /* ! __alpha */
711 #if defined(AFS_SUN56_ENV)
712 memcpy((char *)altsblock.fs_u.fs_csp_pad, (char *)sblock.fs_u.fs_csp_pad,
713 sizeof(sblock.fs_u.fs_csp_pad));
715 memcpy((char *)altsblock.fs_fsmnt, (char *)sblock.fs_fsmnt,
716 sizeof sblock.fs_fsmnt);
718 memcpy((char *)altsblock.fs_sparecon, (char *)sblock.fs_sparecon,
719 sizeof sblock.fs_sparecon);
722 * The following should not have to be copied.
724 altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
726 # if defined(AFS_SUN59_ENV) && defined(FS_SI_OK)
727 /* fs_interleave replaced with fs_si and FS_SI_OK defined in */
728 /* ufs_fs.h version 2.63 don't need to compare either */
729 altsblock.fs_si = sblock.fs_si;
731 altsblock.fs_interleave = sblock.fs_interleave;
733 altsblock.fs_npsect = sblock.fs_npsect;
734 altsblock.fs_nrpos = sblock.fs_nrpos;
735 #endif /* AFS_NEWCG_ENV */
736 #if defined(AFS_HPUX110_ENV)
737 UpdateAlternateSuper(&sblock, &altsblock);
738 #endif /* AFS_HPUX110_ENV */
739 if (memcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
742 ((char *)&sblock.fs_blank[0], (char *)&altsblock.fs_blank[0],
743 MAXCSBUFS * sizeof(int))) {
744 memset((char *)sblock.fs_blank, 0, sizeof(sblock.fs_blank));
748 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
766 msgprintf("%s: ", devname);
767 pfatal("BAD SUPER BLOCK: %s\n", s);
769 pwarn("USE AN ALTERNATE SUPER-BLOCK TO SUPPLY NEEDED INFORMATION;\n");
770 pwarn("eg. fsck [-F ufs] -o b=# [special ...] \n");
771 pfatal("where # is the alternate super block. SEE fsck_ufs(1M). \n");
775 /* dummy function that fails if ever called */
776 calcsb(dev, devfd, fs)
779 register struct fs *fs;
784 #include <sys/ustat.h>
786 #include <sys/pstat.h>
788 #include <sys/errno.h>
792 is_mounted(device, dev_st)
796 char blockdev[BUFSIZ];
800 strcpy(blockdev, device);
801 if (stat(blockdev, dev_st) < 0)
804 if (is_pre_init(dev_st->st_rdev))
807 if ((dev_st->st_mode & S_IFMT) == S_IFCHR) {
808 dp = strrchr(blockdev, '/');
809 if (strncmp(dp, "/r", 2) != 0)
810 while (dp >= blockdev && *--dp != '/');
811 if (*(dp + 1) == 'r')
812 (void)strcpy(dp + 1, dp + 2);
813 if (stat(blockdev, dev_st) < 0)
816 if (ustat(dev_st->st_rdev, &ust) >= 0) {
817 /* make sure we are not in pre_init_rc. If we are 0 should be returned in here. */
818 if ((is_root(dev_st->st_rdev)) && is_roroot())
828 #ifdef AFS_HPUX102_ENV
829 #define PSTAT(P, N, I) pstat_getswap(P, sizeof(*P), (size_t)N, I)
831 #define PSTAT(P, N, I) pstat(PSTAT_SWAPINFO, P, sizeof(*P), (size_t)N, I)
836 struct pst_swapinfo pst[PS_BURST];
837 register struct pst_swapinfo *psp = &pst[0];
838 int idx = 0, count, match = 0;
840 while ((count = PSTAT(psp, PS_BURST, idx) != 0)) {
841 idx = pst[count - 1].pss_idx + 1;
842 if ((psp->pss_flags & SW_BLOCK) && (psp->pss_major == major(devno))
843 && (psp->pss_minor == minor(devno))) {
851 #endif /* AFS_HPUX_ENV */
864 #ifndef UID_NO_CHANGE
867 if (stat("/", &stslash) < 0)
869 if (chown("/", stslash.st_uid, stslash.st_gid) == 0)
872 if (chown("/", UID_NO_CHANGE, GID_NO_CHANGE) == 0)
875 else if (errno != EROFS) {
876 printf("fsck: chown failed: %d\n", errno);
882 is_hotroot(fs_device)
885 struct stat stslash, stblock, stchar;
886 char blockdev[BUFSIZ];
888 strcpy(blockdev, fs_device);
889 if (stat("/", &stslash) < 0) {
890 pfatal("Can't stat root\n");
894 if (stat(blockdev, &stblock) < 0) {
895 pfatal("Can't stat %s\n", blockdev);
899 if (is_pre_init(stblock.st_rdev))
902 /* convert the device name to be block device name */
903 if ((stblock.st_mode & S_IFMT) == S_IFCHR) {
905 if (stat(blockdev, &stblock) < 0)
908 if ((stblock.st_mode & S_IFMT) != S_IFBLK)
910 if (stslash.st_dev != stblock.st_rdev)
912 /* is root file system mounted read only? */
923 if (stat("/", &stslash) < 0)
925 if (stslash.st_dev != rdev_num)
930 getline(fp, loc, maxlen)
935 register char *p, *lastloc;
938 lastloc = &p[maxlen - 1];
939 while ((n = getc(fp)) != '\n') {
942 if (!isspace(n) && p < lastloc)
950 * freply - prints the string, s, gets a reply fromterminal and returns
951 * 0 - no (don't continue), and 1 - yes (continue)
959 errexit("exiting\n");
961 if (getline(stdin, line, sizeof(line)) == EOF)
963 if (line[0] == 'y' || line[0] == 'Y')
969 #if defined(AFS_HPUX110_ENV)
971 * Refer to function compare_sblocks() in HP's fsck.c
974 * This routine will compare the primary superblock (PRIM_SBLOCK) to the
975 * alternate superblock (ALT_SBLOCK). This routine will take into account
976 * that certain fields in the alternate superblock could be different than
977 * in the primary superblock. This routine checks the "static" fields
978 * and ignores the "dynamic" fields. Superblocks with the same "static"
979 * fields are considered equivalent.
982 UpdateAlternateSuper(prim_sblock, alt_sblock)
983 struct fs *prim_sblock;
984 struct fs *alt_sblock; /* will be modified */
987 * Set all possible fields that could differ, then do check
988 * of whole super block against an alternate super block.
990 * Copy dynamic fields of prim_sblock into alt_sblock
992 alt_sblock->fs_time = prim_sblock->fs_time;
993 alt_sblock->fs_minfree = prim_sblock->fs_minfree;
994 alt_sblock->fs_rotdelay = prim_sblock->fs_rotdelay;
995 alt_sblock->fs_maxcontig = prim_sblock->fs_maxcontig;
996 alt_sblock->fs_maxbpg = prim_sblock->fs_maxbpg;
997 alt_sblock->fs_mirror = prim_sblock->fs_mirror;
998 alt_sblock->fs_cstotal = prim_sblock->fs_cstotal;
999 alt_sblock->fs_fmod = prim_sblock->fs_fmod;
1000 alt_sblock->fs_clean = prim_sblock->fs_clean;
1001 alt_sblock->fs_ronly = prim_sblock->fs_ronly;
1002 alt_sblock->fs_flags = prim_sblock->fs_flags;
1003 alt_sblock->fs_cgrotor = prim_sblock->fs_cgrotor;
1005 alt_sblock->fs_csp = prim_sblock->fs_csp;
1006 #else /* not __LP64__ */
1007 alt_sblock->fs_csp = prim_sblock->fs_csp;
1008 alt_sblock->fs_csp_pad = prim_sblock->fs_csp_pad;
1009 #endif /* not __LP64__ */
1010 memcpy((char *)alt_sblock->fs_fsmnt, (char *)prim_sblock->fs_fsmnt,
1011 sizeof prim_sblock->fs_fsmnt);
1012 memcpy((char *)alt_sblock->fs_fname, (char *)prim_sblock->fs_fname,
1013 sizeof prim_sblock->fs_fname);
1014 memcpy((char *)alt_sblock->fs_fpack, (char *)prim_sblock->fs_fpack,
1015 sizeof prim_sblock->fs_fpack);
1016 if (prim_sblock->fs_featurebits & FSF_LARGEUIDS)
1017 alt_sblock->fs_featurebits |= FSF_LARGEUIDS;
1019 alt_sblock->fs_featurebits &= ~FSF_LARGEUIDS;
1021 #endif /* AFS_HPUX110_ENV */