Possible fix for the WBFS corruption

Discussion in 'Wii - Hacking' started by AllWiidUp, Apr 12, 2009.

  1. AllWiidUp
    OP

    AllWiidUp Advanced Member

    Newcomer
    84
    0
    Dec 17, 2008
    Canada
    Looking at the WBFS alloc and free functions I noticed an off by 1 error, that likely frees the wrong block.

    in libwbfs.c:

    CODE--- a/libwbfs.cÂÂ 2009-03-31 18:26:00.000000000 -0700
    +++ b/libwbfs.cÂÂÂÂ 2009-04-12 12:28:23.516024000 -0700
    @@ -389,8 +389,8 @@
    }
    static void free_block(wbfs_t *p,int bl)
    {
    -ÂÂÂÂÂÂÂÂint i = bl/(32);
    -ÂÂÂÂÂÂÂÂint j = bl&31;
    +ÂÂÂÂÂÂÂÂint i = (bl-1)/(32);
    +ÂÂÂÂÂÂÂÂint j = (bl-1)&31;
    ÂÂÂÂÂÂÂÂ u32 v = wbfs_ntohl(p->freeblks);
    ÂÂÂÂÂÂÂÂ p->freeblks = wbfs_htonl(v | 1freeblks);
    ÂÂÂÂÂÂÂÂp->freeblks = wbfs_htonl(v | 1wlba_table); // bl = info->wlba_table
    ÂÂÂÂÂÂÂÂÂÂif (iwlba)
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂfree_block(p,iwlba); // should have beenÂÂfree_block(p,iwlba - 1);[/code]
    but since "alloc_block" adds the +1 then "free_block" should have the -1, otherwise someone else might introduce the bug again, if the use free_block in another place since both block functions are used for "wlba_table".



    EDIT:
    WiiNinja compiled and tested a windows version with the fix and all it well ;P
    WBFS.Windows.with.free.space.fix

    now supported in WBFuse

    Managers with Support:
    WBFS Manager 2.2


    Loaders with support:
    KongsNutz Loader
    Waninkoko v1.4
     


  2. Mark McDonut

    Mark McDonut GBAtemp Advanced Fan

    Member
    597
    114
    Oct 8, 2008
    United States
    you should contact qwiirk or waninkoko, you really may be on to something.
     
  3. AllWiidUp
    OP

    AllWiidUp Advanced Member

    Newcomer
    84
    0
    Dec 17, 2008
    Canada

    I don't know Kwiirk's contact info and since he did up this version, I thought I'd put it out there in case he could see.
     
  4. OuahOuah

    OuahOuah GBAtemp Advanced Fan

    Member
    991
    200
    Oct 2, 2006
    France
    France
    He's on Wiibrew [​IMG]
     
  5. FenrirWolf

    FenrirWolf GBAtemp Psycho!

    Member
    4,347
    329
    Nov 19, 2008
    United States
    Sandy, UT
    So in what manner would this possibly fix the corruption? Would it cause a game to move the other games out of the way instead of overwriting them or something?
     
  6. kongsnutz

    kongsnutz QuickTimeEvent

    Member
    1,457
    272
    Jul 19, 2008
    pretty much .......yeh
     
  7. FoGBaV

    FoGBaV Advanced Member

    Newcomer
    82
    0
    Jan 31, 2008
    Can someone confirm this fix - this would be the best Loader out there ... a Loader with no corruption in the file system ! 8)
     
  8. FenrirWolf

    FenrirWolf GBAtemp Psycho!

    Member
    4,347
    329
    Nov 19, 2008
    United States
    Sandy, UT
    From what I gather this has to do with the wbfs filesystem itself and not any loader application, but correct me if I'm wrong.
     
  9. FoGBaV

    FoGBaV Advanced Member

    Newcomer
    82
    0
    Jan 31, 2008
    Its the libwbfs ... so its part of something when compiled ... so the usb loader has this code in it i guess ...
    also the wbfs tools ...
     
  10. maglat

    maglat Advanced Member

    Newcomer
    60
    2
    Dec 21, 2006
    Gambia, The
    I think we musst reformat our hdd`s when they build in this fix
     
  11. FenrirWolf

    FenrirWolf GBAtemp Psycho!

    Member
    4,347
    329
    Nov 19, 2008
    United States
    Sandy, UT
    I'm thinking the same thing. It'll be well worth it since you have to reinstall games when they get corrupted anyway.
     
  12. djtaz

    djtaz PM's Full - Wadder Me

    Member
    2,997
    2
    Sep 21, 2008
    It would be a great find if its the fix - its been bugging everyone and makes the format seem a little unstable for most.
    well done AllWiidup
     
  13. Blue-K

    Blue-K No right of appeal.

    Member
    2,572
    1
    Jun 21, 2008
    Swaziland
    Helvetica
    That's awesome!!! [​IMG].Good work! Have you maybe also found the bug why games can't be dumped by the Wii to a Partition over 512GB [​IMG]? That would be also awesome [​IMG].
     
  14. waninkoko

    waninkoko GBAtemp Fan

    Member
    300
    2
    Feb 1, 2008
    Salamanca, Spain
    You're completely right. It frees an incorrect block (we don't free the first block of the game, but we free the first block next to the last block of the game).
     
  15. wiiNinja

    wiiNinja GBAtemp Fan

    Member
    387
    25
    Jan 13, 2009
    United States
    Finally, the bug is found. Thanks AllWiidup.
     
  16. --=ZerO=--

    --=ZerO=-- GBAtemp Regular

    Member
    271
    3
    Jan 18, 2006
    Gambia, The
    So... i see... i'm sure u and kwiirk will fix this very soon... CIOS11 is on it's way. [​IMG]
    U guys are great!
     
  17. Linuks

    Linuks GBAtemp Regular

    Member
    299
    0
    Aug 30, 2008
    France
    France
    USB Loader 1.3 is already here.
     
  18. --=ZerO=--

    --=ZerO=-- GBAtemp Regular

    Member
    271
    3
    Jan 18, 2006
    Gambia, The
    yeah, and? I thougth it's a problem of libwbfs and not the loader...
     
  19. wiiNinja

    wiiNinja GBAtemp Fan

    Member
    387
    25
    Jan 13, 2009
    United States
    THe loader contains wbfs code for adding/deleting ISOs.

    Version 1.3 does not fix this problem. I suspect 1.4.
     
  20. AllWiidUp
    OP

    AllWiidUp Advanced Member

    Newcomer
    84
    0
    Dec 17, 2008
    Canada
    Thanks wiiNinja for compiling and testing the fix, to verify it works.