summaryrefslogtreecommitdiffstats
path: root/shlibs/blkid/src/verify.c
diff options
context:
space:
mode:
authorKarel Zak2010-03-17 14:49:14 +0100
committerKarel Zak2010-03-17 14:49:14 +0100
commit6c2f2b9d62b196296e827f8bb7336a39e80695a9 (patch)
treeb4da6079a7a7af0080989e37782cc07465d5d760 /shlibs/blkid/src/verify.c
parentlib: fix blkdev_find_size() (diff)
downloadkernel-qcow2-util-linux-6c2f2b9d62b196296e827f8bb7336a39e80695a9.tar.gz
kernel-qcow2-util-linux-6c2f2b9d62b196296e827f8bb7336a39e80695a9.tar.xz
kernel-qcow2-util-linux-6c2f2b9d62b196296e827f8bb7336a39e80695a9.zip
libblkid: add microsecond resolution for cache entries
The libblkid library uses stat.st_mtine to detect changes on the device. The last update time of of the device in the cache is stored as TIME= tag in the /etc/blkid.tab file. Linux since 2.5.48 supports nanosecond resolution and more precise time is available in the stat.st_mtim timespec struct. This patch add microsecond precision to TIME= tag in the cache file, old format: TIME="<sec>" the new format: TIME="<sec>.<usec>" This change is backwardly compatible. Now, the blkid_verify() function checks stat.st_mtime and stat.st_mtim.tv_nsec/1000. Test: # e2label /dev/sdb1 AAAA old version: # blkid -s LABEL /dev/sdb1; e2label /dev/sdb1 BBBB; blkid -s LABEL /dev/sdb1 /dev/sdb1: LABEL="AAAA" /dev/sdb1: LABEL="AAAA" new version: # blkid -s LABEL /dev/sdb1; e2label /dev/sdb1 BBBB; blkid -s LABEL /dev/sdb1 /dev/sdb1: LABEL="AAAA" /dev/sdb1: LABEL="BBBB" Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/blkid/src/verify.c')
-rw-r--r--shlibs/blkid/src/verify.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/shlibs/blkid/src/verify.c b/shlibs/blkid/src/verify.c
index 273602600..a0cb3fea2 100644
--- a/shlibs/blkid/src/verify.c
+++ b/shlibs/blkid/src/verify.c
@@ -11,6 +11,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
+#include <sys/time.h>
#include <sys/types.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
@@ -73,19 +74,34 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
return NULL;
}
- if ((now >= dev->bid_time) &&
- (st.st_mtime <= dev->bid_time) &&
- ((diff < BLKID_PROBE_MIN) ||
- (dev->bid_flags & BLKID_BID_FL_VERIFIED &&
- diff < BLKID_PROBE_INTERVAL)))
+ if (now >= dev->bid_time &&
+#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+ (st.st_mtime < dev->bid_time ||
+ (st.st_mtime == dev->bid_time &&
+ st.st_mtim.tv_nsec / 1000 <= dev->bid_utime)) &&
+#else
+ st.st_mtime <= dev->bid_time &&
+#endif
+ (diff < BLKID_PROBE_MIN ||
+ (dev->bid_flags & BLKID_BID_FL_VERIFIED &&
+ diff < BLKID_PROBE_INTERVAL)))
return dev;
+#ifndef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
DBG(DEBUG_PROBE,
printf("need to revalidate %s (cache time %lu, stat time %lu,\n\t"
"time since last check %lu)\n",
dev->bid_name, (unsigned long)dev->bid_time,
(unsigned long)st.st_mtime, (unsigned long)diff));
-
+#else
+ DBG(DEBUG_PROBE,
+ printf("need to revalidate %s (cache time %lu.%lu, stat time %lu.%lu,\n\t"
+ "time since last check %lu)\n",
+ dev->bid_name,
+ (unsigned long)dev->bid_time, (unsigned long)dev->bid_utime,
+ (unsigned long)st.st_mtime, (unsigned long)st.st_mtim.tv_nsec / 1000,
+ (unsigned long)diff));
+#endif
if (!cache->probe) {
cache->probe = blkid_new_probe();
@@ -156,8 +172,16 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
found_type:
if (dev) {
+#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+ struct timeval tv;
+ if (!gettimeofday(&tv, NULL)) {
+ dev->bid_time = tv.tv_sec;
+ dev->bid_utime = tv.tv_usec;
+ } else
+#endif
+ dev->bid_time = time(0);
+
dev->bid_devno = st.st_rdev;
- dev->bid_time = time(0);
dev->bid_flags |= BLKID_BID_FL_VERIFIED;
cache->bic_flags |= BLKID_BIC_FL_CHANGED;