Compare commits
1 Commits
cleanup/ip
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7313f9f43 |
@@ -53,9 +53,9 @@ Progress
|
||||
<!-- progress:start -->
|
||||
| Decompiled | Matched | Linked | Data |
|
||||
|:---:|:---:|:---:|:---:|
|
||||
| 88.75% | 78.13% | 56.92% | 88.24% |
|
||||
| 88.96% | 79.07% | 56.92% | 88.24% |
|
||||
|
||||
units 752/1027 complete, functions 11441/12563 matched.
|
||||
units 752/1027 complete, functions 11492/12563 matched.
|
||||
|
||||
decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data
|
||||
<!-- progress:end -->
|
||||
|
||||
@@ -102,6 +102,8 @@ typedef struct PFDIR_VOLUME_DIRS {
|
||||
typedef struct PFDIR_GLOBAL_STATE {
|
||||
pf_u8 state_prefix[0x40];
|
||||
pf_s32 last_error;
|
||||
pf_u8 driver_and_code_state[0x1C];
|
||||
pf_u32 setting;
|
||||
} PFDIR_GLOBAL_STATE;
|
||||
|
||||
extern PFDIR_GLOBAL_STATE pf_vol_set;
|
||||
@@ -134,6 +136,26 @@ extern pf_s32 PFVOL_CheckCurrentDir(PF_VOLUME* volume, pf_u32 start_cluster);
|
||||
extern pf_s32 PFENT_RemoveEntry(PF_DIR_ENT* entry, PF_ENT_ITER* iter);
|
||||
extern pf_s32 PFFAT_FreeChain(PFDIR_FFD* ffd, pf_u32 start_cluster, pf_u32 chain_index, pf_u32 size);
|
||||
|
||||
static inline pf_u32 directory_is_open(PF_DIR_ENT* entry) {
|
||||
PFDIR_VOLUME_DIRS* volume = (PFDIR_VOLUME_DIRS*)entry->p_vol;
|
||||
pf_s32 index;
|
||||
PFDIR_SDD* sdd = volume->sdds;
|
||||
for (index = 0; index < 3; index++, sdd++) {
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
entry->p_vol == sdd->dir_entry.p_vol &&
|
||||
entry->entry_sector == sdd->dir_entry.entry_sector &&
|
||||
entry->entry_offset == sdd->dir_entry.entry_offset) { return 1; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern void PFFAT_ResetFFD(PFDIR_FFD*, pf_u32*);
|
||||
static inline pf_s32 release_directory_chain(PFDIR_FFD* ffd, pf_u32 cluster, pf_u32 count) {
|
||||
pf_s32 error = PFFAT_FreeChain(ffd, cluster, -1U, count);
|
||||
if (error != 0) { return error; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_CheckDirIsEmpty(PF_ENT_ITER* iter, pf_u32* is_empty) {
|
||||
pf_u32 start_cluster = *iter->ffd.p_start_cluster;
|
||||
pf_s32 error;
|
||||
@@ -177,8 +199,8 @@ PFDIR_SDD* PFDIR_GetSDD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
pf_s32 i;
|
||||
pf_s32 remaining = 3;
|
||||
|
||||
for (i = 0; remaining != 0; i++, free_candidate++, remaining--) {
|
||||
if ((volume_dirs->sdds[i].stat & 1) == 0 || (volume_dirs->sdds[i].stat & 2) == 0) {
|
||||
for (i = 0; remaining != 0; remaining--) {
|
||||
if ((volume_dirs->sdds[i].stat & 1) == 0 || ((volume_dirs->sdds[i].stat & 1) != 0 && (!volume_dirs->sdds[i].stat & 2) != 0)) {
|
||||
if (first_free_sdd == 0) {
|
||||
first_free_sdd = free_candidate;
|
||||
}
|
||||
@@ -187,6 +209,8 @@ PFDIR_SDD* PFDIR_GetSDD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
entry->entry_offset == volume_dirs->sdds[i].dir_entry.entry_offset) {
|
||||
return &volume_dirs->sdds[i];
|
||||
}
|
||||
free_candidate++;
|
||||
i++;
|
||||
}
|
||||
if (first_free_sdd == 0) {
|
||||
return 0;
|
||||
@@ -198,12 +222,21 @@ PFDIR_SDD* PFDIR_GetSDD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
return first_free_sdd;
|
||||
}
|
||||
|
||||
static inline PFDIR_DIR* unused_directory(PF_VOLUME* volume) {
|
||||
pf_s32 index;
|
||||
for (index = 0; index < 3; index++) {
|
||||
if ((((PFDIR_VOLUME_DIRS*)volume)->udds[index].stat & 1) == 0) {
|
||||
return &((PFDIR_VOLUME_DIRS*)volume)->udds[index];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_DoFsexecOpenDir(PF_DIR_ENT* entry, PF_ENT_ITER* iter, PFDIR_DIR** opened_dir) {
|
||||
PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)entry->p_vol;
|
||||
pf_s32 i;
|
||||
PFDIR_SDD* sdd;
|
||||
PFDIR_DIR* dir;
|
||||
PFDIR_DIR* scan_dir;
|
||||
pf_s32 i;
|
||||
|
||||
*opened_dir = 0;
|
||||
if ((entry->attr & 0x10) == 0) {
|
||||
@@ -213,15 +246,7 @@ pf_s32 PFDIR_DoFsexecOpenDir(PF_DIR_ENT* entry, PF_ENT_ITER* iter, PFDIR_DIR** o
|
||||
if (sdd == 0) {
|
||||
return 0x15;
|
||||
}
|
||||
scan_dir = volume_dirs->udds;
|
||||
for (i = 0; i < 3; i++, scan_dir++) {
|
||||
if ((scan_dir->stat & 1) == 0) {
|
||||
dir = &volume_dirs->udds[i];
|
||||
goto directory_available;
|
||||
}
|
||||
}
|
||||
dir = 0;
|
||||
directory_available:
|
||||
dir = unused_directory((PF_VOLUME*)volume_dirs);
|
||||
if (dir == 0) {
|
||||
return 0x16;
|
||||
}
|
||||
@@ -239,9 +264,9 @@ directory_available:
|
||||
pf_s32 PFDIR_p_opendir(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_DIR** opened_dir) {
|
||||
PF_ENT_ITER iter;
|
||||
PF_DIR_ENT entry;
|
||||
pf_s32 i;
|
||||
PFDIR_SDD* sdd;
|
||||
PFDIR_DIR* dir;
|
||||
pf_s32 i;
|
||||
pf_s32 error;
|
||||
|
||||
if ((PFSTR_StrNCmp(path, (const pf_s8*)"\\", 1, 0, 1) == 0 ||
|
||||
@@ -255,9 +280,6 @@ pf_s32 PFDIR_p_opendir(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_DIR** opened_di
|
||||
} else if (PFSTR_StrNumChar(path, 1) == 2 &&
|
||||
PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0) {
|
||||
error = PFVOL_GetCurrentDir(volume, &entry);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
goto open_directory;
|
||||
} else if (PFSTR_StrNumChar(path, 1) == 3 &&
|
||||
PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0 &&
|
||||
@@ -288,14 +310,7 @@ open_directory:
|
||||
if (sdd == 0) {
|
||||
return 0x15;
|
||||
}
|
||||
for (i = 0; i < 3; i++) {
|
||||
if ((((PFDIR_VOLUME_DIRS*)volume)->udds[i].stat & 1) == 0) {
|
||||
dir = &((PFDIR_VOLUME_DIRS*)volume)->udds[i];
|
||||
goto directory_available;
|
||||
}
|
||||
}
|
||||
dir = 0;
|
||||
directory_available:
|
||||
dir = unused_directory(volume);
|
||||
if (dir == 0) {
|
||||
return 0x16;
|
||||
}
|
||||
@@ -349,17 +364,23 @@ 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 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*);
|
||||
extern pf_u16* pf_w_strcpy(pf_u16*, const pf_u16*);
|
||||
|
||||
pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_dta) {
|
||||
pf_s32 err;
|
||||
PF_STR full_path;
|
||||
PF_STR dirname;
|
||||
PFDIR_STR full_path;
|
||||
PFDIR_STR dirname;
|
||||
pf_u16 dirname_len;
|
||||
PF_ENT_ITER parent_iter;
|
||||
PF_DIR_ENT entry;
|
||||
PF_DIR_ENT parent_entry;
|
||||
PF_ENT_ITER parent_iter;
|
||||
PF_FFD ffd;
|
||||
PFDIR_FFD ffd;
|
||||
PFDIR_FAT_HINT fat_hint;
|
||||
pf_u32 pos;
|
||||
PF_FAT_HINT fat_hint;
|
||||
pf_u32 prev_chain[2];
|
||||
pf_u32 new_sector;
|
||||
|
||||
@@ -368,7 +389,7 @@ pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_
|
||||
err = 0;
|
||||
new_sector = 0;
|
||||
|
||||
err = VFiPFPATH_SplitPath(p_path, &full_path, &dirname);
|
||||
err = PFPATH_SplitPath((PFDIR_STR*)p_path, &full_path, &dirname);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
@@ -383,40 +404,39 @@ pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_
|
||||
if (p_dta != PF_NULL) {
|
||||
p_dta->parent_start_cluster = parent_entry.start_cluster;
|
||||
}
|
||||
VFiPFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster);
|
||||
err = VFiPFENT_findEntry(&ffd, &entry, 0U, &dirname, 0x77U, PF_NULL, PF_NULL);
|
||||
PFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster);
|
||||
err = PFENT_findEntry(&ffd, &entry, 0U, &dirname, 0x77U, PF_NULL, PF_NULL);
|
||||
if (err == 0) {
|
||||
return 8;
|
||||
}
|
||||
if (err != 3) {
|
||||
return err;
|
||||
}
|
||||
dirname_len = VFiPFSTR_StrNumChar(&dirname, 1U);
|
||||
if ((dirname_len > 0xFFU) || ((dirname_len + parent_entry.path_len) > 0x103U)) {
|
||||
return 2;
|
||||
}
|
||||
err = VFiPFENT_InitENT(&entry, &dirname, 0x10U, 1U, &parent_entry, p_vol);
|
||||
dirname_len = PFSTR_StrNumChar(&dirname, 1U);
|
||||
if (dirname_len + parent_entry.path_len > 0x103U) { return 2; }
|
||||
if (dirname_len > 0xFFU) { return 1; }
|
||||
err = VFiPFENT_InitENT(&entry, (PF_STR*)&dirname, 0x10U, 1U, &parent_entry, p_vol);
|
||||
if (err == 0) {
|
||||
VFiPFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster);
|
||||
err = VFiPFENT_allocateEntry(&entry, (entry.num_entry_LFNs + 1), &ffd, prev_chain, PF_NULL, 0x77U, &pos);
|
||||
PFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster);
|
||||
err = VFiPFENT_allocateEntry(&entry, (entry.num_entry_LFNs + 1), (PF_FFD*)&ffd, prev_chain, PF_NULL, 0x77U, &pos);
|
||||
if (err == 0) {
|
||||
entry.start_cluster = 0;
|
||||
VFiPFFAT_InitFFD(&ffd, &fat_hint, p_vol, &entry.start_cluster);
|
||||
err = VFiPFFAT_GetSectorSpecified(&ffd, 0U, 1U, &new_sector);
|
||||
PFFAT_InitFFD(&ffd, &fat_hint, p_vol, &entry.start_cluster);
|
||||
err = PFFAT_GetSectorSpecified(&ffd, 0U, 1U, &new_sector);
|
||||
if (new_sector == -1U) {
|
||||
err = 6;
|
||||
}
|
||||
if (err == 0) {
|
||||
err = VFiPFENT_FillVoidEntryToSectors(p_vol, new_sector, p_vol->bpb.sectors_per_cluster, 1U, &entry, &parent_entry);
|
||||
if (err == 0) {
|
||||
if ((entry.long_name[0] != 0) && ((VFipf_vol_set.setting & 2) == 2)) {
|
||||
if ((entry.long_name[0] != 0) && ((pf_vol_set.setting & 2) == 2)) {
|
||||
VFiPFPATH_AdjustExtShortName(&entry.short_name[0], pos);
|
||||
entry.check_sum = VFiPFENT_CalcCheckSum(&entry);
|
||||
}
|
||||
err = VFiPFENT_UpdateEntry(&entry, prev_chain, 0U);
|
||||
}
|
||||
if (err != 0) {
|
||||
VFiPFFAT_FreeChain(&ffd, entry.start_cluster, -1U, -1U);
|
||||
PFFAT_FreeChain(&ffd, entry.start_cluster, -1U, -1U);
|
||||
} else if (p_dta != PF_NULL) {
|
||||
p_dta->p_file = PF_NULL;
|
||||
p_dta->p_dir = PF_NULL;
|
||||
@@ -428,16 +448,16 @@ pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_
|
||||
p_dta->Date = entry.modify_date;
|
||||
p_dta->FileSize = entry.file_size;
|
||||
p_dta->Attribute = entry.attr;
|
||||
if (VFiPFSTR_GetCodeMode(&dirname) == 1) {
|
||||
VFiPFPATH_SetSearchPattern(p_dta->reg_exp, PF_NULL, &dirname);
|
||||
if (VFiPFSTR_GetCodeMode((PF_STR*)&dirname) == 1) {
|
||||
PFPATH_SetSearchPattern(p_dta->reg_exp, PF_NULL, &dirname);
|
||||
p_dta->status |= 1;
|
||||
} else {
|
||||
VFiPFPATH_SetSearchPattern(p_dta->reg_exp, ((PF_DTAW*)p_dta)->reg_expW, &dirname);
|
||||
PFPATH_SetSearchPattern(p_dta->reg_exp, ((PF_DTAW*)p_dta)->reg_expW, &dirname);
|
||||
p_dta->status |= 2;
|
||||
}
|
||||
VFipf_strcpy(p_dta->FileName, &entry.short_name[0]);
|
||||
pf_strcpy(p_dta->FileName, &entry.short_name[0]);
|
||||
if ((p_dta->status & 2) == 2) {
|
||||
VFiPFPATH_transformInUnicode(((PF_DTAW*)p_dta)->FileNameW, p_dta->FileName);
|
||||
PFPATH_transformInUnicode(((PF_DTAW*)p_dta)->FileNameW, p_dta->FileName);
|
||||
}
|
||||
if (entry.long_name[0] == 0) {
|
||||
p_dta->ordinal = 0;
|
||||
@@ -449,17 +469,17 @@ pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_
|
||||
} else {
|
||||
p_dta->ordinal = 1;
|
||||
p_dta->check_sum = entry.check_sum;
|
||||
if ((VFipf_vol_set.setting & 2) == 2) {
|
||||
VFipf_vol_set.setting &= 0xFFFFFFFC;
|
||||
VFipf_vol_set.setting |= 1;
|
||||
VFiPFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name);
|
||||
VFipf_vol_set.setting &= 0xFFFFFFFC;
|
||||
VFipf_vol_set.setting |= 2;
|
||||
if ((pf_vol_set.setting & 2) == 2) {
|
||||
pf_vol_set.setting &= 0xFFFFFFFC;
|
||||
pf_vol_set.setting |= 1;
|
||||
PFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name);
|
||||
pf_vol_set.setting &= 0xFFFFFFFC;
|
||||
pf_vol_set.setting |= 2;
|
||||
} else {
|
||||
VFiPFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name);
|
||||
PFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name);
|
||||
}
|
||||
if ((p_dta->status & 2) == 2) {
|
||||
VFipf_w_strcpy(((PF_DTAW*)p_dta)->LongNameW, entry.long_name);
|
||||
pf_w_strcpy(((PF_DTAW*)p_dta)->LongNameW, entry.long_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -524,7 +544,7 @@ pf_s32 PFDIR_p_chdir(PF_VOLUME* p_vol, PFDIR_STR* p_path_str) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_chmod(PF_VOLUME* volume, PFDIR_STR* path, pf_u8 attributes) {
|
||||
pf_s32 PFDIR_p_chmod(PF_VOLUME* volume, PFDIR_STR* path, pf_u32 attributes) {
|
||||
PFDIR_STR directory_path;
|
||||
PFDIR_STR filename;
|
||||
PF_ENT_ITER iter;
|
||||
@@ -544,52 +564,50 @@ pf_s32 PFDIR_p_chmod(PF_VOLUME* volume, PFDIR_STR* path, pf_u8 attributes) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (((entry.attr & 0x10) == 0 && (attributes & 0x10) != 0) ||
|
||||
((entry.attr & 0x10) != 0 && (attributes & 0x10) == 0)) {
|
||||
if (((entry.attr & 0x10) != 0 && (attributes & 0x10) == 0) ||
|
||||
((entry.attr & 0x10) == 0 && (attributes & 0x10) != 0)) {
|
||||
return 10;
|
||||
}
|
||||
if ((attributes & 0x40) != 0) {
|
||||
attributes &= (pf_u8)~0x40;
|
||||
attributes = (pf_u8)(attributes & ~0x40);
|
||||
}
|
||||
if ((entry.attr & 0x10) == 0) {
|
||||
if (PFFILE_IsOpened(&entry) != 0) {
|
||||
return 0x13;
|
||||
}
|
||||
} else {
|
||||
if ((entry.attr & 0x10) != 0) {
|
||||
volume_dirs = (PFDIR_VOLUME_DIRS*)volume;
|
||||
for (i = 0; i < 3; i++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[i];
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
entry.p_vol == sdd->dir_entry.p_vol &&
|
||||
entry.entry_sector == sdd->dir_entry.entry_sector &&
|
||||
entry.entry_offset == sdd->dir_entry.entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
if ((attributes & 4) != 0 && (attributes & 0xF) != 0xF) {
|
||||
if (directory_is_open(&entry) != 0) { return 0x13; }
|
||||
|
||||
if ((attributes & 4) != 0 && (pf_s32)(attributes & 0xF) != 0xF) {
|
||||
return 10;
|
||||
}
|
||||
attributes |= 0x10;
|
||||
entry.attr = attributes;
|
||||
} else {
|
||||
if (PFFILE_IsOpened(&entry) != 0) {
|
||||
return 0x13;
|
||||
}
|
||||
entry.attr = attributes;
|
||||
}
|
||||
create_time_ms = PFENT_getcurrentDateTimeForEnt(&date, &time);
|
||||
entry.modify_date = date;
|
||||
entry.modify_time = time;
|
||||
entry.create_time_ms = create_time_ms;
|
||||
entry.attr = attributes;
|
||||
return PFENT_updateEntry(&entry, 0);
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.access_date, &time);
|
||||
if (entry.file_size == 0 && (entry.attr & 0x10) == 0) { entry.start_cluster = 0; }
|
||||
error = PFENT_updateEntry(&entry, 0);
|
||||
if (error != 0) { return error; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_rmdir(PF_VOLUME* volume, PFDIR_STR* path) {
|
||||
PFDIR_VOLUME_DIRS* volume_dirs;
|
||||
PFDIR_STR directory_path;
|
||||
PFDIR_STR filename;
|
||||
PFDIR_FAT_HINT saved_hint;
|
||||
PFDIR_FAT_HINT hint;
|
||||
PFDIR_FFD ffd;
|
||||
PF_ENT_ITER iter;
|
||||
PF_ENT_ITER directory_iter;
|
||||
PF_DIR_ENT entry;
|
||||
pf_u32 is_empty;
|
||||
pf_u32 is_empty = 0;
|
||||
pf_u32 i;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFPATH_SplitPath(path, &directory_path, &filename);
|
||||
if (error != 0) { return error; }
|
||||
error = PFENT_ITER_GetEntryOfPath(&iter, &entry, volume, path, 0);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -597,30 +615,19 @@ pf_s32 PFDIR_p_rmdir(PF_VOLUME* volume, PFDIR_STR* path) {
|
||||
if ((entry.attr & 0x10) == 0 || (entry.attr & 1) != 0) {
|
||||
return 0x14;
|
||||
}
|
||||
if (entry.start_cluster == 1 ||
|
||||
(volume->bpb.fat_type == FAT_32 && entry.start_cluster == volume->bpb.root_dir_cluster)) {
|
||||
return 0x1C;
|
||||
}
|
||||
volume_dirs = (PFDIR_VOLUME_DIRS*)volume;
|
||||
for (i = 0; i < 3; i++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[i];
|
||||
if ((sdd->stat & 3) == 3 && entry.p_vol == sdd->dir_entry.p_vol &&
|
||||
entry.entry_sector == sdd->dir_entry.entry_sector &&
|
||||
entry.entry_offset == sdd->dir_entry.entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
directory_iter = iter;
|
||||
saved_hint = *iter.ffd.p_hint;
|
||||
if (directory_is_open(&entry) != 0) { return 0x13; }
|
||||
|
||||
error = PFVOL_CheckCurrentDir(volume, entry.start_cluster);
|
||||
if (error != 0) {
|
||||
return 0x1C;
|
||||
}
|
||||
if (error != 0 || entry.start_cluster == 1 ||
|
||||
(volume->bpb.fat_type == FAT_32 && entry.start_cluster == volume->bpb.root_dir_cluster)) { return 0x1C; }
|
||||
PFFAT_InitFFD(&ffd, &hint, volume, &entry.start_cluster);
|
||||
directory_iter.ffd = ffd;
|
||||
error = PFENT_ITER_IteratorInitialize(&directory_iter, 0);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
is_empty = 0;
|
||||
error = PFDIR_CheckDirIsEmpty(&directory_iter, &is_empty);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -628,18 +635,20 @@ pf_s32 PFDIR_p_rmdir(PF_VOLUME* volume, PFDIR_STR* path) {
|
||||
if (is_empty == 0) {
|
||||
return 0x1D;
|
||||
}
|
||||
iter = directory_iter;
|
||||
iter.ffd.p_hint = &saved_hint;
|
||||
error = PFENT_RemoveEntry(&entry, &iter);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
return PFFAT_FreeChain(&iter.ffd, entry.start_cluster, -1U, -1U);
|
||||
return release_directory_chain(&iter.ffd, entry.start_cluster, -1U);
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_fstat(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_FILE_STAT* file_stat) {
|
||||
PF_ENT_ITER iter;
|
||||
PF_DIR_ENT entry;
|
||||
PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)volume;
|
||||
pf_u32 index;
|
||||
pf_s32 index = 0;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFENT_ITER_GetEntryOfPath(&iter, &entry, volume, path, 0);
|
||||
@@ -648,32 +657,32 @@ pf_s32 PFDIR_p_fstat(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_FILE_STAT* file_s
|
||||
}
|
||||
if (volume_dirs->num_opened_files != 0) {
|
||||
for (index = 0; index < 5; index++) {
|
||||
PFDIR_SFD* sfd = &volume_dirs->sfds[index];
|
||||
if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 &&
|
||||
entry.p_vol == sfd->dir_entry.p_vol &&
|
||||
entry.entry_sector == sfd->dir_entry.entry_sector &&
|
||||
entry.entry_offset == sfd->dir_entry.entry_offset) {
|
||||
file_stat->file_size = sfd->dir_entry.file_size;
|
||||
file_stat->access_date = sfd->dir_entry.access_date;
|
||||
file_stat->modify_time = sfd->dir_entry.modify_time;
|
||||
file_stat->modify_date = sfd->dir_entry.modify_date;
|
||||
file_stat->create_time = sfd->dir_entry.create_time;
|
||||
file_stat->create_date = sfd->dir_entry.create_date;
|
||||
file_stat->small_letter_flag = sfd->dir_entry.small_letter_flag;
|
||||
file_stat->attributes = sfd->dir_entry.attr;
|
||||
if ((volume_dirs->sfds[index].stat & 1) != 0 && (volume_dirs->sfds[index].stat & 2) != 0 &&
|
||||
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) {
|
||||
file_stat->file_size = volume_dirs->sfds[index].dir_entry.file_size;
|
||||
file_stat->attributes = volume_dirs->sfds[index].dir_entry.attr;
|
||||
file_stat->modify_time = volume_dirs->sfds[index].dir_entry.modify_time;
|
||||
file_stat->modify_date = volume_dirs->sfds[index].dir_entry.modify_date;
|
||||
file_stat->access_date = volume_dirs->sfds[index].dir_entry.access_date;
|
||||
file_stat->create_time = volume_dirs->sfds[index].dir_entry.create_time;
|
||||
file_stat->create_date = volume_dirs->sfds[index].dir_entry.create_date;
|
||||
file_stat->small_letter_flag = volume_dirs->sfds[index].dir_entry.create_time_ms;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (volume_dirs->num_opened_files == 0 || index == 5) {
|
||||
file_stat->file_size = (entry.attr & 0x10) == 0 ? entry.file_size : 0;
|
||||
file_stat->access_date = entry.access_date;
|
||||
if ((entry.attr & 0x10) != 0) { file_stat->file_size = 0; }
|
||||
else { file_stat->file_size = entry.file_size; }
|
||||
file_stat->attributes = entry.attr;
|
||||
file_stat->modify_time = entry.modify_time;
|
||||
file_stat->modify_date = entry.modify_date;
|
||||
file_stat->access_date = entry.access_date;
|
||||
file_stat->create_time = entry.create_time;
|
||||
file_stat->create_date = entry.create_date;
|
||||
file_stat->small_letter_flag = entry.small_letter_flag;
|
||||
file_stat->attributes = entry.attr;
|
||||
file_stat->small_letter_flag = entry.create_time_ms;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -721,14 +730,18 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
PFDIR_STR destination_directory;
|
||||
PFDIR_STR destination_name;
|
||||
pf_s8 normalized_name[512];
|
||||
pf_u32 code_mode;
|
||||
const pf_s8* name;
|
||||
pf_u32 entry_position;
|
||||
pf_u16 filename_length;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFPATH_SplitPath((PFDIR_STR*)old_path, &source_directory, &source_name);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
filename_length = PFSTR_StrNumChar(&source_name, 1);
|
||||
if (filename_length > 0xFF) { return 1; }
|
||||
if (PFSTR_GetCodeMode(&source_name) == 2) {
|
||||
if (PFSTR_StrNumChar(&source_name, 1) > 0xFF) {
|
||||
return 1;
|
||||
@@ -755,7 +768,7 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (entry_position == 0) {
|
||||
if (entry_position == 999999) {
|
||||
return 3;
|
||||
}
|
||||
if ((source_entry.attr & 0x10) != 0) {
|
||||
@@ -784,7 +797,7 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
if (source_iter.ffd.start_cluster != destination_parent.start_cluster) {
|
||||
return 0x1F;
|
||||
}
|
||||
if (PFSTR_GetCodeMode(&destination_name) == 2) {
|
||||
if ((code_mode = PFSTR_GetCodeMode(&destination_name)) == 2) {
|
||||
if (PFSTR_StrNumChar(&destination_name, 1) > 0xFF) {
|
||||
return 1;
|
||||
}
|
||||
@@ -822,8 +835,10 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
PFDIR_STR destination_name;
|
||||
PFDIR_VOLUME_DIRS* volume_dirs;
|
||||
pf_s8 normalized_name[512];
|
||||
pf_u32 code_mode;
|
||||
pf_u32 entry_position;
|
||||
pf_u32 index;
|
||||
pf_u16 filename_length;
|
||||
pf_s32 index = 0;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume,
|
||||
@@ -839,7 +854,9 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (PFSTR_GetCodeMode(&destination_name) == 2) {
|
||||
filename_length = PFSTR_StrNumChar(&destination_name, 1);
|
||||
if (filename_length > 0xFF) { return 1; }
|
||||
if ((code_mode = PFSTR_GetCodeMode(&destination_name)) == 2) {
|
||||
if (PFSTR_StrNumChar(&destination_name, 1) > 0xFF) {
|
||||
return 1;
|
||||
}
|
||||
@@ -869,15 +886,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
source_entry.start_cluster == volume->bpb.root_dir_cluster)) {
|
||||
return 0x1C;
|
||||
}
|
||||
for (index = 0; index < 3; index++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[index];
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
sdd->dir_entry.p_vol == source_entry.p_vol &&
|
||||
sdd->dir_entry.entry_sector == source_entry.entry_sector &&
|
||||
sdd->dir_entry.entry_offset == source_entry.entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
if (directory_is_open(&source_entry) != 0) { return 0x13; }
|
||||
} else if (PFFILE_IsOpened(&source_entry) != 0) {
|
||||
return 0x13;
|
||||
}
|
||||
@@ -908,9 +917,10 @@ pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter)
|
||||
PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)entry->p_vol;
|
||||
PFDIR_FAT_HINT hint;
|
||||
PF_ENT_ITER directory_iter;
|
||||
pf_u32 is_empty;
|
||||
pf_u32 index;
|
||||
pf_u32 start_cluster = entry->start_cluster;
|
||||
pf_u32 is_empty = 0;
|
||||
pf_s32 index = 0;
|
||||
pf_u32 start_cluster;
|
||||
pf_u32 chain_size;
|
||||
pf_s32 error;
|
||||
|
||||
if ((entry->attr & 1) != 0) {
|
||||
@@ -922,32 +932,30 @@ pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter)
|
||||
entry->start_cluster == entry->p_vol->bpb.root_dir_cluster)) {
|
||||
return 0x1C;
|
||||
}
|
||||
for (index = 0; index < 3; index++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[index];
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
sdd->dir_entry.p_vol == entry->p_vol &&
|
||||
sdd->dir_entry.entry_sector == entry->entry_sector &&
|
||||
sdd->dir_entry.entry_offset == entry->entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
if (directory_is_open(entry) != 0) { return 0x13; }
|
||||
|
||||
directory_iter = *iter;
|
||||
PFFAT_InitFFD(&directory_iter.ffd, &hint, entry->p_vol, &entry->start_cluster);
|
||||
error = PFENT_ITER_IteratorInitialize(&directory_iter, 0);
|
||||
hint = *iter->ffd.p_hint;
|
||||
PFFAT_ResetFFD(&iter->ffd, &entry->start_cluster);
|
||||
error = PFENT_ITER_IteratorInitialize(iter, 0);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
is_empty = 0;
|
||||
error = PFDIR_CheckDirIsEmpty(&directory_iter, &is_empty);
|
||||
error = PFDIR_CheckDirIsEmpty(iter, &is_empty);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (is_empty == 0) {
|
||||
return 0x1D;
|
||||
}
|
||||
} else if (PFFILE_IsOpened(entry) != 0) {
|
||||
return 0x13;
|
||||
*iter = directory_iter;
|
||||
iter->ffd.p_hint = &hint;
|
||||
chain_size = -1U;
|
||||
} else {
|
||||
if (PFFILE_IsOpened(entry) != 0) { return 0x13; }
|
||||
chain_size = entry->file_size;
|
||||
}
|
||||
start_cluster = entry->start_cluster;
|
||||
entry->num_entry_LFNs = data->num_entry_LFNs;
|
||||
entry->ordinal = data->ordinal;
|
||||
entry->check_sum = data->check_sum;
|
||||
@@ -955,21 +963,29 @@ pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter)
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
return PFFAT_FreeChain(&iter->ffd, start_cluster, -1U, -1U);
|
||||
return release_directory_chain(&iter->ffd, start_cluster, chain_size);
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 attributes, pf_u32 mode) {
|
||||
|
||||
pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 mode, pf_u32 attributes) {
|
||||
PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)entry->p_vol;
|
||||
pf_u16 date;
|
||||
pf_u16 time;
|
||||
pf_u8 create_time_ms;
|
||||
pf_u32 index;
|
||||
pf_s32 index = 0;
|
||||
pf_s32 error;
|
||||
|
||||
if ((attributes & 0x40) != 0) {
|
||||
attributes &= ~0x40;
|
||||
attributes = (pf_u8)(attributes & ~0x40);
|
||||
}
|
||||
if ((entry->attr & 0x10) == 0) {
|
||||
if ((entry->attr & 0x10) != 0) {
|
||||
if ((attributes & 4) != 0) {
|
||||
return 10;
|
||||
}
|
||||
if (directory_is_open(entry) != 0) { return 0x13; }
|
||||
|
||||
entry->attr = attributes | 0x10;
|
||||
} else {
|
||||
if ((attributes & 0x10) != 0) {
|
||||
return 10;
|
||||
}
|
||||
@@ -977,25 +993,8 @@ pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 attributes,
|
||||
return 0x13;
|
||||
}
|
||||
entry->attr = attributes;
|
||||
} else {
|
||||
if ((attributes & 4) != 0) {
|
||||
return 10;
|
||||
}
|
||||
for (index = 0; index < 3; index++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[index];
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
sdd->dir_entry.p_vol == entry->p_vol &&
|
||||
sdd->dir_entry.entry_sector == entry->entry_sector &&
|
||||
sdd->dir_entry.entry_offset == entry->entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
entry->attr = attributes | 0x10;
|
||||
}
|
||||
create_time_ms = PFENT_getcurrentDateTimeForEnt(&date, &time);
|
||||
entry->modify_date = date;
|
||||
entry->modify_time = time;
|
||||
entry->create_time_ms = create_time_ms;
|
||||
PFENT_getcurrentDateTimeForEnt(&entry->access_date, &time);
|
||||
error = PFENT_updateEntry(entry, 0);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -1003,7 +1002,9 @@ pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 attributes,
|
||||
if ((mode & 0x80000000) == 0) {
|
||||
data->Attribute = entry->attr;
|
||||
}
|
||||
return PFCACHE_FlushDataCacheSpecific(entry->p_vol, 0);
|
||||
error = PFCACHE_FlushDataCacheSpecific(entry->p_vol, 0);
|
||||
if (error != 0) { return error; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_fsexec_fopen(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32 flags,
|
||||
@@ -1062,9 +1063,9 @@ pf_s32 PFDIR_p_fsexec_opendir(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) {
|
||||
PF_ENT_ITER iter;
|
||||
PFDIR_FFD ffd;
|
||||
PFDIR_FAT_HINT hint;
|
||||
PF_ENT_ITER iter;
|
||||
PF_DIR_ENT entry;
|
||||
PFDIR_STR pattern;
|
||||
pf_u32 logical_position;
|
||||
@@ -1074,32 +1075,34 @@ pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) {
|
||||
const pf_s8* name;
|
||||
pf_s32 error;
|
||||
|
||||
if ((flags & 0x26) == 0 && (flags & 1) == 0) {
|
||||
if ((flags & 6) == 0 && (flags & 1) == 0 && (flags & 0x10) == 0 && (flags & 0x20) == 0) {
|
||||
return 10;
|
||||
}
|
||||
if ((flags & 0x26) != 0 || (flags & 1) != 0 || ((flags & 0x10) != 0 && mode != 2)) {
|
||||
if ((flags & 6) != 0 || (flags & 1) != 0 || ((flags & 0x10) != 0 && mode != 2)) {
|
||||
error = PFVOL_CheckForWrite(data->p_vol);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
entry.start_cluster = data->parent_start_cluster;
|
||||
entry.check_sum = 0;
|
||||
PFFAT_InitFFD(&ffd, &hint, data->p_vol, &entry.start_cluster);
|
||||
iter.p_vol = data->p_vol;
|
||||
iter.ffd = ffd;
|
||||
start_position = data->parent_pos - 1;
|
||||
if ((flags & 0x80000000) == 0) {
|
||||
start_position -= data->num_entry_LFNs;
|
||||
}
|
||||
PFFAT_InitFFD(&ffd, &hint, data->p_vol, &data->parent_start_cluster);
|
||||
iter.p_vol = data->p_vol;
|
||||
iter.ffd = ffd;
|
||||
error = PFENT_ITER_IteratorInitialize(&iter, start_position);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if ((data->status & 1) != 0) {
|
||||
if ((data->status & 1) == 1) {
|
||||
code_mode = 1;
|
||||
name = data->FileName;
|
||||
} else {
|
||||
code_mode = 2;
|
||||
if ((VFipf_vol_set.setting & 2) != 0) {
|
||||
if ((pf_vol_set.setting & 2) != 0) {
|
||||
name = (const pf_s8*)((PF_DTAW*)data)->LongNameW;
|
||||
} else {
|
||||
name = (const pf_s8*)((PF_DTAW*)data)->FileNameW;
|
||||
@@ -1109,7 +1112,7 @@ pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if ((VFipf_vol_set.setting & 2) != 0) {
|
||||
if ((pf_vol_set.setting & 2) != 0) {
|
||||
PFSTR_SetLocalStr(&pattern, (pf_u32)data->LongName);
|
||||
} else {
|
||||
PFSTR_SetLocalStr(&pattern, (pf_u32)data->FileName);
|
||||
@@ -1137,7 +1140,7 @@ pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) {
|
||||
return error;
|
||||
}
|
||||
if ((flags & 6) != 0) {
|
||||
return PFDIR_p_fsexec_chmod(data, &entry, flags, mode);
|
||||
return PFDIR_p_fsexec_chmod(data, &entry, mode, flags);
|
||||
}
|
||||
if ((flags & 1) != 0) {
|
||||
return PFDIR_p_fsexec_remove(data, &entry, &iter);
|
||||
@@ -1316,7 +1319,7 @@ void PFDIR_opendir(PF_STR* path, PFDIR_DIR** dir) {
|
||||
pf_vol_set.last_error = error;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
} else {
|
||||
((PFDIR_VOLUME_DIRS*)volume)->num_opened_directories++;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->num_opened_directories += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1507,9 +1510,15 @@ pf_s32 PFDIR_chdir(PF_STR* path) {
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
return error;
|
||||
} else {
|
||||
PFVOL_SetCurrentVolume(volume);
|
||||
}
|
||||
PFVOL_SetCurrentVolume(volume);
|
||||
return error;
|
||||
}
|
||||
|
||||
static inline pf_s32 set_directory_context(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
pf_s32 error = PFVOL_SetCurrentDir(volume, entry);
|
||||
if (error != 0) { return error; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1528,14 +1537,14 @@ pf_s32 PFDIR_fchdir(PFDIR_DIR* dir) {
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
return error;
|
||||
}
|
||||
error = PFVOL_SetCurrentDir(volume, &dir->p_sdd->dir_entry);
|
||||
error = set_directory_context(volume, &dir->p_sdd->dir_entry);
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
return error;
|
||||
} else {
|
||||
PFVOL_SetCurrentVolume(volume);
|
||||
}
|
||||
PFVOL_SetCurrentVolume(volume);
|
||||
return 0;
|
||||
return error;
|
||||
}
|
||||
|
||||
void PFDIR_chmod(PF_STR* path, pf_u8 attributes) {
|
||||
@@ -1580,7 +1589,7 @@ void PFDIR_chdmod(PF_STR* path, pf_u8 attributes) {
|
||||
return;
|
||||
}
|
||||
volume_dirs->cache_signature = 0;
|
||||
error = PFDIR_p_chmod(volume, (PFDIR_STR*)path, attributes | 0x10);
|
||||
error = PFDIR_p_chmod(volume, (PFDIR_STR*)path, (pf_u8)(attributes | 0x10));
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
@@ -1608,7 +1617,7 @@ pf_s32 PFDIR_p_fsnext(PF_DTA* data) {
|
||||
pf_u32 logical_position = 0;
|
||||
pf_u32 entry_position = 0;
|
||||
pf_u32 code_mode;
|
||||
pf_u32 index;
|
||||
pf_s32 index = 0;
|
||||
pf_s32 error;
|
||||
|
||||
if ((data->status & 1) == 1) {
|
||||
@@ -1621,63 +1630,55 @@ pf_s32 PFDIR_p_fsnext(PF_DTA* data) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
PFSTR_SetLocalStr(&pattern, 0);
|
||||
if (entry_position < 0xF423F) {
|
||||
if (data->parent_pos > 0xF423E) {
|
||||
return 10;
|
||||
}
|
||||
ffd.start_cluster = data->parent_start_cluster;
|
||||
PFFAT_InitFFD(&ffd, &hint, data->p_vol, &ffd.start_cluster);
|
||||
PFSTR_SetLocalStr(&pattern, (pf_u32)data->reg_exp);
|
||||
while (entry_position < 999999) {
|
||||
if (data->parent_pos >= 999999) { return 10; }
|
||||
entry.start_cluster = data->parent_start_cluster;
|
||||
PFFAT_InitFFD(&ffd, &hint, data->p_vol, &entry.start_cluster);
|
||||
error = PFENT_findEntryPos(&ffd, &entry, data->parent_pos, &pattern, data->attr, 0,
|
||||
&logical_position, &entry_position);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (error != 0) { return error; }
|
||||
data->parent_pos = entry_position + 1;
|
||||
if (entry_position == 0xF423F) {
|
||||
return 3;
|
||||
}
|
||||
if (entry_position == 999999) { return 3; }
|
||||
}
|
||||
pf_strcpy(data->FileName, entry.short_name);
|
||||
if ((data->status & 2) == 2) {
|
||||
PFPATH_transformInUnicode(((PF_DTAW*)data)->FileNameW, data->FileName);
|
||||
}
|
||||
if (entry.long_name[0] == 0) {
|
||||
data->LongName[0] = 0;
|
||||
if ((data->status & 2) == 2) {
|
||||
((PF_DTAW*)data)->LongNameW[0] = 0;
|
||||
}
|
||||
} else {
|
||||
if ((VFipf_vol_set.setting & 2) == 2) {
|
||||
VFipf_vol_set.setting &= 0xFFFFFFFC;
|
||||
VFipf_vol_set.setting |= 1;
|
||||
if (entry.long_name[0] != 0) {
|
||||
if ((pf_vol_set.setting & 2) == 2) {
|
||||
pf_vol_set.setting &= 0xFFFFFFFC;
|
||||
pf_vol_set.setting |= 1;
|
||||
PFPATH_transformFromUnicodeToNormal(data->LongName, entry.long_name);
|
||||
VFipf_vol_set.setting &= 0xFFFFFFFC;
|
||||
VFipf_vol_set.setting |= 2;
|
||||
pf_vol_set.setting &= 0xFFFFFFFC;
|
||||
pf_vol_set.setting |= 2;
|
||||
} else {
|
||||
PFPATH_transformFromUnicodeToNormal(data->LongName, entry.long_name);
|
||||
}
|
||||
if ((data->status & 2) == 2) {
|
||||
pf_w_strcpy(((PF_DTAW*)data)->LongNameW, entry.long_name);
|
||||
}
|
||||
} else {
|
||||
data->LongName[0] = 0;
|
||||
if ((data->status & 2) == 2) {
|
||||
((PF_DTAW*)data)->LongNameW[0] = 0;
|
||||
}
|
||||
}
|
||||
if (((PFDIR_VOLUME_DIRS*)data->p_vol)->num_opened_files != 0) {
|
||||
PFDIR_SFD* sfd = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds;
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 &&
|
||||
sfd->dir_entry.p_vol == entry.p_vol &&
|
||||
sfd->dir_entry.entry_sector == entry.entry_sector &&
|
||||
sfd->dir_entry.entry_offset == entry.entry_offset) {
|
||||
data->FileSize = sfd->dir_entry.file_size;
|
||||
data->Time = sfd->dir_entry.modify_time;
|
||||
data->Date = sfd->dir_entry.modify_date;
|
||||
data->Attribute = sfd->dir_entry.attr;
|
||||
data->num_entry_LFNs = sfd->dir_entry.num_entry_LFNs;
|
||||
data->ordinal = sfd->dir_entry.ordinal;
|
||||
data->check_sum = sfd->dir_entry.check_sum;
|
||||
if ((((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].stat & 1) != 0 && (((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].stat & 2) != 0 &&
|
||||
entry.p_vol == ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.p_vol &&
|
||||
((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.entry_sector == entry.entry_sector &&
|
||||
((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.entry_offset == entry.entry_offset) {
|
||||
data->FileSize = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.file_size;
|
||||
data->Time = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.modify_time;
|
||||
data->Date = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.modify_date;
|
||||
data->Attribute = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.attr;
|
||||
data->num_entry_LFNs = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.num_entry_LFNs;
|
||||
data->ordinal = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.ordinal;
|
||||
data->check_sum = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.check_sum;
|
||||
break;
|
||||
}
|
||||
sfd++;
|
||||
}
|
||||
}
|
||||
if (((PFDIR_VOLUME_DIRS*)data->p_vol)->num_opened_files == 0 || index == 5) {
|
||||
|
||||
@@ -358,8 +358,8 @@ s32 PFFAT_FindClusterLink(PFFAT_FFD* file, u32 chainIndex, u32* cluster,
|
||||
u32 nextCluster;
|
||||
s32 error;
|
||||
|
||||
*found = 0;
|
||||
nextCluster = -1;
|
||||
*found = 0;
|
||||
if (file->cluster_link.position == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -388,6 +388,7 @@ s32 PFFAT_FindClusterLink(PFFAT_FFD* file, u32 chainIndex, u32* cluster,
|
||||
&nextCluster);
|
||||
break;
|
||||
default:
|
||||
nextCluster = -1;
|
||||
error = 15;
|
||||
break;
|
||||
}
|
||||
@@ -486,6 +487,7 @@ s32 PFFAT_ReadCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
u32* nextCluster, u32* checkClusterLink)
|
||||
{
|
||||
s32 error;
|
||||
u32 value;
|
||||
|
||||
*nextCluster = -1;
|
||||
if (file->cluster_link.buffer != 0 && *checkClusterLink == 1) {
|
||||
@@ -515,22 +517,22 @@ s32 PFFAT_ReadCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (*nextCluster == 0) {
|
||||
value = *nextCluster;
|
||||
if (value == 0) {
|
||||
return 13;
|
||||
}
|
||||
if (*nextCluster == -1) {
|
||||
if (value == -1) {
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
if (file->cluster_link.buffer != 0 &&
|
||||
*nextCluster != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
|
||||
if (file->cluster_link.buffer != 0 &&
|
||||
value != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
|
||||
if (file->cluster_link.max_count > file->cluster_link.position &&
|
||||
file->cluster_link.max_count != 0) {
|
||||
if (chainIndex == file->cluster_link.position *
|
||||
(file->cluster_link.interval + 1)) {
|
||||
file->cluster_link.interval_offset = 0;
|
||||
file->cluster_link.buffer[file->cluster_link.position] =
|
||||
*nextCluster;
|
||||
value;
|
||||
file->cluster_link.position++;
|
||||
} else {
|
||||
file->cluster_link.interval_offset++;
|
||||
@@ -538,6 +540,7 @@ s32 PFFAT_ReadCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
file->cluster_link.save_index = chainIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -546,6 +549,7 @@ s32 PFFAT_ReadClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
PF_CACHE_PAGE* page)
|
||||
{
|
||||
s32 error;
|
||||
u32 value;
|
||||
|
||||
*nextCluster = -1;
|
||||
if (file->cluster_link.buffer != 0 && *checkClusterLink == 1) {
|
||||
@@ -576,22 +580,22 @@ s32 PFFAT_ReadClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (*nextCluster == 0) {
|
||||
value = *nextCluster;
|
||||
if (value == 0) {
|
||||
return 13;
|
||||
}
|
||||
if (*nextCluster == -1) {
|
||||
if (value == -1) {
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
if (file->cluster_link.buffer != 0 &&
|
||||
*nextCluster != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
|
||||
if (file->cluster_link.buffer != 0 &&
|
||||
value != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
|
||||
if (file->cluster_link.max_count > file->cluster_link.position &&
|
||||
file->cluster_link.max_count != 0) {
|
||||
if (chainIndex == file->cluster_link.position *
|
||||
(file->cluster_link.interval + 1)) {
|
||||
file->cluster_link.interval_offset = 0;
|
||||
file->cluster_link.buffer[file->cluster_link.position] =
|
||||
*nextCluster;
|
||||
value;
|
||||
file->cluster_link.position++;
|
||||
} else {
|
||||
file->cluster_link.interval_offset++;
|
||||
@@ -599,6 +603,7 @@ s32 PFFAT_ReadClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
file->cluster_link.save_index = chainIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -608,6 +613,7 @@ s32 PFFAT_WriteCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
u32 accessCluster;
|
||||
u32 position;
|
||||
u32 divisor;
|
||||
u32* linkBuffer;
|
||||
u32 precedingIndex;
|
||||
s32 error;
|
||||
|
||||
@@ -641,14 +647,15 @@ s32 PFFAT_WriteCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (file->cluster_link.buffer != 0 && useClusterLink == 1) {
|
||||
linkBuffer = file->cluster_link.buffer;
|
||||
if (linkBuffer != 0 && useClusterLink == 1) {
|
||||
if (nextCluster == 0) {
|
||||
divisor = file->cluster_link.interval + 1;
|
||||
position = chainIndex / divisor;
|
||||
|
||||
if (file->cluster_link.max_count >= position) {
|
||||
if (chainIndex % divisor == 0) {
|
||||
file->cluster_link.buffer[position] = 0;
|
||||
linkBuffer[position] = 0;
|
||||
}
|
||||
if (file->cluster_link.save_index >= chainIndex) {
|
||||
precedingIndex = chainIndex - 1;
|
||||
@@ -694,6 +701,7 @@ s32 PFFAT_WriteClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
u32 accessCluster;
|
||||
u32 position;
|
||||
u32 divisor;
|
||||
u32* linkBuffer;
|
||||
u32 precedingIndex;
|
||||
s32 error;
|
||||
|
||||
@@ -729,14 +737,15 @@ s32 PFFAT_WriteClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (file->cluster_link.buffer != 0 && useClusterLink == 1) {
|
||||
linkBuffer = file->cluster_link.buffer;
|
||||
if (linkBuffer != 0 && useClusterLink == 1) {
|
||||
if (nextCluster == 0) {
|
||||
divisor = file->cluster_link.interval + 1;
|
||||
position = chainIndex / divisor;
|
||||
|
||||
if (file->cluster_link.max_count >= position) {
|
||||
if (chainIndex % divisor == 0) {
|
||||
file->cluster_link.buffer[position] = 0;
|
||||
linkBuffer[position] = 0;
|
||||
}
|
||||
if (file->cluster_link.save_index >= chainIndex) {
|
||||
precedingIndex = chainIndex - 1;
|
||||
@@ -1108,14 +1117,25 @@ s32 PFFAT_GetClusterAllocatedInChain(PFFAT_FFD* file, u32 initialCluster,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline s32 find_cluster_in_chain(PFFAT_FFD* file, u32 index, u32 mode, u32 count, u32 useFirst, u32* cluster) {
|
||||
u32 firstCluster;
|
||||
u32 lastCluster;
|
||||
u32 candidate;
|
||||
s32 error = PFFAT_GetClusterInChain(file, index, mode, count, &firstCluster, &lastCluster);
|
||||
if (error != 0) { return error; }
|
||||
candidate = useFirst ? firstCluster : lastCluster;
|
||||
if (candidate >= 2 && candidate < file->p_vol->bpb.num_clusters + 2) { *cluster = candidate; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 PFFAT_GetClusterSpecified(PFFAT_FFD* file, u32 chainIndex,
|
||||
u32 mayAllocate, u32* cluster)
|
||||
{
|
||||
PFFAT_HINT* hint;
|
||||
u32 fatType;
|
||||
u32 found;
|
||||
u32 locateEnd;
|
||||
u32 locateStart;
|
||||
u32 locateEnd;
|
||||
s32 error;
|
||||
|
||||
fatType = file->p_vol->bpb.fat_type;
|
||||
@@ -1144,20 +1164,7 @@ s32 PFFAT_GetClusterSpecified(PFFAT_FFD* file, u32 chainIndex,
|
||||
}
|
||||
}
|
||||
*cluster = -1;
|
||||
error = PFFAT_GetClusterInChain(file, chainIndex, mayAllocate != 0, 0,
|
||||
&locateStart, &locateEnd);
|
||||
if (error == 0) {
|
||||
goto cluster_lookup_succeeded;
|
||||
}
|
||||
goto cluster_lookup_complete;
|
||||
|
||||
cluster_lookup_succeeded:
|
||||
if (locateEnd >= 2 && locateEnd < file->p_vol->bpb.num_clusters + 2) {
|
||||
*cluster = locateEnd;
|
||||
}
|
||||
error = 0;
|
||||
|
||||
cluster_lookup_complete:
|
||||
error = find_cluster_in_chain(file, chainIndex, mayAllocate != 0, 0, 0, cluster);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
@@ -1173,10 +1180,10 @@ cluster_lookup_complete:
|
||||
s32 PFFAT_GetClusterAllocated(PFFAT_FFD* file, u32 chainIndex,
|
||||
u32 numClusters, u32* cluster)
|
||||
{
|
||||
u32 fatType;
|
||||
PFFAT_HINT* hint;
|
||||
u32 locateEnd;
|
||||
u32 fatType;
|
||||
u32 locateStart;
|
||||
u32 locateEnd;
|
||||
s32 error;
|
||||
|
||||
fatType = file->p_vol->bpb.fat_type;
|
||||
@@ -1189,15 +1196,7 @@ s32 PFFAT_GetClusterAllocated(PFFAT_FFD* file, u32 chainIndex,
|
||||
*file->p_start_cluster = file->p_vol->bpb.root_dir_cluster;
|
||||
}
|
||||
*cluster = -1;
|
||||
error = PFFAT_GetClusterInChain(file, chainIndex, 2, numClusters,
|
||||
&locateStart, &locateEnd);
|
||||
if (error == 0) {
|
||||
if (locateStart >= 2 &&
|
||||
locateStart < file->p_vol->bpb.num_clusters + 2) {
|
||||
*cluster = locateStart;
|
||||
}
|
||||
error = 0;
|
||||
}
|
||||
error = find_cluster_in_chain(file, chainIndex, 2, numClusters, 1, cluster);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
@@ -1225,17 +1224,18 @@ s32 PFFAT_GetSector(PFFAT_FFD* file, u32 fileSectorIndex, u32 mode,
|
||||
u32 size, u32* sector)
|
||||
{
|
||||
PF_VOLUME* volume;
|
||||
u32 fatType;
|
||||
u32 chainIndex;
|
||||
u32 cluster;
|
||||
u32 numDivide;
|
||||
u32 numRemainder;
|
||||
u32 numSectors;
|
||||
u32 numDivide;
|
||||
u32 numClusters;
|
||||
u32 numSectors;
|
||||
s32 error;
|
||||
|
||||
volume = file->p_vol;
|
||||
if (*file->p_start_cluster == 1 &&
|
||||
(u32)volume->bpb.fat_type <= FAT_16) {
|
||||
fatType = volume->bpb.fat_type;
|
||||
if (*file->p_start_cluster == 1 && fatType <= FAT_16) {
|
||||
error = PFFAT_GetSectorInRootDirRegion(volume, fileSectorIndex, sector);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -1244,13 +1244,12 @@ s32 PFFAT_GetSector(PFFAT_FFD* file, u32 fileSectorIndex, u32 mode,
|
||||
}
|
||||
chainIndex = fileSectorIndex >> volume->bpb.log2_sectors_per_cluster;
|
||||
if (mode == 2) {
|
||||
numDivide = size / volume->bpb.bytes_per_sector;
|
||||
numRemainder = (size % volume->bpb.bytes_per_sector) != 0;
|
||||
numSectors = numDivide + numRemainder;
|
||||
numSectors = (size / volume->bpb.bytes_per_sector) +
|
||||
((size % volume->bpb.bytes_per_sector) != 0);
|
||||
numDivide = numSectors / volume->bpb.sectors_per_cluster;
|
||||
numRemainder =
|
||||
(numSectors % volume->bpb.sectors_per_cluster) != 0;
|
||||
numClusters = numDivide + numRemainder;
|
||||
numClusters = numRemainder + numDivide;
|
||||
error = PFFAT_GetClusterAllocated(file, chainIndex, numClusters,
|
||||
&cluster);
|
||||
if (error != 0) {
|
||||
@@ -1375,7 +1374,8 @@ s32 PFFAT_CountAllocatedClusters(PFFAT_FFD* file, u32 size,
|
||||
*numAllocatedClusters = file->p_hint->chain_index;
|
||||
cluster = file->p_hint->cluster;
|
||||
chainIndex = file->p_hint->chain_index + 1;
|
||||
size -= file->p_hint->chain_index * bytesPerCluster;
|
||||
size -= file->p_hint->chain_index *
|
||||
(file->p_vol->bpb.bytes_per_sector * file->p_vol->bpb.sectors_per_cluster);
|
||||
} else {
|
||||
cluster = *file->p_start_cluster;
|
||||
chainIndex = 1;
|
||||
@@ -1520,9 +1520,9 @@ s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
|
||||
}
|
||||
if (nextCluster == 0) {
|
||||
s32 firstFlushError;
|
||||
u32 fatSector;
|
||||
u16 fatIndex;
|
||||
PF_CACHE_PAGE* flushPage;
|
||||
u16 fatIndex;
|
||||
u32 fatSector;
|
||||
|
||||
firstFlushError = 0;
|
||||
flushPage = page;
|
||||
@@ -1857,7 +1857,8 @@ s32 PFFAT_RefreshFSINFO(PF_VOLUME* volume)
|
||||
if ((volume->fsi_flag & 4) != 0) {
|
||||
error = PFCACHE_AllocateDataPage(volume, -1, &page,
|
||||
&alreadyAllocated);
|
||||
if (error == 0) {
|
||||
if (error != 0) { goto finished; }
|
||||
{
|
||||
error = PFSEC_ReadData(
|
||||
volume, page->p_buf, volume->bpb.fs_info_sector, 0,
|
||||
volume->bpb.bytes_per_sector, &completedBytes, 0);
|
||||
@@ -1896,6 +1897,7 @@ s32 PFFAT_RefreshFSINFO(PF_VOLUME* volume)
|
||||
PFCACHE_FreeDataPage(volume, page);
|
||||
}
|
||||
}
|
||||
finished:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_dir.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_path.h>
|
||||
@@ -414,16 +415,24 @@ pf_s32 PFFILE_Cursor_Read(PFFILE_FILE* file, pf_u8* buffer, pf_u32 size, pf_u32*
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void advance_write_cursor(PFFILE_FILE* file, pf_u32 size, pf_u32 sector) {
|
||||
PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
pf_u32 position = file->cursor.offset_in_sector + size;
|
||||
pf_u32 next_sector = sector + (position >> volume->bpb.log2_bytes_per_sector);
|
||||
if (((volume->bpb.bytes_per_sector - 1) & position) != 0) { file->cursor.sector = next_sector; }
|
||||
else { file->cursor.sector = -1; }
|
||||
file->cursor.position += size;
|
||||
if (file->cursor.position > file->p_sfd->dir_entry.file_size) {
|
||||
file->p_sfd->dir_entry.file_size = file->cursor.position;
|
||||
}
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
PFCLUSTER_UpdateLastAccessCluster(file, next_sector);
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size,
|
||||
pf_u32* size_written) {
|
||||
pf_s32 error;
|
||||
pf_u32 success_size;
|
||||
pf_u32 next_position;
|
||||
pf_u32 new_position;
|
||||
pf_u32 current_sector;
|
||||
pf_u32 written_size;
|
||||
pf_u32 sector_advance;
|
||||
pf_u32 next_sector;
|
||||
PF_VOLUME* volume;
|
||||
|
||||
*size_written = 0;
|
||||
@@ -452,24 +461,7 @@ pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_
|
||||
return error;
|
||||
}
|
||||
*size_written = success_size;
|
||||
current_sector = file->cursor.sector;
|
||||
written_size = success_size;
|
||||
volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
next_position = file->cursor.offset_in_sector + written_size;
|
||||
sector_advance = next_position >> volume->bpb.log2_bytes_per_sector;
|
||||
next_sector = current_sector + sector_advance;
|
||||
if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) {
|
||||
file->cursor.sector = next_sector;
|
||||
} else {
|
||||
file->cursor.sector = -1;
|
||||
}
|
||||
new_position = file->cursor.position + success_size;
|
||||
file->cursor.position = new_position;
|
||||
if (new_position > file->p_sfd->dir_entry.file_size) {
|
||||
file->p_sfd->dir_entry.file_size = new_position;
|
||||
}
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
PFCLUSTER_UpdateLastAccessCluster(file);
|
||||
advance_write_cursor(file, success_size, file->cursor.sector);
|
||||
if (success_size != size) {
|
||||
return error;
|
||||
}
|
||||
@@ -481,7 +473,6 @@ pf_s32 PFFILE_Cursor_WriteBodySectors(PFFILE_FILE* file, const pf_u8* buffer, pf
|
||||
pf_s32 error;
|
||||
pf_u32 num_sectors;
|
||||
pf_u32 success_size;
|
||||
pf_u32 next_position;
|
||||
PF_VOLUME* volume;
|
||||
|
||||
*size_written = 0;
|
||||
@@ -506,18 +497,7 @@ pf_s32 PFFILE_Cursor_WriteBodySectors(PFFILE_FILE* file, const pf_u8* buffer, pf
|
||||
return error;
|
||||
}
|
||||
*size_written = success_size;
|
||||
next_position = file->cursor.offset_in_sector + success_size;
|
||||
if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) {
|
||||
file->cursor.sector += next_position >> volume->bpb.log2_bytes_per_sector;
|
||||
} else {
|
||||
file->cursor.sector = -1;
|
||||
}
|
||||
file->cursor.position += success_size;
|
||||
if (file->cursor.position > file->p_sfd->dir_entry.file_size) {
|
||||
file->p_sfd->dir_entry.file_size = file->cursor.position;
|
||||
}
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
PFCLUSTER_UpdateLastAccessCluster(file);
|
||||
advance_write_cursor(file, success_size, file->cursor.sector);
|
||||
if (success_size != size - (size & (volume->bpb.bytes_per_sector - 1))) {
|
||||
return error;
|
||||
}
|
||||
@@ -528,12 +508,6 @@ pf_s32 PFFILE_Cursor_WriteTailSector(PFFILE_FILE* file, const pf_u8* buffer, pf_
|
||||
pf_u32* size_written) {
|
||||
pf_s32 error;
|
||||
pf_u32 success_size;
|
||||
pf_u32 next_position;
|
||||
pf_u32 current_sector;
|
||||
pf_u32 written_size;
|
||||
pf_u32 sector_advance;
|
||||
pf_u32 next_sector;
|
||||
pf_u32 new_position;
|
||||
PF_VOLUME* volume;
|
||||
|
||||
*size_written = 0;
|
||||
@@ -563,24 +537,7 @@ pf_s32 PFFILE_Cursor_WriteTailSector(PFFILE_FILE* file, const pf_u8* buffer, pf_
|
||||
return error;
|
||||
}
|
||||
*size_written = success_size;
|
||||
current_sector = file->cursor.sector;
|
||||
written_size = success_size;
|
||||
volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
next_position = file->cursor.offset_in_sector + written_size;
|
||||
sector_advance = next_position >> volume->bpb.log2_bytes_per_sector;
|
||||
next_sector = current_sector + sector_advance;
|
||||
if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) {
|
||||
file->cursor.sector = next_sector;
|
||||
} else {
|
||||
file->cursor.sector = -1;
|
||||
}
|
||||
new_position = file->cursor.position + success_size;
|
||||
file->cursor.position = new_position;
|
||||
if (new_position > file->p_sfd->dir_entry.file_size) {
|
||||
file->p_sfd->dir_entry.file_size = new_position;
|
||||
}
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
PFCLUSTER_UpdateLastAccessCluster(file);
|
||||
advance_write_cursor(file, success_size, file->cursor.sector);
|
||||
if (success_size != size) {
|
||||
return error;
|
||||
}
|
||||
@@ -697,15 +654,16 @@ PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
pf_u32 index = 0;
|
||||
|
||||
for (; index < 5; index++, sfd++) {
|
||||
if ((sfd->stat & 1) == 0 || (sfd->stat & 2) == 0) {
|
||||
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_index = index;
|
||||
}
|
||||
} else if (entry->p_vol == sfd->dir_entry.p_vol &&
|
||||
entry->entry_sector == sfd->dir_entry.entry_sector &&
|
||||
entry->entry_offset == sfd->dir_entry.entry_offset) {
|
||||
return sfd;
|
||||
} 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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,22 +702,23 @@ PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* filename) {
|
||||
PF_DIR_ENT parent_entry = *entry;
|
||||
PFFILE_FFD ffd;
|
||||
PF_FAT_HINT hint;
|
||||
PFFILE_FAT_HINT hint;
|
||||
pf_u32 previous_sectors[2];
|
||||
pf_u32* previous_sector;
|
||||
pf_u32 success_size;
|
||||
pf_u32 entry_position;
|
||||
pf_u32 num_chars;
|
||||
pf_u32 num_entries;
|
||||
pf_s32 num_chars;
|
||||
pf_u8 num_entries;
|
||||
pf_u8 checksum;
|
||||
pf_u32 ordinal;
|
||||
pf_u32 sector;
|
||||
pf_u32 success_size;
|
||||
pf_s32 error;
|
||||
pf_u8 short_entry_buffer[13];
|
||||
pf_u8 long_entry_buffer[32];
|
||||
|
||||
num_chars = PFSTR_StrNumChar(filename, 1) & 0xFFFF;
|
||||
if (num_chars + parent_entry.path_len >= 0x104 || num_chars >= 0x100) {
|
||||
return 1;
|
||||
}
|
||||
if (num_chars + parent_entry.path_len > 0x103) { return 1; }
|
||||
if (num_chars > 0xFF) { return 1; }
|
||||
PFFAT_InitFFD(&ffd, &hint, parent_entry.p_vol, &parent_entry.start_cluster);
|
||||
if (((PFFILE_VOLUME_DIRS*)volume)->num_opened_files >= 5) {
|
||||
return 0x15;
|
||||
@@ -768,9 +727,7 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
if (error != 0 && entry->short_name[0] == 0) {
|
||||
return 1;
|
||||
}
|
||||
if (error == 0) {
|
||||
entry->long_name[0] = 0;
|
||||
} else {
|
||||
if (error != 0) {
|
||||
error = PFENT_AdjustSFN(&parent_entry, entry->short_name);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -780,8 +737,11 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
} else {
|
||||
pf_w_strcpy(entry->long_name, (const pf_u16*)PFSTR_GetStrPos(filename, 1));
|
||||
}
|
||||
} else {
|
||||
entry->long_name[0] = 0;
|
||||
}
|
||||
entry->start_cluster = volume->bpb.fat_type == FAT_32 ? 1 : 0;
|
||||
if (volume->bpb.fat_type == FAT_32) { entry->start_cluster = 1; }
|
||||
else { entry->start_cluster = 0; }
|
||||
entry->file_size = 0;
|
||||
entry->p_vol = volume;
|
||||
entry->small_letter_flag = 0;
|
||||
@@ -798,14 +758,16 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if ((pf_vol_set.file_settings & 2) != 0) {
|
||||
if ((pf_vol_set.file_settings & 2) == 2) {
|
||||
PFPATH_AdjustExtShortName(entry->short_name, entry_position);
|
||||
}
|
||||
entry->num_entry_LFNs = num_entries;
|
||||
sector = entry->entry_sector;
|
||||
for (ordinal = num_entries; ordinal != 0; ordinal--) {
|
||||
checksum = PFENT_CalcCheckSum(entry);
|
||||
previous_sector = previous_sectors;
|
||||
for (ordinal = num_entries; ordinal >= 1; ordinal--) {
|
||||
PFENT_storeLFNEntryFieldsToBuf(long_entry_buffer, entry, ordinal,
|
||||
PFENT_CalcCheckSum(entry), ordinal == num_entries);
|
||||
checksum, ordinal == num_entries);
|
||||
error = PFSEC_WriteData(volume, long_entry_buffer, sector, entry->entry_offset,
|
||||
0x20, &success_size, 0);
|
||||
if (error != 0) {
|
||||
@@ -817,8 +779,7 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
entry->entry_offset += 0x20;
|
||||
if (entry->entry_offset >= volume->bpb.bytes_per_sector) {
|
||||
entry->entry_offset = 0;
|
||||
sector = previous_sectors[0];
|
||||
previous_sectors[0] = previous_sectors[1];
|
||||
sector = *previous_sector++;
|
||||
}
|
||||
}
|
||||
entry->entry_sector = sector;
|
||||
@@ -834,14 +795,25 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
return PFENT_updateEntry(entry, 1);
|
||||
}
|
||||
|
||||
static inline pf_u32 file_is_open(PF_DIR_ENT* entry) {
|
||||
pf_s32 index;
|
||||
for (index = 0; index < 5; index++) {
|
||||
PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)entry->p_vol)->sfds[index];
|
||||
if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 &&
|
||||
entry->p_vol == sfd->dir_entry.p_vol && entry->entry_sector == sfd->dir_entry.entry_sector &&
|
||||
entry->entry_offset == sfd->dir_entry.entry_offset) { return 1; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_remove(PF_VOLUME* volume, PF_STR* path) {
|
||||
PF_STR directory;
|
||||
PF_STR filename;
|
||||
PF_DIR_ENT entry;
|
||||
PFFILE_ENT_ITER iter;
|
||||
PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume;
|
||||
pf_s32 error;
|
||||
pf_u32 index;
|
||||
PFFILE_FAT_HINT hint;
|
||||
pf_u32 start_cluster;
|
||||
|
||||
error = PFPATH_SplitPath(path, &directory, &filename);
|
||||
if (error != 0) {
|
||||
@@ -851,39 +823,34 @@ pf_s32 PFFILE_p_remove(PF_VOLUME* volume, PF_STR* path) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
hint = *(PFFILE_FAT_HINT*)iter.ffd.p_hint;
|
||||
if ((entry.attr & 0x19) != 0) {
|
||||
return 0xB;
|
||||
}
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((volume_dirs->sfds[index].stat & 1) != 0 &&
|
||||
(volume_dirs->sfds[index].stat & 2) != 0 &&
|
||||
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 0x13;
|
||||
}
|
||||
}
|
||||
if (file_is_open(&entry) != 0) { return 0x13; }
|
||||
iter.ffd.p_hint = (PF_FAT_HINT*)&hint;
|
||||
start_cluster = entry.start_cluster;
|
||||
error = PFENT_RemoveEntry(&entry, &iter);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
return PFFAT_FreeChain(&iter.ffd, entry.start_cluster, 0xFFFFFFFF, entry.file_size);
|
||||
return PFFAT_FreeChain(&iter.ffd, start_cluster, 0xFFFFFFFF, entry.file_size);
|
||||
}
|
||||
|
||||
static PFFILE_FILE* PFFILE_GetFreeUFD(PF_VOLUME* volume);
|
||||
|
||||
pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
PFFILE_FILE** result) {
|
||||
PF_STR directory;
|
||||
PF_STR filename;
|
||||
PF_STR directory;
|
||||
PF_DIR_ENT entry;
|
||||
PFFILE_ENT_ITER iter;
|
||||
PFFILE_FFD ffd;
|
||||
PF_FAT_HINT hint;
|
||||
PFFILE_FAT_HINT hint;
|
||||
PFFILE_SFD* sfd;
|
||||
PFFILE_FILE* file;
|
||||
pf_s8 normalized_filename[0x200];
|
||||
pf_u32 num_chars;
|
||||
pf_u32 index;
|
||||
pf_u32 success_size;
|
||||
pf_s32 num_chars;
|
||||
pf_u16 access_time;
|
||||
pf_s32 error;
|
||||
|
||||
@@ -908,49 +875,7 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
(const pf_u16*)PFSTR_GetStrPos(&filename, 1));
|
||||
}
|
||||
PFSTR_SetLocalStr(&filename, normalized_filename);
|
||||
if ((open_mode & 2) == 0) {
|
||||
error = PFFILE_createEmptyFile(volume, &entry, &filename);
|
||||
if (error == 8) {
|
||||
if ((open_mode & 0x10) != 0) {
|
||||
return 8;
|
||||
}
|
||||
if ((open_mode & 1) != 0) {
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].stat & 3) == 3 &&
|
||||
entry.p_vol ==
|
||||
((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].dir_entry.p_vol &&
|
||||
entry.entry_sector ==
|
||||
((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].dir_entry.entry_sector &&
|
||||
entry.entry_offset ==
|
||||
((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].dir_entry.entry_offset) {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((entry.attr & 1) != 0 &&
|
||||
((open_mode & 1) != 0 || (open_mode & 4) != 0 || (open_mode & 8) != 0)) {
|
||||
return 0xA;
|
||||
}
|
||||
if ((entry.attr & 0x10) != 0) {
|
||||
return 0x17;
|
||||
}
|
||||
if ((open_mode & 1) != 0) {
|
||||
PFFAT_InitFFD(&ffd, &hint, entry.p_vol, &entry.start_cluster);
|
||||
if (entry.start_cluster > 1 && entry.start_cluster != 0xFFFFFFFF &&
|
||||
entry.file_size != 0) {
|
||||
PFFAT_FreeChain(&ffd, entry.start_cluster, 0xFFFFFFFF, entry.file_size);
|
||||
}
|
||||
entry.start_cluster = 0;
|
||||
entry.file_size = 0;
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.modify_date, &entry.modify_time);
|
||||
entry.access_date = entry.modify_date;
|
||||
} else {
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.access_date, &access_time);
|
||||
}
|
||||
} else if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
} else {
|
||||
if ((open_mode & 2) != 0) {
|
||||
PFFAT_InitFFD(&ffd, &hint, entry.p_vol, &entry.start_cluster);
|
||||
error = PFENT_findEntry(&ffd, &entry, 0, &filename, 0x7F, 0);
|
||||
if (error != 0) {
|
||||
@@ -963,37 +888,61 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
return 0x17;
|
||||
}
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.access_date, &access_time);
|
||||
} else {
|
||||
error = PFFILE_createEmptyFile(volume, &entry, &filename);
|
||||
if (error == 8) {
|
||||
if ((open_mode & 0x10) != 0) {
|
||||
return 8;
|
||||
}
|
||||
if ((open_mode & 1) != 0) {
|
||||
if (file_is_open(&entry) != 0) { return 8; }
|
||||
}
|
||||
if ((entry.attr & 1) != 0 &&
|
||||
((open_mode & 1) != 0 || (open_mode & 4) != 0 || (open_mode & 8) != 0)) {
|
||||
return 0xA;
|
||||
}
|
||||
if ((entry.attr & 0x10) != 0) {
|
||||
return 0x17;
|
||||
}
|
||||
if ((open_mode & 1) != 0) {
|
||||
if (entry.start_cluster >= 2 && entry.start_cluster != 0xFFFFFFFF &&
|
||||
entry.file_size != 0) {
|
||||
PFFAT_FreeChain(&iter.ffd, entry.start_cluster, 0xFFFFFFFF, entry.file_size);
|
||||
}
|
||||
entry.start_cluster = 0;
|
||||
entry.file_size = 0;
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.modify_date, &entry.modify_time);
|
||||
entry.access_date = entry.modify_date;
|
||||
} else {
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.access_date, &access_time);
|
||||
}
|
||||
} else if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
volume = entry.p_vol;
|
||||
sfd = PFFILE_GetSFD(volume, &entry);
|
||||
if (sfd == PF_NULL) {
|
||||
return 0x15;
|
||||
}
|
||||
file = PF_NULL;
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((((PFFILE_VOLUME_DIRS*)volume)->ufds[index].stat & 1) == 0) {
|
||||
file = &((PFFILE_VOLUME_DIRS*)volume)->ufds[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
file = PFFILE_GetFreeUFD(volume);
|
||||
if (file == PF_NULL) {
|
||||
return 0x16;
|
||||
}
|
||||
file->p_sfd = sfd;
|
||||
file->stat = 1;
|
||||
file->open_mode = open_mode;
|
||||
file->last_access_data.state.last_access_chain_index = 0;
|
||||
file->last_access_data.state.last_error = 0;
|
||||
file->lock_count = 0;
|
||||
PFFAT_InitHint(&file->hint);
|
||||
file->cursor.position = 0;
|
||||
file->cursor.sector = 0xFFFFFFFF;
|
||||
file->cursor.position = 0;
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
if ((open_mode & 1) != 0) {
|
||||
sfd->stat |= 4;
|
||||
file->p_sfd->stat |= 4;
|
||||
}
|
||||
if ((open_mode & 4) != 0) {
|
||||
file->cursor.position = entry.file_size;
|
||||
if ((file->open_mode & 4) != 0) {
|
||||
file->cursor.position = file->p_sfd->dir_entry.file_size;
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
}
|
||||
sfd->handler_count++;
|
||||
@@ -1002,7 +951,26 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_fread(PF_VOLUME* volume, pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
PFFILE_FILE* file, pf_u32* count_read);
|
||||
PFFILE_FILE* file, pf_u32* count_read) {
|
||||
pf_u32 bytes_read = 0;
|
||||
pf_s32 error;
|
||||
|
||||
*count_read = 0;
|
||||
if ((file->open_mode & 8) == 0 &&
|
||||
((file->open_mode & 1) != 0 || (file->open_mode & 4) != 0)) {
|
||||
return 0xA;
|
||||
}
|
||||
if ((file->p_sfd->lock.mode & 3) != 0 && file->lock_count == 0) {
|
||||
return 0x19;
|
||||
}
|
||||
if (file->cursor.position >= file->p_sfd->dir_entry.file_size) {
|
||||
return 0x1C;
|
||||
}
|
||||
error = PFFILE_Cursor_Read(file, buffer, size * count, &bytes_read);
|
||||
*count_read = bytes_read / size;
|
||||
error &= (-error | error) >> 31;
|
||||
return error;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_fwrite(PF_VOLUME* volume, const pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
PFFILE_FILE* file, pf_u32* count_written) {
|
||||
@@ -1028,32 +996,30 @@ pf_s32 PFFILE_p_fwrite(PF_VOLUME* volume, const pf_u8* buffer, pf_u32 size, pf_u
|
||||
if (file->cursor.position > file->p_sfd->dir_entry.file_size) {
|
||||
remaining = file->cursor.position - file->p_sfd->dir_entry.file_size;
|
||||
file->cursor.position = file->p_sfd->dir_entry.file_size;
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
file->cursor.file_sector_index = file->cursor.position >> volume->bpb.log2_bytes_per_sector;
|
||||
file->cursor.offset_in_sector = file->cursor.position & (volume->bpb.bytes_per_sector - 1);
|
||||
error = PFCACHE_AllocateDataPage(volume, 0xFFFFFFFF, &page, &allocation_option);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
pf_memset(page->p_buf, 0, volume->bpb.bytes_per_sector);
|
||||
while (remaining != 0) {
|
||||
if (remaining <= volume->bpb.bytes_per_sector) {
|
||||
if (remaining > volume->bpb.bytes_per_sector) {
|
||||
error = PFFILE_Cursor_Write(file, page->p_buf, volume->bpb.bytes_per_sector, &bytes_written);
|
||||
if (error != 0) { return error; }
|
||||
} else {
|
||||
error = PFFILE_Cursor_Write(file, page->p_buf, remaining, &bytes_written);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (error != 0) { return error; }
|
||||
break;
|
||||
}
|
||||
error = PFFILE_Cursor_Write(file, page->p_buf, volume->bpb.bytes_per_sector,
|
||||
&bytes_written);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
remaining -= volume->bpb.bytes_per_sector;
|
||||
}
|
||||
PFCACHE_FreeDataPage(volume, page);
|
||||
}
|
||||
error = PFFILE_Cursor_Write(file, buffer, size * count, &bytes_written);
|
||||
*count_written = bytes_written / size;
|
||||
return error;
|
||||
if (error != 0) { return error; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_fappend(PFFILE_FILE* file, pf_u32 size, pf_u32* size_appended) {
|
||||
@@ -1126,10 +1092,8 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa
|
||||
PFFILE_ENT_ITER second_iter_copy;
|
||||
PF_DIR_ENT first_entry;
|
||||
PF_DIR_ENT second_entry;
|
||||
PF_FAT_HINT first_hint;
|
||||
PF_FAT_HINT second_hint;
|
||||
pf_u32 index;
|
||||
pf_s32 found;
|
||||
PFFILE_FAT_HINT first_hint;
|
||||
PFFILE_FAT_HINT second_hint;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFENT_ITER_GetEntryOfPath(&first_iter, &first_entry, volume, first_path, 0);
|
||||
@@ -1146,41 +1110,12 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa
|
||||
if ((first_entry.attr & 1) != 0 || (second_entry.attr & 1) != 0) {
|
||||
return 0x18;
|
||||
}
|
||||
found = 0;
|
||||
for (index = 0; index < 5; index++) {
|
||||
PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)first_entry.p_vol)->sfds[index];
|
||||
|
||||
if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 &&
|
||||
first_entry.p_vol == sfd->dir_entry.p_vol &&
|
||||
first_entry.entry_sector == sfd->dir_entry.entry_sector &&
|
||||
first_entry.entry_offset == sfd->dir_entry.entry_offset) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found != 0) {
|
||||
return 0x13;
|
||||
}
|
||||
found = 0;
|
||||
for (index = 0; index < 5; index++) {
|
||||
PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)second_entry.p_vol)->sfds[index];
|
||||
|
||||
if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 &&
|
||||
second_entry.p_vol == sfd->dir_entry.p_vol &&
|
||||
second_entry.entry_sector == sfd->dir_entry.entry_sector &&
|
||||
second_entry.entry_offset == sfd->dir_entry.entry_offset) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found != 0) {
|
||||
return 0x13;
|
||||
}
|
||||
if (file_is_open(&first_entry) != 0 || file_is_open(&second_entry) != 0) { return 0x13; }
|
||||
if (first_entry.entry_sector == second_entry.entry_sector &&
|
||||
first_entry.entry_offset == second_entry.entry_offset) {
|
||||
return 0xA;
|
||||
}
|
||||
if (0xFFFFFFFF - second_entry.file_size < first_entry.file_size) {
|
||||
if (0xFFFFFFFF - first_entry.file_size < second_entry.file_size) {
|
||||
return 0x25;
|
||||
}
|
||||
PFFAT_InitHint(&first_hint);
|
||||
@@ -1204,24 +1139,20 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa
|
||||
|
||||
pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destination_path,
|
||||
pf_u32 split_size) {
|
||||
PF_STR destination_directory;
|
||||
PF_STR destination_filename;
|
||||
PF_STR destination_directory;
|
||||
PF_DIR_ENT source_entry;
|
||||
PF_DIR_ENT source_entry_copy;
|
||||
PF_DIR_ENT destination_entry;
|
||||
PF_DIR_ENT source_entry_copy;
|
||||
PFFILE_ENT_ITER source_iter;
|
||||
PFFILE_ENT_ITER destination_iter;
|
||||
PFFILE_ENT_ITER destination_file_iter;
|
||||
PFFILE_FFD source_ffd;
|
||||
PFFILE_FFD destination_ffd;
|
||||
PF_FAT_HINT source_hint;
|
||||
PF_FAT_HINT destination_hint;
|
||||
PFFILE_FAT_HINT source_hint;
|
||||
PFFILE_FAT_HINT destination_hint;
|
||||
pf_s8 normalized_filename[0x200];
|
||||
pf_u32 original_start_cluster;
|
||||
pf_u32 original_size;
|
||||
pf_u32 index;
|
||||
pf_u16 current_time;
|
||||
pf_u32 original_start_cluster;
|
||||
pf_s32 error;
|
||||
pf_s32 divide_error;
|
||||
|
||||
error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume, source_path, 0);
|
||||
if (error != 0) {
|
||||
@@ -1233,17 +1164,7 @@ pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destinati
|
||||
if ((source_entry.attr & 1) != 0) {
|
||||
return 0x18;
|
||||
}
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].stat & 3) == 3 &&
|
||||
source_entry.p_vol ==
|
||||
((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].dir_entry.p_vol &&
|
||||
source_entry.entry_sector ==
|
||||
((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].dir_entry.entry_sector &&
|
||||
source_entry.entry_offset ==
|
||||
((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].dir_entry.entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
if (file_is_open(&source_entry) != 0) { return 0x13; }
|
||||
if (source_entry.file_size == 0) {
|
||||
return 0xA;
|
||||
}
|
||||
@@ -1255,7 +1176,7 @@ pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destinati
|
||||
return 1;
|
||||
}
|
||||
if (PFSTR_GetCodeMode(&destination_filename) == 2) {
|
||||
if ((PFSTR_StrNumChar(&destination_filename, 1) & 0xFFFF) > 0xFF) {
|
||||
if ((pf_s32)(PFSTR_StrNumChar(&destination_filename, 1) & 0xFFFF) > 0xFF) {
|
||||
return 1;
|
||||
}
|
||||
PFPATH_transformFromUnicodeToNormal(
|
||||
@@ -1274,13 +1195,13 @@ pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destinati
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
PFFAT_InitHint(&destination_hint);
|
||||
PFFAT_InitFFD(&destination_ffd, &destination_hint, volume, &destination_entry.start_cluster);
|
||||
PFFAT_InitHint(&source_hint);
|
||||
PFFAT_InitFFD(&source_ffd, &source_hint, volume, &source_entry.start_cluster);
|
||||
PFFAT_InitFFD(&source_iter.ffd, &source_hint, volume, &source_entry.start_cluster);
|
||||
PFFAT_InitHint(&destination_hint);
|
||||
PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster);
|
||||
pf_memcpy(&source_entry_copy, &source_entry, sizeof(source_entry_copy));
|
||||
original_start_cluster = source_entry.start_cluster;
|
||||
original_size = source_entry.file_size;
|
||||
original_start_cluster = source_entry.start_cluster;
|
||||
PFENT_getcurrentDateTimeForEnt(&source_entry.modify_date, &source_entry.modify_time);
|
||||
source_entry.access_date = source_entry.modify_date;
|
||||
if (split_size == 0) {
|
||||
@@ -1288,32 +1209,30 @@ pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destinati
|
||||
}
|
||||
source_entry.file_size = split_size;
|
||||
error = PFENT_updateEntry(&source_entry, 1);
|
||||
if (error == 0 &&
|
||||
((((PFFILE_VOLUME_DIRS*)volume)->cache_control & 4) == 0 ||
|
||||
PFCACHE_FlushDataCacheSpecific(volume, 0) == 0)) {
|
||||
error = PFCLUSTER_DivideFile(&source_iter, &destination_iter, &source_entry_copy,
|
||||
&destination_entry, split_size);
|
||||
if (error == 0) {
|
||||
destination_entry.create_time = source_entry.modify_time;
|
||||
destination_entry.create_date = source_entry.modify_date;
|
||||
destination_entry.modify_time = source_entry.modify_time;
|
||||
destination_entry.modify_date = source_entry.modify_date;
|
||||
destination_entry.access_date = source_entry.access_date;
|
||||
destination_entry.attr = source_entry.attr;
|
||||
error = PFENT_updateEntry(&destination_entry, 1);
|
||||
return error & (-error | error) >> 31;
|
||||
}
|
||||
PFCACHE_FlushFATCache(volume);
|
||||
source_entry.start_cluster = original_start_cluster;
|
||||
source_entry.file_size = original_size;
|
||||
PFENT_updateEntry(&source_entry, 1);
|
||||
error = PFENT_ITER_GetEntryOfPath(&destination_file_iter, &destination_entry, volume,
|
||||
destination_path, 0);
|
||||
if (error == 0) {
|
||||
PFENT_RemoveEntry(&destination_entry, &destination_file_iter);
|
||||
}
|
||||
if (error != 0) { return error; }
|
||||
if ((((PFFILE_VOLUME_DIRS*)volume)->cache_control & 4) != 0) {
|
||||
error = PFCACHE_FlushDataCacheSpecific(volume, 0);
|
||||
if (error != 0) { return error; }
|
||||
}
|
||||
return error;
|
||||
error = PFCLUSTER_DivideFile(&source_iter, &destination_iter, &source_entry_copy,
|
||||
&destination_entry, split_size);
|
||||
divide_error = error;
|
||||
if (error != 0) {
|
||||
PFCACHE_FlushFATCache(volume);
|
||||
source_entry.file_size = original_size;
|
||||
source_entry.start_cluster = original_start_cluster;
|
||||
PFENT_updateEntry(&source_entry, 1);
|
||||
PFENT_ITER_GetEntryOfPath(&destination_iter, &destination_entry, volume,
|
||||
destination_path, 0);
|
||||
PFENT_RemoveEntry(&destination_entry, &destination_iter);
|
||||
return divide_error;
|
||||
}
|
||||
destination_entry.modify_date = source_entry.modify_date;
|
||||
destination_entry.modify_time = source_entry.modify_time;
|
||||
destination_entry.access_date = source_entry.access_date;
|
||||
destination_entry.attr = source_entry.attr;
|
||||
error = PFENT_updateEntry(&destination_entry, 1);
|
||||
return error & (-error | error) >> 31;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_cinsert(PF_VOLUME* volume, PF_STR* path, pf_u32 cluster_index,
|
||||
@@ -1403,20 +1322,15 @@ pf_s32 PFFILE_p_cdelete(PF_VOLUME* volume, PF_STR* path, pf_u32 cluster_index,
|
||||
|
||||
pf_s32 PFFILE_p_flock(PFFILE_FILE* file, pf_u32 mode) {
|
||||
if ((mode & 3) != 0) {
|
||||
if ((file->p_sfd->lock.mode & 3) != 0 && (mode & 0x10) != 0) {
|
||||
if ((mode & 1) != 0) {
|
||||
if ((file->p_sfd->lock.mode & 2) != 0) {
|
||||
return 0x27;
|
||||
}
|
||||
} else if ((mode & 2) != 0 && (file->p_sfd->lock.mode & 1) != 0) {
|
||||
return 0x27;
|
||||
}
|
||||
if (file->p_sfd->lock.owner != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) {
|
||||
if ((file->p_sfd->lock.mode & 3) != 0 && (mode & 8) != 0) {
|
||||
if (((mode & 1) != 0 && (file->p_sfd->lock.mode & 2) != 0) ||
|
||||
((mode & 2) != 0 && (file->p_sfd->lock.mode & 1) != 0) ||
|
||||
(file->p_sfd->lock.owner != 0 && file->p_sfd->lock.owner != (PF_FILE*)file)) {
|
||||
return 0x27;
|
||||
}
|
||||
}
|
||||
if ((mode & 1) != 0) {
|
||||
if (file->p_sfd->lock.count == 0 || (file->p_sfd->lock.mode & 2) == 0) {
|
||||
if (file->p_sfd->lock.count == 0 || (file->p_sfd->lock.mode & 2) != 0) {
|
||||
file->p_sfd->lock.wcount++;
|
||||
PF_LockFile((PF_FILE*)file, 0);
|
||||
file->p_sfd->lock.wcount--;
|
||||
@@ -1432,7 +1346,7 @@ pf_s32 PFFILE_p_flock(PFFILE_FILE* file, pf_u32 mode) {
|
||||
}
|
||||
file->p_sfd->lock.count++;
|
||||
file->lock_count++;
|
||||
return 0;
|
||||
goto complete;
|
||||
}
|
||||
if (file->lock_count == 0 || file->p_sfd->lock.count == 0) {
|
||||
return 0x27;
|
||||
@@ -1440,23 +1354,14 @@ pf_s32 PFFILE_p_flock(PFFILE_FILE* file, pf_u32 mode) {
|
||||
if ((file->p_sfd->lock.mode & 2) != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) {
|
||||
return 0x27;
|
||||
}
|
||||
if ((file->p_sfd->lock.mode & 1) != 0) {
|
||||
file->p_sfd->lock.count -= file->lock_count;
|
||||
file->lock_count = 0;
|
||||
if (file->p_sfd->lock.count == 0) {
|
||||
PF_UnLockFile((PF_FILE*)file);
|
||||
}
|
||||
file->p_sfd->lock.mode &= ~3;
|
||||
} else {
|
||||
if (file->p_sfd->lock.owner != (PF_FILE*)file) {
|
||||
return 0x27;
|
||||
}
|
||||
file->p_sfd->lock.count = 0;
|
||||
file->lock_count = 0;
|
||||
file->p_sfd->lock.owner = 0;
|
||||
file->lock_count--;
|
||||
file->p_sfd->lock.count--;
|
||||
if (file->p_sfd->lock.count == 0) {
|
||||
PF_UnLockFile((PF_FILE*)file);
|
||||
if ((file->p_sfd->lock.mode & 2) != 0) { file->p_sfd->lock.owner = 0; }
|
||||
file->p_sfd->lock.mode &= ~3;
|
||||
}
|
||||
complete:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1708,10 +1613,12 @@ close_file_complete:
|
||||
|
||||
pf_s32 PFFILE_fread(pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
PFFILE_FILE* file, pf_u32* count_read) {
|
||||
PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
PF_VOLUME* volume;
|
||||
pf_s32 error;
|
||||
pf_u32 completed_count;
|
||||
|
||||
*count_read = 0;
|
||||
volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
error = PFVOL_CheckForRead(volume);
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
@@ -1724,7 +1631,8 @@ pf_s32 PFFILE_fread(pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
return 0x26;
|
||||
}
|
||||
((PFFILE_VOLUME_DIRS*)volume)->cache_signature = file;
|
||||
error = PFFILE_p_fread(volume, buffer, size, count, file, count_read);
|
||||
error = PFFILE_p_fread(volume, buffer, size, count, file, &completed_count);
|
||||
*count_read = completed_count;
|
||||
((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL;
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
@@ -1869,8 +1777,8 @@ pf_s32 PFFILE_fsetclstlink(PFFILE_FILE* file, pf_u32 mode,
|
||||
file->p_sfd->ffd.cluster_link.interval_offset = 0;
|
||||
file->p_sfd->ffd.cluster_link.position = 0;
|
||||
file->p_sfd->ffd.cluster_link.save_index = 0;
|
||||
if (file->p_sfd->dir_entry.file_size != 0 && settings->link_max != 0) {
|
||||
settings->buffer[0] = *file->p_sfd->ffd.p_start_cluster;
|
||||
if (file->p_sfd->dir_entry.file_size != 0 && file->p_sfd->ffd.cluster_link.max_count != 0) {
|
||||
file->p_sfd->ffd.cluster_link.buffer[0] = *file->p_sfd->ffd.p_start_cluster;
|
||||
file->p_sfd->ffd.cluster_link.position++;
|
||||
}
|
||||
if (file->p_sfd->ffd.p_hint != PF_NULL) {
|
||||
@@ -2217,25 +2125,3 @@ pf_s32 PFFILE_flock(PFFILE_FILE* file, pf_u32 mode) {
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_fread(PF_VOLUME* volume, pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
PFFILE_FILE* file, pf_u32* count_read) {
|
||||
pf_u32 bytes_read = 0;
|
||||
pf_s32 error;
|
||||
|
||||
*count_read = 0;
|
||||
if ((file->open_mode & 8) == 0 &&
|
||||
((file->open_mode & 1) != 0 || (file->open_mode & 4) != 0)) {
|
||||
return 0xA;
|
||||
}
|
||||
if ((file->p_sfd->lock.mode & 3) != 0 && file->lock_count == 0) {
|
||||
return 0x19;
|
||||
}
|
||||
if (file->cursor.position >= file->p_sfd->dir_entry.file_size) {
|
||||
return 0x1C;
|
||||
}
|
||||
error = PFFILE_Cursor_Read(file, buffer, size * count, &bytes_read);
|
||||
*count_read = bytes_read / size;
|
||||
error &= (-error | error) >> 31;
|
||||
return error;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
16
tools/decomp-assist/attempts/fa-dir.md
Normal file
16
tools/decomp-assist/attempts/fa-dir.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# fa/pf_dir
|
||||
|
||||
Baseline 22/38 exact. VF source diff inspected before editing. Sources already contained all 38 bodies; several large bodies lacked fa-specific operations.
|
||||
|
||||
Remaining attempts, instruction counts (source/target), retained source in the final commit:
|
||||
- GetSDD: original flag condition 67/69; status-word negation 68/69; retain flag prerequisite 69/69 with two increment-order differences; update pointer in body, measured below.
|
||||
- opendir: explicit += count update 39/39 two register differences; invert successful branch 39/39 nine differences; inline status helper 39/39 nine differences. Restored first form.
|
||||
- p_fsnext: local pattern, loop and global setting correction 186/193; signed indexed file scan 191/193; while loop 193/193, 39 differences (loop-limit hoisting).
|
||||
- p_rmdir: opened-directory helper 165/202; normalize FreeChain result 169/202; add path split and iterator/hint copies 186/202; restore saved iterator/hint before removal 203/202. Stack/copy scheduling remains.
|
||||
- p_fsexec_remove: opened-directory helper 159/176; initialize a separate iterator 153/176; delay cluster load 151/176; reset supplied iterator and restore its saved state, with file size bound 178/176. Stack/control scheduling remains.
|
||||
- p_mkdir: port API calls and fa FFD/STR/hint types 254/562; order iterator workspace and split name-length errors 256/562; order hint before position 256/562. Missing original inline entry initialization/allocation operations remain.
|
||||
- p_rename: unconditional filename validation 190/625; swapped iterator workspaces and corrected end sentinel 191/625; explicit destination code-mode local and restored iterator order 191/625. Original long-name allocation/update operations remain missing.
|
||||
- p_move: unconditional filename validation 211/631; use opened-directory helper and workspace order 215/631; explicit code-mode local and restored iterator order 215/631. Original cross-directory entry allocation/update remains missing.
|
||||
- p_fsexec: correct flags and use entry start-cluster storage 206/280; move iterator setup before start-position selection 206/280; reorder workspaces and compare status explicitly 207/280. Original name-search/control paths still differ.
|
||||
|
||||
New exact functions include directory allocation, open-by-path, chmod, stat, fsexec chmod and context changes. No shared headers changed.
|
||||
13
tools/decomp-assist/attempts/fa-fat.md
Normal file
13
tools/decomp-assist/attempts/fa-fat.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# fa/pf_fat
|
||||
|
||||
Baseline 22/35 exact. Diff against Matching vf source inspected first. Final source preserves all 35 function bodies and changes no headers.
|
||||
|
||||
Remaining attempts, source/target instruction counts:
|
||||
- DoAllocateChain: page-before-sector initialization (216/216, five register differences); initialize flush error after loading page (same); reorder page/sector locals (same); direct page buffer alias (217/216). Restored original 216/216.
|
||||
- GetClusterAllocated: reorder hint/fat type loads (69/70, 45 differences); reorder first/last cluster locals (same); isolate range check in traversal helper (70/70, eight differences); restore original load ordering (70/70, six differences); reorder hint/fat type declarations (unchanged). Six pointer register differences remain.
|
||||
- GetSector: preload FAT type before root check (88/88, seven register differences); swap quotient/remainder declaration order (same); reverse addition operand order (same); spell rounded sector count directly (same). Division span and quotient registers remain swapped.
|
||||
- GetSectorSpecified: immediate error return (17/17, four differences, compiler uses arithmetic normalization); explicit success/error scopes (16/17); inline wrapper boundary (20/17). Restored original 16/17, one conditional branch expansion remains.
|
||||
- FreeChain: remove page alias (260/254); reorder flush scan locals (256/254, 113 differences); cache FAT type before the loop (different register/control stream). Restored 256/254. Status lifetime and flush registers remain different.
|
||||
- RefreshFSINFO: reorder endian expression (88/93); explicit FSINFO buffer local (87/93); shared allocation-failure exit (93/93, fourteen differences). Restored endian expression and retained common return; remaining allocation status branch and endian store scheduling differ.
|
||||
|
||||
Other experiments yielded exact read/write cluster functions, cluster-link traversal, allocated-cluster counting and specified cluster traversal. Invalid intermediate code with an uninitialized alias was corrected immediately and is absent from the final source.
|
||||
36
tools/decomp-assist/attempts/fa-file.md
Normal file
36
tools/decomp-assist/attempts/fa-file.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# fa/pf_file
|
||||
|
||||
Baseline 32/45 exact, 10384/17820 code bytes. Compared the existing fa source against the Matching vf counterpart before changing it. Final source defines the existing PF_FA_STR_LAYOUT header guard locally; no shared headers changed.
|
||||
|
||||
Remaining attempts, source/target instruction counts:
|
||||
- GetSFD: corrected free-slot predicate and indexed return (113/113, 28 differences); indexed entry comparisons (113/113, 18 differences); move index initialization before pointer initialization and reverse loop updates (113/113, 42 differences); extract SFD initialization into an inline helper and remove the volume alias (113/113, 38 differences); restore original declarations and reverse loop increments (113/113, 18 differences, different increment ordering). Retained original declarations and loop order: 113/113, 18 differences. Callee-saved registers and two loop increments still differ; objdiff 99.09734%.
|
||||
- fread: move p_fread definition into object order (96/67, still inlined); use a separate completed-count local (96/67); initialize that local to zero (96/67); introduce a separate read-status scope (96/67); put output initialization before volume lookup and remove the extra status scope (97/67, 28 comparison differences). Retained the last form, which follows the target's output and volume initialization order. The compiler inlines p_fread into this wrapper whereas the original calls it separately; objdiff 48.208954%. p_fread itself remains instruction exact.
|
||||
|
||||
New exact functions: Cursor_WriteHeadSector, Cursor_WriteBodySectors, Cursor_WriteTailSector, createEmptyFile, p_remove, p_fopen, p_fwrite, p_combine, p_divide, p_flock, fsetclstlink.
|
||||
|
||||
Key source corrections: pass the next sector to the last-access update; use the fa hint and string layouts; retain the removal iterator hint and original first cluster; compute the LFN checksum once and advance the previous-sector pointer; reuse the free-UFD helper; initialize the divide iterators directly and preserve its error through cleanup; propagate cache flush failures; use the target lock flags and release one lock at a time.
|
||||
|
||||
The other units' remaining function attempts and evidence are in fa-volume.md, fa-dir.md and fa-fat.md. No configuration state changed.
|
||||
|
||||
Remaining objdiff scores across the batch:
|
||||
- PFVOL_p_setvol 98.82979%; reason and three or more attempts recorded in fa-volume.md.
|
||||
- PFVOL_attach 98.72159%; reason and three or more attempts recorded in fa-volume.md.
|
||||
- PFVOL_setcode 53.869564%; reason and three or more attempts recorded in fa-volume.md.
|
||||
- PFVOL_regctx 99.0%; reason and three or more attempts recorded in fa-volume.md.
|
||||
- PFDIR_GetSDD 99.710144%; reason and three or more attempts recorded in fa-dir.md.
|
||||
- PFDIR_p_mkdir 24.046263%; reason and three or more attempts recorded in fa-dir.md.
|
||||
- PFDIR_p_rmdir 81.4802%; reason and three or more attempts recorded in fa-dir.md.
|
||||
- PFDIR_p_rename 24.0336%; reason and three or more attempts recorded in fa-dir.md.
|
||||
- PFDIR_p_move 25.359747%; reason and three or more attempts recorded in fa-dir.md.
|
||||
- PFDIR_p_fsnext 97.74612%; reason and three or more attempts recorded in fa-dir.md.
|
||||
- PFDIR_p_fsexec_remove 98.46591%; reason and three or more attempts recorded in fa-dir.md.
|
||||
- PFDIR_p_fsexec 63.478573%; reason and three or more attempts recorded in fa-dir.md.
|
||||
- PFDIR_opendir 99.74359%; reason and three or more attempts recorded in fa-dir.md.
|
||||
- PFFAT_DoAllocateChain 99.83796%; reason and three or more attempts recorded in fa-fat.md.
|
||||
- PFFAT_GetClusterAllocated 99.57143%; reason and three or more attempts recorded in fa-fat.md.
|
||||
- PFFAT_GetSector 99.431816%; reason and three or more attempts recorded in fa-fat.md.
|
||||
- PFFAT_GetSectorSpecified 93.52941%; reason and three or more attempts recorded in fa-fat.md.
|
||||
- PFFAT_FreeChain 97.95276%; reason and three or more attempts recorded in fa-fat.md.
|
||||
- PFFAT_RefreshFSINFO 96.62366%; reason and three or more attempts recorded in fa-fat.md.
|
||||
- PFFILE_GetSFD 99.09734%; register allocation and loop increment ordering.
|
||||
- PFFILE_fread 48.208954%; compiler inlines the separate read operation.
|
||||
11
tools/decomp-assist/attempts/fa-volume.md
Normal file
11
tools/decomp-assist/attempts/fa-volume.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# fa/pf_volume
|
||||
|
||||
Baseline: 7/37 exact, 1048/17992 code bytes. Matching vf source compared first; this fa variant has 26 volumes and three context slots.
|
||||
|
||||
Remaining experiments (ctxdiff evidence in /tmp during matching):
|
||||
- PFVOL_p_setvol: inline whole operation (93/94, different stack slots); normalize helper result (97/94, different stack slots); remove redundant root error else (93/94, only first conditional branch expansion). Retained original stack layout, 93/94.
|
||||
- PFVOL_attach: correct free-cluster and drive fields (170/176); canonical search loop (169/176); split driver/cache initialization and mount status (173/176); reorder locals and signed drive conversion (174/176); separate mount helper (174/176, unchanged). Remaining status return boundary, 174/176.
|
||||
- PFVOL_setcode: six named pointer assignments (23/23, 17 diffs); aggregate assignment (same); word loop (same); inline copy helper (same). Compiler schedules loads before stores and allocates a different base register.
|
||||
- PFVOL_regctx: indexed context loop (79/75); initialize free index after system call (77/75); return system status (75/75, 20 register differences); reorder free/index declarations (75/75, 15 register differences); split masked status declaration and assignment (unchanged). Retained 75/75.
|
||||
|
||||
Other corrected operations now instruction exact: driver request handling, read/write checks, formatting, context removal, label removal, cache flush status, buffering, mount/unmount and configuration. No shared headers changed.
|
||||
Reference in New Issue
Block a user