Programming help?

Discussion in 'Wii - Hacking' started by techboy, Jun 18, 2011.

Jun 18, 2011

Programming help? by techboy at 6:45 AM (1,656 Views / 0 Likes) 26 replies

  1. techboy
    OP

    Member techboy GBAtemp Advanced Maniac

    Joined:
    Mar 15, 2009
    Messages:
    1,720
    Location:
    Pennsylvania
    Country:
    United States
    Hi all,

    I'm looking for some help getting ISFS_RENAME() to work in a program I'm working on. It keeps returning with error -101 (EINVAL) when I run it on my wii. AHBPROT is used for FS permissions (to eliminate error -102).

    Interestingly, this exact same DOL works perfectly on UNEEK.

    The files that are to be renamed do exist. They're part of a dummy channel (titleID 00010001-41414141) I installed for this program, and I verified their existence with FSToolbox. Both 00000000.app and 00000003.app are channel banners. The idea is that when the DOL runs, it swaps the banners, changing the appearance of the channel.

    Below is a commented copy of my main() function from a test DOL. The DOL is run via WiiLoad to an HBC 1.0.8 using IOS58.

    Anybody got a clue why this won't work?

    CODEint main(int argc, char *argv[])
    {
    initialiseWiiApp(); //Contains the VIDEO_INIT(), PAD_INIT(), etc...
    clearConsole(BLACK);
    if (!IOSPATCH_Apply()) { //This applies FS_permissions patch to running IOS with AHBPROT (function from IOSPATCH.C from FTPii).
    printf("ERROR: Failure applying memory patches.");
    }
    //IOS_ReloadIOS(249); //Also tried this in place of the above AHBPROT patch. No change.
    int rets;

    rets = ISFS_Initialize();
    sleep(2);
    printf("\nOpen ISFS: %d\n",rets);
    //ISFS_Mount();

    rets = ISFS_Rename("/title/00010001/41414141/content/00000000.app","/title/00010001/41414141/content/00000004.app"); //Returns -101
    printf("\nISFS_Rename() returned %d\n", rets);

    rets = ISFS_Rename("/title/00010001/41414141/content/00000003.app","/title/00010001/41414141/content/00000000.app"); //Returns -101
    printf("\nISFS_Rename() returned %d\n", rets);

    rets = ISFS_Rename("/title/00010001/41414141/content/00000004.app","/title/00010001/41414141/content/00000003.app"); //Returns -106 (expected, this file won't exist if above actions fail.)
    printf("\nISFS_Rename() returned %d\n", rets);

    ISFS_Deinitialize();
    sleep(5);
    return 0;
    }
     


  2. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    Does it work if you use IOS236? My 1st guess would be you run this with IOS58 or IOS61 and it doesn't like the nand permissions patch.

    Can you read/wirte any file you want?

    And i don't think it's able to overwrite files, so did you check for that?
     
  3. techboy
    OP

    Member techboy GBAtemp Advanced Maniac

    Joined:
    Mar 15, 2009
    Messages:
    1,720
    Location:
    Pennsylvania
    Country:
    United States
    I checked in FSToolbox, the target doesn't exist, so it shouldn't be an issue.
     
  4. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    Try to put the parameters for ISFS_Rename in aligned buffers.
    memalign(32, x);

    When reading a file that is required, even an u8 buffer[x] ATTIBUTE_ALIGN(32); doesn't work for the read.
     
  5. techboy
    OP

    Member techboy GBAtemp Advanced Maniac

    Joined:
    Mar 15, 2009
    Messages:
    1,720
    Location:
    Pennsylvania
    Country:
    United States
    ...the above runs, but still gives -101. [​IMG]
     
  6. SanGor

    Member SanGor Witchhunter

    Joined:
    Aug 21, 2008
    Messages:
    993
    Country:
    United States
    source and target filename must be the same!

    i.e.:

    Code:
    ISFS_Rename("/tmp/00000004.app", "/title/00010001/41414141/content/00000004.app");
     
  7. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    might have a chance to work.
     
  8. tueidj

    Member tueidj I R Expert

    Joined:
    Jan 8, 2009
    Messages:
    2,569
    Country:
    Alignment of the path arguments is irrelevant, they're copied into a struct before being passed to IOS (and don't use sprintf where strcpy would be sufficient).
     
  9. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    Ok. Do you have any idea what's causing this error?
     
  10. tueidj

    Member tueidj I R Expert

    Joined:
    Jan 8, 2009
    Messages:
    2,569
    Country:
    crediar SanGor already answered it.
     
  11. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    Lol, why didn't stupid GBAtemp show me that post? Sorry, i didn't see it.
     
  12. techboy
    OP

    Member techboy GBAtemp Advanced Maniac

    Joined:
    Mar 15, 2009
    Messages:
    1,720
    Location:
    Pennsylvania
    Country:
    United States
    So this function is more for *moving* files, not renaming them...ISFS_Rename() is not what I need then. Anyone have example code for how to actually rename a file?

    @WiiPower: Thanks for the tips on using aligned buffers [​IMG]
     
  13. scooby74029

    Member scooby74029 "fake coder"

    Joined:
    May 7, 2010
    Messages:
    1,174
    Location:
    oklahoma, USA
    Country:
    United States
    @ techboy

    i am not one to make suggestions but you could try

    to read file into buffer then write file to the appropriate place

    read from "/temp/00000000.app to buffer
    write buffer to //title/00010001/41414141/content/00000004.app
    then del then temp file or folder

    sorry i should have put youll have to create dir if they dont exist

    i know i am no coder but it might work
     
  14. obcd

    Member obcd GBAtemp Advanced Maniac

    Joined:
    Apr 5, 2011
    Messages:
    1,594
    Country:
    Belgium
    Also be aware that on multi threaded systems, a file can be in use by another thread preventing some actions like deleting it.
    It might not be an issue here, but it's good to keep in mind.
     
  15. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    I would not copy the whole file into one buffer. A loop with a 2K buffer should work.
     
  16. scooby74029

    Member scooby74029 "fake coder"

    Joined:
    May 7, 2010
    Messages:
    1,174
    Location:
    oklahoma, USA
    Country:
    United States
    @wiipower

    is that better to do?

    i am still teaching myself this stuff!!

    thanks for the great info
     
  17. techboy
    OP

    Member techboy GBAtemp Advanced Maniac

    Joined:
    Mar 15, 2009
    Messages:
    1,720
    Location:
    Pennsylvania
    Country:
    United States
     
  18. tueidj

    Member tueidj I R Expert

    Joined:
    Jan 8, 2009
    Messages:
    2,569
    Country:
    Functions return values for a reason, you shouldn't ignore them.
     
  19. giantpune

    Member giantpune GBAtemp Addict

    Joined:
    Apr 10, 2009
    Messages:
    2,860
    Country:
    United States
    how does the system menu handle it if your calls to ISFS_Rename() fail? does it start up at all or do some bannerbrick nonsense?
     
  20. techboy
    OP

    Member techboy GBAtemp Advanced Maniac

    Joined:
    Mar 15, 2009
    Messages:
    1,720
    Location:
    Pennsylvania
    Country:
    United States
    I know. I'm assuming this was in reference to ISFS_SetAttr = -102.

    It was because I was using ISFS_SetAttr to try and change the ownerID. As it turns out, the function just can't be used for that (a hackmii IRC log makes a mention of someone else having the same issue - it rejects attempts to change ownerID).

    Since the SM doesn't care about the ownerID of the banner not being 0, I just set the ownerID to the file's real ownerID. With the real owner specified, the rest of the attributes (groupID, ownerperm, groupperm, otherperm) were updated properly and the function returned 0.
     

Share This Page