-.TH FSTRIM 8 "July 2014" "util-linux" "System Administration"
+.TH FSTRIM 8 "May 2019" "util-linux" "System Administration"
.SH NAME
fstrim \- discard unused blocks on a mounted filesystem
.SH SYNOPSIS
.B --length
option).
.TP
+.B \-\-quiet
+Suppress error messages. This option is meant to be used in systemd service
+file to hide warnings that are result of known problems, such as NTFS driver
+reporting
+.I Bad file descriptor
+when device is mounted read-only, or lack of file system support for ioctl
+FITRIM call.
+.TP
.BR \-V , " \-\-version"
Display version information and exit.
.TP
struct fstrim_range range;
unsigned int verbose : 1,
+ quiet : 1,
fstab : 1,
dryrun : 1;
};
errno = 0;
if (ioctl(fd, FITRIM, &range)) {
- rc = errno == EOPNOTSUPP || errno == ENOTTY ? 1 : -errno;
-
- if (rc != 1)
+ switch (errno) {
+ case EBADF:
+ case ENOTTY:
+ case EOPNOTSUPP:
+ if (ctl->quiet) {
+ rc = 1;
+ break;
+ }
+ default:
+ rc = -errno;
+ }
+ if (rc < 0)
warn(_("%s: FITRIM ioctl failed"), path);
goto done;
}
fputs(_(" -l, --length <num> the number of bytes to discard\n"), out);
fputs(_(" -m, --minimum <num> the minimum extent length to discard\n"), out);
fputs(_(" -v, --verbose print number of discarded bytes\n"), out);
+ fputs(_(" --quiet suppress error messages\n"), out);
fputs(_(" -n, --dry-run does everything, but trim\n"), out);
fputs(USAGE_SEPARATOR, out);
struct fstrim_control ctl = {
.range = { .len = ULLONG_MAX }
};
+ enum {
+ OPT_QUIET = CHAR_MAX + 1
+ };
static const struct option longopts[] = {
{ "all", no_argument, NULL, 'a' },
{ "length", required_argument, NULL, 'l' },
{ "minimum", required_argument, NULL, 'm' },
{ "verbose", no_argument, NULL, 'v' },
+ { "quiet", no_argument, NULL, OPT_QUIET },
{ "dry-run", no_argument, NULL, 'n' },
{ NULL, 0, NULL, 0 }
};
case 'v':
ctl.verbose = 1;
break;
-
+ case OPT_QUIET:
+ ctl.quiet = 1;
+ break;
case 'h':
usage();
case 'V':