vpnor: Avoid mmap() due to lack of support on some filesystems
JFFS2 does not support writable mappings. Switch to read()/write() and
add all the failure handling to ensure we get the required semantics.
Change-Id: I5ec547bf7a01a389cf8f1403f748026fe6bb21fa
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/vpnor/partition.hpp b/vpnor/partition.hpp
index d6346b1..6b6d46b 100644
--- a/vpnor/partition.hpp
+++ b/vpnor/partition.hpp
@@ -49,47 +49,13 @@
Request& operator=(Request&&) = default;
~Request() = default;
- ssize_t read(void* dst, size_t len)
- {
- len = clamp(len);
- constexpr auto flags = O_RDONLY;
- fs::path path = getPartitionFilePath(flags);
- return fulfil(path, flags, dst, len);
- }
-
- ssize_t write(void* dst, size_t len)
- {
- if (len != clamp(len))
- {
- std::stringstream err;
- err << "Request size 0x" << std::hex << len << " from offset 0x"
- << std::hex << offset << " exceeds the partition size 0x"
- << std::hex
- << (partition.data.size << backend->block_size_shift);
- throw OutOfBoundsOffset(err.str());
- }
- constexpr auto flags = O_RDWR;
- /* Ensure file is at least the size of the maximum access */
- fs::path path = getPartitionFilePath(flags);
- resize(path, len);
- return fulfil(path, flags, dst, len);
- }
+ ssize_t read(void* dst, size_t len);
+ ssize_t write(void* dst, size_t len);
private:
/** @brief Clamp the access length to the maximum supported by the ToC */
size_t clamp(size_t len);
- /** @brief Ensure the backing file is sized appropriately for the access
- *
- * We need to ensure the file is big enough to satisfy the request so that
- * mmap() will succeed for the required size.
- *
- * @return The valid access length
- *
- * Throws: std::system_error
- */
- void resize(const std::experimental::filesystem::path& path, size_t len);
-
/** @brief Returns the partition file path associated with the offset.
*
* The search strategy for the partition file depends on the value of the
@@ -124,15 +90,6 @@
*/
std::experimental::filesystem::path getPartitionFilePath(int flags);
- /** @brief Fill dst with the content of the partition relative to offset.
- *
- * @param[in] offset - The pnor offset(bytes).
- * @param[out] dst - The buffer to fill with partition data
- * @param[in] len - The length of the destination buffer
- */
- size_t fulfil(const std::experimental::filesystem::path& path, int flags,
- void* dst, size_t len);
-
struct backend* backend;
const pnor_partition& partition;
size_t base;