Ignore wipe operation on non-block devices.
The implementation of make_ext4fs() calls make_ext4fs_internal() by
forcing the |wipe| parameter to true, which is problematic when the
library is used within the emulator (the wipe operation will always
fail on non-Linux platforms).
This patch does the following:
- Add a 'is_block_device_fd()' function to check that a file descriptor
points to a real block device.
- Modify the implementation of wipe_block_device() uses it to return
silently when trying to wipe a non-block-device file.
- Add a WIPE_IS_SUPPORTED flag in wipe.h that indicates whether
block device wiping is supported on the current platform
(for now, this is only the case on Linux).
BUG=NONE
Change-Id: I62b62b7c3e99b465c3b876154231e7c2fe541b23
diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.c
index 3755fee..bb6c863 100644
--- a/ext4_utils/ext4_utils.c
+++ b/ext4_utils/ext4_utils.c
@@ -393,6 +393,20 @@
return size;
}
+int is_block_device_fd(int fd)
+{
+#ifdef USE_MINGW
+ return 0;
+#else
+ struct stat st;
+ int ret = fstat(fd, &st);
+ if (ret < 0)
+ return 0;
+
+ return S_ISBLK(st.st_mode);
+#endif
+}
+
u64 get_file_size(int fd)
{
struct stat buf;