Compare commits

...

12 Commits

Author SHA1 Message Date
Devin AI
8d5142ec5e audit: rename lbl_ objects semantically, remove volatile use-site casts (owner rules)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 21:23:44 +00:00
Devin AI
2f5cecd891 fapark3: pf_fat12 ReadFATEntryWithBuf decl-order rotation (34->23 diffs)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 19:25:29 +00:00
Devin AI
fcad7ab6f2 fa: (s8) cast at FADrvTbl.drive use site in FAAttach (field stays char; header s8 broke linked C++ codegen)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 18:45:14 +00:00
Devin AI
7e3a856338 fa: s8 FADrvTbl.drive field type + document session-6 retests
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 18:42:25 +00:00
Devin AI
ce1c67016f pf_entry_iterator: match GetLFNEntryName via derived byte-IV decode
index = i * 13 per-iteration (non-affine) makes MWCC derive the byte-IV
(base+off recompute) instead of pointer-IV folding; terminator recomputed
from num_entry_LFNs * 26 >> 1 reproduces orig's mulli-0x1a + clrrwi.
Byte-identical.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 18:31:44 +00:00
Devin AI
cc45d98455 fapark3.attempts.md: session-5 findings
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 17:22:21 +00:00
Devin AI
45699e2372 fa/pdm_partition: MBR_WORD low-first merge + index decl-last
- MBR_WORD flat low-first (b0 + b1<<8 + b2<<16 + b3<<24): get_start_sector
  word diffs 146->45 (fuzzy 82.6->95.0); orig residual is pairwise
  (b2<<16+b0)+(b3<<24+b1<<8) scheduling, unreachable via + trees.
- is_master_boot_sector: pf_s16 index declared last -> pointer webs
  home r6/r7 correctly (35->25).

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 17:17:52 +00:00
Devin AI
378619bcb9 fa/pf_entry_iterator: named GLOBAL sdata string objects; pf_fat12: err late-init
- .sdata ".."/"."/":"/"\\"/"/" decode as file-scope GLOBAL pf_s8 objects
  (orig STB_GLOBAL lbl_81698350-81698360), replacing pooled literals;
  reloc sites now addend-0 to named objects like orig.
- ReadFATEntryWithBuf: pf_s32 err uninit + err=0 before while (34 vs 35).

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 17:13:53 +00:00
Devin AI
1cb165c9d7 fapark3.attempts.md: session-4 code-tie findings (volatile store-load pin, copy peel, IV/recompute walls)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 15:42:37 +00:00
Devin AI
32d3310567 sd_drv: 20/26 fns matched — copy_bytes peel split, volatile store-load pins
- copy_bytes: peeled dst[0]=*src form (abs-fold elem0 + k(r3) walk) for
  8B sites; plain-loop copy_bytes_all for 11B volume_label sites — reproduces
  orig's per-site peel/abs mix exactly. store_bpb_buf/store_fat32_bpb_buf
  now byte-identical.
- volatile-cast pins store->load source order: init (device store +
  media_inserted read; disk store + flags read) and finalize (flags write
  then media_inserted/disk/drive zeroes) now byte-identical. removal_callback
  media_inserted store + device check pinned the same way.
- init tail restructured to early-return (if disk!=info.disk return -44)
  matching orig's select->branch emission.
- get_disk_info str_base decl moved below result/status (no effect on the
  r30/r31 home swap — still a tie).
- Residual: regalloc-order ties (store_mbr_buf r8/r9, get_total_sectors,
  build_mbr_bpb r28/r29), removal_callback +1 (unproducible lbl_81690D54
  symbol boundary — MWCC forces 8-align, orig object sits at 0x3c),
  get_disk_info symbol truncation, build_fat32_mbr_bpb unreachable dead
  OSReport block (orig keeps emitted block MWCC deletes).

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 15:23:50 +00:00
Devin AI
b4253b4ad2 fa/fapark3: sd_drv full-data via STB_GLOBAL decode; pf_path sdata2 globals
sd_drv: merged 8 orig GLOBAL .data objects into one named array (byte-
identical 2576B), per-fn str_base pointer-homing matching orig's addend-0
reloc pattern, g_event aligned(32) for .sbss, 32B PFD_SDDRV_INFO with
reserved_1c tail. All four data sections now objdiff 100%.

pf_path: sdata2 sig bytes are orig file-scope u8 globals — declspec'd
non-const globals emit lbz-per-object codegen identical to orig. 2B tail
is an extraction hole (unproducible).

DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d unchanged.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 13:23:00 +00:00
Devin AI
e6a0b93a34 fa tie-break pass: adopt fapark sources, get_disk_info explicit return, sdata2 decl fix
- adopted prior-wave sources (pf_cluster/pf_dir/pf_fat/pf_path/sd_drv)
- pfd_sddrv_get_disk_info: return 0 on success path (insn-identical mod
  symbol truncation)
- pf_volume: deleted_entry_mark as non-static const (GLOBAL binding)
- documented fold/select/batch/reg-model walls in fapark3.attempts.md

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-01 11:57:43 +00:00
13 changed files with 644 additions and 150 deletions

View File

@@ -79,7 +79,7 @@ FAError FAAttach(u32 device, char* nand_path, u32 nand_size, FADrvTbl* table) {
if (error != 0) {
return -1;
}
index = table->drive - 'A';
index = (s8)table->drive - 'A';
if (device <= 2) {
gOpenDisk[index] = disk;
gOpenPartition[index] = table->pPart;

View File

@@ -11,6 +11,7 @@ typedef struct PFD_SDDRV_INFO {
u32 media_inserted;
u32 media_ejected;
s8 drive;
u32 reserved_1c;
} PFD_SDDRV_INFO;
typedef union PFD_SDDEV_STORAGE {
@@ -35,7 +36,152 @@ u8 g_pfd_sddrv_buf[0x200];
static FAInsertCallback g_attach_func = 0;
static FAEjectCallback g_detach_func = 0;
u32 g_event;
u32 g_event __attribute__((aligned(32)));
char sd_drv_error_strings[] =
"ERR:Failed to regist intr handler. pfd_st_inter_callback()\n\0"
"ERR:Failed to regist intr handler. pfd_st_removal_callback()\n\0"
"\0"
"\0"
"INFO SD Card driver is already initialize. pfd_sddrv_init()\n\0"
"\0"
"\0"
"\0"
"ERR:Failed to init SD Card Driver in pfd_sddrv_init()\n\0"
"\0"
"ERR SD card can not mount [ret = 0x%x]. pfd_sddrv_init()\n\0"
"\0"
"\0"
"ERR Failed to get sd card status. [ret = 0x%x]\n\0"
"ERR:Failed to regist intr handler1 [ret = 0x%x] pfd_sddrv_init()\n\0"
"\0"
"\0"
"INFO sdcard alrady mounted. pfd_sddrv_mount()\n\0"
"\0"
"ERROR Failed to SD Card Reset [ret = 0x%x]. pfd_sddrv_mount()\n\0"
"\0"
"ERR Failed to read OCR reg. pfd_sddrv_mount()\n\0"
"\0"
"ERR Failed to read CID reg. pfd_sddrv_mount()\n\0"
"\0"
"ERR Failed to read RCA reg. pfd_sddrv_mount()\n\0"
"";
char sd_drv_format_sd[] =
"FULL_FORMAT";
char sd_drv_msg_open_fail[] =
"ERR Failed to full format. pfd_sddrv_full_format()\n";
char sd_drv_msg_read_fail[] =
"WARNING Faild to UnregisterDeviceIntrHandler sd card [ret = %d]\n\0"
"\0"
"\0"
"";
char sd_drv_msg_write_fail[] =
"WARNING Faild to unmount sd card [ret = %d]\n\0"
"\0"
"\0"
"\0"
"INFO Card not inserted! in pfd_sddrv_get_disk_info()\n\0"
"\0"
"\0"
"INFO Card removed! in pfd_sddrv_get_disk_info()\n\0"
"\0"
"\0"
"\0"
"INFO SD card type is not memory. in pfd_sddrv_get_disk_info()\n\0"
"\0"
"ERR Failed to read master boot sector. pfd_sddrv_get_disk_info()\n\0"
"\0"
"\0"
"INFO Failed to read SD card1 [ret = 0x%x] pfd_sddrv_physical_read()\n\0"
"\0"
"\0"
"\0"
"INFO Failed to read SD card2 [ret = 0x%x] pfd_sddrv_physical_read()\n\0"
"\0"
"\0"
"\0"
"INFO Failed to read SD card3 [ret = 0x%x] pfd_sddrv_physical_read()\n\0"
"\0"
"\0"
"\0"
"INFO Failed to write SD card1 [ret = 0x%x] pfd_sddrv_physical_write()\n\0"
"\0"
"INFO Failed to write SD card2 [ret = 0x%x] pfd_sddrv_physical_write()\n\0"
"\0"
"INFO Failed to write SD card3 [ret = 0x%x] pfd_sddrv_physical_write()\n\0"
"";
char sd_drv_msg_ioctl[] =
"ERR Failed to get CSD Info. pfd_sddrv_get_total_sectors()\n\0"
"";
char sd_drv_msg_status[] =
"ERR Failed to get values with total sectors. pfd_sddrv_get_value_with_total_sectors()\n\0"
"\0"
" \0"
"\0"
"\0"
"\0"
"NO NAME \0"
"FAT12 \0"
"\0"
"\0"
"\0"
"FAT16 \0"
"\0"
"\0"
"\0"
"ERR Failed to calculate MBR and BPB values. pfd_sddrv_calc_mbr_bpb()\n\0"
"\0"
"\0"
"ERR Failed to store BPB values to buf. pfd_sddrv_store_bpb_buf()\n\0"
"\0"
"\0"
"ERR Failed to write BPB fields. ISD_WriteBlock()\n\0"
"\0"
"\0"
"ERR Failed to store MBR values to buf. pfd_sddrv_store_mbr_buf()\n\0"
"\0"
"\0"
"ERR Failed to write MBR fields. ISD_WriteBlock()\n\0"
"\0"
"\0"
"FAT32 \0"
"\0"
"\0"
"\0"
"ERR Failed to calculate MBR and BPB values. pfd_sddrv_calc_fat32_mbr_bpb()\n\0"
"\0"
"\0"
"\0"
"\0"
"ERR Failed to store BPB values to buf. pfd_sddrv_store_fat32_bpb_buf()\n\0"
"ERR Failed to store FSInfo values to buf. pfd_sddrv_store_fat32_fsi_buf()\n\0"
"\0"
"ERR Failed to store reserved for boot sector values to buf. \0"
"\0"
"\0"
"\0"
"pfd_sddrv_store_fat32_reserved_buf()\n\0"
"\0"
"\0"
"ERROR Failed to SD Card Reset [ret = 0x%x]. pfd_sddrv_full_format()\n\0"
"\0"
"\0"
"\0"
"\0"
"\0"
"\0"
"\0"
"ERR Failed to get total sectors. pfd_sddrv_get_total_sectors()\n\0"
"ERR Failed to build up and write MBR and BPB fields.\n\0"
"\0"
"";
extern u8 pfd_get_media_drv_char(FADisk*, s8*, u32);
extern void pdm_disk_notify_media_insert(FADisk*);
@@ -44,17 +190,29 @@ extern void* pf_memset(void*, s32, u32);
extern void* pf_memcpy(void*, const void*, u32);
extern s32 pf_strcmp(const char*, const char*);
s32 pfd_st_inter_callback(s32 status, void* data);
s32 pfd_st_removal_callback(s32 status, void* data);
static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_sector, u32* blocks_read);
s32 pfd_sddrv_physical_write(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_sector, u32* blocks_written);
s32 pfd_sddrv_init(FADisk* disk);
s32 pfd_sddrv_finalize(FADisk* disk);
s32 pfd_sddrv_mount(FADisk* disk);
s32 pfd_sddrv_unmount(FADisk* disk);
s32 pfd_sddrv_format(FADisk* disk, u8* format_name);
s32 pfd_sddrv_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* blocks_read);
s32 pfd_sddrv_pwrite(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* blocks_written);
s32 pfd_sddrv_get_disk_info(FADisk* disk, FADiskInfo* disk_info);
const FAFuncTbl pfd_sddrv_func = {
@@ -162,8 +320,21 @@ typedef union PFD_SDDRV_U16_BYTES {
static inline void pfd_sddrv_copy_bytes(u8* destination, const u8* source, u32 size) {
u32 index;
if (destination != 0 && source != 0) {
const u8* src = source;
destination[0] = *src;
src++;
for (index = 1; index < size; index++) {
destination[index] = *src++;
}
}
}
static inline void pfd_sddrv_copy_bytes_all(u8* destination, const u8* source, u32 size) {
u32 index;
if (destination != 0 && source != 0) {
const u8* src = source;
for (index = 0; index < size; index++) {
destination[index] = source[index];
destination[index] = *src++;
}
}
}
@@ -259,6 +430,7 @@ static inline s8 pfd_sddrv_drive(const PFD_SDDRV_INFO* info) {
return info->drive;
}
s32 pfd_st_inter_callback(s32 status, void* data) {
s32 result;
@@ -269,7 +441,7 @@ s32 pfd_st_inter_callback(s32 status, void* data) {
g_event = 2;
result = ISD_RegisterDeviceIntrHandler(g_pfd_sddrv_info.device, (SDDevIntrCallback)pfd_st_removal_callback, &g_event);
if (result != 0) {
OSReport("ERR:Failed to regist intr handler. pfd_st_inter_callback()\n");
OSReport((const char*)sd_drv_error_strings);
}
}
if (pfd_sddrv_disk(&g_pfd_sddrv_info) != 0) {
@@ -284,6 +456,7 @@ s32 pfd_st_inter_callback(s32 status, void* data) {
return 0;
}
s32 pfd_st_removal_callback(s32 status, void* data) {
s32 result;
@@ -291,11 +464,11 @@ s32 pfd_st_removal_callback(s32 status, void* data) {
return 0;
}
g_pfd_sddrv_info.media_inserted = 0;
if (pfd_sddrv_device(&g_pfd_sddrv_info) != 0) {
if (g_pfd_sddrv_info.device != 0) {
g_event = 1;
result = ISD_RegisterDeviceIntrHandler(g_pfd_sddrv_info.device, (SDDevIntrCallback)pfd_st_inter_callback, &g_event);
if (result != 0) {
OSReport("ERR:Failed to regist intr handler. pfd_st_removal_callback()\n");
OSReport(&sd_drv_error_strings[0x3c]);
}
}
if (pfd_sddrv_disk(&g_pfd_sddrv_info) != 0) {
@@ -308,27 +481,29 @@ s32 pfd_st_removal_callback(s32 status, void* data) {
return 0;
}
s32 pfd_sddrv_init(FADisk* disk) {
const char* str_base = sd_drv_error_strings;
s32 sd_result;
SDDev* device;
u32 status;
if (disk == 0) {
if (disk == NULL) {
return -30;
}
if ((pfd_sddrv_flags(&g_pfd_sddrv_info) & 1) != 0) {
OSReport("INFO SD Card driver is already initialize. pfd_sddrv_init()\n");
if (disk == g_pfd_sddrv_info.disk) {
return 0;
OSReport((str_base + 0x7c));
if (disk != g_pfd_sddrv_info.disk) {
return -44;
}
return -44;
return 0;
}
if ((g_pfd_sddrv_info.flags & 4) == 0) {
g_pfd_sddrv_info.bytes_per_sector = 0x200;
pf_memset(&g_pfd_sddev, 0, 0x28);
sd_result = ISD_InitCard();
if (sd_result != 0) {
OSReport("ERR:Failed to init SD Card Driver in pfd_sddrv_init()\n");
OSReport((str_base + 0xbc));
return -40;
}
g_pfd_sddrv_info.flags |= 4;
@@ -337,12 +512,12 @@ s32 pfd_sddrv_init(FADisk* disk) {
device = &g_pfd_sddev.device;
sd_result = ISD_MountCard(0, &device);
if (sd_result != 0) {
OSReport("ERR SD card can not mount [ret = 0x%x]. pfd_sddrv_init()\n", sd_result);
OSReport((str_base + 0xf4), sd_result);
return -41;
}
sd_result = ISD_GetDeviceStatus(device, &status);
if (sd_result != 0) {
OSReport("ERR Failed to get sd card status. [ret = 0x%x]\n", sd_result);
OSReport((str_base + 0x130), sd_result);
return 21;
}
if ((status & 1) != 0) {
@@ -353,7 +528,7 @@ s32 pfd_sddrv_init(FADisk* disk) {
g_event = 2;
sd_result = ISD_RegisterDeviceIntrHandler(device, (SDDevIntrCallback)pfd_st_removal_callback, &g_event);
if (sd_result != 0) {
OSReport("ERR:Failed to regist intr handler1 [ret = 0x%x] pfd_sddrv_init()\n", sd_result);
OSReport((str_base + 0x160), sd_result);
ISD_UnmountCard(device);
g_pfd_sddrv_info.device = 0;
return -42;
@@ -362,7 +537,7 @@ s32 pfd_sddrv_init(FADisk* disk) {
g_event = 1;
sd_result = ISD_RegisterDeviceIntrHandler(device, (SDDevIntrCallback)pfd_st_inter_callback, &g_event);
if (sd_result != 0) {
OSReport("ERR:Failed to regist intr handler1 [ret = 0x%x] pfd_sddrv_init()\n", sd_result);
OSReport((str_base + 0x160), sd_result);
ISD_UnmountCard(device);
g_pfd_sddrv_info.device = 0;
return -42;
@@ -373,7 +548,9 @@ s32 pfd_sddrv_init(FADisk* disk) {
return 0;
}
s32 pfd_sddrv_mount(FADisk* disk) {
const char* str_base = sd_drv_error_strings;
s32 result;
u32 attempts;
u32 ocr;
@@ -387,7 +564,7 @@ s32 pfd_sddrv_mount(FADisk* disk) {
return -33;
}
if ((g_pfd_sddrv_info.flags & 2) != 0) {
OSReport("INFO sdcard alrady mounted. pfd_sddrv_mount()\n");
OSReport((str_base + 0x1a4));
return 0;
}
attempts = 0;
@@ -400,7 +577,7 @@ s32 pfd_sddrv_mount(FADisk* disk) {
g_pfd_sddrv_info.media_ejected = 0;
break;
}
OSReport("ERROR Failed to SD Card Reset [ret = 0x%x]. pfd_sddrv_mount()\n", result);
OSReport((str_base + 0x1d4), result);
attempts++;
} while (attempts < 5);
if (attempts == 5) {
@@ -412,27 +589,29 @@ s32 pfd_sddrv_mount(FADisk* disk) {
ocr = 0;
result = ISD_ReadCardRegister(g_pfd_sddrv_info.device, 0x29, &ocr, 4);
if (result != 0) {
OSReport("ERR Failed to read OCR reg. pfd_sddrv_mount()\n");
OSReport((str_base + 0x214));
return -43;
}
pf_memset(cid, 0, 0x10);
result = ISD_ReadCardRegister(g_pfd_sddrv_info.device, 10, (u32*)cid, 0x10);
if (result != 0) {
OSReport("ERR Failed to read CID reg. pfd_sddrv_mount()\n");
OSReport((str_base + 0x244));
return -43;
}
rca = 0;
result = ISD_ReadCardRegister(g_pfd_sddrv_info.device, 3, (u32*)&rca, 2);
if (result != 0) {
OSReport("ERR Failed to read RCA reg. pfd_sddrv_mount()\n");
OSReport((str_base + 0x274));
return -43;
}
g_pfd_sddrv_info.flags |= 2;
return 0;
}
s32 pfd_sddrv_full_format(void);
s32 pfd_sddrv_format(FADisk* disk, u8* format_name) {
s32 result;
@@ -443,11 +622,11 @@ s32 pfd_sddrv_format(FADisk* disk, u8* format_name) {
return -33;
}
if (format_name != 0) {
result = pf_strcmp((char*)format_name, "FULL_FORMAT");
result = pf_strcmp((char*)format_name, sd_drv_format_sd);
if (result == 0) {
result = pfd_sddrv_full_format();
if (result != 0) {
OSReport("ERR Failed to full format. pfd_sddrv_full_format()\n");
OSReport(sd_drv_msg_open_fail);
return result;
}
}
@@ -455,6 +634,7 @@ s32 pfd_sddrv_format(FADisk* disk, u8* format_name) {
return 0;
}
s32 pfd_sddrv_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* blocks_read) {
if (disk == 0 || buffer == 0 || blocks_read == 0) {
return -30;
@@ -462,6 +642,7 @@ s32 pfd_sddrv_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* block
return pfd_sddrv_physical_read(blocks, buffer, sector, g_pfd_sddrv_info.bytes_per_sector, blocks_read);
}
s32 pfd_sddrv_pwrite(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* blocks_written) {
if (disk == 0 || buffer == 0 || blocks_written == 0) {
return -30;
@@ -469,6 +650,7 @@ s32 pfd_sddrv_pwrite(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* bloc
return pfd_sddrv_physical_write(blocks, buffer, sector, g_pfd_sddrv_info.bytes_per_sector, blocks_written);
}
s32 pfd_sddrv_unmount(FADisk* disk) {
if (disk == 0) {
return -30;
@@ -479,6 +661,7 @@ s32 pfd_sddrv_unmount(FADisk* disk) {
return 0;
}
s32 pfd_sddrv_finalize(FADisk* disk) {
s32 result;
@@ -491,11 +674,11 @@ s32 pfd_sddrv_finalize(FADisk* disk) {
if ((g_pfd_sddrv_info.flags & 1) != 0) {
result = ISD_UnregisterDeviceIntrHandler(g_pfd_sddrv_info.device);
if (result != 0) {
OSReport("WARNING Faild to UnregisterDeviceIntrHandler sd card [ret = %d]\n", result);
OSReport(sd_drv_msg_read_fail, result);
}
result = ISD_UnmountCard(g_pfd_sddrv_info.device);
if (result != 0) {
OSReport("WARNING Faild to unmount sd card [ret = %d]\n", result);
OSReport(sd_drv_msg_write_fail, result);
}
g_pfd_sddrv_info.device = 0;
}
@@ -506,11 +689,14 @@ s32 pfd_sddrv_finalize(FADisk* disk) {
return 0;
}
s32 pfd_sddrv_get_total_sectors(u32* sectors, u16* bytes_per_sector);
s32 pfd_sddrv_get_disk_info(FADisk* disk, FADiskInfo* disk_info) {
s32 result;
u32 status;
const char* str_base = sd_drv_error_strings;
if (disk == 0 || disk_info == 0) {
return -30;
@@ -526,19 +712,19 @@ s32 pfd_sddrv_get_disk_info(FADisk* disk, FADiskInfo* disk_info) {
}
result = ISD_GetDeviceStatus(g_pfd_sddrv_info.device, &status);
if (result != 0) {
OSReport("ERR Failed to get sd card status. [ret = 0x%x]\n", result);
OSReport((str_base + 0x130), result);
return -39;
}
if ((status & 1) == 0) {
OSReport("INFO Card not inserted! in pfd_sddrv_get_disk_info()\n");
OSReport((str_base + 0x358));
return -33;
}
if ((status & 2) != 0) {
OSReport("INFO Card removed! in pfd_sddrv_get_disk_info()\n");
OSReport((str_base + 0x390));
return -33;
}
if ((status & 0x10000) == 0 && (status & 0x100000) == 0) {
OSReport("INFO SD card type is not memory. in pfd_sddrv_get_disk_info()\n");
OSReport((str_base + 0x3c4));
return -35;
}
disk_info->mediaAttr = 4;
@@ -547,28 +733,31 @@ s32 pfd_sddrv_get_disk_info(FADisk* disk, FADiskInfo* disk_info) {
}
result = pfd_sddrv_get_total_sectors(&disk_info->totalSectors, &disk_info->bytesPerSector);
if (result != 0) {
OSReport("ERR Failed to read master boot sector. pfd_sddrv_get_disk_info()\n");
OSReport((str_base + 0x404));
return result;
}
disk_info->cylinders = 0;
disk_info->heads = 0;
disk_info->sectorsPerTrack = 0;
disk_info->formatParam = 0;
return result;
return 0;
}
s32 pfd_sddrv_init_drv_tbl(FADiskTbl* disk_table, u32 extended) {
disk_table->uiExt = extended;
disk_table->pFunc = (FAFuncTbl*)&pfd_sddrv_func;
return 0;
}
s32 pfd_sddrv_registar_callback(FAInsertCallback attach, FAEjectCallback detach) {
g_attach_func = attach;
g_detach_func = detach;
return 0;
}
s32 pfd_sddrv_is_media_insert(void) {
s32 result;
s8 drive;
@@ -589,7 +778,9 @@ s32 pfd_sddrv_is_media_insert(void) {
return result;
}
static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_sector, u32* blocks_read) {
const char* str_base = sd_drv_error_strings;
s32 result;
s32 current_sector;
u32 completed;
@@ -615,14 +806,14 @@ static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes
if (blocks == 1) {
result = ISD_ReadBlock(g_pfd_sddrv_info.device, current_sector, buffer, blocks);
if (result != 0) {
OSReport("INFO Failed to read SD card1 [ret = 0x%x] pfd_sddrv_physical_read()\n", result);
OSReport((str_base + 0x448), result);
*blocks_read = 0;
return -37;
}
} else {
result = ISD_ReadMultiBlock(g_pfd_sddrv_info.device, current_sector, buffer, blocks);
if (result != 0) {
OSReport("INFO Failed to read SD card2 [ret = 0x%x] pfd_sddrv_physical_read()\n", result);
OSReport((str_base + 0x490), result);
*blocks_read = 0;
return -37;
}
@@ -639,7 +830,7 @@ static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes
}
result = ISD_ReadBlock(g_pfd_sddrv_info.device, current_sector, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("INFO Failed to read SD card3 [ret = 0x%x] pfd_sddrv_physical_read()\n", result);
OSReport((str_base + 0x4d8), result);
if (completed != 0) {
*blocks_read = completed;
return 0;
@@ -654,7 +845,9 @@ static s32 pfd_sddrv_physical_read(u32 blocks, u8* buffer, u32 sector, u32 bytes
return 0;
}
s32 pfd_sddrv_physical_write(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_sector, u32* blocks_written) {
const char* str_base = sd_drv_error_strings;
s32 result;
s32 current_sector;
u32 completed;
@@ -680,14 +873,14 @@ s32 pfd_sddrv_physical_write(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_s
if (blocks == 1) {
result = ISD_WriteBlock(g_pfd_sddrv_info.device, current_sector, buffer, blocks);
if (result != 0) {
OSReport("INFO Failed to write SD card1 [ret = 0x%x] pfd_sddrv_physical_write()\n", result);
OSReport((str_base + 0x520), result);
*blocks_written = 0;
return -36;
}
} else {
result = ISD_WriteMultiBlock(g_pfd_sddrv_info.device, current_sector, buffer, blocks);
if (result != 0) {
OSReport("INFO Failed to write SD card2 [ret = 0x%x] pfd_sddrv_physical_write()\n", result);
OSReport((str_base + 0x568), result);
*blocks_written = 0;
return -36;
}
@@ -705,7 +898,7 @@ s32 pfd_sddrv_physical_write(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_s
pf_memcpy(g_pfd_sddrv_buf, current_buffer, bytes_per_sector);
result = ISD_WriteBlock(g_pfd_sddrv_info.device, current_sector, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("INFO Failed to write SD card3 [ret = 0x%x] pfd_sddrv_physical_write()\n", result);
OSReport((str_base + 0x5b0), result);
if (completed != 0) {
*blocks_written = completed;
return 0;
@@ -719,6 +912,7 @@ s32 pfd_sddrv_physical_write(u32 blocks, u8* buffer, u32 sector, u32 bytes_per_s
return 0;
}
s32 pfd_sddrv_get_total_sectors(u32* sectors, u16* bytes_per_sector) {
s32 result;
u32 csd[4];
@@ -737,7 +931,7 @@ s32 pfd_sddrv_get_total_sectors(u32* sectors, u16* bytes_per_sector) {
pf_memset(csd, 0, 0x10);
result = ISD_ReadCardRegister(g_pfd_sddrv_info.device, 9, csd, 0x10);
if (result != 0) {
OSReport("ERR Failed to get CSD Info. pfd_sddrv_get_total_sectors()\n");
OSReport(sd_drv_msg_ioctl);
return -43;
}
if ((csd[3] & 0x400000) == 0) {
@@ -766,6 +960,7 @@ static inline u32 pfd_sddrv_encode_serial(s32 year, s32 month, s32 day, s32 hour
return (date << 16) + time;
}
s32 pfd_sddrv_calc_mbr_bpb(PFD_SDDRV_FORMAT_DATA* format_data) {
PFD_SDDRV_SIZE_SETTINGS settings;
u32 entry_index;
@@ -803,7 +998,7 @@ s32 pfd_sddrv_calc_mbr_bpb(PFD_SDDRV_FORMAT_DATA* format_data) {
}
result = entry_index == 14 ? -30 : 0;
if (result != 0) {
OSReport("ERR Failed to get values with total sectors. pfd_sddrv_get_value_with_total_sectors()\n");
OSReport(sd_drv_msg_status);
return result;
}
format_data->sectors_per_cluster = settings.sectors_per_cluster;
@@ -883,7 +1078,9 @@ s32 pfd_sddrv_calc_mbr_bpb(PFD_SDDRV_FORMAT_DATA* format_data) {
}
s32 pfd_sddrv_store_bpb_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector_buffer) {
const char* str_base = sd_drv_error_strings;
PFD_SDDRV_SIZE_SETTINGS settings;
PFD_SDDRV_BPB* boot_sector;
u32 entry_index;
@@ -910,7 +1107,7 @@ s32 pfd_sddrv_store_bpb_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector_buffe
}
result = entry_index == 14 ? -30 : 0;
if (result != 0) {
OSReport("ERR Failed to get values with total sectors. pfd_sddrv_get_value_with_total_sectors()\n");
OSReport((str_base + 0x634));
return result;
}
sectors_32 = format_data->partition_sector_count;
@@ -924,12 +1121,12 @@ s32 pfd_sddrv_store_bpb_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector_buffe
}
pf_memset(sector_buffer, 0, 0x200);
boot_sector = (PFD_SDDRV_BPB*)sector_buffer;
pfd_sddrv_copy_bytes(boot_sector->oem_name, (const u8*)" ", 8);
pfd_sddrv_copy_bytes(boot_sector->volume_label, (const u8*)"NO NAME ", 11);
pfd_sddrv_copy_bytes(boot_sector->oem_name, (const u8*)(str_base + 0x68c), 8);
pfd_sddrv_copy_bytes_all(boot_sector->volume_label, (const u8*)(str_base + 0x698), 11);
if (format_data->fat_type == 0) {
pfd_sddrv_copy_bytes(boot_sector->file_system_type, (const u8*)"FAT12 ", 8);
pfd_sddrv_copy_bytes(boot_sector->file_system_type, (const u8*)(str_base + 0x6a4), 8);
} else {
pfd_sddrv_copy_bytes(boot_sector->file_system_type, (const u8*)"FAT16 ", 8);
pfd_sddrv_copy_bytes(boot_sector->file_system_type, (const u8*)(str_base + 0x6b0), 8);
}
boot_sector->jump[0] = 0xeb;
boot_sector->jump[1] = 0;
@@ -954,6 +1151,7 @@ s32 pfd_sddrv_store_bpb_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector_buffe
return 0;
}
s32 pfd_sddrv_store_mbr_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector_buffer) {
PFD_SDDRV_SIZE_SETTINGS settings;
PFD_SDDRV_MBR* master_boot_record;
@@ -987,7 +1185,7 @@ s32 pfd_sddrv_store_mbr_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector_buffe
}
result = entry_index == 14 ? -30 : 0;
if (result != 0) {
OSReport("ERR Failed to get values with total sectors. pfd_sddrv_get_value_with_total_sectors()\n");
OSReport(sd_drv_msg_status);
return result;
}
start_cylinder = format_data->partition_start_sector / (settings.fat_copies * settings.root_entries);
@@ -1024,7 +1222,9 @@ s32 pfd_sddrv_store_mbr_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector_buffe
return 0;
}
s32 pfd_sddrv_build_mbr_bpb(u32 total_sectors) {
const char* str_base = sd_drv_error_strings;
PFD_SDDRV_FORMAT_DATA format_data;
s32 result;
u32 partition_start_sector;
@@ -1033,12 +1233,12 @@ s32 pfd_sddrv_build_mbr_bpb(u32 total_sectors) {
format_data.total_sectors = total_sectors;
result = pfd_sddrv_calc_mbr_bpb(&format_data);
if (result != 0) {
OSReport("ERR Failed to calculate MBR and BPB values. pfd_sddrv_calc_mbr_bpb()\n");
OSReport((str_base + 0x6bc));
return result;
}
result = pfd_sddrv_store_bpb_buf(&format_data, g_pfd_sddrv_buf);
if (result != 0) {
OSReport("ERR Failed to store BPB values to buf. pfd_sddrv_store_bpb_buf()\n");
OSReport((str_base + 0x704));
return result;
}
partition_start_sector = format_data.partition_start_sector;
@@ -1050,12 +1250,12 @@ s32 pfd_sddrv_build_mbr_bpb(u32 total_sectors) {
}
result = ISD_WriteBlock(g_pfd_sddrv_info.device, partition_start_sector, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("ERR Failed to write BPB fields. ISD_WriteBlock()\n");
OSReport((str_base + 0x748));
return -36;
}
result = pfd_sddrv_store_mbr_buf(&format_data, g_pfd_sddrv_buf);
if (result != 0) {
OSReport("ERR Failed to store MBR values to buf. pfd_sddrv_store_mbr_buf()\n");
OSReport((str_base + 0x77c));
return result;
}
if (g_pfd_sddrv_info.media_inserted == 0) {
@@ -1066,12 +1266,13 @@ s32 pfd_sddrv_build_mbr_bpb(u32 total_sectors) {
}
result = ISD_WriteBlock(g_pfd_sddrv_info.device, 0, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("ERR Failed to write MBR fields. ISD_WriteBlock()\n");
OSReport((str_base + 0x7c0));
return -36;
}
return 0;
}
s32 pfd_sddrv_calc_fat32_mbr_bpb(PFD_SDDRV_FORMAT_DATA* format_data) {
u8 sectors_per_cluster;
u32 fat_sector_count;
@@ -1113,7 +1314,7 @@ s32 pfd_sddrv_calc_fat32_mbr_bpb(PFD_SDDRV_FORMAT_DATA* format_data) {
}
result = entry_index == 14 ? -30 : 0;
if (result != 0) {
OSReport("ERR Failed to get values with total sectors. pfd_sddrv_get_value_with_total_sectors()\n");
OSReport(sd_drv_msg_status);
return result;
}
sectors_per_cluster = settings.sectors_per_cluster;
@@ -1171,6 +1372,7 @@ s32 pfd_sddrv_calc_fat32_mbr_bpb(PFD_SDDRV_FORMAT_DATA* format_data) {
return 0;
}
s32 pfd_sddrv_store_fat32_mbr_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector_buffer) {
PFD_SDDRV_SIZE_SETTINGS settings;
PFD_SDDRV_MBR* master_boot_record;
@@ -1206,7 +1408,7 @@ s32 pfd_sddrv_store_fat32_mbr_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector
}
result = entry_index == 14 ? -30 : 0;
if (result != 0) {
OSReport("ERR Failed to get values with total sectors. pfd_sddrv_get_value_with_total_sectors()\n");
OSReport(sd_drv_msg_status);
return result;
}
if (format_data->partition_start_sector > 0xfb0400) {
@@ -1248,6 +1450,7 @@ s32 pfd_sddrv_store_fat32_mbr_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector
return 0;
}
s32 pfd_sddrv_store_fat32_fsi_buf(u8* sector_buffer) NO_INLINE {
PFD_SDDRV_FAT32_FSINFO* fs_info;
@@ -1296,7 +1499,9 @@ s32 pfd_sddrv_store_fat32_fsi_buf(u8* sector_buffer) NO_INLINE {
return 0;
}
s32 pfd_sddrv_store_fat32_bpb_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector_buffer) {
const char* str_base = sd_drv_error_strings;
PFD_SDDRV_SIZE_SETTINGS settings;
PFD_SDDRV_FAT32_BPB* boot_sector;
u32 entry_index;
@@ -1321,14 +1526,14 @@ s32 pfd_sddrv_store_fat32_bpb_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector
}
result = entry_index == 14 ? -30 : 0;
if (result != 0) {
OSReport("ERR Failed to get values with total sectors. pfd_sddrv_get_value_with_total_sectors()\n");
OSReport((str_base + 0x634));
return result;
}
pf_memset(sector_buffer, 0, 0x200);
boot_sector = (PFD_SDDRV_FAT32_BPB*)sector_buffer;
pfd_sddrv_copy_bytes(boot_sector->oem_name, (const u8*)" ", 8);
pfd_sddrv_copy_bytes(boot_sector->volume_label, (const u8*)"NO NAME ", 11);
pfd_sddrv_copy_bytes(boot_sector->filesystem_type, (const u8*)"FAT32 ", 8);
pfd_sddrv_copy_bytes(boot_sector->oem_name, (const u8*)&str_base[0x68c], 8);
pfd_sddrv_copy_bytes_all(boot_sector->volume_label, (const u8*)((str_base + 0x698)), 11);
pfd_sddrv_copy_bytes(boot_sector->filesystem_type, (const u8*)((str_base + 0x7f4)), 8);
boot_sector->jump[0] = 0xeb;
boot_sector->jump[1] = 0;
boot_sector->jump[2] = 0x90;
@@ -1358,12 +1563,10 @@ s32 pfd_sddrv_store_fat32_bpb_buf(PFD_SDDRV_FORMAT_DATA* format_data, u8* sector
return 0;
}
static s32 pfd_sddrv_store_fat32_reserved_buf(u8* sector_buffer) {
PFD_SDDRV_RESERVED_BOOT_SECTOR* reserved_boot_sector;
if (sector_buffer == 0) {
return -30;
}
pf_memset(sector_buffer, 0, 0x200);
reserved_boot_sector = (PFD_SDDRV_RESERVED_BOOT_SECTOR*)sector_buffer;
if (((u32)reserved_boot_sector->signature.bytes & 1) != 0) {
@@ -1375,19 +1578,21 @@ static s32 pfd_sddrv_store_fat32_reserved_buf(u8* sector_buffer) {
return 0;
}
s32 pfd_sddrv_build_fat32_mbr_bpb(u32 total_sectors) {
const char* str_base = sd_drv_error_strings;
PFD_SDDRV_FORMAT_DATA format_data;
s32 result;
pf_memset(&format_data, 0, 0x20);
format_data.total_sectors = total_sectors;
result = pfd_sddrv_calc_fat32_mbr_bpb(&format_data);
if (result != 0) {
OSReport("ERR Failed to calculate MBR and BPB values. pfd_sddrv_calc_fat32_mbr_bpb()\n");
OSReport((str_base + 0x800));
return result;
}
result = pfd_sddrv_store_fat32_bpb_buf(&format_data, g_pfd_sddrv_buf);
if (result != 0) {
OSReport("ERR Failed to store BPB values to buf. pfd_sddrv_store_fat32_bpb_buf()\n");
OSReport((str_base + 0x850));
return result;
}
if (g_pfd_sddrv_info.media_inserted == 0) {
@@ -1398,17 +1603,17 @@ s32 pfd_sddrv_build_fat32_mbr_bpb(u32 total_sectors) {
}
result = ISD_WriteBlock(g_pfd_sddrv_info.device, format_data.partition_start_sector, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("ERR Failed to write BPB fields. ISD_WriteBlock()\n");
OSReport((str_base + 0x748));
return -36;
}
result = ISD_WriteBlock(g_pfd_sddrv_info.device, format_data.partition_start_sector + 6, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("ERR Failed to write BPB fields. ISD_WriteBlock()\n");
OSReport((str_base + 0x748));
return -36;
}
result = pfd_sddrv_store_fat32_fsi_buf(g_pfd_sddrv_buf);
if (result != 0) {
OSReport("ERR Failed to store FSInfo values to buf. pfd_sddrv_store_fat32_fsi_buf()\n");
OSReport((str_base + 0x898));
return result;
}
if (g_pfd_sddrv_info.media_inserted == 0) {
@@ -1419,18 +1624,18 @@ s32 pfd_sddrv_build_fat32_mbr_bpb(u32 total_sectors) {
}
result = ISD_WriteBlock(g_pfd_sddrv_info.device, format_data.partition_start_sector + 1, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("ERR Failed to write BPB fields. ISD_WriteBlock()\n");
OSReport((str_base + 0x748));
return -36;
}
result = ISD_WriteBlock(g_pfd_sddrv_info.device, format_data.partition_start_sector + 7, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("ERR Failed to write BPB fields. ISD_WriteBlock()\n");
OSReport((str_base + 0x748));
return -36;
}
result = pfd_sddrv_store_fat32_reserved_buf(g_pfd_sddrv_buf);
if (result != 0) {
OSReport("ERR Failed to store reserved for boot sector values to buf. ");
OSReport("pfd_sddrv_store_fat32_reserved_buf()\n");
OSReport((str_base + 0x8e4));
OSReport((str_base + 0x924));
return result;
}
if (g_pfd_sddrv_info.media_inserted == 0) {
@@ -1441,17 +1646,17 @@ s32 pfd_sddrv_build_fat32_mbr_bpb(u32 total_sectors) {
}
result = ISD_WriteBlock(g_pfd_sddrv_info.device, format_data.partition_start_sector + 2, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("ERR Failed to write BPB fields. ISD_WriteBlock()\n");
OSReport((str_base + 0x748));
return -36;
}
result = ISD_WriteBlock(g_pfd_sddrv_info.device, format_data.partition_start_sector + 8, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("ERR Failed to write BPB fields. ISD_WriteBlock()\n");
OSReport((str_base + 0x748));
return -36;
}
result = pfd_sddrv_store_fat32_mbr_buf(&format_data, g_pfd_sddrv_buf);
if (result != 0) {
OSReport("ERR Failed to store MBR values to buf. pfd_sddrv_store_mbr_buf()\n");
OSReport((str_base + 0x77c));
return result;
}
if (g_pfd_sddrv_info.media_inserted == 0) {
@@ -1462,13 +1667,15 @@ s32 pfd_sddrv_build_fat32_mbr_bpb(u32 total_sectors) {
}
result = ISD_WriteBlock(g_pfd_sddrv_info.device, 0, g_pfd_sddrv_buf, 1);
if (result != 0) {
OSReport("ERR Failed to write MBR fields. ISD_WriteBlock()\n");
OSReport((str_base + 0x7c0));
return -36;
}
return 0;
}
s32 pfd_sddrv_full_format(void) {
const char* str_base = sd_drv_error_strings;
FADiskInfo geometry;
u32 status;
u32 retry_count;
@@ -1484,7 +1691,7 @@ s32 pfd_sddrv_full_format(void) {
g_pfd_sddrv_info.media_ejected = 0;
break;
}
OSReport("ERROR Failed to SD Card Reset [ret = 0x%x]. pfd_sddrv_full_format()\n", result);
OSReport((str_base + 0x94c), result);
retry_count++;
} while (retry_count < 5);
if (retry_count == 5) {
@@ -1495,7 +1702,7 @@ s32 pfd_sddrv_full_format(void) {
}
result = ISD_GetDeviceStatus(g_pfd_sddrv_info.device, &status);
if (result != 0) {
OSReport("ERR Failed to get sd card status. [ret = 0x%x]\n", result);
OSReport((str_base + 0x130), result);
return -39;
}
if ((status & 4) != 0) {
@@ -1506,7 +1713,7 @@ s32 pfd_sddrv_full_format(void) {
}
result = pfd_sddrv_get_total_sectors(&geometry.totalSectors, &geometry.bytesPerSector);
if (result != 0) {
OSReport("ERR Failed to get total sectors. pfd_sddrv_get_total_sectors()\n");
OSReport((str_base + 0x998));
return result;
}
if ((status & 0x10000) != 0 && (status & 0x100000) == 0) {
@@ -1523,7 +1730,7 @@ s32 pfd_sddrv_full_format(void) {
return -31;
}
if (result != 0) {
OSReport("ERR Failed to build up and write MBR and BPB fields.\n");
OSReport((str_base + 0x9d8));
return result;
}
return 0;

View File

@@ -1,25 +1,25 @@
#include <private/fa/pdm.h>
#include <revolution/types.h>
#define MBR_WORD(buf, offset) (((pf_u32)(buf)[(offset) + 3] << 24) + ((pf_u32)(buf)[(offset) + 2] << 16) + ((pf_u32)(buf)[(offset) + 1] << 8) + (buf)[offset])
#define MBR_WORD(buf, offset) ((pf_u32)(buf)[offset] + ((pf_u32)(buf)[(offset) + 1] << 8) + ((pf_u32)(buf)[(offset) + 2] << 16) + ((pf_u32)(buf)[(offset) + 3] << 24))
static inline pf_u16 read_boot_u16(pf_u8* buf, pf_u32 offset) {
if ((pf_u32)&buf[offset] & 1) { return (buf[offset + 1] << 8) | buf[offset]; }
return PF_SWAP_16(*(pf_u16*)&buf[(offset + 1) & ~1]);
}
pf_s32 pdm_part_is_master_boot_sector(pf_u8* buf, pf_u32 total, pf_bool* p_is_mbr) {
pf_s16 index;
pf_u32 start[4];
pf_u32 count[4];
pf_u32* p_start;
pf_u32* p_count;
pf_s16 index;
*p_is_mbr = 0;
if (buf[510] != 0x55 || buf[511] != 0xAA) { return 2; }
p_start = start;
p_count = count;
for (index = 0; index < 4; index++) {
*p_start = 0;
*p_start = (((pf_u32)buf[456] << 16) + buf[454]) + (((pf_u32)buf[457] << 24) + ((pf_u32)buf[455] << 8));
*p_count = (((pf_u32)buf[460] << 16) + buf[458]) + (((pf_u32)buf[461] << 24) + ((pf_u32)buf[459] << 8));
*p_start = (((pf_u32)buf[457] << 24) + (((pf_u32)buf[455] << 8) + (((pf_u32)buf[456] << 16) + buf[454])));
*p_count = (((pf_u32)buf[461] << 24) + (((pf_u32)buf[459] << 8) + (((pf_u32)buf[460] << 16) + buf[458])));
if (*p_start != 0 && *p_count != 0) {
if (index == 0) { *p_is_mbr = 1; }
} else {

View File

@@ -609,7 +609,7 @@ pf_s32 PFCACHE_DoWriteNumSectorAndFreeIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE**
(p_page->sector + p_page->size) >= (sector + num_sector)) {
pf_memcpy(p_page->buffer, (pf_u8*)&p_buf[(p_page->sector - sector) << p_vol->bpb.log2_bytes_per_sector],
(sector + num_sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector);
num_overlap = p_page->size - ((p_page->sector + p_page->size) - (num_sector + sector));
num_overlap = sector + num_sector - p_page->sector;
last_sector = p_page->sector + num_overlap - 1;
*p_num_success += num_overlap;
num_rest_sector -= num_overlap;

View File

@@ -370,8 +370,9 @@ pf_s32 PFCLUSTER_CombineFiles(PFCLUSTER_ENT_ITER* p_first_iter, PFCLUSTER_ENT_IT
if (*p_second_iter->ffd.p_start_cluster != 0) {
second_spare_clusters = p_second_iter->ffd.last_cluster.max_chain_index + 1 - second_used_clusters;
}
if (-1U / cluster_size + 1 < (second_used_clusters + second_spare_clusters) + first_used_clusters) {
excess_clusters = (second_used_clusters + second_spare_clusters) + first_used_clusters - (-1U / cluster_size + 1);
excess_clusters = (second_used_clusters + second_spare_clusters) + first_used_clusters;
if (-1U / cluster_size + 1 < excess_clusters) {
excess_clusters -= -1U / cluster_size + 1;
err = PFFAT_TraceClustersChain(&p_second_iter->ffd, second_spare_cluster,
cluster_size * ((p_second_iter->ffd.last_cluster.max_chain_index + 1 - excess_clusters) - second_used_clusters),
&end_cluster, &spare_cluster);
@@ -546,9 +547,9 @@ pf_s32 PFCLUSTER_InsertCluster(PFCLUSTER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent,
pf_u32 last_cluster;
pf_u32 requested_size;
pf_u32 file_clusters;
PF_VOLUME* p_vol;
pf_u32 remainder;
pf_u32 extra_size;
PF_VOLUME* p_vol;
p_vol = p_ent->p_vol;
cluster_size = p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster;
@@ -599,14 +600,14 @@ pf_s32 PFCLUSTER_InsertCluster(PFCLUSTER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent,
pf_s32 PFCLUSTER_DeleteCluster(PFCLUSTER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent,
pf_u32 cluster_index, pf_u32 num_clusters, pf_u32* p_deleted_clusters) {
PF_VOLUME* p_vol;
pf_u32 cluster_size;
pf_u32 byte_position;
pf_s32 err;
pf_u32 previous_cluster;
pf_u32 next_cluster;
pf_u32 first_deleted_cluster;
pf_u32 last_deleted_cluster;
PF_VOLUME* p_vol;
pf_u32 cluster_size;
pf_u32 byte_position;
p_vol = p_ent->p_vol;
cluster_size = p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster;

View File

@@ -144,7 +144,7 @@ static inline pf_u32 current_directory_is_open(PF_VOLUME* volume, pf_u32 cluster
pf_u32 index;
for (index = 0; index < 4; index++) {
if (pf_vol_set.volume_state.volumes[index].p_vol == volume) {
PFDIR_VOLUME_DIRS* state = (PFDIR_VOLUME_DIRS*)volume;
PFDIR_VOLUME_DIRS* state = (PFDIR_VOLUME_DIRS*)pf_vol_set.volume_state.volumes[index].p_vol;
PF_CUR_DIR* directory = state->current_dirs;
pf_u32 slot;
for (slot = 0; slot < 4; slot++, directory++) {
@@ -381,7 +381,7 @@ pf_s32 PFDIR_p_readdir(PFDIR_DIR* dir, PFDIR_READ_RESULT* result) {
return 0;
}
extern pf_s32 PFENT_findEntry(PFDIR_FFD*, PF_DIR_ENT*, pf_u32, PFDIR_STR*, pf_u8, pf_u32*, pf_u32*);
extern pf_s32 PFENT_findEntry(PFDIR_FFD*, PF_DIR_ENT*, pf_u32, PFDIR_STR*, pf_u32, pf_u32);
extern pf_s32 PFFAT_GetSectorSpecified(PFDIR_FFD*, pf_u32, pf_u32, pf_u32*);
extern pf_s32 PFPATH_transformInUnicode(pf_u16*, const pf_s8*);
extern void PFPATH_SetSearchPattern(pf_s8*, pf_u16*, PFDIR_STR*);
@@ -453,7 +453,7 @@ extern pf_s32 PFENT_ITER_GetEntryOfPattern(PF_ENT_ITER* iter, PF_DIR_ENT* entry,
extern pf_s32 PFENT_ITER_FindEntry(PF_ENT_ITER* iter, PF_DIR_ENT* entry, PFDIR_STR* pattern,
pf_u8 attributes, pf_u32 start, pf_u32* found);
extern pf_s32 PFENT_findEntry(PFDIR_FFD* ffd, PF_DIR_ENT* entry, pf_u32 start, PFDIR_STR* pattern,
pf_u8 attributes, pf_u32* logical_position, pf_u32* entry_position);
pf_u32 attributes, pf_u32 attr_forbidden);
extern pf_u32 PFSTR_GetCodeMode(PFDIR_STR* path);
extern const pf_s8* PFSTR_GetStrPos(PFDIR_STR* path, pf_u32 target);
extern pf_s32 PFPATH_SplitPathPattern(PF_STR* path, PFDIR_STR* directory, PFDIR_STR* pattern);
@@ -876,7 +876,7 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
pf_s32 filename_length;
pf_s32 parse_error;
pf_s32 allocation_error = 0;
pf_s32 error;
pf_s32 error = 0;
pf_u32 index;
PF_DIR_ENT* update_entry;
@@ -925,7 +925,7 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
}
destination_entry.start_cluster = source_parent.start_cluster;
PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster);
error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0, 0);
error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0);
if (error == 0) { return 8; }
if (error != 0 && error != 3) { return error; }
if ((source_entry.attr & 0x10) == 0) {
@@ -961,7 +961,8 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
destination_entry.num_entry_LFNs = 0;
PFENT_getcurrentDateTimeForEnt(&destination_entry.access_date, &time);
error = PFENT_updateEntry(&destination_entry, 1);
goto finish_rename;
if (error != 0) { allocation_error = error; return error; }
return allocation_error;
}
if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) {
saved_initial_char = source_entry.long_name[0];
@@ -1033,8 +1034,7 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
update_entry->entry_sector = sector;
}
error = PFENT_updateEntry(update_entry, 1);
finish_rename:
if (error != 0) { allocation_error = error; }
if (error != 0) { return error; }
return allocation_error;
}
pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
@@ -1083,7 +1083,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
if (error != 0) { return error; }
destination_entry.start_cluster = destination_parent.start_cluster;
PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster);
error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0, 0);
error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0);
if (error == 0) {
if (destination_entry.entry_sector == source_entry.entry_sector &&
destination_entry.entry_offset == source_entry.entry_offset) { return 0; }
@@ -1120,7 +1120,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster);
PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1);
PFSTR_SetLocalStr(&parent_name, 0);
error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &parent_name, 0x7F, 0, 0);
error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &parent_name, 0x7F, 0);
if (error != 0) { return error; }
parent_cluster = destination_entry.start_cluster;
if (parent_cluster == 1 || parent_cluster == 0) { break; }
@@ -1180,7 +1180,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
if (allocation_error != 0) {
if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) {
source_entry.long_name[0] = saved_initial_char;
source_entry.entry_offset -= (source_entry.num_entry_LFNs & 0xff) * 32;
source_entry.entry_offset -= (pf_u16)(source_entry.num_entry_LFNs * 32);
}
update_entry = &source_entry;
} else {
@@ -1192,7 +1192,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
PFFAT_InitFFD(&source_iter.ffd, &source_hint, volume, &source_entry.start_cluster);
PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1);
PFSTR_SetLocalStr(&parent_name, 0);
error = PFENT_findEntry(&source_iter.ffd, &source_entry, 0, &parent_name, 0x7F, 0, 0);
error = PFENT_findEntry(&source_iter.ffd, &source_entry, 0, &parent_name, 0x7F, 0);
if (error != 0) { return error; }
if (destination_parent.start_cluster == 1 || destination_parent.start_cluster == 0 ||
(destination_parent.start_cluster == 2 && volume->bpb.fat_type == FAT_32)) {
@@ -1226,7 +1226,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
update_entry->entry_sector = sector;
}
error = PFENT_updateEntry(update_entry, 1);
if (error != 0) { allocation_error = error; }
if (error != 0) { return error; }
return allocation_error;
}

View File

@@ -29,6 +29,12 @@ typedef struct PFITER_ENT_ITER {
pf_u8 log2_entries_per_sector;
} PFITER_ENT_ITER;
__declspec(section ".sdata") pf_s8 g_pfent_iter_parent_dir[] = "..";
__declspec(section ".sdata") pf_s8 g_pfent_iter_current_dir[] = ".";
__declspec(section ".sdata") pf_s8 g_pfent_iter_colon[] = ":";
__declspec(section ".sdata") pf_s8 g_pfent_iter_backslash[] = "\\";
__declspec(section ".sdata") pf_s8 g_pfent_iter_slash[] = "/";
typedef struct PFITER_BPB {
pf_u16 bytes_per_sector;
pf_u16 num_reserved_sectors;
@@ -234,8 +240,8 @@ pf_s32 PFENT_ITER_DoFindEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_STR
pf_u32 index_search_from;
pf_u32 is_extsfn = 0;
*p_is_found = 0;
if (PFSTR_StrCmp(p_pattern, (pf_s8*)"..") == 0 && (p_ent->attr & 0x10) && p_ent->start_cluster == 1) return 2;
if (PFSTR_StrCmp(p_pattern, (pf_s8*)".") == 0) {
if (PFSTR_StrCmp(p_pattern, g_pfent_iter_parent_dir) == 0 && (p_ent->attr & 0x10) && p_ent->start_cluster == 1) return 2;
if (PFSTR_StrCmp(p_pattern, g_pfent_iter_current_dir) == 0) {
*p_is_found = 1;
return 0;
}
@@ -339,10 +345,10 @@ pf_s32 PFENT_ITER_DoGetEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_VOLU
pf_s32 err;
pf_u32 code_mode;
if (PFSTR_StrNCmp(p_path, (pf_s8*)":", 1, 1, 1) == 0) {
if (PFSTR_StrNCmp(p_path, g_pfent_iter_colon, 1, 1, 1) == 0) {
PFSTR_MoveStrPos(p_path, 2);
}
if ((PFSTR_StrNCmp(p_path, (pf_s8*)"\\", 1, 0, 1) == 0 || PFSTR_StrNCmp(p_path, (pf_s8*)"/", 1, 0, 1) == 0)) {
if ((PFSTR_StrNCmp(p_path, g_pfent_iter_backslash, 1, 0, 1) == 0 || PFSTR_StrNCmp(p_path, g_pfent_iter_slash, 1, 0, 1) == 0)) {
err = PFENT_GetRootDir(p_vol, p_ent);
if (err != 0) {
return err;
@@ -528,7 +534,7 @@ pf_s32 PFENT_ITER_FindCluster(PF_DIR_ENT* p_ent, pf_u32 cluster, pf_bool* p_is_f
while (iter.index != 0) {
err = PFENT_ITER_LoadEntry(&iter);
if (err != 0) return err;
if (pf_strncmp((pf_s8*)iter.buf, (pf_s8*)"..", 2) == 0) break;
if (pf_strncmp((pf_s8*)iter.buf, g_pfent_iter_parent_dir, 2) == 0) break;
err = PFENT_ITER_Retreat(&iter, 0);
if (err != 0) return err;
if (current_cluster == cluster) {
@@ -552,7 +558,7 @@ pf_s32 PFENT_ITER_FindCluster(PF_DIR_ENT* p_ent, pf_u32 cluster, pf_bool* p_is_f
while (current_cluster > 2) {
err = PFENT_ITER_LoadEntry(&iter);
if (err != 0) return err;
if (pf_strncmp((pf_s8*)iter.buf, (pf_s8*)"..", 2) == 0) {
if (pf_strncmp((pf_s8*)iter.buf, g_pfent_iter_parent_dir, 2) == 0) {
if (current_cluster == cluster) {
*p_is_found = 1;
return 0;
@@ -685,8 +691,8 @@ pf_s32 PFENT_ITER_FindEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_STR*
pf_s32 err;
*p_is_found = 0;
if (attr_required & attr_forbidden) return 10;
if (PFSTR_StrNCmp(p_pattern, (pf_s8*)":", 1, 1, 1) == 0) PFSTR_MoveStrPos(p_pattern, 2);
if (PFSTR_StrNCmp(p_pattern, (pf_s8*)"\\", 1, 0, 1) == 0 || PFSTR_StrNCmp(p_pattern, (pf_s8*)"/", 1, 0, 1) == 0) {
if (PFSTR_StrNCmp(p_pattern, g_pfent_iter_colon, 1, 1, 1) == 0) PFSTR_MoveStrPos(p_pattern, 2);
if (PFSTR_StrNCmp(p_pattern, g_pfent_iter_backslash, 1, 0, 1) == 0 || PFSTR_StrNCmp(p_pattern, g_pfent_iter_slash, 1, 0, 1) == 0) {
err = PFENT_GetRootDir(p_iter->p_vol, p_ent);
if (err != 0) return err;
if (PFSTR_StrNumChar(p_pattern, 1) == 1 && PFSTR_StrNCmp(p_pattern, (pf_s8*)"\0\0\0", 2, 0, 1) == 0) return 0;
@@ -727,24 +733,23 @@ pf_s32 PFENT_ITER_GetEntryOfIter(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
}
pf_s32 PFENT_ITER_GetLFNEntryName(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
pf_u16* destination;
pf_u32 i;
pf_u32 index;
pf_s32 err;
if (p_ent->num_entry_LFNs != 0 && !(p_ent->small_letter_flag & 0x18)) {
index = 0;
for (i = 0; i < p_ent->num_entry_LFNs; ++i) {
pf_u16* destination;
err = PFENT_ITER_Retreat(p_iter, 0);
if (err != 0) return err;
err = PFENT_ITER_LoadEntry(p_iter);
if (err != 0) return err;
index = i * 13;
destination = &p_ent->long_name[index];
pf_memcpy(destination, &p_iter->buf[1], 10);
pf_memcpy(destination + 5, &p_iter->buf[14], 12);
pf_memcpy(destination + 11, &p_iter->buf[28], 4);
index += 13;
}
p_ent->long_name[index] = 0;
p_ent->long_name[p_ent->num_entry_LFNs * 26 >> 1] = 0;
}
return 0;
}

View File

@@ -1548,24 +1548,26 @@ s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
0, 1, page);
chainIndex++;
} else {
s32 writeError;
currentPage = page;
switch (volume->bpb.fat_type) {
case FAT_12:
error = PFFAT12_WriteFATEntryWithBuf(
writeError = PFFAT12_WriteFATEntryWithBuf(
volume, (u16)startCluster, 0, currentPage);
break;
case FAT_16:
error = PFFAT16_WriteFATEntryWithBuf(volume, startCluster, 0,
writeError = PFFAT16_WriteFATEntryWithBuf(volume, startCluster, 0,
currentPage);
break;
case FAT_32:
error = PFFAT32_WriteFATEntryWithBuf(volume, startCluster, 0,
writeError = PFFAT32_WriteFATEntryWithBuf(volume, startCluster, 0,
currentPage);
break;
default:
error = 15;
writeError = 15;
break;
}
error = writeError;
}
if (error != 0) {
PFCACHE_FreeDataPage(volume, page);

View File

@@ -121,12 +121,12 @@ pf_s32 VFiPFFAT12_WriteFATEntry(PF_VOLUME* p_vol, pf_u16 cluster, pf_u16 value)
pf_s32 PFFAT12_WriteFATEntryWithBuf(PF_VOLUME* p_vol, pf_s16 cluster, pf_u16 value, PF_CACHE_PAGE* p_page) {
pf_s32 err;
pf_u32 next_sector;
pf_u32 offset_in_sector;
pf_u16 current_fat;
pf_s32 fat_offset;
pf_u32 fat_sector;
pf_s32 result;
pf_u32 next_sector;
fat_offset = (pf_u16)(cluster + (cluster >> 1));
fat_sector = (pf_u16)(p_vol->bpb.active_FAT_sector + (fat_offset >> p_vol->bpb.log2_bytes_per_sector));
offset_in_sector = fat_offset & (p_vol->bpb.bytes_per_sector - 1);
@@ -153,7 +153,7 @@ pf_s32 PFFAT12_WriteFATEntryWithBuf(PF_VOLUME* p_vol, pf_s16 cluster, pf_u16 val
p_page->sector = next_sector;
p_page->p_buf[0] = value >> 4;
} else {
((pf_u16)offset_in_sector + p_page->p_buf)[1] = value >> 4;
p_page->p_buf[(pf_u16)offset_in_sector + 1] = value >> 4;
}
} else {
p_page->p_buf[(pf_u16)offset_in_sector] = value;
@@ -165,7 +165,7 @@ pf_s32 PFFAT12_WriteFATEntryWithBuf(PF_VOLUME* p_vol, pf_s16 cluster, pf_u16 val
p_page->sector = next_sector;
p_page->p_buf[0] = (p_page->p_buf[0] & 0xF0) | ((pf_u8)(value >> 8));
} else {
((pf_u16)offset_in_sector + p_page->p_buf)[1] = (((pf_u16)offset_in_sector + p_page->p_buf)[1] & 0xF0) | ((pf_u8)(value >> 8));
p_page->p_buf[(pf_u16)offset_in_sector + 1] = (p_page->p_buf[(pf_u16)offset_in_sector + 1] & 0xF0) | ((pf_u8)(value >> 8));
}
}
if (err != 0) { result = err; }
@@ -175,11 +175,11 @@ pf_s32 PFFAT12_WriteFATEntryWithBuf(PF_VOLUME* p_vol, pf_s16 cluster, pf_u16 val
pf_s32 PFFAT12_ReadFATEntryWithBuf(PF_VOLUME* p_vol , pf_u16 cluster , pf_u32* p_value ,
PF_CACHE_PAGE* p_page ) {
pf_s32 result;
pf_u32 sector;
pf_s32 err;
pf_u32 current_fat;
pf_u32 sector;
pf_u32 offset;
pf_s32 result;
#define LOAD_FAT_SECTOR(next_sector) \
if (p_page->sector != sector + (next_sector)) { \

View File

@@ -649,22 +649,21 @@ void PFFILE_Cursor_MoveToClusterEnd(PFFILE_FILE* file, pf_u32 size) {
PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume;
PFFILE_SFD* first_free_sfd = PF_NULL;
PFFILE_SFD* sfd = volume_dirs->sfds;
pf_u32 first_free_index = 0;
pf_u32 index = 0;
PFFILE_SFD* first_free_sfd = PF_NULL;
pf_s32 index;
for (; index < 5; index++, sfd++) {
for (index = 0; index < 5; index++) {
if ((volume_dirs->sfds[index].stat & 1) == 0 ||
((volume_dirs->sfds[index].stat & 1) != 0 && (!volume_dirs->sfds[index].stat & 2) != 0)) {
if (first_free_sfd == PF_NULL) {
first_free_sfd = sfd;
first_free_sfd = volume_dirs->sfds + index;
first_free_index = index;
}
} else if (entry->p_vol == volume_dirs->sfds[index].dir_entry.p_vol &&
entry->entry_sector == volume_dirs->sfds[index].dir_entry.entry_sector &&
entry->entry_offset == volume_dirs->sfds[index].dir_entry.entry_offset) {
return &volume_dirs->sfds[index];
return volume_dirs->sfds + index;
}
}
@@ -681,14 +680,14 @@ PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
first_free_sfd->lock.resource = 0;
PFFAT_InitFFD(&first_free_sfd->ffd, PF_NULL, entry->p_vol,
&first_free_sfd->dir_entry.start_cluster);
if ((volume_dirs->cluster_link.flag & 1) != 0) {
pf_u32* link_buffer = volume_dirs->cluster_link.buffer +
first_free_index * volume_dirs->cluster_link.link_max;
if ((((PFFILE_VOLUME_DIRS*)volume)->cluster_link.flag & 1) != 0) {
pf_u32* link_buffer = ((PFFILE_VOLUME_DIRS*)volume)->cluster_link.buffer +
first_free_index * ((PFFILE_VOLUME_DIRS*)volume)->cluster_link.link_max;
first_free_sfd->ffd.cluster_link.buffer = link_buffer;
pf_memset(link_buffer, 0, volume_dirs->cluster_link.link_max << 2);
first_free_sfd->ffd.cluster_link.max_count = volume_dirs->cluster_link.link_max;
first_free_sfd->ffd.cluster_link.interval = volume_dirs->cluster_link.interval;
pf_memset(link_buffer, 0, ((PFFILE_VOLUME_DIRS*)volume)->cluster_link.link_max << 2);
first_free_sfd->ffd.cluster_link.max_count = ((PFFILE_VOLUME_DIRS*)volume)->cluster_link.link_max;
first_free_sfd->ffd.cluster_link.interval = ((PFFILE_VOLUME_DIRS*)volume)->cluster_link.interval;
first_free_sfd->ffd.cluster_link.interval_offset = 0;
first_free_sfd->ffd.cluster_link.position = 0;
first_free_sfd->ffd.cluster_link.save_index = 0;
@@ -1368,7 +1367,7 @@ complete:
static PFFILE_FILE* PFFILE_GetFreeUFD(PF_VOLUME* volume) {
PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume;
pf_u32 index;
pf_s32 index;
for (index = 0; index < 5; index++) {
if ((volume_dirs->ufds[index].stat & 1) == 0) {
@@ -1439,7 +1438,7 @@ pf_s32 PFFILE_FsexecOpenFile(PF_DIR_ENT* entry, PFFILE_ENT_ITER* iter,
pf_bool PFFILE_IsOpened(PF_DIR_ENT* entry) {
PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)entry->p_vol;
pf_u32 index;
pf_s32 index;
for (index = 0; index < 5; index++) {
PFFILE_SFD* sfd = &volume_dirs->sfds[index];

View File

@@ -21,7 +21,7 @@ typedef struct PF_FILE_NAME_ITER {
#undef PF_IS_PATH_SEPERATOR
#undef PF_IS_PATH_NULL
#undef PF_IS_PATH_NOT_NULL
#define PF_IS_PATH_SEPERATOR(s, t, i) (PFSTR_StrNCmp(s, (const pf_s8*)"\\", t, i, 1) == 0 || PFSTR_StrNCmp(s, (const pf_s8*)"/", t, i, 1) == 0)
#define PF_IS_PATH_SEPERATOR(s, t, i) (PFSTR_StrNCmp(s, (pf_s8*)"\\", t, i, 1) == 0 || PFSTR_StrNCmp(s, (pf_s8*)"/", t, i, 1) == 0)
#define PF_IS_PATH_NULL(s, t, i) (PFSTR_StrNCmp(s, (const pf_s8*)"\0", t, i, 1) == 0)
#define PF_IS_PATH_NOT_NULL(s, t, i) (PFSTR_StrNCmp(s, (const pf_s8*)"\0", t, i, 1) != 0)
@@ -400,10 +400,10 @@ pf_s32 PFPATH_cmpNameImpl(const pf_s8* name, const pf_s8* pattern, pf_u32* match
case '*': {
do {
pattern_width = volume->codeset.oem_char_width(pattern);
if (pattern_width != 1) {
read_char = (pf_u16)PF_GET_LE_U16((const pf_u8*)pattern);
} else {
if (pattern_width == 1) {
read_char = pf_toupper(*pattern);
} else {
read_char = (pf_u16)PF_GET_LE_U16((const pf_u8*)pattern);
}
pattern_char = (pf_u16)read_char;
pattern += pattern_width;
@@ -465,11 +465,11 @@ pf_s32 PFPATH_cmpName(const pf_s8* short_name, PF_STR* pattern, pf_u32 short_sea
work.matched_end = 0;
pattern_text = PFSTR_GetStrPos(pattern, 3);
pf_strcpy(name, short_name);
if ((pf_vol_set.setting & 2) == 2 && PFSTR_GetCodeMode(pattern) == 2 && pf_strcmp(name, (const pf_s8*)".") != 0 &&
pf_strcmp(name, (const pf_s8*)"..") != 0 && PFPATH_CheckExtShortName(pattern, 3, PF_TRUE) == 0 && short_search == 0) {
if ((pf_vol_set.setting & 2) == 2 && PFSTR_GetCodeMode(pattern) == 2 && pf_strcmp(name, (pf_s8*)".") != 0 &&
pf_strcmp(name, (pf_s8*)"..") != 0 && PFPATH_CheckExtShortName(pattern, 3, PF_TRUE) == 0 && short_search == 0) {
return 1;
}
if (pf_strcmp(pattern_text, (const pf_s8*)"*.") == 0) {
if (pf_strcmp(pattern_text, (pf_s8*)"*.") == 0) {
name_end = name;
while (*name_end != 0 && *name_end != '.') {
name_end++;
@@ -1014,6 +1014,11 @@ void PFPATH_SetSearchPattern(pf_s8* p_buf_local, pf_u16* p_buf_unicode, PF_STR*
PFPATH_transformFromUnicodeToNormal(p_buf_local, p_buf_unicode);
}
__declspec(section ".sdata2") pf_s8 path_sig_byte0 = 1;
__declspec(section ".sdata2") pf_s8 path_sig_byte1 = 2;
__declspec(section ".sdata2") pf_s8 path_sig_byte2 __attribute__((aligned(4))) = 1;
__declspec(section ".sdata2") pf_s8 path_sig_byte3 = 2;
pf_u32 PFPATH_CheckExtShortNameSignature(PF_STR* p_str) {
pf_u32 result = 0;
pf_s8 sig[2] = "\x01\x02";
@@ -1029,10 +1034,13 @@ pf_u32 PFPATH_CheckExtShortName(PF_STR* p_str, pf_u32 target, pf_bool wildcard)
pf_s16 i;
pf_s16 num;
pf_bool is_wildcard = PF_FALSE;
pf_s8 sig[2] = "\x01\x02";
pf_s8 sig[2];
pf_s8* p_c;
pf_u16* p_wc;
sig[0] = path_sig_byte0;
sig[1] = path_sig_byte1;
if (PFSTR_StrNCmp(p_str, sig, target, 0, 2) == 0 ||
(PFSTR_StrNCmp(p_str, (pf_s8*)"?", target, 0, 1) == 0 &&
(PFSTR_StrNCmp(p_str, (pf_s8*)"?", target, 1, 1) == 0 || PFSTR_StrNCmp(p_str, (pf_s8*)"*", target, 0, 1) == 0)) ||
@@ -1075,10 +1083,13 @@ pf_u32 PFPATH_GetExtShortNameIndex(PF_STR* p_str, pf_u32* p_index) {
pf_s16 i;
pf_s16 num;
pf_u32 index;
pf_s8 sig[2] = "\x01\x02";
pf_s8 sig[2];
pf_s8* p_c;
pf_u16* p_wc;
sig[0] = path_sig_byte2;
sig[1] = path_sig_byte3;
if (PFSTR_StrNCmp(p_str, sig, 1, 0, 2) == 0) {
index = 0;

View File

@@ -225,7 +225,8 @@ typedef struct PFVOL_SET {
PFVOL_SET pf_vol_set;
static s8 default_volume_label[12] = "NO NAME ";
static const u8 deleted_entry_mark[8] = {0xE5};
__declspec(section ".sdata2") u8 deleted_entry_mark[8] = {0xE5};
char vol_wildcard_path[] = {0x2A, 0};
extern s32 PFDRV_mount(PFVOL_VOLUME* volume);
extern s32 PFDRV_unmount(PFVOL_VOLUME* volume, u32 mode);
@@ -502,7 +503,7 @@ s32 PFVOL_p_setvol(PFVOL_VOLUME* volume, const s8* label) {
return error;
} else {
PFFAT_InitFFD(&ffd, &hint, volume, &root_entry.start_cluster);
PFSTR_InitStr(&path, "*", 1);
PFSTR_InitStr(&path, vol_wildcard_path, 1);
PFSTR_SetLocalStr(&path, 0);
error = PFENT_findEntryPos(&ffd, &entry, 0, &path, 8, 0, &logical_position, &entry_position);
if (error != 0 && error != 3) {
@@ -555,8 +556,8 @@ s32 PFVOL_p_getvol(PFVOL_VOLUME* volume, PFVOL_VOLUME_INFO* volume_info) {
return error;
}
PFFAT_InitFFD(&ffd, &hint, volume, &root_entry.start_cluster);
PFSTR_InitStr(&path, "*", 1);
PFSTR_SetLocalStr(&path, "*");
PFSTR_InitStr(&path, vol_wildcard_path, 1);
PFSTR_SetLocalStr(&path, vol_wildcard_path);
error = PFENT_findEntryPos(&ffd, &entry, 0, &path, 8, 0, &logical_position, &entry_position);
if (error != 0 && error != 3) {
return error;
@@ -592,8 +593,8 @@ s32 PFVOL_p_rmvvol(PFVOL_VOLUME* volume) {
return error;
}
PFFAT_InitFFD(&ffd, &hint, volume, &root_entry.start_cluster);
PFSTR_InitStr(&path, "*", 1);
PFSTR_SetLocalStr(&path, "*");
PFSTR_InitStr(&path, vol_wildcard_path, 1);
PFSTR_SetLocalStr(&path, vol_wildcard_path);
error = PFENT_findEntryPos(&ffd, &entry, 0, &path, 8, 0, &logical_position, &entry_position);
if (error != 0 && error != 3) {
return error;

View File

@@ -0,0 +1,268 @@
# fapark3 — remaining fa/ NonMatching tie-breaks
Leaf: `agent/w0929/fapark3` off origin/main@bcb37e07. 12 owned units, all
NonMatching: pf_cache, pf_cluster, pf_dir, pf_entry_iterator, pf_fat, pf_fat12,
pf_file, pf_path, pf_volume, pdm_partition, driver/sd_drv, api/FAAttach.
Data sections are already 100% on all of them — every residual below is code.
Adopted prior-wave `agent/w0929/fapark` sources (only files differing from
main): pf_cluster.c, pf_dir.c, pf_fat.c, pf_path.c, driver/sd_drv.c.
## Wins this wave
- `pfd_sddrv_get_disk_info` (sd_drv): `return result` → `return 0` made the fn
instruction-identical (96/96) — orig emits `li r3,0` on the success path even
when r3 is already 0. Residual fuzzy 97.9 is a pure extraction artifact:
orig's symbol extent (0x848/0x180) ends mid-epilogue — `mtlr` is the last
covered insn, `addi r1;blr` uncovered. Byte-identical code, fuzzy <100
forever (same class as PFSYS_TimeStamp / pdm_disk backtick name).
- `deleted_entry_mark` (pf_volume): orig's .sdata2 object is GLOBAL OBJECT
(8B, `e5`+pad). Non-static `const u8 deleted_entry_mark[8] = {0xE5}`
reproduces binding+bytes exactly.
## Verified walls (levers tried, documented)
- **Global-const fold** (`PFVOL_p_rmvvol`, 95.9): orig emits `lbz r0,
deleted_entry_mark` for a same-TU GLOBAL const. MWCC -ipa file folds every
form to `li r0,0xe5`: static const array, extern-linkage const scalar,
extern-linkage const array, extern-decl+def split. Only the head ordering
differs (4 diffs at 64/64 insns).
- **Select-fold, both directions** (`PFFAT_GetSectorSpecified` −1,
`pfd_sddrv_init` −2): orig emits a branchy `beq;b;li r3,0` for the
0/error two-return. Every source form either select-folds
(andc/neg-or-srawi, 17 insns, fuzzy 85.9) or merges to a single
`bne`+`li`+shared tail (16 insns, better fuzzy — kept). Tried: explicit
if/else returns, goto-out, `goto zero`, self-assign arm, init'd decl.
The orig shape needs an isolated zero-return block MWCC won't emit here.
- **Batch-vs-seq struct copy** (`PFVOL_setcode`, 53.9): orig interleaves
`lwz r0,off/stw r0,off` per field of the codeset struct copy; MWCC batches
all loads then all stores for `pf_vol_set.codeset = *code_set`. Tried
per-field assigns, u32* casts, loop, memcpy (emits call), array-type
assign (illegal C). No source lever.
- **Reg-model cascade** (`PFVOL_attach` −2): orig carries the mount error in
r0 across ClearMountRequested (`mr r0,r3` + shared `li r0,0` + per-branch
`li r3,0` returns); MWCC keeps it in r3 and merges. Same wall as init.
- **Induction-var home** (`PFENT_ITER_GetLFNEntryName`, 90.5): orig keeps a
byte-offset cursor (r28+=0x1a, `mulli r0,count,0x1a` + `rlwinm &~1`
terminator) vs mine u16-index. Byte-offset rewrite regressed (76 insns);
`long_name[num*13]` terminator emits `mulli 0xd;slwi` (extra insn);
`(u8*)+num*26` emits `mulli 0x1a` but no `&~1` and changes the epilogue
(inline lwz's vs orig's `_restgpr` tail). Kept u16-index form (73/73).
- **Callee-save +2 / scheduling** (`pdm_part_is_master_boot_sector` +2,
`pdm_part_get_start_sector` 46 sched diffs at 276/276,
`PFDIR_p_rename` +1): orig homes loop state in different callee regs
(uniform +1 window); instruction streams otherwise identical modulo
ordering. Regalloc-internal, no lever found (documented prior wave).
- **Symbol-overlap artifact** (`PFPATH_MatchFileNameWithPattern`, 98.5):
orig symbol range over-extends 12B into the next fn (putShortName) — the
covered code is byte-identical; fuzzy can't reach 100.
- **sd_drv .sbss**: 24B of dead slots between the live globals — extraction
layout artifact, no source decl produces it.
## Remaining sub-100 fns (all documented above or size-equal regname ties)
- pdm_partition: is_master_boot_sector 86.5, get_start_sector 82.6,
chg_ltop 97.8 (regname only)
- pf_cache: DoWriteNumSectorAndFreeIfNeeded 98.2
- pf_cluster: CombineFiles 99.8, InsertCluster 98.8, DeleteCluster 98.2
- pf_dir: p_mkdir 99.6, p_rename 98.2, p_move 99.3
- pf_entry_iterator: FindCluster 99.8, GetLFNEntryName 90.5
- pf_fat: DoAllocateChain 99.8, GetClusterAllocated 99.6, GetSector 99.4,
GetSectorSpecified 93.5 (goto-merge beats select's 85.9 — kept),
FreeChain 99.6, RefreshFSINFO 99.1
- pf_fat12: WriteFATEntryWithBuf 99.8, ReadFATEntryWithBuf 98.7
- pf_file: GetSFD 99.1
- pf_path: cmpNameImpl 98.4, MatchFileNameWithPattern 98.5 (artifact)
- pf_volume: p_rmvvol 95.9, attach 98.7, setcode 53.9, regctx 99.0
- FAAttach: FAAttach 99.4 (volatile-reg home tie)
- sd_drv: removal_callback 96.8, init 92.9, finalize 92.6, get_disk_info
97.9 (artifact), get_total_sectors 99.5, store_mbr_buf 99.8,
build_fat32_mbr_bpb 97.2
## STB_GLOBAL decode (session 3) — mechanism verified, sd_drv data all-100
Orig .o exports `STB_GLOBAL lbl_XXXX` data symbols = real file-scope objects
(pooled literals are STB_LOCAL). Reproduce with named file-scope decls.
### sd_drv — all data sections now 100% (.data/.rodata/.sbss/.bss)
- Orig .data = 8 GLOBAL objects packed at 4-aligned slots; MWCC 8-aligns every
.data object ≥8B so separate decls CANNOT reproduce it — merged all 2576B into
ONE named array `char lbl_81690D18[]` (verified byte-identical). String pad
rule: consecutive C literals share no implicit NUL; non-final string needs
`slot_len - len` explicit `\0`s, final needs `slot_len - len - 1`.
- Orig refs: ALL .data relocs are `lbl_X+0` — orig materializes each object
base into a register then adds plain-int offsets per site. Reproduced via
per-function `const char* str_base = lbl_81690D18;` + `str_base + off`.
Single-ref fns use direct `(const char*)lbl_81690D18` (inline lis/addi).
`pfd_st_inter_callback` now instruction-identical this way.
- .sbss 24B "dead slot" was NOT a dead object: it is g_event alignment pad —
`u32 g_event __attribute__((aligned(32)))` puts it at 0x20; section 100%.
- .bss residual was a real decode bug: PFD_SDDRV_INFO is 32B not 28 — trailing
`u32 reserved_1c;` (unreferenced tail field). Now byte-extent-identical.
- Remaining .text ties: multi-base materialization (fns referencing 2+ orig
objects materialize each base; single str_base under/over-shoots ±8-24B),
callee-reg home choices, and MWCC not homing globals that orig re-lis'd per
site (finalize/format). Documented tie class, no source lever found.
### pf_path — .sdata2 object identities decoded
- Orig .sdata2 = 4 separate GLOBAL u8 objects {1,2,1,2} in two 4-aligned
slots. Reproduced via `__declspec(section ".sdata2") pf_s8 lbl_81695998=1;`
style decls (non-const so code emits `lbz` per object, matching orig's
SDA21 relocs; const folds to `li`). sig init is `sig[0]=g; sig[1]=h;`
assignments (local array init needs constant exprs).
- 2B section tail = extraction hole, same class as orig dead objects; no
decl produces PROGBITS zero bytes (zero-init routes to .sbss, and MWCC
doesn't round section size to alignment). Left at 6/8B.
- orig also had .sdata globals lbl_81698390/8391 {1,2} and lbl_81698394
{0x20,0} shared by 3+ fns — byte-identical already via pooled literals;
left as pools (declaring globals at 0x28 would reshuffle pool order).
## Session 4 — code-tie grind (no flips)
- **Volatile store→load pinning (sd_drv, decoded lever):** casting to
`((volatile PFD_SDDRV_INFO*)&g_pfd_sddrv_info)->field` on BOTH the store and
the dependent load pins MWCC's memory-op order to source order — stops it
hoisting a load past a preceding same-struct store. Applied at init (2
sites), finalize (4 tail assigns), removal_callback (store + check).
Byte-identical at those sites.
- **copy_bytes peel model (sd_drv, decoded):** orig's copy helper is manually
peeled — `d[0]=*src; src++; for(i=1;i<size;i++) d[i]=*src++;` gives the
`addic.` live-IV test + abs-folded elem0 + `lbz k(r3)` walk. But the two
11B volume_label copies emit an UNPEELED all-walk — needed a second plain
helper called only at the 11B sites. store_bpb_buf + store_fat32_bpb_buf
byte-identical.
- **Early-return vs select-assign:** `r=-44; if(cond) r=0; return r;` folds to
select (`li -44; bne`); `if(!cond) return -44; return 0;` gives orig's
branch layout. Fixed pfd_sddrv_init tail.
- **GetLFNEntryName IV model (pf_entry_iterator, partial):** orig's `index`
is a byte offset into p_ent (long_name at +0): `li r31,0; addi r31,0x1a`;
dst recomputed `add r30,r28,r31` per iter; terminator via byte-arith
`*(u16*)((u8*)p_ent + num*0x1a) = 0` → `mulli 0x1a; rlwinm; sthx`.
u16-index forms give `mulli 0xd; slwi`. Byte-offset forms reproduce the
terminator but MWCC folds `p_ent + index` into a pointer-IV (4 callee webs)
vs orig's index-IV + per-iter recompute (5 webs, r27-r31). ~8 source forms
tried: `&long_name[index]`/`index += 13` (closest, 38 diffs — kept),
`(u8*)p_ent->long_name + index` (+63), `(u8*)p_ent + index` (+66),
`num*0x1a` terminator. Residual = MWCC IV-vs-recompute choice; no lever.
- **DoWrite overlap-sum derivation (pf_cache, decoded but unwinnable):**
orig computes `sum = sector+num_sector` once then derives `last = sum-1`
(`addi r3,r4,-1`) and `num_overlap = sum - p_sector` (`subf r4,r5,r4`).
Source forms sharing the sum (`sector+num_sector-1` either order, named
`end_sector` temp, `last+1-p_sector`) all cascade regalloc elsewhere
(-205/-88/-120 diffs vs 7 baseline). The 6-diff reorder reads
num_overlap before assignment — UB, rejected. Kept honest form.
- **pdm_part_get_start_sector:** 46 residual diffs are pure scheduling
permutations of the flat-assoc MBR_WORD decode (same insn set, lbz/slwi
interleave differs). Documented tie.
- **Uniform callee-reg rotations (regname-only, insn-identical):**
pf_cluster×3 (InsertCluster +1-web rotation, DeleteCluster mixed),
FAAttach (volatile-reg homes on the gOpenDisk/gOpenPartition store
cluster — inlining `table->drive-'A'` per site regressed to 136 insns),
pf_file GetSFD (3-word mr-ordering swap, ~6 lever forms across waves),
pf_fat12 ReadFATEntryWithBuf (flag r29/err r28 web swap in the select
`li flag,1; beq; clrlwi` — WriteFAT's identical construct matched, so
it's context regalloc; uninit-err rotated everything wrong).
## Session 5
### pf_entry_iterator .sdata decode (STB_GLOBAL -> named file-scope objects)
- orig exports 5 STB_GLOBAL .sdata objects ("..", ".", ":", "\\", "/") plus one 4B
all-zero object. Named file-scope `__declspec(section ".sdata") pf_s8 g_*[]`
reproduces them: relocs become addend-0 against named globals exactly like orig.
- NEW WALL: MWCC emits ALL all-zero-init objects to .sbss — declspec/volatile/
const/{0}/"" all fail to reach .sdata. The 4B zero object is only reproducible
as the pooled literal "\0\0\0" (literal pool always emits to .sdata).
- FindCluster residual: 8 word diffs = paired web-home swap — store-`1` web
(start_cluster/previous_cluster/chain_index stores) vs shift-`1` web
(1<<log2_entries_per_sector) swap r7/r8 between builds. Reorders cascade (218)
or no-op.
### pf_fat12 ReadFATEntryWithBuf
- `pf_s32 err;` uninit + `err = 0;` before `while (PF_TRUE)` homes err in the
LAST callee web like orig (35->34). Residual = pure callee-reg rotation
(orig offset->r31,sector->r30,flag->r29,err->r28; mine err->r31,...).
DECL ORDER DOES NOT CONTROL MWCC callee-web priority — proven invariant
across all orderings.
### pdm_partition
- MBR_WORD merge order: flat LOW-BYTE-FIRST `b0 + (b1<<8) + (b2<<16) + (b3<<24)`
is best (get_start_sector 146->45 word diffs, fuzzy 82.6->95.0). Orig's
residual tree is PAIRWISE `(b2<<16+b0) + (b3<<24+b1<<8)` — even/odd pairing.
MWCC reassociates flat `+` chains freely: no source-visible + or | tree
reproduces the pairing (all pairwise/| forms measure 82-275).
- is_master_boot_sector: `pf_s16 index` declared LAST in the local block ->
pointer webs home r6/r7 correctly (35->25). Residual = same pairwise-merge
scheduling + store-reload model (orig store-reloads *p_count for the test;
volatile pf_u32* p_count alone is a no-op, volatile p_start regresses 68).
- chg_ltop: 16 diffs, ndiff 0 — pure regname class.
### FAAttach (10 diffs, invariant)
- orig: index->r0 computed once before bgt, scaled copy->r6 (then arm) / r5
(else arm); bases->r5,r4. mine: index+scaled fused->r5, bases->r4,r3.
u32 index / u8 casts / index-in-arm / decl rotation: 10-57, all >= 10.
- PFFILE_GetSFD: 3 word diffs = marshal-order swap of 3 independent setup insns
({addi r7,r3,0x40},{mr r6,r28},{mr r29,r4}); operand flips 5-7. Documented.
- PFCACHE_DoWriteNumSectorAndFreeIfNeeded: 9-diff cluster around
`last_sector`/`num_overlap`: orig computes last=sum-1 via addi on the shared
sector+num_sector web; all rewrites (`sum-1` first, `p_page->sector+overlap`,
reordered) cascade 60-228. Committed form stays optimal.
- PFCLUSTER_CombineFiles: 7 diffs = {-1/div/+1 chain r3, sum chain r0} orig vs
{-1 r0, quot r3/r0, sums r4} mine. temp/polarity/lim-decl: 7-8. Documented.
## Session 6 (GetLFNEntryName match + s8-field decode + retests)
### MATCHED: PFENT_ITER_GetLFNEntryName (43->0 diffs)
- Derived byte-IV decode: orig uses an INDEX-IV (`add rD,rBase,rIV` dst
recompute + `addi rIV,rIV,N`) instead of MWCC's usual pointer-IV fold.
Reproduce by writing the byte index NON-AFFINE inside the loop:
`index = i * 13;` as its own statement + `destination = &long_name[index]`
(writing `long_name[i*13]` directly explodes into 4 webs, 63-72 diffs).
- Terminator: `long_name[num_entry_LFNs * 26 >> 1] = 0` (recompute from the
bound field, element-stride arithmetic) kills the element-IV and reproduces
orig's `mulli 0x1a` + `clrrwi`.
- DECL-FIRST pointer local flipped i<->dst callee homes r29<->r30 to match
orig (pointer local declared before the index locals). Combined: 0 diffs.
### s8 decode (WRONG SITE -- corrected): FADrvTbl.drive stays `char`
- orig emits `lbz rX,off` + `extsb` reading `table->drive` in FAAttach.
First theory `char drive -> s8 drive` in types.h is REFUTED by the DOL:
iplSDVFWorker.cpp (Matching, linked) passes `driveTable.drive` to s8
params -- with an s8 field it gains extsb at every call site -> hash
breaks. Orig field is `char`; orig's extsb comes from source-level `(s8)`
at the USE SITE: `index = (s8)table->drive - 'A';` reproduces the extsb
AND makes FAAttach's instruction stream ndiff-0 (remaining 10 diffs are
pure regname: orig index->r0/scale->r6/value->r3 vs mine index->r5 fused).
- pf_stub.o byte-identical either way (already Matching on main upstream).
- RETESTS this session: FAAttach cast-s8/drv-tmp/decl-order all still 10
(parked reg-rotation); GetSFD start_cluster_p local: still 3 (cyclic
marshal-order tie confirmed); FindCluster inline-`1<<x`/decl-order/fused
assign: all still 8 (paired r7<->r8 web swap, regalloc tie).
## Session: Devin Bot lever round (web-lifetime / paired-decl / cyclic-reorder)
Applied the three targeted levers; no flips.
- FAAttach index web (r0 vs r5): tried web-shortening via block-scope,
expression-in-arg-position, web-lifetime extension — all ≥10 or cascade.
Pure allocator home choice; parked.
- FindCluster paired r7<->r8 webs: all decl-pair swaps invariant at 8.
- GetSFD 3-insn cyclic marshal: all 6 decl perms + cyclic stmt reorder
invariant at 3 (marshal order is not source-statement order here).
- PFCACHE_DoWriteNumSectorAndFreeIfNeeded overlap branch (9 diffs):
orig remats `num_sector+sector` as `add r4,r27,r26` and emits
last=sum-1 BEFORE overlap=sum-p_sect. Any source form that reintroduces
the literal sum CSEs to hoisted r31 (228/106 cascade) — remat choice is
internal. Reassociated/inline forms all ≥106. Parked at 9.
- PFFAT12_ReadFATEntryWithBuf: decl-order rotation `res,sec,err,cur,off`
DID move it 34->23 (first decl-order win on this unit); residual is a
second callee rotation (one web homes r31 mine vs r28/r29 orig).
u16 sector/offset, init'd-err-decl, else-if, mul3 form all worse.
## owner-rule audit (w1001): lbl_ names + volatile casts banned
- Banned: lbl_XXXXXXXX identifiers, volatile use-site casts for memop pinning, score-lifting objects.
- sd_drv: 7 string-pool arrays renamed semantically (sd_drv_error_strings, sd_drv_format_sd,
sd_drv_msg_*), 6 volatile-cast sites removed. Cost: init +5, finalize +4, removal_callback +12
memop-order diffs (store/load reorder pairs MWCC now schedules freely). Declaring the whole struct
volatile would need banned-adjacent cast-aways at &obj call sites -> left partial, honest.
- pf_path: lbl_8169599x sig bytes -> path_sig_byte0-3. pf_volume: lbl_81698398 -> vol_wildcard_path.
- Renames are byte-neutral: all data sections still 100% after audit.