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.
19 static char sccsid[] = "@(#)setup.c 5.25 (Berkeley) 2/1/90";
25 #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();
114 struct disklabel *getdisklabel();
120 long cg, size, asked, i, j;
122 struct disklabel *lp;
125 #if defined(AFS_SUN5_ENV)
126 static char sname[MAXPATHLEN];
129 /* reset static variables that may have been damaged by parent fork */
136 #if defined(ACLS) && defined(AFS_HPUX_ENV)
140 if (stat("/", &statb) < 0)
141 errexit("Can't stat root\n");
142 rootdev = statb.st_dev;
143 #if defined(AFS_SUN5_ENV)
144 strncpy(sname, dev, sizeof(sname));
146 if (stat(sname, &statb) < 0) {
148 msgprintf("Can't stat %s\n", sname);
150 if (stat(dev, &statb) < 0) {
152 printf("Can't stat %s\n", dev);
157 if ((statb.st_mode & S_IFMT) == S_IFDIR) {
161 if ((fp = fopen(VFSTAB, "r")) == NULL) {
162 pfatal("Can't open %s file\n", VFSTAB);
165 while (!getvfsent(fp, &vtab)) {
166 if (vtab.vfs_mountp && !strcmp(vtab.vfs_mountp, sname)) {
167 strcpy(sname, vtab.vfs_special);
169 char *s = vtab.vfs_fsckdev;
178 if ((statb.st_mode & S_IFMT) != S_IFBLK &&
179 (statb.st_mode & S_IFMT) != S_IFCHR) {
180 pfatal("device is not a block or character device");
181 if (reply("file is not a block or character device; OK") == 0)
189 printf("%s is mounted, fsck on BLOCK device ignored\n", sname);
193 char bname[MAXPATHLEN], *tname;
195 strcpy(bname, sname);
196 tname = unrawname(bname);
197 if (stat(tname, &statb) < 0) {
198 pfatal("Can't stat %s\n", tname);
205 hotroot = is_hotroot(dev);
208 * The following code is added to improve usability of fsck.
209 * we need to give user a warning if the device being checked is
210 * a hotroot, a mounted file system, or a swap device.
212 * 1) if nflag is set, it's pretty safe to fsck the target dev
213 * 2) if the target device is a swap, exit
214 * 3) if hotroot is set, and "-F" is not specified prompt the
215 * user and wait for reply
216 * 4) if the target is a mounted file system, and "-F" is not
217 * specified, prompt the user and wait for reply
218 * 5) if the "-m" is specifed, do no prompting since only a sanity
219 * check is being done. important during booting
221 * Caveat: There is no way to tell the current run level, so we cannot
222 * tell whether or not we are in single user mode.
226 struct stat st_mounted;
230 mounted = is_mounted(dev,&st_mounted);
231 swap = is_swap(st_mounted.st_rdev);
233 if (!fflag && !mflag) {
235 msgprintf("fsck: %s: root file system",dev);
237 msgprintf(" (CONTINUING)\n");
239 if (!freply("continue (y/n)"))
242 } else if (mounted) {
243 msgprintf("fsck: %s: mounted file system",dev);
245 msgprintf(" (CONTINUING)\n");
247 if (!freply("continue (y/n)"))
251 msgprintf("fsck: %s: swap device\n",dev);
253 msgprintf(" (CONTINUING)\n");
255 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",
355 if (reply("SET TO DEFAULT") == 1) {
356 sblock.fs_minfree = 10;
362 * If '-p' is used and the partition was cleanly unmounted last time then skip the
365 if (only_when_needed && (sblock.fs_clean == FS_CLEAN) &&
366 clean_byte_valid(sblock.fs_lastfsck)) {
367 msgprintf("%s: umounted cleanly\n", dev);
373 * Do we need to continue ?
375 if (pclean && sblock.fs_clean == FS_CLEAN)
377 if (pclean && hotroot && sblock.fs_clean == FS_OK)
381 if (sblock.fs_interleave < 1) {
382 pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK",
383 sblock.fs_interleave);
384 sblock.fs_interleave = 1;
386 msgprintf(" (FIXED)\n");
387 if (preen || reply("SET TO DEFAULT") == 1) {
392 #endif /* AFS_NEWCG_ENV */
394 if (sblock.fs_npsect < sblock.fs_nsect) {
395 pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK",
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);
422 sblock.fs_rotbloff = &sblock.fs_space[0] -
423 (u_char *)(&sblock.fs_link);
425 fragroundup(&sblock, CGSIZE(&sblock));
427 * Planning now for future expansion.
429 # if (BYTE_ORDER == BIG_ENDIAN)
430 sblock.fs_qbmask.val[0] = 0;
431 sblock.fs_qbmask.val[1] = ~sblock.fs_bmask;
432 sblock.fs_qfmask.val[0] = 0;
433 sblock.fs_qfmask.val[1] = ~sblock.fs_fmask;
434 # endif /* BIG_ENDIAN */
435 # if (BYTE_ORDER == LITTLE_ENDIAN)
436 sblock.fs_qbmask.val[0] = ~sblock.fs_bmask;
437 sblock.fs_qbmask.val[1] = 0;
438 sblock.fs_qfmask.val[0] = ~sblock.fs_fmask;
439 sblock.fs_qfmask.val[1] = 0;
440 # endif /* LITTLE_ENDIAN */
441 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
443 sblock.fs_state = FSOKAY - sblock.fs_time; /* make mountable */
445 fs_set_state(&sblock, FSOKAY - sblock.fs_time);
447 sblock.fs_clean = FSCLEAN;
451 } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) {
453 * Requested to convert from new format to old format
455 if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048 ||
456 sblock.fs_cpg > 32 || sblock.fs_cpc > 16) {
458 "PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
460 "ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n"); errexit("");
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;
469 sblock.fs_cgsize = fragroundup(&sblock,
470 sizeof(struct ocg) + howmany(sblock.fs_fpg, NBBY));
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 bcopy((char *)&sblock, (char *)&altsblock,
490 (int)sblock.fs_sbsize);
491 flush(fswritefd, &asblk);
494 * read in the summary info.
497 #if defined(AFS_SUN56_ENV)
500 sip = calloc(1, sblock.fs_cssize);
501 sblock.fs_u.fs_csp = (struct csum *)sip;
502 for (i=0, j=0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
503 size = sblock.fs_cssize - i < sblock.fs_bsize ?
504 sblock.fs_cssize - i : sblock.fs_bsize;
505 if (bread(fsreadfd, sip,
506 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
507 size) != 0 && !asked) {
508 pfatal("BAD SUMMARY INFORMATION");
509 if (reply("CONTINUE") == 0)
516 #else /* AFS_SUN56_ENV */
517 #if defined(AFS_HPUX110_ENV)
518 size = fragroundup(&sblock, sblock.fs_cssize);
519 sblock.fs_csp = (struct csum *)calloc(1, (unsigned)size);
520 if ((bread(fsreadfd, (char *)sblock.fs_csp,
521 fsbtodb(&sblock, sblock.fs_csaddr), size) != 0) &&
523 pfatal("BAD SUMMARY INFORMATION");
524 if (reply("CONTINUE") == 0)
528 #else /* AFS_HPUX110_ENV */
529 #if defined(AFS_HPUX101_ENV)
532 size = fragroundup(&sblock, sblock.fs_cssize);
534 for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
535 size = sblock.fs_cssize - i < sblock.fs_bsize ?
536 sblock.fs_cssize - i : sblock.fs_bsize;
537 #endif /* AFS_HPUX101_ENV */
538 sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size);
539 if (bread(fsreadfd, (char *)sblock.fs_csp[j],
540 fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
541 size) != 0 && !asked) {
542 pfatal("BAD SUMMARY INFORMATION");
543 if (reply("CONTINUE") == 0)
552 #endif /* else AFS_HPUX110_ENV */
553 #endif /* else AFS_SUN56_ENV */
555 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
557 * if not forced, preening, not converting, and is clean; stop checking
560 if ((fflag == 0) && preen && (isconvert == 0) &&
561 (FSOKAY == (sblock.fs_state + sblock.fs_time)) &&
563 if (preen && (isconvert == 0) &&
564 (FSOKAY == (fs_get_state(&sblock) + sblock.fs_time)) &&
566 ((sblock.fs_clean == FSCLEAN) ||
567 (sblock.fs_clean == FSSTABLE)))
575 if (!fflag && !bflag && !nflag && !hotroot
576 && sblock.fs_clean == FS_CLEAN && !sblk.b_dirty) {
577 pwarn("Clean file system - skipping fsck\n");
580 #endif /* AFS_OSF_ENV */
583 * allocate and initialize the necessary maps
585 bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
586 blockmap = calloc((unsigned)bmapsize, sizeof (char));
587 if (blockmap == NULL) {
588 msgprintf("cannot alloc %d bytes for blockmap\n", bmapsize);
591 statemap = calloc((unsigned)(maxino + 1), sizeof(char));
592 if (statemap == NULL) {
593 msgprintf("cannot alloc %d bytes for statemap\n", maxino + 1);
596 lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short));
597 if (lncntp == NULL) {
598 msgprintf("cannot alloc %d bytes for lncntp\n",
599 (maxino + 1) * sizeof(short));
612 * Read in the super block and its summary info.
618 daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
619 #else /* AFS_NEWCG_ENV */
620 daddr_t super = bflag ? bflag : SBLOCK;
622 #endif /* AFS_NEWCG_ENV */
623 if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
626 sblk.b_size = SBSIZE;
628 * run a few consistency checks of the super block
631 #if defined(FD_FSMAGIC)
632 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN)
633 && (sblock.fs_magic != FD_FSMAGIC)
634 #if defined(AFS_HPUX101_ENV)
635 && ( sblock.fs_magic != FD_FSMAGIC_2)
638 #else /* not new magic number */
639 if ((sblock.fs_magic != FS_MAGIC) && (sblock.fs_magic != FS_MAGIC_LFN))
640 #endif /* new magic number */
642 if (sblock.fs_magic != FS_MAGIC)
644 { badsb(listerr, "MAGIC NUMBER WRONG"); return (0); }
645 if (sblock.fs_ncg < 1)
646 { badsb(listerr, "NCG OUT OF RANGE"); return (0); }
647 if (sblock.fs_cpg < 1)
648 { printf("fs_cpg= %d\n", sblock.fs_cpg); badsb(listerr, "CPG OUT OF RANGE"); return (0); }
649 if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl ||
650 (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl)
651 { badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); }
652 if (sblock.fs_sbsize > SBSIZE)
653 { badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); }
655 * Compute block size that the filesystem is based on,
656 * according to fsbtodb, and adjust superblock block number
657 * so we can tell if this is an alternate later.
660 dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
661 sblk.b_bno = super / dev_bsize;
663 * Set all possible fields that could differ, then do check
664 * of whole super block against an alternate super block.
665 * When an alternate super-block is specified this check is skipped.
667 getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
674 altsblock.fs_link = sblock.fs_link;
675 altsblock.fs_rlink = sblock.fs_rlink;
676 altsblock.fs_time = sblock.fs_time;
677 altsblock.fs_cstotal = sblock.fs_cstotal;
678 altsblock.fs_cgrotor = sblock.fs_cgrotor;
679 altsblock.fs_fmod = sblock.fs_fmod;
681 altsblock.fs_clean = sblock.fs_clean;
682 #if defined(AFS_SUN_ENV) && !defined(AFS_SUN3_ENV)
684 altsblock.fs_state = sblock.fs_state;
686 fs_set_state(&altsblock, fs_get_state(&sblock));
689 altsblock.fs_ronly = sblock.fs_ronly;
690 altsblock.fs_flags = sblock.fs_flags;
691 altsblock.fs_maxcontig = sblock.fs_maxcontig;
692 altsblock.fs_minfree = sblock.fs_minfree;
693 altsblock.fs_optim = sblock.fs_optim;
694 altsblock.fs_rotdelay = sblock.fs_rotdelay;
695 altsblock.fs_maxbpg = sblock.fs_maxbpg;
696 #if !defined(__alpha) && !defined(AFS_SUN56_ENV)
697 #if !defined(AFS_HPUX110_ENV)
698 /* HPUX110 will use UpdateAlternateSuper() below */
699 bcopy((char *)sblock.fs_csp, (char *)altsblock.fs_csp,
700 sizeof sblock.fs_csp);
701 #endif /* ! AFS_HPUX110_ENV */
702 #endif /* ! __alpha */
703 #if defined(AFS_SUN56_ENV)
704 bcopy((char *)sblock.fs_u.fs_csp_pad, (char *)altsblock.fs_u.fs_csp_pad,
705 sizeof (sblock.fs_u.fs_csp_pad));
707 bcopy((char *)sblock.fs_fsmnt, (char *)altsblock.fs_fsmnt,
708 sizeof sblock.fs_fsmnt);
710 bcopy((char *)sblock.fs_sparecon, (char *)altsblock.fs_sparecon,
711 sizeof sblock.fs_sparecon);
713 #if defined(AFS_DEC_ENV)
714 bcopy((char *)sblock.fs_extra, (char *)altsblock.fs_extra,
715 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 (bcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) {
734 if (bcmp((char *)&sblock.fs_blank[0],
735 (char *)&altsblock.fs_blank[0],
736 MAXCSBUFS*sizeof(int))) {
737 bzero((char *)sblock.fs_blank,
738 sizeof(sblock.fs_blank));
742 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
760 msgprintf("%s: ", devname);
761 pfatal("BAD SUPER BLOCK: %s\n", s);
763 pwarn("USE AN ALTERNATE SUPER-BLOCK TO SUPPLY NEEDED INFORMATION;\n");
764 pwarn("eg. fsck [-F ufs] -o b=# [special ...] \n");
765 pfatal("where # is the alternate super block. SEE fsck_ufs(1M). \n");
769 /* dummy function that fails if ever called */
770 calcsb(dev, devfd, fs)
773 register struct fs *fs;
779 clean_byte_valid(lastfsck)
786 if ((!sblock.fs_deftimer) || (!sblock.fs_lastfsck) || (lastfsck > now)) {
787 sblock.fs_deftimer = 0;
790 if (!sblock.fs_cleantimer)
792 delta = (now - lastfsck) / 86400;
800 #include <sys/ustat.h>
801 #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);
839 #ifdef AFS_HPUX102_ENV
840 #define PSTAT(P, N, I) pstat_getswap(P, sizeof(*P), (size_t)N, I)
842 #define PSTAT(P, N, I) pstat(PSTAT_SWAPINFO, P, sizeof(*P), (size_t)N, I)
847 struct pst_swapinfo pst[PS_BURST];
848 register struct pst_swapinfo *psp = &pst[0];
849 int idx = 0, count, match=0;
851 while ((count = PSTAT(psp, PS_BURST, idx) != 0)) {
852 idx = pst[count - 1].pss_idx + 1;
853 if ((psp->pss_flags & SW_BLOCK) && (psp->pss_major == major(devno)) && (psp->pss_minor == minor(devno))) {
871 if ( chown("/",UID_NO_CHANGE,GID_NO_CHANGE) == 0 )
873 else if (errno != EROFS ) {
874 printf ("fsck: chown failed: %d\n",errno);
880 is_hotroot(fs_device)
883 struct stat stslash, stblock, stchar;
884 char blockdev[BUFSIZ];
886 strcpy(blockdev,fs_device);
887 if (stat("/", &stslash) < 0) {
888 pfatal("Can't stat root\n");
892 if (stat(blockdev, &stblock) < 0) {
893 pfatal("Can't stat %s\n", blockdev);
897 if (is_pre_init(stblock.st_rdev))
900 /* convert the device name to be block device name */
901 if ((stblock.st_mode & S_IFMT) == S_IFCHR) {
903 if (stat(blockdev, &stblock) < 0)
906 if ((stblock.st_mode & S_IFMT) != S_IFBLK)
908 if (stslash.st_dev != stblock.st_rdev)
910 /* is root file system mounted read only? */
921 if (stat("/",&stslash) < 0)
923 if (stslash.st_dev != rdev_num)
928 getline(fp, loc, maxlen)
933 register char *p, *lastloc;
936 lastloc = &p[maxlen-1];
937 while ((n = getc(fp)) != '\n') {
940 if (!isspace(n) && p < lastloc)
948 * freply - prints the string, s, gets a reply fromterminal and returns
949 * 0 - no (don't continue), and 1 - yes (continue)
957 errexit("exiting\n");
959 if (getline(stdin, line, sizeof(line)) == EOF)
961 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 */