-
- if (!bd) {
- throw CopyError ("Failed to open partition", 0);
- }
- LOG_DISK_NC ("Opened partition");
-
- nanomsg->blocking_send(DISK_WRITER_FORMATTING "\n");
-
- r = ext4_mkfs(&fs, bd, &info, F_SET_EXT4);
- 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");
- nanomsg->blocking_send(DISK_WRITER_OK "\n");
-} catch (CopyError& e) {
- LOG_DISK("CopyError: %1 %2", e.message(), e.number());
- nanomsg->blocking_send(String::compose(DISK_WRITER_ERROR "\n%1\n%2\n", e.message(), e.number()));
-} catch (VerifyError& e) {
- LOG_DISK("VerifyError: %1 %2", e.message(), e.number());
- nanomsg->blocking_send(String::compose(DISK_WRITER_ERROR "\n%1\n%2\n", e.message(), e.number()));
-} catch (exception& e) {
- LOG_DISK("Exception: %1", e.what());
- nanomsg->blocking_send(String::compose(DISK_WRITER_ERROR "\n%1\n0\n", e.what()));