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