xref: /illumos-gate/usr/src/cmd/fs.d/udfs/fsck/inode.c (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
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 #include <stdio.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <time.h>
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/sysmacros.h>
36 #include <sys/mntent.h>
37 #include <sys/vnode.h>
38 #include <pwd.h>
39 #include "fsck.h"
40 #include <sys/fs/udf_volume.h>
41 #include <locale.h>
42 
43 extern void	errexit(char *, ...);
44 
45 extern unsigned int largefile_count;
46 
47 /*
48  * Enter inodes into the cache.
49  */
50 struct fileinfo *
51 cachefile(feblock, len)
52 	uint32_t feblock;
53 	uint32_t len;
54 {
55 	register struct fileinfo *inp;
56 	struct fileinfo **inpp;
57 
58 	inpp = &inphash[feblock % listmax];
59 	for (inp = *inpp; inp; inp = inp->fe_nexthash) {
60 		if (inp->fe_block == feblock)
61 			break;
62 	}
63 	if (!inp) {
64 		if (inpnext >= inplast) {
65 			inpnext = (struct fileinfo *)calloc(FEGROW + 1,
66 				sizeof (struct fileinfo));
67 			if (inpnext == NULL)
68 				errexit(gettext("Cannot grow inphead list\n"));
69 			/* Link at extra entry so that we can find them */
70 			inplast->fe_nexthash = inpnext;
71 			inplast->fe_block = (uint32_t)-1;
72 			inplast = &inpnext[FEGROW];
73 		}
74 		inp = inpnext++;
75 		inp->fe_block = feblock;
76 		inp->fe_len = (uint16_t)len;
77 		inp->fe_lseen = 1;
78 		inp->fe_nexthash = *inpp;
79 		*inpp = inp;
80 		if (debug) {
81 		    (void) printf("cacheing %x\n", feblock);
82 		}
83 	} else {
84 		inp->fe_lseen++;
85 		if (debug) {
86 		    (void) printf("cache hit %x lcount %d lseen %d\n", feblock,
87 			inp->fe_lcount, inp->fe_lseen);
88 		}
89 	}
90 	return (inp);
91 }
92