17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
37c478bdstevel@tonic-gate * Use is subject to license terms.
47c478bdstevel@tonic-gate */
57c478bdstevel@tonic-gate
67c478bdstevel@tonic-gate/*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
77c478bdstevel@tonic-gate/*	  All Rights Reserved  	*/
87c478bdstevel@tonic-gate
97c478bdstevel@tonic-gate/*
107c478bdstevel@tonic-gate * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
117c478bdstevel@tonic-gate * All rights reserved.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * Redistribution and use in source and binary forms are permitted
147c478bdstevel@tonic-gate * provided that: (1) source distributions retain this entire copyright
157c478bdstevel@tonic-gate * notice and comment, and (2) distributions including binaries display
167c478bdstevel@tonic-gate * the following acknowledgement:  ``This product includes software
177c478bdstevel@tonic-gate * developed by the University of California, Berkeley and its contributors''
187c478bdstevel@tonic-gate * in the documentation or other materials provided with the distribution
197c478bdstevel@tonic-gate * and in all advertising materials mentioning features or use of this
207c478bdstevel@tonic-gate * software. Neither the name of the University nor the names of its
217c478bdstevel@tonic-gate * contributors may be used to endorse or promote products derived
227c478bdstevel@tonic-gate * from this software without specific prior written permission.
237c478bdstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
247c478bdstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
257c478bdstevel@tonic-gate * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
267c478bdstevel@tonic-gate */
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#include <stdio.h>
317c478bdstevel@tonic-gate#include <string.h>
327c478bdstevel@tonic-gate#include <stdlib.h>
337c478bdstevel@tonic-gate#include <unistd.h>
347c478bdstevel@tonic-gate#include <time.h>
357c478bdstevel@tonic-gate#include <sys/param.h>
367c478bdstevel@tonic-gate#include <sys/types.h>
377c478bdstevel@tonic-gate#include <sys/sysmacros.h>
387c478bdstevel@tonic-gate#include <sys/mntent.h>
397c478bdstevel@tonic-gate#include <sys/vnode.h>
407c478bdstevel@tonic-gate#include <pwd.h>
417c478bdstevel@tonic-gate#include "fsck.h"
427c478bdstevel@tonic-gate#include <sys/fs/udf_volume.h>
437c478bdstevel@tonic-gate#include <locale.h>
447c478bdstevel@tonic-gate
457c478bdstevel@tonic-gateextern void	errexit(char *, ...);
467c478bdstevel@tonic-gate
477c478bdstevel@tonic-gateextern unsigned int largefile_count;
487c478bdstevel@tonic-gate
497c478bdstevel@tonic-gate/*
507c478bdstevel@tonic-gate * Enter inodes into the cache.
517c478bdstevel@tonic-gate */
527c478bdstevel@tonic-gatestruct fileinfo *
537c478bdstevel@tonic-gatecachefile(feblock, len)
547c478bdstevel@tonic-gate	uint32_t feblock;
557c478bdstevel@tonic-gate	uint32_t len;
567c478bdstevel@tonic-gate{
577c478bdstevel@tonic-gate	register struct fileinfo *inp;
587c478bdstevel@tonic-gate	struct fileinfo **inpp;
597c478bdstevel@tonic-gate
607c478bdstevel@tonic-gate	inpp = &inphash[feblock % listmax];
617c478bdstevel@tonic-gate	for (inp = *inpp; inp; inp = inp->fe_nexthash) {
627c478bdstevel@tonic-gate		if (inp->fe_block == feblock)
637c478bdstevel@tonic-gate			break;
647c478bdstevel@tonic-gate	}
657c478bdstevel@tonic-gate	if (!inp) {
667c478bdstevel@tonic-gate		if (inpnext >= inplast) {
677c478bdstevel@tonic-gate			inpnext = (struct fileinfo *)calloc(FEGROW + 1,
687c478bdstevel@tonic-gate				sizeof (struct fileinfo));
697c478bdstevel@tonic-gate			if (inpnext == NULL)
707c478bdstevel@tonic-gate				errexit(gettext("Cannot grow inphead list\n"));
717c478bdstevel@tonic-gate			/* Link at extra entry so that we can find them */
727c478bdstevel@tonic-gate			inplast->fe_nexthash = inpnext;
737c478bdstevel@tonic-gate			inplast->fe_block = (uint32_t)-1;
747c478bdstevel@tonic-gate			inplast = &inpnext[FEGROW];
757c478bdstevel@tonic-gate		}
767c478bdstevel@tonic-gate		inp = inpnext++;
777c478bdstevel@tonic-gate		inp->fe_block = feblock;
787c478bdstevel@tonic-gate		inp->fe_len = (uint16_t)len;
797c478bdstevel@tonic-gate		inp->fe_lseen = 1;
807c478bdstevel@tonic-gate		inp->fe_nexthash = *inpp;
817c478bdstevel@tonic-gate		*inpp = inp;
827c478bdstevel@tonic-gate		if (debug) {
837c478bdstevel@tonic-gate		    (void) printf("cacheing %x\n", feblock);
847c478bdstevel@tonic-gate		}
857c478bdstevel@tonic-gate	} else {
867c478bdstevel@tonic-gate		inp->fe_lseen++;
877c478bdstevel@tonic-gate		if (debug) {
887c478bdstevel@tonic-gate		    (void) printf("cache hit %x lcount %d lseen %d\n", feblock,
897c478bdstevel@tonic-gate			inp->fe_lcount, inp->fe_lseen);
907c478bdstevel@tonic-gate		}
917c478bdstevel@tonic-gate	}
927c478bdstevel@tonic-gate	return (inp);
937c478bdstevel@tonic-gate}
94