From: Stanislav Brabec Date: Mon, 10 Jun 2019 19:59:45 +0000 (+0200) Subject: fstrim -a/-A: Skip read-only volumes X-Git-Tag: v2.34~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d22ac64e4;p=thirdparty%2Futil-linux.git 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 --- diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c index ff029015e6..ea29a56958 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++;