*Changed back to old install function. This one never freezes or codedumps (i hope so).

This commit is contained in:
dimok321 2009-05-12 21:19:51 +00:00
parent 4093776c3b
commit 5fabf08980

View File

@ -394,95 +394,90 @@ static void free_block(wbfs_t *p,int bl)
u32 v = wbfs_ntohl(p->freeblks[i]); u32 v = wbfs_ntohl(p->freeblks[i]);
p->freeblks[i] = wbfs_htonl(v | 1<<j); p->freeblks[i] = wbfs_htonl(v | 1<<j);
} }
u32 wbfs_add_disc(wbfs_t*p,read_wiidisc_callback_t read_src_wii_disc, u32 wbfs_add_disc(wbfs_t*p,read_wiidisc_callback_t read_src_wii_disc,
void *callback_data,progress_callback_t spinner,partition_selector_t sel,int copy_1_1) void *callback_data,progress_callback_t spinner,partition_selector_t sel,int copy_1_1)
{ {
int i,discn; int i,discn;
u32 tot,cur; u32 tot,cur;
u32 wii_sec_per_wbfs_sect = 1<<(p->wbfs_sec_sz_s-p->wii_sec_sz_s); u32 wii_sec_per_wbfs_sect = 1<<(p->wbfs_sec_sz_s-p->wii_sec_sz_s);
wiidisc_t *d = 0; wiidisc_t *d = 0;
u8 *used = 0; u8 *used = 0;
wbfs_disc_info_t *info = 0; wbfs_disc_info_t *info = 0;
u8* copy_buffer = 0; u8* copy_buffer = 0;
used = wbfs_malloc(p->n_wii_sec_per_disc); used = wbfs_malloc(p->n_wii_sec_per_disc);
if(!used) if(!used)
ERROR("unable to alloc memory"); ERROR("unable to alloc memory");
if(!copy_1_1) if(!copy_1_1)
{ {
d = wd_open_disc(read_src_wii_disc,callback_data); d = wd_open_disc(read_src_wii_disc,callback_data);
if(!d) if(!d)
ERROR("unable to open wii disc"); ERROR("unable to open wii disc");
wd_build_disc_usage(d,sel,used); wd_build_disc_usage(d,sel,used);
wd_close_disc(d); wd_close_disc(d);
d = 0; d = 0;
} }
for(i=0;i<p->max_disc;i++)// find a free slot. for(i=0;i<p->max_disc;i++)// find a free slot.
if(p->head->disc_table[i]==0) if(p->head->disc_table[i]==0)
break; break;
if(i==p->max_disc) if(i==p->max_disc)
ERROR("no space left on device (table full)"); ERROR("no space left on device (table full)");
p->head->disc_table[i] = 1; p->head->disc_table[i] = 1;
discn = i; discn = i;
load_freeblocks(p); load_freeblocks(p);
// build disc info // build disc info
info = wbfs_ioalloc(p->disc_info_sz); info = wbfs_ioalloc(p->disc_info_sz);
read_src_wii_disc(callback_data,0,0x100,info->disc_header_copy); read_src_wii_disc(callback_data,0,0x100,info->disc_header_copy);
copy_buffer = wbfs_ioalloc(p->wii_sec_sz); copy_buffer = wbfs_ioalloc(p->wbfs_sec_sz);
if(!copy_buffer) if(!copy_buffer)
ERROR("alloc memory"); ERROR("alloc memory");
tot=0; tot=0;
cur=0; cur=0;
if(spinner){ if(spinner){
// count total number to write for spinner // count total number to write for spinner
for(i=0; i<p->n_wbfs_sec_per_disc;i++) for(i=0; i<p->n_wbfs_sec_per_disc;i++)
if(copy_1_1 || block_used(used,i,wii_sec_per_wbfs_sect)) tot += wii_sec_per_wbfs_sect; if(copy_1_1 || block_used(used,i,wii_sec_per_wbfs_sect)) tot++;
spinner(0,tot); spinner(0,tot);
} }
for(i=0; i<p->n_wbfs_sec_per_disc;i++){ for(i=0; i<p->n_wbfs_sec_per_disc;i++){
u16 bl = 0; u16 bl = 0;
if(copy_1_1 || block_used(used,i,wii_sec_per_wbfs_sect)) { if(copy_1_1 || block_used(used,i,wii_sec_per_wbfs_sect)) {
u16 j; bl = alloc_block(p);
if (bl==0xffff)
bl = alloc_block(p); ERROR("no space left on device (disc full)");
if (bl==0xffff) read_src_wii_disc(callback_data,i*(p->wbfs_sec_sz>>2),p->wbfs_sec_sz,copy_buffer);
ERROR("no space left on device (disc full)");
for(j=0; j<wii_sec_per_wbfs_sect;j++) { //fix the partition table.
u32 offset = (i*(p->wbfs_sec_sz>>2)) + (j*(p->wii_sec_sz>>2)); if(i==(0x40000>>p->wbfs_sec_sz_s))
wd_fix_partition_table(d, sel, copy_buffer+(0x40000&(p->wbfs_sec_sz-1)));
read_src_wii_disc(callback_data,offset,p->wii_sec_sz,copy_buffer);
p->write_hdsector(p->callback_data,p->part_lba+bl*(p->wbfs_sec_sz/p->hd_sec_sz),
//fix the partition table p->wbfs_sec_sz/p->hd_sec_sz,copy_buffer);
if(offset == (0x40000>>2)) cur++;
wd_fix_partition_table(d, sel, copy_buffer); if(spinner)
p->write_hdsector(p->callback_data,p->part_lba+bl*(p->wbfs_sec_sz/p->hd_sec_sz)+j*(p->wii_sec_sz/p->hd_sec_sz), spinner(cur,tot);
p->wii_sec_sz/p->hd_sec_sz,copy_buffer); }
cur++; info->wlba_table[i] = wbfs_htons(bl);
if(spinner) }
spinner(cur,tot); // write disc info
} int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
} p->write_hdsector(p->callback_data,p->part_lba+1+discn*disc_info_sz_lba,disc_info_sz_lba,info);
info->wlba_table[i] = wbfs_htons(bl); wbfs_sync(p);
} error:
// write disc info if(d)
int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s; wd_close_disc(d);
p->write_hdsector(p->callback_data,p->part_lba+1+discn*disc_info_sz_lba,disc_info_sz_lba,info); if(used)
wbfs_sync(p); wbfs_free(used);
error: if(info)
if(d) wbfs_iofree(info);
wd_close_disc(d); if(copy_buffer)
if(used) wbfs_iofree(copy_buffer);
wbfs_free(used); // init with all free blocks
if(info)
wbfs_iofree(info); return 0;
if(copy_buffer)
wbfs_iofree(copy_buffer);
// init with all free blocks
return 0;
} }
u32 wbfs_rm_disc(wbfs_t*p, u8* discid) u32 wbfs_rm_disc(wbfs_t*p, u8* discid)
{ {
@ -564,7 +559,6 @@ u32 wbfs_estimate_disc(
partition_selector_t sel) partition_selector_t sel)
{ {
u8 *b; u8 *b;
int disc_info_sz_lba;
int i; int i;
u32 tot; u32 tot;
u32 wii_sec_per_wbfs_sect = 1 << (p->wbfs_sec_sz_s-p->wii_sec_sz_s); u32 wii_sec_per_wbfs_sect = 1 << (p->wbfs_sec_sz_s-p->wii_sec_sz_s);