Return to Default
2025/08/15
I/O device error を吐いてコピーが中断されるファイルのサルベージ作業。
今回もこちらにお世話になる。

強制ファイルコピープログラム:fcopy.exe
http://hyperstone​apple3.myd​ns.jp/fcopy/fcopy.htm

実行してみたところ、どうも途中から挙動がおかしい。
ソースを読んでみると、2GB までしか対応してない感じ。ファイルがでかすぎるせいか。
対応しよう。

とりあえず mingw-w64 の gcc でコンパイル。

Releases · niXman/mingw-builds-binaries
https://github.com​/niXman/mingw-builds-binaries/releases

win32 が4種類あるけど、i686 は 32bit用、msvcrt は Windows10 より前のものってことなので、x86_64-15.2.0-release-win32-seh-ucrt-rt_v13-rev0.7z をダウンロード。
解凍して bin にパスを通すだけ。

64bit でコンパイルされてるよねと long のサイズを確認したところ、4byte。あれ。

【開発環境ほか 1-9】C/C++言語で、64bit環境上で動作するプログラムを作る際の技術的な注意点はありますか? | 図研エルミック
https://www.elwsc.​co.jp/knowledge/6494/
LLP64 :ポインタのみ64bit (Windows環境)
LP64 :long変数/ポインタが64bit (Linux等UNIX系環境)

Linux だと 64bit になるけど、Windows だと 32bit のままなんだっけ。
__int64 に置き換え。

次にアドレスを printf している個所を8桁から16桁に拡張したけど、8桁しか表示されず。

[MSVC 2005] printf系で64Bit型整数に気をつけよう #VisualStudio - Qiita
https://qiita.com/chromabox/items/13f85e51af​a9a875042c​
gccでは上位32Bitが切られて表示されます。

書式文字列に%xを指定するのではなくて%llxとするとちゃんと表示できます。

%lx を %llx にする必要があると。

あとは、ファイル操作系の関数を 64bit 対応のものに置き換え。

--- fcopy.c    Sat Jun 06 15:30:02 2009
+++ fcopy64.c  Fri Aug 15 10:51:02 2025
@@ -89 +89 @@
-    long pos = 0;
+    __int64 pos = 0;
@@ -179 +179 @@
-            printf( "Read error at %08lX pos = %08lX\n", ftell( fi ), pos );
+            printf( "Read error at %016llX pos = %016llX\n", _ftelli64( fi ), pos );
@@ -181 +181 @@
-            fseek( fi, pos + buff_size, SEEK_SET );
+            _fseeki64( fi, pos + buff_size, SEEK_SET );

こんな感じで。



修正版を実行。

fcopy64 e:\foo.vhdx d:\foo.vhdx
Read error at 00000000067A8000 pos = 00000000067A8000
Read error at 00000000067C8000 pos = 00000000067C8000
Read error at 00000000068F8000 pos = 00000000068F8000
Read error at 000000015EA58000 pos = 000000015EA58000
Total error count = 4 block(s)

fcopy64 e:\bar.vhdx d:\bar.vhdx
Read error at 0000000077600000 pos = 0000000077600000
Read error at 0000000077608000 pos = 0000000077608000
Read error at 0000000077610000 pos = 0000000077610000
Read error at 0000000077618000 pos = 0000000077618000
Read error at 0000000077620000 pos = 0000000077620000

(中略)

Read error at 0000000077738000 pos = 0000000077738000
Read error at 0000000077740000 pos = 0000000077740000
Read error at 0000000077748000 pos = 0000000077748000
Read error at 0000000077750000 pos = 0000000077750000
Read error at 0000000077758000 pos = 0000000077758000
Total error count = 44 block(s)

32bit 超の領域もちゃんと処理されてますね。
にしても、エラー吐いてんなぁ!

1ブロック 32KB なので 1MB 程度ではあるものの、これはあくまで読み出せなかった領域。
他が破損してないというわけではないので、微妙なところ。



恐る恐る仮想マシンを起動してみたところ、両方起動。
イェーイ!

ただ起動はしたものの、chkdsk でめちゃくちゃエラー検出されてからの起動。
ネットワークドライブに繋がらなかったりと挙動も怪しいので再構築はしよう。
とりあえずデータを吸い出せる状態までは持っていけてよかった。
あれ。酒場放浪記、チバテレビで放送してる?
今日もラム肉焼いて飲んだくれ。
2025/08/14
酒飲んで寝て起きて夜中の1時。
chkdsk が終わっていたのでログを確認。

CHKDSK is verifying files (stage 1 of 3)...
 0 percent complete. (7528 of 212736 file records processed)
File record segment 7528 is unreadable.

(中略)

 2 percent complete. (56222 of 212736 file records processed)
File record segment 56222 is unreadable.
  212736 file records processed.
File verification completed.
  125 large file records processed.
  76 bad file records processed.

CHKDSK is verifying indexes (stage 2 of 3)...
67 percent complete. (213412 of 240844 index entries processed)
Deleting index entry foo in index $I30 of file 7052.

(中略)

Deleting index entry bar in index $I30 of file 56153.
  240844 index entries processed.
Index verification completed.
CHKDSK is scanning unindexed files for reconnect to their original directory.
  15 unindexed files scanned.
75 percent complete. (16 of 15 unindexed files scanned)
CHKDSK is recovering remaining unindexed files.
  15 unindexed files recovered.

CHKDSK is verifying security descriptors (stage 3 of 3)...
Security descriptor verification completed.
  14055 data files processed.
CHKDSK is verifying Usn Journal...
Usn Journal verification completed.
Adding 27 bad clusters to the Bad Clusters File.
Correcting errors in the master file table's (MFT) DATA attribute.
CHKDSK discovered free space marked as allocated in the
master file table (MFT) bitmap.
CHKDSK discovered free space marked as allocated in the volume bitmap.

Windows has made corrections to the file system.
No further action is required.

1953382399 KB total disk space.
1116433040 KB in 198341 files.
     55348 KB in 14058 indexes.
       108 KB in bad sectors.
    338351 KB in use by the system.
     65536 KB occupied by the log file.
 836555552 KB available on disk.

      4096 bytes in each allocation unit.
 488345599 total allocation units on disk.
 209138888 allocation units available on disk.

だいぶやられてるな。

コピー作業を再開する。
昼頃にコピー完了。
chkdsk 後にも I/O device error を吐くような状態のファイルは3つだけだったのは僥倖。

ただその中に Hyper-V の仮想ディスクが2つが入ってるのが問題なんだよな…
特に Trac と Redmine を動かしていた環境のもの。
Wiki、Git、Subversion がまとめて飛んでしまった
これの復旧は別に考えよう。


あれこれ部屋の中を引っ掻き回した結果、目に見える範囲にHDDが19台転がっている。
うち4台が未開封。
なんなんだこの部屋。
いったんコピーし終わったので、ドライブレターを入れ替えて以下の作業。
再起動すれば勝手に置き換わるはずだけど一応。

iSCSI

vhd をインポートし直し。
例によって「Unable to import the virtual disk. A Virtual disk with that file path already exists.」がでたので、HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\iSCSI Target\WTDisks から対象を削除。
したけどダメ。

あれぇと思ったけど、サービスの再起動が必要なんだった。

Hyper-V

こちらも再インポートしようといったん削除してからインポートしたところ、エラーではじかれた。
調べたら、Virtual Machines 配下の xml が物理削除されてた。
消すな!!

旧ディスクからコピーし直して再インポート。

Spinel

sexe を登録し直し。
酒飲んでたら部下からメール。
北海道から帰ってきたので土産を渡したいとのこと。
駅前で落ち合って日本酒をもらった。

賄賂だな?
Garmin Pay がいつの間にか Wallet になってたと思ったら、今度は Wallet & Garmin Pay になってる。
2025/08/13
あんまりにも止まるもんで先に chkdsk をかけることにする。
また1日待機。
ラム肉焼いて飲んだくれ。