-
- if (!bd) {
- throw CopyError ("Failed to open partition", 0);
- }
- LOG_DISK_NC ("Opened partition");
-
- nanomsg->send(DISK_WRITER_FORMATTING "\n", SHORT_TIMEOUT);
-
- r = ext4_mkfs(&fs, bd, &info, F_SET_EXT2);
- if (r != EOK) {
- throw CopyError ("Failed to make filesystem", r);
- }
- LOG_DISK_NC ("Made filesystem");
-
- r = ext4_device_register(bd, "ext4_fs");
- if (r != EOK) {
- throw CopyError ("Failed to register device", r);
- }
- LOG_DISK_NC ("Registered device");
-
- r = ext4_mount("ext4_fs", "/mp/", false);
- if (r != EOK) {
- throw CopyError ("Failed to mount device", r);
- }
- LOG_DISK_NC ("Mounted device");
-
- uint64_t total_bytes = 0;
- count (dcp_path, total_bytes);
-
- /* XXX: this is a hack. We are going to "treat" every byte twice; write it, and then verify it. Double the
- * bytes totals so that progress works itself out (assuming write is the same speed as read).
- */
- total_bytes *= 2;
- copy (dcp_path, "/mp", total_bytes, total_bytes);
-
- r = ext4_umount("/mp/");
- if (r != EOK) {
- throw CopyError ("Failed to unmount device", r);
- }
-
- ext4_device_unregister("ext4_fs");
- 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);
-} catch (VerifyError& e) {
- LOG_DISK("VerifyError (from write): %1 %2", e.message(), e.number());
- nanomsg->send(String::compose(DISK_WRITER_ERROR "\n%1\n%2\n", e.message(), e.number()), LONG_TIMEOUT);
-} catch (exception& e) {
- LOG_DISK("Exception (from write): %1", e.what());
- nanomsg->send(String::compose(DISK_WRITER_ERROR "\n%1\n0\n", e.what()), LONG_TIMEOUT);
-}
-
-struct Parameters
-{
- boost::filesystem::path dcp_path;
- std::string device;
-};
-
-#ifdef DCPOMATIC_LINUX
-static
-void
-polkit_callback (GObject *, GAsyncResult* res, gpointer data)
-{
- Parameters* parameters = reinterpret_cast<Parameters*> (data);
- PolkitAuthorizationResult* result = polkit_authority_check_authorization_finish (polkit_authority, res, 0);
- if (result && polkit_authorization_result_get_is_authorized(result)) {
- write (parameters->dcp_path, parameters->device);
- }
- delete parameters;
- if (result) {
- g_object_unref (result);
- }