#endif
#ifdef DCPOMATIC_OSX
+#include "lib/stdout_log.h"
#undef nil
extern "C" {
#include <lwext4/file_dev.h>
uint8_t* buffer = new uint8_t[block_size];
Digester digester;
+ int progress_frequency = 5000;
+ int progress_count = 0;
uint64_t remaining = file_size (from);
while (remaining > 0) {
uint64_t const this_time = min(remaining, block_size);
}
remaining -= this_time;
total_remaining -= this_time;
- nanomsg->send(String::compose(DISK_WRITER_PROGRESS "\n%1\n", (1 - float(total_remaining) / total)), SHORT_TIMEOUT);
+
+ ++progress_count;
+ if ((progress_count % progress_frequency) == 0) {
+ nanomsg->send(String::compose(DISK_WRITER_PROGRESS "\n%1\n", (1 - float(total_remaining) / total)), SHORT_TIMEOUT);
+ }
}
fclose (in);
}
LOG_DISK_NC ("Wrote MBR");
-#ifdef DCPOMATIC_WINDOWS
struct ext4_mbr_bdevs bdevs;
r = ext4_mbr_scan (bd, &bdevs);
if (r != EOK) {
throw CopyError ("Failed to read MBR", r);
}
+#ifdef DCPOMATIC_WINDOWS
file_windows_partition_set (bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size);
#endif
+ LOG_DISK ("Writing to partition at %1 size %2; bd part size is %3", bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size, bd->part_size);
+
#ifdef DCPOMATIC_LINUX
/* Re-read the partition table */
int fd = open(device.c_str(), O_RDONLY);
nanomsg->send(DISK_WRITER_FORMATTING "\n", SHORT_TIMEOUT);
- r = ext4_mkfs(&fs, bd, &info, F_SET_EXT4);
+ r = ext4_mkfs(&fs, bd, &info, F_SET_EXT2);
if (r != EOK) {
throw CopyError ("Failed to make filesystem", r);
}
if (!nanomsg->send(DISK_WRITER_OK "\n", LONG_TIMEOUT)) {
throw CommunicationFailedError ();
}
+
+ disk_write_finished ();
} catch (CopyError& e) {
LOG_DISK("CopyError (from write): %1 %2", e.message(), e.number().get_value_or(0));
nanomsg->send(String::compose(DISK_WRITER_ERROR "\n%1\n%2\n", e.message(), e.number().get_value_or(0)), LONG_TIMEOUT);
}
#endif
+
bool
idle ()
try
return true;
}
+ LOG_DISK("Writer receives command: %1", *s);
+
if (*s == DISK_WRITER_QUIT) {
exit (EXIT_SUCCESS);
} else if (*s == DISK_WRITER_UNMOUNT) {
optional<string> xml_head = nanomsg->receive (LONG_TIMEOUT);
optional<string> xml_body = nanomsg->receive (LONG_TIMEOUT);
if (!xml_head || !xml_body) {
+ LOG_DISK_NC("Failed to receive unmount request");
throw CommunicationFailedError ();
}
- if (Drive(*xml_head + *xml_body).unmount()) {
- if (!nanomsg->send (DISK_WRITER_OK "\n", LONG_TIMEOUT)) {
- throw CommunicationFailedError();
- }
- } else {
- if (!nanomsg->send (DISK_WRITER_ERROR "\n", LONG_TIMEOUT)) {
- throw CommunicationFailedError();
- }
+ bool const success = Drive(*xml_head + *xml_body).unmount();
+ if (!nanomsg->send (success ? (DISK_WRITER_OK "\n") : (DISK_WRITER_ERROR "\n"), LONG_TIMEOUT)) {
+ LOG_DISK_NC("CommunicationFailedError in unmount_finished");
+ throw CommunicationFailedError ();
}
- } else {
- optional<string> dcp_path = nanomsg->receive(LONG_TIMEOUT);
- optional<string> device = nanomsg->receive(LONG_TIMEOUT);
+ } else if (*s == DISK_WRITER_WRITE) {
+ optional<string> dcp_path = nanomsg->receive (LONG_TIMEOUT);
+ optional<string> device = nanomsg->receive (LONG_TIMEOUT);
if (!dcp_path || !device) {
+ LOG_DISK_NC("Failed to receive write request");
throw CommunicationFailedError();
}
/* Do some basic sanity checks; this is a bit belt-and-braces but it can't hurt... */
#ifdef DCPOMATIC_OSX
- if (!starts_with(*device, "/dev/disk")) {
+ if (!starts_with(*device, "/dev/rdisk")) {
LOG_DISK ("Will not write to %1", *device);
- nanomsg->try_send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n", LONG_TIMEOUT);
+ nanomsg->send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n", LONG_TIMEOUT);
return true;
}
#endif
#ifdef DCPOMATIC_WINDOWS
if (!starts_with(*device, "\\\\.\\PHYSICALDRIVE")) {
LOG_DISK ("Will not write to %1", *device);
- nanomsg->try_send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n", LONG_TIMEOUT);
+ nanomsg->send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n", LONG_TIMEOUT);
return true;
}
#endif
bool on_drive_list = false;
bool mounted = false;
for (auto const& i: Drive::get()) {
- if (i.device() == *device) {
+ if (i.device_for_write() == *device) {
on_drive_list = true;
mounted = i.mounted();
}
int
main ()
{
+#ifdef DCPOMATIC_OSX
+ /* On macOS this is running as root, so config_path() will be somewhere in root's
+ * home. Instead, just write to stdout as the macOS process control stuff will
+ * redirect this to a file in /var/log
+ */
+ dcpomatic_log.reset(new StdoutLog(LogEntry::TYPE_DISK));
+ LOG_DISK_NC("dcpomatic_disk_writer started");
+#else
/* XXX: this is a hack, but I expect we'll need logs and I'm not sure if there's
* a better place to put them.
*/
dcpomatic_log.reset(new FileLog(config_path() / "disk_writer.log", LogEntry::TYPE_DISK));
LOG_DISK_NC("dcpomatic_disk_writer started");
+#endif
try {
nanomsg = new Nanomsg (false);