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 */
135 #if defined(ACLS) && defined(AFS_HPUX_ENV)
139 if (stat("/", &statb) < 0)
140 errexit("Can't stat root\n");
141 rootdev = statb.st_dev;
142 #if defined(AFS_SUN5_ENV)
143 strncpy(sname, dev, sizeof(sname));
145 if (stat(sname, &statb) < 0) {
147 msgprintf("Can't stat %s\n", sname);
149 if (stat(dev, &statb) < 0) {
151 printf("Can't stat %s\n", dev);
156 if ((statb.st_mode & S_IFMT) == S_IFDIR) {
160 if ((fp = fopen(VFSTAB, "r")) == NULL) {
161 pfatal("Can't open %s file\n", VFSTAB);
164 while (!getvfsent(fp, &vtab)) {
165 if (vtab.vfs_mountp && !strcmp(vtab.vfs_mountp, sname)) {
166 strcpy(sname, vtab.vfs_special);
168 char *s = vtab.vfs_fsckdev;
177 if ((statb.st_mode & S_IFMT) != S_IFBLK
178 && (statb.st_mode & S_IFMT) != S_IFCHR) {
179 pfatal("device is not a block or character device");
180 if (reply("file is not a block or character device; OK") == 0)
188 printf("%s is mounted, fsck on BLOCK device ignored\n", sname);
192 char bname[MAXPATHLEN], *tname;
194 strcpy(bname, sname);
195 tname = unrawname(bname);
196 if (stat(tname, &statb) < 0) {
197 pfatal("Can't stat %s\n", tname);
203 hotroot = is_hotroot(dev);
206 * The following code is added to improve usability of fsck.
207 * we need to give user a warning if the device being checked is
208 * a hotroot, a mounted file system, or a swap device.
210 * 1) if nflag is set, it's pretty safe to fsck the target dev
211 * 2) if the target device is a swap, exit
212 * 3) if hotroot is set, and "-F" is not specified prompt the
213 * user and wait for reply
214 * 4) if the target is a mounted file system, and "-F" is not
215 * specified, prompt the user and wait for reply
216 * 5) if the "-m" is specifed, do no prompting since only a sanity
217 * check is being done. important during booting
219 * Caveat: There is no way to tell the current run level, so we cannot
220 * tell whether or not we are in single user mode.
224 struct stat st_mounted;
228 mounted = is_mounted(dev, &st_mounted);
230 swap = is_swap(st_mounted.st_rdev);
239 msgprintf("fsck: %s: root file system", dev);
241 msgprintf(" (CONTINUING)\n");
243 if (!freply("continue (y/n)"))
246 } else if (mounted) {
247 msgprintf("fsck: %s: mounted file system", dev);
249 msgprintf(" (CONTINUING)\n");
251 if (!freply("continue (y/n)"))
255 msgprintf("fsck: %s: swap device\n", dev);
257 msgprintf(" (CONTINUING)\n");
259 if (!freply("continue (y/n)"))
265 if (rootdev == statb.st_rdev)
267 if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
269 msgprintf("Can't open %s\n", dev);
273 msgprintf("** %s", dev);
274 if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
276 msgprintf(" (NO WRITE)");
279 pfatal("NO WRITE ACCESS");
285 #if defined(AFS_HPUX101_ENV)
286 setup_all_block_seek();
290 printf(" pid %d\n", getpid());
291 if (debug && (hotroot || mountedfs)) {
292 printf("** %s", sname);
294 printf(" is root fs");
299 printf(" is mounted");
308 sblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
309 asblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
311 sblk.b_un.b_buf = malloc(SBSIZE);
312 asblk.b_un.b_buf = malloc(SBSIZE);
314 if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
315 errexit("cannot allocate space for superblock\n");
316 dev_bsize = secsize = DEV_BSIZE;
319 * Read in the superblock, looking for alternates if necessary
321 if (readsb(1) == 0) {
322 if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
324 if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
326 for (cg = 0; cg < proto.fs_ncg; cg++) {
327 bflag = fsbtodb(&proto, cgsblock(&proto, cg));
331 if (cg >= proto.fs_ncg) {
332 msgprintf("%s %s\n%s %s\n%s %s\n",
333 "SEARCH FOR ALTERNATE SUPER-BLOCK",
334 "FAILED. YOU MUST USE THE",
335 "-b OPTION TO FSCK TO SPECIFY THE",
336 "LOCATION OF AN ALTERNATE",
337 "SUPER-BLOCK TO SUPPLY NEEDED",
338 "INFORMATION; SEE fsck(8).");
341 pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
343 maxfsblock = sblock.fs_size;
344 maxino = sblock.fs_ncg * sblock.fs_ipg;
346 * Check and potentially fix certain fields in the super block.
348 if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) {
349 pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
350 if (reply("SET TO DEFAULT") == 1) {
351 sblock.fs_optim = FS_OPTTIME;
355 if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) {
356 pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", sblock.fs_minfree);
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 # ifndef AFS_SUN59_ENV
384 if (sblock.fs_interleave < 1) {
385 pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK", sblock.fs_interleave);
386 sblock.fs_interleave = 1;
388 msgprintf(" (FIXED)\n");
389 if (preen || reply("SET TO DEFAULT") == 1) {
394 # endif /* AFS_SUN59_ENV */
395 #endif /* AFS_NEWCG_ENV */
397 if (sblock.fs_npsect < sblock.fs_nsect) {
398 pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK", sblock.fs_npsect);
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);
425 &sblock.fs_space[0] - (u_char *) (&sblock.fs_link);
426 sblock.fs_cgsize = fragroundup(&sblock, CGSIZE(&sblock));
428 * Planning now for future expansion.
430 # if (BYTE_ORDER == BIG_ENDIAN)
431 sblock.fs_qbmask.val[0] = 0;
432 sblock.fs_qbmask.val[1] = ~sblock.fs_bmask;
433 sblock.fs_qfmask.val[0] = 0;
434 sblock.fs_qfmask.val[1] = ~sblock.fs_fmask;
435 # endif /* BIG_ENDIAN */
436 # if (BYTE_ORDER == LITTLE_ENDIAN)
437 sblock.fs_qbmask.val[0] = ~sblock.fs_bmask;
438 sblock.fs_qbmask.val[1] = 0;
439 sblock.fs_qfmask.val[0] = ~sblock.fs_fmask;
440 sblock.fs_qfmask.val[1] = 0;
441 # endif /* LITTLE_ENDIAN */
442 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
444 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
446 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
448 sblock.fs_clean = FSCLEAN;
452 } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) {
454 * Requested to convert from new format to old format
456 if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048
457 || sblock.fs_cpg > 32 || sblock.fs_cpc > 16) {
458 msgprintf("PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
459 msgprintf("ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n");
464 pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n");
465 else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT"))
468 sblock.fs_postblformat = FS_42POSTBLFMT;
471 sizeof(struct ocg) + howmany(sblock.fs_fpg,
473 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
475 sblock.fs_npsect = 0;
476 # ifndef AFS_SUN59_ENV
477 sblock.fs_interleave = 0;
479 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
481 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
483 sblock.fs_clean = FSCLEAN;
488 errexit("UNKNOWN FILE SYSTEM FORMAT\n");
491 #endif /* AFS_NEWCG_ENV */
493 memcpy((char *)&altsblock, (char *)&sblock, (int)sblock.fs_sbsize);
494 flush(fswritefd, &asblk);
497 * read in the summary info.
500 #if defined(AFS_SUN56_ENV)
503 sip = calloc(1, sblock.fs_cssize);
504 sblock.fs_u.fs_csp = (struct csum *)sip;
505 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
507 sblock.fs_cssize - i <
508 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
511 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
512 size) != 0 && !asked) {
513 pfatal("BAD SUMMARY INFORMATION");
514 if (reply("CONTINUE") == 0)
521 #else /* AFS_SUN56_ENV */
522 #if defined(AFS_HPUX110_ENV)
523 size = fragroundup(&sblock, sblock.fs_cssize);
524 sblock.fs_csp = (struct csum *)calloc(1, (unsigned)size);
526 (fsreadfd, (char *)sblock.fs_csp, fsbtodb(&sblock, sblock.fs_csaddr),
527 size) != 0) && !asked) {
528 pfatal("BAD SUMMARY INFORMATION");
529 if (reply("CONTINUE") == 0)
533 #else /* AFS_HPUX110_ENV */
534 #if defined(AFS_HPUX101_ENV)
537 size = fragroundup(&sblock, sblock.fs_cssize);
539 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
541 sblock.fs_cssize - i <
542 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
543 #endif /* AFS_HPUX101_ENV */
544 sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
546 (fsreadfd, (char *)sblock.fs_csp[j],
547 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
548 size) != 0 && !asked) {
549 pfatal("BAD SUMMARY INFORMATION");
550 if (reply("CONTINUE") == 0)
559 #endif /* else AFS_HPUX110_ENV */
560 #endif /* else AFS_SUN56_ENV */
562 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
564 * if not forced, preening, not converting, and is clean; stop checking
567 if ((fflag == 0) && preen && (isconvert == 0)
568 && (FSOKAY == (sblock.fs_state + sblock.fs_time)) &&
570 if (preen && (isconvert == 0)
571 && (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)) &&
573 ((sblock.fs_clean == FSCLEAN) || (sblock.fs_clean == FSSTABLE))) {
580 if (!fflag && !bflag && !nflag && !hotroot && sblock.fs_clean == FS_CLEAN
582 pwarn("Clean file system - skipping fsck\n");
585 #endif /* AFS_OSF_ENV */
588 * allocate and initialize the necessary maps
590 bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
591 blockmap = calloc((unsigned)bmapsize, sizeof(char));
592 if (blockmap == NULL) {
593 msgprintf("cannot alloc %d bytes for blockmap\n", bmapsize);
596 statemap = calloc((unsigned)(maxino + 1), sizeof(char));
597 if (statemap == NULL) {
598 msgprintf("cannot alloc %d bytes for statemap\n", maxino + 1);
601 lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
602 if (lncntp == NULL) {
603 msgprintf("cannot alloc %d bytes for lncntp\n",
604 (maxino + 1) * sizeof(short));
617 * Read in the super block and its summary info.
623 daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
624 #else /* AFS_NEWCG_ENV */
625 daddr_t super = bflag ? bflag : SBLOCK;
627 #endif /* AFS_NEWCG_ENV */
628 if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
631 sblk.b_size = SBSIZE;
633 * run a few consistency checks of the super block
636 #if defined(FD_FSMAGIC)
637 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN)
638 && (sblock.fs_magic != FD_FSMAGIC)
639 #if defined(AFS_HPUX101_ENV)
640 && (sblock.fs_magic != FD_FSMAGIC_2)
643 #else /* not new magic number */
644 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN))
645 #endif /* new magic number */
647 if (sblock.fs_magic != FS_MAGIC)
650 badsb(listerr, "MAGIC NUMBER WRONG");
653 if (sblock.fs_ncg < 1) {
654 badsb(listerr, "NCG OUT OF RANGE");
657 if (sblock.fs_cpg < 1) {
658 printf("fs_cpg= %d\n", sblock.fs_cpg);
659 badsb(listerr, "CPG OUT OF RANGE");
662 if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl
663 || (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) {
664 badsb(listerr, "NCYL LESS THAN NCG*CPG");
667 if (sblock.fs_sbsize > SBSIZE) {
668 badsb(listerr, "SIZE PREPOSTEROUSLY LARGE");
672 * Compute block size that the filesystem is based on,
673 * according to fsbtodb, and adjust superblock block number
674 * so we can tell if this is an alternate later.
677 dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
678 sblk.b_bno = super / dev_bsize;
680 * Set all possible fields that could differ, then do check
681 * of whole super block against an alternate super block.
682 * When an alternate super-block is specified this check is skipped.
684 getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
691 altsblock.fs_link = sblock.fs_link;
692 #ifdef STRUCT_FS_HAS_FS_ROLLED
693 altsblock.fs_rolled = sblock.fs_rolled;
695 altsblock.fs_rlink = sblock.fs_rlink;
697 altsblock.fs_time = sblock.fs_time;
698 altsblock.fs_cstotal = sblock.fs_cstotal;
699 altsblock.fs_cgrotor = sblock.fs_cgrotor;
700 altsblock.fs_fmod = sblock.fs_fmod;
702 altsblock.fs_clean = sblock.fs_clean;
703 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
705 altsblock.fs_state = sblock.fs_state;
707 fs_set_state(&altsblock, fs_get_state(&sblock));
710 altsblock.fs_ronly = sblock.fs_ronly;
711 altsblock.fs_flags = sblock.fs_flags;
712 altsblock.fs_maxcontig = sblock.fs_maxcontig;
713 altsblock.fs_minfree = sblock.fs_minfree;
714 altsblock.fs_optim = sblock.fs_optim;
715 altsblock.fs_rotdelay = sblock.fs_rotdelay;
716 altsblock.fs_maxbpg = sblock.fs_maxbpg;
717 #if !defined(__alpha) && !defined(AFS_SUN56_ENV)
718 #if !defined(AFS_HPUX110_ENV)
719 /* HPUX110 will use UpdateAlternateSuper() below */
720 memcpy((char *)altsblock.fs_csp, (char *)sblock.fs_csp,
721 sizeof sblock.fs_csp);
722 #endif /* ! AFS_HPUX110_ENV */
723 #endif /* ! __alpha */
724 #if defined(AFS_SUN56_ENV)
725 memcpy((char *)altsblock.fs_u.fs_csp_pad, (char *)sblock.fs_u.fs_csp_pad,
726 sizeof(sblock.fs_u.fs_csp_pad));
728 memcpy((char *)altsblock.fs_fsmnt, (char *)sblock.fs_fsmnt,
729 sizeof sblock.fs_fsmnt);
731 memcpy((char *)altsblock.fs_sparecon, (char *)sblock.fs_sparecon,
732 sizeof sblock.fs_sparecon);
734 #if defined(AFS_DEC_ENV)
735 memcpy((char *)altsblock.fs_extra, (char *)sblock.fs_extra,
736 sizeof sblock.fs_extra);
737 altsblock.fs_deftimer = sblock.fs_deftimer;
738 altsblock.fs_lastfsck = sblock.fs_lastfsck;
739 altsblock.fs_gennum = sblock.fs_gennum;
742 * The following should not have to be copied.
744 altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
746 # if defined(AFS_SUN59_ENV) && defined(FS_SI_OK)
747 /* fs_interleave replaced with fs_si and FS_SI_OK defined in */
748 /* ufs_fs.h version 2.63 don't need to compare either */
749 altsblock.fs_si = sblock.fs_si;
751 altsblock.fs_interleave = sblock.fs_interleave;
753 altsblock.fs_npsect = sblock.fs_npsect;
754 altsblock.fs_nrpos = sblock.fs_nrpos;
755 #endif /* AFS_NEWCG_ENV */
756 #if defined(AFS_HPUX110_ENV)
757 UpdateAlternateSuper(&sblock, &altsblock);
758 #endif /* AFS_HPUX110_ENV */
759 if (memcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
762 ((char *)&sblock.fs_blank[0], (char *)&altsblock.fs_blank[0],
763 MAXCSBUFS * sizeof(int))) {
764 memset((char *)sblock.fs_blank, 0, sizeof(sblock.fs_blank));
768 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
786 msgprintf("%s: ", devname);
787 pfatal("BAD SUPER BLOCK: %s\n", s);
789 pwarn("USE AN ALTERNATE SUPER-BLOCK TO SUPPLY NEEDED INFORMATION;\n");
790 pwarn("eg. fsck [-F ufs] -o b=# [special ...] \n");
791 pfatal("where # is the alternate super block. SEE fsck_ufs(1M). \n");
795 /* dummy function that fails if ever called */
796 calcsb(dev, devfd, fs)
799 register struct fs *fs;
805 clean_byte_valid(lastfsck)
812 if ((!sblock.fs_deftimer) || (!sblock.fs_lastfsck) || (lastfsck > now)) {
813 sblock.fs_deftimer = 0;
816 if (!sblock.fs_cleantimer)
818 delta = (now - lastfsck) / 86400;
825 #include <sys/ustat.h>
827 #include <sys/pstat.h>
829 #include <sys/errno.h>
833 is_mounted(device, dev_st)
837 char blockdev[BUFSIZ];
841 strcpy(blockdev, device);
842 if (stat(blockdev, dev_st) < 0)
845 if (is_pre_init(dev_st->st_rdev))
848 if ((dev_st->st_mode & S_IFMT) == S_IFCHR) {
849 dp = strrchr(blockdev, '/');
850 if (strncmp(dp, "/r", 2) != 0)
851 while (dp >= blockdev && *--dp != '/');
852 if (*(dp + 1) == 'r')
853 (void)strcpy(dp + 1, dp + 2);
854 if (stat(blockdev, dev_st) < 0)
857 if (ustat(dev_st->st_rdev, &ust) >= 0) {
858 /* make sure we are not in pre_init_rc. If we are 0 should be returned in here. */
859 if ((is_root(dev_st->st_rdev)) && is_roroot())
869 #ifdef AFS_HPUX102_ENV
870 #define PSTAT(P, N, I) pstat_getswap(P, sizeof(*P), (size_t)N, I)
872 #define PSTAT(P, N, I) pstat(PSTAT_SWAPINFO, P, sizeof(*P), (size_t)N, I)
877 struct pst_swapinfo pst[PS_BURST];
878 register struct pst_swapinfo *psp = &pst[0];
879 int idx = 0, count, match = 0;
881 while ((count = PSTAT(psp, PS_BURST, idx) != 0)) {
882 idx = pst[count - 1].pss_idx + 1;
883 if ((psp->pss_flags & SW_BLOCK) && (psp->pss_major == major(devno))
884 && (psp->pss_minor == minor(devno))) {
892 #endif /* AFS_HPUX_ENV */
905 #ifndef UID_NO_CHANGE
908 if (stat("/", &stslash) < 0)
910 if (chown("/", stslash.st_uid, stslash.st_gid) == 0)
913 if (chown("/", UID_NO_CHANGE, GID_NO_CHANGE) == 0)
916 else if (errno != EROFS) {
917 printf("fsck: chown failed: %d\n", errno);
923 is_hotroot(fs_device)
926 struct stat stslash, stblock, stchar;
927 char blockdev[BUFSIZ];
929 strcpy(blockdev, fs_device);
930 if (stat("/", &stslash) < 0) {
931 pfatal("Can't stat root\n");
935 if (stat(blockdev, &stblock) < 0) {
936 pfatal("Can't stat %s\n", blockdev);
940 if (is_pre_init(stblock.st_rdev))
943 /* convert the device name to be block device name */
944 if ((stblock.st_mode & S_IFMT) == S_IFCHR) {
946 if (stat(blockdev, &stblock) < 0)
949 if ((stblock.st_mode & S_IFMT) != S_IFBLK)
951 if (stslash.st_dev != stblock.st_rdev)
953 /* is root file system mounted read only? */
964 if (stat("/", &stslash) < 0)
966 if (stslash.st_dev != rdev_num)
971 getline(fp, loc, maxlen)
976 register char *p, *lastloc;
979 lastloc = &p[maxlen - 1];
980 while ((n = getc(fp)) != '\n') {
983 if (!isspace(n) && p < lastloc)
991 * freply - prints the string, s, gets a reply fromterminal and returns
992 * 0 - no (don't continue), and 1 - yes (continue)
1000 errexit("exiting\n");
1001 printf("\n%s? ", s);
1002 if (getline(stdin, line, sizeof(line)) == EOF)
1004 if (line[0] == 'y' || line[0] == 'Y')
1010 #if defined(AFS_HPUX110_ENV)
1012 * Refer to function compare_sblocks() in HP's fsck.c
1015 * This routine will compare the primary superblock (PRIM_SBLOCK) to the
1016 * alternate superblock (ALT_SBLOCK). This routine will take into account
1017 * that certain fields in the alternate superblock could be different than
1018 * in the primary superblock. This routine checks the "static" fields
1019 * and ignores the "dynamic" fields. Superblocks with the same "static"
1020 * fields are considered equivalent.
1023 UpdateAlternateSuper(prim_sblock, alt_sblock)
1024 struct fs *prim_sblock;
1025 struct fs *alt_sblock; /* will be modified */
1028 * Set all possible fields that could differ, then do check
1029 * of whole super block against an alternate super block.
1031 * Copy dynamic fields of prim_sblock into alt_sblock
1033 alt_sblock->fs_time = prim_sblock->fs_time;
1034 alt_sblock->fs_minfree = prim_sblock->fs_minfree;
1035 alt_sblock->fs_rotdelay = prim_sblock->fs_rotdelay;
1036 alt_sblock->fs_maxcontig = prim_sblock->fs_maxcontig;
1037 alt_sblock->fs_maxbpg = prim_sblock->fs_maxbpg;
1038 alt_sblock->fs_mirror = prim_sblock->fs_mirror;
1039 alt_sblock->fs_cstotal = prim_sblock->fs_cstotal;
1040 alt_sblock->fs_fmod = prim_sblock->fs_fmod;
1041 alt_sblock->fs_clean = prim_sblock->fs_clean;
1042 alt_sblock->fs_ronly = prim_sblock->fs_ronly;
1043 alt_sblock->fs_flags = prim_sblock->fs_flags;
1044 alt_sblock->fs_cgrotor = prim_sblock->fs_cgrotor;
1046 alt_sblock->fs_csp = prim_sblock->fs_csp;
1047 #else /* not __LP64__ */
1048 alt_sblock->fs_csp = prim_sblock->fs_csp;
1049 alt_sblock->fs_csp_pad = prim_sblock->fs_csp_pad;
1050 #endif /* not __LP64__ */
1051 memcpy((char *)alt_sblock->fs_fsmnt, (char *)prim_sblock->fs_fsmnt,
1052 sizeof prim_sblock->fs_fsmnt);
1053 memcpy((char *)alt_sblock->fs_fname, (char *)prim_sblock->fs_fname,
1054 sizeof prim_sblock->fs_fname);
1055 memcpy((char *)alt_sblock->fs_fpack, (char *)prim_sblock->fs_fpack,
1056 sizeof prim_sblock->fs_fpack);
1057 if (prim_sblock->fs_featurebits & FSF_LARGEUIDS)
1058 alt_sblock->fs_featurebits |= FSF_LARGEUIDS;
1060 alt_sblock->fs_featurebits &= ~FSF_LARGEUIDS;
1062 #endif /* AFS_HPUX110_ENV */