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();
41 #include <sys/vnode.h>
42 #include <sys/mount.h>
43 #include <ufs/inode.h>
50 #else /* AFS_OSF_ENV */
51 #ifdef AFS_VFSINCL_ENV
52 #include <sys/vnode.h>
54 #include <sys/fs/ufs_inode.h>
55 #include <sys/fs/ufs_fs.h>
57 #include <sys/fs/ufs_fsdir.h>
59 #include <sys/fs/ufs_mount.h>
61 #include <ufs/inode.h>
64 #else /* AFS_VFSINCL_ENV */
65 #include <sys/inode.h>
67 #define LONGFILENAMES 1
68 #include <sys/sysmacros.h>
72 #endif /* AFS_VFSINCL_ENV */
73 #endif /* AFS_OSF_ENV */
77 #include <sys/mntent.h>
78 #include <sys/vfstab.h>
81 #include <afs/osi_inode.h>
87 #define altsblock (*asblk.b_un.b_fs)
88 #define POWEROF2(num) (((num) & ((num) - 1)) == 0)
91 * The size of a cylinder group is calculated by CGSIZE. The maximum size
92 * is limited by the fact that cylinder groups are at most one block.
93 * Its size is derived from the size of the maps maintained in the
94 * cylinder group and the (struct cg) size.
97 /* base cg */ (sizeof(struct cg) + \
98 /* blktot size */ (fs)->fs_cpg * sizeof(afs_int32) + \
99 /* blks size */ (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(short) + \
100 /* inode map */ howmany((fs)->fs_ipg, NBBY) + \
101 /* block map */ howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY))
103 char *malloc(), *calloc();
104 struct disklabel *getdisklabel();
110 long cg, size, asked, i, j;
112 struct disklabel *lp;
115 #if defined(AFS_SUN5_ENV)
116 static char sname[MAXPATHLEN];
119 /* reset static variables that may have been damaged by parent fork */
123 #if defined(ACLS) && defined(AFS_HPUX_ENV)
127 if (stat("/", &statb) < 0)
128 errexit("Can't stat root\n");
129 rootdev = statb.st_dev;
130 #if defined(AFS_SUN5_ENV)
131 strncpy(sname, dev, sizeof(sname));
133 if (stat(sname, &statb) < 0) {
135 msgprintf("Can't stat %s\n", sname);
137 if (stat(dev, &statb) < 0) {
139 printf("Can't stat %s\n", dev);
144 if ((statb.st_mode & S_IFMT) == S_IFDIR) {
148 if ((fp = fopen(VFSTAB, "r")) == NULL) {
149 pfatal("Can't open %s file\n", VFSTAB);
152 while (!getvfsent(fp, &vtab)) {
153 if (vtab.vfs_mountp && !strcmp(vtab.vfs_mountp, sname)) {
154 strcpy(sname, vtab.vfs_special);
156 char *s = vtab.vfs_fsckdev;
165 if ((statb.st_mode & S_IFMT) != S_IFBLK
166 && (statb.st_mode & S_IFMT) != S_IFCHR) {
167 pfatal("device is not a block or character device");
168 if (reply("file is not a block or character device; OK") == 0)
176 printf("%s is mounted, fsck on BLOCK device ignored\n", sname);
180 char bname[MAXPATHLEN], *tname;
182 strcpy(bname, sname);
183 tname = unrawname(bname);
184 if (stat(tname, &statb) < 0) {
185 pfatal("Can't stat %s\n", tname);
191 hotroot = is_hotroot(dev);
194 * The following code is added to improve usability of fsck.
195 * we need to give user a warning if the device being checked is
196 * a hotroot, a mounted file system, or a swap device.
198 * 1) if nflag is set, it's pretty safe to fsck the target dev
199 * 2) if the target device is a swap, exit
200 * 3) if hotroot is set, and "-F" is not specified prompt the
201 * user and wait for reply
202 * 4) if the target is a mounted file system, and "-F" is not
203 * specified, prompt the user and wait for reply
204 * 5) if the "-m" is specifed, do no prompting since only a sanity
205 * check is being done. important during booting
207 * Caveat: There is no way to tell the current run level, so we cannot
208 * tell whether or not we are in single user mode.
212 struct stat st_mounted;
216 mounted = is_mounted(dev, &st_mounted);
218 swap = is_swap(st_mounted.st_rdev);
227 msgprintf("fsck: %s: root file system", dev);
229 msgprintf(" (CONTINUING)\n");
231 if (!freply("continue (y/n)"))
234 } else if (mounted) {
235 msgprintf("fsck: %s: mounted file system", dev);
237 msgprintf(" (CONTINUING)\n");
239 if (!freply("continue (y/n)"))
243 msgprintf("fsck: %s: swap device\n", dev);
245 msgprintf(" (CONTINUING)\n");
247 if (!freply("continue (y/n)"))
253 if (rootdev == statb.st_rdev)
255 if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
257 msgprintf("Can't open %s\n", dev);
261 msgprintf("** %s", dev);
262 if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) {
264 msgprintf(" (NO WRITE)");
267 pfatal("NO WRITE ACCESS");
273 #if defined(AFS_HPUX101_ENV)
274 setup_all_block_seek();
278 printf(" pid %d\n", getpid());
279 if (debug && (hotroot || mountedfs)) {
280 printf("** %s", sname);
282 printf(" is root fs");
287 printf(" is mounted");
296 sblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
297 asblk.b_un.b_buf = malloc(SBSIZE + ALPHA_EXT);
299 sblk.b_un.b_buf = malloc(SBSIZE);
300 asblk.b_un.b_buf = malloc(SBSIZE);
302 if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
303 errexit("cannot allocate space for superblock\n");
304 dev_bsize = secsize = DEV_BSIZE;
307 * Read in the superblock, looking for alternates if necessary
309 if (readsb(1) == 0) {
310 if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
312 if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
314 for (cg = 0; cg < proto.fs_ncg; cg++) {
315 bflag = fsbtodb(&proto, cgsblock(&proto, cg));
319 if (cg >= proto.fs_ncg) {
320 msgprintf("%s %s\n%s %s\n%s %s\n",
321 "SEARCH FOR ALTERNATE SUPER-BLOCK",
322 "FAILED. YOU MUST USE THE",
323 "-b OPTION TO FSCK TO SPECIFY THE",
324 "LOCATION OF AN ALTERNATE",
325 "SUPER-BLOCK TO SUPPLY NEEDED",
326 "INFORMATION; SEE fsck(8).");
329 pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
331 maxfsblock = sblock.fs_size;
332 maxino = sblock.fs_ncg * sblock.fs_ipg;
334 * Check and potentially fix certain fields in the super block.
336 if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) {
337 pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
338 if (reply("SET TO DEFAULT") == 1) {
339 sblock.fs_optim = FS_OPTTIME;
343 if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) {
344 pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", sblock.fs_minfree);
345 if (reply("SET TO DEFAULT") == 1) {
346 sblock.fs_minfree = 10;
352 * Do we need to continue ?
354 if (pclean && sblock.fs_clean == FS_CLEAN)
356 if (pclean && hotroot && sblock.fs_clean == FS_OK)
360 # ifndef AFS_SUN59_ENV
361 if (sblock.fs_interleave < 1) {
362 pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK", sblock.fs_interleave);
363 sblock.fs_interleave = 1;
365 msgprintf(" (FIXED)\n");
366 if (preen || reply("SET TO DEFAULT") == 1) {
371 # endif /* AFS_SUN59_ENV */
372 #endif /* AFS_NEWCG_ENV */
374 if (sblock.fs_npsect < sblock.fs_nsect) {
375 pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK", sblock.fs_npsect);
376 sblock.fs_npsect = sblock.fs_nsect;
378 msgprintf(" (FIXED)\n");
379 if (preen || reply("SET TO DEFAULT") == 1) {
384 #endif /* AFS_NEWCG_ENV */
387 if (sblock.fs_postblformat == FS_42POSTBLFMT) {
389 * Requested to convert from old format to new format
392 pwarn("CONVERTING TO NEW FILE SYSTEM FORMAT\n");
393 else if (!reply("CONVERT TO NEW FILE SYSTEM FORMAT"))
396 sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
398 sblock.fs_postbloff =
399 (char *)(&sblock.fs_opostbl[0][0]) -
400 (char *)(&sblock.fs_link);
402 &sblock.fs_space[0] - (u_char *) (&sblock.fs_link);
403 sblock.fs_cgsize = fragroundup(&sblock, CGSIZE(&sblock));
405 * Planning now for future expansion.
407 # if (BYTE_ORDER == BIG_ENDIAN)
408 sblock.fs_qbmask.val[0] = 0;
409 sblock.fs_qbmask.val[1] = ~sblock.fs_bmask;
410 sblock.fs_qfmask.val[0] = 0;
411 sblock.fs_qfmask.val[1] = ~sblock.fs_fmask;
412 # endif /* BIG_ENDIAN */
413 # if (BYTE_ORDER == LITTLE_ENDIAN)
414 sblock.fs_qbmask.val[0] = ~sblock.fs_bmask;
415 sblock.fs_qbmask.val[1] = 0;
416 sblock.fs_qfmask.val[0] = ~sblock.fs_fmask;
417 sblock.fs_qfmask.val[1] = 0;
418 # endif /* LITTLE_ENDIAN */
419 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
421 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
423 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
425 sblock.fs_clean = FSCLEAN;
429 } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) {
431 * Requested to convert from new format to old format
433 if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048
434 || sblock.fs_cpg > 32 || sblock.fs_cpc > 16) {
435 msgprintf("PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
436 msgprintf("ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n");
441 pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n");
442 else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT"))
445 sblock.fs_postblformat = FS_42POSTBLFMT;
448 sizeof(struct ocg) + howmany(sblock.fs_fpg,
450 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
452 sblock.fs_npsect = 0;
453 # ifndef AFS_SUN59_ENV
454 sblock.fs_interleave = 0;
456 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
458 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
460 sblock.fs_clean = FSCLEAN;
465 errexit("UNKNOWN FILE SYSTEM FORMAT\n");
468 #endif /* AFS_NEWCG_ENV */
470 memcpy((char *)&altsblock, (char *)&sblock, (int)sblock.fs_sbsize);
471 flush(fswritefd, &asblk);
474 * read in the summary info.
477 #if defined(AFS_SUN56_ENV)
480 sip = calloc(1, sblock.fs_cssize);
481 sblock.fs_u.fs_csp = (struct csum *)sip;
482 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
484 sblock.fs_cssize - i <
485 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
488 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
489 size) != 0 && !asked) {
490 pfatal("BAD SUMMARY INFORMATION");
491 if (reply("CONTINUE") == 0)
498 #else /* AFS_SUN56_ENV */
499 #if defined(AFS_HPUX110_ENV)
500 size = fragroundup(&sblock, sblock.fs_cssize);
501 sblock.fs_csp = (struct csum *)calloc(1, (unsigned)size);
503 (fsreadfd, (char *)sblock.fs_csp, fsbtodb(&sblock, sblock.fs_csaddr),
504 size) != 0) && !asked) {
505 pfatal("BAD SUMMARY INFORMATION");
506 if (reply("CONTINUE") == 0)
510 #else /* AFS_HPUX110_ENV */
511 #if defined(AFS_HPUX101_ENV)
514 size = fragroundup(&sblock, sblock.fs_cssize);
516 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
518 sblock.fs_cssize - i <
519 sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize;
520 #endif /* AFS_HPUX101_ENV */
521 sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
523 (fsreadfd, (char *)sblock.fs_csp[j],
524 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
525 size) != 0 && !asked) {
526 pfatal("BAD SUMMARY INFORMATION");
527 if (reply("CONTINUE") == 0)
536 #endif /* else AFS_HPUX110_ENV */
537 #endif /* else AFS_SUN56_ENV */
539 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
541 * if not forced, preening, not converting, and is clean; stop checking
544 if ((fflag == 0) && preen && (isconvert == 0)
545 && (FSOKAY == (sblock.fs_state + sblock.fs_time)) &&
547 if (preen && (isconvert == 0)
548 && (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)) &&
550 ((sblock.fs_clean == FSCLEAN) || (sblock.fs_clean == FSSTABLE))) {
557 if (!fflag && !bflag && !nflag && !hotroot && sblock.fs_clean == FS_CLEAN
559 pwarn("Clean file system - skipping fsck\n");
562 #endif /* AFS_OSF_ENV */
565 * allocate and initialize the necessary maps
567 bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
568 blockmap = calloc((unsigned)bmapsize, sizeof(char));
569 if (blockmap == NULL) {
570 msgprintf("cannot alloc %d bytes for blockmap\n", bmapsize);
573 statemap = calloc((unsigned)(maxino + 1), sizeof(char));
574 if (statemap == NULL) {
575 msgprintf("cannot alloc %d bytes for statemap\n", maxino + 1);
578 lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
579 if (lncntp == NULL) {
580 msgprintf("cannot alloc %d bytes for lncntp\n",
581 (maxino + 1) * sizeof(short));
594 * Read in the super block and its summary info.
600 daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
601 #else /* AFS_NEWCG_ENV */
602 daddr_t super = bflag ? bflag : SBLOCK;
604 #endif /* AFS_NEWCG_ENV */
605 if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
608 sblk.b_size = SBSIZE;
610 * run a few consistency checks of the super block
613 #if defined(FD_FSMAGIC)
614 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN)
615 && (sblock.fs_magic != FD_FSMAGIC)
616 #if defined(AFS_HPUX101_ENV)
617 && (sblock.fs_magic != FD_FSMAGIC_2)
620 #else /* not new magic number */
621 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN))
622 #endif /* new magic number */
624 if (sblock.fs_magic != FS_MAGIC)
627 badsb(listerr, "MAGIC NUMBER WRONG");
630 if (sblock.fs_ncg < 1) {
631 badsb(listerr, "NCG OUT OF RANGE");
634 if (sblock.fs_cpg < 1) {
635 printf("fs_cpg= %d\n", sblock.fs_cpg);
636 badsb(listerr, "CPG OUT OF RANGE");
639 if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl
640 || (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) {
641 badsb(listerr, "NCYL LESS THAN NCG*CPG");
644 if (sblock.fs_sbsize > SBSIZE) {
645 badsb(listerr, "SIZE PREPOSTEROUSLY LARGE");
649 * Compute block size that the filesystem is based on,
650 * according to fsbtodb, and adjust superblock block number
651 * so we can tell if this is an alternate later.
654 dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
655 sblk.b_bno = super / dev_bsize;
657 * Set all possible fields that could differ, then do check
658 * of whole super block against an alternate super block.
659 * When an alternate super-block is specified this check is skipped.
661 getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
668 altsblock.fs_link = sblock.fs_link;
669 #ifdef STRUCT_FS_HAS_FS_ROLLED
670 altsblock.fs_rolled = sblock.fs_rolled;
672 altsblock.fs_rlink = sblock.fs_rlink;
674 altsblock.fs_time = sblock.fs_time;
675 altsblock.fs_cstotal = sblock.fs_cstotal;
676 altsblock.fs_cgrotor = sblock.fs_cgrotor;
677 altsblock.fs_fmod = sblock.fs_fmod;
679 altsblock.fs_clean = sblock.fs_clean;
680 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
682 altsblock.fs_state = sblock.fs_state;
684 fs_set_state(&altsblock, fs_get_state(&sblock));
687 altsblock.fs_ronly = sblock.fs_ronly;
688 altsblock.fs_flags = sblock.fs_flags;
689 altsblock.fs_maxcontig = sblock.fs_maxcontig;
690 altsblock.fs_minfree = sblock.fs_minfree;
691 altsblock.fs_optim = sblock.fs_optim;
692 altsblock.fs_rotdelay = sblock.fs_rotdelay;
693 altsblock.fs_maxbpg = sblock.fs_maxbpg;
694 #if !defined(__alpha) && !defined(AFS_SUN56_ENV)
695 #if !defined(AFS_HPUX110_ENV)
696 /* HPUX110 will use UpdateAlternateSuper() below */
697 memcpy((char *)altsblock.fs_csp, (char *)sblock.fs_csp,
698 sizeof sblock.fs_csp);
699 #endif /* ! AFS_HPUX110_ENV */
700 #endif /* ! __alpha */
701 #if defined(AFS_SUN56_ENV)
702 memcpy((char *)altsblock.fs_u.fs_csp_pad, (char *)sblock.fs_u.fs_csp_pad,
703 sizeof(sblock.fs_u.fs_csp_pad));
705 memcpy((char *)altsblock.fs_fsmnt, (char *)sblock.fs_fsmnt,
706 sizeof sblock.fs_fsmnt);
708 memcpy((char *)altsblock.fs_sparecon, (char *)sblock.fs_sparecon,
709 sizeof sblock.fs_sparecon);
712 * The following should not have to be copied.
714 altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
716 # if defined(AFS_SUN59_ENV) && defined(FS_SI_OK)
717 /* fs_interleave replaced with fs_si and FS_SI_OK defined in */
718 /* ufs_fs.h version 2.63 don't need to compare either */
719 altsblock.fs_si = sblock.fs_si;
721 altsblock.fs_interleave = sblock.fs_interleave;
723 altsblock.fs_npsect = sblock.fs_npsect;
724 altsblock.fs_nrpos = sblock.fs_nrpos;
725 #endif /* AFS_NEWCG_ENV */
726 #if defined(AFS_HPUX110_ENV)
727 UpdateAlternateSuper(&sblock, &altsblock);
728 #endif /* AFS_HPUX110_ENV */
729 if (memcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
732 ((char *)&sblock.fs_blank[0], (char *)&altsblock.fs_blank[0],
733 MAXCSBUFS * sizeof(int))) {
734 memset(sblock.fs_blank, 0, sizeof(sblock.fs_blank));
738 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
756 msgprintf("%s: ", devname);
757 pfatal("BAD SUPER BLOCK: %s\n", s);
759 pwarn("USE AN ALTERNATE SUPER-BLOCK TO SUPPLY NEEDED INFORMATION;\n");
760 pwarn("eg. fsck [-F ufs] -o b=# [special ...] \n");
761 pfatal("where # is the alternate super block. SEE fsck_ufs(1M). \n");
765 /* dummy function that fails if ever called */
766 calcsb(dev, devfd, fs)
774 #include <sys/ustat.h>
776 #include <sys/pstat.h>
778 #include <sys/errno.h>
782 is_mounted(device, dev_st)
786 char blockdev[BUFSIZ];
790 strcpy(blockdev, device);
791 if (stat(blockdev, dev_st) < 0)
794 if (is_pre_init(dev_st->st_rdev))
797 if ((dev_st->st_mode & S_IFMT) == S_IFCHR) {
798 dp = strrchr(blockdev, '/');
799 if (strncmp(dp, "/r", 2) != 0)
800 while (dp >= blockdev && *--dp != '/');
801 if (*(dp + 1) == 'r')
802 (void)strcpy(dp + 1, dp + 2);
803 if (stat(blockdev, dev_st) < 0)
806 if (ustat(dev_st->st_rdev, &ust) >= 0) {
807 /* make sure we are not in pre_init_rc. If we are 0 should be returned in here. */
808 if ((is_root(dev_st->st_rdev)) && is_roroot())
818 #ifdef AFS_HPUX102_ENV
819 #define PSTAT(P, N, I) pstat_getswap(P, sizeof(*P), (size_t)N, I)
821 #define PSTAT(P, N, I) pstat(PSTAT_SWAPINFO, P, sizeof(*P), (size_t)N, I)
826 struct pst_swapinfo pst[PS_BURST];
827 struct pst_swapinfo *psp = &pst[0];
828 int idx = 0, count, match = 0;
830 while ((count = PSTAT(psp, PS_BURST, idx) != 0)) {
831 idx = pst[count - 1].pss_idx + 1;
832 if ((psp->pss_flags & SW_BLOCK) && (psp->pss_major == major(devno))
833 && (psp->pss_minor == minor(devno))) {
841 #endif /* AFS_HPUX_ENV */
854 #ifndef UID_NO_CHANGE
857 if (stat("/", &stslash) < 0)
859 if (chown("/", stslash.st_uid, stslash.st_gid) == 0)
862 if (chown("/", UID_NO_CHANGE, GID_NO_CHANGE) == 0)
865 else if (errno != EROFS) {
866 printf("fsck: chown failed: %d\n", errno);
872 is_hotroot(fs_device)
875 struct stat stslash, stblock, stchar;
876 char blockdev[BUFSIZ];
878 strcpy(blockdev, fs_device);
879 if (stat("/", &stslash) < 0) {
880 pfatal("Can't stat root\n");
884 if (stat(blockdev, &stblock) < 0) {
885 pfatal("Can't stat %s\n", blockdev);
889 if (is_pre_init(stblock.st_rdev))
892 /* convert the device name to be block device name */
893 if ((stblock.st_mode & S_IFMT) == S_IFCHR) {
895 if (stat(blockdev, &stblock) < 0)
898 if ((stblock.st_mode & S_IFMT) != S_IFBLK)
900 if (stslash.st_dev != stblock.st_rdev)
902 /* is root file system mounted read only? */
913 if (stat("/", &stslash) < 0)
915 if (stslash.st_dev != rdev_num)
920 getline(fp, loc, maxlen)
928 lastloc = &p[maxlen - 1];
929 while ((n = getc(fp)) != '\n') {
932 if (!isspace(n) && p < lastloc)
940 * freply - prints the string, s, gets a reply fromterminal and returns
941 * 0 - no (don't continue), and 1 - yes (continue)
949 errexit("exiting\n");
951 if (getline(stdin, line, sizeof(line)) == EOF)
953 if (line[0] == 'y' || line[0] == 'Y')
959 #if defined(AFS_HPUX110_ENV)
961 * Refer to function compare_sblocks() in HP's fsck.c
964 * This routine will compare the primary superblock (PRIM_SBLOCK) to the
965 * alternate superblock (ALT_SBLOCK). This routine will take into account
966 * that certain fields in the alternate superblock could be different than
967 * in the primary superblock. This routine checks the "static" fields
968 * and ignores the "dynamic" fields. Superblocks with the same "static"
969 * fields are considered equivalent.
972 UpdateAlternateSuper(prim_sblock, alt_sblock)
973 struct fs *prim_sblock;
974 struct fs *alt_sblock; /* will be modified */
977 * Set all possible fields that could differ, then do check
978 * of whole super block against an alternate super block.
980 * Copy dynamic fields of prim_sblock into alt_sblock
982 alt_sblock->fs_time = prim_sblock->fs_time;
983 alt_sblock->fs_minfree = prim_sblock->fs_minfree;
984 alt_sblock->fs_rotdelay = prim_sblock->fs_rotdelay;
985 alt_sblock->fs_maxcontig = prim_sblock->fs_maxcontig;
986 alt_sblock->fs_maxbpg = prim_sblock->fs_maxbpg;
987 alt_sblock->fs_mirror = prim_sblock->fs_mirror;
988 alt_sblock->fs_cstotal = prim_sblock->fs_cstotal;
989 alt_sblock->fs_fmod = prim_sblock->fs_fmod;
990 alt_sblock->fs_clean = prim_sblock->fs_clean;
991 alt_sblock->fs_ronly = prim_sblock->fs_ronly;
992 alt_sblock->fs_flags = prim_sblock->fs_flags;
993 alt_sblock->fs_cgrotor = prim_sblock->fs_cgrotor;
995 alt_sblock->fs_csp = prim_sblock->fs_csp;
996 #else /* not __LP64__ */
997 alt_sblock->fs_csp = prim_sblock->fs_csp;
998 alt_sblock->fs_csp_pad = prim_sblock->fs_csp_pad;
999 #endif /* not __LP64__ */
1000 memcpy((char *)alt_sblock->fs_fsmnt, (char *)prim_sblock->fs_fsmnt,
1001 sizeof prim_sblock->fs_fsmnt);
1002 memcpy((char *)alt_sblock->fs_fname, (char *)prim_sblock->fs_fname,
1003 sizeof prim_sblock->fs_fname);
1004 memcpy((char *)alt_sblock->fs_fpack, (char *)prim_sblock->fs_fpack,
1005 sizeof prim_sblock->fs_fpack);
1006 if (prim_sblock->fs_featurebits & FSF_LARGEUIDS)
1007 alt_sblock->fs_featurebits |= FSF_LARGEUIDS;
1009 alt_sblock->fs_featurebits &= ~FSF_LARGEUIDS;
1011 #endif /* AFS_HPUX110_ENV */