Compare commits

...

24 Commits

Author SHA1 Message Date
Devin AI
3d9d17a475 pf_volume: attach_mount goto/two-var decode (176-diffs -> ~6, beq+mr+b edge, shared ClearMount)
Orig: result-bound check with error=result on the error edge (mr r0,r3),
shared ClearMount block for success+mounted paths, li r0,0 remat at join.
Residual: phi-coalescing tie (r3 vs r0).

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 12:31:13 +00:00
Devin AI
77ffcfa537 pf_path: decode 3-pair sig-global layout (sdata2 scalar pairs + export'd const-zero pads)
Orig .sdata2 holds three anonymous-padded byte pairs: declspec'd s8 scalars
at 0,1 (CheckExtShortName) and 4,5 (GetExtShortNameIndex) with 00 00 pads
at 2,3 and 6,7. const pf_u16=0 objects emit the pads but mwld dead-strips
unreferenced consts at link; __declspec(export) keeps them -> DOL sha1 green.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 12:15:20 +00:00
Devin AI
6b989cb795 sd_drv: init accumulator tail decode (branchless NOR-select -> branchy, 31d -> SIZE-2)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 11:33:33 +00:00
Devin AI
f72d58b058 pf_volume: attach_mount eq0-guard decode (SIZE-2 -> 176=176, 21 reg diffs)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:30:42 +00:00
Devin AI
eb2f4c2107 pf_volume: restore declspec sdata2 mark (static const folds to li, regresses p_rmvvol 4d)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:27 +00:00
Devin AI
7583182e68 sd_drv: finalize explicit-RMW expr (6->4d); pf_fat12: err decl last (46->23d)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:14 +00:00
Devin AI
425d6c8238 pf_dir: yoda-order sfds compares, u16-widened LFN*32 mask (p_rename 51->50, p_move 44->42)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:09 +00:00
Devin AI
e8ebf0d917 pf_dir: p_rename tail returns updateEntry result directly (52->51 diffs)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:09 +00:00
Devin AI
7f762c49f9 pf_dir: decode .sdata/.sdata2 global-object layout (named string globals + sdata2 markers, empty-string literal)
Orig used named file-scope non-static pf_s8 globals (not string literals):
backslash/slash at file top; volume-sep/wildcard/parent/current-name
declared after the path-check helpers so the '' literal emits between
them (dtk merges literal+pad into the 4B zero object at .sdata+8).
.sdata2: two __declspec 1B pf_u8 0xE5 marker objects feeding the
p_rename/p_move deleted_marker copies. Data now 100%; 35/38 fns.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:09 +00:00
Devin AI
6b2d4aa950 pf_dir: p_rename nested-if guards GetVolumeFromPath speculation (+2 SIZE gone)
The compound && let MWCC speculate the GetVolumeFromPath(new_path) call at
function entry where its result died unused. Nested if keeps it in position.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:09 +00:00
Devin AI
eadb3bf2d7 sd_drv: finalize flags as &= ~1 (6d->4d)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:09 +00:00
Devin AI
c8f35f1395 pf_volume: match PFVOL_regctx via decl reorder + inlined stat compare
context_index decl before free_context_index flips the r7/r8 web binding;
inlining stat&1 into both compares removes the temp web.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:09 +00:00
Devin AI
68f20340d8 pf_dir: arg-first volume compare in current_directory_is_open (operand order)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:03 +00:00
Devin AI
6344d60e8c pf_fat: block-2 flush decl reorder (FreeChain 17->14 diffs)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:03 +00:00
Devin AI
6b44d50777 pf_dir: decl-order web-priority fix for counter bindings (p_rename 65->52, p_move 71->44)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:03 +00:00
Devin AI
ecf4718d92 pf_fat: FreeChain join-side phi materialization via entryError temp
Routing the WriteFATEntryWithBuf switch results through a scoped
s32 entryError then assigning to error after the switch reproduces
base's single join mr (producers stay in r3, one copy at the phi)
instead of per-producer mr copies — SIZE 254=254, diffs 30->17.
Remaining diffs are the register-permutation family (flush-loop
web coloring).

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:03 +00:00
Devin AI
bf12ec00b4 pf_dir: decode .sdata2 deleted_marker objects + all structural diffs
- PFENT_findEntry extern decls corrected to 6-param signature (removes
  phantom li r9,0 at 4 call sites)
- current_directory_is_open: state from volumes[index].p_vol (lwzu)
- p_rename: check-then-goto tail duplicates the error check at join
- deleted_marker: dead [4] init-array emits 4B .sdata2 objects while
  marker[0] = init[0] produces the 1-byte lbz+stb stack copy (data
  .sdata/.sdata2 now byte-identical)

p_move/p_rename now exact insn counts (631/625); residuals are
register-permutation diffs only

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:03 +00:00
Devin AI
38fb242b2c pfrest: pdm_partition is_master_boot_sector — second loop to index form (25->21 diffs)
Pointer-walk replaced by start[index]/count[index] access matches base's
pointer binding; residual is byte-load interleave scheduling (A,C,D,B vs
A,B,D,C leaf emission) — documented scheduling tie.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:03 +00:00
Devin AI
f318abd6f5 fa: post-rebase data decode — pf_dir sdata pads, pf_fat flat rodata table, pf_volume label, puh_msc_blk sbss
- pf_dir: deleted_marker[4] emits .sdata2 tail; ".\0x6" literal fills .sdata tail (byte-identical)
- pf_fat: fat_special_values as flat u32[FAT_MAX*5+1] — byte-identical .rodata incl +4 tail; flat indexing also clears ~10 reg-diff fns
- pf_volume: default_volume_label[16] emits the 4B .data tail
- puh_msc_blk: uhg_msc_blk_msg_id (unreferenced global) emits .sbss+4 — reverse decl order matches base

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:21:03 +00:00
Devin AI
216b18a1ef pfrest: pf_path .sdata2 decode — non-const sig globals force lbz loads (CheckExtShortName byte-identical, .sdata2 8B match)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:20:52 +00:00
Devin AI
3611bc0764 pfrest: pf_path .sdata decode — file-scope pf_s8 sig byte globals + \x20\0\0 literal (48B byte-identical)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:20:52 +00:00
Devin AI
3013d33b86 pfrest: sd_drv .bss/.sbss globals decode (write_protected tail member, 7 unreferenced u32s before/after g_event)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:20:52 +00:00
Devin AI
f0b1b028df pfrest: sd_drv explicit-nul literal pads .data to 2576B
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:20:27 +00:00
Devin AI
6f39d3c485 pfrest: adopt fapark3 states for pdm_partition, pf_entry_iterator, pf_fat12, pf_file
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 10:19:55 +00:00
8 changed files with 174 additions and 123 deletions

View File

@@ -35,7 +35,14 @@ u8 g_pfd_sddrv_buf[0x200];
static FAInsertCallback g_attach_func = 0;
static FAEjectCallback g_detach_func = 0;
u32 g_callback_status;
u32 g_event;
u32 g_inserted_status;
u32 g_removed_status;
u32 g_attach_status;
u32 g_detach_status;
u32 g_sddrv_work0;
u32 g_sddrv_work1;
extern u8 pfd_get_media_drv_char(FADisk*, s8*, u32);
extern void pdm_disk_notify_media_insert(FADisk*);
@@ -318,10 +325,11 @@ s32 pfd_sddrv_init(FADisk* disk) {
}
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;
sd_result = 0;
if (disk != g_pfd_sddrv_info.disk) {
sd_result = -44;
}
return -44;
return sd_result;
}
if ((g_pfd_sddrv_info.flags & 4) == 0) {
g_pfd_sddrv_info.bytes_per_sector = 0x200;
@@ -499,7 +507,7 @@ s32 pfd_sddrv_finalize(FADisk* disk) {
}
g_pfd_sddrv_info.device = 0;
}
g_pfd_sddrv_info.flags = g_pfd_sddrv_info.flags & 0xfffffffe;
g_pfd_sddrv_info.flags = g_pfd_sddrv_info.flags & ~1;
g_pfd_sddrv_info.media_inserted = 0;
g_pfd_sddrv_info.disk = 0;
g_pfd_sddrv_info.drive = 0;
@@ -1523,7 +1531,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("ERR Failed to build up and write MBR and BPB fields.\n\0\0");
return result;
}
return 0;

View File

@@ -2,6 +2,7 @@
#include <string.h>
UHF_MSC_DEVICE uhg_msc_blk_device_tbl[8];
u32 uhg_msc_blk_msg_id;
static u8* st_uhs_msc_blk_buf;
extern void pdm_disk_notify_media_insert(FADisk* disk);
s32 uhf_msc_blk_init(FADisk* disk);

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 {
@@ -29,15 +29,11 @@ pf_s32 pdm_part_is_master_boot_sector(pf_u8* buf, pf_u32 total, pf_bool* p_is_mb
p_count++;
buf += 16;
}
p_start = start;
p_count = count;
for (index = 0; index < 4; index++) {
if (*p_start + *p_count > total) {
if (start[index] + count[index] > total) {
if (index == 0) { *p_is_mbr = 0; }
return 2;
}
p_start++;
p_count++;
}
return 0;
}
@@ -141,7 +137,7 @@ pf_s32 pdm_part_get_start_sector(PDM_PARTITION* p_part) {
}
return 0;
}
static inline pf_u32 partition_physical_sector(PDM_PARTITION* p_part, pf_u32 sector, pf_u32 bps) {
pf_u32 pdm_part_chg_ltop(PDM_PARTITION* p_part, pf_u32 sector, pf_u32 bps) {
pf_u16 media_bps;
pf_u32 ratio;
pf_u32 start;
@@ -158,9 +154,6 @@ static inline pf_u32 partition_physical_sector(PDM_PARTITION* p_part, pf_u32 sec
else if (ratio == 8) { start >>= 3; }
return sector + start;
}
pf_u32 pdm_part_chg_ltop(PDM_PARTITION* p_part, pf_u32 sector, pf_u32 bps) NO_INLINE {
return partition_physical_sector(p_part, sector, bps);
}
pf_s32 pdm_part_get_partition(PDM_DISK* p_disk, pf_u32 id, PDM_PARTITION** pp_part) {
pf_s32 err;
pf_u16 index;

View File

@@ -24,6 +24,15 @@ typedef struct PFDIR_FAT_HINT {
pf_u32 previous_cluster;
} PFDIR_FAT_HINT;
pf_s8 pf_dir_sep_backslash[] = "\\";
pf_s8 pf_dir_sep_slash[] = "/";
extern pf_s8 pf_dir_volume_sep[];
extern pf_s8 pf_dir_wildcard[];
extern pf_s8 pf_dir_parent_name[];
extern pf_s8 pf_dir_current_name[];
__declspec(section ".sdata2") pf_u8 pf_dir_rename_marker[1] = {0xE5};
__declspec(section ".sdata2") pf_u8 pf_dir_move_marker[1] = {0xE5};
typedef struct PFDIR_STR {
const pf_s8* p_head;
const pf_s8* p_tail;
@@ -143,8 +152,8 @@ extern pf_s32 PFFAT_FreeChain(PFDIR_FFD* ffd, pf_u32 start_cluster, pf_u32 chain
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;
if (volume == pf_vol_set.volume_state.volumes[index].p_vol) {
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++) {
@@ -286,8 +295,8 @@ pf_s32 PFDIR_p_opendir(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_DIR** opened_di
PFDIR_DIR* dir;
pf_s32 error;
if ((PFSTR_StrNCmp(path, (const pf_s8*)"\\", 1, 0, 1) == 0 ||
PFSTR_StrNCmp(path, (const pf_s8*)"/", 1, 0, 1) == 0) &&
if ((PFSTR_StrNCmp(path, pf_dir_sep_backslash, 1, 0, 1) == 0 ||
PFSTR_StrNCmp(path, pf_dir_sep_slash, 1, 0, 1) == 0) &&
PFSTR_StrNCmp(path, (const pf_s8*)"", 1, 1, 1) == 0) {
error = PFENT_GetRootDir(volume, &entry);
if (error != 0) {
@@ -295,22 +304,22 @@ pf_s32 PFDIR_p_opendir(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_DIR** opened_di
}
goto open_directory;
} else if (PFSTR_StrNumChar(path, 1) == 2 &&
PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0) {
PFSTR_StrNCmp(path, pf_dir_volume_sep, 1, 1, 1) == 0) {
error = PFVOL_GetCurrentDir(volume, &entry);
goto open_directory;
} else if (PFSTR_StrNumChar(path, 1) == 3 &&
PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0 &&
(PFSTR_StrNCmp(path, (const pf_s8*)"\\", 1, 2, 1) == 0 ||
PFSTR_StrNCmp(path, (const pf_s8*)"/", 1, 2, 1) == 0)) {
PFSTR_StrNCmp(path, pf_dir_volume_sep, 1, 1, 1) == 0 &&
(PFSTR_StrNCmp(path, pf_dir_sep_backslash, 1, 2, 1) == 0 ||
PFSTR_StrNCmp(path, pf_dir_sep_slash, 1, 2, 1) == 0)) {
error = PFENT_GetRootDir(volume, &entry);
if (error != 0) {
return error;
}
goto open_directory;
} else {
if (PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0 &&
(PFSTR_StrNCmp(path, (const pf_s8*)"\\", 1, 2, 1) == 0 ||
PFSTR_StrNCmp(path, (const pf_s8*)"/", 1, 2, 1) == 0)) {
if (PFSTR_StrNCmp(path, pf_dir_volume_sep, 1, 1, 1) == 0 &&
(PFSTR_StrNCmp(path, pf_dir_sep_backslash, 1, 2, 1) == 0 ||
PFSTR_StrNCmp(path, pf_dir_sep_slash, 1, 2, 1) == 0)) {
PFSTR_MoveStrPos(path, 2);
}
error = PFENT_ITER_GetEntryOfPath(&iter, &entry, volume, path, 0);
@@ -361,7 +370,7 @@ pf_s32 PFDIR_p_readdir(PFDIR_DIR* dir, PFDIR_READ_RESULT* result) {
dir->next_position = 0;
}
do {
PFSTR_InitStr(&pattern, (const pf_s8*)"*", 1);
PFSTR_InitStr(&pattern, pf_dir_wildcard, 1);
PFSTR_SetLocalStr(&pattern, 0);
error = PFENT_findEntryPos(&ffd, &entry, dir->current_position, &pattern, 0x7F, 0,
&logical_position, &entry_position);
@@ -381,7 +390,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*);
@@ -406,7 +415,12 @@ extern pf_s32 PFFAT_GetSectorSpecified(PFDIR_FFD* ffd, pf_u32 index, pf_u32 allo
extern void PFPATH_AdjustExtShortName(pf_s8* name, pf_u32 position);
extern pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME* volume, pf_u32 sector, PF_CACHE_PAGE** page, pf_u32* size);
extern void PFCACHE_FreeDataPage(PF_VOLUME* volume, PF_CACHE_PAGE* page);
extern void PFCACHE_FreeDataPage(PF_VOLUME* volume, PF_CACHE_PAGE* page);pf_s8 pf_dir_volume_sep[] = ":";
pf_s8 pf_dir_wildcard[] = "*";
pf_s8 pf_dir_parent_name[] = "..";
pf_s8 pf_dir_current_name[] = ".";
static inline void set_dot_entry(pf_u8* buffer) {
buffer[0] = '.';
buffer[1] = ' ';
@@ -453,7 +467,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 attr_required, 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);
@@ -656,7 +670,7 @@ pf_s32 PFDIR_p_chdir(PF_VOLUME* p_vol, PFDIR_STR* p_path_str) {
PF_ENT_ITER iter;
PF_DIR_ENT entry_dir;
if (((PFSTR_StrNCmp(p_path_str, (pf_s8*)"\\", 1U, 0, 1U) == 0) || (PFSTR_StrNCmp(p_path_str, (pf_s8*)"/", 1U, 0, 1U) == 0)) &&
if (((PFSTR_StrNCmp(p_path_str, pf_dir_sep_backslash, 1U, 0, 1U) == 0) || (PFSTR_StrNCmp(p_path_str, pf_dir_sep_slash, 1U, 0, 1U) == 0)) &&
(PFSTR_StrNCmp(p_path_str, (pf_s8*)"", 1U, 1, 1U) == 0)) {
err = PFENT_GetRootDir(p_vol, &entry_dir);
if (err != 0) {
@@ -669,11 +683,11 @@ pf_s32 PFDIR_p_chdir(PF_VOLUME* p_vol, PFDIR_STR* p_path_str) {
return 0;
}
if ((PFSTR_StrNumChar(p_path_str, 1U) == 2) && (PFSTR_StrNCmp(p_path_str, (pf_s8*)":", 1U, 1, 1U) == 0)) {
if ((PFSTR_StrNumChar(p_path_str, 1U) == 2) && (PFSTR_StrNCmp(p_path_str, pf_dir_volume_sep, 1U, 1, 1U) == 0)) {
return 0;
}
if ((PFSTR_StrNumChar(p_path_str, 1U) == 3) && (PFSTR_StrNCmp(p_path_str, (pf_s8*)":", 1U, 1, 1U) == 0) &&
((PFSTR_StrNCmp(p_path_str, (pf_s8*)"\\", 1U, 2, 1U) == 0) || (PFSTR_StrNCmp(p_path_str, (pf_s8*)"/", 1U, 2, 1U) == 0))) {
if ((PFSTR_StrNumChar(p_path_str, 1U) == 3) && (PFSTR_StrNCmp(p_path_str, pf_dir_volume_sep, 1U, 1, 1U) == 0) &&
((PFSTR_StrNCmp(p_path_str, pf_dir_sep_backslash, 1U, 2, 1U) == 0) || (PFSTR_StrNCmp(p_path_str, pf_dir_sep_slash, 1U, 2, 1U) == 0))) {
err = PFENT_GetRootDir(p_vol, &entry_dir);
if (err != 0) {
return err;
@@ -685,8 +699,8 @@ pf_s32 PFDIR_p_chdir(PF_VOLUME* p_vol, PFDIR_STR* p_path_str) {
return 0;
}
if ((PFSTR_StrNCmp(p_path_str, (pf_s8*)":", 1U, 1, 1U) == 0) &&
((PFSTR_StrNCmp(p_path_str, (pf_s8*)"\\", 1U, 2, 1U) == 0) || (PFSTR_StrNCmp(p_path_str, (pf_s8*)"/", 1U, 2, 1U) == 0))) {
if ((PFSTR_StrNCmp(p_path_str, pf_dir_volume_sep, 1U, 1, 1U) == 0) &&
((PFSTR_StrNCmp(p_path_str, pf_dir_sep_backslash, 1U, 2, 1U) == 0) || (PFSTR_StrNCmp(p_path_str, pf_dir_sep_slash, 1U, 2, 1U) == 0))) {
PFSTR_MoveStrPos(p_path_str, 2);
}
err = PFENT_ITER_GetEntryOfPath(&iter, &entry_dir, p_vol, p_path_str, 0);
@@ -869,17 +883,18 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
pf_u32 position;
pf_u32 found;
pf_u16 time;
pf_u8 deleted_marker[1] = {0xE5};
pf_u16 saved_initial_char = 0;
pf_u8 deleted_marker[1];
pf_u32 sector;
pf_u32* next_sector;
pf_s32 filename_length;
pf_s32 parse_error;
pf_s32 allocation_error = 0;
pf_u16 saved_initial_char = 0;
pf_s32 error;
pf_u32 index;
PF_DIR_ENT* update_entry;
deleted_marker[0] = pf_dir_rename_marker[0];
error = PFPATH_SplitPath((PFDIR_STR*)old_path, &directory, &source_name);
if (error != 0) { return error; }
if (PFSTR_GetCodeMode(&source_name) == 2) {
@@ -900,8 +915,9 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
if (found == 0) { return 3; }
if ((source_entry.attr & 8) != 0) { return 3; }
if ((source_entry.attr & 1) != 0) { return 0x18; }
if (PFSTR_StrNCmp((PFDIR_STR*)new_path, (const pf_s8*)":", 1, 1, 1) == 0 &&
volume != PFPATH_GetVolumeFromPath(new_path)) { return 0x1F; }
if (PFSTR_StrNCmp((PFDIR_STR*)new_path, pf_dir_volume_sep, 1, 1, 1) == 0) {
if (volume != PFPATH_GetVolumeFromPath(new_path)) { return 0x1F; }
}
error = PFPATH_SplitPath((PFDIR_STR*)new_path, &directory, &destination_name);
if (error != 0) { return error; }
if (PFSTR_GetCodeMode(&destination_name) == 2) {
@@ -925,7 +941,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) {
@@ -933,15 +949,15 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
} else {
if (directory_is_open(&source_entry) != 0) { return 0x13; }
if (current_directory_is_open(source_entry.p_vol, source_entry.start_cluster) != 0) { return 0x1C; }
if (PFSTR_StrNCmp(&source_name, (const pf_s8*)"..", 1, 0, 2) == 0) { return 0x1C; }
if (PFSTR_StrNCmp(&source_name, (const pf_s8*)".", 1, 0, 1) == 0) { return 0x1C; }
if (PFSTR_StrNCmp(&source_name, pf_dir_parent_name, 1, 0, 2) == 0) { return 0x1C; }
if (PFSTR_StrNCmp(&source_name, pf_dir_current_name, 1, 0, 1) == 0) { return 0x1C; }
{
PFDIR_SFD* file = ((PFDIR_VOLUME_DIRS*)volume)->sfds;
pf_u32 directory_sector = volume->bpb.first_data_sector +
((source_entry.start_cluster - 2) << volume->bpb.log2_sectors_per_cluster);
for (index = 0; index < 5; index++, file++) {
if ((file->stat & 1) != 0 && (file->stat & 2) != 0) {
if (file->dir_entry.p_vol == volume && file->dir_entry.entry_sector == directory_sector) { return 0x13; }
if (volume == file->dir_entry.p_vol && directory_sector == file->dir_entry.entry_sector) { return 0x13; }
found = 0;
error = PFENT_ITER_FindCluster(&file->dir_entry, source_entry.start_cluster, &found);
if (error != 0) { return error; }
@@ -961,6 +977,7 @@ 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);
if (error != 0) { return error; }
goto finish_rename;
}
if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) {
@@ -969,13 +986,13 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
for (index = 1; index <= source_entry.num_entry_LFNs; index++) {
error = PFENT_ITER_Retreat(&source_iter, 0);
if (error != 0) { return error; }
error = PFSEC_WriteData(volume, deleted_marker, source_iter.sector,
error = PFSEC_WriteData(volume, (pf_u8*)&deleted_marker, source_iter.sector,
source_iter.offset, 1, &written, 0);
if (error != 0) { return error; }
if (written != 1) { return 0x11; }
}
}
error = PFSEC_WriteData(volume, deleted_marker, source_entry.entry_sector,
error = PFSEC_WriteData(volume, (pf_u8*)&deleted_marker, source_entry.entry_sector,
source_entry.entry_offset, 1, &written, 0);
if (error != 0) { return error; }
if (written != 1) { return 0x11; }
@@ -1034,7 +1051,7 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
}
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) {
@@ -1056,8 +1073,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
pf_u32 position;
pf_u32 found;
pf_u16 time;
pf_u8 deleted_marker[1] = {0xE5};
pf_u16 saved_initial_char = 0;
pf_u8 deleted_marker[1];
pf_u32 sector;
pf_u32* next_sector;
pf_s32 filename_length;
@@ -1066,8 +1082,10 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
pf_s32 error;
pf_u32 index;
pf_u32 lfn_index;
pf_u16 saved_initial_char = 0;
PF_DIR_ENT* update_entry;
deleted_marker[0] = pf_dir_move_marker[0];
error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume, (PFDIR_STR*)old_path, 0);
if (error != 0) { return error; }
if (volume != PFPATH_GetVolumeFromPath(new_path)) { return 0x1F; }
@@ -1083,7 +1101,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; }
@@ -1097,15 +1115,15 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
if (current_directory_is_open(source_entry.p_vol, source_entry.start_cluster) != 0) { return 0x1C; }
error = PFPATH_SplitPath((PFDIR_STR*)old_path, &directory, &source_name);
if (error != 0) { return error; }
if (PFSTR_StrNCmp(&source_name, (const pf_s8*)"..", 1, 0, 2) == 0) { return 10; }
if (PFSTR_StrNCmp(&source_name, (const pf_s8*)".", 1, 0, 1) == 0) { return 10; }
if (PFSTR_StrNCmp(&source_name, pf_dir_parent_name, 1, 0, 2) == 0) { return 10; }
if (PFSTR_StrNCmp(&source_name, pf_dir_current_name, 1, 0, 1) == 0) { return 10; }
{
PFDIR_SFD* file = ((PFDIR_VOLUME_DIRS*)volume)->sfds;
pf_u32 directory_sector = volume->bpb.first_data_sector +
((source_entry.start_cluster - 2) << volume->bpb.log2_sectors_per_cluster);
for (index = 0; index < 5; index++, file++) {
if ((file->stat & 1) != 0 && (file->stat & 2) != 0) {
if (file->dir_entry.p_vol == volume && file->dir_entry.entry_sector == directory_sector) { return 0x13; }
if (volume == file->dir_entry.p_vol && directory_sector == file->dir_entry.entry_sector) { return 0x13; }
found = 0;
error = PFENT_ITER_FindCluster(&file->dir_entry, source_entry.start_cluster, &found);
if (error != 0) { return error; }
@@ -1118,9 +1136,9 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
pf_u32 parent_cluster;
if (destination_entry.start_cluster == 1 || destination_entry.start_cluster == 0) { break; }
PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster);
PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1);
PFSTR_InitStr(&parent_name, pf_dir_parent_name, 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; }
@@ -1145,13 +1163,13 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
for (index = 1; index <= source_entry.num_entry_LFNs; index++) {
error = PFENT_ITER_Retreat(&source_iter, 0);
if (error != 0) { return error; }
error = PFSEC_WriteData(volume, deleted_marker, source_iter.sector,
error = PFSEC_WriteData(volume, (pf_u8*)&deleted_marker, source_iter.sector,
source_iter.offset, 1, &written, 0);
if (error != 0) { return error; }
if (written != 1) { return 0x11; }
}
}
error = PFSEC_WriteData(volume, deleted_marker, source_entry.entry_sector,
error = PFSEC_WriteData(volume, (pf_u8*)&deleted_marker, source_entry.entry_sector,
source_entry.entry_offset, 1, &written, 0);
if (error != 0) { return error; }
if (written != 1) { return 0x11; }
@@ -1180,7 +1198,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 & 0xff) * 32);
}
update_entry = &source_entry;
} else {
@@ -1190,9 +1208,9 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
update_entry = &destination_entry;
if ((source_entry.attr & 0x10) != 0) {
PFFAT_InitFFD(&source_iter.ffd, &source_hint, volume, &source_entry.start_cluster);
PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1);
PFSTR_InitStr(&parent_name, pf_dir_parent_name, 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)) {

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

@@ -94,18 +94,13 @@ typedef struct PFFAT_FFD {
PF_VOLUME* p_vol;
} PFFAT_FFD;
static const struct {
u32 bad;
u32 eoc1;
u32 eoc2;
u32 fat0_mask;
u32 fat1;
} fat_special_values[FAT_MAX] = {
{0xFF7, 0xFF8, 0xFFF, 0xF00, 0xFFF},
{0xFFF7, 0xFFF8, 0xFFFF, 0xFF00, 0xFFFF},
{0xFFFFFF7, 0xFFFFFF8, 0xFFFFFFF, 0xFFFFF00, 0xFFFFFFF}
const u32 fat_special_values[FAT_MAX*5+1] = {
0xFF7, 0xFF8, 0xFFF, 0xF00, 0xFFF,
0xFFF7, 0xFFF8, 0xFFFF, 0xFF00, 0xFFFF,
0xFFFFFF7, 0xFFFFFF8, 0xFFFFFFF, 0xFFFFF00, 0xFFFFFFF, 0
};
extern s32 PFSEC_ReadFAT(PF_VOLUME* volume, u8* buffer, u32 sector, u16 offset,
u16 size);
extern s32 PFCACHE_AllocateDataPage(PF_VOLUME* volume, u32 sector,
@@ -404,7 +399,7 @@ s32 PFFAT_FindClusterLink(PFFAT_FFD* file, u32 chainIndex, u32* cluster,
if (nextCluster == 0) {
return 13;
}
if (nextCluster == fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
if (nextCluster == fat_special_values[file->p_vol->bpb.fat_type*5+2]) {
return 0;
}
*cluster = nextCluster;
@@ -471,7 +466,7 @@ s32 PFFAT_FindClusterLinkWithBuf(PFFAT_FFD* file, u32 chainIndex,
if (nextCluster == 0) {
return 13;
}
if (nextCluster == fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
if (nextCluster == fat_special_values[file->p_vol->bpb.fat_type*5+2]) {
return 0;
}
*cluster = nextCluster;
@@ -525,7 +520,7 @@ s32 PFFAT_ReadCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
return 6;
}
if (file->cluster_link.buffer != 0 &&
value != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
value != fat_special_values[file->p_vol->bpb.fat_type*5+2]) {
if (file->cluster_link.max_count > file->cluster_link.position &&
file->cluster_link.max_count != 0) {
if (chainIndex == file->cluster_link.position *
@@ -588,7 +583,7 @@ s32 PFFAT_ReadClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
return 6;
}
if (file->cluster_link.buffer != 0 &&
value != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
value != fat_special_values[file->p_vol->bpb.fat_type*5+2]) {
if (file->cluster_link.max_count > file->cluster_link.position &&
file->cluster_link.max_count != 0) {
if (chainIndex == file->cluster_link.position *
@@ -667,7 +662,7 @@ s32 PFFAT_WriteCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
}
}
} else if (cluster !=
fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
fat_special_values[file->p_vol->bpb.fat_type*5+2]) {
error = PFFAT_FindClusterLink(file, chainIndex, &accessCluster,
&useClusterLink);
if (error != 0) {
@@ -757,7 +752,7 @@ s32 PFFAT_WriteClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
}
}
} else if (cluster !=
fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
fat_special_values[file->p_vol->bpb.fat_type*5+2]) {
error = PFFAT_FindClusterLinkWithBuf(
file, chainIndex, &accessCluster, &useClusterLink, page);
if (error != 0) {
@@ -814,7 +809,7 @@ s32 PFFAT_DoAllocateChain(PFFAT_FFD* file, u32 chainLength, u32 chainIndex,
PF_CACHE_PAGE* page;
volume = file->p_vol;
eoc2 = fat_special_values[volume->bpb.fat_type].eoc2;
eoc2 = fat_special_values[volume->bpb.fat_type*5+2];
*firstAllocatedCluster = -1;
*lastAllocatedCluster = -1;
lastFreeCluster = -1;
@@ -919,8 +914,8 @@ s32 PFFAT_GetClusterInChain(PFFAT_FFD* file, u32 chainIndex, u32 mode,
PF_CACHE_PAGE* page;
s32 error;
badCluster = fat_special_values[file->p_vol->bpb.fat_type].bad;
eoc1 = fat_special_values[file->p_vol->bpb.fat_type].eoc1;
badCluster = fat_special_values[file->p_vol->bpb.fat_type*5+0];
eoc1 = fat_special_values[file->p_vol->bpb.fat_type*5+1];
*locateEnd = -1;
*locateStart = -1;
@@ -950,7 +945,7 @@ s32 PFFAT_GetClusterInChain(PFFAT_FFD* file, u32 chainIndex, u32 mode,
appendCount = file->last_cluster.max_chain_index + numClusters -
chainIndex;
currentCluster = file->last_cluster.num_last_cluster;
nextCluster = fat_special_values[file->p_vol->bpb.fat_type].eoc2;
nextCluster = fat_special_values[file->p_vol->bpb.fat_type*5+2];
searchIndex = file->last_cluster.max_chain_index + 1;
}
} else {
@@ -984,7 +979,7 @@ s32 PFFAT_GetClusterInChain(PFFAT_FFD* file, u32 chainIndex, u32 mode,
}
} else {
nextCluster =
fat_special_values[file->p_vol->bpb.fat_type].eoc2;
fat_special_values[file->p_vol->bpb.fat_type*5+2];
searchIndex--;
}
if ((nextCluster < 2 ||
@@ -1060,7 +1055,7 @@ s32 PFFAT_GetClusterContinuousSectorInChain(PFFAT_FFD* file,
}
if (cluster + 1 != nextCluster) {
if (nextCluster ==
fat_special_values[volume->bpb.fat_type].eoc2) {
fat_special_values[volume->bpb.fat_type*5+2]) {
file->last_cluster.num_last_cluster = cluster;
file->last_cluster.max_chain_index = chainIndex - 1;
}
@@ -1107,7 +1102,7 @@ s32 PFFAT_GetClusterAllocatedInChain(PFFAT_FFD* file, u32 initialCluster,
return error;
}
if (nextCluster ==
fat_special_values[volume->bpb.fat_type].eoc2) {
fat_special_values[volume->bpb.fat_type*5+2]) {
file->last_cluster.num_last_cluster = cluster;
file->last_cluster.max_chain_index = chainIndex - 1;
break;
@@ -1475,7 +1470,7 @@ s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
if (startCluster == 0) {
return 0;
}
eoc1 = fat_special_values[volume->bpb.fat_type].eoc1;
eoc1 = fat_special_values[volume->bpb.fat_type*5+1];
if (size != 0) {
fileSize = size;
clusterSize = volume->bpb.bytes_per_sector
@@ -1551,24 +1546,26 @@ s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
0, 1, page);
chainIndex++;
} else {
s32 entryError;
currentPage = page;
switch (volume->bpb.fat_type) {
case FAT_12:
error = PFFAT12_WriteFATEntryWithBuf(
entryError = PFFAT12_WriteFATEntryWithBuf(
volume, (u16)startCluster, 0, currentPage);
break;
case FAT_16:
error = PFFAT16_WriteFATEntryWithBuf(volume, startCluster, 0,
entryError = PFFAT16_WriteFATEntryWithBuf(volume, startCluster, 0,
currentPage);
break;
case FAT_32:
error = PFFAT32_WriteFATEntryWithBuf(volume, startCluster, 0,
entryError = PFFAT32_WriteFATEntryWithBuf(volume, startCluster, 0,
currentPage);
break;
default:
error = 15;
entryError = 15;
break;
}
error = entryError;
}
if (error != 0) {
PFCACHE_FreeDataPage(volume, page);
@@ -1588,9 +1585,9 @@ s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
}
{
s32 firstFlushError;
u32 fatSector;
u16 fatIndex;
PF_CACHE_PAGE* flushPage;
u16 fatIndex;
u32 fatSector;
firstFlushError = 0;
flushPage = page;
@@ -1630,7 +1627,7 @@ s32 PFFAT_getBeforeChain(PF_VOLUME* volume, u32 startCluster,
s32 alreadyAllocated;
s32 error;
eoc1 = fat_special_values[volume->bpb.fat_type].eoc1;
eoc1 = fat_special_values[volume->bpb.fat_type*5+1];
*cluster = -1;
error = PFCACHE_AllocateDataPage(volume, -1, &page,
&alreadyAllocated);
@@ -1702,7 +1699,7 @@ s32 PFFAT_InitFATRegion(PF_VOLUME* volume)
}
PFCACHE_FreeFATPage(volume, page);
fatValue = volume->bpb.media |
fat_special_values[volume->bpb.fat_type].fat0_mask;
fat_special_values[volume->bpb.fat_type*5+3];
switch (volume->bpb.fat_type) {
case FAT_12:
if (fatValue > 0xFFF) {
@@ -1732,7 +1729,7 @@ s32 PFFAT_InitFATRegion(PF_VOLUME* volume)
if (error != 0) {
return error;
}
fatValue = fat_special_values[volume->bpb.fat_type].fat1;
fatValue = fat_special_values[volume->bpb.fat_type*5+4];
switch (volume->bpb.fat_type) {
case FAT_12:
if (fatValue > 0xFFF) {
@@ -1778,7 +1775,7 @@ s32 PFFAT_MakeRootDir(PF_VOLUME* volume)
s32 error;
rootCluster = volume->bpb.root_dir_cluster;
fatValue = fat_special_values[volume->bpb.fat_type].eoc2;
fatValue = fat_special_values[volume->bpb.fat_type*5+2];
switch (volume->bpb.fat_type) {
case FAT_12:
if (fatValue > 0xFFF) {
@@ -1940,7 +1937,7 @@ s32 PFFAT_TraceClustersChain(PFFAT_FFD* file, u32 startCluster, u32 size,
volume = file->p_vol;
if (size == -1 && file->last_cluster.num_last_cluster != 0) {
*targetCluster = file->last_cluster.num_last_cluster;
*nextClusterOutput = fat_special_values[volume->bpb.fat_type].eoc2;
*nextClusterOutput = fat_special_values[volume->bpb.fat_type*5+2];
return 0;
}
clusterSize = volume->bpb.bytes_per_sector *
@@ -1964,7 +1961,7 @@ s32 PFFAT_TraceClustersChain(PFFAT_FFD* file, u32 startCluster, u32 size,
}
savedCluster = startCluster;
if (nextCluster ==
fat_special_values[volume->bpb.fat_type].eoc2) {
fat_special_values[volume->bpb.fat_type*5+2]) {
file->last_cluster.num_last_cluster = startCluster;
file->last_cluster.max_chain_index = chainIndex - 1;
break;
@@ -2125,5 +2122,5 @@ s32 PFFAT_FinalizeFFD(PFFAT_FFD* file)
u32 PFFAT_GetValueOfEOC2(PF_VOLUME* volume)
{
return fat_special_values[volume->bpb.fat_type].eoc2;
return fat_special_values[volume->bpb.fat_type*5+2];
}

View File

@@ -1015,25 +1015,35 @@ void PFPATH_SetSearchPattern(pf_s8* p_buf_local, pf_u16* p_buf_unicode, PF_STR*
PFPATH_transformFromUnicodeToNormal(p_buf_local, p_buf_unicode);
}
pf_s8 pf_path_sig_byte0 = 1;
pf_s8 pf_path_sig_byte1 = 2;
pf_u32 PFPATH_CheckExtShortNameSignature(PF_STR* p_str) {
pf_u32 result = 0;
pf_s8 sig[2] = "\x01\x02";
pf_s8 sig[2];
sig[0] = pf_path_sig_byte0;
sig[1] = pf_path_sig_byte1;
if (PFSTR_StrNCmp(p_str, sig, 1, 0, 2) == 0) {
result = 1;
}
return result;
}
__declspec(section ".sdata2") pf_s8 pf_path_sig_c0 = 1;
__declspec(section ".sdata2") pf_s8 pf_path_sig_c1 = 2;
__declspec(export) const pf_u16 pf_path_sig_z0 = 0;
pf_u32 PFPATH_CheckExtShortName(PF_STR* p_str, pf_u32 target, pf_bool wildcard) {
pf_u32 result = 0;
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] = pf_path_sig_c0;
sig[1] = pf_path_sig_c1;
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)) ||
@@ -1071,15 +1081,21 @@ pf_u32 PFPATH_CheckExtShortName(PF_STR* p_str, pf_u32 target, pf_bool wildcard)
return result;
}
__declspec(section ".sdata2") pf_s8 pf_path_idx_sig0 = 1;
__declspec(section ".sdata2") pf_s8 pf_path_idx_sig1 = 2;
__declspec(export) const pf_u16 pf_path_sig_z1 = 0;
pf_u32 PFPATH_GetExtShortNameIndex(PF_STR* p_str, pf_u32* p_index) {
pf_bool result = PF_FALSE;
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] = pf_path_idx_sig0;
sig[1] = pf_path_idx_sig1;
if (PFSTR_StrNCmp(p_str, sig, 1, 0, 2) == 0) {
index = 0;

View File

@@ -224,8 +224,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};
static s8 default_volume_label[16] = "NO NAME ";
__declspec(section ".sdata2") u8 deleted_entry_mark[8] = {0xE5};
extern s32 PFDRV_mount(PFVOL_VOLUME* volume);
extern s32 PFDRV_unmount(PFVOL_VOLUME* volume, u32 mode);
extern s32 PFDRV_format(PFVOL_VOLUME* volume, const u8* format_options);
@@ -1052,8 +1052,21 @@ static inline s32 initialize_volume_cache(PFVOL_VOLUME* volume, PFVOL_DRIVER* dr
}
static inline s32 attach_mount(PFVOL_VOLUME* volume, PFVOL_DRIVER* driver) {
s32 error = clear_mount(volume);
if (error != 0) { pf_vol_set.last_error = error; volume->last_error = error; return error; }
s32 error;
if ((volume->flags & 8) == 0) {
s32 result = PFVOL_DoMountVolume(volume);
if (result != 0) {
error = result;
goto done;
}
volume->fsi_flag &= ~7;
PFDRV_ClearUnmountRequested(volume);
pf_vol_set.num_mounted_volumes++;
}
PFDRV_ClearMountRequested(volume);
error = 0;
done:
if (error != 0) { pf_vol_set.last_error = error; volume->last_error = error; return 0; }
driver->stat |= 2;
return 0;
}
@@ -1472,17 +1485,17 @@ s32 PFVOL_setcode(PFVOL_CHARCODE* code_set) {
s32 PFVOL_regctx(void) {
s32 context_id;
s32 free_context_index;
u32 context_index;
s32 free_context_index;
s32 error;
error = PFSYS_GetCurrentContextID(&context_id);
if (error != 0) { pf_vol_set.last_error = 26; return 26; }
free_context_index = 0;
for (context_index = 1; context_index < 4; context_index++) {
u32 stat;
stat = pf_vol_set.context[context_index - 1].stat & 1;
if (stat != 0 && pf_vol_set.context[context_index - 1].context_id == context_id) { break; }
if (stat == 0 && free_context_index == 0) { free_context_index = context_index; }
if ((pf_vol_set.context[context_index - 1].stat & 1) != 0 &&
pf_vol_set.context[context_index - 1].context_id == context_id) { break; }
if ((pf_vol_set.context[context_index - 1].stat & 1) == 0 && free_context_index == 0) { free_context_index = context_index; }
}
if (context_index == 4) {
if (free_context_index != 0) {