diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2011-09-22 17:23:35 +0000 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2011-09-22 17:23:35 +0000 |
commit | 14254bd0be6b4979c4a2d90d4b12e70af0a61396 (patch) | |
tree | 9c6cbfa0c593ee2c2fe0e4f74cefda2df8f34796 /libdm/libdm-file.c | |
parent | 07e237d6f449ff2cdb09584cdd80baac0c4a5822 (diff) | |
download | lvm2-14254bd0be6b4979c4a2d90d4b12e70af0a61396.tar.gz lvm2-14254bd0be6b4979c4a2d90d4b12e70af0a61396.tar.xz lvm2-14254bd0be6b4979c4a2d90d4b12e70af0a61396.zip |
Add dm_device_has_holders fn to to check use of the device by another device.
Add dm_device_has_mounted_fs fn to check mounted filesystem on a device.
This requires sysfs directory to be correctly set via dm_set_sysfs_dir
(/sys by default). If sysfs dir is not used or it's set incorrectly,
dm_device_has_{holders,mounted_fs} will return 0!
Diffstat (limited to 'libdm/libdm-file.c')
-rw-r--r-- | libdm/libdm-file.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libdm/libdm-file.c b/libdm/libdm-file.c index 91fdce02..700008bc 100644 --- a/libdm/libdm-file.c +++ b/libdm/libdm-file.c @@ -76,6 +76,26 @@ int dm_create_dir(const char *dir) return 0; } +int dm_is_empty_dir(const char *dir) +{ + struct dirent *dirent; + DIR *d; + + if (!(d = opendir(dir))) { + log_sys_error("opendir", dir); + return 0; + } + + while ((dirent = readdir(d))) + if (strcmp(dirent->d_name, ".") && strcmp(dirent->d_name, "..")) + break; + + if (closedir(d)) + log_sys_error("closedir", dir); + + return dirent ? 0 : 1; +} + int dm_fclose(FILE *stream) { int prev_fail = ferror(stream); |