return 1;
rc = fstatfs(fd, &vfs) != 0 || vfs.f_type == STATFS_AUTOFS_MAGIC;
close(fd);
+ if (rc)
+ return 1;
- return rc;
+ /* FITRIM on read-only filesystem can fail, and it can fail */
+ if (access(tgt, W_OK) != 0) {
+ if (errno == EROFS)
+ return 1;
+ if (errno == EACCES)
+ return 1;
+ }
+ return 0;
}
static int uniq_fs_target_cmp(
while (mnt_table_next_fs(tab, itr, &fs) == 0) {
const char *src = mnt_fs_get_srcpath(fs),
*tgt = mnt_fs_get_target(fs);
+ char *path;
+ int rc = 1;
if (!tgt || is_unwanted_fs(fs, tgt)) {
mnt_table_remove_fs(tab, fs);
mnt_table_remove_fs(tab, fs);
continue;
}
- }
-
- /* de-duplicate by source */
- mnt_table_uniq_fs(tab, MNT_UNIQ_FORWARD, uniq_fs_source_cmp);
-
- mnt_reset_iter(itr, MNT_ITER_BACKWARD);
-
- /* Do FITRIM */
- while (mnt_table_next_fs(tab, itr, &fs) == 0) {
- const char *src = mnt_fs_get_srcpath(fs),
- *tgt = mnt_fs_get_target(fs);
- char *path;
- int rc = 1;
/* Is it really accessible mountpoint? Not all mountpoints are
* accessible (maybe over mounted by another filesystem) */
if (path && streq_paths(path, tgt))
rc = 0;
free(path);
- if (rc)
+ if (rc) {
+ mnt_table_remove_fs(tab, fs);
continue; /* overlaying mount */
-
- /* FITRIM on read-only filesystem can fail, and it can fail */
- if (access(tgt, W_OK) != 0) {
- if (errno == EROFS)
- continue;
- if (errno == EACCES)
- continue;
}
if (!is_directory(tgt, 1) ||
- !has_discard(src, &wholedisk))
+ !has_discard(src, &wholedisk)) {
+ mnt_table_remove_fs(tab, fs);
continue;
+ }
+ }
+
+ /* de-duplicate by source */
+ mnt_table_uniq_fs(tab, MNT_UNIQ_FORWARD, uniq_fs_source_cmp);
+
+ mnt_reset_iter(itr, MNT_ITER_BACKWARD);
+
+ /* Do FITRIM */
+ while (mnt_table_next_fs(tab, itr, &fs) == 0) {
+ const char *src = mnt_fs_get_srcpath(fs),
+ *tgt = mnt_fs_get_target(fs);
+ int rc;
+
cnt++;
/*