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>
27 #if defined(AFS_SUN_ENV) || defined(AFS_OSF_ENV)
34 #define msgprintf vfscklogprintf
35 extern vfscklogprintf();
39 #include <sys/param.h>
43 #include <sys/vnode.h>
44 #include <sys/mount.h>
45 #include <ufs/inode.h>
53 #else /* AFS_OSF_ENV */
54 #ifdef AFS_VFSINCL_ENV
55 #include <sys/vnode.h>
59 #include <sys/fs/ufs_inode.h>
60 #include <sys/fs/ufs_fs.h>
62 #include <sys/fs/ufs_fsdir.h>
64 #include <sys/fs/ufs_mount.h>
66 #include <ufs/inode.h>
69 #else /* AFS_VFSINCL_ENV */
70 #include <sys/inode.h>
73 #define LONGFILENAMES 1
74 #include <sys/sysmacros.h>
78 #endif /* AFS_VFSINCL_ENV */
79 #endif /* AFS_OSF_ENV */
82 #include <sys/ioctl.h>
86 #include <sys/mntent.h>
87 #include <sys/vfstab.h>
90 #include <afs/osi_inode.h>
96 #define altsblock (*asblk.b_un.b_fs)
97 #define POWEROF2(num) (((num) & ((num) - 1)) == 0)
100 * The size of a cylinder group is calculated by CGSIZE. The maximum size
101 * is limited by the fact that cylinder groups are at most one block.
102 * Its size is derived from the size of the maps maintained in the
103 * cylinder group and the (struct cg) size.
106 /* base cg */ (sizeof(struct cg) + \
107 /* blktot size */ (fs)->fs_cpg * sizeof(afs_int32) + \
108 /* blks size */ (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(short) + \
109 /* inode map */ howmany((fs)->fs_ipg, NBBY) + \
110 /* block map */ howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY))
112 char *malloc(), *calloc();
113 struct disklabel *getdisklabel();
119 long cg, size, asked, i, j;
121 struct disklabel *lp;
124 #if defined(AFS_SUN5_ENV)
125 static char sname[MAXPATHLEN];
128 /* reset static variables that may have been damaged by parent fork */
132 #if defined(ACLS) && defined(AFS_HPUX_ENV)
136 if (stat("/", &statb) < 0)
137 errexit("Can't stat root\n");
138 rootdev = statb.st_dev;
139 #if defined(AFS_SUN5_ENV)
140 strncpy(sname, dev, sizeof(sname));
142 if (stat(sname, &statb) < 0) {
144 msgprintf("Can't stat %s\n", sname);
146 if (stat(dev, &statb) < 0) {
148 printf("Can't stat %s\n", dev);
153 if ((statb.st_mode & S_IFMT) == S_IFDIR) {
157 if ((fp = fopen(VFSTAB, "r")) == NULL) {
158 pfatal("Can't open %s file\n", VFSTAB);
161 while (!getvfsent(fp, &vtab)) {
162 if (vtab.vfs_mountp && !strcmp(vtab.vfs_mountp, sname)) {
163 strcpy(sname, vtab.vfs_special);
165 char *s = vtab.vfs_fsckdev;
174 if ((statb.st_mode & S_IFMT) != S_IFBLK
175 && (statb.st_mode & S_IFMT) != S_IFCHR) {
176 pfatal("device is not a block or character device");
177 if (reply("file is not a block or character device; OK") == 0)
185 printf("%s is mounted, fsck on BLOCK device ignored\n", sname);
189 char bname[MAXPATHLEN], *tname;
191 strcpy(bname, sname);
192 tname = unrawname(bname);
193 if (stat(tname, &statb) < 0) {
194 pfatal("Can't stat %s\n", tname);
200 hotroot = is_hotroot(dev);
203 * The following code is added to improve usability of fsck.
204 * we need to give user a warning if the device being checked is
205 * a hotroot, a mounted file system, or a swap device.
207 * 1) if nflag is set, it's pretty safe to fsck the target dev
208 * 2) if the target device is a swap, exit
209 * 3) if hotroot is set, and "-F" is not specified prompt the
210 * user and wait for reply
211 * 4) if the target is a mounted file system, and "-F" is not
212 * specified, prompt the user and wait for reply
213 * 5) if the "-m" is specifed, do no prompting since only a sanity
214 * check is being done. important during booting
216 * Caveat: There is no way to tell the current run level, so we cannot
217 * tell whether or not we are in single user mode.
221 struct stat st_mounted;
225 mounted = is_mounted(dev, &st_mounted);
227 swap = is_swap(st_mounted.st_rdev);
236 msgprintf("fsck: %s: root file system", dev);
238 msgprintf(" (CONTINUING)\n");
240 if (!freply("continue (y/n)"))
243 } else if (mounted) {
244 msgprintf("fsck: %s: mounted file system", dev);
246 msgprintf(" (CONTINUING)\n");
248 if (!freply("continue (y/n)"))
252 msgprintf("fsck: %s: swap device\n", dev);
254 msgprintf(" (CONTINUING)\n");
256 if (!freply("continue (y/n)"))
262 if (rootdev == statb.st_rdev)
264 if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
266 msgprintf("Can't open %s\n", dev);
270 msgprintf("** %s", dev);
271 if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
273 msgprintf(" (NO WRITE)");
276 pfatal("NO WRITE ACCESS");
282 #if defined(AFS_HPUX101_ENV)
283 setup_all_block_seek();
287 printf(" pid %d\n", getpid());
288 if (debug && (hotroot || mountedfs)) {
289 printf("** %s", sname);
291 printf(" is root fs");
296 printf(" is mounted");
305 sblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
306 asblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
308 sblk.b_un.b_buf = malloc(SBSIZE);
309 asblk.b_un.b_buf = malloc(SBSIZE);
311 if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
312 errexit("cannot allocate space for superblock\n");
313 dev_bsize = secsize = DEV_BSIZE;
316 * Read in the superblock, looking for alternates if necessary
318 if (readsb(1) == 0) {
319 if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
321 if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
323 for (cg = 0; cg < proto.fs_ncg; cg++) {
324 bflag = fsbtodb(&proto, cgsblock(&proto, cg));
328 if (cg >= proto.fs_ncg) {
329 msgprintf("%s %s\n%s %s\n%s %s\n",
330 "SEARCH FOR ALTERNATE SUPER-BLOCK",
331 "FAILED. YOU MUST USE THE",
332 "-b OPTION TO FSCK TO SPECIFY THE",
333 "LOCATION OF AN ALTERNATE",
334 "SUPER-BLOCK TO SUPPLY NEEDED",
335 "INFORMATION; SEE fsck(8).");
338 pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
340 maxfsblock = sblock.fs_size;
341 maxino = sblock.fs_ncg * sblock.fs_ipg;
343 * Check and potentially fix certain fields in the super block.
345 if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) {
346 pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
347 if (reply("SET TO DEFAULT") == 1) {
348 sblock.fs_optim = FS_OPTTIME;
352 if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) {
353 pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", sblock.fs_minfree);
354 if (reply("SET TO DEFAULT") == 1) {
355 sblock.fs_minfree = 10;
361 * Do we need to continue ?
363 if (pclean && sblock.fs_clean == FS_CLEAN)
365 if (pclean && hotroot && sblock.fs_clean == FS_OK)
369 # ifndef AFS_SUN59_ENV
370 if (sblock.fs_interleave < 1) {
371 pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK", sblock.fs_interleave);
372 sblock.fs_interleave = 1;
374 msgprintf(" (FIXED)\n");
375 if (preen || reply("SET TO DEFAULT") == 1) {
380 # endif /* AFS_SUN59_ENV */
381 #endif /* AFS_NEWCG_ENV */
383 if (sblock.fs_npsect < sblock.fs_nsect) {
384 pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK", sblock.fs_npsect);
385 sblock.fs_npsect = sblock.fs_nsect;
387 msgprintf(" (FIXED)\n");
388 if (preen || reply("SET TO DEFAULT") == 1) {
393 #endif /* AFS_NEWCG_ENV */
396 if (sblock.fs_postblformat == FS_42POSTBLFMT) {
398 * Requested to convert from old format to new format
401 pwarn("CONVERTING TO NEW FILE SYSTEM FORMAT\n");
402 else if (!reply("CONVERT TO NEW FILE SYSTEM FORMAT"))
405 sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
407 sblock.fs_postbloff =
408 (char *)(&sblock.fs_opostbl[0][0]) -
409 (char *)(&sblock.fs_link);
411 &sblock.fs_space[0] - (u_char *) (&sblock.fs_link);
412 sblock.fs_cgsize = fragroundup(&sblock, CGSIZE(&sblock));
414 * Planning now for future expansion.
416 # if (BYTE_ORDER == BIG_ENDIAN)
417 sblock.fs_qbmask.val[0] = 0;
418 sblock.fs_qbmask.val[1] = ~sblock.fs_bmask;
419 sblock.fs_qfmask.val[0] = 0;
420 sblock.fs_qfmask.val[1] = ~sblock.fs_fmask;
421 # endif /* BIG_ENDIAN */
422 # if (BYTE_ORDER == LITTLE_ENDIAN)
423 sblock.fs_qbmask.val[0] = ~sblock.fs_bmask;
424 sblock.fs_qbmask.val[1] = 0;
425 sblock.fs_qfmask.val[0] = ~sblock.fs_fmask;
426 sblock.fs_qfmask.val[1] = 0;
427 # endif /* LITTLE_ENDIAN */
428 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
430 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
432 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
434 sblock.fs_clean = FSCLEAN;
438 } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) {
440 * Requested to convert from new format to old format
442 if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048
443 || sblock.fs_cpg > 32 || sblock.fs_cpc > 16) {
444 msgprintf("PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
445 msgprintf("ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n");
450 pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n");
451 else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT"))
454 sblock.fs_postblformat = FS_42POSTBLFMT;
457 sizeof(struct ocg) + howmany(sblock.fs_fpg,
459 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
461 sblock.fs_npsect = 0;
462 # ifndef AFS_SUN59_ENV
463 sblock.fs_interleave = 0;
465 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
467 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
469 sblock.fs_clean = FSCLEAN;
474 errexit("UNKNOWN FILE SYSTEM FORMAT\n");
477 #endif /* AFS_NEWCG_ENV */
479 memcpy((char *)&altsblock, (char *)&sblock, (int)sblock.fs_sbsize);
480 flush(fswritefd, &asblk);
483 * read in the summary info.
486 #if defined(AFS_SUN56_ENV)
489 sip = calloc(1, sblock.fs_cssize);
490 sblock.fs_u.fs_csp = (struct csum *)sip;
491 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
493 sblock.fs_cssize - i <
494 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
497 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
498 size) != 0 && !asked) {
499 pfatal("BAD SUMMARY INFORMATION");
500 if (reply("CONTINUE") == 0)
507 #else /* AFS_SUN56_ENV */
508 #if defined(AFS_HPUX110_ENV)
509 size = fragroundup(&sblock, sblock.fs_cssize);
510 sblock.fs_csp = (struct csum *)calloc(1, (unsigned)size);
512 (fsreadfd, (char *)sblock.fs_csp, fsbtodb(&sblock, sblock.fs_csaddr),
513 size) != 0) && !asked) {
514 pfatal("BAD SUMMARY INFORMATION");
515 if (reply("CONTINUE") == 0)
519 #else /* AFS_HPUX110_ENV */
520 #if defined(AFS_HPUX101_ENV)
523 size = fragroundup(&sblock, sblock.fs_cssize);
525 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
527 sblock.fs_cssize - i <
528 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
529 #endif /* AFS_HPUX101_ENV */
530 sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
532 (fsreadfd, (char *)sblock.fs_csp[j],
533 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
534 size) != 0 && !asked) {
535 pfatal("BAD SUMMARY INFORMATION");
536 if (reply("CONTINUE") == 0)
545 #endif /* else AFS_HPUX110_ENV */
546 #endif /* else AFS_SUN56_ENV */
548 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
550 * if not forced, preening, not converting, and is clean; stop checking
553 if ((fflag == 0) && preen && (isconvert == 0)
554 && (FSOKAY == (sblock.fs_state + sblock.fs_time)) &&
556 if (preen && (isconvert == 0)
557 && (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)) &&
559 ((sblock.fs_clean == FSCLEAN) || (sblock.fs_clean == FSSTABLE))) {
566 if (!fflag && !bflag && !nflag && !hotroot && sblock.fs_clean == FS_CLEAN
568 pwarn("Clean file system - skipping fsck\n");
571 #endif /* AFS_OSF_ENV */
574 * allocate and initialize the necessary maps
576 bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
577 blockmap = calloc((unsigned)bmapsize, sizeof(char));
578 if (blockmap == NULL) {
579 msgprintf("cannot alloc %d bytes for blockmap\n", bmapsize);
582 statemap = calloc((unsigned)(maxino + 1), sizeof(char));
583 if (statemap == NULL) {
584 msgprintf("cannot alloc %d bytes for statemap\n", maxino + 1);
587 lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
588 if (lncntp == NULL) {
589 msgprintf("cannot alloc %d bytes for lncntp\n",
590 (maxino + 1) * sizeof(short));
603 * Read in the super block and its summary info.
609 daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
610 #else /* AFS_NEWCG_ENV */
611 daddr_t super = bflag ? bflag : SBLOCK;
613 #endif /* AFS_NEWCG_ENV */
614 if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
617 sblk.b_size = SBSIZE;
619 * run a few consistency checks of the super block
622 #if defined(FD_FSMAGIC)
623 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN)
624 && (sblock.fs_magic != FD_FSMAGIC)
625 #if defined(AFS_HPUX101_ENV)
626 && (sblock.fs_magic != FD_FSMAGIC_2)
629 #else /* not new magic number */
630 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN))
631 #endif /* new magic number */
633 if (sblock.fs_magic != FS_MAGIC)
636 badsb(listerr, "MAGIC NUMBER WRONG");
639 if (sblock.fs_ncg < 1) {
640 badsb(listerr, "NCG OUT OF RANGE");
643 if (sblock.fs_cpg < 1) {
644 printf("fs_cpg= %d\n", sblock.fs_cpg);
645 badsb(listerr, "CPG OUT OF RANGE");
648 if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl
649 || (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) {
650 badsb(listerr, "NCYL LESS THAN NCG*CPG");
653 if (sblock.fs_sbsize > SBSIZE) {
654 badsb(listerr, "SIZE PREPOSTEROUSLY LARGE");
658 * Compute block size that the filesystem is based on,
659 * according to fsbtodb, and adjust superblock block number
660 * so we can tell if this is an alternate later.
663 dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
664 sblk.b_bno = super / dev_bsize;
666 * Set all possible fields that could differ, then do check
667 * of whole super block against an alternate super block.
668 * When an alternate super-block is specified this check is skipped.
670 getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
677 altsblock.fs_link = sblock.fs_link;
678 #ifdef STRUCT_FS_HAS_FS_ROLLED
679 altsblock.fs_rolled = sblock.fs_rolled;
681 altsblock.fs_rlink = sblock.fs_rlink;
683 altsblock.fs_time = sblock.fs_time;
684 altsblock.fs_cstotal = sblock.fs_cstotal;
685 altsblock.fs_cgrotor = sblock.fs_cgrotor;
686 altsblock.fs_fmod = sblock.fs_fmod;
688 altsblock.fs_clean = sblock.fs_clean;
689 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
691 altsblock.fs_state = sblock.fs_state;
693 fs_set_state(&altsblock, fs_get_state(&sblock));
696 altsblock.fs_ronly = sblock.fs_ronly;
697 altsblock.fs_flags = sblock.fs_flags;
698 altsblock.fs_maxcontig = sblock.fs_maxcontig;
699 altsblock.fs_minfree = sblock.fs_minfree;
700 altsblock.fs_optim = sblock.fs_optim;
701 altsblock.fs_rotdelay = sblock.fs_rotdelay;
702 altsblock.fs_maxbpg = sblock.fs_maxbpg;
703 #if !defined(__alpha) && !defined(AFS_SUN56_ENV)
704 #if !defined(AFS_HPUX110_ENV)
705 /* HPUX110 will use UpdateAlternateSuper() below */
706 memcpy((char *)altsblock.fs_csp, (char *)sblock.fs_csp,
707 sizeof sblock.fs_csp);
708 #endif /* ! AFS_HPUX110_ENV */
709 #endif /* ! __alpha */
710 #if defined(AFS_SUN56_ENV)
711 memcpy((char *)altsblock.fs_u.fs_csp_pad, (char *)sblock.fs_u.fs_csp_pad,
712 sizeof(sblock.fs_u.fs_csp_pad));
714 memcpy((char *)altsblock.fs_fsmnt, (char *)sblock.fs_fsmnt,
715 sizeof sblock.fs_fsmnt);
717 memcpy((char *)altsblock.fs_sparecon, (char *)sblock.fs_sparecon,
718 sizeof sblock.fs_sparecon);
721 * The following should not have to be copied.
723 altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
725 # if defined(AFS_SUN59_ENV) && defined(FS_SI_OK)
726 /* fs_interleave replaced with fs_si and FS_SI_OK defined in */
727 /* ufs_fs.h version 2.63 don't need to compare either */
728 altsblock.fs_si = sblock.fs_si;
730 altsblock.fs_interleave = sblock.fs_interleave;
732 altsblock.fs_npsect = sblock.fs_npsect;
733 altsblock.fs_nrpos = sblock.fs_nrpos;
734 #endif /* AFS_NEWCG_ENV */
735 #if defined(AFS_HPUX110_ENV)
736 UpdateAlternateSuper(&sblock, &altsblock);
737 #endif /* AFS_HPUX110_ENV */
738 if (memcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
741 ((char *)&sblock.fs_blank[0], (char *)&altsblock.fs_blank[0],
742 MAXCSBUFS * sizeof(int))) {
743 memset((char *)sblock.fs_blank, 0, sizeof(sblock.fs_blank));
747 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
765 msgprintf("%s: ", devname);
766 pfatal("BAD SUPER BLOCK: %s\n", s);
768 pwarn("USE AN ALTERNATE SUPER-BLOCK TO SUPPLY NEEDED INFORMATION;\n");
769 pwarn("eg. fsck [-F ufs] -o b=# [special ...] \n");
770 pfatal("where # is the alternate super block. SEE fsck_ufs(1M). \n");
774 /* dummy function that fails if ever called */
775 calcsb(dev, devfd, fs)
778 register struct fs *fs;
783 #include <sys/ustat.h>
785 #include <sys/pstat.h>
787 #include <sys/errno.h>
791 is_mounted(device, dev_st)
795 char blockdev[BUFSIZ];
799 strcpy(blockdev, device);
800 if (stat(blockdev, dev_st) < 0)
803 if (is_pre_init(dev_st->st_rdev))
806 if ((dev_st->st_mode & S_IFMT) == S_IFCHR) {
807 dp = strrchr(blockdev, '/');
808 if (strncmp(dp, "/r", 2) != 0)
809 while (dp >= blockdev && *--dp != '/');
810 if (*(dp + 1) == 'r')
811 (void)strcpy(dp + 1, dp + 2);
812 if (stat(blockdev, dev_st) < 0)
815 if (ustat(dev_st->st_rdev, &ust) >= 0) {
816 /* make sure we are not in pre_init_rc. If we are 0 should be returned in here. */
817 if ((is_root(dev_st->st_rdev)) && is_roroot())
827 #ifdef AFS_HPUX102_ENV
828 #define PSTAT(P, N, I) pstat_getswap(P, sizeof(*P), (size_t)N, I)
830 #define PSTAT(P, N, I) pstat(PSTAT_SWAPINFO, P, sizeof(*P), (size_t)N, I)
835 struct pst_swapinfo pst[PS_BURST];
836 register struct pst_swapinfo *psp = &pst[0];
837 int idx = 0, count, match = 0;
839 while ((count = PSTAT(psp, PS_BURST, idx) != 0)) {
840 idx = pst[count - 1].pss_idx + 1;
841 if ((psp->pss_flags & SW_BLOCK) && (psp->pss_major == major(devno))
842 && (psp->pss_minor == minor(devno))) {
850 #endif /* AFS_HPUX_ENV */
863 #ifndef UID_NO_CHANGE
866 if (stat("/", &stslash) < 0)
868 if (chown("/", stslash.st_uid, stslash.st_gid) == 0)
871 if (chown("/", UID_NO_CHANGE, GID_NO_CHANGE) == 0)
874 else if (errno != EROFS) {
875 printf("fsck: chown failed: %d\n", errno);
881 is_hotroot(fs_device)
884 struct stat stslash, stblock, stchar;
885 char blockdev[BUFSIZ];
887 strcpy(blockdev, fs_device);
888 if (stat("/", &stslash) < 0) {
889 pfatal("Can't stat root\n");
893 if (stat(blockdev, &stblock) < 0) {
894 pfatal("Can't stat %s\n", blockdev);
898 if (is_pre_init(stblock.st_rdev))
901 /* convert the device name to be block device name */
902 if ((stblock.st_mode & S_IFMT) == S_IFCHR) {
904 if (stat(blockdev, &stblock) < 0)
907 if ((stblock.st_mode & S_IFMT) != S_IFBLK)
909 if (stslash.st_dev != stblock.st_rdev)
911 /* is root file system mounted read only? */
922 if (stat("/", &stslash) < 0)
924 if (stslash.st_dev != rdev_num)
929 getline(fp, loc, maxlen)
934 register char *p, *lastloc;
937 lastloc = &p[maxlen - 1];
938 while ((n = getc(fp)) != '\n') {
941 if (!isspace(n) && p < lastloc)
949 * freply - prints the string, s, gets a reply fromterminal and returns
950 * 0 - no (don't continue), and 1 - yes (continue)
958 errexit("exiting\n");
960 if (getline(stdin, line, sizeof(line)) == EOF)
962 if (line[0] == 'y' || line[0] == 'Y')
968 #if defined(AFS_HPUX110_ENV)
970 * Refer to function compare_sblocks() in HP's fsck.c
973 * This routine will compare the primary superblock (PRIM_SBLOCK) to the
974 * alternate superblock (ALT_SBLOCK). This routine will take into account
975 * that certain fields in the alternate superblock could be different than
976 * in the primary superblock. This routine checks the "static" fields
977 * and ignores the "dynamic" fields. Superblocks with the same "static"
978 * fields are considered equivalent.
981 UpdateAlternateSuper(prim_sblock, alt_sblock)
982 struct fs *prim_sblock;
983 struct fs *alt_sblock; /* will be modified */
986 * Set all possible fields that could differ, then do check
987 * of whole super block against an alternate super block.
989 * Copy dynamic fields of prim_sblock into alt_sblock
991 alt_sblock->fs_time = prim_sblock->fs_time;
992 alt_sblock->fs_minfree = prim_sblock->fs_minfree;
993 alt_sblock->fs_rotdelay = prim_sblock->fs_rotdelay;
994 alt_sblock->fs_maxcontig = prim_sblock->fs_maxcontig;
995 alt_sblock->fs_maxbpg = prim_sblock->fs_maxbpg;
996 alt_sblock->fs_mirror = prim_sblock->fs_mirror;
997 alt_sblock->fs_cstotal = prim_sblock->fs_cstotal;
998 alt_sblock->fs_fmod = prim_sblock->fs_fmod;
999 alt_sblock->fs_clean = prim_sblock->fs_clean;
1000 alt_sblock->fs_ronly = prim_sblock->fs_ronly;
1001 alt_sblock->fs_flags = prim_sblock->fs_flags;
1002 alt_sblock->fs_cgrotor = prim_sblock->fs_cgrotor;
1004 alt_sblock->fs_csp = prim_sblock->fs_csp;
1005 #else /* not __LP64__ */
1006 alt_sblock->fs_csp = prim_sblock->fs_csp;
1007 alt_sblock->fs_csp_pad = prim_sblock->fs_csp_pad;
1008 #endif /* not __LP64__ */
1009 memcpy((char *)alt_sblock->fs_fsmnt, (char *)prim_sblock->fs_fsmnt,
1010 sizeof prim_sblock->fs_fsmnt);
1011 memcpy((char *)alt_sblock->fs_fname, (char *)prim_sblock->fs_fname,
1012 sizeof prim_sblock->fs_fname);
1013 memcpy((char *)alt_sblock->fs_fpack, (char *)prim_sblock->fs_fpack,
1014 sizeof prim_sblock->fs_fpack);
1015 if (prim_sblock->fs_featurebits & FSF_LARGEUIDS)
1016 alt_sblock->fs_featurebits |= FSF_LARGEUIDS;
1018 alt_sblock->fs_featurebits &= ~FSF_LARGEUIDS;
1020 #endif /* AFS_HPUX110_ENV */