aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2021-05-22 14:29:53 +0000
committerBrian Behlendorf <behlendorf1@llnl.gov>2021-06-11 16:10:13 +0000
commit64dfdaba372f07f91a6eab598b3480693b1d14c8 (patch)
tree2ce1d5f5d44c79a4211ef5f36a539e7149bff516 /lib
parentbf80fb53f59c1d98c03758dec6322cfacec4ccf9 (diff)
Diffstat (limited to 'lib')
-rw-r--r--lib/libzutil/os/linux/zutil_import_os.c12
-rw-r--r--lib/libzutil/zutil_import.c15
2 files changed, 16 insertions, 11 deletions
diff --git a/lib/libzutil/os/linux/zutil_import_os.c b/lib/libzutil/os/linux/zutil_import_os.c
index 433a72282bb7..5defb526f210 100644
--- a/lib/libzutil/os/linux/zutil_import_os.c
+++ b/lib/libzutil/os/linux/zutil_import_os.c
@@ -114,9 +114,11 @@ zpool_open_func(void *arg)
/*
* Ignore failed stats. We only want regular files and block devices.
+ * Ignore files that are too small to hold a zpool.
*/
if (stat64(rn->rn_name, &statbuf) != 0 ||
- (!S_ISREG(statbuf.st_mode) && !S_ISBLK(statbuf.st_mode)))
+ (!S_ISREG(statbuf.st_mode) && !S_ISBLK(statbuf.st_mode)) ||
+ (S_ISREG(statbuf.st_mode) && statbuf.st_size < SPA_MINDEVSIZE))
return;
/*
@@ -132,14 +134,6 @@ zpool_open_func(void *arg)
if (fd < 0)
return;
- /*
- * This file is too small to hold a zpool
- */
- if (S_ISREG(statbuf.st_mode) && statbuf.st_size < SPA_MINDEVSIZE) {
- (void) close(fd);
- return;
- }
-
error = zpool_read_label(fd, &config, &num_labels);
if (error != 0) {
(void) close(fd);
diff --git a/lib/libzutil/zutil_import.c b/lib/libzutil/zutil_import.c
index 9d7fcb8d9685..871a75ab2326 100644
--- a/lib/libzutil/zutil_import.c
+++ b/lib/libzutil/zutil_import.c
@@ -1243,10 +1243,21 @@ zpool_find_import_scan_dir(libpc_handle_t *hdl, pthread_mutex_t *lock,
while ((dp = readdir64(dirp)) != NULL) {
const char *name = dp->d_name;
- if (name[0] == '.' &&
- (name[1] == 0 || (name[1] == '.' && name[2] == 0)))
+ if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
continue;
+ switch (dp->d_type) {
+ case DT_UNKNOWN:
+ case DT_BLK:
+#ifdef __FreeBSD__
+ case DT_CHR:
+#endif
+ case DT_REG:
+ break;
+ default:
+ continue;
+ }
+
zpool_find_import_scan_add_slice(hdl, lock, cache, path, name,
order);
}