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