1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-11 09:18:25 +03:00

Rename device node during a DM_RENAME command.

This commit is contained in:
Patrick Caulfield 2002-04-11 12:45:18 +00:00
parent 3ed065de37
commit ec43efbb20
3 changed files with 41 additions and 1 deletions

View File

@ -354,8 +354,13 @@ int dm_task_run(struct dm_task *dmt)
case DM_DEVICE_REMOVE:
rm_dev_node(dmt->dev_name);
break;
case DM_DEVICE_RENAME:
rename_dev_node(dmt->dev_name, dmt->newname);
break;
}
dmt->dmi = dmi;
close(fd);
return 1;

View File

@ -195,6 +195,40 @@ int add_dev_node(const char *dev_name, dev_t dev)
return 1;
}
int rename_dev_node(const char *old_name, const char *new_name)
{
char oldpath[PATH_MAX];
char newpath[PATH_MAX];
struct stat info;
_build_dev_path(oldpath, sizeof(oldpath), old_name);
_build_dev_path(newpath, sizeof(newpath), new_name);
if (stat(newpath, &info) >= 0) {
if (!S_ISBLK(info.st_mode)) {
log_error("A non-block device file at '%s' "
"is already present", newpath);
return 0;
}
if (unlink(newpath) < 0) {
if (errno == EPERM) { /* devfs, entry has already been renamed */
return 1;
}
log_error("Unable to unlink device node for '%s'",
new_name);
return 0;
}
}
if (rename(oldpath, newpath) < 0) {
log_error("Unable to rename device node from '%s' to '%s'", old_name, new_name);
return 0;
}
return 1;
}
int rm_dev_node(const char *dev_name)
{
char path[PATH_MAX];

View File

@ -25,6 +25,7 @@ extern struct target *create_target(uint64_t start,
int add_dev_node(const char *dev_name, dev_t dev);
int rm_dev_node(const char *dev_name);
int rename_dev_node(const char *old_name, const char *new_name);
#define DM_LIB_VERSION @DM_LIB_VERSION@