pnor_partition_table: Raise exception for unmapped offsets

Allow reads and writes of offsets that don't map onto partitions defined
in the ToC. Do so by ignoring the mapping failure and filling a window
with 0xff in the hole from the requested offset to the following
partition.

This change also removes the reliance on InternalFailure as the
exception of choice for communicating failures. We can do better without
the teeth-pulling required by phosphor-logging by translating custom
exceptions into phosphor-logging exceptions at the edges.

Change-Id: Ibfa961a66b0b979354c6dc226ccbe7e9fbafc16d
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/pnor_partition_table.hpp b/pnor_partition_table.hpp
index 730e75b..88c8fb9 100644
--- a/pnor_partition_table.hpp
+++ b/pnor_partition_table.hpp
@@ -163,6 +163,8 @@
      *
      *  @returns const reference to pnor_partition, if found, else an
      *           exception will be thrown.
+     *
+     *  Throws: UnmappedOffset
      */
     const pnor_partition& partition(size_t offset) const;
 
@@ -172,6 +174,8 @@
      *
      *  @returns const reference to pnor_partition, if found, else an
      *           exception will be thrown.
+     *
+     *  Throws: UnknownPartition
      */
     const pnor_partition& partition(const std::string& name) const;
 
@@ -304,6 +308,35 @@
     }
 };
 
+class UnmappedOffset : public std::exception
+{
+  public:
+    UnmappedOffset(size_t base, size_t next) : base(base), next(next)
+    {
+    }
+
+    const size_t base;
+    const size_t next;
+};
+
+class OutOfBoundsOffset : public ReasonedError
+{
+  public:
+    OutOfBoundsOffset(const std::string&& reason) :
+        ReasonedError(std::move(reason))
+    {
+    }
+};
+
+class UnknownPartition : public ReasonedError
+{
+  public:
+    UnknownPartition(const std::string&& reason) :
+        ReasonedError(std::move(reason))
+    {
+    }
+};
+
 } // namespace virtual_pnor
 } // namespace openpower