mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Merge 194b9b1193 into 5f5f22c82b
This commit is contained in:
2
.github/workflows/ccpp.yml
vendored
2
.github/workflows/ccpp.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- name: brew
|
||||
run: brew install sqlite pkg-config libusb ninja protobuf
|
||||
run: brew install sqlite pkg-config libusb ninja protobuf truncate
|
||||
- name: make
|
||||
run: make
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
syntax = "proto2";
|
||||
|
||||
enum FluxMagic {
|
||||
MAGIC = 0x466c7578;
|
||||
}
|
||||
|
||||
enum FluxFileVersion {
|
||||
VERSION_1 = 1;
|
||||
}
|
||||
@@ -11,7 +15,8 @@ message TrackFluxProto {
|
||||
}
|
||||
|
||||
message FluxFileProto {
|
||||
optional FluxFileVersion version = 1;
|
||||
repeated TrackFluxProto track = 2;
|
||||
optional int32 magic = 1;
|
||||
optional FluxFileVersion version = 2;
|
||||
repeated TrackFluxProto track = 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
~Fl2FluxSink()
|
||||
{
|
||||
FluxFileProto proto;
|
||||
proto.set_magic(FluxMagic::MAGIC);
|
||||
proto.set_version(FluxFileVersion::VERSION_1);
|
||||
for (const auto& e : _data)
|
||||
{
|
||||
|
||||
@@ -39,9 +39,8 @@ void FluxSink::updateConfigForFilename(FluxSinkProto* proto, const std::string&
|
||||
{
|
||||
static const std::vector<std::pair<std::regex, std::function<void(const std::string&)>>> formats =
|
||||
{
|
||||
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { proto->set_fluxfile(s); }},
|
||||
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { proto->mutable_fl2()->set_filename(s); }},
|
||||
{ std::regex("^(.*\\.scp)$"), [&](const auto& s) { proto->mutable_scp()->set_filename(s); }},
|
||||
{ std::regex("^(.*\\.fl2)$"), [&](const auto& s) { proto->mutable_fl2()->set_filename(s); }},
|
||||
{ std::regex("^vcd:(.*)$"), [&](const auto& s) { proto->mutable_vcd()->set_directory(s); }},
|
||||
{ std::regex("^au:(.*)$"), [&](const auto& s) { proto->mutable_au()->set_directory(s); }},
|
||||
{ std::regex("^drive:(.*)"), [&](const auto& s) { proto->mutable_drive()->set_drive(std::stoi(s)); }},
|
||||
|
||||
@@ -50,6 +50,13 @@ private:
|
||||
|
||||
std::unique_ptr<FluxSource> FluxSource::createFl2FluxSource(const Fl2FluxSourceProto& config)
|
||||
{
|
||||
char buffer[16];
|
||||
std::ifstream(config.filename(), std::ios::in | std::ios::binary).read(buffer, 16);
|
||||
if (strncmp(buffer, "SQLite format 3", 16) == 0)
|
||||
{
|
||||
std::cerr << "Warning: reading a deprecated flux file format; please upgrade it\n";
|
||||
return FluxSource::createSqliteFluxSource(config.filename());
|
||||
}
|
||||
return std::unique_ptr<FluxSource>(new Fl2FluxSource(config));
|
||||
}
|
||||
|
||||
|
||||
@@ -50,12 +50,12 @@ std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config)
|
||||
|
||||
void FluxSource::updateConfigForFilename(FluxSourceProto* proto, const std::string& filename)
|
||||
{
|
||||
|
||||
static const std::vector<std::pair<std::regex, std::function<void(const std::string&)>>> formats =
|
||||
{
|
||||
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { proto->set_fluxfile(s); }},
|
||||
{ std::regex("^(.*\\.flux)$"), [&](const auto& s) { proto->mutable_fl2()->set_filename(s); }},
|
||||
{ std::regex("^(.*\\.scp)$"), [&](const auto& s) { proto->mutable_scp()->set_filename(s); }},
|
||||
{ std::regex("^(.*\\.cwf)$"), [&](const auto& s) { proto->mutable_cwf()->set_filename(s); }},
|
||||
{ std::regex("^(.*\\.fl2)$"), [&](const auto& s) { proto->mutable_fl2()->set_filename(s); }},
|
||||
{ std::regex("^erase:$"), [&](const auto& s) { proto->mutable_erase(); }},
|
||||
{ std::regex("^kryoflux:(.*)$"), [&](const auto& s) { proto->mutable_kryoflux()->set_directory(s); }},
|
||||
{ std::regex("^testpattern:(.*)"), [&](const auto& s) { proto->mutable_test_pattern(); }},
|
||||
|
||||
@@ -270,10 +270,6 @@ encodedecodetest() {
|
||||
echo " format=$format"
|
||||
echo " configs=$*"
|
||||
echo " fluxx=scp"
|
||||
echo "build $OBJDIR/$format.encodedecode.fl2.stamp : encodedecode | fluxengine$EXTENSION scripts/encodedecodetest.sh $*"
|
||||
echo " format=$format"
|
||||
echo " configs=$*"
|
||||
echo " fluxx=fl2"
|
||||
}
|
||||
|
||||
buildlibrary libagg.a \
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if [ $(uname) != "Linux" ]; then
|
||||
echo "Skipping test as not on Linux"
|
||||
if [ "$(uname)" != "Linux" -a "$(uname)" != "Darwin" ]; then
|
||||
echo "Skipping test as not on Linux" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -16,7 +16,7 @@ shift
|
||||
|
||||
trap "rm -f $srcfile $fluxfile $destfile" EXIT
|
||||
|
||||
dd if=/dev/urandom of=$srcfile bs=1M count=2 2>&1
|
||||
dd if=/dev/urandom of=$srcfile bs=1048576 count=2 2>&1
|
||||
|
||||
./fluxengine write $format -i $srcfile -d $fluxfile "$@"
|
||||
./fluxengine read $format -s $fluxfile -o $destfile "$@"
|
||||
|
||||
@@ -2,133 +2,35 @@
|
||||
#include "flags.h"
|
||||
#include "sql.h"
|
||||
#include "fluxmap.h"
|
||||
#include "writer.h"
|
||||
#include "proto.h"
|
||||
#include "lib/fluxsource/fluxsource.h"
|
||||
#include "lib/fluxsink/fluxsink.h"
|
||||
#include "lib/fluxsource/fluxsource.pb.h"
|
||||
#include "lib/fluxsink/fluxsink.pb.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
static sqlite3* db;
|
||||
|
||||
static void update_version_1_to_3()
|
||||
{
|
||||
for (const auto i : sqlFindFlux(db))
|
||||
{
|
||||
Fluxmap after;
|
||||
const auto before = sqlReadFlux(db, i.first, i.second);
|
||||
|
||||
/* Remember, before does not contain valid opcodes! */
|
||||
unsigned pending = 0;
|
||||
for (uint8_t b : before->rawBytes())
|
||||
{
|
||||
if (b < 0x80)
|
||||
{
|
||||
after.appendInterval(b + pending);
|
||||
after.appendPulse();
|
||||
pending = 0;
|
||||
}
|
||||
else
|
||||
pending += 0x80;
|
||||
}
|
||||
|
||||
sqlWriteFlux(db, i.first, i.second, after);
|
||||
std::cout << '.' << std::flush;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
static void update_version_2_to_3()
|
||||
{
|
||||
for (const auto i : sqlFindFlux(db))
|
||||
{
|
||||
Fluxmap after;
|
||||
const auto before = sqlReadFlux(db, i.first, i.second);
|
||||
|
||||
/* Remember, before does not contain valid opcodes! */
|
||||
unsigned pending = 0;
|
||||
for (uint8_t b : before->rawBytes())
|
||||
{
|
||||
switch (b)
|
||||
{
|
||||
case 0x80: /* pulse */
|
||||
after.appendInterval(pending);
|
||||
after.appendPulse();
|
||||
pending = 0;
|
||||
break;
|
||||
|
||||
case 0x81: /* index */
|
||||
after.appendInterval(pending);
|
||||
after.appendIndex();
|
||||
pending = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
pending += b;
|
||||
break;
|
||||
}
|
||||
}
|
||||
after.appendInterval(pending);
|
||||
|
||||
sqlWriteFlux(db, i.first, i.second, after);
|
||||
std::cout << '.' << std::flush;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
#include <fstream>
|
||||
|
||||
int mainUpgradeFluxFile(int argc, const char* argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
Error() << "syntax: fe-upgradefluxfile <fluxfile>";
|
||||
Error() << "syntax: fluxengine upgradefluxfile <fluxfile>";
|
||||
std::string filename = argv[1];
|
||||
std::string newfilename = filename + ".new";
|
||||
|
||||
db = sqlOpen(filename, SQLITE_OPEN_READWRITE);
|
||||
atexit([]()
|
||||
{
|
||||
sqlClose(db);
|
||||
}
|
||||
);
|
||||
setRange(config.mutable_cylinders(), "0-79");
|
||||
setRange(config.mutable_heads(), "0-1");
|
||||
|
||||
int version = sqlGetVersion(db);
|
||||
std::cout << fmt::format("File at version {}\n", version);
|
||||
if (version == FLUX_VERSION_CURRENT)
|
||||
{
|
||||
std::cout << "Up to date!\n";
|
||||
return 0;
|
||||
}
|
||||
FluxSourceProto fluxSourceProto;
|
||||
fluxSourceProto.mutable_fl2()->set_filename(filename);
|
||||
|
||||
if (version == FLUX_VERSION_0)
|
||||
{
|
||||
std::cout << "Upgrading to version 1\n";
|
||||
sqlPrepareFlux(db);
|
||||
sqlStmt(db, "BEGIN;");
|
||||
sqlStmt(db,
|
||||
"INSERT INTO zdata"
|
||||
" SELECT track, side, data, 0 AS compression FROM rawdata;"
|
||||
);
|
||||
sqlStmt(db, "DROP TABLE rawdata;");
|
||||
version = FLUX_VERSION_1;
|
||||
sqlWriteIntProperty(db, "version", version);
|
||||
sqlStmt(db, "COMMIT;");
|
||||
}
|
||||
FluxSinkProto fluxSinkProto;
|
||||
fluxSinkProto.mutable_fl2()->set_filename(newfilename);
|
||||
|
||||
if (version == FLUX_VERSION_1)
|
||||
{
|
||||
std::cout << "Upgrading to version 3\n";
|
||||
sqlStmt(db, "BEGIN;");
|
||||
update_version_1_to_3();
|
||||
version = FLUX_VERSION_3;
|
||||
sqlWriteIntProperty(db, "version", version);
|
||||
sqlStmt(db, "COMMIT;");
|
||||
}
|
||||
auto fluxSource = FluxSource::create(fluxSourceProto);
|
||||
auto fluxSink = FluxSink::create(fluxSinkProto);
|
||||
writeRawDiskCommand(*fluxSource, *fluxSink);
|
||||
|
||||
if (version == FLUX_VERSION_2)
|
||||
{
|
||||
std::cout << "Upgrading to version 3\n";
|
||||
sqlStmt(db, "BEGIN;");
|
||||
update_version_2_to_3();
|
||||
version = FLUX_VERSION_3;
|
||||
sqlWriteIntProperty(db, "version", version);
|
||||
sqlStmt(db, "COMMIT;");
|
||||
}
|
||||
|
||||
std::cout << "Vacuuming\n";
|
||||
sqlStmt(db, "VACUUM;");
|
||||
std::cout << "Upgrade done\n";
|
||||
rename(newfilename.c_str(), filename.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user