static int verify_tag(const char *devname, const char *name, const char *value)
{
blkid_probe pr;
- int fd = -1, rc = -1;
+ int rc = -1;
size_t len;
const char *data;
int errsv = 0;
blkid_probe_enable_partitions(pr, TRUE);
blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
- fd = open(devname, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
- if (fd < 0) {
+ if (blkid_probe_open_device(pr, devname, 0)) {
errsv = errno;
goto done;
}
- if (blkid_probe_set_device(pr, fd, 0, 0))
- goto done;
rc = blkid_do_safeprobe(pr);
if (rc)
goto done;
done:
DBG(EVALUATE, ul_debug("%s: %s verification %s",
devname, name, rc == 0 ? "PASS" : "FAILED"));
- if (fd >= 0)
- close(fd);
blkid_free_probe(pr);
/* for non-root users we use unverified udev links */
const char *type, *value;
struct stat st;
time_t diff, now;
- int fd;
if (!dev || !cache)
return NULL;
DBG(PROBE, ul_debug("blkid_verify: error %m (%d) while "
"trying to stat %s", errno,
dev->bid_name));
- open_err:
- if ((errno == EPERM) || (errno == EACCES) || (errno == ENOENT)) {
- /* We don't have read permission, just return cache data. */
- DBG(PROBE, ul_debug("returning unverified data for %s",
- dev->bid_name));
- return dev;
- }
- blkid_free_dev(dev);
- return NULL;
+ goto dev_err;
}
if (now >= dev->bid_time &&
(long long)diff));
#endif
- if (sysfs_devno_is_dm_private(st.st_rdev, NULL)) {
- blkid_free_dev(dev);
- return NULL;
- }
+ if (sysfs_devno_is_dm_private(st.st_rdev, NULL))
+ goto dev_free;
if (!cache->probe) {
cache->probe = blkid_new_probe();
- if (!cache->probe) {
- blkid_free_dev(dev);
- return NULL;
- }
+ if (!cache->probe)
+ goto dev_free;
}
- fd = open(dev->bid_name, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
- if (fd < 0) {
+ if (blkid_probe_open_device(cache->probe, dev->bid_name, 0)) {
DBG(PROBE, ul_debug("blkid_verify: error %m (%d) while "
"opening %s", errno,
dev->bid_name));
- goto open_err;
- }
-
- if (blkid_probe_set_device(cache->probe, fd, 0, 0)) {
- /* failed to read the device */
- close(fd);
- blkid_free_dev(dev);
- return NULL;
+ goto dev_err;
}
/* remove old cache info */
/* reset prober */
blkid_probe_reset_superblocks_filter(cache->probe);
blkid_probe_set_device(cache->probe, -1, 0, 0);
- close(fd);
return dev;
+
+dev_err:
+ if ((errno == EPERM) || (errno == EACCES) || (errno == ENOENT)) {
+ DBG(PROBE, ul_debug("returning unverified data for %s",
+ dev->bid_name));
+ return dev;
+ }
+dev_free:
+ blkid_free_dev(dev);
+ return NULL;
}
#ifdef TEST_PROGRAM