[bmap-tools] [PATCH 07/14] Filemap: distinguish the "not supported" error

Artem Bityutskiy dedekind1 at gmail.com
Tue Jan 21 12:34:28 EST 2014


From: Artem Bityutskiy <artem.bityutskiy at intel.com>

Introduce a new exception type (ErrorNotSupp) in order to distinguish the
situation when FIEMAP or SEEK_HOLE is not supported by the system.

Change-Id: I61a8ec24a1f88d5adccbc449eb3ac2d2fd80163b
Signed-off-by: Artem Bityutskiy <artem.bityutskiy at intel.com>
---
 bmaptools/Filemap.py | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/bmaptools/Filemap.py b/bmaptools/Filemap.py
index 8104ff0..2daf77e 100644
--- a/bmaptools/Filemap.py
+++ b/bmaptools/Filemap.py
@@ -29,14 +29,17 @@ import fcntl
 from bmaptools import BmapHelpers
 
 
-class Error(Exception):
+class ErrorNotSupp(Exception):
     """
-    A class for exceptions generated by this module. We currently support only
-    one type of exceptions, and we basically throw human-readable problem
-    description in case of errors.
+    An exception of this type is raised when the 'FIEMAP' or 'SEEK_HOLE' feature
+    is not supported either by the kernel or the file-system.
     """
     pass
 
+class Error(Exception):
+    """A class for all the other exceptions raised by this module."""
+    pass
+
 
 class _FilemapBase:
     """
@@ -142,6 +145,7 @@ class _FilemapBase:
 
         raise Error("the method is not implemented")
 
+
 # The 'SEEK_HOLE' and 'SEEK_DATA' options of the file seek system call
 _SEEK_DATA = 3
 _SEEK_HOLE = 4
@@ -171,6 +175,9 @@ class FilemapSeek(_FilemapBase):
             # hole starting from the specified offset.
             if err.errno == os.errno.ENXIO:
                 return -1
+            elif err.errno == os.errno.EINVAL:
+                raise ErrorNotSupp("the kernel or file-system does not support "
+                                   "\"SEEK_HOLE\" and \"SEEK_DATA\"")
             else:
                 raise
 
@@ -303,6 +310,12 @@ class FilemapFiemap(_FilemapBase):
         except IOError as err:
             # Note, the FIEMAP ioctl is supported by the Linux kernel starting
             # from version 2.6.28 (year 2008).
+            if err.errno == os.errno.EOPNOTSUPP:
+                raise ErrorNotSupp("the FIEMAP ioctl is not supported by "
+                                   "the file-system")
+            if err.errno == os.errno.ENOTTY:
+                raise ErrorNotSupp("the FIEMAP ioctl is not supported by "
+                                   "the kernel")
             raise Error("the FIEMAP ioctl failed for '%s': %s"
                         % (self._image_path, err))
 
@@ -417,5 +430,5 @@ def filemap(image):
 
     try:
         return FilemapFiemap(image)
-    except Error:
+    except ErrorNotSupp:
         return FilemapSeek(image)
-- 
1.8.3.1




More information about the Bmap-tools mailing list