Scans the SD card on a MEGA65 (via ethernet / ETHLOAD) and rewrites fragmented files into contiguous clusters.
make # builds bin/m65defrag
Object files and the static library libm65ftp.a are built under build/
(mirroring lib/ and src/); make clean removes build/ and bin/.
The Makefile detects the platform automatically (uname -s).
- Linux —
gcc,make - macOS — Xcode command line tools (uses
cc/Clang),make - Windows — MSYS2/MinGW64 (uses
gcc,make)
Ethernet-only — no USB/serial dependencies. On Linux the binary links against libc only.
./bin/m65defrag [root]
Connects to the MEGA65 (ETHLOAD must be running), scans the directory tree
under root (default /), marks each file OK or FRAGMENTED, and rewrites
any fragmented files in place so they occupy contiguous clusters.
lib/ vendored MEGA65-FTP library (ethernet only)
src/m65ftp_lib.[ch] local wrapper over the vendored core
src/m65defrag.c CLI (scan + defrag mode)
The vendored library is a stripped copy of the MEGA65 FTP tool from
MEGA65/mega65-tools, so the same
MEGA65-FTP protocol as upstream's mega65_ftp is used. See lib/README.md
for the vendored library's provenance and the local deltas, and
scripts/sync-upstream.sh (Linux), scripts/sync-upstream-mac.sh (macOS)
or scripts/sync-upstream.bat (Windows) for refreshing it.
The vendored lib/ code is copyright the MEGA65 project and is licensed
under the GNU General Public License, version 3
(LICENSE.txt);
lib/mega65_ftp.c carries a per-file GPL-2.0-or-later header. See
lib/README.md for the exact provenance. This project's own code
(src/) is distributed under the same terms.
USE AT YOUR OWN RISK. This tool modifies the FAT32 filesystem on your SD card. While it has been tested, there is always a risk of data loss or corruption. The author makes no warranties and accepts no responsibility for any damage or data loss that may occur. Back up your SD card before use.

