From 46efbfd6a165fd873cd369d0558c73d192211c26 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 14:02:32 +1100 Subject: [PATCH 1/7] mega65_ftp: speed up Ethernet uploads - Use the 28-packet window on R5/R6 (xc7a200t, 32 ETH RX buffers), not 3 - Flush the write queue at 64KB in Ethernet mode (helper accepts 128-sector batches) - Send queued sector writes in ascending order so file data forms one batch Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SaBDrQJU9NJb1UxBiLfpfd --- src/tools/mega65_ftp.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/tools/mega65_ftp.c b/src/tools/mega65_ftp.c index 6d4ab49..9ae32a6 100644 --- a/src/tools/mega65_ftp.c +++ b/src/tools/mega65_ftp.c @@ -1774,10 +1774,24 @@ int execute_write_queue(void) push_ram(0x50000, write_buffer_offset, &write_data_buffer[0]); } - // XXX - Sort sector number order and merge consecutive writes into - // multi-sector writes would be a good idea here. + // Issue the jobs in ascending sector order. FAT and directory sectors get + // appended to the queue part-way through a run of file data, which used to + // split one contiguous run into several small batches (each batch boundary + // costs a full ack drain + verify on the MEGA65). The data buffer stays where + // it is; each job just points at its slot. + int order[65536 / 512]; + for (int i = 0; i < write_sector_count; i++) + order[i] = i; + for (int i = 1; i < write_sector_count; i++) { + int v = order[i], j = i - 1; + while (j >= 0 && write_sector_numbers[order[j]] > write_sector_numbers[v]) { + order[j + 1] = order[j]; + j--; + } + order[j + 1] = v; + } for (int i = 0; i < write_sector_count; i++) { - queue_physical_write_sector(write_sector_numbers[i], 0x50000 + (i << 9)); + queue_physical_write_sector(write_sector_numbers[order[i]], 0x50000 + (order[i] << 9)); } // printf("Execute write queue with %d entries\n", write_sector_count); queue_execute(); @@ -1803,7 +1817,9 @@ void queue_write_sector(uint32_t sector_number, uint8_t *buffer) // Purge pending jobs when they are banked up // (only 32KB at a time, as the l command for fast pushing data // can't do 64KB - if (write_buffer_offset >= 32768) + // Over Ethernet there is no 'l' command limit, and the helper accepts batches + // of up to 128 sectors (64KB), so use the whole buffer there. + if (write_buffer_offset >= (ethernet_mode ? 65536 : 32768)) execute_write_queue(); // printf("adding sector $%08x to the write queue (pos#%d)\n", sector_number, write_sector_count); @@ -5622,6 +5638,8 @@ void determine_ethernet_window_size(void) case 0x01: case 0x03: case 0x04: + case 0x05: // R5 and R6 are also xc7a200t with 32 ETH RX buffers (see mega65r5/r6.vhdl) + case 0x06: case 0x21: ethernet_window_size = 28; // xc7a200t_0 models have more Ethernet receive buffers break; From 5daa839c6983ea7cc67ec5e1494744477c0be18a Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 15:02:34 +1100 Subject: [PATCH 2/7] mega65_ftp: stop rescanning the whole FAT for free space on every upload - Start the free-cluster search at the FAT32 FSInfo next-free hint and keep it updated in-session; wrap to the start of the FAT if nothing fits after it - Write the hint and an adjusted free-cluster count back to FSInfo after upload, mkdir and delete - Read the FAT 128 sectors per request while scanning (was 16) - mkdir: '..' of a directory in the root now points at cluster 0 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SaBDrQJU9NJb1UxBiLfpfd --- src/tools/mega65_ftp.c | 88 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 4 deletions(-) diff --git a/src/tools/mega65_ftp.c b/src/tools/mega65_ftp.c index 9ae32a6..e02d130 100644 --- a/src/tools/mega65_ftp.c +++ b/src/tools/mega65_ftp.c @@ -125,6 +125,7 @@ char current_dir[1024] = "/"; #endif int open_file_system(void); +void update_fsinfo_next_free(void); int upload_slot(int slot_number, char* src_name); int download_slot(int sllot, char *dest_name); int download_file(char *dest_name, char *local_name, int showClusters); @@ -255,6 +256,12 @@ unsigned int sectors_per_fat = 0; unsigned int data_sectors = 0; unsigned int first_cluster = 0; unsigned int fsinfo_sector = 0; +// Where to start looking for free clusters. Seeded from the FAT32 FSInfo "next free" +// hint, then kept up to date as we allocate, so we don't rescan the whole FAT from +// cluster 2 on every upload (on a large card with 4KB clusters that is many MB of reads). +unsigned int free_cluster_hint = 0; +int free_cluster_delta = 0; // clusters freed(+)/allocated(-) since FSInfo was last written +#define FAT_SCAN_READAHEAD 128 unsigned int reserved_sectors = 0; unsigned int fat1_sector = 0, fat2_sector = 0; unsigned int first_cluster_sector; // Slightly confusing name, as the first cluster is actually cluster #2 @@ -2157,10 +2164,52 @@ int open_file_system(void) file_system_found = 1; + free_cluster_hint = 0; + if (fsinfo_sector && fsinfo_sector < reserved_sectors) { + unsigned char fsi[512]; + if (!read_sector(partition_start + fsinfo_sector, fsi, CACHE_YES, 0) && fsi[0] == 'R' && fsi[1] == 'R' + && fsi[2] == 'a' && fsi[3] == 'A' && fsi[484] == 'r' && fsi[485] == 'r' && fsi[486] == 'A' && fsi[487] == 'a') { + unsigned int hint = fsi[492] | (fsi[493] << 8) | (fsi[494] << 16) | ((unsigned int)fsi[495] << 24); + if (hint >= 2 && hint < sectors_per_fat * (512 / 4)) + free_cluster_hint = hint; + } + } + log_info("Free cluster search starts at cluster %u", free_cluster_hint); + } while (0); return retVal; } +void update_fsinfo_next_free(void) +{ + if (!fsinfo_sector || fsinfo_sector >= reserved_sectors || free_cluster_hint < 2) + return; + unsigned char fsi[512]; + if (read_sector(partition_start + fsinfo_sector, fsi, CACHE_YES, 0)) + return; + if (!(fsi[0] == 'R' && fsi[1] == 'R' && fsi[2] == 'a' && fsi[3] == 'A' && fsi[484] == 'r' && fsi[485] == 'r' + && fsi[486] == 'A' && fsi[487] == 'a')) + return; + // Keep the free cluster count in step with what we allocated/freed (if it is known) + unsigned int free_count = fsi[488] | (fsi[489] << 8) | (fsi[490] << 16) | ((unsigned int)fsi[491] << 24); + if (free_count != 0xffffffff) { + long long n = (long long)free_count + free_cluster_delta; + if (n < 0 || n > (long long)sectors_per_fat * (512 / 4)) + n = 0xffffffff; // out of range: mark as unknown, the FAT32 spec allows that + free_count = (unsigned int)n; + fsi[488] = free_count; + fsi[489] = free_count >> 8; + fsi[490] = free_count >> 16; + fsi[491] = free_count >> 24; + } + free_cluster_delta = 0; + fsi[492] = free_cluster_hint; + fsi[493] = free_cluster_hint >> 8; + fsi[494] = free_cluster_hint >> 16; + fsi[495] = free_cluster_hint >> 24; + write_sector(partition_start + fsinfo_sector, fsi); +} + unsigned char buf[512]; unsigned int get_next_cluster(int cluster) @@ -2645,6 +2694,16 @@ int set_fat_cluster_ptr(unsigned int cluster, unsigned int value) log_debug("marking cluster $%x in use by writing to offset $%x of FAT sector $%x", cluster, fat_sector_offset, fat_sector_num); + { + unsigned int old = (fat_sector[fat_sector_offset + 0] | (fat_sector[fat_sector_offset + 1] << 8) + | (fat_sector[fat_sector_offset + 2] << 16) | (fat_sector[fat_sector_offset + 3] << 24)) + & 0x0fffffff; + if (old == 0 && (value & 0x0fffffff) != 0) + free_cluster_delta--; + else if (old != 0 && (value & 0x0fffffff) == 0) + free_cluster_delta++; + } + // Set the bytes for this cluster to $0FFFFF8 to mark end of chain and in use fat_sector[fat_sector_offset + 0] = (value)&0xff; fat_sector[fat_sector_offset + 1] = (value >> 8) & 0xff; @@ -2731,7 +2790,7 @@ BOOL is_free_cluster(unsigned int cluster) i = cluster / (512 / 4); o = cluster % (512 / 4) * 4; - if (read_sector(partition_start + fat1_sector + i, fat_sector, CACHE_YES, 0)) { + if (read_sector(partition_start + fat1_sector + i, fat_sector, CACHE_YES, FAT_SCAN_READAHEAD)) { log_error("failed to read sector $%x of first FAT", i); exit(-1); } @@ -2758,7 +2817,7 @@ unsigned int find_free_cluster(unsigned int first_cluster) for (; i < sectors_per_fat; i++) { // Read FAT sector // printf("Checking FAT sector $%x for free clusters.\n",i); - if (read_sector(partition_start + fat1_sector + i, fat_sector, CACHE_YES, 0)) { + if (read_sector(partition_start + fat1_sector + i, fat_sector, CACHE_YES, FAT_SCAN_READAHEAD)) { log_error("failed to read sector $%x of first FAT", i); retVal = -1; break; @@ -2892,13 +2951,24 @@ unsigned int count_total_clusters(unsigned int first_cluster) unsigned int find_contiguous_clusters(unsigned int total_clusters) { - unsigned int start_cluster = 0; + unsigned int max_cluster = sectors_per_fat * (512 / 4); + unsigned int start_cluster = free_cluster_hint; + int wrapped = (start_cluster < 2); while (1) { BOOL is_contiguous = TRUE; unsigned int cnt; start_cluster = find_free_cluster(start_cluster); + if (start_cluster == 0 || start_cluster + total_clusters > max_cluster) { + // ran off the end of the FAT: retry once from the beginning + if (wrapped) + return 0; + wrapped = 1; + start_cluster = 0; + continue; + } + for (cnt = 1; cnt < total_clusters; cnt++) { if (!is_free_cluster(start_cluster + cnt)) { is_contiguous = FALSE; @@ -2912,6 +2982,7 @@ unsigned int find_contiguous_clusters(unsigned int total_clusters) start_cluster += cnt; } + free_cluster_hint = start_cluster + total_clusters; return start_cluster; } @@ -4192,6 +4263,8 @@ int delete_single_file(char *name, BOOL consent) current_cluster = next_cluster; } while (current_cluster > 0 && current_cluster < FAT32_MIN_END_OF_CLUSTER_MARKER); + update_fsinfo_next_free(); + // Flush any pending sector writes out execute_write_queue(); @@ -4853,6 +4926,9 @@ int upload_single_file(char *name, char *dest_name) break; } + // Remember where free space continues, so the next session doesn't rescan the FAT + update_fsinfo_next_free(); + // Flush any pending sector writes out execute_write_queue(); @@ -4974,7 +5050,7 @@ int create_dir(char *dest_name) if (!first_cluster_of_file) { // printf("File currently has no first cluster allocated.\n"); - int a_cluster = find_free_cluster(0); + int a_cluster = find_contiguous_clusters(1); if (!a_cluster) { printf("ERROR: Failed to find a free cluster.\n"); retVal = -1; @@ -5063,6 +5139,8 @@ int create_dir(char *dest_name) assemble_time_into_raw(&buffer[0x20], tm); + if (parent_cluster == first_cluster) + parent_cluster = 0; // FAT spec: '..' in a subdirectory of the root points to cluster 0 buffer[0x20 + 0x1A] = (parent_cluster >> 0) & 0xff; buffer[0x20 + 0x1B] = (parent_cluster >> 8) & 0xff; buffer[0x20 + 0x14] = (parent_cluster >> 16) & 0xff; @@ -5102,6 +5180,8 @@ int create_dir(char *dest_name) break; } + update_fsinfo_next_free(); + // Flush any pending sector writes out execute_write_queue(); From 6319bbe902286dfbddd9199d5a3ca766cc0d6d09 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 3 Nov 2026 15:20:57 +1100 Subject: [PATCH 3/7] remotesd_eth: ack a write batch before its read-back verify The helper verified each 128-sector batch before sending the final ack, so the PC sat idle for the whole read-back. Now the verify runs from process() after the ack is out, before any new packet is handled (the RX buffers hold the next batch meanwhile). A failed verify still halts the helper. mega65_ftp does one extra round trip at the end of upload/mkdir/delete so a failure in the last batch is still reported. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SaBDrQJU9NJb1UxBiLfpfd --- src/tools/mega65_ftp.c | 14 ++++++++++++++ src/utilities/remotesd_eth.c | 26 ++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/tools/mega65_ftp.c b/src/tools/mega65_ftp.c index e02d130..86a6b29 100644 --- a/src/tools/mega65_ftp.c +++ b/src/tools/mega65_ftp.c @@ -126,6 +126,7 @@ char current_dir[1024] = "/"; int open_file_system(void); void update_fsinfo_next_free(void); +void confirm_writes_verified(void); int upload_slot(int slot_number, char* src_name); int download_slot(int sllot, char *dest_name); int download_file(char *dest_name, char *local_name, int showClusters); @@ -4267,6 +4268,7 @@ int delete_single_file(char *name, BOOL consent) // Flush any pending sector writes out execute_write_queue(); + confirm_writes_verified(); printf("%s '%s' successfully deleted\n", msg, name); return 0; @@ -4931,6 +4933,7 @@ int upload_single_file(char *name, char *dest_name) // Flush any pending sector writes out execute_write_queue(); + confirm_writes_verified(); if (time(0) == upload_start) upload_start = time(0) - 1; @@ -5184,6 +5187,7 @@ int create_dir(char *dest_name) // Flush any pending sector writes out execute_write_queue(); + confirm_writes_verified(); if (time(0) == upload_start) upload_start = time(0) - 1; @@ -5698,6 +5702,16 @@ unsigned char peek(unsigned long addr) } } +// The MEGA65 helper acks a write batch before reading it back to verify it, so the +// PC can keep going. Doing one more round trip makes sure the last batch passed its +// verify: the helper only answers once verification is done, and halts (so we time +// out with an error) if it failed. +void confirm_writes_verified(void) +{ + if (ethernet_mode) + peek(0xFFD3629); +} + void poke(unsigned long addr, unsigned char value) { if (ethernet_mode) { diff --git a/src/utilities/remotesd_eth.c b/src/utilities/remotesd_eth.c index e572ac3..ae49b42 100644 --- a/src/utilities/remotesd_eth.c +++ b/src/utilities/remotesd_eth.c @@ -177,6 +177,10 @@ uint8_t sector_reading, sector_buffered; uint32_t sector_number_read, sector_number_buf, sector_number_write; uint8_t read_batch_active = 0; uint8_t write_batch_active = 0; +// Set when a write batch has been fully written to SD. The read-back verify then runs +// from process() after the ack has gone out, so the PC isn't stalled waiting for it. +uint8_t verify_pending = 0; +void verify_written_batch(void); uint8_t slot_ids_received[256]; uint8_t slots_written; uint8_t write_batch_max_id = 0; @@ -706,9 +710,6 @@ void init_new_write_batch() void multi_sector_write_next() { - static uint32_t verify_sector_number = 0; - static uint32_t verify_cache_position = 0x40000ul; - static uint8_t i; int cmd = 5; // Multi-sector mid @@ -741,7 +742,17 @@ void multi_sector_write_next() return; } - // verify complete batch written against cache + // all slots written: verify later, after the ack for this packet has been sent + verify_pending = 1; +} + +void verify_written_batch(void) +{ + static uint32_t verify_sector_number; + static uint32_t verify_cache_position; + static uint8_t i; + + verify_pending = 0; verify_sector_number = sector_number_write; verify_cache_position = 0x40000ul; wait_for_sd_ready(); @@ -1357,6 +1368,13 @@ void process() write_batch_active = 0; } + // The ack for the batch's last packet has already been handed to the TX + // controller above, so verify now. New packets wait in the RX buffers meanwhile, + // and the batch cache at $40000 is not touched until we have finished. + if (verify_pending) { + verify_written_batch(); + } + if (sector_buffered) { lcopy((uint32_t)&reply_template, (uint32_t)&send_buf, ETH_HDR_SIZE + IPV6_HDR_SIZE + UDP_HDR_SIZE + FTP_HDR_SIZE + sizeof(READ_SECTOR_JOB)); // copy header incl. opcode From f97c509244cc861ee04b6819fea23aa4e78b3518 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 19:44:17 +1100 Subject: [PATCH 4/7] mega65_ftp: handle files of 2GB and larger - upload: remaining length was an int, so files >= 2GB wrote no data at all but still created a directory entry with the full size (and one cluster) - directory entries: file size was assembled with int shifts and stored in a long, so sizes >= 2GB went negative and those files were hidden from dir/get/del; now parsed as unsigned 32-bit into a long long - download: remaining byte count is now 64-bit - reject files over the FAT32 limit (4GB - 1) with a clear error Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SaBDrQJU9NJb1UxBiLfpfd --- src/tools/mega65_ftp.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/tools/mega65_ftp.c b/src/tools/mega65_ftp.c index 86a6b29..7becce4 100644 --- a/src/tools/mega65_ftp.c +++ b/src/tools/mega65_ftp.c @@ -73,7 +73,7 @@ char *usbdev_get_next_device(const int start) struct m65dirent { long d_ino; /* start cluster */ - long d_filelen; /* length of file */ + long long d_filelen; /* length of file (FAT32: 0 .. 4GB-1) */ unsigned short d_reclen; /* Always sizeof struct dirent. */ unsigned short d_namlen; /* Length of name in d_name. */ unsigned char d_attr; /* FAT file attributes */ @@ -2590,8 +2590,12 @@ int fat_readdir(struct m65dirent *d, int extend_dir_flag) if (dirent_raw == 2 && d->d_name[0]) dump_bytes(0, "dirent raw", &dir_sector_buffer[dir_sector_offset], 32); - d->d_filelen = (dir_sector_buffer[dir_sector_offset + 0x1C] << 0) | (dir_sector_buffer[dir_sector_offset + 0x1D] << 8) - | (dir_sector_buffer[dir_sector_offset + 0x1E] << 16) | (dir_sector_buffer[dir_sector_offset + 0x1F] << 24); + // Assemble as unsigned 32-bit: with int arithmetic, sizes >= 2GB came out negative and the + // file was then hidden from dir/get/del (they skip entries with d_filelen < 0). + d->d_filelen = (long long)((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1C] + | ((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1D] << 8) + | ((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1E] << 16) + | ((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1F] << 24)); d->d_attr = dir_sector_buffer[dir_sector_offset + 0xb]; if (d->d_attr & 0xC8) @@ -3351,7 +3355,7 @@ int show_directory(char *path) } else if (itm->d_name[0] && itm->d_filelen >= 0) { file_count++; - printf("%12d | %-20s | %-12s | %s\n", (int)itm->d_filelen, get_datetime_str(&itm->d_time), itm->d_name, + printf("%12lld | %-20s | %-12s | %s\n", itm->d_filelen, get_datetime_str(&itm->d_time), itm->d_name, itm->d_longname); } if (dirent_raw == 1) { @@ -3455,7 +3459,7 @@ int purge_directory_or_file(char *path) log_info("deleting | %-20s | %-12s | %s\n", get_datetime_str(&itm->d_time), itm->d_name, itm->d_longname); } else if (itm->d_name[0] && itm->d_filelen >= 0) { - log_info("deleting %12d | %-20s | %-12s | %s\n", (int)itm->d_filelen, get_datetime_str(&itm->d_time), itm->d_name, + log_info("deleting %12lld | %-20s | %-12s | %s\n", itm->d_filelen, get_datetime_str(&itm->d_time), itm->d_name, itm->d_longname); } @@ -4769,6 +4773,12 @@ int upload_single_file(char *name, char *dest_name) perror("stat() failed"); return -1; } + + if ((long long)st.st_size > 0xFFFFFFFFLL) { + fprintf(stderr, "ERROR: '%s' is %lld bytes. FAT32 files can be at most 4294967295 bytes (4GB - 1).\n", name, + (long long)st.st_size); + return -1; + } // printf("File '%s' is %ld bytes long.\n",name,(long)st.st_size); if (!safe_open_dir()) @@ -4846,7 +4856,7 @@ int upload_single_file(char *name, char *dest_name) } // else printf("First cluster of file is $%x\n",first_cluster_of_file); // Now write the file out sector by sector, and allocate new clusters as required - int remaining_length = st.st_size; + long long remaining_length = st.st_size; int sector_in_cluster = 0; int file_cluster = first_cluster_of_file; unsigned long long last_status_output = 0; @@ -5835,7 +5845,7 @@ int download_single_file(char *dest_name, char *local_name, int showClusters) unsigned int first_cluster_of_file = calc_first_cluster_of_file(); // Now write the file to local disk sector by sector - int remaining_bytes = de.d_filelen; + long long remaining_bytes = de.d_filelen; int sector_in_cluster = 0; int file_cluster = first_cluster_of_file; unsigned long long last_status_output = 0; From a0e492000cc8abb26245d8d7f6aefb9de0bb0564 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 21:33:07 +1100 Subject: [PATCH 5/7] mega65_ftp: show local file sizes >= 2GB correctly in ldir Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SaBDrQJU9NJb1UxBiLfpfd --- src/tools/mega65_ftp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/mega65_ftp.c b/src/tools/mega65_ftp.c index 7becce4..31de471 100644 --- a/src/tools/mega65_ftp.c +++ b/src/tools/mega65_ftp.c @@ -3178,7 +3178,7 @@ void show_local_directory(char *searchpattern) if (!stat(dir->d_name, &file_stats)) { if (!S_ISDIR(file_stats.st_mode)) { if (dir->d_name[0] && file_stats.st_size >= 0) - printf("%12d %s\n", (int)file_stats.st_size, dir->d_name); + printf("%12lld %s\n", (long long)file_stats.st_size, dir->d_name); } } } From 61d0c5876c3ed5d27d81119a93abfda42227820b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 10 Nov 2026 20:03:58 +1100 Subject: [PATCH 6/7] etherload: check the socket that was just created in probe_mega65_ipv6_address discoverfd is an array, so 'discoverfd < 0' compared the array address and a failed socket() call was never noticed. It is also a hard error in g++ 13+, which stopped the gtest suite from building. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SaBDrQJU9NJb1UxBiLfpfd --- src/tools/etherload/etherload_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/etherload/etherload_common.c b/src/tools/etherload/etherload_common.c index d6fd306..d0ad8c1 100644 --- a/src/tools/etherload/etherload_common.c +++ b/src/tools/etherload/etherload_common.c @@ -237,7 +237,7 @@ int probe_mega65_ipv6_address(int timeout_ms) for (int idx = 0; idx < num_if; ++idx) { // creating an IPv6 UDP server socket and listen on port 4510 for incoming packets discoverfd[idx] = socket(AF_INET6, SOCK_DGRAM, 0); - if (discoverfd < 0) { + if (discoverfd[idx] < 0) { log_crit("Unable to create socket"); goto leave_probe_mega65; } From 8ae67383294b3a9c229b96445e66c4605633db09 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 10 Nov 2026 20:04:23 +1100 Subject: [PATCH 7/7] mega65_ftp: clang-format the changed lines Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SaBDrQJU9NJb1UxBiLfpfd --- src/tools/mega65_ftp.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tools/mega65_ftp.c b/src/tools/mega65_ftp.c index 31de471..d8b37a3 100644 --- a/src/tools/mega65_ftp.c +++ b/src/tools/mega65_ftp.c @@ -2168,8 +2168,8 @@ int open_file_system(void) free_cluster_hint = 0; if (fsinfo_sector && fsinfo_sector < reserved_sectors) { unsigned char fsi[512]; - if (!read_sector(partition_start + fsinfo_sector, fsi, CACHE_YES, 0) && fsi[0] == 'R' && fsi[1] == 'R' - && fsi[2] == 'a' && fsi[3] == 'A' && fsi[484] == 'r' && fsi[485] == 'r' && fsi[486] == 'A' && fsi[487] == 'a') { + if (!read_sector(partition_start + fsinfo_sector, fsi, CACHE_YES, 0) && fsi[0] == 'R' && fsi[1] == 'R' && fsi[2] == 'a' + && fsi[3] == 'A' && fsi[484] == 'r' && fsi[485] == 'r' && fsi[486] == 'A' && fsi[487] == 'a') { unsigned int hint = fsi[492] | (fsi[493] << 8) | (fsi[494] << 16) | ((unsigned int)fsi[495] << 24); if (hint >= 2 && hint < sectors_per_fat * (512 / 4)) free_cluster_hint = hint; @@ -2593,9 +2593,9 @@ int fat_readdir(struct m65dirent *d, int extend_dir_flag) // Assemble as unsigned 32-bit: with int arithmetic, sizes >= 2GB came out negative and the // file was then hidden from dir/get/del (they skip entries with d_filelen < 0). d->d_filelen = (long long)((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1C] - | ((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1D] << 8) - | ((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1E] << 16) - | ((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1F] << 24)); + | ((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1D] << 8) + | ((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1E] << 16) + | ((uint32_t)dir_sector_buffer[dir_sector_offset + 0x1F] << 24)); d->d_attr = dir_sector_buffer[dir_sector_offset + 0xb]; if (d->d_attr & 0xC8) @@ -3355,8 +3355,8 @@ int show_directory(char *path) } else if (itm->d_name[0] && itm->d_filelen >= 0) { file_count++; - printf("%12lld | %-20s | %-12s | %s\n", itm->d_filelen, get_datetime_str(&itm->d_time), itm->d_name, - itm->d_longname); + printf( + "%12lld | %-20s | %-12s | %s\n", itm->d_filelen, get_datetime_str(&itm->d_time), itm->d_name, itm->d_longname); } if (dirent_raw == 1) { dump_bytes(0, "dirent raw", itm->de_raw, 32);