db->tdb = NULL;
return;
}
- db->tdb = tdb_open(db->tdb_fn, 0, TDB_CLEAR_IF_FIRST,
+
+ if (num_dirs < 99991)
+ num_dirs = 99991; /* largest 5 digit prime */
+
+ db->tdb = tdb_open(db->tdb_fn, num_dirs, TDB_NOLOCK | TDB_NOSYNC,
O_RDWR | O_CREAT | O_TRUNC, 0600);
close(fd);
}
ext2_icount_t icount;
errcode_t retval;
char *fn, uuid[40];
+ ext2_ino_t num_inodes;
int fd;
retval = alloc_icount(fs, flags, &icount);
sprintf(fn, "%s/%s-icount-XXXXXX", tdb_dir, uuid);
fd = mkstemp(fn);
+ /*
+ * This is an overestimate of the size that we will need; the
+ * ideal value is the number of used inodes with a count
+ * greater than 1. OTOH the times when we really need this is
+ * with the backup programs that use lots of hard links, in
+ * which case the number of inodes in use approaches the ideal
+ * value.
+ */
+ num_inodes = fs->super->s_inodes_count - fs->super->s_free_inodes_count;
+
icount->tdb_fn = fn;
- icount->tdb = tdb_open(fn, 0, TDB_CLEAR_IF_FIRST,
+ icount->tdb = tdb_open(fn, num_inodes, TDB_NOLOCK | TDB_NOSYNC,
O_RDWR | O_CREAT | O_TRUNC, 0600);
if (icount->tdb) {
close(fd);
static struct tdb_context *tdbs = NULL;
-/* This is based on the hash algorithm from gdbm */
+/* This is from a hash algorithm suggested by Rogier Wolff */
static unsigned int default_tdb_hash(TDB_DATA *key)
{
u32 value; /* Used to compute the hash value. */
u32 i; /* Used to cycle through random values. */
/* Set the initial value from the key size. */
- for (value = 0x238F13AF * key->dsize, i=0; i < key->dsize; i++)
- value = (value + (key->dptr[i] << (i*5 % 24)));
+ for (value = 0, i=0; i < key->dsize; i++)
+ value = value * 256 + key->dptr[i] + (value >> 24) * 241;
- return (1103515243 * value + 12345);
+ return value;
}