From b9fc790ddc0db2522b0d20d08fd2b8d40ef0fa4e Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 7 Feb 2011 15:46:09 +0100 Subject: di-set: provide a lookup method This is required for patch, and hence is about to move to gnulib. * gl/lib/di-set.c (di_set_lookup): New function. * gl/lib/di-set.h: Declare it. * gl/tests/test-di-set.c (main): Exercise it. The bug was introduced on 2004-12-04 via commit 7380cf79. --- gl/lib/di-set.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'gl/lib/di-set.c') diff --git a/gl/lib/di-set.c b/gl/lib/di-set.c index 05d24d609..5e839a311 100644 --- a/gl/lib/di-set.c +++ b/gl/lib/di-set.c @@ -235,3 +235,25 @@ di_set_insert (struct di_set *dis, dev_t dev, ino_t ino) /* Put I into the inode set. */ return hash_insert0 (ino_set, (void *) i, NULL); } + +/* Look up the DEV,INO pair in the set DIS. + If found, return 1; if not found, return 0. + Upon any failure return -1. */ +int +di_set_lookup (struct di_set *dis, dev_t dev, ino_t ino) +{ + hashint i; + + /* Map the device number to a set of inodes. */ + struct hash_table *ino_set = map_device (dis, dev); + if (! ino_set) + return -1; + + /* Map the inode number to a small representative I. */ + i = map_inode_number (dis, ino); + if (i == INO_MAP_INSERT_FAILURE) + return -1; + + /* Perform the look-up. */ + return !!hash_lookup (ino_set, (void const *) i); +} -- cgit v1.2.3-54-g00ecf