2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 #ident "$Id: hash.c,v 1.3 2006/07/04 04:57:42 hpa Exp $"
14 /* ----------------------------------------------------------------------- *
16 * Copyright 2001 H. Peter Anvin - All Rights Reserved
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
21 * USA; either version 2 of the License, or (at your option) any later
22 * version; incorporated herein by reference.
24 * ----------------------------------------------------------------------- */
29 * Hash table used to find hard-linked files
32 #include "mkzftree.h" /* Must be included first! */
34 #define HASH_BUCKETS 2683
37 struct file_hash *next;
39 const char *outfile_name;
42 static struct file_hash *hashp[HASH_BUCKETS];
44 const char *hash_find_file(struct stat *st)
46 int bucket = (st->st_ino + st->st_dev) % HASH_BUCKETS;
49 for ( hp = hashp[bucket] ; hp ; hp = hp->next ) {
50 if ( hp->st.st_ino == st->st_ino &&
51 hp->st.st_dev == st->st_dev &&
52 hp->st.st_mode == st->st_mode &&
53 hp->st.st_nlink == st->st_nlink &&
54 hp->st.st_uid == st->st_uid &&
55 hp->st.st_gid == st->st_gid &&
56 hp->st.st_size == st->st_size &&
57 hp->st.st_mtime == st->st_mtime ) {
58 /* Good enough, it's the same file */
59 return hp->outfile_name;
62 return NULL; /* No match */
65 /* Note: the stat structure is the input file; the name
66 is the output file to link to */
67 void hash_insert_file(struct stat *st, const char *outfile)
69 int bucket = (st->st_ino + st->st_dev) % HASH_BUCKETS;
70 struct file_hash *hp = xmalloc(sizeof(struct file_hash));
72 hp->next = hashp[bucket];
73 memcpy(&hp->st, st, sizeof(struct stat));
74 hp->outfile_name = xstrdup(outfile);