summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/imgtool/library.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/imgtool/library.h')
-rw-r--r--src/tools/imgtool/library.h261
1 files changed, 135 insertions, 126 deletions
diff --git a/src/tools/imgtool/library.h b/src/tools/imgtool/library.h
index 312d3bbe30f..023b5fb948f 100644
--- a/src/tools/imgtool/library.h
+++ b/src/tools/imgtool/library.h
@@ -22,6 +22,7 @@
#include "timeconv.h"
#include "utilfwd.h"
+#include <algorithm>
#include <chrono>
#include <cstdint>
#include <ctime>
@@ -32,16 +33,15 @@
#include <vector>
-namespace imgtool
-{
- class image;
- class partition;
- class directory;
- class charconverter;
- class stream;
-};
+namespace imgtool {
+
+class image;
+class partition;
+class directory;
+class charconverter;
+class stream;
-enum imgtool_suggestion_viability_t
+enum suggestion_viability_t
{
SUGGESTION_END,
SUGGESTION_POSSIBLE,
@@ -57,162 +57,171 @@ union filterinfo
imgtoolerr_t (*read_file)(imgtool::partition &partition, const char *filename, const char *fork, imgtool::stream &destf);
imgtoolerr_t (*write_file)(imgtool::partition &partition, const char *filename, const char *fork, imgtool::stream &sourcef, util::option_resolution *opts);
- imgtoolerr_t (*check_stream)(imgtool::stream &stream, imgtool_suggestion_viability_t *viability);
+ imgtoolerr_t (*check_stream)(imgtool::stream &stream, suggestion_viability_t *viability);
};
typedef void (*filter_getinfoproc)(uint32_t state, union filterinfo *info);
-namespace imgtool
+class datetime
{
- class datetime
- {
- public:
- typedef util::arbitrary_clock<std::int64_t, 1600, 1, 1, 0, 0, 0, std::ratio<1, 10000000> > imgtool_clock;
+public:
+ typedef util::arbitrary_clock<std::int64_t, 1600, 1, 1, 0, 0, 0, std::ratio<1, 10000000> > imgtool_clock;
- enum datetime_type
- {
- NONE,
- LOCAL,
- GMT
- };
+ enum datetime_type
+ {
+ NONE,
+ LOCAL,
+ GMT
+ };
- datetime()
- : m_type(datetime_type::NONE)
- {
- }
+ datetime()
+ : m_type(datetime_type::NONE)
+ {
+ }
- template<typename Rep, int Y, int M, int D, int H, int N, int S, typename Ratio>
- datetime(datetime_type type, std::chrono::time_point<util::arbitrary_clock<Rep, Y, M, D, H, N, S, Ratio> > tp)
- : m_type(type)
- , m_time_point(imgtool_clock::from_arbitrary_time_point(tp))
- {
- }
+ template<typename Rep, int Y, int M, int D, int H, int N, int S, typename Ratio>
+ datetime(datetime_type type, std::chrono::time_point<util::arbitrary_clock<Rep, Y, M, D, H, N, S, Ratio> > tp)
+ : m_type(type)
+ , m_time_point(imgtool_clock::from_arbitrary_time_point(tp))
+ {
+ }
- datetime(datetime_type type, std::chrono::time_point<std::chrono::system_clock> tp);
- datetime(datetime_type type, time_t t);
- datetime(datetime_type type, const util::arbitrary_datetime &dt, bool clamp = true);
- datetime(const datetime &that) = default;
- datetime(datetime &&that) = default;
+ datetime(datetime_type type, std::chrono::time_point<std::chrono::system_clock> tp);
+ datetime(datetime_type type, time_t t);
+ datetime(datetime_type type, const util::arbitrary_datetime &dt, bool clamp = true);
+ datetime(const datetime &that) = default;
+ datetime(datetime &&that) = default;
- // accessors
- datetime_type type() const { return m_type; }
- bool empty() const { return type() == datetime_type::NONE; }
- std::chrono::time_point<imgtool_clock> time_point() const { return m_time_point; }
+ // accessors
+ datetime_type type() const { return m_type; }
+ bool empty() const { return type() == datetime_type::NONE; }
+ std::chrono::time_point<imgtool_clock> time_point() const { return m_time_point; }
- // operators
- datetime &operator =(const datetime &that)
- {
- m_type = that.m_type;
- m_time_point = that.m_time_point;
- return *this;
- }
+ // operators
+ datetime &operator =(const datetime &that)
+ {
+ m_type = that.m_type;
+ m_time_point = that.m_time_point;
+ return *this;
+ }
- // returns the current time
- static datetime now(datetime_type type);
+ // returns the current time
+ static datetime now(datetime_type type);
- // returns time structures
- std::tm localtime() const;
- std::tm gmtime() const;
- time_t to_time_t() const;
+ // returns time structures
+ std::tm localtime() const;
+ std::tm gmtime() const;
+ time_t to_time_t() const;
- private:
- static imgtool_clock::duration s_gmt_offset;
- datetime_type m_type;
- std::chrono::time_point<imgtool_clock> m_time_point;
+private:
+ static imgtool_clock::duration s_gmt_offset;
+ datetime_type m_type;
+ std::chrono::time_point<imgtool_clock> m_time_point;
- static imgtool_clock::duration calculate_gmt_offset();
- };
+ static imgtool_clock::duration calculate_gmt_offset();
};
-struct imgtool_dirent
-{
- char filename[1024];
- char attr[64];
- uint64_t filesize;
-
- imgtool::datetime creation_time;
- imgtool::datetime lastmodified_time;
- imgtool::datetime lastaccess_time;
-
- char softlink[1024];
- char comment[256];
- /* flags */
- unsigned int eof : 1;
- unsigned int corrupt : 1;
- unsigned int directory : 1;
- unsigned int hardlink : 1;
-};
-
-struct imgtool_chainent
+struct chainent
{
uint8_t level;
uint64_t block;
};
-namespace imgtool
+class fork_entry
{
- class fork_entry
+public:
+ enum class type_t
{
- public:
- enum class type_t
- {
- DATA,
- RESOURCE,
- ALT
- };
-
- fork_entry(uint64_t size, type_t type = type_t::DATA)
- : m_size(size)
- , m_type(type)
- , m_name(default_name(type))
- {
+ DATA,
+ RESOURCE,
+ ALT
+ };
- }
+ fork_entry(uint64_t size, type_t type = type_t::DATA)
+ : m_size(size)
+ , m_type(type)
+ , m_name(default_name(type))
+ {
- fork_entry(uint64_t size, std::string &&name)
- : m_size(size)
- , m_type(fork_entry::type_t::ALT)
- , m_name(std::move(name))
- {
- }
+ }
- fork_entry(const fork_entry &that) = default;
- fork_entry(fork_entry &&that) = default;
+ fork_entry(uint64_t size, std::string &&name)
+ : m_size(size)
+ , m_type(fork_entry::type_t::ALT)
+ , m_name(std::move(name))
+ {
+ }
- uint64_t size() const { return m_size; }
- type_t type() const { return m_type; }
- const std::string &name() const { return m_name; }
+ fork_entry(const fork_entry &that) = default;
+ fork_entry(fork_entry &&that) = default;
- private:
- static std::string default_name(type_t type)
+ uint64_t size() const { return m_size; }
+ type_t type() const { return m_type; }
+ const std::string &name() const { return m_name; }
+
+private:
+ static std::string default_name(type_t type)
+ {
+ switch (type)
{
- switch (type)
- {
- case type_t::DATA:
- return std::string("");
- case type_t::RESOURCE:
- return std::string("RESOURCE_FORK");
- default:
- throw false;
- }
+ case type_t::DATA:
+ return std::string("");
+ case type_t::RESOURCE:
+ return std::string("RESOURCE_FORK");
+ default:
+ throw false;
}
+ }
- uint64_t m_size;
- type_t m_type;
- std::string m_name;
- };
-}
+ uint64_t m_size;
+ type_t m_type;
+ std::string m_name;
+};
-struct imgtool_transfer_suggestion
+struct transfer_suggestion
{
- imgtool_suggestion_viability_t viability;
+ suggestion_viability_t viability;
filter_getinfoproc filter;
const char *fork;
const char *description;
};
+} // namespace imgtool
+
+struct imgtool_dirent
+{
+ imgtool_dirent()
+ {
+ std::fill(std::begin(filename), std::end(filename), 0);
+ std::fill(std::begin(attr), std::end(attr), 0);
+ filesize = 0;
+
+ std::fill(std::begin(softlink), std::end(softlink), 0);
+ std::fill(std::begin(comment), std::end(comment), 0);
+
+ eof = corrupt = directory = hardlink = 0;
+ }
+
+ char filename[1024];
+ char attr[64];
+ uint64_t filesize;
+
+ imgtool::datetime creation_time;
+ imgtool::datetime lastmodified_time;
+ imgtool::datetime lastaccess_time;
+
+ char softlink[1024];
+ char comment[256];
+
+ /* flags */
+ unsigned int eof : 1;
+ unsigned int corrupt : 1;
+ unsigned int directory : 1;
+ unsigned int hardlink : 1;
+};
+
enum
{
/* --- the following bits of info are returned as 64-bit signed integers --- */
@@ -407,8 +416,8 @@ union imgtoolinfo
imgtoolerr_t (*set_attrs) (imgtool::partition &partition, const char *path, const uint32_t *attrs, const imgtool_attribute *values);
imgtoolerr_t (*attr_name) (uint32_t attribute, const imgtool_attribute *attr, char *buffer, size_t buffer_len);
imgtoolerr_t (*get_iconinfo) (imgtool::partition &partition, const char *path, imgtool_iconinfo *iconinfo);
- imgtoolerr_t (*suggest_transfer) (imgtool::partition &partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length);
- imgtoolerr_t (*get_chain) (imgtool::partition &partition, const char *path, imgtool_chainent *chain, size_t chain_size);
+ imgtoolerr_t (*suggest_transfer) (imgtool::partition &partition, const char *path, imgtool::transfer_suggestion *suggestions, size_t suggestions_length);
+ imgtoolerr_t (*get_chain) (imgtool::partition &partition, const char *path, imgtool::chainent *chain, size_t chain_size);
imgtoolerr_t (*get_geometry) (imgtool::image &image, uint32_t *tracks, uint32_t *heads, uint32_t *sectors);
imgtoolerr_t (*read_sector) (imgtool::image &image, uint32_t track, uint32_t head, uint32_t sector, std::vector<uint8_t> &buffer);
imgtoolerr_t (*write_sector) (imgtool::image &image, uint32_t track, uint32_t head, uint32_t sector, const void *buffer, size_t len, int ddam);