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 */
134 #if defined(ACLS) && defined(AFS_HPUX_ENV)
138 if (stat("/", &statb) < 0)
139 errexit("Can't stat root\n");
140 rootdev = statb.st_dev;
141 #if defined(AFS_SUN5_ENV)
142 strncpy(sname, dev, sizeof(sname));
144 if (stat(sname, &statb) < 0) {
146 msgprintf("Can't stat %s\n", sname);
148 if (stat(dev, &statb) < 0) {
150 printf("Can't stat %s\n", dev);
155 if ((statb.st_mode & S_IFMT) == S_IFDIR) {
159 if ((fp = fopen(VFSTAB, "r")) == NULL) {
160 pfatal("Can't open %s file\n", VFSTAB);
163 while (!getvfsent(fp, &vtab)) {
164 if (vtab.vfs_mountp && !strcmp(vtab.vfs_mountp, sname)) {
165 strcpy(sname, vtab.vfs_special);
167 char *s = vtab.vfs_fsckdev;
176 if ((statb.st_mode & S_IFMT) != S_IFBLK &&
177 (statb.st_mode & S_IFMT) != S_IFCHR) {
178 pfatal("device is not a block or character device");
179 if (reply("file is not a block or character device; OK") == 0)
187 printf("%s is mounted, fsck on BLOCK device ignored\n", sname);
191 char bname[MAXPATHLEN], *tname;
193 strcpy(bname, sname);
194 tname = unrawname(bname);
195 if (stat(tname, &statb) < 0) {
196 pfatal("Can't stat %s\n", tname);
202 hotroot = is_hotroot(dev);
205 * The following code is added to improve usability of fsck.
206 * we need to give user a warning if the device being checked is
207 * a hotroot, a mounted file system, or a swap device.
209 * 1) if nflag is set, it's pretty safe to fsck the target dev
210 * 2) if the target device is a swap, exit
211 * 3) if hotroot is set, and "-F" is not specified prompt the
212 * user and wait for reply
213 * 4) if the target is a mounted file system, and "-F" is not
214 * specified, prompt the user and wait for reply
215 * 5) if the "-m" is specifed, do no prompting since only a sanity
216 * check is being done. important during booting
218 * Caveat: There is no way to tell the current run level, so we cannot
219 * tell whether or not we are in single user mode.
223 struct stat st_mounted;
227 mounted = is_mounted(dev,&st_mounted);
229 swap = is_swap(st_mounted.st_rdev);
238 msgprintf("fsck: %s: root file system",dev);
240 msgprintf(" (CONTINUING)\n");
242 if (!freply("continue (y/n)"))
245 } else if (mounted) {
246 msgprintf("fsck: %s: mounted file system",dev);
248 msgprintf(" (CONTINUING)\n");
250 if (!freply("continue (y/n)"))
254 msgprintf("fsck: %s: swap device\n",dev);
256 msgprintf(" (CONTINUING)\n");
258 if (!freply("continue (y/n)"))
264 if (rootdev == statb.st_rdev)
266 if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
268 msgprintf("Can't open %s\n", dev);
272 msgprintf("** %s", dev);
273 if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
275 msgprintf(" (NO WRITE)");
278 pfatal("NO WRITE ACCESS");
284 #if defined(AFS_HPUX101_ENV)
285 setup_all_block_seek();
289 printf(" pid %d\n", getpid());
290 if (debug && (hotroot || mountedfs)) {
291 printf("** %s", sname);
293 printf(" is root fs");
298 printf(" is mounted");
307 sblk.b_un.b_buf = malloc(SBSIZE+ALPHA_EXT);
308 asblk.b_un.b_buf = malloc(SBSIZE+ALPHA_EXT);
310 sblk.b_un.b_buf = malloc(SBSIZE);
311 asblk.b_un.b_buf = malloc(SBSIZE);
313 if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
314 errexit("cannot allocate space for superblock\n");
315 dev_bsize = secsize = DEV_BSIZE;
318 * Read in the superblock, looking for alternates if necessary
320 if (readsb(1) == 0) {
321 if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
323 if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
325 for (cg = 0; cg < proto.fs_ncg; cg++) {
326 bflag = fsbtodb(&proto, cgsblock(&proto, cg));
330 if (cg >= proto.fs_ncg) {
331 msgprintf("%s %s\n%s %s\n%s %s\n",
332 "SEARCH FOR ALTERNATE SUPER-BLOCK",
333 "FAILED. YOU MUST USE THE",
334 "-b OPTION TO FSCK TO SPECIFY THE",
335 "LOCATION OF AN ALTERNATE",
336 "SUPER-BLOCK TO SUPPLY NEEDED",
337 "INFORMATION; SEE fsck(8).");
340 pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
342 maxfsblock = sblock.fs_size;
343 maxino = sblock.fs_ncg * sblock.fs_ipg;
345 * Check and potentially fix certain fields in the super block.
347 if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) {
348 pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
349 if (reply("SET TO DEFAULT") == 1) {
350 sblock.fs_optim = FS_OPTTIME;
354 if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) {
355 pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK",
357 if (reply("SET TO DEFAULT") == 1) {
358 sblock.fs_minfree = 10;
364 * If '-p' is used and the partition was cleanly unmounted last time then skip the
367 if (only_when_needed && (sblock.fs_clean == FS_CLEAN) &&
368 clean_byte_valid(sblock.fs_lastfsck)) {
369 msgprintf("%s: umounted cleanly\n", dev);
375 * Do we need to continue ?
377 if (pclean && sblock.fs_clean == FS_CLEAN)
379 if (pclean && hotroot && sblock.fs_clean == FS_OK)
383 if (sblock.fs_interleave < 1) {
384 pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK",
385 sblock.fs_interleave);
386 sblock.fs_interleave = 1;
388 msgprintf(" (FIXED)\n");
389 if (preen || reply("SET TO DEFAULT") == 1) {
394 #endif /* AFS_NEWCG_ENV */
396 if (sblock.fs_npsect < sblock.fs_nsect) {
397 pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK",
399 sblock.fs_npsect = sblock.fs_nsect;
401 msgprintf(" (FIXED)\n");
402 if (preen || reply("SET TO DEFAULT") == 1) {
407 #endif /* AFS_NEWCG_ENV */
410 if (sblock.fs_postblformat == FS_42POSTBLFMT) {
412 * Requested to convert from old format to new format
415 pwarn("CONVERTING TO NEW FILE SYSTEM FORMAT\n");
416 else if (!reply("CONVERT TO NEW FILE SYSTEM FORMAT"))
419 sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
421 sblock.fs_postbloff =
422 (char *)(&sblock.fs_opostbl[0][0]) -
423 (char *)(&sblock.fs_link);
424 sblock.fs_rotbloff = &sblock.fs_space[0] -
425 (u_char *)(&sblock.fs_link);
427 fragroundup(&sblock, CGSIZE(&sblock));
429 * Planning now for future expansion.
431 # if (BYTE_ORDER == BIG_ENDIAN)
432 sblock.fs_qbmask.val[0] = 0;
433 sblock.fs_qbmask.val[1] = ~sblock.fs_bmask;
434 sblock.fs_qfmask.val[0] = 0;
435 sblock.fs_qfmask.val[1] = ~sblock.fs_fmask;
436 # endif /* BIG_ENDIAN */
437 # if (BYTE_ORDER == LITTLE_ENDIAN)
438 sblock.fs_qbmask.val[0] = ~sblock.fs_bmask;
439 sblock.fs_qbmask.val[1] = 0;
440 sblock.fs_qfmask.val[0] = ~sblock.fs_fmask;
441 sblock.fs_qfmask.val[1] = 0;
442 # endif /* LITTLE_ENDIAN */
443 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
445 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
447 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
449 sblock.fs_clean = FSCLEAN;
453 } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) {
455 * Requested to convert from new format to old format
457 if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048 ||
458 sblock.fs_cpg > 32 || sblock.fs_cpc > 16) {
460 "PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
462 "ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n"); errexit("");
466 pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n");
467 else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT"))
470 sblock.fs_postblformat = FS_42POSTBLFMT;
471 sblock.fs_cgsize = fragroundup(&sblock,
472 sizeof(struct ocg) + howmany(sblock.fs_fpg, NBBY));
473 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
475 sblock.fs_npsect = 0;
476 sblock.fs_interleave = 0;
477 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
479 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
481 sblock.fs_clean = FSCLEAN;
486 errexit("UNKNOWN FILE SYSTEM FORMAT\n");
489 #endif /* AFS_NEWCG_ENV */
491 memcpy((char *)&altsblock, (char *)&sblock, (int)sblock.fs_sbsize);
492 flush(fswritefd, &asblk);
495 * read in the summary info.
498 #if defined(AFS_SUN56_ENV)
501 sip = calloc(1, sblock.fs_cssize);
502 sblock.fs_u.fs_csp = (struct csum *)sip;
503 for (i=0, j=0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
504 size = sblock.fs_cssize - i < sblock.fs_bsize ?
505 sblock.fs_cssize - i : sblock.fs_bsize;
506 if (bread(fsreadfd, sip,
507 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
508 size) != 0 && !asked) {
509 pfatal("BAD SUMMARY INFORMATION");
510 if (reply("CONTINUE") == 0)
517 #else /* AFS_SUN56_ENV */
518 #if defined(AFS_HPUX110_ENV)
519 size = fragroundup(&sblock, sblock.fs_cssize);
520 sblock.fs_csp = (struct csum *)calloc(1, (unsigned)size);
521 if ((bread(fsreadfd, (char *)sblock.fs_csp,
522 fsbtodb(&sblock, sblock.fs_csaddr), size) != 0) &&
524 pfatal("BAD SUMMARY INFORMATION");
525 if (reply("CONTINUE") == 0)
529 #else /* AFS_HPUX110_ENV */
530 #if defined(AFS_HPUX101_ENV)
533 size = fragroundup(&sblock, sblock.fs_cssize);
535 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
536 size = sblock.fs_cssize - i < sblock.fs_bsize ?
537 sblock.fs_cssize - i : sblock.fs_bsize;
538 #endif /* AFS_HPUX101_ENV */
539 sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
540 if (bread(fsreadfd, (char *)sblock.fs_csp[j],
541 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
542 size) != 0 && !asked) {
543 pfatal("BAD SUMMARY INFORMATION");
544 if (reply("CONTINUE") == 0)
553 #endif /* else AFS_HPUX110_ENV */
554 #endif /* else AFS_SUN56_ENV */
556 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
558 * if not forced, preening, not converting, and is clean; stop checking
561 if ((fflag == 0) && preen && (isconvert == 0) &&
562 (FSOKAY == (sblock.fs_state + sblock.fs_time)) &&
564 if (preen && (isconvert == 0) &&
565 (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)) &&
567 ((sblock.fs_clean == FSCLEAN) ||
568 (sblock.fs_clean == FSSTABLE)))
576 if (!fflag && !bflag && !nflag && !hotroot
577 && sblock.fs_clean == FS_CLEAN && !sblk.b_dirty) {
578 pwarn("Clean file system - skipping fsck\n");
581 #endif /* AFS_OSF_ENV */
584 * allocate and initialize the necessary maps
586 bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
587 blockmap = calloc((unsigned)bmapsize, sizeof (char));
588 if (blockmap == NULL) {
589 msgprintf("cannot alloc %d bytes for blockmap\n", bmapsize);
592 statemap = calloc((unsigned)(maxino + 1), sizeof(char));
593 if (statemap == NULL) {
594 msgprintf("cannot alloc %d bytes for statemap\n", maxino + 1);
597 lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
598 if (lncntp == NULL) {
599 msgprintf("cannot alloc %d bytes for lncntp\n",
600 (maxino + 1) * sizeof(short));
613 * Read in the super block and its summary info.
619 daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
620 #else /* AFS_NEWCG_ENV */
621 daddr_t super = bflag ? bflag : SBLOCK;
623 #endif /* AFS_NEWCG_ENV */
624 if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
627 sblk.b_size = SBSIZE;
629 * run a few consistency checks of the super block
632 #if defined(FD_FSMAGIC)
633 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN)
634 && (sblock.fs_magic != FD_FSMAGIC)
635 #if defined(AFS_HPUX101_ENV)
636 && ( sblock.fs_magic != FD_FSMAGIC_2)
639 #else /* not new magic number */
640 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN))
641 #endif /* new magic number */
643 if (sblock.fs_magic != FS_MAGIC)
645 { badsb(listerr, "MAGIC NUMBER WRONG"); return (0); }
646 if (sblock.fs_ncg < 1)
647 { badsb(listerr, "NCG OUT OF RANGE"); return (0); }
648 if (sblock.fs_cpg < 1)
649 { printf("fs_cpg= %d\n", sblock.fs_cpg); badsb(listerr, "CPG OUT OF RANGE"); return (0); }
650 if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl ||
651 (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl)
652 { badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); }
653 if (sblock.fs_sbsize > SBSIZE)
654 { badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); }
656 * Compute block size that the filesystem is based on,
657 * according to fsbtodb, and adjust superblock block number
658 * so we can tell if this is an alternate later.
661 dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
662 sblk.b_bno = super / dev_bsize;
664 * Set all possible fields that could differ, then do check
665 * of whole super block against an alternate super block.
666 * When an alternate super-block is specified this check is skipped.
668 getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
675 altsblock.fs_link = sblock.fs_link;
676 #ifdef STRUCT_FS_HAS_FS_ROLLED
677 altsblock.fs_rolled = sblock.fs_rolled;
679 altsblock.fs_rlink = sblock.fs_rlink;
681 altsblock.fs_time = sblock.fs_time;
682 altsblock.fs_cstotal = sblock.fs_cstotal;
683 altsblock.fs_cgrotor = sblock.fs_cgrotor;
684 altsblock.fs_fmod = sblock.fs_fmod;
686 altsblock.fs_clean = sblock.fs_clean;
687 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
689 altsblock.fs_state = sblock.fs_state;
691 fs_set_state(&altsblock, fs_get_state(&sblock));
694 altsblock.fs_ronly = sblock.fs_ronly;
695 altsblock.fs_flags = sblock.fs_flags;
696 altsblock.fs_maxcontig = sblock.fs_maxcontig;
697 altsblock.fs_minfree = sblock.fs_minfree;
698 altsblock.fs_optim = sblock.fs_optim;
699 altsblock.fs_rotdelay = sblock.fs_rotdelay;
700 altsblock.fs_maxbpg = sblock.fs_maxbpg;
701 #if !defined(__alpha) && !defined(AFS_SUN56_ENV)
702 #if !defined(AFS_HPUX110_ENV)
703 /* HPUX110 will use UpdateAlternateSuper() below */
704 memcpy((char *)altsblock.fs_csp, (char *)sblock.fs_csp, sizeof sblock.fs_csp);
705 #endif /* ! AFS_HPUX110_ENV */
706 #endif /* ! __alpha */
707 #if defined(AFS_SUN56_ENV)
708 memcpy((char *)altsblock.fs_u.fs_csp_pad, (char *)sblock.fs_u.fs_csp_pad, sizeof (sblock.fs_u.fs_csp_pad));
710 memcpy((char *)altsblock.fs_fsmnt, (char *)sblock.fs_fsmnt, sizeof sblock.fs_fsmnt);
712 memcpy((char *)altsblock.fs_sparecon, (char *)sblock.fs_sparecon, sizeof sblock.fs_sparecon);
714 #if defined(AFS_DEC_ENV)
715 memcpy((char *)altsblock.fs_extra, (char *)sblock.fs_extra, sizeof sblock.fs_extra);
716 altsblock.fs_deftimer = sblock.fs_deftimer;
717 altsblock.fs_lastfsck = sblock.fs_lastfsck;
718 altsblock.fs_gennum = sblock.fs_gennum;
721 * The following should not have to be copied.
723 altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
725 altsblock.fs_interleave = sblock.fs_interleave;
726 altsblock.fs_npsect = sblock.fs_npsect;
727 altsblock.fs_nrpos = sblock.fs_nrpos;
728 #endif /* AFS_NEWCG_ENV */
729 #if defined(AFS_HPUX110_ENV)
730 UpdateAlternateSuper(&sblock, &altsblock);
731 #endif /* AFS_HPUX110_ENV */
732 if (memcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
734 if (memcmp((char *)&sblock.fs_blank[0],
735 (char *)&altsblock.fs_blank[0],
736 MAXCSBUFS*sizeof(int))) {
737 memset((char *)sblock.fs_blank, 0, sizeof(sblock.fs_blank));
741 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
759 msgprintf("%s: ", devname);
760 pfatal("BAD SUPER BLOCK: %s\n", s);
762 pwarn("USE AN ALTERNATE SUPER-BLOCK TO SUPPLY NEEDED INFORMATION;\n");
763 pwarn("eg. fsck [-F ufs] -o b=# [special ...] \n");
764 pfatal("where # is the alternate super block. SEE fsck_ufs(1M). \n");
768 /* dummy function that fails if ever called */
769 calcsb(dev, devfd, fs)
772 register struct fs *fs;
778 clean_byte_valid(lastfsck)
785 if ((!sblock.fs_deftimer) || (!sblock.fs_lastfsck) || (lastfsck > now)) {
786 sblock.fs_deftimer = 0;
789 if (!sblock.fs_cleantimer)
791 delta = (now - lastfsck) / 86400;
798 #include <sys/ustat.h>
800 #include <sys/pstat.h>
802 #include <sys/errno.h>
806 is_mounted(device,dev_st)
810 char blockdev[BUFSIZ];
814 strcpy(blockdev,device);
815 if (stat(blockdev,dev_st)<0)
818 if (is_pre_init(dev_st->st_rdev))
821 if ((dev_st->st_mode & S_IFMT) == S_IFCHR) {
822 dp = strrchr(blockdev, '/');
823 if (strncmp(dp, "/r", 2) != 0)
824 while (dp >= blockdev && *--dp != '/');
826 (void)strcpy(dp+1, dp+2);
827 if (stat(blockdev,dev_st)<0)
830 if (ustat(dev_st->st_rdev, &ust) >= 0) {
831 /* make sure we are not in pre_init_rc. If we are 0 should be returned in here. */
832 if ((is_root(dev_st->st_rdev)) && is_roroot()) return (0);
841 #ifdef AFS_HPUX102_ENV
842 #define PSTAT(P, N, I) pstat_getswap(P, sizeof(*P), (size_t)N, I)
844 #define PSTAT(P, N, I) pstat(PSTAT_SWAPINFO, P, sizeof(*P), (size_t)N, I)
849 struct pst_swapinfo pst[PS_BURST];
850 register struct pst_swapinfo *psp = &pst[0];
851 int idx = 0, count, match=0;
853 while ((count = PSTAT(psp, PS_BURST, idx) != 0)) {
854 idx = pst[count - 1].pss_idx + 1;
855 if ((psp->pss_flags & SW_BLOCK) && (psp->pss_major == major(devno)) && (psp->pss_minor == minor(devno))) {
876 #ifndef UID_NO_CHANGE
879 if (stat("/",&stslash) < 0)
881 if ( chown("/", stslash.st_uid, stslash.st_gid) == 0 )
884 if ( chown("/",UID_NO_CHANGE,GID_NO_CHANGE) == 0 )
887 else if (errno != EROFS ) {
888 printf ("fsck: chown failed: %d\n",errno);
894 is_hotroot(fs_device)
897 struct stat stslash, stblock, stchar;
898 char blockdev[BUFSIZ];
900 strcpy(blockdev,fs_device);
901 if (stat("/", &stslash) < 0) {
902 pfatal("Can't stat root\n");
906 if (stat(blockdev, &stblock) < 0) {
907 pfatal("Can't stat %s\n", blockdev);
911 if (is_pre_init(stblock.st_rdev))
914 /* convert the device name to be block device name */
915 if ((stblock.st_mode & S_IFMT) == S_IFCHR) {
917 if (stat(blockdev, &stblock) < 0)
920 if ((stblock.st_mode & S_IFMT) != S_IFBLK)
922 if (stslash.st_dev != stblock.st_rdev)
924 /* is root file system mounted read only? */
935 if (stat("/",&stslash) < 0)
937 if (stslash.st_dev != rdev_num)
942 getline(fp, loc, maxlen)
947 register char *p, *lastloc;
950 lastloc = &p[maxlen-1];
951 while ((n = getc(fp)) != '\n') {
954 if (!isspace(n) && p < lastloc)
962 * freply - prints the string, s, gets a reply fromterminal and returns
963 * 0 - no (don't continue), and 1 - yes (continue)
971 errexit("exiting\n");
973 if (getline(stdin, line, sizeof(line)) == EOF)
975 if (line[0] == 'y' || line[0] == 'Y')
981 #if defined(AFS_HPUX110_ENV)
983 * Refer to function compare_sblocks() in HP's fsck.c
986 * This routine will compare the primary superblock (PRIM_SBLOCK) to the
987 * alternate superblock (ALT_SBLOCK). This routine will take into account
988 * that certain fields in the alternate superblock could be different than
989 * in the primary superblock. This routine checks the "static" fields
990 * and ignores the "dynamic" fields. Superblocks with the same "static"
991 * fields are considered equivalent.
994 UpdateAlternateSuper(prim_sblock, alt_sblock)
995 struct fs *prim_sblock;
996 struct fs *alt_sblock; /* will be modified */
999 * Set all possible fields that could differ, then do check
1000 * of whole super block against an alternate super block.
1002 * Copy dynamic fields of prim_sblock into alt_sblock
1004 alt_sblock->fs_time = prim_sblock->fs_time;
1005 alt_sblock->fs_minfree = prim_sblock->fs_minfree;
1006 alt_sblock->fs_rotdelay = prim_sblock->fs_rotdelay;
1007 alt_sblock->fs_maxcontig = prim_sblock->fs_maxcontig;
1008 alt_sblock->fs_maxbpg = prim_sblock->fs_maxbpg;
1009 alt_sblock->fs_mirror = prim_sblock->fs_mirror;
1010 alt_sblock->fs_cstotal = prim_sblock->fs_cstotal;
1011 alt_sblock->fs_fmod = prim_sblock->fs_fmod;
1012 alt_sblock->fs_clean = prim_sblock->fs_clean;
1013 alt_sblock->fs_ronly = prim_sblock->fs_ronly;
1014 alt_sblock->fs_flags = prim_sblock->fs_flags;
1015 alt_sblock->fs_cgrotor = prim_sblock->fs_cgrotor;
1017 alt_sblock->fs_csp = prim_sblock->fs_csp;
1018 #else /* not __LP64__ */
1019 alt_sblock->fs_csp = prim_sblock->fs_csp;
1020 alt_sblock->fs_csp_pad = prim_sblock->fs_csp_pad;
1021 #endif /* not __LP64__ */
1022 memcpy((char *)alt_sblock->fs_fsmnt, (char *)prim_sblock->fs_fsmnt,
1023 sizeof prim_sblock->fs_fsmnt);
1024 memcpy((char *)alt_sblock->fs_fname, (char *)prim_sblock->fs_fname,
1025 sizeof prim_sblock->fs_fname);
1026 memcpy((char *)alt_sblock->fs_fpack, (char *)prim_sblock->fs_fpack,
1027 sizeof prim_sblock->fs_fpack);
1028 if (prim_sblock->fs_featurebits & FSF_LARGEUIDS)
1029 alt_sblock->fs_featurebits |= FSF_LARGEUIDS;
1031 alt_sblock->fs_featurebits &= ~FSF_LARGEUIDS;
1033 #endif /* AFS_HPUX110_ENV */