Hacking Programming help?

techboy

Well-Known Member
OP
Member
Joined
Mar 15, 2009
Messages
1,720
Trophies
0
Age
31
Location
Pennsylvania
Website
Visit site
XP
306
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;
}
 

WiiPower

Well-Known Member
Member
Joined
Oct 17, 2008
Messages
8,165
Trophies
0
XP
345
Country
Gambia, The
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?
 

techboy

Well-Known Member
OP
Member
Joined
Mar 15, 2009
Messages
1,720
Trophies
0
Age
31
Location
Pennsylvania
Website
Visit site
XP
306
Country
United States
WiiPower said:
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.
It does run on IOS58. The IOSpatch_apply() returns 0 (success), but it still doesn't work right. I'll install IOS236 and try running it from that.

EDIT: IOS236 made no difference. Still -101.

WiiPower said:
Can you read/wirte any file you want?
I didn't try (this app doesn't need it), but I'll see if it can open files.

EDIT: ISFS_Open works correctly, as does ISFS_Read.

QUOTE(WiiPower @ Jun 18 2011, 04:36 AM)
And i don't think it's able to overwrite files, so did you check for that?
I checked in FSToolbox, the target doesn't exist, so it shouldn't be an issue.
 

WiiPower

Well-Known Member
Member
Joined
Oct 17, 2008
Messages
8,165
Trophies
0
XP
345
Country
Gambia, The
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.
 

techboy

Well-Known Member
OP
Member
Joined
Mar 15, 2009
Messages
1,720
Trophies
0
Age
31
Location
Pennsylvania
Website
Visit site
XP
306
Country
United States
WiiPower said:
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.
I'm still really new to C (this is only my second program...), so still have a LOT to learn.

Is this correct, or am I completely confused about pointers and how to create aligned buffers?
CODEchar *filein = memalign(32,ISFS_MAXPATH);
char *fileout = memalign(32,ISFS_MAXPATH);

filein="/title/00010001/41414141/content/00000000.app";
fileout="/title/00010001/41414141/content/00000004.app";

rets = ISFS_Rename(filein, fileout);
printf("\nResult: %d\n",rets);

...the above runs, but still gives -101.
frown.gif
 

SanGor

Witchhunter
Member
Joined
Aug 21, 2008
Messages
993
Trophies
0
Website
Visit site
XP
215
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");
 

WiiPower

Well-Known Member
Member
Joined
Oct 17, 2008
Messages
8,165
Trophies
0
XP
345
Country
Gambia, The
techboy said:
WiiPower said:
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.
I'm still really new to C (this is only my second program...), so still have a LOT to learn.

Is this correct, or am I completely confused about pointers and how to create aligned buffers?
Code:
char *filein = memalign(32,ISFS_MAXPATH);
char *fileout = memalign(32,ISFS_MAXPATH);

filein="/title/00010001/41414141/content/00000000.app";
fileout="/title/00010001/41414141/content/00000004.app";

rets = ISFS_Rename(filein, fileout);
printf("\nResult: %d\n",rets);

...the above runs, but still gives -101.
frown.gif



1. Always when using memalign or malloc, check if you really got some memory.

char *filein = memalign(32,ISFS_MAXPATH);
if (filein == NULL)
{
ERROR Out of memory
}

2. If you use filein="/title/00010001/41414141/content/00000000.app";
then you set the pointer filein to the memory offset of your string, so you are not using your allocated buffer.



Code:
ÂÂÂÂchar path[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
ÂÂÂÂsprintf(path, "/title/00010001/41414141/content/00000000.app");

This might work, if not

CODE
char *path;
path = memalign(32, ISFS_MAXPATH);
if (path == NULL)
{
ERROR
}
sprintf(path, "/title/00010001/41414141/content/00000000.app");

might have a chance to work.
 

tueidj

I R Expert
Member
Joined
Jan 8, 2009
Messages
2,569
Trophies
0
Website
Visit site
XP
999
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).
 

WiiPower

Well-Known Member
Member
Joined
Oct 17, 2008
Messages
8,165
Trophies
0
XP
345
Country
Gambia, The
tueidj said:
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).

Ok. Do you have any idea what's causing this error?
 

techboy

Well-Known Member
OP
Member
Joined
Mar 15, 2009
Messages
1,720
Trophies
0
Age
31
Location
Pennsylvania
Website
Visit site
XP
306
Country
United States
SanGor said:
source and target filename must be the same!

i.e.:

Code:
ISFS_Rename("/tmp/00000004.app", "/title/00010001/41414141/content/00000004.app");
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
smile.gif
 

scooby74029

wanttabe dev
Member
Joined
May 7, 2010
Messages
1,357
Trophies
1
Age
48
Location
oklahoma, USA
Website
www.wiithemer.org
XP
1,339
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
 

obcd

Well-Known Member
Member
Joined
Apr 5, 2011
Messages
1,594
Trophies
0
XP
432
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.
 

techboy

Well-Known Member
OP
Member
Joined
Mar 15, 2009
Messages
1,720
Trophies
0
Age
31
Location
Pennsylvania
Website
Visit site
XP
306
Country
United States
scooby74029 said:
@wiipower

is that better to do?

i am still teaching myself this stuff!!

thanks for the great info
Actually wondering the same thing...I used a single large buffer and it worked fine. I'm guessing this may have something to do with possibly running out of memory?

I grabbed the "wiibasics" include from DOP-Mii and used the ISFS_ReadFileToArray() and ISFS_WriteFileFromArray() in there. I created a buffer: u8 buffer[524288]; (I'll resize this, it's much larger than I need) then read the file into it, and wrote it out again with a different name. The old and new files match perfectly (same SHA1)
smile.gif
.

ISFS_Delete() can delete the newly created 5.app, so I'll assume ISFS_Delete will work on other content as well.

The only issue now is getting the permissions right. The owner of a title content is supposed to be 0, but my 5.app has an owner of 4253 (the HBC's owner ID). ISFS_SetAttr() can't be used to change it. Any ideas on fixing the permissions?

EDIT: Got the whole thing to work.
smile.gif
The SM doesn't care about the banner owner not being 0, so I'm not going to worry about it. Also, MMM was happy when uninstalling the title with mixed up contents.

For those who want to know, the spoiler below contains a simplified version of my code (I removed error handling and printf() statements to shorten it).
CODEÂÂÂÂstatic u8 bannerbuffer1[BUFFER_SIZE] ATTRIBUTE_ALIGN(32); //Buffer.
ÂÂÂÂu32 bbfs1; //File size of the banner in the buffer.

ÂÂÂÂrets = ISFS_Initialize();
ÂÂÂÂsleep(1);
ÂÂÂÂ
ÂÂÂÂ//Copy 0.app as 3.app into /tmp/
ÂÂÂÂrets = ISFS_ReadFileToArray("/title/00010001/41414141/content/00000000.app",bannerbuffer1,BUFFER_SIZE,&bbfs1);
ÂÂÂÂrets = ISFS_WriteFileFromArray("/tmp/00000003.app",bannerbuffer1,bbfs1,0,0,0,3,3,0);

ÂÂÂÂ//Copy 3.app as 0.app into /tmp/
ÂÂÂÂrets = ISFS_ReadFileToArray("/title/00010001/41414141/content/00000003.app",bannerbuffer1,BUFFER_SIZE,&bbfs1);
ÂÂÂÂrets = ISFS_WriteFileFromArray("/tmp/00000000.app",bannerbuffer1,bbfs1,0,0,0,3,3,0);

ÂÂÂÂ//Delete the originals and move the copies into place.
ÂÂÂÂrets = ISFS_Delete("/title/00010001/41414141/content/00000000.app");
ÂÂÂÂrets = ISFS_Delete("/title/00010001/41414141/content/00000003.app");
ÂÂÂÂrets = ISFS_Rename("/tmp/00000000.app","/title/00010001/41414141/content/00000000.app");
ÂÂÂÂrets = ISFS_Rename("/tmp/00000003.app","/title/00010001/41414141/content/00000003.app");

ÂÂÂÂISFS_Deinitialize();
 

giantpune

Well-Known Member
Member
Joined
Apr 10, 2009
Messages
2,860
Trophies
0
XP
213
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?
 

techboy

Well-Known Member
OP
Member
Joined
Mar 15, 2009
Messages
1,720
Trophies
0
Age
31
Location
Pennsylvania
Website
Visit site
XP
306
Country
United States
giantpune said:
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?
The channel just won't appear on the menu if the banner is missing. The menu works fine, and does not brick. I accidentally discovered this when I forgot to uncomment the ISFS_Rename() calls in a build. I did have to reinstall the channel though (I lost the contents since they got left in /tmp/ ...oops).

QUOTEFunctions return values for a reason, you shouldn't ignore them.
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.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    BigOnYa @ BigOnYa: Ok thanks, I love my X but have not messed with a S yet.