# # old_revision [2a1aa0228658a33cec42dc65322034564ef2447d] # # patch "lib/libdm-common.c" # from [0a431e3a4cc2ae33e2ec9f9bb079b597f711fa61] # to [d7123176df7d6731620675ae44a1950a97a6b8b4] # ============================================================ --- lib/libdm-common.c 0a431e3a4cc2ae33e2ec9f9bb079b597f711fa61 +++ lib/libdm-common.c d7123176df7d6731620675ae44a1950a97a6b8b4 @@ -17,7 +17,10 @@ #include "libdm-targets.h" #include "libdm-common.h" #include "list.h" + +#ifdef linux #include "kdev_t.h" +#endif #include #include @@ -34,6 +37,10 @@ # include #endif +#ifdef __NetBSD__ +#include +#endif + #define DEV_DIR "/dev/" static char _dm_dir[PATH_MAX] = DEV_DIR DM_DIR; @@ -268,6 +275,45 @@ static int _add_dev_node(const char *dev dev_t dev = MKDEV(major, minor); mode_t old_mask; +#ifdef __NetBSD__ + char rpath[PATH_MAX]; + uint32_t raw_major,raw_minor; + dev_t rdev; + char raw_devname[DM_NAME_LEN+1]; /* r + other device name */ + + nbsd_get_dm_major(&raw_major,&raw_minor,DM_CHAR_MAJOR); + rdev = MKDEV(raw_major,minor); + + snprintf(raw_devname,sizeof(raw_devname),"r%s",dev_name); + + _build_dev_path(rpath, sizeof(rpath), raw_devname); + + if (stat(rpath, &info) >= 0) { + if (!S_ISCHR(info.st_mode)) { + log_error("A non-raw device file at '%s' " + "is already present", rpath); + return 0; + } + + /* If right inode already exists we don't touch uid etc. */ + if (info.st_rdev == rdev) + return 1; + + if (unlink(rpath) < 0) { + log_error("Unable to unlink device node for '%s'", + raw_devname); + return 0; + } + } + + old_mask = umask(0); + + if (mknod(rpath, S_IFCHR | mode, rdev) < 0) { + log_error("Unable to make device node for '%s'", raw_devname); + return 0; + } +#endif + _build_dev_path(path, sizeof(path), dev_name); if (stat(path, &info) >= 0) { @@ -289,10 +335,12 @@ static int _add_dev_node(const char *dev } old_mask = umask(0); + if (mknod(path, S_IFBLK | mode, dev) < 0) { log_error("Unable to make device node for '%s'", dev_name); return 0; - } + } + umask(old_mask); if (chown(path, uid, gid) < 0) { @@ -316,6 +364,42 @@ static int _rename_dev_node(const char * char newpath[PATH_MAX]; struct stat info; +#ifdef __NetBSD__ + char rpath[PATH_MAX]; + char nrpath[PATH_MAX]; + char raw_devname[DM_NAME_LEN+1]; /* r + other device name */ + char nraw_devname[DM_NAME_LEN+1]; /* r + other device name */ + + snprintf(nraw_devname,sizeof(raw_devname),"r%s",new_name); + snprintf(raw_devname,sizeof(raw_devname),"r%s",old_name); + + _build_dev_path(nrpath, sizeof(nrpath), nraw_devname); + _build_dev_path(rpath, sizeof(rpath), raw_devname); + + if (stat(nrpath, &info) == 0) { + if (S_ISBLK(info.st_mode)) { + log_error("A block device file at '%s' " + "is present where raw device should be.", newpath); + return 0; + } + + if (unlink(nrpath) < 0) { + log_error("Unable to unlink device node for '%s'", + nraw_devname); + return 0; + } + } + + if (rename(rpath, nrpath) < 0) { + log_error("Unable to rename device node from '%s' to '%s'", + raw_devname, nraw_devname); + return 0; + } + + log_debug("Renamed %s to %s", rpath, nrpath); + +#endif + _build_dev_path(oldpath, sizeof(oldpath), old_name); _build_dev_path(newpath, sizeof(newpath), new_name); @@ -353,6 +437,25 @@ static int _rm_dev_node(const char *dev_ char path[PATH_MAX]; struct stat info; +#ifdef __NetBSD__ + char rpath[PATH_MAX]; + char raw_devname[DM_NAME_LEN+1]; /* r + other device name */ + + snprintf(raw_devname,sizeof(raw_devname),"r%s",dev_name); + + _build_dev_path(rpath, sizeof(rpath), raw_devname); + + if (stat(rpath, &info) < 0) + return 1; + + if (unlink(rpath) < 0) { + log_error("Unable to unlink device node for '%s'", raw_devname); + return 0; + } + + log_debug("Removed %s", rpath); +#endif + _build_dev_path(path, sizeof(path), dev_name); if (stat(path, &info) < 0)