From 0527f5d46b7d3f3f874d45cd59db01aa48a84046 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Tue, 6 Sep 2016 23:34:24 -0500 Subject: [PATCH] Handle ntfs-3g EINVAL for attr save/restore It appears that ntfs-3g now returns EINVAL for unsupported ioctls including FS_IOC_GET_FLAGS and FS_IOC_SET_FLAGS. Treat EINVAL like the existing expected errors for these calls, but since there's evidence to suggest that other devices/filesystems use EINVAL to indicate more serious trouble and use ENOTTY to indicate unsupported ioctls, include a request to report any occurrences of EINVAL when ntfs-3g is not involved. Thanks to Mark J Hewitt for reporting the problem. Signed-off-by: Rob Browning Tested-by: Rob Browning --- lib/bup/metadata.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py index f77edbe..3dd8af9 100644 --- a/lib/bup/metadata.py +++ b/lib/bup/metadata.py @@ -5,6 +5,7 @@ # This code is covered under the terms of the GNU Library General # Public License as described in the bup LICENSE file. +from errno import EACCES, EINVAL, ENOTTY, ENOSYS, EOPNOTSUPP from io import BytesIO import errno, os, sys, stat, time, pwd, grp, socket, struct @@ -188,6 +189,8 @@ _rec_tag_linux_xattr = 7 # getfattr(1) setfattr(1) _rec_tag_hardlink_target = 8 # hard link target path _rec_tag_common_v2 = 9 # times, user, group, type, perms, etc. (current) +_warned_about_attr_einval = None + class ApplyError(Exception): # Thrown when unable to apply any given bit of metadata to a path. @@ -585,9 +588,17 @@ class Metadata: except OSError as e: if e.errno == errno.EACCES: add_error('read Linux attr: %s' % e) - elif e.errno in (errno.ENOTTY, errno.ENOSYS, errno.EOPNOTSUPP): + elif e.errno in (ENOTTY, ENOSYS, EOPNOTSUPP): # Assume filesystem doesn't support attrs. return + elif e.errno == EINVAL: + global _warned_about_attr_einval + if not _warned_about_attr_einval: + log("Ignoring attr EINVAL;" + + " if you're not using ntfs-3g, please report: " + + repr(path) + '\n') + _warned_about_attr_einval = True + return else: raise @@ -615,10 +626,13 @@ class Metadata: try: set_linux_file_attr(path, self.linux_attr) except OSError as e: - if e.errno in (errno.ENOTTY, errno.EOPNOTSUPP, errno.ENOSYS, - errno.EACCES): + if e.errno in (EACCES, ENOTTY, EOPNOTSUPP, ENOSYS): raise ApplyError('Linux chattr: %s (0x%s)' % (e, hex(self.linux_attr))) + elif e.errno == EINVAL: + msg = "if you're not using ntfs-3g, please report" + raise ApplyError('Linux chattr: %s (0x%s) (%s)' + % (e, hex(self.linux_attr), msg)) else: raise -- 2.39.2