11#include "accdvd_internal.h"
15static void cdfs_reset(
struct cdfs_softc *cdfsc)
38 v4 = ((path->name_len[0] | (path->name_len[1] << 8)) + 1) & 0xFFFFFFFE;
51static void cdfs_ready_done(
struct acd *
acd,
const struct cdfs_softc *arg,
int ret)
65 asc = (acUint16) - (ret & 0xFFFF);
66 if ( -ret >> 16 == 6 )
84 if ( acd_ready(
acd) < 0 )
93 SignalSema(arg->semid);
97static void cdfs_detach(
struct cdfs_softc *cdfsc)
106 ptr_v1 = cdfsc->pcache;
108 FreeSysMemory(ptr_v1);
109 ptr_v2 = cdfsc->dcache;
111 FreeSysMemory(ptr_v2);
115static int cdfs_attach(
struct cdfs_softc *cdfsc,
struct acd *
acd,
int remount)
125 semid = cdfsc->semid;
129 active = WaitSema(semid);
132 acd_setup((
struct acd *)cdfsc->buf, (acd_done_t)cdfs_ready_done, cdfsc, -5000000);
133 if ( acd_ready((
struct acd *)cdfsc->buf) < 0 )
135 if ( cdfsc->semid > 0 )
136 SignalSema(cdfsc->semid);
140 if ( cdfsc->semid > 0 )
141 active_v3 = WaitSema(cdfsc->semid);
146 active_v6 = cdfsc->all;
149 if ( active_v6 != 0 )
156 if ( active_v6 == 0 )
168 active_v12 = acd_read(
acd, v17, buf, 1);
170 if ( active_v12 < 0 )
172 printf(
"cdfs:super:read: error %d\n", active_v12);
175 if ( !strncmp((
const char *)buf + 1,
"CD001", 5u) )
180 if ( active_v13 == 255 )
182 printf(
"cdfs:%u:invalid descriptor\n", (
unsigned int)v17);
186 if ( active_v13 == 1 )
188 cdfsc->all = *((acUint32 *)buf + 20);
189 cdfsc->rootlsn = *(acUint32 *)(buf + 158);
190 cdfsc->rootsize = *(acUint32 *)(buf + 166);
206 ret_v14 = *(acUint32 *)&cdfsc->buf[132];
207 lsn = *(acUint32 *)&cdfsc->buf[140];
208 cdfsc->pcsize = ret_v14;
209 ret_v16 = (
unsigned int)(ret_v14 + 2047) >> 11;
211 pcache_v17 = (
struct iso9660_path *)AllocSysMemory(0, ret_v16 << 11, 0);
212 cdfsc->pcache = pcache_v17;
213 if ( pcache_v17 == 0 )
219 ret = acd_read(
acd, lsn, pcache_v17, ret_v16);
224 active_v18 = cdfs_path_init(0, cdfsc->pcache, cdfsc->pcsize);
225 cdfsc->ptnum = active_v18;
227 (8 * active_v18 == 0)
228 || (ptable_v19 = (
struct cdfs_ptable *)AllocSysMemory(0, 8 * active_v18, 0), (cdfsc->ptable = ptable_v19) != 0) )
235 n = cdfs_path_init(cdfsc->ptable, cdfsc->pcache, cdfsc->pcsize);
237 ptable = cdfsc->ptable;
241 if ( cdfsc->rootlsn == *(acUint32 *)ptable[active_v24].path->extent )
243 ptable[active_v24].size = cdfsc->rootsize;
256 printf(
"accdvd:cdfs:path_read: malloc failed\n");
267 if ( cdfsc->semid > 0 )
269 SignalSema(cdfsc->semid);
278 acd_setup(&v1, 0, 0, 5000000);
279 return cdfs_attach(&Cdfsc, &v1, 0);
286 if ( Cdfsc.semid <= 0 )
288 ret = WaitSema(Cdfsc.semid);
294 if ( Cdfsc.semid > 0 )
296 SignalSema(Cdfsc.semid);
301int cdfs_recover(
int ret)
311 if ( !(v1 >= 255 && (v1 >> 16 == 6 || (v1 & 0xFFFF) == 1025 || (v1 & 0xFFFF) == 10240)) )
313 v3 = cdfs_attach(&Cdfsc, &acd_data, 1);
320int cdfs_lookup(
struct cdfs_dirent *result,
const char *path,
int pathlen)
361 const acUint8 *len_v43;
363 unsigned char *s2_v45;
374 acd_setup(&acd_data, 0, 0, 5000000);
381 if ( Cdfsc.semid > 0 )
382 v6 = WaitSema(Cdfsc.semid);
392 if ( pathlen <= 0 || *path == 92 )
413 dcsize = Cdfsc.dcsize;
414 pt = &path_v24->name_len[(
unsigned int)Cdfsc.ptable];
415 v33 = *(acUint32 *)&path_v24->extent[(
unsigned int)Cdfsc.ptable + 2];
416 lsn = *(acUint32 *)(*(acUint32 *)pt + 2);
419 if ( lsn != Cdfsc.dclsn )
421 ret_v30 = acd_read(
acd, lsn, Cdfsc.buf, 1);
436 v40 = dirent_v32->length[0];
437 if ( !dirent_v32->length[0] )
439 if ( dirent_v32->name_len[0] == 1 && !dirent_v32->name[0] )
441 v33 = *(acUint32 *)dirent_v32->size;
447 *((acUint32 *)pt + 1) = v33;
456 n = (
unsigned int)ret_v31 >> 11;
457 if ( dcsize >= (
unsigned int)ret_v31 >> 11 )
459 dirent_v37 = Cdfsc.dcache;
464 FreeSysMemory(Cdfsc.dcache);
465 path_v36 = (
struct iso9660_path *)AllocSysMemory(0, n << 11, 0);
466 dirent_v37 = path_v36;
481 if ( acd_read(
acd, lsn + 1, dirent_v37, n) < 0 )
501 for ( i_v40 = 1; i_v40 >= 0; --i_v40 )
509 if ( size_v29 < 2048 )
514 v48 = dirent_v38->length[0];
519 if ( namlen == dirent_v38->name_len[0] )
521 len_v43 = (acUint8 *)name_v8;
522 idx_v44 = namlen - 1;
523 s2_v45 = dirent_v38->name;
524 while ( idx_v44 >= 0 )
528 if ( *s2_v45++ != v52 )
540 path_v48 = (
char *)dirent_v38;
546 rest -= dirent_v38->length[0];
558 dirent_v38 = (
struct iso9660_dirent *)((
char *)dirent_v38 + rest);
564 dirent_v38 = Cdfsc.dcache;
565 v55 = size_v29 + 2047;
566 if ( size_v29 + 2047 < 0 )
567 v55 = size_v29 + 4094;
578 result->d_lsn = *(acUint32 *)(dirent + 2);
579 result->d_size = *(acUint32 *)(dirent + 10);
580 result->d_vol = (dirent[28] & 0xFF) | ((dirent[29] & 0xFF) << 8);
582 result->d_ftype = dirent[25];
583 result->d_namlen = v57;
585 result->d_name[t0] = 0;
586 d_namlen = result->d_namlen;
587 result->d_time.t_mon = dirent[19];
588 result->d_time.t_day = dirent[20];
589 result->d_time.t_hour = dirent[21];
590 result->d_time.t_padding = 0;
591 result->d_time.t_min = dirent[22];
592 result->d_time.t_sec = dirent[23];
593 result->d_time.t_year = (dirent[18] & 0xFF) + 1900;
594 memcpy(result->d_name, dirent + 33, d_namlen);
599 namlen_v9 = namlen - len;
601 if ( namlen_v9 && (namlen_v9 != 1 || name_v8->length[0] != 46) )
603 if ( namlen_v9 == 2 && name_v8->length[0] == 46 && name_v8->ext_attr_length[0] == 46 )
605 idx = (Cdfsc.ptable[idx].path->parent[0] | (Cdfsc.ptable[idx].path->parent[1] << 8)) - 1;
621 path_v16 = Cdfsc.ptable[ret / 2].path;
622 v23 = path_v16->parent[1] << 8;
623 ret_v18 = (path_v16->parent[0] | v23) - 1 - idx_v10;
624 if ( (path_v16->parent[0] | v23) - 1 == idx_v10 )
626 len_v19 = path_v16->name_len[0] | (path_v16->name_len[1] << 8);
628 if ( namlen_v9 < len_v19 )
630 idx_v21 = len_v19 - 1;
631 dirent_v22 = name_v8;
632 while ( idx_v21 >= 0 )
634 len_v23 = dirent_v22->length[0];
636 ret_v18 = *s2 - len_v23;
637 if ( *s2++ != len_v23 )
669 if ( Cdfsc.semid > 0 )
670 SignalSema(Cdfsc.semid);
673 if ( Cdfsc.semid > 0 )
674 SignalSema(Cdfsc.semid);
675 v8 = cdfs_attach(&Cdfsc, &acd_data, 1);
681int cdfs_read(
struct cdfs_file *file,
void *buf,
int size)
690 unsigned int cpos_v14;
691 unsigned int npos_v15;
692 unsigned int npos_v16;
693 unsigned int lsn_v17;
695 unsigned char *data_v33;
697 unsigned int cpos_v35;
698 unsigned int npos_v36;
700 unsigned int lsn_v38;
706 acd_setup(&acd_data, 0, 0, 5000000);
708 f_size = file->f_size;
710 npos = cpos - (off - 2048);
711 if ( (cpos & 0x7FF) == 0 )
720 if ( cpos + size < f_size )
722 f_size = cpos + size;
724 len = 2048 - (cpos & 0x7FF);
730 lsn = file->f_lsn + (cpos >> 11);
740 if ( Cdfsc.semid > 0 )
741 ret_v8 = WaitSema(Cdfsc.semid);
752 if ( Cdfsc.dclsn == lsn )
759 ret_v10 = acd_read(&acd_data, lsn, Cdfsc.buf, 1);
769 memcpy(buf, &Cdfsc.buf[off], len);
773 if ( Cdfsc.semid > 0 )
774 SignalSema(Cdfsc.semid);
779 data = (
unsigned char *)buf + ret;
783 cpos_v14 = file->f_pos;
784 npos_v15 = cpos_v14 + rest;
785 if ( file->f_size < cpos_v14 + rest )
786 npos_v15 = file->f_size;
787 npos_v16 = npos_v15 - (npos_v15 & 0x7FF);
788 lsn_v17 = file->f_lsn + (cpos_v14 >> 11);
789 len_v18 = npos_v16 - cpos_v14;
790 if ( (
int)(npos_v16 - cpos_v14) < 2048 )
799 if ( ((uiptr)data & 3) == 0 )
803 ret_v32 = acd_read(&acd_data, file->f_lsn + (cpos_v14 >> 11), data, len_v18 / 2048);
807 file->f_pos = npos_v16;
816 rest_v20 = npos_v16 - cpos_v14;
828 if ( Cdfsc.semid > 0 )
829 ret_v21 = WaitSema(Cdfsc.semid);
838 if ( Cdfsc.dclsn == lsn_v17 )
845 ret_v22 = acd_read(&acd_data, lsn_v17, Cdfsc.buf, 1);
855 memcpy(ptr, &Cdfsc,
sizeof(Cdfsc));
858 Cdfsc.dclsn = lsn_v17++;
859 if ( Cdfsc.semid > 0 )
860 SignalSema(Cdfsc.semid);
866 file->f_pos = npos_v16;
870 data_v33 = &data[ret];
873 rest_v34 = rest - ret;
874 cpos_v35 = file->f_pos;
875 npos_v36 = cpos_v35 + rest_v34;
876 if ( file->f_size < cpos_v35 + rest_v34 )
877 npos_v36 = file->f_size;
878 len_v37 = npos_v36 - cpos_v35;
879 lsn_v38 = file->f_lsn + (cpos_v35 >> 11);
881 if ( (
int)(npos_v36 - cpos_v35) > 0 )
886 if ( Cdfsc.semid > 0 )
887 ret_v39 = WaitSema(Cdfsc.semid);
901 if ( Cdfsc.dclsn == lsn_v38 )
908 ret_v40 = acd_read(&acd_data, lsn_v38, Cdfsc.buf, 1);
918 memcpy(data_v33, Cdfsc.buf, len_v37);
919 file->f_pos = npos_v36;
921 Cdfsc.dclsn = lsn_v38;
922 if ( Cdfsc.semid > 0 )
923 SignalSema(Cdfsc.semid);
927 rest_v42 = rest_v34 - ret;
929 return size - rest_v42;
933int cdfs_module_status()
935 return Cdfsc.semid > 0;
938int cdfs_module_start(
int argc,
char **argv)
947 ret = cdfs_module_status();
956 v4 = CreateSema(¶m);
959 printf(
"accdvd:cdfs:sem_alloc: error %d\n", v4);
967int cdfs_module_stop()
972 ret = cdfs_module_status();
980 if ( Cdfsc.semid > 0 )
981 WaitSema(Cdfsc.semid);
991int cdfs_module_restart(
int argc,
char **argv)
u32 count
start sector of fragmented bd/file