mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-25 23:52:17 +00:00
add mounted-checking for btrfs-vol
Adding a mounted device is dangerous because it will destroy the filesystem on that mounted device. So we add mounted-checking for btrfs-vol. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
This commit is contained in:
parent
595cb1df15
commit
ddf85067bb
18
btrfs-vol.c
18
btrfs-vol.c
@ -108,10 +108,24 @@ int main(int ac, char **av)
|
|||||||
if (device && strcmp(device, "missing") == 0 &&
|
if (device && strcmp(device, "missing") == 0 &&
|
||||||
cmd == BTRFS_IOC_RM_DEV) {
|
cmd == BTRFS_IOC_RM_DEV) {
|
||||||
fprintf(stderr, "removing missing devices from %s\n", mnt);
|
fprintf(stderr, "removing missing devices from %s\n", mnt);
|
||||||
} else if (device) {
|
} else if (cmd != BTRFS_IOC_BALANCE) {
|
||||||
|
if (cmd == BTRFS_IOC_ADD_DEV) {
|
||||||
|
ret = check_mounted(device);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"error checking %s mount status\n",
|
||||||
|
device);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (ret == 1) {
|
||||||
|
fprintf(stderr, "%s is mounted\n", device);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
devfd = open(device, O_RDWR);
|
devfd = open(device, O_RDWR);
|
||||||
if (!devfd) {
|
if (devfd < 0) {
|
||||||
fprintf(stderr, "Unable to open device %s\n", device);
|
fprintf(stderr, "Unable to open device %s\n", device);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
ret = fstat(devfd, &st);
|
ret = fstat(devfd, &st);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
Loading…
Reference in New Issue
Block a user