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 if (sblock.fs_interleave < 1) {
384 pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK", sblock.fs_interleave);
385 sblock.fs_interleave = 1;
387 msgprintf(" (FIXED)\n");
388 if (preen || reply("SET TO DEFAULT") == 1) {
393 #endif /* AFS_NEWCG_ENV */
395 if (sblock.fs_npsect < sblock.fs_nsect) {
396 pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK", sblock.fs_npsect);
397 sblock.fs_npsect = sblock.fs_nsect;
399 msgprintf(" (FIXED)\n");
400 if (preen || reply("SET TO DEFAULT") == 1) {
405 #endif /* AFS_NEWCG_ENV */
408 if (sblock.fs_postblformat == FS_42POSTBLFMT) {
410 * Requested to convert from old format to new format
413 pwarn("CONVERTING TO NEW FILE SYSTEM FORMAT\n");
414 else if (!reply("CONVERT TO NEW FILE SYSTEM FORMAT"))
417 sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
419 sblock.fs_postbloff =
420 (char *)(&sblock.fs_opostbl[0][0]) -
421 (char *)(&sblock.fs_link);
423 &sblock.fs_space[0] - (u_char *) (&sblock.fs_link);
424 sblock.fs_cgsize = fragroundup(&sblock, CGSIZE(&sblock));
426 * Planning now for future expansion.
428 # if (BYTE_ORDER == BIG_ENDIAN)
429 sblock.fs_qbmask.val[0] = 0;
430 sblock.fs_qbmask.val[1] = ~sblock.fs_bmask;
431 sblock.fs_qfmask.val[0] = 0;
432 sblock.fs_qfmask.val[1] = ~sblock.fs_fmask;
433 # endif /* BIG_ENDIAN */
434 # if (BYTE_ORDER == LITTLE_ENDIAN)
435 sblock.fs_qbmask.val[0] = ~sblock.fs_bmask;
436 sblock.fs_qbmask.val[1] = 0;
437 sblock.fs_qfmask.val[0] = ~sblock.fs_fmask;
438 sblock.fs_qfmask.val[1] = 0;
439 # endif /* LITTLE_ENDIAN */
440 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
442 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
444 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
446 sblock.fs_clean = FSCLEAN;
450 } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) {
452 * Requested to convert from new format to old format
454 if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048
455 || sblock.fs_cpg > 32 || sblock.fs_cpc > 16) {
456 msgprintf("PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
457 msgprintf("ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n");
462 pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n");
463 else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT"))
466 sblock.fs_postblformat = FS_42POSTBLFMT;
469 sizeof(struct ocg) + howmany(sblock.fs_fpg,
471 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
473 sblock.fs_npsect = 0;
474 sblock.fs_interleave = 0;
475 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
477 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
479 sblock.fs_clean = FSCLEAN;
484 errexit("UNKNOWN FILE SYSTEM FORMAT\n");
487 #endif /* AFS_NEWCG_ENV */
489 memcpy((char *)&altsblock, (char *)&sblock, (int)sblock.fs_sbsize);
490 flush(fswritefd, &asblk);
493 * read in the summary info.
496 #if defined(AFS_SUN56_ENV)
499 sip = calloc(1, sblock.fs_cssize);
500 sblock.fs_u.fs_csp = (struct csum *)sip;
501 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
503 sblock.fs_cssize - i <
504 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
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);
522 (fsreadfd, (char *)sblock.fs_csp, fsbtodb(&sblock, sblock.fs_csaddr),
523 size) != 0) && !asked) {
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++) {
537 sblock.fs_cssize - i <
538 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
539 #endif /* AFS_HPUX101_ENV */
540 sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
542 (fsreadfd, (char *)sblock.fs_csp[j],
543 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
544 size) != 0 && !asked) {
545 pfatal("BAD SUMMARY INFORMATION");
546 if (reply("CONTINUE") == 0)
555 #endif /* else AFS_HPUX110_ENV */
556 #endif /* else AFS_SUN56_ENV */
558 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
560 * if not forced, preening, not converting, and is clean; stop checking
563 if ((fflag == 0) && preen && (isconvert == 0)
564 && (FSOKAY == (sblock.fs_state + sblock.fs_time)) &&
566 if (preen && (isconvert == 0)
567 && (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)) &&
569 ((sblock.fs_clean == FSCLEAN) || (sblock.fs_clean == FSSTABLE))) {
576 if (!fflag && !bflag && !nflag && !hotroot && sblock.fs_clean == FS_CLEAN
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)
646 badsb(listerr, "MAGIC NUMBER WRONG");
649 if (sblock.fs_ncg < 1) {
650 badsb(listerr, "NCG OUT OF RANGE");
653 if (sblock.fs_cpg < 1) {
654 printf("fs_cpg= %d\n", sblock.fs_cpg);
655 badsb(listerr, "CPG OUT OF RANGE");
658 if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl
659 || (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) {
660 badsb(listerr, "NCYL LESS THAN NCG*CPG");
663 if (sblock.fs_sbsize > SBSIZE) {
664 badsb(listerr, "SIZE PREPOSTEROUSLY LARGE");
668 * Compute block size that the filesystem is based on,
669 * according to fsbtodb, and adjust superblock block number
670 * so we can tell if this is an alternate later.
673 dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
674 sblk.b_bno = super / dev_bsize;
676 * Set all possible fields that could differ, then do check
677 * of whole super block against an alternate super block.
678 * When an alternate super-block is specified this check is skipped.
680 getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
687 altsblock.fs_link = sblock.fs_link;
688 #ifdef STRUCT_FS_HAS_FS_ROLLED
689 altsblock.fs_rolled = sblock.fs_rolled;
691 altsblock.fs_rlink = sblock.fs_rlink;
693 altsblock.fs_time = sblock.fs_time;
694 altsblock.fs_cstotal = sblock.fs_cstotal;
695 altsblock.fs_cgrotor = sblock.fs_cgrotor;
696 altsblock.fs_fmod = sblock.fs_fmod;
698 altsblock.fs_clean = sblock.fs_clean;
699 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
701 altsblock.fs_state = sblock.fs_state;
703 fs_set_state(&altsblock, fs_get_state(&sblock));
706 altsblock.fs_ronly = sblock.fs_ronly;
707 altsblock.fs_flags = sblock.fs_flags;
708 altsblock.fs_maxcontig = sblock.fs_maxcontig;
709 altsblock.fs_minfree = sblock.fs_minfree;
710 altsblock.fs_optim = sblock.fs_optim;
711 altsblock.fs_rotdelay = sblock.fs_rotdelay;
712 altsblock.fs_maxbpg = sblock.fs_maxbpg;
713 #if !defined(__alpha) && !defined(AFS_SUN56_ENV)
714 #if !defined(AFS_HPUX110_ENV)
715 /* HPUX110 will use UpdateAlternateSuper() below */
716 memcpy((char *)altsblock.fs_csp, (char *)sblock.fs_csp,
717 sizeof sblock.fs_csp);
718 #endif /* ! AFS_HPUX110_ENV */
719 #endif /* ! __alpha */
720 #if defined(AFS_SUN56_ENV)
721 memcpy((char *)altsblock.fs_u.fs_csp_pad, (char *)sblock.fs_u.fs_csp_pad,
722 sizeof(sblock.fs_u.fs_csp_pad));
724 memcpy((char *)altsblock.fs_fsmnt, (char *)sblock.fs_fsmnt,
725 sizeof sblock.fs_fsmnt);
727 memcpy((char *)altsblock.fs_sparecon, (char *)sblock.fs_sparecon,
728 sizeof sblock.fs_sparecon);
730 #if defined(AFS_DEC_ENV)
731 memcpy((char *)altsblock.fs_extra, (char *)sblock.fs_extra,
732 sizeof sblock.fs_extra);
733 altsblock.fs_deftimer = sblock.fs_deftimer;
734 altsblock.fs_lastfsck = sblock.fs_lastfsck;
735 altsblock.fs_gennum = sblock.fs_gennum;
738 * The following should not have to be copied.
740 altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
742 altsblock.fs_interleave = sblock.fs_interleave;
743 altsblock.fs_npsect = sblock.fs_npsect;
744 altsblock.fs_nrpos = sblock.fs_nrpos;
745 #endif /* AFS_NEWCG_ENV */
746 #if defined(AFS_HPUX110_ENV)
747 UpdateAlternateSuper(&sblock, &altsblock);
748 #endif /* AFS_HPUX110_ENV */
749 if (memcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
752 ((char *)&sblock.fs_blank[0], (char *)&altsblock.fs_blank[0],
753 MAXCSBUFS * sizeof(int))) {
754 memset((char *)sblock.fs_blank, 0, sizeof(sblock.fs_blank));
758 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
776 msgprintf("%s: ", devname);
777 pfatal("BAD SUPER BLOCK: %s\n", s);
779 pwarn("USE AN ALTERNATE SUPER-BLOCK TO SUPPLY NEEDED INFORMATION;\n");
780 pwarn("eg. fsck [-F ufs] -o b=# [special ...] \n");
781 pfatal("where # is the alternate super block. SEE fsck_ufs(1M). \n");
785 /* dummy function that fails if ever called */
786 calcsb(dev, devfd, fs)
789 register struct fs *fs;
795 clean_byte_valid(lastfsck)
802 if ((!sblock.fs_deftimer) || (!sblock.fs_lastfsck) || (lastfsck > now)) {
803 sblock.fs_deftimer = 0;
806 if (!sblock.fs_cleantimer)
808 delta = (now - lastfsck) / 86400;
815 #include <sys/ustat.h>
817 #include <sys/pstat.h>
819 #include <sys/errno.h>
823 is_mounted(device, dev_st)
827 char blockdev[BUFSIZ];
831 strcpy(blockdev, device);
832 if (stat(blockdev, dev_st) < 0)
835 if (is_pre_init(dev_st->st_rdev))
838 if ((dev_st->st_mode & S_IFMT) == S_IFCHR) {
839 dp = strrchr(blockdev, '/');
840 if (strncmp(dp, "/r", 2) != 0)
841 while (dp >= blockdev && *--dp != '/');
842 if (*(dp + 1) == 'r')
843 (void)strcpy(dp + 1, dp + 2);
844 if (stat(blockdev, dev_st) < 0)
847 if (ustat(dev_st->st_rdev, &ust) >= 0) {
848 /* make sure we are not in pre_init_rc. If we are 0 should be returned in here. */
849 if ((is_root(dev_st->st_rdev)) && is_roroot())
859 #ifdef AFS_HPUX102_ENV
860 #define PSTAT(P, N, I) pstat_getswap(P, sizeof(*P), (size_t)N, I)
862 #define PSTAT(P, N, I) pstat(PSTAT_SWAPINFO, P, sizeof(*P), (size_t)N, I)
867 struct pst_swapinfo pst[PS_BURST];
868 register struct pst_swapinfo *psp = &pst[0];
869 int idx = 0, count, match = 0;
871 while ((count = PSTAT(psp, PS_BURST, idx) != 0)) {
872 idx = pst[count - 1].pss_idx + 1;
873 if ((psp->pss_flags & SW_BLOCK) && (psp->pss_major == major(devno))
874 && (psp->pss_minor == minor(devno))) {
882 #endif /* AFS_HPUX_ENV */
895 #ifndef UID_NO_CHANGE
898 if (stat("/", &stslash) < 0)
900 if (chown("/", stslash.st_uid, stslash.st_gid) == 0)
903 if (chown("/", UID_NO_CHANGE, GID_NO_CHANGE) == 0)
906 else if (errno != EROFS) {
907 printf("fsck: chown failed: %d\n", errno);
913 is_hotroot(fs_device)
916 struct stat stslash, stblock, stchar;
917 char blockdev[BUFSIZ];
919 strcpy(blockdev, fs_device);
920 if (stat("/", &stslash) < 0) {
921 pfatal("Can't stat root\n");
925 if (stat(blockdev, &stblock) < 0) {
926 pfatal("Can't stat %s\n", blockdev);
930 if (is_pre_init(stblock.st_rdev))
933 /* convert the device name to be block device name */
934 if ((stblock.st_mode & S_IFMT) == S_IFCHR) {
936 if (stat(blockdev, &stblock) < 0)
939 if ((stblock.st_mode & S_IFMT) != S_IFBLK)
941 if (stslash.st_dev != stblock.st_rdev)
943 /* is root file system mounted read only? */
954 if (stat("/", &stslash) < 0)
956 if (stslash.st_dev != rdev_num)
961 getline(fp, loc, maxlen)
966 register char *p, *lastloc;
969 lastloc = &p[maxlen - 1];
970 while ((n = getc(fp)) != '\n') {
973 if (!isspace(n) && p < lastloc)
981 * freply - prints the string, s, gets a reply fromterminal and returns
982 * 0 - no (don't continue), and 1 - yes (continue)
990 errexit("exiting\n");
992 if (getline(stdin, line, sizeof(line)) == EOF)
994 if (line[0] == 'y' || line[0] == 'Y')
1000 #if defined(AFS_HPUX110_ENV)
1002 * Refer to function compare_sblocks() in HP's fsck.c
1005 * This routine will compare the primary superblock (PRIM_SBLOCK) to the
1006 * alternate superblock (ALT_SBLOCK). This routine will take into account
1007 * that certain fields in the alternate superblock could be different than
1008 * in the primary superblock. This routine checks the "static" fields
1009 * and ignores the "dynamic" fields. Superblocks with the same "static"
1010 * fields are considered equivalent.
1013 UpdateAlternateSuper(prim_sblock, alt_sblock)
1014 struct fs *prim_sblock;
1015 struct fs *alt_sblock; /* will be modified */
1018 * Set all possible fields that could differ, then do check
1019 * of whole super block against an alternate super block.
1021 * Copy dynamic fields of prim_sblock into alt_sblock
1023 alt_sblock->fs_time = prim_sblock->fs_time;
1024 alt_sblock->fs_minfree = prim_sblock->fs_minfree;
1025 alt_sblock->fs_rotdelay = prim_sblock->fs_rotdelay;
1026 alt_sblock->fs_maxcontig = prim_sblock->fs_maxcontig;
1027 alt_sblock->fs_maxbpg = prim_sblock->fs_maxbpg;
1028 alt_sblock->fs_mirror = prim_sblock->fs_mirror;
1029 alt_sblock->fs_cstotal = prim_sblock->fs_cstotal;
1030 alt_sblock->fs_fmod = prim_sblock->fs_fmod;
1031 alt_sblock->fs_clean = prim_sblock->fs_clean;
1032 alt_sblock->fs_ronly = prim_sblock->fs_ronly;
1033 alt_sblock->fs_flags = prim_sblock->fs_flags;
1034 alt_sblock->fs_cgrotor = prim_sblock->fs_cgrotor;
1036 alt_sblock->fs_csp = prim_sblock->fs_csp;
1037 #else /* not __LP64__ */
1038 alt_sblock->fs_csp = prim_sblock->fs_csp;
1039 alt_sblock->fs_csp_pad = prim_sblock->fs_csp_pad;
1040 #endif /* not __LP64__ */
1041 memcpy((char *)alt_sblock->fs_fsmnt, (char *)prim_sblock->fs_fsmnt,
1042 sizeof prim_sblock->fs_fsmnt);
1043 memcpy((char *)alt_sblock->fs_fname, (char *)prim_sblock->fs_fname,
1044 sizeof prim_sblock->fs_fname);
1045 memcpy((char *)alt_sblock->fs_fpack, (char *)prim_sblock->fs_fpack,
1046 sizeof prim_sblock->fs_fpack);
1047 if (prim_sblock->fs_featurebits & FSF_LARGEUIDS)
1048 alt_sblock->fs_featurebits |= FSF_LARGEUIDS;
1050 alt_sblock->fs_featurebits &= ~FSF_LARGEUIDS;
1052 #endif /* AFS_HPUX110_ENV */