From 2d22ac64e4d6e6732640f38b7232b5bcdc84a877 Mon Sep 17 00:00:00 2001 From: Stanislav Brabec Date: Mon, 10 Jun 2019 21:59:45 +0200 Subject: fstrim -a/-A: Skip read-only volumes Calling TRIM on some read-only volumes can fail with: fstrim: /win: FITRIM ioctl failed: Bad file descriptor Skipping all read-only mounts seems to be safe and logical strategy. Fixes opensuse#1106214. Signed-off-by: Stanislav Brabec --- sys-utils/fstrim.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'sys-utils') diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c index ff029015e..ea29a5695 100644 --- a/sys-utils/fstrim.c +++ b/sys-utils/fstrim.c @@ -311,6 +311,14 @@ static int fstrim_all(struct fstrim_control *ctl) if (rc) continue; /* overlaying mount */ + /* FSTRIM on read-only filesystem can fail, and it can fail */ + if (access(path, W_OK) != 0) { + if (errno == EROFS) + continue; + if (errno == EACCES) + continue; + } + if (!has_discard(src, &wholedisk)) continue; cnt++; -- cgit v1.2.3-55-g7522