Skip to content
Browse files

applied latest patches from kwiirk

added info about filling empty space in extracted image
  • Loading branch information...
1 parent ce1d7fa commit ce8b2dbe2da1596355ef52fbd5eba200775e6990 caristat committed Apr 20, 2009
View
2 Makefile 100644 → 100755
@@ -1,5 +1,5 @@
PROGS = negentig scrub wbfs
-COMMON = tools.o bn.o ec.o disc_usage_table.o libwbfs.o libwbfs_linux.o wiidisc.o rijndael.o
+COMMON = tools.o bn.o ec.o disc_usage_table.o libwbfs.o libwbfs_unix.o wiidisc.o rijndael.o
DEFINES = -DLARGE_FILES -D_FILE_OFFSET_BITS=64
LIBS = -lcrypto
View
0 README 100644 → 100755
File mode changed.
View
0 TODO.txt 100644 → 100755
File mode changed.
View
0 bn.c 100644 → 100755
File mode changed.
View
0 disc_usage_table.c 100644 → 100755
File mode changed.
View
0 ec.c 100644 → 100755
File mode changed.
View
0 gpl-2.0.txt 100644 → 100755
File mode changed.
View
0 icon.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
718 libwbfs/libwbfs.c 100644 → 100755
@@ -19,20 +19,23 @@
static int force_mode=0;
+
void wbfs_set_force_mode(int force)
{
- force_mode = force;
+ force_mode = force;
}
+
static u8 size_to_shift(u32 size)
{
- u8 ret = 0;
- while(size)
- {
- ret++;
- size>>=1;
- }
- return ret-1;
+ u8 ret = 0;
+ while (size)
+ {
+ ret++;
+ size>>=1;
+ }
+ return ret-1;
}
+
#define read_le32_unaligned(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24))
void wbfs_sync(wbfs_t*p);
@@ -44,38 +47,38 @@ wbfs_t*wbfs_open_hd(
close_callback_t close_hd,
#endif
void *callback_data,
- int hd_sector_size,
+ int hd_sector_size,
#ifdef WIN32
int num_hd_sector,
#else
- int num_hd_sector __attribute((unused)),
+ int num_hd_sector __attribute((unused)),
#endif
- int reset)
+ int reset)
{
- int i
+ int i
#ifdef UNUSED_STUFF
- = num_hd_sector
+ = num_hd_sector
#endif
- , ret;
- u8 *ptr,*tmp_buffer = wbfs_ioalloc(hd_sector_size);
- u8 part_table[16*4];
- ret = read_hdsector(callback_data,0,1,tmp_buffer);
- if(ret)
- return 0;
- //find wbfs partition
- wbfs_memcpy(part_table,tmp_buffer+0x1be,16*4);
- ptr = part_table;
- for(i=0;i<4;i++,ptr+=16)
- {
- u32 part_lba = read_le32_unaligned(ptr+0x8);
- wbfs_head_t *head = (wbfs_head_t *)tmp_buffer;
+ , ret;
+ u8 *ptr,*tmp_buffer = wbfs_ioalloc(hd_sector_size);
+ u8 part_table[16*4];
+ ret = read_hdsector(callback_data,0,1,tmp_buffer);
+ if(ret)
+ return 0;
+ //find wbfs partition
+ wbfs_memcpy(part_table,tmp_buffer+0x1be,16*4);
+ ptr = part_table;
+ for(i=0;i<4;i++,ptr+=16)
+ {
+ u32 part_lba = read_le32_unaligned(ptr+0x8);
+ wbfs_head_t *head = (wbfs_head_t *)tmp_buffer;
#ifdef UNUSED_STUFF
- ret =
+ ret =
#endif
read_hdsector(callback_data,part_lba,1,tmp_buffer);
- // verify there is the magic.
- if (head->magic == wbfs_htonl(WBFS_MAGIC))
- {
+ // verify there is the magic.
+ if (head->magic == wbfs_htonl(WBFS_MAGIC))
+ {
wbfs_t *p = wbfs_open_partition( read_hdsector,
write_hdsector,
#ifdef WIN32
@@ -87,12 +90,12 @@ wbfs_t*wbfs_open_hd(
part_lba,reset
);
return p;
- }
- }
- if(reset)// XXX make a empty hd partition..
- {
- }
- return 0;
+ }
+ }
+ if(reset)// XXX make a empty hd partition..
+ {
+ }
+ return 0;
}
wbfs_t*wbfs_open_partition(rw_sector_callback_t read_hdsector,
rw_sector_callback_t write_hdsector,
@@ -102,321 +105,323 @@ wbfs_t*wbfs_open_partition(rw_sector_callback_t read_hdsector,
void *callback_data,
int hd_sector_size, int num_hd_sector, u32 part_lba, int reset)
{
- wbfs_t *p = wbfs_malloc(sizeof(wbfs_t));
-
- wbfs_head_t *head = wbfs_ioalloc(hd_sector_size?hd_sector_size:512);
-
- //constants, but put here for consistancy
- p->wii_sec_sz = 0x8000;
- p->wii_sec_sz_s = size_to_shift(0x8000);
- p->n_wii_sec = (num_hd_sector/0x8000)*hd_sector_size;
- p->n_wii_sec_per_disc = 143432*2;//support for double layers discs..
- p->head = head;
- p->part_lba = part_lba;
- // init the partition
- if (reset)
- {
- u8 sz_s;
- wbfs_memset(head,0,hd_sector_size);
- head->magic = wbfs_htonl(WBFS_MAGIC);
- head->hd_sec_sz_s = size_to_shift(hd_sector_size);
- head->n_hd_sec = wbfs_htonl(num_hd_sector);
- // choose minimum wblk_sz that fits this partition size
- for(sz_s=6;sz_s<11;sz_s++)
- {
- // ensure that wbfs_sec_sz is big enough to address every blocks using 16 bits
- if(p->n_wii_sec <((1U<<16)*(1<<sz_s)))
- break;
- }
- head->wbfs_sec_sz_s = sz_s+p->wii_sec_sz_s;
- }else
- read_hdsector(callback_data,p->part_lba,1,head);
- if (head->magic != wbfs_htonl(WBFS_MAGIC))
- ERROR("bad magic");
- if(!force_mode && hd_sector_size && head->hd_sec_sz_s != size_to_shift(hd_sector_size))
- ERROR("hd sector size doesn't match");
- if(!force_mode && num_hd_sector && head->n_hd_sec != wbfs_htonl(num_hd_sector))
- ERROR("hd num sector doesn't match");
- p->hd_sec_sz = 1<<head->hd_sec_sz_s;
- p->hd_sec_sz_s = head->hd_sec_sz_s;
- p->n_hd_sec = wbfs_ntohl(head->n_hd_sec);
-
- p->n_wii_sec = (p->n_hd_sec/p->wii_sec_sz)*(p->hd_sec_sz);
-
- p->wbfs_sec_sz_s = head->wbfs_sec_sz_s;
- p->wbfs_sec_sz = 1<<p->wbfs_sec_sz_s;
- p->n_wbfs_sec = p->n_wii_sec >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s);
- p->n_wbfs_sec_per_disc = p->n_wii_sec_per_disc >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s);
- p->disc_info_sz = ALIGN_LBA(sizeof(wbfs_disc_info_t) + p->n_wbfs_sec_per_disc*2);
-
- //printf("hd_sector_size %X wii_sector size %X wbfs sector_size %X\n",p->hd_sec_sz,p->wii_sec_sz,p->wbfs_sec_sz);
- p->read_hdsector = read_hdsector;
- p->write_hdsector = write_hdsector;
+ wbfs_t *p = wbfs_malloc(sizeof(wbfs_t));
+
+ wbfs_head_t *head = wbfs_ioalloc(hd_sector_size?hd_sector_size:512);
+
+ //constants, but put here for consistancy
+ p->wii_sec_sz = 0x8000;
+ p->wii_sec_sz_s = size_to_shift(0x8000);
+ p->n_wii_sec = (num_hd_sector/0x8000)*hd_sector_size;
+ p->n_wii_sec_per_disc = 143432*2;//support for double layers discs..
+ p->head = head;
+ p->part_lba = part_lba;
+ // init the partition
+ if (reset)
+ {
+ u8 sz_s;
+ wbfs_memset(head,0,hd_sector_size);
+ head->magic = wbfs_htonl(WBFS_MAGIC);
+ head->hd_sec_sz_s = size_to_shift(hd_sector_size);
+ head->n_hd_sec = wbfs_htonl(num_hd_sector);
+ // choose minimum wblk_sz that fits this partition size
+ for(sz_s=6;sz_s<11;sz_s++)
+ {
+ // ensure that wbfs_sec_sz is big enough to address every blocks using 16 bits
+ if(p->n_wii_sec <((1U<<16)*(1<<sz_s)))
+ break;
+ }
+ head->wbfs_sec_sz_s = sz_s+p->wii_sec_sz_s;
+ } else
+ read_hdsector(callback_data,p->part_lba,1,head);
+ if (head->magic != wbfs_htonl(WBFS_MAGIC))
+ ERROR("bad magic");
+ if(!force_mode && hd_sector_size && head->hd_sec_sz_s != size_to_shift(hd_sector_size))
+ ERROR("hd sector size doesn't match");
+ if(!force_mode && num_hd_sector && head->n_hd_sec != wbfs_htonl(num_hd_sector))
+ ERROR("hd num sector doesn't match");
+ p->hd_sec_sz = 1<<head->hd_sec_sz_s;
+ p->hd_sec_sz_s = head->hd_sec_sz_s;
+ p->n_hd_sec = wbfs_ntohl(head->n_hd_sec);
+
+ p->n_wii_sec = (p->n_hd_sec/p->wii_sec_sz)*(p->hd_sec_sz);
+
+ p->wbfs_sec_sz_s = head->wbfs_sec_sz_s;
+ p->wbfs_sec_sz = 1<<p->wbfs_sec_sz_s;
+ p->n_wbfs_sec = p->n_wii_sec >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s);
+ p->n_wbfs_sec_per_disc = p->n_wii_sec_per_disc >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s);
+ p->disc_info_sz = ALIGN_LBA(sizeof(wbfs_disc_info_t) + p->n_wbfs_sec_per_disc*2);
+
+ //printf("hd_sector_size %X wii_sector size %X wbfs sector_size %X\n",p->hd_sec_sz,p->wii_sec_sz,p->wbfs_sec_sz);
+ p->read_hdsector = read_hdsector;
+ p->write_hdsector = write_hdsector;
#ifdef WIN32
p->close_hd = close_hd;
#endif
- p->callback_data = callback_data;
-
- p->freeblks_lba = (p->wbfs_sec_sz - p->n_wbfs_sec/8)>>p->hd_sec_sz_s;
-
- if(!reset)
- p->freeblks = 0; // will alloc and read only if needed
- else
- {
- // init with all free blocks
- p->freeblks = wbfs_ioalloc(ALIGN_LBA(p->n_wbfs_sec/8));
- wbfs_memset(p->freeblks,0xff,p->n_wbfs_sec/8);
- }
- p->max_disc = (p->freeblks_lba-1)/(p->disc_info_sz>>p->hd_sec_sz_s);
- if(p->max_disc > p->hd_sec_sz - sizeof(wbfs_head_t))
- p->max_disc = p->hd_sec_sz - sizeof(wbfs_head_t);
-
- p->tmp_buffer = wbfs_ioalloc(p->hd_sec_sz);
- p->n_disc_open = 0;
- wbfs_sync(p);
- return p;
+ p->callback_data = callback_data;
+
+ p->freeblks_lba = (p->wbfs_sec_sz - p->n_wbfs_sec/8)>>p->hd_sec_sz_s;
+
+ if(!reset)
+ p->freeblks = 0; // will alloc and read only if needed
+ else
+ {
+ // init with all free blocks
+ p->freeblks = wbfs_ioalloc(ALIGN_LBA(p->n_wbfs_sec/8));
+ wbfs_memset(p->freeblks,0xff,p->n_wbfs_sec/8);
+ }
+ p->max_disc = (p->freeblks_lba-1)/(p->disc_info_sz>>p->hd_sec_sz_s);
+ if(p->max_disc > p->hd_sec_sz - sizeof(wbfs_head_t))
+ p->max_disc = p->hd_sec_sz - sizeof(wbfs_head_t);
+
+ p->tmp_buffer = wbfs_ioalloc(p->hd_sec_sz);
+ p->n_disc_open = 0;
+ wbfs_sync(p);
+ return p;
error:
- wbfs_free(p);
- wbfs_iofree(head);
+ wbfs_free(p);
+ wbfs_iofree(head);
return 0;
-
+
}
void wbfs_sync(wbfs_t*p)
{
- // copy back descriptors
- if(p->write_hdsector){
- p->write_hdsector(p->callback_data,p->part_lba+0,1, p->head);
-
- if(p->freeblks) {
+ // copy back descriptors
+ if(p->write_hdsector){
+ p->write_hdsector(p->callback_data,p->part_lba+0,1, p->head);
+
+ if(p->freeblks) {
p->write_hdsector(p->callback_data,p->part_lba+p->freeblks_lba,ALIGN_LBA(p->n_wbfs_sec/8)>>p->hd_sec_sz_s, p->freeblks);
- }
+ }
- }
+ }
}
void wbfs_close(wbfs_t*p)
{
- wbfs_sync(p);
+ wbfs_sync(p);
- if(p->n_disc_open)
- ERROR("trying to close wbfs while discs still open");
+ if(p->n_disc_open)
+ ERROR("trying to close wbfs while discs still open");
- wbfs_iofree(p->head);
- wbfs_iofree(p->tmp_buffer);
- if(p->freeblks)
- wbfs_iofree(p->freeblks);
-
+ wbfs_iofree(p->head);
+ wbfs_iofree(p->tmp_buffer);
+ if(p->freeblks)
+ wbfs_iofree(p->freeblks);
+
#ifdef WIN32
p->close_hd(p->callback_data);
#endif
- wbfs_free(p);
-
+ wbfs_free(p);
+
error:
- return;
+ return;
}
wbfs_disc_t *wbfs_open_disc(wbfs_t* p, u8 *discid)
{
- u32 i;
- int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
- wbfs_disc_t *d = 0;
- for(i=0;i<p->max_disc;i++)
- {
- if (p->head->disc_table[i]){
- p->read_hdsector(p->callback_data,
- p->part_lba+1+i*disc_info_sz_lba,1,p->tmp_buffer);
+ u32 i;
+ int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
+ wbfs_disc_t *d = 0;
+ for(i=0;i<p->max_disc;i++)
+ {
+ if (p->head->disc_table[i]){
+ p->read_hdsector(p->callback_data,
+ p->part_lba+1+i*disc_info_sz_lba,1,p->tmp_buffer);
#ifdef WIN32
- if(_strnicmp(discid,p->tmp_buffer,6)==0){
+ if(_strnicmp(discid,p->tmp_buffer,6)==0){
#else
- if(wbfs_memcmp(discid,p->tmp_buffer,6)==0){
+ if(wbfs_memcmp(discid,p->tmp_buffer,6)==0){
#endif
- d = wbfs_malloc(sizeof(*d));
- if(!d)
- ERROR("allocating memory");
- d->p = p;
- d->i = i;
- d->header = wbfs_ioalloc(p->disc_info_sz);
- if(!d->header)
- ERROR("allocating memory");
- p->read_hdsector(p->callback_data,
- p->part_lba+1+i*disc_info_sz_lba,
- disc_info_sz_lba,d->header);
- p->n_disc_open ++;
-// for(i=0;i<p->n_wbfs_sec_per_disc;i++)
-// printf("%d,",wbfs_ntohs(d->header->wlba_table[i]));
- return d;
- }
- }
- }
+ d = wbfs_malloc(sizeof(*d));
+ if(!d)
+ ERROR("allocating memory");
+ d->p = p;
+ d->i = i;
+ d->header = wbfs_ioalloc(p->disc_info_sz);
+ if(!d->header)
+ ERROR("allocating memory");
+ p->read_hdsector(p->callback_data,
+ p->part_lba+1+i*disc_info_sz_lba,
+ disc_info_sz_lba,d->header);
+ p->n_disc_open ++;
+// for(i=0;i<p->n_wbfs_sec_per_disc;i++)
+// printf("%d,",wbfs_ntohs(d->header->wlba_table[i]));
+ return d;
+ }
+ }
+ }
#ifdef WIN32
_set_errno(ENOENT);
#endif
- return 0;
+ return 0;
error:
- if(d) {
+ if (d) {
wbfs_iofree(d);
}
#ifdef WIN32
_set_errno(ENOENT);
#endif
- return 0;
-
+ return 0;
+
}
void wbfs_close_disc(wbfs_disc_t*d)
{
- d->p->n_disc_open --;
- wbfs_iofree(d->header);
- wbfs_free(d);
+ d->p->n_disc_open --;
+ wbfs_iofree(d->header);
+ wbfs_free(d);
}
// offset is pointing 32bit words to address the whole dvd, although len is in bytes
-int wbfs_disc_read(wbfs_disc_t*d,u32 offset, u8 *data, u32 len)
+int wbfs_disc_read(wbfs_disc_t *d, u32 offset, u8 *data, u32 len)
{
- wbfs_t *p = d->p;
- u16 wlba = offset>>(p->wbfs_sec_sz_s-2);
- u32 iwlba_shift = p->wbfs_sec_sz_s - p->hd_sec_sz_s;
- u32 lba_mask = (p->wbfs_sec_sz-1)>>(p->hd_sec_sz_s);
- u32 lba = (offset>>(p->hd_sec_sz_s-2))&lba_mask;
- u32 off = offset&((p->hd_sec_sz>>2)-1);
- u16 iwlba = wbfs_ntohs(d->header->wlba_table[wlba]);
- u32 len_copied;
- int err = 0;
- u8 *ptr = data;
- if(unlikely(iwlba==0))
- return 1;
- if(unlikely(off)){
- off*=4;
- err = p->read_hdsector(p->callback_data,
- p->part_lba + (iwlba<<iwlba_shift) + lba, 1, p->tmp_buffer);
- if(err)
- return err;
- len_copied = p->hd_sec_sz - off;
- if(likely(len < len_copied))
- len_copied = len;
- wbfs_memcpy(ptr, p->tmp_buffer + off, len_copied);
- len -= len_copied;
- ptr += len_copied;
- lba++;
- if(unlikely(lba>lba_mask && len)){
- lba=0;
- iwlba = wbfs_ntohs(d->header->wlba_table[++wlba]);
- if(unlikely(iwlba==0))
- return 1;
- }
- }
- while(likely(len>=p->hd_sec_sz))
- {
- u32 nlb = len>>(p->hd_sec_sz_s);
-
- if(unlikely(lba + nlb > p->wbfs_sec_sz)) // dont cross wbfs sectors..
- nlb = p->wbfs_sec_sz-lba;
- err = p->read_hdsector(p->callback_data,
- p->part_lba + (iwlba<<iwlba_shift) + lba, nlb, ptr);
- if(err)
- return err;
- len -= nlb<<p->hd_sec_sz_s;
- ptr += nlb<<p->hd_sec_sz_s;
- lba += nlb;
- if(unlikely(lba>lba_mask && len)){
- lba = 0;
- iwlba =wbfs_ntohs(d->header->wlba_table[++wlba]);
- if(unlikely(iwlba==0))
- return 1;
- }
- }
- if(unlikely(len)){
- err = p->read_hdsector(p->callback_data,
- p->part_lba + (iwlba<<iwlba_shift) + lba, 1, p->tmp_buffer);
- if(err)
- return err;
- wbfs_memcpy(ptr, p->tmp_buffer, len);
- }
- return 0;
+ wbfs_t *p = d->p;
+ u16 wlba = offset>>(p->wbfs_sec_sz_s-2);
+ u32 iwlba_shift = p->wbfs_sec_sz_s - p->hd_sec_sz_s;
+ u32 lba_mask = (p->wbfs_sec_sz-1)>>(p->hd_sec_sz_s);
+ u32 lba = (offset>>(p->hd_sec_sz_s-2))&lba_mask;
+ u32 off = offset&((p->hd_sec_sz>>2)-1);
+ u16 iwlba = wbfs_ntohs(d->header->wlba_table[wlba]);
+ u32 len_copied;
+ int err = 0;
+ u8 *ptr = data;
+ if(unlikely(iwlba==0))
+ return 1;
+ if(unlikely(off)){
+ off*=4;
+ err = p->read_hdsector(p->callback_data,
+ p->part_lba + (iwlba<<iwlba_shift) + lba, 1, p->tmp_buffer);
+ if(err)
+ return err;
+ len_copied = p->hd_sec_sz - off;
+ if(likely(len < len_copied))
+ len_copied = len;
+ wbfs_memcpy(ptr, p->tmp_buffer + off, len_copied);
+ len -= len_copied;
+ ptr += len_copied;
+ lba++;
+ if(unlikely(lba>lba_mask && len)){
+ lba=0;
+ iwlba = wbfs_ntohs(d->header->wlba_table[++wlba]);
+ if(unlikely(iwlba==0))
+ return 1;
+ }
+ }
+ while(likely(len>=p->hd_sec_sz))
+ {
+ u32 nlb = len>>(p->hd_sec_sz_s);
+
+ if(unlikely(lba + nlb > p->wbfs_sec_sz)) // dont cross wbfs sectors..
+ nlb = p->wbfs_sec_sz-lba;
+ err = p->read_hdsector(p->callback_data,
+ p->part_lba + (iwlba<<iwlba_shift) + lba, nlb, ptr);
+ if(err)
+ return err;
+ len -= nlb<<p->hd_sec_sz_s;
+ ptr += nlb<<p->hd_sec_sz_s;
+ lba += nlb;
+ if(unlikely(lba>lba_mask && len)){
+ lba = 0;
+ iwlba =wbfs_ntohs(d->header->wlba_table[++wlba]);
+ if(unlikely(iwlba==0))
+ return 1;
+ }
+ }
+ if(unlikely(len)){
+ err = p->read_hdsector(p->callback_data,
+ p->part_lba + (iwlba<<iwlba_shift) + lba, 1, p->tmp_buffer);
+ if(err)
+ return err;
+ wbfs_memcpy(ptr, p->tmp_buffer, len);
+ }
+ return 0;
}
// disc listing
u32 wbfs_count_discs(wbfs_t*p)
{
- u32 i,count=0;
- for(i=0;i<p->max_disc;i++)
- if (p->head->disc_table[i])
- count++;
- return count;
-
+ u32 i,count=0;
+ for(i=0;i<p->max_disc;i++)
+ if (p->head->disc_table[i])
+ count++;
+ return count;
+
}
+
static u32 wbfs_sector_used(wbfs_t *p,wbfs_disc_info_t *di)
{
- u32 tot_blk=0,j;
- for(j=0;j<p->n_wbfs_sec_per_disc;j++)
- if(wbfs_ntohs(di->wlba_table[j]))
- tot_blk++;
- return tot_blk;
+ u32 tot_blk=0,j;
+ for(j=0;j<p->n_wbfs_sec_per_disc;j++)
+ if(wbfs_ntohs(di->wlba_table[j]))
+ tot_blk++;
+ return tot_blk;
}
+
u32 wbfs_get_disc_info(wbfs_t*p, u32 index,u8 *header,int header_size,u32 *size)//size in 32 bit
{
- u32 i,count=0;
- int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
- for(i=0;i<p->max_disc;i++)
- if (p->head->disc_table[i]){
- if(count++==index)
- {
+ u32 i,count=0;
+ int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
+ for(i=0;i<p->max_disc;i++)
+ if (p->head->disc_table[i]){
+ if(count++==index)
+ {
u32 magic;
- p->read_hdsector(p->callback_data,
- p->part_lba+1+i*disc_info_sz_lba,1,p->tmp_buffer);
- if(header_size > (int)p->hd_sec_sz)
- header_size = p->hd_sec_sz;
- magic = wbfs_ntohl(*(u32*)(p->tmp_buffer+24));
- if(magic!=0x5D1C9EA3){
- p->head->disc_table[i]=0;
- return 1;
- }
- memcpy(header,p->tmp_buffer,header_size);
- if(size)
- {
- u32 sec_used;
- u8 *header = wbfs_ioalloc(p->disc_info_sz);
-
- p->read_hdsector(p->callback_data,
- p->part_lba+1+i*disc_info_sz_lba,disc_info_sz_lba,header);
- sec_used = wbfs_sector_used(p,(wbfs_disc_info_t *)header);
- wbfs_iofree(header);
- *size = sec_used<<(p->wbfs_sec_sz_s-2);
- }
- return 0;
- }
- }
- return 1;
+ p->read_hdsector(p->callback_data,
+ p->part_lba+1+i*disc_info_sz_lba,1,p->tmp_buffer);
+ if(header_size > (int)p->hd_sec_sz)
+ header_size = p->hd_sec_sz;
+ magic = wbfs_ntohl(*(u32*)(p->tmp_buffer+24));
+ if(magic!=0x5D1C9EA3){
+ p->head->disc_table[i]=0;
+ return 1;
+ }
+ memcpy(header,p->tmp_buffer,header_size);
+ if(size)
+ {
+ u32 sec_used;
+ u8 *header = wbfs_ioalloc(p->disc_info_sz);
+
+ p->read_hdsector(p->callback_data,
+ p->part_lba+1+i*disc_info_sz_lba,disc_info_sz_lba,header);
+ sec_used = wbfs_sector_used(p,(wbfs_disc_info_t *)header);
+ wbfs_iofree(header);
+ *size = sec_used<<(p->wbfs_sec_sz_s-2);
+ }
+ return 0;
+ }
+ }
+ return 1;
}
static void load_freeblocks(wbfs_t*p)
{
- if(p->freeblks)
- return;
- // XXX should handle malloc error..
- p->freeblks = wbfs_ioalloc(ALIGN_LBA(p->n_wbfs_sec/8));
- p->read_hdsector(p->callback_data,p->part_lba+p->freeblks_lba,ALIGN_LBA(p->n_wbfs_sec/8)>>p->hd_sec_sz_s, p->freeblks);
-
+ if(p->freeblks)
+ return;
+ // XXX should handle malloc error..
+ p->freeblks = wbfs_ioalloc(ALIGN_LBA(p->n_wbfs_sec/8));
+ p->read_hdsector(p->callback_data,p->part_lba+p->freeblks_lba,ALIGN_LBA(p->n_wbfs_sec/8)>>p->hd_sec_sz_s, p->freeblks);
+
}
u32 wbfs_count_usedblocks(wbfs_t*p)
{
- u32 i,j,count=0;
-
- load_freeblocks(p);
- for(i=0;i<p->n_wbfs_sec/(8*4);i++)
- {
- u32 v = wbfs_ntohl(p->freeblks[i]);
- if(v == ~0U)
- count+=32;
- else if(v!=0)
- for(j=0;j<32;j++)
- if (v & (1<<j))
- count++;
- }
- return count;
+ u32 i,j,count=0;
+
+ load_freeblocks(p);
+ for(i=0;i<p->n_wbfs_sec/(8*4);i++)
+ {
+ u32 v = wbfs_ntohl(p->freeblks[i]);
+ if(v == ~0U)
+ count+=32;
+ else if(v!=0)
+ for(j=0;j<32;j++)
+ if (v & (1<<j))
+ count++;
+ }
+ return count;
}
@@ -425,38 +430,39 @@ u32 wbfs_count_usedblocks(wbfs_t*p)
static int block_used(u8 *used,u32 i,u32 wblk_sz)
{
- u32 k;
- i*=wblk_sz;
- for(k=0;k<wblk_sz;k++)
- if(i+k<143432*2 && used[i+k])
- return 1;
- return 0;
+ u32 k;
+ i*=wblk_sz;
+ for(k=0;k<wblk_sz;k++)
+ if(i+k<143432*2 && used[i+k])
+ return 1;
+ return 0;
}
static u32 alloc_block(wbfs_t*p)
{
- u32 i,j;
- for(i=0;i<p->n_wbfs_sec/(8*4);i++)
- {
- u32 v = wbfs_ntohl(p->freeblks[i]);
- if(v != 0)
- {
- for(j=0;j<32;j++)
- if (v & (1<<j))
- {
- p->freeblks[i] = wbfs_htonl(v & ~(1<<j));
- return (i*32)+j+1;
- }
- }
- }
- return ~0;
+ u32 i,j;
+ for(i=0;i<p->n_wbfs_sec/(8*4);i++)
+ {
+ u32 v = wbfs_ntohl(p->freeblks[i]);
+ if(v != 0)
+ {
+ for(j=0;j<32;j++)
+ if (v & (1<<j))
+ {
+ p->freeblks[i] = wbfs_htonl(v & ~(1<<j));
+ return (i*32)+j+1;
+ }
+ }
+ }
+ return ~0;
}
+
static void free_block(wbfs_t *p,int bl)
{
- int i = (bl-1)/(32);
- int j = (bl-1)&31;
- u32 v = wbfs_ntohl(p->freeblks[i]);
- p->freeblks[i] = wbfs_htonl(v | 1<<j);
+ int i = (bl-1)/(32);
+ int j = (bl-1)&31;
+ u32 v = wbfs_ntohl(p->freeblks[i]);
+ p->freeblks[i] = wbfs_htonl(v | 1<<j);
}
u32 wbfs_add_disc
@@ -741,57 +747,61 @@ u32 wbfs_estimate_disc
u32 wbfs_rm_disc(wbfs_t*p, u8* discid)
{
- wbfs_disc_t *d = wbfs_open_disc(p,discid);
- int i;
- int discn = 0;
- int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
- if(!d)
- return 1;
-
- load_freeblocks(p);
- discn = d->i;
- for( i=0; i< p->n_wbfs_sec_per_disc; i++)
- {
- u32 iwlba = wbfs_ntohs(d->header->wlba_table[i]);
- if (iwlba)
- free_block(p,iwlba);
- }
- memset(d->header,0,p->disc_info_sz);
- p->write_hdsector(p->callback_data,p->part_lba+1+discn*disc_info_sz_lba,disc_info_sz_lba,d->header);
- p->head->disc_table[discn] = 0;
- wbfs_close_disc(d);
- wbfs_sync(p);
- return 0;
+ wbfs_disc_t *d = wbfs_open_disc(p,discid);
+ int i;
+ int discn = 0;
+ int disc_info_sz_lba = p->disc_info_sz>>p->hd_sec_sz_s;
+ if(!d)
+ return 1;
+
+ load_freeblocks(p);
+ discn = d->i;
+ for( i=0; i< p->n_wbfs_sec_per_disc; i++)
+ {
+ u32 iwlba = wbfs_ntohs(d->header->wlba_table[i]);
+ if (iwlba)
+ free_block(p,iwlba);
+ }
+ memset(d->header,0,p->disc_info_sz);
+ p->write_hdsector(p->callback_data,p->part_lba+1+discn*disc_info_sz_lba,disc_info_sz_lba,d->header);
+ p->head->disc_table[discn] = 0;
+ wbfs_close_disc(d);
+ wbfs_sync(p);
+ return 0;
}
/* trim the file-system to its minimum size
*/
u32 wbfs_trim(wbfs_t*p)
{
- u32 maxbl;
- load_freeblocks(p);
- maxbl = alloc_block(p);
- p->n_hd_sec = maxbl<<(p->wbfs_sec_sz_s-p->hd_sec_sz_s);
- p->head->n_hd_sec = wbfs_htonl(p->n_hd_sec);
- // make all block full
- memset(p->freeblks,0,p->n_wbfs_sec/8);
- wbfs_sync(p);
- // os layer will truncate the file.
- return maxbl;
+ u32 maxbl;
+ load_freeblocks(p);
+ maxbl = alloc_block(p);
+ p->n_hd_sec = maxbl<<(p->wbfs_sec_sz_s-p->hd_sec_sz_s);
+ p->head->n_hd_sec = wbfs_htonl(p->n_hd_sec);
+ // make all block full
+ memset(p->freeblks,0,p->n_wbfs_sec/8);
+ wbfs_sync(p);
+ // os layer will truncate the file.
+ return maxbl;
}
-
+
// data extraction
u32 wbfs_extract_disc(wbfs_disc_t*d, rw_sector_callback_t write_dst_wii_sector,void *callback_data,progress_callback_t spinner)
{
wbfs_t *p = d->p;
u8* copy_buffer = 0;
int tot = 0, cur = 0;
int i;
+ int filling_info = 0;
+
int src_wbs_nlb=p->wbfs_sec_sz/p->hd_sec_sz;
int dst_wbs_nlb=p->wbfs_sec_sz/p->wii_sec_sz;
+
copy_buffer = wbfs_ioalloc(p->wbfs_sec_sz);
- if(!copy_buffer)
- ERROR("alloc memory");
+
+ if (!copy_buffer)
+ ERROR("alloc memory");
if (spinner)
{
@@ -807,7 +817,7 @@ u32 wbfs_extract_disc(wbfs_disc_t*d, rw_sector_callback_t write_dst_wii_sector,v
}
}
- for ( i=0; i< p->n_wbfs_sec_per_disc; i++)
+ for (i = 0; i < p->n_wbfs_sec_per_disc; i++)
{
u32 iwlba = wbfs_ntohs(d->header->wlba_table[i]);
if (iwlba)
@@ -818,6 +828,24 @@ u32 wbfs_extract_disc(wbfs_disc_t*d, rw_sector_callback_t write_dst_wii_sector,v
p->read_hdsector(p->callback_data, p->part_lba + iwlba*src_wbs_nlb, src_wbs_nlb, copy_buffer);
write_dst_wii_sector(callback_data, i*dst_wbs_nlb, dst_wbs_nlb, copy_buffer);
+ }
+ else
+ {
+ switch (filling_info) {
+ case 0:
+ if (cur == tot)
+ filling_info = 1;
+ break;
+
+ case 1:
+ fprintf(stderr, "Filling empty space in extracted image. Please wait...\n");
+ filling_info = 2;
+ break;
+
+ case 2:
+ default:
+ break;
+ }
}
}
wbfs_iofree(copy_buffer);
View
0 libwbfs/libwbfs.h 100644 → 100755
File mode changed.
View
130 libwbfs/libwbfs_linux.c
@@ -1,130 +0,0 @@
-#ifdef __linux__
-
-#include <stdio.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <linux/fs.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "libwbfs.h"
-
-static int wbfs_fread_sector(void *_fp,u32 lba,u32 count,void*buf)
-{
- FILE*fp =_fp;
- u64 off = lba;
- off*=512ULL;
- if (fseeko(fp, off, SEEK_SET))
- {
- fprintf(stderr,"\n\n%lld %d %p\n",off,count,_fp);
- wbfs_error("error seeking in disc partition");
- return 1;
- }
- if (fread(buf, count*512ULL, 1, fp) != 1){
- wbfs_error("error reading disc");
- return 1;
- }
- return 0;
-
-}
-static int wbfs_fwrite_sector(void *_fp,u32 lba,u32 count,void*buf)
-{
- FILE*fp =_fp;
- u64 off = lba;
- off*=512ULL;
- if (fseeko(fp, off, SEEK_SET))
- {
- wbfs_error("error seeking in disc file");
- return 1;
- }
- if (fwrite(buf, count*512ULL, 1, fp) != 1){
- wbfs_error("error writing disc");
- return 1;
- }
- return 0;
-
-}
-static int get_capacity(char *file,u32 *sector_size,u32 *n_sector)
-{
- int fd = open(file,O_RDONLY);
- int ret;
- if(fd<0){
- return 0;
- }
- ret = ioctl(fd,BLKSSZGET,sector_size);
- if(ret<0)
- {
- FILE *f;
- close(fd);
- f = fopen(file,"r");
- fseeko(f,0,SEEK_END);
- *n_sector = ftello(f)/512;
- *sector_size = 512;
- fclose(f);
- return 1;
- }
- ret = ioctl(fd,BLKGETSIZE,n_sector);
- close(fd);
- if(*sector_size>512)
- *n_sector*=*sector_size/512;
- if(*sector_size<512)
- *n_sector/=512/ *sector_size;
- return 1;
-}
-wbfs_t *wbfs_try_open_hd(char *fn,int reset)
-{
- u32 sector_size, n_sector;
- if(!get_capacity(fn,&sector_size,&n_sector))
- return NULL;
- FILE *f = fopen(fn,"r+");
- if (!f)
- return NULL;
- return wbfs_open_hd(wbfs_fread_sector,wbfs_fwrite_sector,f,
- sector_size ,n_sector,reset);
-}
-wbfs_t *wbfs_try_open_partition(char *fn,int reset)
-{
- u32 sector_size, n_sector;
- if(!get_capacity(fn,&sector_size,&n_sector))
- return NULL;
- FILE *f = fopen(fn,"r+");
- if (!f)
- return NULL;
- return wbfs_open_partition(wbfs_fread_sector,wbfs_fwrite_sector,f,
- sector_size ,n_sector,0,reset);
-}
-wbfs_t *wbfs_try_open(char *disc,char *partition, int reset)
-{
- wbfs_t *p = 0;
- if(partition)
- p = wbfs_try_open_partition(partition,reset);
- if (!p && !reset && disc)
- p = wbfs_try_open_hd(disc,0);
- else if(!p && !reset){
- char buffer[32];
- int i;
- for (i='c';i<'z';i++)
- {
- snprintf(buffer,32,"/dev/sd%c",i);
- p = wbfs_try_open_hd(buffer,0);
- if(p)
- {
- fprintf(stderr,"using %s\n",buffer);
- return p;
- }
- snprintf(buffer,32,"/dev/hd%c",i);
- p = wbfs_try_open_hd(buffer,0);
- if(p)
- {
- fprintf(stderr,"using %s\n",buffer);
- return p;
- }
- }
- wbfs_error("cannot find any wbfs partition (verify permissions))");
- }
- return p;
-
-}
-
-#endif
View
162 libwbfs/libwbfs_macosx.c
@@ -1,162 +0,0 @@
-// Linux code ported to Mac OS X by g3power, 2009
-// Licensed under the terms of the GNU GPL, version 2
-// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
-
-#ifdef __APPLE__
-
-#include <stdio.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/disk.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "libwbfs.h"
-
-
-static int wbfs_read_sector(void *_fp, u32 lba, u32 count, void *buf) {
- int file_des = fileno((FILE *)_fp);
- u64 off = lba;
- off *= 512ULL;
- size_t size = count * 512ULL;
-
- if ( lseek(file_des, off, SEEK_SET) != off ) {
- fprintf(stderr, "\n\n%lld %d %p\n", off, count, _fp);
- wbfs_error("error seeking in disc partition");
-
- return 1;
- }
-
- if ( read(file_des, buf, size) != size ) {
- wbfs_error("error reading disc");
-
- return 1;
- }
-
- return 0;
-}
-
-static int wbfs_write_sector(void *_fp, u32 lba, u32 count, void *buf) {
- int file_des = fileno((FILE *)_fp);
- u64 off = lba;
- off *= 512ULL;
- size_t size = count * 512ULL;
-
- if ( lseek(file_des, off, SEEK_SET) != off ) {
- wbfs_error("error seeking in disc file");
-
- return 1;
- }
-
- if ( write(file_des, buf, size) != size ) {
- wbfs_error("error writing disc");
-
- return 1;
- }
-
- return 0;
-}
-
-static int get_capacity(char *file, u32 *sector_size, u32 *n_sector) {
- int fd = open(file, O_RDONLY);
- int ret;
-
- if (fd < 0) {
- return 0;
- }
-
- ret = ioctl(fd, DKIOCGETBLOCKSIZE, sector_size);
-
- if (ret < 0) {
- FILE *f;
- close(fd);
- f = fopen(file, "r");
- fseeko(f, 0, SEEK_END);
- *n_sector = ftello(f) / 512;
- *sector_size = 512;
- fclose(f);
-
- return 1;
- }
-
- long long my_n_sector;
-#ifdef UNUSED_STUFF
- ret =
-#endif
- ioctl(fd, DKIOCGETBLOCKCOUNT, &my_n_sector);
- *n_sector = (long)my_n_sector;
-
- close(fd);
-
- if (*sector_size > 512)
- *n_sector *= *sector_size / 512;
- if (*sector_size < 512)
- *n_sector /= 512 / *sector_size;
-
- return 1;
-}
-
-wbfs_t * wbfs_try_open_hd(char *fn, int reset) {
- u32 sector_size, n_sector;
-
- if (!get_capacity(fn, &sector_size, &n_sector))
- return NULL;
-
- FILE *f = fopen(fn, "r+");
-
- if (!f)
- return NULL;
-
- return wbfs_open_hd(wbfs_read_sector, wbfs_write_sector, f,
- sector_size , n_sector, reset);
-}
-
-wbfs_t * wbfs_try_open_partition(char *fn, int reset) {
- u32 sector_size, n_sector;
-
- if (!get_capacity(fn, &sector_size, &n_sector))
- return NULL;
-
- FILE *f = fopen(fn, "r+");
-
- if (!f)
- return NULL;
-
- return wbfs_open_partition(wbfs_read_sector, wbfs_write_sector, f,
- sector_size , n_sector, 0, reset);
-}
-
-wbfs_t * wbfs_try_open(char *disc, char *partition, int reset) {
- wbfs_t *p = 0;
-
- if (partition)
- p = wbfs_try_open_partition(partition, reset);
-
- if (!p && !reset && disc)
- p = wbfs_try_open_hd(disc, 0);
- else if (!p && !reset) {
- char buffer[32];
- int i;
- for (i = 'c';i < 'z';i++) {
- snprintf(buffer, 32, "/dev/sd%c", i);
- p = wbfs_try_open_hd(buffer, 0);
- if (p) {
- fprintf(stderr, "using %s\n", buffer);
- return p;
- }
- snprintf(buffer, 32, "/dev/hd%c", i);
- p = wbfs_try_open_hd(buffer, 0);
- if (p) {
- fprintf(stderr, "using %s\n", buffer);
- return p;
- }
- }
-
- wbfs_error("cannot find any wbfs partition (verify permissions))");
- }
-
- return p;
-}
-
-#endif
View
157 libwbfs/libwbfs_unix.c
@@ -0,0 +1,157 @@
+#if defined( __linux__) || defined(__APPLE__)
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef __linux__
+#include <linux/fs.h>
+#else
+#include <sys/disk.h>
+#endif
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "libwbfs.h"
+
+static int wbfs_fread_sector(void *_fp,u32 lba,u32 count,void*buf)
+{
+ FILE*fp =_fp;
+ u64 off = lba;
+ off*=512ULL;
+ if (fseeko(fp, off, SEEK_SET))
+ {
+ fprintf(stderr,"\n\n%lld %d %p\n",off,count,_fp);
+ wbfs_error("error seeking in disc partition");
+ return 1;
+ }
+ if (fread(buf, count*512ULL, 1, fp) != 1){
+ wbfs_error("error reading disc");
+ return 1;
+ }
+ return 0;
+
+}
+static int wbfs_fwrite_sector(void *_fp,u32 lba,u32 count,void*buf)
+{
+ FILE*fp =_fp;
+ u64 off = lba;
+ off*=512ULL;
+ if (fseeko(fp, off, SEEK_SET))
+ {
+ wbfs_error("error seeking in disc file");
+ return 1;
+ }
+ if (fwrite(buf, count*512ULL, 1, fp) != 1){
+ wbfs_error("error writing disc");
+ return 1;
+ }
+ return 0;
+
+}
+static int get_capacity(char *file,u32 *sector_size,u32 *n_sector)
+{
+ int fd = open(file,O_RDONLY);
+ int ret;
+ if(fd<0){
+ return 0;
+ }
+#ifdef __linux__
+ ret = ioctl(fd,BLKSSZGET,sector_size);
+#else //__APPLE__
+ ret = ioctl(fd,DKIOCGETBLOCKSIZE,sector_size);
+#endif
+ if(ret<0)
+ {
+ FILE *f;
+ close(fd);
+ f = fopen(file,"r");
+ fseeko(f,0,SEEK_END);
+ *n_sector = ftello(f)/512;
+ *sector_size = 512;
+ fclose(f);
+ return 1;
+ }
+#ifdef __linux__
+ ret = ioctl(fd,BLKGETSIZE,n_sector);
+#else //__APPLE__
+ long long my_n_sector;
+ ret = ioctl(fd,DKIOCGETBLOCKCOUNT,&my_n_sector);
+ *n_sector = (long)my_n_sector;
+#endif
+ close(fd);
+ if(*sector_size>512)
+ *n_sector*=*sector_size/512;
+ if(*sector_size<512)
+ *n_sector/=512/ *sector_size;
+ return 1;
+}
+wbfs_t *wbfs_try_open_hd(char *fn,int reset)
+{
+ u32 sector_size, n_sector;
+ if(!get_capacity(fn,&sector_size,&n_sector))
+ return NULL;
+ FILE *f = fopen(fn,"r+");
+ if (!f)
+ return NULL;
+ return wbfs_open_hd(wbfs_fread_sector,wbfs_fwrite_sector,f,
+ sector_size ,n_sector,reset);
+}
+wbfs_t *wbfs_try_open_partition(char *fn,int reset)
+{
+ u32 sector_size, n_sector;
+ if(!get_capacity(fn,&sector_size,&n_sector))
+ return NULL;
+ FILE *f = fopen(fn,"r+");
+ if (!f)
+ return NULL;
+ return wbfs_open_partition(wbfs_fread_sector,wbfs_fwrite_sector,f,
+ sector_size ,n_sector,0,reset);
+}
+wbfs_t *wbfs_try_open(char *disc,char *partition, int reset)
+{
+ wbfs_t *p = 0;
+ if(partition)
+ p = wbfs_try_open_partition(partition,reset);
+ if (!p && !reset && disc)
+ p = wbfs_try_open_hd(disc,0);
+ else if(!p && !reset){
+ char buffer[32];
+ int i;
+#ifdef __linux__
+ for (i='b';i<'z';i++)
+ {
+ snprintf(buffer,32,"/dev/sd%c",i);
+ p = wbfs_try_open_hd(buffer,0);
+ if (p)
+ {
+ fprintf(stderr,"using %s\n",buffer);
+ return p;
+ }
+ snprintf(buffer,32,"/dev/hd%c",i);
+ p = wbfs_try_open_hd(buffer,0);
+ if (p)
+ {
+ fprintf(stderr,"using %s\n",buffer);
+ return p;
+ }
+ }
+#else
+ int j;
+ for (i=0;i<10;i++)
+ for (j=0;j<10;j++){
+ snprintf(buffer,32,"/dev/disk%ds%d",i,j);
+ p = wbfs_try_open_partition(buffer,0);
+ if (p)
+ {
+ fprintf(stderr,"using %s\n",buffer);
+ return p;
+ }
+ }
+#endif
+ wbfs_error("cannot find any wbfs partition (verify permissions))");
+ }
+ return p;
+
+}
+
+#endif //__linux__ or __APPLE__
View
0 libwbfs/rijndael.c 100644 → 100755
File mode changed.
View
0 libwbfs/wiidisc.c 100644 → 100755
File mode changed.
View
0 libwbfs/wiidisc.h 100644 → 100755
File mode changed.
View
0 libwbfs_os.h 100644 → 100755
File mode changed.
View
0 libwbfslite/libwbfs.c 100644 → 100755
File mode changed.
View
0 libwbfslite/libwbfs.h 100644 → 100755
File mode changed.
View
0 macosx/wbfs/wbfs.1 100644 → 100755
File mode changed.
View
24 macosx/wbfs/wbfs.xcodeproj/project.pbxproj 100644 → 100755
@@ -7,10 +7,11 @@
objects = {
/* Begin PBXBuildFile section */
+ 3D6638380F9C7BA500298B12 /* libwbfs_unix.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D6638370F9C7BA500298B12 /* libwbfs_unix.c */; };
+ 3D6638390F9C7BA500298B12 /* libwbfs_unix.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D6638370F9C7BA500298B12 /* libwbfs_unix.c */; };
+ 3D66383A0F9C7BA500298B12 /* libwbfs_unix.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D6638370F9C7BA500298B12 /* libwbfs_unix.c */; };
3DBBF7A60F89071A00592CB6 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DBBF7A50F89071A00592CB6 /* libcrypto.dylib */; };
3DBBF7DC0F8907E000592CB6 /* libwbfs.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7CC0F8907E000592CB6 /* libwbfs.c */; };
- 3DBBF7DD0F8907E000592CB6 /* libwbfs_linux.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7CE0F8907E000592CB6 /* libwbfs_linux.c */; };
- 3DBBF7DE0F8907E000592CB6 /* libwbfs_macosx.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7CF0F8907E000592CB6 /* libwbfs_macosx.c */; };
3DBBF7DF0F8907E000592CB6 /* rijndael.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D00F8907E000592CB6 /* rijndael.c */; };
3DBBF7E00F8907E000592CB6 /* wiidisc.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D10F8907E000592CB6 /* wiidisc.c */; };
3DBBF7E20F8907E000592CB6 /* disc_usage_table.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D40F8907E000592CB6 /* disc_usage_table.c */; };
@@ -20,8 +21,6 @@
3DBBF7E70F8907E000592CB6 /* wbfs.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7DB0F8907E000592CB6 /* wbfs.c */; };
3DBBF8180F8908DB00592CB6 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DBBF7A50F89071A00592CB6 /* libcrypto.dylib */; };
3DBBF81D0F89092600592CB6 /* libwbfs.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7CC0F8907E000592CB6 /* libwbfs.c */; };
- 3DBBF81F0F89092600592CB6 /* libwbfs_linux.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7CE0F8907E000592CB6 /* libwbfs_linux.c */; };
- 3DBBF8200F89092600592CB6 /* libwbfs_macosx.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7CF0F8907E000592CB6 /* libwbfs_macosx.c */; };
3DBBF8210F89092600592CB6 /* rijndael.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D00F8907E000592CB6 /* rijndael.c */; };
3DBBF8220F89092600592CB6 /* wiidisc.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D10F8907E000592CB6 /* wiidisc.c */; };
3DBBF8240F89092600592CB6 /* disc_usage_table.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D40F8907E000592CB6 /* disc_usage_table.c */; };
@@ -30,8 +29,6 @@
3DBBF8270F89092600592CB6 /* tools.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D80F8907E000592CB6 /* tools.c */; };
3DBBF8280F89092600592CB6 /* bn.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D90F8907E000592CB6 /* bn.c */; };
3DBBF8330F89096E00592CB6 /* libwbfs.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7CC0F8907E000592CB6 /* libwbfs.c */; };
- 3DBBF8340F89096E00592CB6 /* libwbfs_linux.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7CE0F8907E000592CB6 /* libwbfs_linux.c */; };
- 3DBBF8350F89096E00592CB6 /* libwbfs_macosx.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7CF0F8907E000592CB6 /* libwbfs_macosx.c */; };
3DBBF8360F89096E00592CB6 /* rijndael.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D00F8907E000592CB6 /* rijndael.c */; };
3DBBF8370F89096E00592CB6 /* wiidisc.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D10F8907E000592CB6 /* wiidisc.c */; };
3DBBF8380F89096E00592CB6 /* scrub.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DBBF7D30F8907E000592CB6 /* scrub.c */; };
@@ -57,11 +54,10 @@
/* Begin PBXFileReference section */
3D1916EC0F8B878100E97958 /* libwbfs_win32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = libwbfs_win32.c; sourceTree = "<group>"; };
3D1917220F8B99B100E97958 /* libwbfs_os.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = libwbfs_os.h; path = ../../libwbfs_os.h; sourceTree = SOURCE_ROOT; };
+ 3D6638370F9C7BA500298B12 /* libwbfs_unix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = libwbfs_unix.c; sourceTree = "<group>"; };
3DBBF7A50F89071A00592CB6 /* libcrypto.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.dylib; path = usr/lib/libcrypto.dylib; sourceTree = SDKROOT; };
3DBBF7CC0F8907E000592CB6 /* libwbfs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = libwbfs.c; sourceTree = "<group>"; };
3DBBF7CD0F8907E000592CB6 /* libwbfs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libwbfs.h; sourceTree = "<group>"; };
- 3DBBF7CE0F8907E000592CB6 /* libwbfs_linux.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = libwbfs_linux.c; sourceTree = "<group>"; };
- 3DBBF7CF0F8907E000592CB6 /* libwbfs_macosx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = libwbfs_macosx.c; sourceTree = "<group>"; };
3DBBF7D00F8907E000592CB6 /* rijndael.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rijndael.c; sourceTree = "<group>"; };
3DBBF7D10F8907E000592CB6 /* wiidisc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = wiidisc.c; sourceTree = "<group>"; };
3DBBF7D20F8907E000592CB6 /* wiidisc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wiidisc.h; sourceTree = "<group>"; };
@@ -148,10 +144,9 @@
3DBBF7CB0F8907E000592CB6 /* libwbfs */ = {
isa = PBXGroup;
children = (
+ 3D6638370F9C7BA500298B12 /* libwbfs_unix.c */,
3DBBF7CC0F8907E000592CB6 /* libwbfs.c */,
3DBBF7CD0F8907E000592CB6 /* libwbfs.h */,
- 3DBBF7CE0F8907E000592CB6 /* libwbfs_linux.c */,
- 3DBBF7CF0F8907E000592CB6 /* libwbfs_macosx.c */,
3D1916EC0F8B878100E97958 /* libwbfs_win32.c */,
3DBBF7D00F8907E000592CB6 /* rijndael.c */,
3DBBF7D10F8907E000592CB6 /* wiidisc.c */,
@@ -247,15 +242,14 @@
buildActionMask = 2147483647;
files = (
3DBBF81D0F89092600592CB6 /* libwbfs.c in Sources */,
- 3DBBF81F0F89092600592CB6 /* libwbfs_linux.c in Sources */,
- 3DBBF8200F89092600592CB6 /* libwbfs_macosx.c in Sources */,
3DBBF8210F89092600592CB6 /* rijndael.c in Sources */,
3DBBF8220F89092600592CB6 /* wiidisc.c in Sources */,
3DBBF8240F89092600592CB6 /* disc_usage_table.c in Sources */,
3DBBF8250F89092600592CB6 /* ec.c in Sources */,
3DBBF8260F89092600592CB6 /* negentig.c in Sources */,
3DBBF8270F89092600592CB6 /* tools.c in Sources */,
3DBBF8280F89092600592CB6 /* bn.c in Sources */,
+ 3D6638390F9C7BA500298B12 /* libwbfs_unix.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -264,15 +258,14 @@
buildActionMask = 2147483647;
files = (
3DBBF8330F89096E00592CB6 /* libwbfs.c in Sources */,
- 3DBBF8340F89096E00592CB6 /* libwbfs_linux.c in Sources */,
- 3DBBF8350F89096E00592CB6 /* libwbfs_macosx.c in Sources */,
3DBBF8360F89096E00592CB6 /* rijndael.c in Sources */,
3DBBF8370F89096E00592CB6 /* wiidisc.c in Sources */,
3DBBF8380F89096E00592CB6 /* scrub.c in Sources */,
3DBBF8390F89096E00592CB6 /* disc_usage_table.c in Sources */,
3DBBF83A0F89096E00592CB6 /* ec.c in Sources */,
3DBBF83B0F89096E00592CB6 /* tools.c in Sources */,
3DBBF83C0F89096E00592CB6 /* bn.c in Sources */,
+ 3D66383A0F9C7BA500298B12 /* libwbfs_unix.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -282,14 +275,13 @@
files = (
3DBBF7E70F8907E000592CB6 /* wbfs.c in Sources */,
3DBBF7DC0F8907E000592CB6 /* libwbfs.c in Sources */,
- 3DBBF7DD0F8907E000592CB6 /* libwbfs_linux.c in Sources */,
- 3DBBF7DE0F8907E000592CB6 /* libwbfs_macosx.c in Sources */,
3DBBF7DF0F8907E000592CB6 /* rijndael.c in Sources */,
3DBBF7E00F8907E000592CB6 /* wiidisc.c in Sources */,
3DBBF7E20F8907E000592CB6 /* disc_usage_table.c in Sources */,
3DBBF7E30F8907E000592CB6 /* ec.c in Sources */,
3DBBF7E50F8907E000592CB6 /* tools.c in Sources */,
3DBBF7E60F8907E000592CB6 /* bn.c in Sources */,
+ 3D6638380F9C7BA500298B12 /* libwbfs_unix.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
2 negentig.c 100644 → 100755
@@ -172,7 +172,7 @@ static void do_data(u64 size)
fp = fopen("###dat###", "wb");
if (fp == 0)
- fatal("cannot open partition output file");
+ fatal("Cannot open partition output file");
fprintf(stderr, "\nDumping partition contents...\n");
offset = 0;
View
0 scrub.c 100644 → 100755
File mode changed.
View
0 tools.c 100644 → 100755
File mode changed.
View
0 tools.h 100644 → 100755
File mode changed.
View
86 wbfs.c 100644 → 100755
@@ -11,28 +11,19 @@
#ifdef WIN32
#include "win32/xgetopt.h"
-#else
-#include <getopt.h>
-#endif
-
-#include <sys/stat.h>
-
-#ifdef WIN32
#include <direct.h>
#include <io.h>
+#define snprintf _snprintf
#else
+#include <getopt.h>
#include <unistd.h>
#endif
-
-#ifdef WIN32
#include <errno.h>
-#endif
+
+#include <sys/stat.h>
#include "tools.h"
#include "libwbfs.h"
-#ifdef WIN32
-#define snprintf _snprintf
-#endif
#ifdef ENABLE_RENAME
#ifndef ENABLE_RENAME_OR_CHANGE_DISKID
@@ -191,7 +182,7 @@ int wbfs_applet_ls(wbfs_t *p)
fprintf(stderr, "%c%c%c%c%c%c %4dM %s\n", b[0], b[1], b[2], b[3], b[4], b[5], (u32)(size * 4ULL / (MB)), b + 0x20);
}
#else
- fprintf(stderr, "%c%c%c%c%c%c|@|%s|@|%.2fG\n",b[0], b[1], b[2], b[3], b[4], b[5],
+ fprintf(stderr, "%c%c%c%c%c%c|@|%-40s|@|%.2fG\n",b[0], b[1], b[2], b[3], b[4], b[5],
b + 0x20,size*4ULL/(GB));
#endif
}
@@ -202,6 +193,8 @@ int wbfs_applet_ls(wbfs_t *p)
#ifdef WIN32
if(!shortcmd)
+#endif
+#ifndef __APPLE__
{
u32 blcount = wbfs_count_usedblocks(p);
fprintf(stderr, "------------\n Total: %.2fG, Used: %.2fG, Free: %.2fG\n",
@@ -210,7 +203,6 @@ int wbfs_applet_ls(wbfs_t *p)
(float)(blcount) * p->wbfs_sec_sz / GB);
}
#endif
-
#ifndef WIN32
return 0;
#endif
@@ -372,7 +364,10 @@ void wbfs_applet_estimate(wbfs_t *p, BOOL shortcmd, int argc, char *argv[])
}
}
#endif
-
+int _wbfs_disc_read(void *fp, u32 lba, u32 count, void *iobuf)
+{
+ return wbfs_disc_read(fp, lba, iobuf, count);
+}
static void _spinner(int x, int y){ spinner(x, y); }
#ifdef WIN32
static void _progress(int x, int y){ progress(x, y); }
@@ -419,21 +414,50 @@ int wbfs_applet_add(wbfs_t *p,char*argv)
}
#else
- if(!f)
- wbfs_error("unable to open disc file");
- else
- {
- fread(discinfo,6,1,f);
- d = wbfs_open_disc(p,discinfo);
- if(d)
- {
- discinfo[6]=0;
- fprintf(stderr,"%s already in disc..\n",discinfo);
- wbfs_close_disc(d);
- return 0;
- } else
- return wbfs_add_disc(p,read_wii_file,f,_spinner,ONLY_GAME_PARTITION,0);
- }
+ if(!f)
+ wbfs_error("unable to open disc file");
+ else
+ {
+ fread(discinfo,6,1,f);
+ if (memcmp(discinfo, "WBFS", 4) == 0) // add all games in the wbfs partition
+ {
+ fclose(f);
+ wbfs_t *src_p = wbfs_try_open_partition(argv, 0);
+ if (!src_p)
+ {
+ wbfs_error("incorrect wbfs file");
+ return 1;
+ }
+ int i, count = wbfs_count_discs(src_p);
+ u8 *b = wbfs_ioalloc(0x100);
+ if (count==0)
+ wbfs_error("no disc in wbfs");
+ for (i=0;i<count;i++)
+ {
+ if(!wbfs_get_disc_info(src_p, i, b, 0x100, NULL)){
+ d = wbfs_open_disc(p, b);
+ if(!d){ // not here already.
+ d = wbfs_open_disc(src_p, b);
+ wbfs_add_disc(p, _wbfs_disc_read, d, _spinner, ONLY_GAME_PARTITION, 0);
+ }
+ wbfs_close_disc(d);
+ }
+ }
+ wbfs_close(src_p);
+ }
+ else
+ {
+ d = wbfs_open_disc(p,discinfo);
+ if(d)
+ {
+ discinfo[6]=0;
+ fprintf(stderr,"%s already in disc..\n",discinfo);
+ wbfs_close_disc(d);
+ return 0;
+ } else
+ return wbfs_add_disc(p,read_wii_file,f,_spinner,ONLY_GAME_PARTITION,0);
+ }
+ }
return 1;
#endif

0 comments on commit ce8b2db

Please sign in to comment.
Something went wrong with that request. Please try again.