From: Joe Thornber Date: Wed, 21 Nov 2001 16:47:10 +0000 (+0000) Subject: o Removed _check_devfs X-Git-Tag: beta1-pre1~85 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=e20ae3f85e97fe719d1126e69307cfe7f03649d8;p=dm.git o Removed _check_devfs o We now do a stat to see if the device node is there --- diff --git a/lib/libdm.c b/lib/libdm.c index bcfe7d9..7e46a99 100644 --- a/lib/libdm.c +++ b/lib/libdm.c @@ -253,57 +253,6 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt) return NULL; } -/* - * FIXME: This function is copied straight from - * LVM1 without an audit. - */ -static int __check_devfs(void) -{ - int r = 0, len; - char dir[PATH_MAX], line[512]; - char type[32]; - FILE *mounts = NULL; - const char *dev_dir = DM_DIR; - - /* trim the trailing slash off dev_dir, yuck */ - len = strlen(dev_dir) - 1; - while(len && dev_dir[len] == '/') - len--; - - if (!(mounts = fopen("/proc/mounts", "r"))) { - log("Unable to open /proc/mounts to determine " - "if devfs is mounted"); - return 0; - } - - while (!feof(mounts)) { - fgets(line, sizeof(line) - 1, mounts); - if (sscanf(line, "%*s %s %s %*s", dir, type) != 2) - continue; - - if (!strcmp(type, "devfs") && !strncmp(dir, dev_dir, len)) { - r = 1; - break; - } - } - - fclose(mounts); - return r; -} - -/* - * Memo the result of __check_devfs. - */ -static int _check_devfs(void) -{ - static int prev_result = -1; - - if (prev_result >= 0) - return prev_result; - - return (prev_result = __check_devfs()); -} - static void _build_dev_path(char *buffer, size_t len, const char *dev_name) { snprintf(buffer, len, "/dev/%s/%s", DM_DIR, dev_name); @@ -312,12 +261,26 @@ static void _build_dev_path(char *buffer, size_t len, const char *dev_name) static int _add_dev_node(const char *dev_name, dev_t dev) { char path[PATH_MAX]; - - if (_check_devfs()) - return 1; + struct stat info; _build_dev_path(path, sizeof(path), dev_name); + if (stat(path, &info) >= 0) { + if (!S_ISBLK(info.st_mode)) { + log("A non-block device file at '%s' " + "is already present", path); + return 0; + } + + if (info.st_rdev == dev) + return 1; + + if (unlink(path) < 0) { + log("Unable to unlink device node for '%s'", dev_name); + return 0; + } + } + if (mknod(path, S_IFBLK | S_IRUSR | S_IWUSR | S_IRGRP, dev) < 0) { log("Unable to make device node for '%s'", dev_name); return 0; @@ -330,9 +293,6 @@ static int _rm_dev_node(const char *dev_name) { char path[PATH_MAX]; - if (_check_devfs()) - return 1; - _build_dev_path(path, sizeof(path), dev_name); if (unlink(path) < 0) {