2003-01-24 00:45:16 +03:00
|
|
|
/*
|
|
|
|
* devname.c - get a dev by its device inode name
|
|
|
|
*
|
|
|
|
* Copyright (C) Andries Brouwer
|
2003-01-26 02:44:33 +03:00
|
|
|
* Copyright (C) 1999, 2000, 2001, 2002, 2003 Theodore Ts'o
|
2003-01-24 00:45:16 +03:00
|
|
|
* Copyright (C) 2001 Andreas Dilger
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the
|
|
|
|
* GNU Lesser General Public License.
|
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
2006-03-08 22:17:28 +03:00
|
|
|
#define _GNU_SOURCE 1
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2006-03-13 07:25:15 +03:00
|
|
|
#include <limits.h>
|
2003-01-24 00:45:16 +03:00
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#if HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_MKDEV_H
|
|
|
|
#include <sys/mkdev.h>
|
|
|
|
#endif
|
|
|
|
#include <time.h>
|
|
|
|
|
2003-01-26 09:54:39 +03:00
|
|
|
#include "blkidP.h"
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2006-03-08 22:17:28 +03:00
|
|
|
#ifdef HAVE_DEVMAPPER
|
|
|
|
#include <libdevmapper.h>
|
|
|
|
#endif
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
/*
|
|
|
|
* Find a dev struct in the cache by device name, if available.
|
2003-02-13 07:51:21 +03:00
|
|
|
*
|
|
|
|
* If there is no entry with the specified device name, and the create
|
|
|
|
* flag is set, then create an empty device entry.
|
2003-01-24 00:45:16 +03:00
|
|
|
*/
|
2003-02-16 08:47:07 +03:00
|
|
|
blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
2003-02-13 07:51:21 +03:00
|
|
|
blkid_dev dev = NULL, tmp;
|
2003-01-24 00:45:16 +03:00
|
|
|
struct list_head *p;
|
|
|
|
|
|
|
|
if (!cache || !devname)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
list_for_each(p, &cache->bic_devs) {
|
2003-02-13 07:51:21 +03:00
|
|
|
tmp = list_entry(p, struct blkid_struct_dev, bid_devs);
|
2003-01-24 00:45:16 +03:00
|
|
|
if (strcmp(tmp->bid_name, devname))
|
|
|
|
continue;
|
|
|
|
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_DEVNAME,
|
|
|
|
printf("found devname %s in cache\n", tmp->bid_name));
|
2003-02-13 07:51:21 +03:00
|
|
|
dev = tmp;
|
2003-01-24 00:45:16 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
if (!dev && (flags & BLKID_DEV_CREATE)) {
|
|
|
|
dev = blkid_new_dev();
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
2006-03-13 07:25:15 +03:00
|
|
|
dev->bid_time = INT_MIN;
|
2003-02-13 07:51:21 +03:00
|
|
|
dev->bid_name = blkid_strdup(devname);
|
|
|
|
dev->bid_cache = cache;
|
|
|
|
list_add_tail(&dev->bid_devs, &cache->bic_devs);
|
|
|
|
cache->bic_flags |= BLKID_BIC_FL_CHANGED;
|
|
|
|
}
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
if (flags & BLKID_DEV_VERIFY)
|
2005-01-28 03:51:47 +03:00
|
|
|
dev = blkid_verify(cache, dev);
|
2003-02-13 07:51:21 +03:00
|
|
|
return dev;
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 22:17:28 +03:00
|
|
|
#ifdef HAVE_DEVMAPPER
|
|
|
|
static int dm_device_is_leaf(const dev_t dev);
|
|
|
|
#endif
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
/*
|
|
|
|
* Probe a single block device to add to the device cache.
|
|
|
|
*/
|
2003-02-14 09:31:45 +03:00
|
|
|
static void probe_one(blkid_cache cache, const char *ptname,
|
2005-05-08 01:06:27 +04:00
|
|
|
dev_t devno, int pri, int only_if_new)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
2003-02-13 07:51:21 +03:00
|
|
|
blkid_dev dev = NULL;
|
|
|
|
struct list_head *p;
|
2003-01-24 00:45:16 +03:00
|
|
|
const char **dir;
|
|
|
|
char *devname = NULL;
|
|
|
|
|
|
|
|
/* See if we already have this device number in the cache. */
|
2003-02-13 07:51:21 +03:00
|
|
|
list_for_each(p, &cache->bic_devs) {
|
|
|
|
blkid_dev tmp = list_entry(p, struct blkid_struct_dev,
|
|
|
|
bid_devs);
|
2006-03-08 22:17:28 +03:00
|
|
|
#ifdef HAVE_DEVMAPPER
|
|
|
|
if (!dm_device_is_leaf(devno))
|
|
|
|
continue;
|
|
|
|
#endif
|
2003-02-13 07:51:21 +03:00
|
|
|
if (tmp->bid_devno == devno) {
|
2005-05-08 01:06:27 +04:00
|
|
|
if (only_if_new)
|
|
|
|
return;
|
2005-01-28 03:51:47 +03:00
|
|
|
dev = blkid_verify(cache, tmp);
|
2003-02-13 07:51:21 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dev && dev->bid_devno == devno)
|
2003-02-14 09:31:45 +03:00
|
|
|
goto set_pri;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a quick look at /dev/ptname for the device number. We check
|
|
|
|
* all of the likely device directories. If we don't find it, or if
|
|
|
|
* the stat information doesn't check out, use blkid_devno_to_devname()
|
|
|
|
* to find it via an exhaustive search for the device major/minor.
|
|
|
|
*/
|
2003-02-13 07:51:21 +03:00
|
|
|
for (dir = blkid_devdirs; *dir; dir++) {
|
2003-01-24 00:45:16 +03:00
|
|
|
struct stat st;
|
|
|
|
char device[256];
|
|
|
|
|
|
|
|
sprintf(device, "%s/%s", *dir, ptname);
|
2003-02-16 08:47:07 +03:00
|
|
|
if ((dev = blkid_get_dev(cache, device, BLKID_DEV_FIND)) &&
|
2003-01-24 00:45:16 +03:00
|
|
|
dev->bid_devno == devno)
|
2003-02-14 09:31:45 +03:00
|
|
|
goto set_pri;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-01-06 01:45:32 +03:00
|
|
|
if (stat(device, &st) == 0 && S_ISBLK(st.st_mode) &&
|
|
|
|
st.st_rdev == devno) {
|
2003-02-13 07:51:21 +03:00
|
|
|
devname = blkid_strdup(device);
|
2003-01-24 00:45:16 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!devname) {
|
|
|
|
devname = blkid_devno_to_devname(devno);
|
|
|
|
if (!devname)
|
2003-02-14 09:31:45 +03:00
|
|
|
return;
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
2003-02-16 08:47:07 +03:00
|
|
|
dev = blkid_get_dev(cache, devname, BLKID_DEV_NORMAL);
|
2003-02-13 07:51:21 +03:00
|
|
|
free(devname);
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-02-14 09:31:45 +03:00
|
|
|
set_pri:
|
|
|
|
if (!pri && !strncmp(ptname, "md", 2))
|
|
|
|
pri = BLKID_PRI_MD;
|
2003-03-06 20:58:03 +03:00
|
|
|
if (dev)
|
|
|
|
dev->bid_pri = pri;
|
2003-02-14 09:31:45 +03:00
|
|
|
return;
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
|
2006-03-08 22:17:28 +03:00
|
|
|
#ifdef HAVE_DEVMAPPER
|
2006-03-19 23:26:26 +03:00
|
|
|
static void dm_quiet_log(int level, const char *file, int line,
|
|
|
|
const char *f, ...)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-08 22:17:28 +03:00
|
|
|
/*
|
|
|
|
* device-mapper support
|
|
|
|
*/
|
|
|
|
static int dm_device_has_dep(const dev_t dev, const char *name)
|
|
|
|
{
|
|
|
|
struct dm_task *task;
|
|
|
|
struct dm_deps *deps;
|
|
|
|
struct dm_info info;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
task = dm_task_create(DM_DEVICE_DEPS);
|
|
|
|
if (!task)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dm_task_set_name(task, name);
|
|
|
|
dm_task_run(task);
|
|
|
|
dm_task_get_info(task, &info);
|
|
|
|
|
|
|
|
if (!info.exists) {
|
|
|
|
dm_task_destroy(task);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
deps = dm_task_get_deps(task);
|
|
|
|
if (!deps || deps->count == 0) {
|
|
|
|
dm_task_destroy(task);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < deps->count; i++) {
|
|
|
|
dev_t dep_dev = deps->device[i];
|
|
|
|
|
|
|
|
if (dev == dep_dev) {
|
|
|
|
dm_task_destroy(task);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dm_task_destroy(task);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dm_device_is_leaf(const dev_t dev)
|
|
|
|
{
|
|
|
|
struct dm_task *task;
|
|
|
|
struct dm_names *names;
|
|
|
|
unsigned int next = 0;
|
|
|
|
int n, ret = 1;
|
|
|
|
|
2006-03-19 23:26:26 +03:00
|
|
|
dm_log_init(dm_quiet_log);
|
2006-03-08 22:17:28 +03:00
|
|
|
task = dm_task_create(DM_DEVICE_LIST);
|
|
|
|
if (!task)
|
|
|
|
return 1;
|
2006-03-19 23:26:26 +03:00
|
|
|
dm_log_init(0);
|
2006-03-08 22:17:28 +03:00
|
|
|
|
|
|
|
dm_task_run(task);
|
|
|
|
names = dm_task_get_names(task);
|
|
|
|
if (!names || !names->dev) {
|
|
|
|
dm_task_destroy(task);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
do {
|
|
|
|
names = (void *)names + next;
|
|
|
|
|
|
|
|
if (dm_device_has_dep(dev, names->name))
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
next = names->next;
|
|
|
|
} while (next);
|
|
|
|
|
|
|
|
dm_task_destroy(task);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static dev_t dm_get_devno(const char *name)
|
|
|
|
{
|
|
|
|
struct dm_task *task;
|
|
|
|
struct dm_info info;
|
|
|
|
dev_t ret = 0;
|
|
|
|
|
|
|
|
task = dm_task_create(DM_DEVICE_INFO);
|
|
|
|
if (!task)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
dm_task_set_name(task, name);
|
|
|
|
dm_task_run(task);
|
|
|
|
dm_task_get_info(task, &info);
|
|
|
|
|
|
|
|
if (!info.exists) {
|
|
|
|
dm_task_destroy(task);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = makedev(info.major, info.minor);
|
|
|
|
|
|
|
|
dm_task_destroy(task);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dm_probe_all(blkid_cache cache, int only_if_new)
|
|
|
|
{
|
|
|
|
struct dm_task *task;
|
|
|
|
struct dm_names *names;
|
|
|
|
unsigned int next = 0;
|
|
|
|
int n;
|
|
|
|
|
2006-03-19 23:26:26 +03:00
|
|
|
dm_log_init(dm_quiet_log);
|
2006-03-08 22:17:28 +03:00
|
|
|
task = dm_task_create(DM_DEVICE_LIST);
|
|
|
|
if (!task)
|
|
|
|
return;
|
2006-03-19 23:26:26 +03:00
|
|
|
dm_log_init(0);
|
2006-03-08 22:17:28 +03:00
|
|
|
|
|
|
|
dm_task_run(task);
|
|
|
|
names = dm_task_get_names(task);
|
|
|
|
if (!names || !names->dev) {
|
|
|
|
dm_task_destroy(task);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
do {
|
|
|
|
int rc;
|
|
|
|
char *device = NULL;
|
|
|
|
dev_t dev = 0;
|
|
|
|
|
|
|
|
names = (void *)names + next;
|
|
|
|
|
2006-09-12 09:30:53 +04:00
|
|
|
rc = asprintf(&device, "mapper/%s", names->name);
|
2006-03-08 22:17:28 +03:00
|
|
|
if (rc < 0)
|
|
|
|
goto try_next;
|
|
|
|
|
|
|
|
dev = dm_get_devno(names->name);
|
|
|
|
if (dev == 0)
|
|
|
|
goto try_next;
|
|
|
|
|
|
|
|
if (!dm_device_is_leaf(dev))
|
|
|
|
goto try_next;
|
|
|
|
|
|
|
|
probe_one(cache, device, dev, BLKID_PRI_DM, only_if_new);
|
|
|
|
|
|
|
|
try_next:
|
2007-03-07 03:56:18 +03:00
|
|
|
free(device);
|
2006-03-08 22:17:28 +03:00
|
|
|
next = names->next;
|
|
|
|
} while (next);
|
|
|
|
|
|
|
|
dm_task_destroy(task);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_DEVMAPPER */
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
#define PROC_PARTITIONS "/proc/partitions"
|
|
|
|
#define VG_DIR "/proc/lvm/VGs"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function initializes the UUID cache with devices from the LVM
|
|
|
|
* proc hierarchy. We currently depend on the names of the LVM
|
|
|
|
* hierarchy giving us the device structure in /dev. (XXX is this a
|
|
|
|
* safe thing to do?)
|
|
|
|
*/
|
|
|
|
#ifdef VG_DIR
|
|
|
|
#include <dirent.h>
|
2003-02-13 07:51:21 +03:00
|
|
|
static dev_t lvm_get_devno(const char *lvm_device)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
|
|
|
FILE *lvf;
|
|
|
|
char buf[1024];
|
2003-02-13 07:51:21 +03:00
|
|
|
int ma, mi;
|
|
|
|
dev_t ret = 0;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_DEVNAME, printf("opening %s\n", lvm_device));
|
2003-01-24 00:45:16 +03:00
|
|
|
if ((lvf = fopen(lvm_device, "r")) == NULL) {
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_DEVNAME, printf("%s: (%d) %s\n", lvm_device, errno,
|
|
|
|
strerror(errno)));
|
2003-02-13 07:51:21 +03:00
|
|
|
return 0;
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), lvf)) {
|
2003-02-13 07:51:21 +03:00
|
|
|
if (sscanf(buf, "device: %d:%d", &ma, &mi) == 2) {
|
|
|
|
ret = makedev(ma, mi);
|
2003-01-24 00:45:16 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(lvf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-05-08 01:06:27 +04:00
|
|
|
static void lvm_probe_all(blkid_cache cache, int only_if_new)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
|
|
|
DIR *vg_list;
|
|
|
|
struct dirent *vg_iter;
|
|
|
|
int vg_len = strlen(VG_DIR);
|
2003-02-13 07:51:21 +03:00
|
|
|
dev_t dev;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
if ((vg_list = opendir(VG_DIR)) == NULL)
|
|
|
|
return;
|
|
|
|
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_DEVNAME, printf("probing LVM devices under %s\n", VG_DIR));
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
while ((vg_iter = readdir(vg_list)) != NULL) {
|
|
|
|
DIR *lv_list;
|
|
|
|
char *vdirname;
|
|
|
|
char *vg_name;
|
|
|
|
struct dirent *lv_iter;
|
|
|
|
|
|
|
|
vg_name = vg_iter->d_name;
|
|
|
|
if (!strcmp(vg_name, ".") || !strcmp(vg_name, ".."))
|
|
|
|
continue;
|
|
|
|
vdirname = malloc(vg_len + strlen(vg_name) + 8);
|
|
|
|
if (!vdirname)
|
|
|
|
goto exit;
|
|
|
|
sprintf(vdirname, "%s/%s/LVs", VG_DIR, vg_name);
|
|
|
|
|
|
|
|
lv_list = opendir(vdirname);
|
|
|
|
free(vdirname);
|
|
|
|
if (lv_list == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
while ((lv_iter = readdir(lv_list)) != NULL) {
|
|
|
|
char *lv_name, *lvm_device;
|
|
|
|
|
|
|
|
lv_name = lv_iter->d_name;
|
|
|
|
if (!strcmp(lv_name, ".") || !strcmp(lv_name, ".."))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lvm_device = malloc(vg_len + strlen(vg_name) +
|
|
|
|
strlen(lv_name) + 8);
|
|
|
|
if (!lvm_device) {
|
|
|
|
closedir(lv_list);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
sprintf(lvm_device, "%s/%s/LVs/%s", VG_DIR, vg_name,
|
|
|
|
lv_name);
|
2003-02-13 07:51:21 +03:00
|
|
|
dev = lvm_get_devno(lvm_device);
|
2003-01-24 00:45:16 +03:00
|
|
|
sprintf(lvm_device, "%s/%s", vg_name, lv_name);
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_DEVNAME, printf("LVM dev %s: devno 0x%04X\n",
|
|
|
|
lvm_device,
|
|
|
|
(unsigned int) dev));
|
2005-05-08 01:06:27 +04:00
|
|
|
probe_one(cache, lvm_device, dev, BLKID_PRI_LVM,
|
|
|
|
only_if_new);
|
2003-01-24 00:45:16 +03:00
|
|
|
free(lvm_device);
|
|
|
|
}
|
|
|
|
closedir(lv_list);
|
|
|
|
}
|
|
|
|
exit:
|
|
|
|
closedir(vg_list);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-26 02:44:33 +03:00
|
|
|
#define PROC_EVMS_VOLUMES "/proc/evms/volumes"
|
|
|
|
|
|
|
|
static int
|
2005-05-08 01:06:27 +04:00
|
|
|
evms_probe_all(blkid_cache cache, int only_if_new)
|
2003-01-26 02:44:33 +03:00
|
|
|
{
|
|
|
|
char line[100];
|
|
|
|
int ma, mi, sz, num = 0;
|
|
|
|
FILE *procpt;
|
|
|
|
char device[110];
|
|
|
|
|
|
|
|
procpt = fopen(PROC_EVMS_VOLUMES, "r");
|
|
|
|
if (!procpt)
|
|
|
|
return 0;
|
|
|
|
while (fgets(line, sizeof(line), procpt)) {
|
|
|
|
if (sscanf (line, " %d %d %d %*s %*s %[^\n ]",
|
|
|
|
&ma, &mi, &sz, device) != 4)
|
|
|
|
continue;
|
|
|
|
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_DEVNAME, printf("Checking partition %s (%d, %d)\n",
|
|
|
|
device, ma, mi));
|
2003-01-26 02:44:33 +03:00
|
|
|
|
2005-05-08 01:06:27 +04:00
|
|
|
probe_one(cache, device, makedev(ma, mi), BLKID_PRI_EVMS,
|
|
|
|
only_if_new);
|
2003-01-26 02:44:33 +03:00
|
|
|
num++;
|
|
|
|
}
|
|
|
|
fclose(procpt);
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
/*
|
|
|
|
* Read the device data for all available block devices in the system.
|
|
|
|
*/
|
2005-05-08 01:06:27 +04:00
|
|
|
static int probe_all(blkid_cache cache, int only_if_new)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
|
|
|
FILE *proc;
|
2003-02-14 09:31:45 +03:00
|
|
|
char line[1024];
|
|
|
|
char ptname0[128], ptname1[128], *ptname = 0;
|
2003-03-06 19:09:18 +03:00
|
|
|
char *ptnames[2];
|
2003-02-14 09:31:45 +03:00
|
|
|
dev_t devs[2];
|
|
|
|
int ma, mi;
|
|
|
|
unsigned long long sz;
|
|
|
|
int lens[2] = { 0, 0 };
|
|
|
|
int which = 0, last = 0;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-03-06 19:09:18 +03:00
|
|
|
ptnames[0] = ptname0;
|
|
|
|
ptnames[1] = ptname1;
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
if (!cache)
|
|
|
|
return -BLKID_ERR_PARAM;
|
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
if (cache->bic_flags & BLKID_BIC_FL_PROBED &&
|
|
|
|
time(0) - cache->bic_time < BLKID_PROBE_INTERVAL)
|
2003-01-24 00:45:16 +03:00
|
|
|
return 0;
|
|
|
|
|
2003-02-23 01:15:20 +03:00
|
|
|
blkid_read_cache(cache);
|
2006-03-08 22:17:28 +03:00
|
|
|
#ifdef HAVE_DEVMAPPER
|
|
|
|
dm_probe_all(cache, only_if_new);
|
|
|
|
#endif
|
2005-05-08 01:06:27 +04:00
|
|
|
evms_probe_all(cache, only_if_new);
|
2003-01-24 00:45:16 +03:00
|
|
|
#ifdef VG_DIR
|
2005-05-08 01:06:27 +04:00
|
|
|
lvm_probe_all(cache, only_if_new);
|
2003-01-24 00:45:16 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
proc = fopen(PROC_PARTITIONS, "r");
|
|
|
|
if (!proc)
|
|
|
|
return -BLKID_ERR_PROC;
|
|
|
|
|
2003-02-14 09:31:45 +03:00
|
|
|
while (fgets(line, sizeof(line), proc)) {
|
|
|
|
last = which;
|
|
|
|
which ^= 1;
|
|
|
|
ptname = ptnames[which];
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-01-13 00:58:33 +03:00
|
|
|
if (sscanf(line, " %d %d %llu %128[^\n ]",
|
2003-02-14 09:31:45 +03:00
|
|
|
&ma, &mi, &sz, ptname) != 4)
|
|
|
|
continue;
|
|
|
|
devs[which] = makedev(ma, mi);
|
|
|
|
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_DEVNAME, printf("read partition name %s\n", ptname));
|
2003-02-14 09:31:45 +03:00
|
|
|
|
2007-11-29 21:57:35 +03:00
|
|
|
/* Skip whole disk devs unless they have no partitions.
|
|
|
|
* If base name of device has changed, also
|
2003-02-14 09:31:45 +03:00
|
|
|
* check previous dev to see if it didn't have a partn.
|
2007-11-29 21:57:35 +03:00
|
|
|
* heuristic: partition name ends in a digit, & partition
|
|
|
|
* names contain whole device name as substring.
|
2003-02-14 09:31:45 +03:00
|
|
|
*
|
|
|
|
* Skip extended partitions.
|
|
|
|
* heuristic: size is 1
|
|
|
|
*
|
|
|
|
* FIXME: skip /dev/{ida,cciss,rd} whole-disk devs
|
|
|
|
*/
|
|
|
|
|
|
|
|
lens[which] = strlen(ptname);
|
2007-11-29 21:57:35 +03:00
|
|
|
|
|
|
|
/* ends in a digit, clearly a partition, so check */
|
2003-02-14 09:31:45 +03:00
|
|
|
if (isdigit(ptname[lens[which] - 1])) {
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_DEVNAME,
|
|
|
|
printf("partition dev %s, devno 0x%04X\n",
|
|
|
|
ptname, (unsigned int) devs[which]));
|
2003-02-14 09:31:45 +03:00
|
|
|
|
|
|
|
if (sz > 1)
|
2005-05-08 01:06:27 +04:00
|
|
|
probe_one(cache, ptname, devs[which], 0,
|
|
|
|
only_if_new);
|
2007-11-29 21:57:35 +03:00
|
|
|
lens[which] = 0; /* mark as checked */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If last was not checked because it looked like a whole-disk
|
|
|
|
* dev, and the device's base name has changed,
|
|
|
|
* check last as well.
|
|
|
|
*/
|
|
|
|
if (lens[last] && strncmp(ptnames[last], ptname, lens[last])) {
|
2003-02-22 21:19:53 +03:00
|
|
|
DBG(DEBUG_DEVNAME,
|
|
|
|
printf("whole dev %s, devno 0x%04X\n",
|
|
|
|
ptnames[last], (unsigned int) devs[last]));
|
2005-05-08 01:06:27 +04:00
|
|
|
probe_one(cache, ptnames[last], devs[last], 0,
|
|
|
|
only_if_new);
|
2003-02-14 09:31:45 +03:00
|
|
|
lens[last] = 0;
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
}
|
2003-02-14 09:31:45 +03:00
|
|
|
|
|
|
|
/* Handle the last device if it wasn't partitioned */
|
|
|
|
if (lens[which])
|
2005-05-08 01:06:27 +04:00
|
|
|
probe_one(cache, ptname, devs[which], 0, only_if_new);
|
2003-02-14 09:31:45 +03:00
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
fclose(proc);
|
2005-05-08 01:06:27 +04:00
|
|
|
blkid_flush_cache(cache);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2005-05-08 01:06:27 +04:00
|
|
|
int blkid_probe_all(blkid_cache cache)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DBG(DEBUG_PROBE, printf("Begin blkid_probe_all()\n"));
|
|
|
|
ret = probe_all(cache, 0);
|
2003-02-13 07:51:21 +03:00
|
|
|
cache->bic_time = time(0);
|
|
|
|
cache->bic_flags |= BLKID_BIC_FL_PROBED;
|
2005-05-08 01:06:27 +04:00
|
|
|
DBG(DEBUG_PROBE, printf("End blkid_probe_all()\n"));
|
|
|
|
return ret;
|
2003-01-24 00:45:16 +03:00
|
|
|
}
|
|
|
|
|
2005-05-08 01:06:27 +04:00
|
|
|
int blkid_probe_all_new(blkid_cache cache)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DBG(DEBUG_PROBE, printf("Begin blkid_probe_all_new()\n"));
|
|
|
|
ret = probe_all(cache, 1);
|
|
|
|
DBG(DEBUG_PROBE, printf("End blkid_probe_all_new()\n"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-24 00:45:16 +03:00
|
|
|
#ifdef TEST_PROGRAM
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2003-01-26 09:54:39 +03:00
|
|
|
blkid_cache cache = NULL;
|
2003-02-23 01:15:20 +03:00
|
|
|
int ret;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-02-22 21:19:53 +03:00
|
|
|
blkid_debug_mask = DEBUG_ALL;
|
2003-01-24 00:45:16 +03:00
|
|
|
if (argc != 1) {
|
|
|
|
fprintf(stderr, "Usage: %s\n"
|
|
|
|
"Probe all devices and exit\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-02-23 01:15:20 +03:00
|
|
|
if ((ret = blkid_get_cache(&cache, "/dev/null")) != 0) {
|
|
|
|
fprintf(stderr, "%s: error creating cache (%d)\n",
|
|
|
|
argv[0], ret);
|
2003-02-13 07:51:21 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (blkid_probe_all(cache) < 0)
|
2003-01-24 00:45:16 +03:00
|
|
|
printf("%s: error probing devices\n", argv[0]);
|
|
|
|
|
2003-02-13 07:51:21 +03:00
|
|
|
blkid_put_cache(cache);
|
2003-01-24 00:45:16 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|