xref: /titanic_44/usr/src/cmd/fs.d/udfs/fsck/inode.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate 
6*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
8*7c478bd9Sstevel@tonic-gate 
9*7c478bd9Sstevel@tonic-gate /*
10*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
11*7c478bd9Sstevel@tonic-gate  * All rights reserved.
12*7c478bd9Sstevel@tonic-gate  *
13*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
14*7c478bd9Sstevel@tonic-gate  * provided that: (1) source distributions retain this entire copyright
15*7c478bd9Sstevel@tonic-gate  * notice and comment, and (2) distributions including binaries display
16*7c478bd9Sstevel@tonic-gate  * the following acknowledgement:  ``This product includes software
17*7c478bd9Sstevel@tonic-gate  * developed by the University of California, Berkeley and its contributors''
18*7c478bd9Sstevel@tonic-gate  * in the documentation or other materials provided with the distribution
19*7c478bd9Sstevel@tonic-gate  * and in all advertising materials mentioning features or use of this
20*7c478bd9Sstevel@tonic-gate  * software. Neither the name of the University nor the names of its
21*7c478bd9Sstevel@tonic-gate  * contributors may be used to endorse or promote products derived
22*7c478bd9Sstevel@tonic-gate  * from this software without specific prior written permission.
23*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
24*7c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
25*7c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26*7c478bd9Sstevel@tonic-gate  */
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #include <stdio.h>
31*7c478bd9Sstevel@tonic-gate #include <string.h>
32*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
33*7c478bd9Sstevel@tonic-gate #include <unistd.h>
34*7c478bd9Sstevel@tonic-gate #include <time.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
40*7c478bd9Sstevel@tonic-gate #include <pwd.h>
41*7c478bd9Sstevel@tonic-gate #include "fsck.h"
42*7c478bd9Sstevel@tonic-gate #include <sys/fs/udf_volume.h>
43*7c478bd9Sstevel@tonic-gate #include <locale.h>
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate extern void	errexit(char *, ...);
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate extern unsigned int largefile_count;
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate /*
50*7c478bd9Sstevel@tonic-gate  * Enter inodes into the cache.
51*7c478bd9Sstevel@tonic-gate  */
52*7c478bd9Sstevel@tonic-gate struct fileinfo *
cachefile(feblock,len)53*7c478bd9Sstevel@tonic-gate cachefile(feblock, len)
54*7c478bd9Sstevel@tonic-gate 	uint32_t feblock;
55*7c478bd9Sstevel@tonic-gate 	uint32_t len;
56*7c478bd9Sstevel@tonic-gate {
57*7c478bd9Sstevel@tonic-gate 	register struct fileinfo *inp;
58*7c478bd9Sstevel@tonic-gate 	struct fileinfo **inpp;
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 	inpp = &inphash[feblock % listmax];
61*7c478bd9Sstevel@tonic-gate 	for (inp = *inpp; inp; inp = inp->fe_nexthash) {
62*7c478bd9Sstevel@tonic-gate 		if (inp->fe_block == feblock)
63*7c478bd9Sstevel@tonic-gate 			break;
64*7c478bd9Sstevel@tonic-gate 	}
65*7c478bd9Sstevel@tonic-gate 	if (!inp) {
66*7c478bd9Sstevel@tonic-gate 		if (inpnext >= inplast) {
67*7c478bd9Sstevel@tonic-gate 			inpnext = (struct fileinfo *)calloc(FEGROW + 1,
68*7c478bd9Sstevel@tonic-gate 				sizeof (struct fileinfo));
69*7c478bd9Sstevel@tonic-gate 			if (inpnext == NULL)
70*7c478bd9Sstevel@tonic-gate 				errexit(gettext("Cannot grow inphead list\n"));
71*7c478bd9Sstevel@tonic-gate 			/* Link at extra entry so that we can find them */
72*7c478bd9Sstevel@tonic-gate 			inplast->fe_nexthash = inpnext;
73*7c478bd9Sstevel@tonic-gate 			inplast->fe_block = (uint32_t)-1;
74*7c478bd9Sstevel@tonic-gate 			inplast = &inpnext[FEGROW];
75*7c478bd9Sstevel@tonic-gate 		}
76*7c478bd9Sstevel@tonic-gate 		inp = inpnext++;
77*7c478bd9Sstevel@tonic-gate 		inp->fe_block = feblock;
78*7c478bd9Sstevel@tonic-gate 		inp->fe_len = (uint16_t)len;
79*7c478bd9Sstevel@tonic-gate 		inp->fe_lseen = 1;
80*7c478bd9Sstevel@tonic-gate 		inp->fe_nexthash = *inpp;
81*7c478bd9Sstevel@tonic-gate 		*inpp = inp;
82*7c478bd9Sstevel@tonic-gate 		if (debug) {
83*7c478bd9Sstevel@tonic-gate 		    (void) printf("cacheing %x\n", feblock);
84*7c478bd9Sstevel@tonic-gate 		}
85*7c478bd9Sstevel@tonic-gate 	} else {
86*7c478bd9Sstevel@tonic-gate 		inp->fe_lseen++;
87*7c478bd9Sstevel@tonic-gate 		if (debug) {
88*7c478bd9Sstevel@tonic-gate 		    (void) printf("cache hit %x lcount %d lseen %d\n", feblock,
89*7c478bd9Sstevel@tonic-gate 			inp->fe_lcount, inp->fe_lseen);
90*7c478bd9Sstevel@tonic-gate 		}
91*7c478bd9Sstevel@tonic-gate 	}
92*7c478bd9Sstevel@tonic-gate 	return (inp);
93*7c478bd9Sstevel@tonic-gate }
94