mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-17 16:59:17 +01:00
*Changed back to old install function. This one never freezes or codedumps (i hope so).
This commit is contained in:
parent
4093776c3b
commit
5fabf08980
@ -394,95 +394,90 @@ static void free_block(wbfs_t *p,int bl)
|
||||
u32 v = wbfs_ntohl(p->freeblks[i]);
|
||||
p->freeblks[i] = wbfs_htonl(v | 1<<j);
|
||||
}
|
||||
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)
|
||||
{
|
||||
int i,discn;
|
||||
u32 tot,cur;
|
||||
u32 wii_sec_per_wbfs_sect = 1<<(p->wbfs_sec_sz_s-p->wii_sec_sz_s);
|
||||
wiidisc_t *d = 0;
|
||||
u8 *used = 0;
|
||||
wbfs_disc_info_t *info = 0;
|
||||
u8* copy_buffer = 0;
|
||||
used = wbfs_malloc(p->n_wii_sec_per_disc);
|
||||
if(!used)
|
||||
ERROR("unable to alloc memory");
|
||||
if(!copy_1_1)
|
||||
{
|
||||
d = wd_open_disc(read_src_wii_disc,callback_data);
|
||||
if(!d)
|
||||
ERROR("unable to open wii disc");
|
||||
wd_build_disc_usage(d,sel,used);
|
||||
wd_close_disc(d);
|
||||
d = 0;
|
||||
}
|
||||
|
||||
|
||||
for(i=0;i<p->max_disc;i++)// find a free slot.
|
||||
if(p->head->disc_table[i]==0)
|
||||
break;
|
||||
if(i==p->max_disc)
|
||||
ERROR("no space left on device (table full)");
|
||||
p->head->disc_table[i] = 1;
|
||||
discn = i;
|
||||
load_freeblocks(p);
|
||||
|
||||
// build disc info
|
||||
info = wbfs_ioalloc(p->disc_info_sz);
|
||||
read_src_wii_disc(callback_data,0,0x100,info->disc_header_copy);
|
||||
|
||||
copy_buffer = wbfs_ioalloc(p->wii_sec_sz);
|
||||
if(!copy_buffer)
|
||||
ERROR("alloc memory");
|
||||
tot=0;
|
||||
cur=0;
|
||||
if(spinner){
|
||||
// count total number to write for spinner
|
||||
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;
|
||||
spinner(0,tot);
|
||||
}
|
||||
for(i=0; i<p->n_wbfs_sec_per_disc;i++){
|
||||
u16 bl = 0;
|
||||
if(copy_1_1 || block_used(used,i,wii_sec_per_wbfs_sect)) {
|
||||
u16 j;
|
||||
|
||||
bl = alloc_block(p);
|
||||
if (bl==0xffff)
|
||||
ERROR("no space left on device (disc full)");
|
||||
for(j=0; j<wii_sec_per_wbfs_sect;j++) {
|
||||
u32 offset = (i*(p->wbfs_sec_sz>>2)) + (j*(p->wii_sec_sz>>2));
|
||||
|
||||
read_src_wii_disc(callback_data,offset,p->wii_sec_sz,copy_buffer);
|
||||
|
||||
//fix the partition table
|
||||
if(offset == (0x40000>>2))
|
||||
wd_fix_partition_table(d, sel, copy_buffer);
|
||||
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),
|
||||
p->wii_sec_sz/p->hd_sec_sz,copy_buffer);
|
||||
cur++;
|
||||
if(spinner)
|
||||
spinner(cur,tot);
|
||||
}
|
||||
}
|
||||
info->wlba_table[i] = wbfs_htons(bl);
|
||||
}
|
||||
// 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);
|
||||
wbfs_sync(p);
|
||||
error:
|
||||
if(d)
|
||||
wd_close_disc(d);
|
||||
if(used)
|
||||
wbfs_free(used);
|
||||
if(info)
|
||||
wbfs_iofree(info);
|
||||
if(copy_buffer)
|
||||
wbfs_iofree(copy_buffer);
|
||||
// init with all free blocks
|
||||
|
||||
return 0;
|
||||
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)
|
||||
{
|
||||
int i,discn;
|
||||
u32 tot,cur;
|
||||
u32 wii_sec_per_wbfs_sect = 1<<(p->wbfs_sec_sz_s-p->wii_sec_sz_s);
|
||||
wiidisc_t *d = 0;
|
||||
u8 *used = 0;
|
||||
wbfs_disc_info_t *info = 0;
|
||||
u8* copy_buffer = 0;
|
||||
used = wbfs_malloc(p->n_wii_sec_per_disc);
|
||||
if(!used)
|
||||
ERROR("unable to alloc memory");
|
||||
if(!copy_1_1)
|
||||
{
|
||||
d = wd_open_disc(read_src_wii_disc,callback_data);
|
||||
if(!d)
|
||||
ERROR("unable to open wii disc");
|
||||
wd_build_disc_usage(d,sel,used);
|
||||
wd_close_disc(d);
|
||||
d = 0;
|
||||
}
|
||||
|
||||
|
||||
for(i=0;i<p->max_disc;i++)// find a free slot.
|
||||
if(p->head->disc_table[i]==0)
|
||||
break;
|
||||
if(i==p->max_disc)
|
||||
ERROR("no space left on device (table full)");
|
||||
p->head->disc_table[i] = 1;
|
||||
discn = i;
|
||||
load_freeblocks(p);
|
||||
|
||||
// build disc info
|
||||
info = wbfs_ioalloc(p->disc_info_sz);
|
||||
read_src_wii_disc(callback_data,0,0x100,info->disc_header_copy);
|
||||
|
||||
copy_buffer = wbfs_ioalloc(p->wbfs_sec_sz);
|
||||
if(!copy_buffer)
|
||||
ERROR("alloc memory");
|
||||
tot=0;
|
||||
cur=0;
|
||||
if(spinner){
|
||||
// count total number to write for spinner
|
||||
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++;
|
||||
spinner(0,tot);
|
||||
}
|
||||
for(i=0; i<p->n_wbfs_sec_per_disc;i++){
|
||||
u16 bl = 0;
|
||||
if(copy_1_1 || block_used(used,i,wii_sec_per_wbfs_sect)) {
|
||||
bl = alloc_block(p);
|
||||
if (bl==0xffff)
|
||||
ERROR("no space left on device (disc full)");
|
||||
read_src_wii_disc(callback_data,i*(p->wbfs_sec_sz>>2),p->wbfs_sec_sz,copy_buffer);
|
||||
|
||||
//fix the partition table.
|
||||
if(i==(0x40000>>p->wbfs_sec_sz_s))
|
||||
wd_fix_partition_table(d, sel, copy_buffer+(0x40000&(p->wbfs_sec_sz-1)));
|
||||
|
||||
p->write_hdsector(p->callback_data,p->part_lba+bl*(p->wbfs_sec_sz/p->hd_sec_sz),
|
||||
p->wbfs_sec_sz/p->hd_sec_sz,copy_buffer);
|
||||
cur++;
|
||||
if(spinner)
|
||||
spinner(cur,tot);
|
||||
}
|
||||
info->wlba_table[i] = wbfs_htons(bl);
|
||||
}
|
||||
// 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);
|
||||
wbfs_sync(p);
|
||||
error:
|
||||
if(d)
|
||||
wd_close_disc(d);
|
||||
if(used)
|
||||
wbfs_free(used);
|
||||
if(info)
|
||||
wbfs_iofree(info);
|
||||
if(copy_buffer)
|
||||
wbfs_iofree(copy_buffer);
|
||||
// init with all free blocks
|
||||
|
||||
return 0;
|
||||
}
|
||||
u32 wbfs_rm_disc(wbfs_t*p, u8* discid)
|
||||
{
|
||||
@ -564,7 +559,6 @@ u32 wbfs_estimate_disc(
|
||||
partition_selector_t sel)
|
||||
{
|
||||
u8 *b;
|
||||
int disc_info_sz_lba;
|
||||
int i;
|
||||
u32 tot;
|
||||
u32 wii_sec_per_wbfs_sect = 1 << (p->wbfs_sec_sz_s-p->wii_sec_sz_s);
|
||||
|
Loading…
Reference in New Issue
Block a user