Compare commits

...

24 Commits

Author SHA1 Message Date
Devin AI
574944349c fa(pf_fat): DoAllocateChain - drop dead init, uninit fat_err w/ late assign (93->63 diffs)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 09:58:20 +00:00
Devin AI
eee97b5612 pf_dir: del_mark extern+EOF-const pattern for data pool; pf_path: revert
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 09:49:56 +00:00
Devin AI
ab962e442f sd_drv: calc_mbr_bpb decl order (binding still tied)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 09:48:07 +00:00
Devin AI
33647df7dd pf_volume: err_test mirror-switch in all mask sites
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 09:46:08 +00:00
Devin AI
b38d82bc89 pf_volume: err_test switch+mirror form (sync/buffering/rmvvol/CheckForWrite/setvol tails)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 09:44:47 +00:00
Devin AI
c521f2acc9 pf_volume: switch-err + ?0:9 ternary idioms; ptr-walk loops; err2 tails
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 09:35:38 +00:00
Devin AI
9de0675732 fa/pf_fat: GetClusterInChain count-before-index (double 0x10 load matches); switch-err idiom in GetClusterSpecified
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 08:27:08 +00:00
Devin AI
96d4aaabca fa: pf_fat switch-err idiom (3 fns to 100); sd_drv struct-wrap+reserved buf; pdm set_change_media_state 100
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 08:25:30 +00:00
Devin AI
f4c1b7346f fa/pf_path: data 100%, 26/27 fns at objdiff 100
MatchFileNameWithPattern sig materialization now byte-identical:
static ext_sig_1/2 (element sda21 loads) + const sig[2] literal
gives exact .sdata/.sdata2 layouts. Remaining residual: 196/199
insns, r29<->r31 alloc swap + a cold block tail-merged past the
epilogue in base.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 08:06:27 +00:00
Devin AI
7e377c0310 fa: fix PF_VOLUME clst alias + PF_CLUSTER_LINK member order
- clst_buf/clst_count alias clst_buffer/clst_link_max (same storage at
  0x1F98/0x1F9C) - fixes +8 shift of p_part/p_callback/format_param
- PF_CLUSTER_LINK base order: buffer, interval, interval_offset,
  position, max_count, save_index - fixes all FFD-relative offsets

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:58:19 +00:00
Devin AI
2a9b2964fb fa/sd_drv: is_media_insert exact (nested-else return idiom); callbacks drop info-local CSE
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:34:49 +00:00
Devin AI
66b49f9fdb fa/pf_dir: p_fsexec_remove exact (PF_ENT_ITER iter_save 0x70 mtctr, PF_FAT_HINT copy, ||fold, p_sdd walk); chmod clause order
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:30:46 +00:00
Devin AI
d1dd7c227b fa/pf_file: Cursor family 6/7 exact (ReadHead/ReadTail/WriteHead/WriteBody/WriteTail+ne-tail idiom); u32 ReadData arg
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
385c3b9da9 fa/pf_dir: dedupe w/ main #250 — port 4 exact fns, 25/38 exact
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
13d3e82cc4 WIP: pf_file recovery in progress (untracked->tracked), pf_dir/pf_fat pending
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
ba8ff95bae fa/pf_dir: implement all 38 functions, reorder to object order, 19 exact
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
c4958c6d09 fa/pdm_partition: byte-expression order in is_master_boot_sector
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
9ed2f96bc9 fa/pf_volume: match p_setvol, p_getvol; fix ctx-check idiom, flag evals, decl order
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
ad4af23bad fa/pf_volume: match setcode, setvolcfg, InitModule, detach; format near
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
33653f444e fa/pf_volume: match unregctx, regctx; fix PF_VOLUME tail layout, data objects
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
402b285d96 rvlsdk-fa: pf_fat.c — 27/34 functions insn-identical, rest are documented tie-breaks
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
33325978c8 rvlsdk-fa: pf_path.c — 26/27 functions insn-identical
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
96c74f4910 fa/sd_drv: implement all 26 functions (partial match, WIP)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
Devin AI
e5714bb327 fa/pdm_partition: match 18/20 functions byte-identical
is_master_boot_sector and get_start_sector are structurally identical
(same insn counts, same frames) with residual MWCC scheduling/register
tie-breaks; chg_ltop r0/r3 binding swap is a regalloc tie-break.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 06:23:51 +00:00
8 changed files with 11789 additions and 1521 deletions

View File

@@ -0,0 +1,430 @@
#ifndef FA_LOCAL_H
#define FA_LOCAL_H
#include <revolution/types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PF_STR {
const s8* p_head; // 0x00
const s8* p_tail; // 0x04
s8* p_local; // 0x08
u32 code_mode; // 0x0C
} PF_STR;
typedef struct PF_FILE_NAME_ITER {
const s8* buf; // 0x00
u32 field_04; // 0x04
u32 kind; // 0x08
u16 index; // 0x0C
u16 pad_0E; // 0x0E
} PF_FILE_NAME_ITER;
typedef struct PF_CHARCODE {
s32 (*oem2unicode)(const s8*, u16*); // 0x00
s32 (*unicode2oem)(const u16*, s8*); // 0x04
s32 (*oem_char_width)(const s8*); // 0x08
u32 (*is_oem_mb_char)(s8, u32); // 0x0C
s32 (*unicode_char_width)(const u16*); // 0x10
u32 (*is_unicode_mb_char)(u16, u32); // 0x14
} PF_CHARCODE;
typedef enum {
FAT_12 = 0,
FAT_16 = 1,
FAT_32 = 2,
FAT_ERR = -1,
} PF_FAT_TYPE;
typedef struct PF_BPB {
u16 bytes_per_sector; // 0x00
u16 num_reserved_sectors; // 0x02
u16 num_root_dir_entries; // 0x04
u8 sectors_per_cluster; // 0x06
u8 num_FATs; // 0x07
u32 total_sectors; // 0x08
u32 sectors_per_FAT; // 0x0C
u32 root_dir_cluster; // 0x10
u16 fs_info_sector; // 0x14
u16 backup_boot_sector; // 0x16
u16 ext_flags; // 0x18
u8 media; // 0x1A
u8 pad_1B;
PF_FAT_TYPE fat_type; // 0x1C
u8 log2_bytes_per_sector; // 0x20
u8 log2_sectors_per_cluster; // 0x21
u8 num_active_FATs; // 0x22
u8 pad_23;
u16 num_root_dir_sectors; // 0x24
u8 pad_26[2];
u32 active_FAT_sector; // 0x28
u32 first_root_dir_sector; // 0x2C
u32 first_data_sector; // 0x30
u32 num_clusters; // 0x34
} PF_BPB;
typedef struct PF_DIR_ENT {
u16 long_name[261]; // 0x00
u8 num_entry_LFNs; // 0x20A
u8 ordinal; // 0x20B
u8 check_sum; // 0x20C
u8 align_pad[1]; // 0x20D
s8 short_name[13]; // 0x20E
u8 small_letter_flag; // 0x21B
u8 attr; // 0x21C
u8 create_time_ms; // 0x21D
u16 create_time; // 0x21E
u16 create_date; // 0x220
u16 access_date; // 0x222
u16 modify_time; // 0x224
u16 modify_date; // 0x226
u32 file_size; // 0x228
struct PF_VOLUME* p_vol; // 0x22C
u32 path_len; // 0x230
u32 start_cluster; // 0x234
u32 entry_sector; // 0x238
u16 entry_offset; // 0x23C
u16 pad_23E;
} PF_DIR_ENT;
typedef struct PF_CUR_DIR {
u32 stat; // 0x00
s32 context_id; // 0x04
PF_DIR_ENT directory; // 0x08
} PF_CUR_DIR;
typedef struct PF_LAST_CLUSTER {
u32 num_last_cluster;
u32 max_chain_index;
} PF_LAST_CLUSTER;
typedef struct PF_FAT_LAST_ACCESS {
u32 chain_index;
u32 cluster;
} PF_FAT_LAST_ACCESS;
typedef struct PF_CLUSTER_LINK {
u32* buffer;
u16 interval;
u16 interval_offset;
u32 position;
u32 max_count;
u32 save_index;
} PF_CLUSTER_LINK;
typedef struct PF_FAT_HINT {
u32 chain_index; // 0x00
u32 cluster; // 0x04
u32 start_cluster; // 0x08
} PF_FAT_HINT;
typedef struct PF_FILE_HINT {
u32 chain_index; // 0x00
u32 cluster; // 0x04
u32 start_cluster; // 0x08
} PF_FILE_HINT;
typedef struct PF_FFD {
u32 start_cluster;
u32 field_04;
u32* p_start_cluster;
PF_LAST_CLUSTER last_cluster;
PF_FAT_LAST_ACCESS last_access_cluster;
PF_CLUSTER_LINK cluster_link;
PF_FAT_HINT* p_hint;
struct PF_VOLUME* p_vol;
} PF_FFD;
typedef struct PF_CACHE_PAGE {
u16 stat; // 0x00
u16 option; // 0x02
u8* buffer; // 0x04
u8* p_buf; // 0x08
u8* p_mod_sbuf; // 0x0C
u8* p_mod_ebuf; // 0x10
u32 size; // 0x14
u32 sector; // 0x18
void* signature; // 0x1C
struct PF_CACHE_PAGE* p_next; // 0x20
struct PF_CACHE_PAGE* p_prev; // 0x24
} PF_CACHE_PAGE;
typedef struct PF_ENT_ITER PF_ENT_ITER;
typedef struct PF_DIRENT {
s8 lname[512]; // 0x00
s8 name[13]; // 0x200
} PF_DIRENT;
typedef struct PF_ENT_ITER {
u8 pad_00[0x8];
PF_FFD ffd; // 0x08
u32 field_40; // 0x40
u32 field_44; // 0x44
u32 field_48; // 0x48
u8 buf[0x24]; // 0x4C
} PF_ENT_ITER;
typedef struct PF_SDD {
u32 stat; // 0x00
u16 num_handlers; // 0x04
u16 pad_06;
PF_FFD ffd; // 0x08
PF_DIR_ENT dir_entry; // 0x40
} PF_SDD;
typedef struct PF_SDD_HANDLE {
u32 stat; // 0x00
u32 pad_4;
PF_SDD* p_sdd; // 0x08
u8 pad_C[0x24];
} PF_SDD_HANDLE;
typedef struct PF_FILE PF_FILE;
typedef struct PF_LOCK {
u16 mode; // 0x00
u16 count; // 0x02
u32 wcount; // 0x04
PF_FILE* owner; // 0x08
s32 resource; // 0x0C
} PF_LOCK;
typedef struct PF_SFD PF_SFD;
struct PF_SFD {
u32 stat; // 0x00
PF_FFD ffd; // 0x04
PF_DIR_ENT dir_entry; // 0x3C
PF_LOCK lock; // 0x27C
u8 pad_28C[0x0C]; // 0x28C
u16 num_handlers; // 0x298
u16 pad_29A;
};
typedef struct PF_CURSOR {
u32 position; // 0x00
u32 sector; // 0x04
u32 file_sector_index; // 0x08
u16 offset_in_sector; // 0x0C
u16 pad_0E;
} PF_CURSOR;
typedef struct PF_FILE {
u32 stat; // 0x00
u32 open_mode; // 0x04
PF_SFD* p_sfd; // 0x08
PF_FILE_HINT hint; // 0x0C
s32 last_error; // 0x18
PF_CURSOR cursor; // 0x1C
u16 lock_count; // 0x2C
u16 pad_2E;
} PF_FILE;
typedef struct PF_INFO {
u32 file_size; // 0x00
u32 io_pointer; // 0x04
u32 empty_size; // 0x08
u32 allocated_size; // 0x0C
u32 lock_mode; // 0x10
PF_FILE* lock_owner; // 0x14
u32 lock_count; // 0x18
u32 lock_tcount; // 0x1C
u8 pad_20[0x14];
u32 field_34; // 0x34
} PF_INFO;
typedef struct PF_FSTAT {
u32 file_size; // 0x00
u16 create_time; // 0x04
u16 modify_time; // 0x06
u16 modify_date; // 0x08
u16 create_date; // 0x0A
u16 access_date; // 0x0C
u16 create_time_ms; // 0x0E
u8 attr; // 0x10
} PF_FSTAT;
typedef struct PF_UDD {
u32 stat; // 0x00
PF_SDD* p_sdd; // 0x04
PF_FILE_HINT hint; // 0x08
u32 field_14; // 0x14
u32 field_18; // 0x18
u32 field_1C; // 0x1C
} PF_UDD;
typedef struct PF_VOLUME {
PF_BPB bpb; // 0x00
u32 num_free_clusters; // 0x38
u32 last_free_cluster; // 0x3C
PF_SFD file_handle[5]; // 0x40
PF_SDD_HANDLE dir_handle[5]; // 0xD4C
PF_SDD sdds[3]; // 0xE3C
PF_UDD udds[3]; // 0x15BC
s32 num_open_files; // 0x161C
u32 num_open_dirs; // 0x1620
u32 buffer_mode; // 0x1624
u16 cache_max_fat; // 0x1628
u16 cache_max_data; // 0x162A
u8 pad_162C[0x10];
u32 fat_buffer_size; // 0x163C
u32 data_buffer_size; // 0x1640
void* cache_signature; // 0x1644
s8 label[12]; // 0x1648
PF_CUR_DIR current_dir[4]; // 0x1654
u32 tail_size; // 0x1F74
u8 tail_area[4]; // 0x1F78
u32* p_tail_buf; // 0x1F7C
s32 last_error; // 0x1F80
s32 last_driver_error; // 0x1F84
u32 file_config; // 0x1F88
u16 flags; // 0x1F8C
s8 drv_char; // 0x1F8E
u8 pad_1F8F;
u16 fsi_flag; // 0x1F90
u8 pad_1F92[2];
u16 clst_flag; // 0x1F94
u16 clst_interval; // 0x1F96
u32* clst_buffer; // 0x1F98
u32 clst_link_max; // 0x1F9C
#define clst_buf clst_buffer
#define clst_count clst_link_max
void* p_part; // 0x1FA0
s32 (*p_callback)(s32); // 0x1FA4
const u8* format_param; // 0x1FA8
} PF_VOLUME;
typedef struct PF_CONTEXT {
u32 stat; // 0x00
s32 context_id; // 0x04
} PF_CONTEXT;
typedef struct PF_CUR_VOLUME {
u32 stat; // 0x00
s32 context_id; // 0x04
PF_VOLUME* p_vol; // 0x08
} PF_CUR_VOLUME;
typedef struct PF_DTA {
void* file; // 0x00
void* dir; // 0x04
PF_VOLUME* vol; // 0x08
u32 parent_start_cluster; // 0x0C
u32 parent_pos; // 0x10
u32 status; // 0x14
u8 num_entry_LFNs; // 0x18
u8 ordinal; // 0x19
u8 check_sum; // 0x1A
u8 attr; // 0x1B
s8 reg_exp[520]; // 0x1C
u16 time; // 0x224
u16 date; // 0x226
u32 file_size; // 0x228
u8 attribute; // 0x22C
s8 file_name[13]; // 0x22D
s8 long_name[520]; // 0x23A
u8 pad_442[2];
u16 reg_expW[260]; // 0x444
u16 file_nameW[13]; // 0x64C
u16 long_nameW[260]; // 0x666
} PF_DTA;
/* pf_vol_set global; offsets verified against base object */
typedef struct PF_VOLUME_SET {
PF_CUR_VOLUME current_vol[4]; // 0x00
s32 num_attached_volumes; // 0x30
s32 num_mounted_volumes; // 0x34
u32 config; // 0x38
u32 pad_3C; // 0x3C
s32 last_error; // 0x40
s32 last_driver_error; // 0x44
PF_CHARCODE codeset; // 0x48
u32 setting; // 0x60
u8 pad_64[0x0C]; // 0x64
PF_CONTEXT context[3]; // 0x70
PF_VOLUME volumes[26]; // 0x88
} PF_VOLUME_SET;
extern PF_VOLUME_SET pf_vol_set;
/* pf_str.c */
void PFSTR_SetCodeMode(PF_STR* p_str, u32 code_mode);
u32 PFSTR_GetCodeMode(PF_STR* p_str);
s8* PFSTR_GetStrPos(PF_STR* p_str, u32 target);
void PFSTR_MoveStrPos(PF_STR* p_str, s16 num_char);
s32 PFSTR_InitStr(PF_STR* p_str, const s8* s, u32 code_mode);
u16 PFSTR_StrLen(PF_STR* p_str);
u16 PFSTR_StrNumChar(PF_STR* p_str, u32 target);
s32 PFSTR_StrCmp(const PF_STR* p_str, const s8* s);
s32 PFSTR_StrNCmp(PF_STR* p_str, const s8* s, u32 target, s16 offset, u16 num);
void PFSTR_ToUpperNStr(PF_STR* p_str, u16 num, s8* dest);
/* pf_clib.c */
s32 pf_strcmp(const s8* s1, const s8* s2);
s32 pf_strncmp(const s8* s1, const s8* s2, u32 n);
s8* pf_strcpy(s8* dst, const s8* src);
u32 pf_strlen(const s8* s);
s32 pf_toupper(s32 c);
s32 pf_w_strcmp(const u16* s1, const u16* s2);
s32 pf_w_strncmp(const u16* s1, const u16* s2, u32 n);
u16* pf_w_strcpy(u16* dst, const u16* src);
u32 pf_w_strlen(const u16* s);
/* pf_code.c */
void PFCODE_Divide_Width(s32 width, s16* oem_width, s16* uni_width);
#define PF_CODE_C_TO_WC(x0, x1) ((u16)(((u8)(x0) << 8) + (u8)(x1)))
#define PF_CODE_C_TO_WC_ARR(x, i) PF_CODE_C_TO_WC(x[i], x[i + 1])
extern const u8 pf_valid_fn_char[96];
/* pf_service.c */
u16 PF_GET_LE_U16(const u8* p);
/* pf_volume.c */
PF_VOLUME* PFVOL_GetCurrentVolume(void);
PF_VOLUME* PFVOL_GetVolumeFromDrvChar(s8 drv_char);
#define PF_IS_PATH_SEPERATOR(s, t, i) ((PFSTR_StrNCmp(s, (const s8*)"\\", t, i, 1) == 0 || PFSTR_StrNCmp(s, (const s8*)"/", t, i, 1) == 0))
#define PF_IS_PATH_NULL(s, t, i) (PFSTR_StrNCmp(s, (const s8*)"\0", t, i, 1) == 0)
#define PF_IS_PATH_NOT_NULL(s, t, i) (PFSTR_StrNCmp(s, (const s8*)"\0", t, i, 1) != 0)
/* pf_path.c */
void PFPATH_InitTokenOfPath(PF_STR* p_str, s8* path, u32 code_mode);
s32 PFPATH_GetNextTokenOfPath(PF_STR* p_str, u32 wildcard);
s32 PFPATH_DoSplitPath(PF_STR* p_path, PF_STR* p_dir_path, PF_STR* p_filename, u32 wildcard);
s32 PFPATH_SplitPath(PF_STR* p_path, PF_STR* p_dir_path, PF_STR* p_filename);
s32 PFPATH_SplitPathPattern(PF_STR* p_path, PF_STR* p_dir_path, PF_STR* p_pattern);
PF_VOLUME* PFPATH_GetVolumeFromPath(PF_STR* p_path);
u32 PFPATH_MatchFileNameWithPattern(const s8* file_name, PF_STR* p_pattern, u32 is_long_name);
s32 PFPATH_cmpNameUni(const u16* p_name, PF_STR* sPattern);
s32 PFPATH_cmpNameImpl(const s8* p_name, const s8* p_pattern, u32* p_flag);
s32 PFPATH_cmpName(const s8* sShort, PF_STR* p_pattern, u32 is_short_search);
s32 PFPATH_cmpTailSFN(const s8* sfn_name, const s8* pattern);
s32 PFPATH_putShortName(u8* pDirEntry, const s8* short_name, u8 attr);
s32 PFPATH_getShortName(s8* short_name, const u8* pDirEntry, u8 attr);
void PFPATH_getLongNameformShortName(s8* short_name, s8* long_name, u8 flag);
u32 PFPATH_GetLengthFromShortname(const s8* sSrc);
u32 PFPATH_GetLengthFromUnicode(const u16* sSrc);
s32 PFPATH_transformFromUnicodeToNormal(s8* sDest, const u16* sSrc);
s32 PFPATH_transformInUnicode(u16* sDestStr, const s8* sSrcStr);
u32 PFPATH_parseShortName(s8* pDest, PF_STR* p_pattern);
s32 PFPATH_parseShortNameNumeric(s8* p_char, u32 count);
void PFPATH_SetSearchPattern(s8* p_buf_local, u16* p_buf_unicode, PF_STR* p_pattern);
u32 PFPATH_CheckExtShortNameSignature(PF_STR* p_str);
u32 PFPATH_CheckExtShortName(PF_STR* p_str, u32 target, u32 wildcard);
u32 PFPATH_GetExtShortNameIndex(PF_STR* p_str, u32* p_index);
s32 PFPATH_AdjustExtShortName(s8* pName, u32 position);
u16 PFPATH_GetNextCharOfPattern(PF_STR* p_pattern, u32 name_kind);
u32 PFPATH_DoMatchFileNameWithPattern(u16 c_name, PF_FILE_NAME_ITER* p_name, u16 c_pat, PF_STR* p_pattern, u32 name_kind);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,495 @@
#include <revolution/types.h>
typedef struct PDM_DISK {
u8 pad_00[0x18];
u32 num_sectors; // +0x18
u8 pad_1C[0x8];
} PDM_DISK;
typedef struct PDM_PARTITION PDM_PARTITION;
typedef void (*PDM_PART_CALLBACK)(PDM_PARTITION* p_part);
struct PDM_PARTITION {
u32 stat; // +0x00
PDM_DISK* p_disk; // +0x04
u32 part_no; // +0x08
u32 start_sector; // +0x0C
u32 num_sectors; // +0x10
s32 driver_error_code; // +0x14
u32 field_18; // +0x18
u32 field_1C; // +0x1C
PDM_PART_CALLBACK callback[2]; // +0x20, +0x24
};
typedef struct PDM_DISK_SET {
u16 num_partition; // +0x00
u8 pad_02[0x4E2]; // +0x02
PDM_PARTITION part_table[0x1A]; // +0x4E4
} PDM_DISK_SET;
extern PDM_DISK_SET pdm_disk_set;
extern s32 pdm_disk_set_disk(PDM_DISK* p_disk, PDM_PARTITION* p_part);
extern s32 pdm_disk_init(PDM_DISK* p_disk);
extern s32 pdm_disk_mount(PDM_DISK* p_disk);
extern s32 pdm_disk_unmount(PDM_DISK* p_disk, u32 force);
extern s32 pdm_disk_format(PDM_DISK* p_disk, u8* param);
extern s32 pdm_disk_finalize(PDM_DISK* p_disk);
extern s32 pdm_disk_get_media_bps(PDM_DISK* p_disk, u16* p_bps);
extern s32 pdm_disk_get_media_attribute(PDM_DISK* p_disk);
extern s32 pdm_disk_physical_read(PDM_DISK* p_disk, u8* buf, u32 sector, u32 num_sector, u16 bps, u32* p_num_success);
extern s32 pdm_disk_physical_write(PDM_DISK* p_disk, const u8* buf, u32 sector, u32 num_sector, u16 bps, u32* p_num_success);
s32 pdm_part_is_master_boot_sector(const u8* p_sector, u32 num_sector, u32* p_is_mbr) {
u32 start_sector[4];
u32 sector_num[4];
u32* p_start;
u32* p_num;
const u8* pe;
s16 i;
*p_is_mbr = 0;
if (p_sector[0x1FE] != 0x55 || p_sector[0x1FF] != 0xAA) {
return 2;
}
pe = p_sector;
p_start = start_sector;
p_num = sector_num;
for (i = 0; i < 4; i++) {
*p_start = 0;
*p_start = (pe[0x1C9] * 0x1000000 + pe[0x1C7] * 0x100) + (pe[0x1C8] * 0x10000 + pe[0x1C6]);
*p_num = (pe[0x1CD] * 0x1000000 + pe[0x1CB] * 0x100) + (pe[0x1CC] * 0x10000 + pe[0x1CA]);
if (*p_start != 0 && *p_num != 0) {
if (i == 0) {
*p_is_mbr = 1;
}
} else {
if (i == 0) {
return 2;
}
}
p_num++;
pe += 0x10;
p_start++;
}
p_num = sector_num;
p_start = start_sector;
for (i = 0; i < 4; i++) {
if (*p_start + *p_num > num_sector) {
if (i == 0) {
*p_is_mbr = 0;
}
return 2;
}
p_start++;
p_num++;
}
return 0;
}
s32 pdm_part_is_boot_sector(const u8* p_sector) {
u16 bps;
s32 is_boot;
is_boot = 1;
if (!((p_sector[0] == 0xEB && p_sector[2] == 0x90) || p_sector[0] == 0xE9)) {
is_boot = 0;
}
if (!(p_sector[0x1FE] == 0x55 && p_sector[0x1FF] == 0xAA)) {
is_boot = 0;
}
if ((u32)&p_sector[0xB] & 1) {
bps = p_sector[0xB] | p_sector[0xC] << 8;
} else {
u16 tmp;
tmp = *(u16*)&p_sector[0xC];
bps = ((tmp >> 8) & 0xFF) | ((tmp << 8) & 0xFF00);
}
if (bps != 0x200 && bps != 0x400 && bps != 0x800 && bps != 0x1000) {
is_boot = 0;
}
if (p_sector[0xD] != 1 && p_sector[0xD] != 2 && p_sector[0xD] != 4 && p_sector[0xD] != 8 &&
p_sector[0xD] != 0x10 && p_sector[0xD] != 0x20 && p_sector[0xD] != 0x40 && p_sector[0xD] != 0x80) {
is_boot = 0;
}
if (p_sector[0x15] != 0xF0 && p_sector[0x15] != 0xF8 && p_sector[0x15] != 0xF9 && p_sector[0x15] != 0xFA &&
p_sector[0x15] != 0xFB && p_sector[0x15] != 0xFC && p_sector[0x15] != 0xFD && p_sector[0x15] != 0xFE &&
p_sector[0x15] != 0xFF) {
is_boot = 0;
}
return is_boot;
}
s32 pdm_part_get_start_sector(PDM_PARTITION* p_part) {
u8 buf[0x200] ATTRIBUTE_ALIGN(32);
u32 num_success;
u32 is_mbr;
u32 start_sector[4];
u32 sector_num[4];
u32 rel_sector;
u32 rel_num;
u32 rel_start;
u32 rel_cnt;
u32 base;
u32 part_no;
u32 cnt;
u16 i;
u16 j;
s32 err;
cnt = 0;
p_part->start_sector = 0;
part_no = p_part->part_no;
p_part->num_sectors = p_part->p_disk->num_sectors;
err = pdm_disk_physical_read(p_part->p_disk, buf, 0, 1, 0x200, &num_success);
if (err != 0) {
return err;
}
pdm_part_is_master_boot_sector(buf, p_part->p_disk->num_sectors, &is_mbr);
if (is_mbr != 0) {
start_sector[0] = buf[0x1C6] + buf[0x1C7] * 0x100 + buf[0x1C8] * 0x10000 + buf[0x1C9] * 0x1000000;
sector_num[0] = buf[0x1CA] + buf[0x1CB] * 0x100 + buf[0x1CC] * 0x10000 + buf[0x1CD] * 0x1000000;
start_sector[1] = buf[0x1D6] + buf[0x1D7] * 0x100 + buf[0x1D8] * 0x10000 + buf[0x1D9] * 0x1000000;
sector_num[1] = buf[0x1DA] + buf[0x1DB] * 0x100 + buf[0x1DC] * 0x10000 + buf[0x1DD] * 0x1000000;
start_sector[2] = buf[0x1E6] + buf[0x1E7] * 0x100 + buf[0x1E8] * 0x10000 + buf[0x1E9] * 0x1000000;
sector_num[2] = buf[0x1EA] + buf[0x1EB] * 0x100 + buf[0x1EC] * 0x10000 + buf[0x1ED] * 0x1000000;
start_sector[3] = buf[0x1F6] + buf[0x1F7] * 0x100 + buf[0x1F8] * 0x10000 + buf[0x1F9] * 0x1000000;
sector_num[3] = buf[0x1FA] + buf[0x1FB] * 0x100 + buf[0x1FC] * 0x10000 + buf[0x1FD] * 0x1000000;
for (i = 0; i < 4; i++) {
rel_start = start_sector[i];
rel_cnt = sector_num[i];
if (rel_start == 0 || rel_cnt == 0) {
return 7;
}
err = pdm_disk_physical_read(p_part->p_disk, buf, rel_start, 1, 0x200, &num_success);
if (err != 0) {
return err;
}
pdm_part_is_master_boot_sector(buf, p_part->p_disk->num_sectors, &is_mbr);
if (is_mbr != 0) {
base = start_sector[i];
rel_sector = base;
for (j = 0; j < 2; j++) {
if (j == 0) {
rel_sector = rel_sector + (buf[0x1C8] * 0x10000 + buf[0x1C6]) +
(buf[0x1C9] * 0x1000000 + buf[0x1C7] * 0x100);
rel_num = buf[0x1CC] * 0x10000 + buf[0x1CA] + buf[0x1CD] * 0x1000000 + buf[0x1CB] * 0x100;
err = pdm_disk_physical_read(p_part->p_disk, buf, rel_sector, 1, 0x200, &num_success);
if (err != 0) {
return err;
}
if (part_no == cnt) {
p_part->start_sector = rel_sector;
p_part->num_sectors = rel_num;
return 0;
}
cnt++;
} else {
rel_sector = base + (buf[0x1D8] * 0x10000 + buf[0x1D6]) +
(buf[0x1D9] * 0x1000000 + buf[0x1D7] * 0x100);
rel_num = buf[0x1DC] * 0x10000 + buf[0x1DA] + buf[0x1DD] * 0x1000000 + buf[0x1DB] * 0x100;
if (rel_sector == 0 || rel_num == 0) {
break;
}
err = pdm_disk_physical_read(p_part->p_disk, buf, rel_sector, 1, 0x200, &num_success);
if (err != 0) {
return err;
}
pdm_part_is_master_boot_sector(buf, p_part->p_disk->num_sectors, &is_mbr);
if (is_mbr == 0) {
break;
}
j = 0;
}
}
} else {
if (part_no == cnt) {
p_part->start_sector = rel_start;
p_part->num_sectors = rel_cnt;
return 0;
}
cnt++;
}
}
} else {
if (part_no >= 2) {
return 7;
}
p_part->start_sector = 0;
p_part->num_sectors = p_part->p_disk->num_sectors;
}
return 0;
}
u32 pdm_part_chg_ltop(PDM_PARTITION* p_part, u32 lsector, u16 lbps) {
u16 bps;
u32 shift;
u32 offset;
pdm_disk_get_media_bps(p_part->p_disk, &bps);
if (lbps == bps) {
return lsector + p_part->start_sector;
}
shift = (u32)bps >> 9;
offset = p_part->start_sector;
if (shift == 2) {
offset <<= 1;
} else if (shift == 4) {
offset <<= 2;
} else if (shift == 8) {
offset <<= 3;
}
shift = (u32)lbps >> 9;
if (shift == 2) {
offset >>= 1;
} else if (shift == 4) {
offset >>= 2;
} else if (shift == 8) {
offset >>= 3;
}
return lsector + offset;
}
s32 pdm_part_get_partition(PDM_DISK* p_disk, u32 part_no, PDM_PARTITION** pp_part) {
PDM_PARTITION* p_part;
u16 i;
s32 err;
*pp_part = NULL;
if (pdm_disk_set.num_partition >= 0x1A) {
return 0xA;
}
for (i = 0; i < 0x1A; i++) {
if (!(pdm_disk_set.part_table[i].stat & 1)) {
break;
}
}
if (i == 0x1A) {
return 0xA;
}
err = pdm_disk_set_disk(p_disk, &pdm_disk_set.part_table[i]);
if (err != 0) {
return err;
}
pdm_disk_set.num_partition += 1;
pdm_disk_set.part_table[i].stat |= 1;
pdm_disk_set.part_table[i].p_disk = p_disk;
pdm_disk_set.part_table[i].part_no = part_no;
*pp_part = &pdm_disk_set.part_table[i];
return 0;
}
s32 pdm_part_release_partition(PDM_PARTITION* p_part) {
p_part->stat &= ~1;
pdm_disk_set.num_partition -= 1;
return 0;
}
s32 pdm_part_is_attached_partition(PDM_PARTITION* p_part) {
return (p_part->stat & 4) >> 2;
}
void pdm_part_set_driver_error_code(PDM_PARTITION* p_part, s32 error_code) {
p_part->driver_error_code = error_code;
}
s32 pdm_part_get_driver_error_code(PDM_PARTITION* p_part) {
return p_part->driver_error_code;
}
s32 pdm_part_get_media_attribute(PDM_PARTITION* p_part) {
s32 err;
err = pdm_disk_get_media_attribute(p_part->p_disk);
if (err != 0) {
return err;
}
return 0;
}
s32 pdm_part_init(PDM_PARTITION* p_part) {
s32 err;
if ((p_part->stat & 4) == 0) {
err = pdm_disk_set_disk(p_part->p_disk, p_part);
if (err != 0) {
return err;
}
err = pdm_disk_init(p_part->p_disk);
if (err != 0) {
return err;
}
} else {
return 0xB;
}
p_part->stat |= 4;
return 0;
}
s32 pdm_part_mount(PDM_PARTITION* p_part) {
s32 err;
if ((p_part->stat & 8) == 0) {
err = pdm_disk_set_disk(p_part->p_disk, p_part);
if (err != 0) {
return err;
}
err = pdm_disk_mount(p_part->p_disk);
if (err != 0) {
return err;
}
err = pdm_part_get_start_sector(p_part);
if (err != 0) {
pdm_disk_unmount(p_part->p_disk, 0);
return err;
}
} else {
return 0xC;
}
p_part->stat = (p_part->stat & ~2) | 8;
return 0;
}
s32 pdm_part_format(PDM_PARTITION* p_part, u8* param) {
s32 err;
err = pdm_disk_set_disk(p_part->p_disk, p_part);
if (err != 0) {
return err;
}
err = pdm_disk_format(p_part->p_disk, param);
if (err != 0) {
return err;
}
return 0;
}
s32 pdm_part_logical_read(PDM_PARTITION* p_part, u8* buf, u32 lsector, u32 num_sector, u16 lbps, u32* p_num_success) {
s32 err;
if ((p_part->stat & 8) != 8 || (p_part->stat & 2) == 2) {
return 0xF;
}
err = pdm_disk_set_disk(p_part->p_disk, p_part);
if (err != 0) {
return err;
}
if (p_part->num_sectors <= lsector) {
return 0x12;
}
if (p_part->num_sectors < lsector + num_sector) {
num_sector -= lsector + num_sector - p_part->num_sectors;
}
err = pdm_disk_physical_read(p_part->p_disk, buf, pdm_part_chg_ltop(p_part, lsector, lbps), num_sector, lbps, p_num_success);
if (err != 0) {
return err;
}
return 0;
}
s32 pdm_part_logical_write(PDM_PARTITION* p_part, const u8* buf, u32 lsector, u32 num_sector, u16 lbps, u32* p_num_success) {
s32 err;
if ((p_part->stat & 8) != 8 || (p_part->stat & 2) == 2) {
return 0xF;
}
err = pdm_disk_set_disk(p_part->p_disk, p_part);
if (err != 0) {
return err;
}
if (p_part->num_sectors <= lsector) {
return 0x12;
}
if (p_part->num_sectors < lsector + num_sector) {
num_sector -= lsector + num_sector - p_part->num_sectors;
}
err = pdm_disk_physical_write(p_part->p_disk, buf, pdm_part_chg_ltop(p_part, lsector, lbps), num_sector, lbps, p_num_success);
if (err != 0) {
return err;
}
return 0;
}
s32 pdm_part_unmount(PDM_PARTITION* p_part, u32 force) {
s32 err;
s32 err2;
err = 0;
if ((p_part->stat & 8) != 0) {
err2 = pdm_disk_set_disk(p_part->p_disk, p_part);
if (err2 != 0) {
return err2;
}
err2 = pdm_disk_unmount(p_part->p_disk, force);
if (err2 != 0) {
err = err2;
}
} else {
err = 0xE;
}
if (err == 0 || force == 1) {
p_part->stat &= ~2;
p_part->stat &= ~8;
}
return err;
}
s32 pdm_part_finalize(PDM_PARTITION* p_part) {
s32 err;
if ((p_part->stat & 4) != 0) {
err = pdm_disk_set_disk(p_part->p_disk, p_part);
if (err != 0) {
return err;
}
err = pdm_disk_finalize(p_part->p_disk);
if (err != 0) {
return err;
}
} else {
return 0xD;
}
p_part->stat &= ~4;
return 0;
}
s32 pdm_part_register_callback(PDM_PARTITION* p_part, PDM_PART_CALLBACK* callback) {
p_part->callback[0] = callback[0];
p_part->callback[1] = callback[1];
return 0;
}
s32 pdm_part_unregister_callback(PDM_PARTITION* p_part) {
p_part->callback[0] = NULL;
p_part->callback[1] = NULL;
return 0;
}
void pdm_part_set_change_media_state(PDM_DISK* p_disk, s32 state) {
PDM_PARTITION* p_part;
u16 i;
for (i = 0; i < 0x1A; i++) {
p_part = &pdm_disk_set.part_table[i];
if (!(pdm_disk_set.part_table[i].stat & 1)) {
continue;
}
if (pdm_disk_set.part_table[i].p_disk != p_disk) {
continue;
}
pdm_disk_set.part_table[i].stat |= 2;
if (state == 0 && pdm_disk_set.part_table[i].callback[1] != NULL) {
pdm_disk_set.part_table[i].callback[1](p_part);
} else {
if (pdm_disk_set.part_table[i].callback[0] != NULL) {
pdm_disk_set.part_table[i].callback[0](p_part);
}
}
}
}

File diff suppressed because it is too large Load Diff

1649
libs/RVL_SDK/src/fa/pf_fat.c Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff