summaryrefslogtreecommitdiffstats
path: root/libdm/libdm-file.c
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2011-09-22 17:23:35 +0000
committerPeter Rajnoha <prajnoha@redhat.com>2011-09-22 17:23:35 +0000
commit14254bd0be6b4979c4a2d90d4b12e70af0a61396 (patch)
tree9c6cbfa0c593ee2c2fe0e4f74cefda2df8f34796 /libdm/libdm-file.c
parent07e237d6f449ff2cdb09584cdd80baac0c4a5822 (diff)
downloadlvm2-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.c20
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);