-
- 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);
-
- uint64_t total_remaining = total_bytes;
- vector<CopiedFile> copied_files;
- copy (dcp_path, "/mp", total_remaining, total_bytes, copied_files);
-
- /* Unmount and re-mount to make sure the write has finished */
- r = ext4_umount("/mp/");
- if (r != EOK) {
- throw CopyError ("Failed to unmount device", r);
- }
- r = ext4_mount("ext4_fs", "/mp/", false);
- if (r != EOK) {
- throw CopyError ("Failed to mount device", r);
- }
- LOG_DISK_NC ("Re-mounted device");
-
- verify (copied_files, 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);