xref: /illumos-gate/usr/src/cmd/fs.d/udfs/fsck/pass1.c (revision eee96f10)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7bfbf29e2SToomas Soome /*	  All Rights Reserved	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
147c478bd9Sstevel@tonic-gate  * provided that: (1) source distributions retain this entire copyright
157c478bd9Sstevel@tonic-gate  * notice and comment, and (2) distributions including binaries display
167c478bd9Sstevel@tonic-gate  * the following acknowledgement:  ``This product includes software
177c478bd9Sstevel@tonic-gate  * developed by the University of California, Berkeley and its contributors''
187c478bd9Sstevel@tonic-gate  * in the documentation or other materials provided with the distribution
197c478bd9Sstevel@tonic-gate  * and in all advertising materials mentioning features or use of this
207c478bd9Sstevel@tonic-gate  * software. Neither the name of the University nor the names of its
217c478bd9Sstevel@tonic-gate  * contributors may be used to endorse or promote products derived
227c478bd9Sstevel@tonic-gate  * from this software without specific prior written permission.
237c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
247c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
257c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <stdio.h>
297c478bd9Sstevel@tonic-gate #include <strings.h>
307c478bd9Sstevel@tonic-gate #include <malloc.h>
317c478bd9Sstevel@tonic-gate #include <sys/param.h>
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
347c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
357c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
367c478bd9Sstevel@tonic-gate #include <sys/fs/udf_volume.h>
377c478bd9Sstevel@tonic-gate #include <sys/dkio.h>
387c478bd9Sstevel@tonic-gate #include <sys/vtoc.h>
397c478bd9Sstevel@tonic-gate #include "fsck.h"
407c478bd9Sstevel@tonic-gate #include "udfs.h"
417c478bd9Sstevel@tonic-gate #include <locale.h>
427c478bd9Sstevel@tonic-gate 
43bfbf29e2SToomas Soome uint64_t maxuniqid;	/* maximum unique id on medium */
44bfbf29e2SToomas Soome 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * for each large file ( size > MAXOFF_T) this global counter
477c478bd9Sstevel@tonic-gate  * gets incremented here.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate extern unsigned int largefile_count;
517c478bd9Sstevel@tonic-gate extern void	pwarn(char *, ...);
527c478bd9Sstevel@tonic-gate extern void	pfatal(char *, ...);
537c478bd9Sstevel@tonic-gate extern void	errexit(char *, ...);
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate extern int32_t	verifytag(struct tag *, uint32_t, struct tag *, int);
567c478bd9Sstevel@tonic-gate extern char	*tagerrs[];
577c478bd9Sstevel@tonic-gate extern void	maketag(struct tag *, struct tag *);
587c478bd9Sstevel@tonic-gate extern void	flush(int32_t, struct bufarea *);
597c478bd9Sstevel@tonic-gate extern void	putfilentry(struct bufarea *);
607c478bd9Sstevel@tonic-gate extern int32_t	bread(int32_t, char *, daddr_t, long);
617c478bd9Sstevel@tonic-gate extern void	bwrite(int, char *, daddr_t, long);
627c478bd9Sstevel@tonic-gate extern int32_t	dofix(struct inodesc *, char *);
637c478bd9Sstevel@tonic-gate extern int32_t	reply(char *);
647c478bd9Sstevel@tonic-gate extern void	ud_swap_short_ad(short_ad_t *);
657c478bd9Sstevel@tonic-gate extern void	ud_swap_long_ad(long_ad_t *);
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate extern void	dump16(char *, char *);
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate static void	adjust(struct fileinfo *);
707c478bd9Sstevel@tonic-gate static void	opndir(struct file_entry *);
717c478bd9Sstevel@tonic-gate static int32_t	getdir(struct file_entry *, struct bufarea **,
727c478bd9Sstevel@tonic-gate 	u_offset_t *, struct file_id **);
737c478bd9Sstevel@tonic-gate static void ckinode(struct file_entry *);
747c478bd9Sstevel@tonic-gate struct bufarea *getfilentry();
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /* Fields for traversing an allocation extent */
777c478bd9Sstevel@tonic-gate static uint32_t dir_adrsize;
787c478bd9Sstevel@tonic-gate static uint32_t dir_adrindx;
797c478bd9Sstevel@tonic-gate static uint32_t dir_naddrs;
807c478bd9Sstevel@tonic-gate static uint8_t *extbuf;
817c478bd9Sstevel@tonic-gate static uint8_t *dir_adrlist;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /* Keep track of where we are in the directory */
847c478bd9Sstevel@tonic-gate static u_offset_t dir_baseoff;
857c478bd9Sstevel@tonic-gate static uint32_t dir_basesize;
867c478bd9Sstevel@tonic-gate static uint8_t *dirbuf;
877c478bd9Sstevel@tonic-gate static uint8_t *dir_fidp;
887c478bd9Sstevel@tonic-gate static uint32_t baseblock;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	MAXFIDSIZE 2048
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate static uint8_t fidbuf[MAXFIDSIZE];
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate void
pass1(void)95*eee96f10SToomas Soome pass1(void)
967c478bd9Sstevel@tonic-gate {
97*eee96f10SToomas Soome 	struct file_entry *fp;
98*eee96f10SToomas Soome 	struct fileinfo *fip;
99*eee96f10SToomas Soome 	struct bufarea *bp;
1007c478bd9Sstevel@tonic-gate 	struct file_id *fidp;
1017c478bd9Sstevel@tonic-gate 	struct bufarea *fbp;
1027c478bd9Sstevel@tonic-gate 	int err;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	(void) cachefile(rootblock, rootlen);
1057c478bd9Sstevel@tonic-gate 	fip = &inphead[0];		/* The root */
1067c478bd9Sstevel@tonic-gate 	fip->fe_lseen = 0;		/* Didn't get here through directory */
1077c478bd9Sstevel@tonic-gate 	n_files = n_dirs = 0;
1087c478bd9Sstevel@tonic-gate 	while (fip->fe_block) {
1097c478bd9Sstevel@tonic-gate 		u_offset_t offset, end;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 		markbusy(fip->fe_block, fip->fe_len);
1127c478bd9Sstevel@tonic-gate 		bp = getfilentry(fip->fe_block, fip->fe_len);
1137c478bd9Sstevel@tonic-gate 		if (bp == NULL) {
1147c478bd9Sstevel@tonic-gate 			pwarn(gettext("Unable to read file entry at %x\n"),
1157c478bd9Sstevel@tonic-gate 				fip->fe_block);
1167c478bd9Sstevel@tonic-gate 			goto next;
1177c478bd9Sstevel@tonic-gate 		}
1187c478bd9Sstevel@tonic-gate 		fp = (struct file_entry *)bp->b_un.b_buf;
1197c478bd9Sstevel@tonic-gate 		fip->fe_lcount = fp->fe_lcount;
1207c478bd9Sstevel@tonic-gate 		fip->fe_type = fp->fe_icb_tag.itag_ftype;
1217c478bd9Sstevel@tonic-gate 		if (fp->fe_uniq_id >= maxuniqid)
1227c478bd9Sstevel@tonic-gate 			maxuniqid = fp->fe_uniq_id + 1;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 		if (fip->fe_block == rootblock &&
1257c478bd9Sstevel@tonic-gate 				fip->fe_type != FTYPE_DIRECTORY)
1267c478bd9Sstevel@tonic-gate 			errexit(gettext("Root file entry is not a "
1277c478bd9Sstevel@tonic-gate 				"directory\n"));
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 		if (debug) {
1307c478bd9Sstevel@tonic-gate 			(void) printf("do %x len %d type %d lcount %d"
1317c478bd9Sstevel@tonic-gate 				" lseen %d end %llx\n",
1327c478bd9Sstevel@tonic-gate 				fip->fe_block, fip->fe_len,
1337c478bd9Sstevel@tonic-gate 				fip->fe_type, fip->fe_lcount,
1347c478bd9Sstevel@tonic-gate 				fip->fe_lseen, fp->fe_info_len);
1357c478bd9Sstevel@tonic-gate 		}
1367c478bd9Sstevel@tonic-gate 		switch (fip->fe_type) {
1377c478bd9Sstevel@tonic-gate 		case FTYPE_DIRECTORY:
1387c478bd9Sstevel@tonic-gate 			n_dirs++;
1397c478bd9Sstevel@tonic-gate 			offset = 0;
1407c478bd9Sstevel@tonic-gate 			end = fp->fe_info_len;
1417c478bd9Sstevel@tonic-gate 			fbp = NULL;
1427c478bd9Sstevel@tonic-gate 			opndir(fp);
1437c478bd9Sstevel@tonic-gate 			for (offset = 0; offset < end;
1447c478bd9Sstevel@tonic-gate 					offset += FID_LENGTH(fidp)) {
1457c478bd9Sstevel@tonic-gate 				err = getdir(fp, &fbp, &offset, &fidp);
1467c478bd9Sstevel@tonic-gate 				if (err) {
1477c478bd9Sstevel@tonic-gate 					pwarn(gettext("Bad directory entry in "
1487c478bd9Sstevel@tonic-gate 						"file %x at offset %llx\n"),
1497c478bd9Sstevel@tonic-gate 						fip->fe_block, offset);
1507c478bd9Sstevel@tonic-gate 					offset = end;
1517c478bd9Sstevel@tonic-gate 				}
1527c478bd9Sstevel@tonic-gate 				if (fidp->fid_flags & FID_DELETED)
1537c478bd9Sstevel@tonic-gate 					continue;
1547c478bd9Sstevel@tonic-gate 				(void) cachefile(fidp->fid_icb.lad_ext_loc,
1557c478bd9Sstevel@tonic-gate 					fidp->fid_icb.lad_ext_len);
1567c478bd9Sstevel@tonic-gate 			}
1577c478bd9Sstevel@tonic-gate 			if (dirbuf) {
1587c478bd9Sstevel@tonic-gate 				free(dirbuf);
1597c478bd9Sstevel@tonic-gate 				dirbuf = NULL;
1607c478bd9Sstevel@tonic-gate 			}
1617c478bd9Sstevel@tonic-gate 			if (fbp)
1627c478bd9Sstevel@tonic-gate 				fbp->b_flags &= ~B_INUSE;
1637c478bd9Sstevel@tonic-gate 			if (debug)
1647c478bd9Sstevel@tonic-gate 				(void) printf("Done %x\n", fip->fe_block);
1657c478bd9Sstevel@tonic-gate 			break;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 		case FTYPE_FILE:
1687c478bd9Sstevel@tonic-gate 		case FTYPE_SYMLINK:
1697c478bd9Sstevel@tonic-gate 			ckinode(fp);
170f45bbb21SToomas Soome 			/* FALLTHROUGH */
1717c478bd9Sstevel@tonic-gate 		default:
1727c478bd9Sstevel@tonic-gate 			n_files++;
1737c478bd9Sstevel@tonic-gate 			break;
1747c478bd9Sstevel@tonic-gate 		}
1757c478bd9Sstevel@tonic-gate 		putfilentry(bp);
1767c478bd9Sstevel@tonic-gate 		bp->b_flags &= ~B_INUSE;
1777c478bd9Sstevel@tonic-gate 	next:
1787c478bd9Sstevel@tonic-gate 		/* At end of this set of fips, get the next set */
1797c478bd9Sstevel@tonic-gate 		if ((++fip)->fe_block == (uint32_t)-1)
1807c478bd9Sstevel@tonic-gate 			fip = fip->fe_nexthash;
1817c478bd9Sstevel@tonic-gate 	}
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	/* Find bad link counts */
1847c478bd9Sstevel@tonic-gate 	fip = &inphead[0];
1857c478bd9Sstevel@tonic-gate 	while (fip->fe_block) {
1867c478bd9Sstevel@tonic-gate 		if (fip->fe_lcount != fip->fe_lseen)
1877c478bd9Sstevel@tonic-gate 			adjust(fip);
1887c478bd9Sstevel@tonic-gate 		/* At end of this set of fips, get the next set */
1897c478bd9Sstevel@tonic-gate 		if ((++fip)->fe_block == (uint32_t)-1)
1907c478bd9Sstevel@tonic-gate 			fip = fip->fe_nexthash;
1917c478bd9Sstevel@tonic-gate 	}
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate static void
opndir(struct file_entry * fp)1957c478bd9Sstevel@tonic-gate opndir(struct file_entry *fp)
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate 	if (dirbuf) {
1987c478bd9Sstevel@tonic-gate 		free(dirbuf);
1997c478bd9Sstevel@tonic-gate 		dirbuf = NULL;
2007c478bd9Sstevel@tonic-gate 	}
2017c478bd9Sstevel@tonic-gate 	if (extbuf) {
2027c478bd9Sstevel@tonic-gate 		free(extbuf);
2037c478bd9Sstevel@tonic-gate 		extbuf = NULL;
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	dir_baseoff = 0;
2077c478bd9Sstevel@tonic-gate 	dir_basesize = 0;
2087c478bd9Sstevel@tonic-gate 	dir_adrindx = 0;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	switch (fp->fe_icb_tag.itag_flags & 0x3) {
2117c478bd9Sstevel@tonic-gate 	case ICB_FLAG_SHORT_AD:
2127c478bd9Sstevel@tonic-gate 		dir_adrsize = sizeof (short_ad_t);
2137c478bd9Sstevel@tonic-gate 		dir_naddrs = fp->fe_len_adesc / sizeof (short_ad_t);
2147c478bd9Sstevel@tonic-gate 		dir_adrlist = (uint8_t *)(fp->fe_spec + fp->fe_len_ear);
2157c478bd9Sstevel@tonic-gate 		break;
2167c478bd9Sstevel@tonic-gate 	case ICB_FLAG_LONG_AD:
2177c478bd9Sstevel@tonic-gate 		dir_adrsize = sizeof (long_ad_t);
2187c478bd9Sstevel@tonic-gate 		dir_naddrs = fp->fe_len_adesc / sizeof (long_ad_t);
2197c478bd9Sstevel@tonic-gate 		dir_adrlist = (uint8_t *)(fp->fe_spec + fp->fe_len_ear);
2207c478bd9Sstevel@tonic-gate 		break;
2217c478bd9Sstevel@tonic-gate 	case ICB_FLAG_EXT_AD:
2227c478bd9Sstevel@tonic-gate 		errexit(gettext("Can't handle ext_ads in directories/n"));
2237c478bd9Sstevel@tonic-gate 		break;
2247c478bd9Sstevel@tonic-gate 	case ICB_FLAG_ONE_AD:
2257c478bd9Sstevel@tonic-gate 		dir_adrsize = 0;
2267c478bd9Sstevel@tonic-gate 		dir_naddrs = 0;
2277c478bd9Sstevel@tonic-gate 		dir_adrlist = NULL;
2287c478bd9Sstevel@tonic-gate 		dir_basesize = fp->fe_len_adesc;
2297c478bd9Sstevel@tonic-gate 		dir_fidp = (uint8_t *)(fp->fe_spec + fp->fe_len_ear);
2307c478bd9Sstevel@tonic-gate 		baseblock = fp->fe_tag.tag_loc;
2317c478bd9Sstevel@tonic-gate 		break;
2327c478bd9Sstevel@tonic-gate 	}
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /* Allocate and read in an allocation extent */
2367c478bd9Sstevel@tonic-gate /* ARGSUSED */
2377c478bd9Sstevel@tonic-gate int
getallocext(struct file_entry * fp,uint32_t loc,uint32_t len)2387c478bd9Sstevel@tonic-gate getallocext(struct file_entry *fp, uint32_t loc, uint32_t len)
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate 	uint32_t nb;
2417c478bd9Sstevel@tonic-gate 	uint8_t *ap;
2427c478bd9Sstevel@tonic-gate 	int i;
2437c478bd9Sstevel@tonic-gate 	int err;
2447c478bd9Sstevel@tonic-gate 	struct alloc_ext_desc *aep;
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 	if (debug)
2477c478bd9Sstevel@tonic-gate 		(void) printf(" allocext loc %x len %x\n", loc, len);
2487c478bd9Sstevel@tonic-gate 	nb = roundup(len, secsize);
2497c478bd9Sstevel@tonic-gate 	if (extbuf)
2507c478bd9Sstevel@tonic-gate 		free(extbuf);
2517c478bd9Sstevel@tonic-gate 	extbuf = (uint8_t *)malloc(nb);
2527c478bd9Sstevel@tonic-gate 	if (extbuf == NULL)
2537c478bd9Sstevel@tonic-gate 		errexit(gettext("Can't allocate directory extent buffer\n"));
2547c478bd9Sstevel@tonic-gate 	if (bread(fsreadfd, (char *)extbuf,
2557c478bd9Sstevel@tonic-gate 			fsbtodb(loc + part_start), nb) != 0) {
2567c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
2577c478bd9Sstevel@tonic-gate 			gettext("Can't read allocation extent\n"));
2587c478bd9Sstevel@tonic-gate 		return (1);
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 	aep = (struct alloc_ext_desc *)extbuf;
2617c478bd9Sstevel@tonic-gate 	err = verifytag(&aep->aed_tag, loc, &aep->aed_tag, UD_ALLOC_EXT_DESC);
2627c478bd9Sstevel@tonic-gate 	if (err) {
2637c478bd9Sstevel@tonic-gate 		(void) printf(
2647c478bd9Sstevel@tonic-gate 			gettext("Bad tag on alloc extent: %s\n"), tagerrs[err]);
2657c478bd9Sstevel@tonic-gate 		free(extbuf);
2667c478bd9Sstevel@tonic-gate 		return (1);
2677c478bd9Sstevel@tonic-gate 	}
2687c478bd9Sstevel@tonic-gate 	dir_adrlist = (uint8_t *)(aep + 1);
2697c478bd9Sstevel@tonic-gate 	dir_naddrs = aep->aed_len_aed / dir_adrsize;
2707c478bd9Sstevel@tonic-gate 	dir_adrindx = 0;
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	/* Swap the descriptors */
2737c478bd9Sstevel@tonic-gate 	for (i = 0, ap = dir_adrlist; i < dir_naddrs; i++, ap += dir_adrsize) {
2747c478bd9Sstevel@tonic-gate 		if (dir_adrsize == sizeof (short_ad_t)) {
2757c478bd9Sstevel@tonic-gate 			ud_swap_short_ad((short_ad_t *)ap);
2767c478bd9Sstevel@tonic-gate 		} else if (dir_adrsize == sizeof (long_ad_t)) {
2777c478bd9Sstevel@tonic-gate 			ud_swap_long_ad((long_ad_t *)ap);
2787c478bd9Sstevel@tonic-gate 		}
2797c478bd9Sstevel@tonic-gate 	}
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	return (0);
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate /*
2857c478bd9Sstevel@tonic-gate  * Variables used in this function and their relationships:
2867c478bd9Sstevel@tonic-gate  *  *poffset - read pointer in the directory
2877c478bd9Sstevel@tonic-gate  *  dir_baseoff - offset at start of dirbuf
2887c478bd9Sstevel@tonic-gate  *  dir_baselen - length of valid data in current extent
2897c478bd9Sstevel@tonic-gate  *  dir_adrindx - index into current allocation extent for location of
2907c478bd9Sstevel@tonic-gate  *	dir_baseoff
2917c478bd9Sstevel@tonic-gate  *  dir_naddrs - number of entries in current allocation extent
2927c478bd9Sstevel@tonic-gate  *  dir_fidp - pointer to dirbuf or immediate data in file entry
2937c478bd9Sstevel@tonic-gate  *  baseblock - block address of dir_baseoff
2947c478bd9Sstevel@tonic-gate  *  newoff - *poffset - dir_baseoff
2957c478bd9Sstevel@tonic-gate  */
2967c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
2977c478bd9Sstevel@tonic-gate static int32_t
getdir(struct file_entry * fp,struct bufarea ** fbp,u_offset_t * poffset,struct file_id ** fidpp)2987c478bd9Sstevel@tonic-gate getdir(struct file_entry *fp, struct bufarea **fbp,
2997c478bd9Sstevel@tonic-gate 	u_offset_t *poffset, struct file_id **fidpp)
3007c478bd9Sstevel@tonic-gate {
301*eee96f10SToomas Soome 	struct file_id *fidp = (struct file_id *)fidbuf;
302*eee96f10SToomas Soome 	struct short_ad *sap;
303*eee96f10SToomas Soome 	struct long_ad *lap;
304*eee96f10SToomas Soome 	int i, newoff, xoff = 0;
305*eee96f10SToomas Soome 	uint32_t block = 0, nb, len = 0, left;
3067c478bd9Sstevel@tonic-gate 	u_offset_t offset;
307*eee96f10SToomas Soome 	int err, type = 0;
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate again:
3117c478bd9Sstevel@tonic-gate 	offset = *poffset;
3127c478bd9Sstevel@tonic-gate again2:
3137c478bd9Sstevel@tonic-gate 	if (debug)
3147c478bd9Sstevel@tonic-gate 		(void) printf("getdir %llx\n", offset);
3157c478bd9Sstevel@tonic-gate 	newoff = offset - dir_baseoff;
3167c478bd9Sstevel@tonic-gate 	if (newoff >= dir_basesize) {
3177c478bd9Sstevel@tonic-gate 		if (dirbuf) {
3187c478bd9Sstevel@tonic-gate 			free(dirbuf);
3197c478bd9Sstevel@tonic-gate 			dirbuf = NULL;
3207c478bd9Sstevel@tonic-gate 		}
3217c478bd9Sstevel@tonic-gate 	} else {
3227c478bd9Sstevel@tonic-gate 		if (block == 0)
3237c478bd9Sstevel@tonic-gate 			block = baseblock + (newoff / secsize);
3247c478bd9Sstevel@tonic-gate 		goto nextone;
3257c478bd9Sstevel@tonic-gate 	}
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate again3:
3287c478bd9Sstevel@tonic-gate 	switch (fp->fe_icb_tag.itag_flags & 0x3) {
3297c478bd9Sstevel@tonic-gate 	case ICB_FLAG_SHORT_AD:
3307c478bd9Sstevel@tonic-gate 		sap = &((short_ad_t *)dir_adrlist)[dir_adrindx];
3317c478bd9Sstevel@tonic-gate 		for (i = dir_adrindx; i < dir_naddrs; i++, sap++) {
3327c478bd9Sstevel@tonic-gate 			len = EXTLEN(sap->sad_ext_len);
3337c478bd9Sstevel@tonic-gate 			type = EXTYPE(sap->sad_ext_len);
3347c478bd9Sstevel@tonic-gate 			if (type == 3) {
3357c478bd9Sstevel@tonic-gate 				if (i < dir_naddrs - 1)
3367c478bd9Sstevel@tonic-gate 					errexit(gettext("Allocation extent not "
3377c478bd9Sstevel@tonic-gate 						"at end of list\n"));
3387c478bd9Sstevel@tonic-gate 				markbusy(sap->sad_ext_loc, len);
3397c478bd9Sstevel@tonic-gate 				if (getallocext(fp, sap->sad_ext_loc, len))
3407c478bd9Sstevel@tonic-gate 					return (1);
3417c478bd9Sstevel@tonic-gate 				goto again3;
3427c478bd9Sstevel@tonic-gate 			}
3437c478bd9Sstevel@tonic-gate 			if (newoff < len)
3447c478bd9Sstevel@tonic-gate 				break;
3457c478bd9Sstevel@tonic-gate 			newoff -= len;
3467c478bd9Sstevel@tonic-gate 			dir_baseoff += len;
3477c478bd9Sstevel@tonic-gate 			if (debug)
3487c478bd9Sstevel@tonic-gate 				(void) printf(
3497c478bd9Sstevel@tonic-gate 				    " loc %x len %x\n", sap->sad_ext_loc,
3507c478bd9Sstevel@tonic-gate 					len);
3517c478bd9Sstevel@tonic-gate 		}
3527c478bd9Sstevel@tonic-gate 		dir_adrindx = i;
3537c478bd9Sstevel@tonic-gate 		if (debug)
3547c478bd9Sstevel@tonic-gate 			(void) printf(" loc %x len %x\n", sap->sad_ext_loc,
3557c478bd9Sstevel@tonic-gate 				sap->sad_ext_len);
3567c478bd9Sstevel@tonic-gate 		baseblock = sap->sad_ext_loc;
3577c478bd9Sstevel@tonic-gate 		if (block == 0)
3587c478bd9Sstevel@tonic-gate 			block = baseblock;
3597c478bd9Sstevel@tonic-gate 		dir_basesize = len;
3607c478bd9Sstevel@tonic-gate 		if (type < 2)
3617c478bd9Sstevel@tonic-gate 			markbusy(sap->sad_ext_loc, len);
3627c478bd9Sstevel@tonic-gate 		if (type != 0) {
3637c478bd9Sstevel@tonic-gate 			*poffset += dir_basesize;
3647c478bd9Sstevel@tonic-gate 			goto again;
3657c478bd9Sstevel@tonic-gate 		}
3667c478bd9Sstevel@tonic-gate 		nb = roundup(len, secsize);
3677c478bd9Sstevel@tonic-gate 		dirbuf = (uint8_t *)malloc(nb);
3687c478bd9Sstevel@tonic-gate 		if (dirbuf == NULL)
3697c478bd9Sstevel@tonic-gate 			errexit(gettext("Can't allocate directory extent "
3707c478bd9Sstevel@tonic-gate 				"buffer\n"));
3717c478bd9Sstevel@tonic-gate 		if (bread(fsreadfd, (char *)dirbuf,
3727c478bd9Sstevel@tonic-gate 				fsbtodb(baseblock + part_start), nb) != 0) {
3737c478bd9Sstevel@tonic-gate 			errexit(gettext("Can't read directory extent\n"));
3747c478bd9Sstevel@tonic-gate 		}
3757c478bd9Sstevel@tonic-gate 		dir_fidp = dirbuf;
3767c478bd9Sstevel@tonic-gate 		break;
3777c478bd9Sstevel@tonic-gate 	case ICB_FLAG_LONG_AD:
3787c478bd9Sstevel@tonic-gate 		lap = &((long_ad_t *)dir_adrlist)[dir_adrindx];
3797c478bd9Sstevel@tonic-gate 		for (i = dir_adrindx; i < dir_naddrs; i++, lap++) {
3807c478bd9Sstevel@tonic-gate 			len = EXTLEN(lap->lad_ext_len);
3817c478bd9Sstevel@tonic-gate 			type = EXTYPE(lap->lad_ext_len);
3827c478bd9Sstevel@tonic-gate 			if (type == 3) {
3837c478bd9Sstevel@tonic-gate 				if (i < dir_naddrs - 1)
3847c478bd9Sstevel@tonic-gate 					errexit(gettext("Allocation extent not "
3857c478bd9Sstevel@tonic-gate 						"at end of list\n"));
3867c478bd9Sstevel@tonic-gate 				markbusy(lap->lad_ext_loc, len);
3877c478bd9Sstevel@tonic-gate 				if (getallocext(fp, lap->lad_ext_loc, len))
3887c478bd9Sstevel@tonic-gate 					return (1);
3897c478bd9Sstevel@tonic-gate 				goto again3;
3907c478bd9Sstevel@tonic-gate 			}
3917c478bd9Sstevel@tonic-gate 			if (newoff < len)
3927c478bd9Sstevel@tonic-gate 				break;
3937c478bd9Sstevel@tonic-gate 			newoff -= len;
3947c478bd9Sstevel@tonic-gate 			dir_baseoff += len;
3957c478bd9Sstevel@tonic-gate 			if (debug)
3967c478bd9Sstevel@tonic-gate 				(void) printf(
3977c478bd9Sstevel@tonic-gate 				    " loc %x len %x\n", lap->lad_ext_loc,
3987c478bd9Sstevel@tonic-gate 					len);
3997c478bd9Sstevel@tonic-gate 		}
4007c478bd9Sstevel@tonic-gate 		dir_adrindx = i;
4017c478bd9Sstevel@tonic-gate 		if (debug)
4027c478bd9Sstevel@tonic-gate 			(void) printf(" loc %x len %x\n", lap->lad_ext_loc,
4037c478bd9Sstevel@tonic-gate 				lap->lad_ext_len);
4047c478bd9Sstevel@tonic-gate 		baseblock = lap->lad_ext_loc;
4057c478bd9Sstevel@tonic-gate 		if (block == 0)
4067c478bd9Sstevel@tonic-gate 			block = baseblock;
4077c478bd9Sstevel@tonic-gate 		dir_basesize = len;
4087c478bd9Sstevel@tonic-gate 		if (type < 2)
4097c478bd9Sstevel@tonic-gate 			markbusy(lap->lad_ext_loc, len);
4107c478bd9Sstevel@tonic-gate 		if (type != 0) {
4117c478bd9Sstevel@tonic-gate 			*poffset += dir_basesize;
4127c478bd9Sstevel@tonic-gate 			goto again;
4137c478bd9Sstevel@tonic-gate 		}
4147c478bd9Sstevel@tonic-gate 		nb = roundup(len, secsize);
4157c478bd9Sstevel@tonic-gate 		dirbuf = (uint8_t *)malloc(nb);
4167c478bd9Sstevel@tonic-gate 		if (dirbuf == NULL)
4177c478bd9Sstevel@tonic-gate 			errexit(gettext("Can't allocate directory extent "
4187c478bd9Sstevel@tonic-gate 				"buffer\n"));
4197c478bd9Sstevel@tonic-gate 		if (bread(fsreadfd, (char *)dirbuf,
4207c478bd9Sstevel@tonic-gate 				fsbtodb(baseblock + part_start), nb) != 0) {
4217c478bd9Sstevel@tonic-gate 			errexit(gettext("Can't read directory extent\n"));
4227c478bd9Sstevel@tonic-gate 		}
4237c478bd9Sstevel@tonic-gate 		dir_fidp = dirbuf;
4247c478bd9Sstevel@tonic-gate 		break;
4257c478bd9Sstevel@tonic-gate 	case ICB_FLAG_EXT_AD:
4267c478bd9Sstevel@tonic-gate 		break;
4277c478bd9Sstevel@tonic-gate 	case ICB_FLAG_ONE_AD:
4287c478bd9Sstevel@tonic-gate 		errexit(gettext("Logic error in getdir - at ICB_FLAG_ONE_AD "
4297c478bd9Sstevel@tonic-gate 			"case\n"));
4307c478bd9Sstevel@tonic-gate 		break;
4317c478bd9Sstevel@tonic-gate 	}
4327c478bd9Sstevel@tonic-gate nextone:
4337c478bd9Sstevel@tonic-gate 	if (debug)
4347c478bd9Sstevel@tonic-gate 		(void) printf("getdirend blk %x dir_baseoff %llx newoff %x\n",
4357c478bd9Sstevel@tonic-gate 			block, dir_baseoff, newoff);
4367c478bd9Sstevel@tonic-gate 	left = dir_basesize - newoff;
4377c478bd9Sstevel@tonic-gate 	if (xoff + left > MAXFIDSIZE)
4387c478bd9Sstevel@tonic-gate 		left = MAXFIDSIZE - xoff;
4397c478bd9Sstevel@tonic-gate 	bcopy((char *)dir_fidp + newoff, (char *)fidbuf + xoff, left);
4407c478bd9Sstevel@tonic-gate 	xoff += left;
4417c478bd9Sstevel@tonic-gate 	/*
4427c478bd9Sstevel@tonic-gate 	 * If we have a fid that crosses an extent boundary, then force
4437c478bd9Sstevel@tonic-gate 	 * a read of the next extent, and fill up the rest of the fid.
4447c478bd9Sstevel@tonic-gate 	 */
4457c478bd9Sstevel@tonic-gate 	if (xoff < sizeof (fidp->fid_tag) ||
4467c478bd9Sstevel@tonic-gate 	    xoff < sizeof (fidp->fid_tag) + SWAP16(fidp->fid_tag.tag_crc_len)) {
4477c478bd9Sstevel@tonic-gate 		offset += left;
4487c478bd9Sstevel@tonic-gate 		if (debug)
4497c478bd9Sstevel@tonic-gate 			(void) printf("block crossing at offset %llx\n",
4507c478bd9Sstevel@tonic-gate 				offset);
4517c478bd9Sstevel@tonic-gate 		goto again2;
4527c478bd9Sstevel@tonic-gate 	}
4537c478bd9Sstevel@tonic-gate 	err = verifytag(&fidp->fid_tag, block, &fidp->fid_tag, UD_FILE_ID_DESC);
4547c478bd9Sstevel@tonic-gate 	if (debug) {
4557c478bd9Sstevel@tonic-gate 		dump16((char *)fidp, "\n");
4567c478bd9Sstevel@tonic-gate 	}
4577c478bd9Sstevel@tonic-gate 	if (err) {
4587c478bd9Sstevel@tonic-gate 		pwarn(gettext("Bad directory tag: %s\n"), tagerrs[err]);
4597c478bd9Sstevel@tonic-gate 		return (err);
4607c478bd9Sstevel@tonic-gate 	}
4617c478bd9Sstevel@tonic-gate 	*fidpp = fidp;
4627c478bd9Sstevel@tonic-gate 	return (0);
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate static void
ckinode(struct file_entry * fp)4667c478bd9Sstevel@tonic-gate ckinode(struct file_entry *fp)
4677c478bd9Sstevel@tonic-gate {
468*eee96f10SToomas Soome 	struct short_ad *sap = NULL;
469*eee96f10SToomas Soome 	struct long_ad *lap;
470*eee96f10SToomas Soome 	int i, type, len;
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	switch (fp->fe_icb_tag.itag_flags & 0x3) {
4737c478bd9Sstevel@tonic-gate 	case ICB_FLAG_SHORT_AD:
4747c478bd9Sstevel@tonic-gate 		dir_adrsize = sizeof (short_ad_t);
4757c478bd9Sstevel@tonic-gate 		dir_naddrs = fp->fe_len_adesc / sizeof (short_ad_t);
4767c478bd9Sstevel@tonic-gate 		sap = (short_ad_t *)(fp->fe_spec + fp->fe_len_ear);
4777c478bd9Sstevel@tonic-gate again1:
4787c478bd9Sstevel@tonic-gate 		for (i = 0; i < dir_naddrs; i++, sap++) {
4797c478bd9Sstevel@tonic-gate 			len = EXTLEN(sap->sad_ext_len);
4807c478bd9Sstevel@tonic-gate 			type = EXTYPE(sap->sad_ext_len);
4817c478bd9Sstevel@tonic-gate 			if (type < 2)
4827c478bd9Sstevel@tonic-gate 				markbusy(sap->sad_ext_loc, len);
4837c478bd9Sstevel@tonic-gate 			if (debug)
4847c478bd9Sstevel@tonic-gate 				(void) printf(
4857c478bd9Sstevel@tonic-gate 				    " loc %x len %x\n", sap->sad_ext_loc,
4867c478bd9Sstevel@tonic-gate 					sap->sad_ext_len);
4877c478bd9Sstevel@tonic-gate 			if (type == 3) {
4887c478bd9Sstevel@tonic-gate 				markbusy(sap->sad_ext_loc, len);
4897c478bd9Sstevel@tonic-gate 				/* This changes dir_naddrs and dir_adrlist */
4907c478bd9Sstevel@tonic-gate 				if (getallocext(fp, sap->sad_ext_loc, len))
4917c478bd9Sstevel@tonic-gate 					break;
4927c478bd9Sstevel@tonic-gate 				sap = (short_ad_t *)dir_adrlist;
4937c478bd9Sstevel@tonic-gate 				goto again1;
4947c478bd9Sstevel@tonic-gate 			}
4957c478bd9Sstevel@tonic-gate 		}
4967c478bd9Sstevel@tonic-gate 		break;
4977c478bd9Sstevel@tonic-gate 	case ICB_FLAG_LONG_AD:
4987c478bd9Sstevel@tonic-gate 		dir_adrsize = sizeof (long_ad_t);
4997c478bd9Sstevel@tonic-gate 		dir_naddrs = fp->fe_len_adesc / sizeof (long_ad_t);
5007c478bd9Sstevel@tonic-gate 		lap = (long_ad_t *)(fp->fe_spec + fp->fe_len_ear);
5017c478bd9Sstevel@tonic-gate again2:
5027c478bd9Sstevel@tonic-gate 		for (i = 0; i < dir_naddrs; i++, lap++) {
5037c478bd9Sstevel@tonic-gate 			len = EXTLEN(lap->lad_ext_len);
5047c478bd9Sstevel@tonic-gate 			type = EXTYPE(lap->lad_ext_len);
5057c478bd9Sstevel@tonic-gate 			if (type < 2)
5067c478bd9Sstevel@tonic-gate 				markbusy(lap->lad_ext_loc, len);
5077c478bd9Sstevel@tonic-gate 			if (debug)
5087c478bd9Sstevel@tonic-gate 				(void) printf(
5097c478bd9Sstevel@tonic-gate 				    " loc %x len %x\n", lap->lad_ext_loc,
5107c478bd9Sstevel@tonic-gate 					lap->lad_ext_len);
5117c478bd9Sstevel@tonic-gate 			if (type == 3) {
5127c478bd9Sstevel@tonic-gate 				markbusy(sap->sad_ext_loc, len);
5137c478bd9Sstevel@tonic-gate 				/* This changes dir_naddrs and dir_adrlist */
5147c478bd9Sstevel@tonic-gate 				if (getallocext(fp, lap->lad_ext_loc, len))
5157c478bd9Sstevel@tonic-gate 					break;
5167c478bd9Sstevel@tonic-gate 				lap = (long_ad_t *)dir_adrlist;
5177c478bd9Sstevel@tonic-gate 				goto again2;
5187c478bd9Sstevel@tonic-gate 			}
5197c478bd9Sstevel@tonic-gate 		}
5207c478bd9Sstevel@tonic-gate 		break;
5217c478bd9Sstevel@tonic-gate 	case ICB_FLAG_EXT_AD:
5227c478bd9Sstevel@tonic-gate 		break;
5237c478bd9Sstevel@tonic-gate 	case ICB_FLAG_ONE_AD:
5247c478bd9Sstevel@tonic-gate 		break;
5257c478bd9Sstevel@tonic-gate 	}
5267c478bd9Sstevel@tonic-gate }
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate static void
adjust(struct fileinfo * fip)5297c478bd9Sstevel@tonic-gate adjust(struct fileinfo *fip)
5307c478bd9Sstevel@tonic-gate {
531*eee96f10SToomas Soome 	struct file_entry *fp;
532*eee96f10SToomas Soome 	struct bufarea *bp;
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	bp = getfilentry(fip->fe_block, fip->fe_len);
5357c478bd9Sstevel@tonic-gate 	if (bp == NULL)
5367c478bd9Sstevel@tonic-gate 		errexit(gettext("Unable to read file entry at %x\n"),
5377c478bd9Sstevel@tonic-gate 			fip->fe_block);
5387c478bd9Sstevel@tonic-gate 	fp = (struct file_entry *)bp->b_un.b_buf;
5397c478bd9Sstevel@tonic-gate 	pwarn(gettext("LINK COUNT %s I=%x"),
5407c478bd9Sstevel@tonic-gate 		fip->fe_type == FTYPE_DIRECTORY ? "DIR" :
5417c478bd9Sstevel@tonic-gate 		fip->fe_type == FTYPE_SYMLINK ? "SYM" :
5427c478bd9Sstevel@tonic-gate 		fip->fe_type == FTYPE_FILE ? "FILE" : "???", fip->fe_block);
5437c478bd9Sstevel@tonic-gate 	(void) printf(gettext(" COUNT %d SHOULD BE %d"),
5447c478bd9Sstevel@tonic-gate 		fip->fe_lcount, fip->fe_lseen);
5457c478bd9Sstevel@tonic-gate 	if (preen) {
5467c478bd9Sstevel@tonic-gate 		if (fip->fe_lseen > fip->fe_lcount) {
5477c478bd9Sstevel@tonic-gate 			(void) printf("\n");
5487c478bd9Sstevel@tonic-gate 			pfatal(gettext("LINK COUNT INCREASING"));
5497c478bd9Sstevel@tonic-gate 		}
5507c478bd9Sstevel@tonic-gate 		(void) printf(gettext(" (ADJUSTED)\n"));
5517c478bd9Sstevel@tonic-gate 	}
5527c478bd9Sstevel@tonic-gate 	if (preen || reply(gettext("ADJUST")) == 1) {
5537c478bd9Sstevel@tonic-gate 		fp->fe_lcount = fip->fe_lseen;
5547c478bd9Sstevel@tonic-gate 		putfilentry(bp);
5557c478bd9Sstevel@tonic-gate 		dirty(bp);
5567c478bd9Sstevel@tonic-gate 		flush(fswritefd, bp);
5577c478bd9Sstevel@tonic-gate 	}
5587c478bd9Sstevel@tonic-gate 	bp->b_flags &= ~B_INUSE;
5597c478bd9Sstevel@tonic-gate }
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate void
dofreemap(void)562*eee96f10SToomas Soome dofreemap(void)
5637c478bd9Sstevel@tonic-gate {
564*eee96f10SToomas Soome 	int i;
565*eee96f10SToomas Soome 	char *bp, *fp;
5667c478bd9Sstevel@tonic-gate 	struct inodesc idesc;
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	if (freemap == NULL)
5697c478bd9Sstevel@tonic-gate 		return;
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate 	/* Flip bits in the busy map */
5727c478bd9Sstevel@tonic-gate 	bp = busymap;
5737c478bd9Sstevel@tonic-gate 	for (i = 0, bp = busymap; i < part_bmp_bytes; i++, bp++)
5747c478bd9Sstevel@tonic-gate 		*bp = ~*bp;
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 	/* Mark leftovers in byte as allocated */
5777c478bd9Sstevel@tonic-gate 	if (part_len % NBBY)
5787c478bd9Sstevel@tonic-gate 		bp[-1] &= (unsigned)0xff >> (NBBY - part_len % NBBY);
5797c478bd9Sstevel@tonic-gate 	bp = busymap;
5807c478bd9Sstevel@tonic-gate 	fp = freemap;
5817c478bd9Sstevel@tonic-gate 	bzero((char *)&idesc, sizeof (struct inodesc));
5827c478bd9Sstevel@tonic-gate 	idesc.id_type = ADDR;
5837c478bd9Sstevel@tonic-gate 	if (bcmp(bp, fp, part_bmp_bytes) != 0 &&
5847c478bd9Sstevel@tonic-gate 		dofix(&idesc, gettext("BLK(S) MISSING IN FREE BITMAP"))) {
5857c478bd9Sstevel@tonic-gate 		bcopy(bp, fp, part_bmp_bytes);
5867c478bd9Sstevel@tonic-gate 		maketag(&spacep->sbd_tag, &spacep->sbd_tag);
5877c478bd9Sstevel@tonic-gate 		bwrite(fswritefd, (char *)spacep, fsbtodb(part_bmp_loc),
5887c478bd9Sstevel@tonic-gate 			part_bmp_sectors * secsize);
5897c478bd9Sstevel@tonic-gate 	}
5907c478bd9Sstevel@tonic-gate }
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate void
dolvint(void)593*eee96f10SToomas Soome dolvint(void)
5947c478bd9Sstevel@tonic-gate {
5957c478bd9Sstevel@tonic-gate 	struct lvid_iu *lviup;
5967c478bd9Sstevel@tonic-gate 	struct inodesc idesc;
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 	bzero((char *)&idesc, sizeof (struct inodesc));
5997c478bd9Sstevel@tonic-gate 	idesc.id_type = ADDR;
6007c478bd9Sstevel@tonic-gate 	lviup = (struct lvid_iu *)&lvintp->lvid_fst[2];
6017c478bd9Sstevel@tonic-gate 	if ((lvintp->lvid_fst[0] != part_len - n_blks ||
6027c478bd9Sstevel@tonic-gate 	    lvintp->lvid_int_type != LVI_CLOSE ||
6037c478bd9Sstevel@tonic-gate 	    lviup->lvidiu_nfiles != n_files ||
6047c478bd9Sstevel@tonic-gate 	    lviup->lvidiu_ndirs != n_dirs ||
6057c478bd9Sstevel@tonic-gate 	    lvintp->lvid_uniqid < maxuniqid) &&
6067c478bd9Sstevel@tonic-gate 	    dofix(&idesc, gettext("LOGICAL VOLUME INTEGRITY COUNTS WRONG"))) {
6077c478bd9Sstevel@tonic-gate 		lvintp->lvid_int_type = LVI_CLOSE;
6087c478bd9Sstevel@tonic-gate 		lvintp->lvid_fst[0] = part_len - n_blks;
6097c478bd9Sstevel@tonic-gate 		lviup->lvidiu_nfiles = n_files;
6107c478bd9Sstevel@tonic-gate 		lviup->lvidiu_ndirs = n_dirs;
6117c478bd9Sstevel@tonic-gate 		lvintp->lvid_uniqid = maxuniqid;
6127c478bd9Sstevel@tonic-gate 		maketag(&lvintp->lvid_tag, &lvintp->lvid_tag);
6137c478bd9Sstevel@tonic-gate 		bwrite(fswritefd, (char *)lvintp, fsbtodb(lvintblock),
6147c478bd9Sstevel@tonic-gate 			lvintlen);
6157c478bd9Sstevel@tonic-gate 	}
6167c478bd9Sstevel@tonic-gate }
617