aldostools / webMAN-MOD

Extended services for PS3 console (web server, ftp server, netiso, ntfs, ps3mapi, etc.)
https://aldostools.github.io/webMAN-MOD/
GNU General Public License v3.0
1.25k stars 177 forks source link

[HELP] Not related to webMAN #1072

Closed LuanTeles closed 1 month ago

LuanTeles commented 1 month ago

Aldo, sorry for asking it here and it's not releated to webMAN at all, but i'm modding HEN and i added a copy command, but it is not working as intended

`int filecopy(const char src, const char dst) { int fd_src, fd_dst, ret; char buffer[0x1000]; uint64_t nread, nrw; CellFsStat stat;

if(cellFsStat(src, &stat) == CELL_FS_SUCCEEDED)
{
    cellFsChmod(src, 0777);

    if(cellFsOpen(src, CELL_FS_O_RDONLY, &fd_src, 0, 0) == CELL_FS_SUCCEEDED && 
       cellFsOpen(dst, CELL_FS_O_CREAT | CELL_FS_O_TRUNC | CELL_FS_O_RDWR, &fd_dst, 0, 0) == CELL_FS_SUCCEEDED)
    {
        while ((ret = cellFsRead(fd_src, buffer, sizeof(buffer), &nread)) == CELL_FS_SUCCEEDED)
        {
            if((int)nread)
            {
                ret = cellFsWrite(fd_dst, buffer, nread, &nrw);

                if(ret != CELL_FS_SUCCEEDED)
                {
                    cellFsClose(fd_src);
                    cellFsClose(fd_dst);
                    return 1;
                }

            }
            else
                break;
        }
        cellFsChmod(dst, 0777);
    }
    else
    {
        cellFsClose(fd_src);
        return 1;
    }
}
else
    return 1;

cellFsClose(fd_src);
cellFsClose(fd_dst);

return 0;

}

static void copy_files(void) { CellFsStat stat;

if(cellFsStat("/dev_hdd0/game/PS34KPROX/USRDIR/toolbox/patches/boot_plugins",&stat)!=0)
{
    filecopy("/dev_hdd0/game/PS34KPROX/USRDIR/toolbox/patches/boot_plugins/hfw/autoexec.bat","/dev_hdd0/autoexec.bat");
    filecopy("/dev_hdd0/game/PS34KPROX/USRDIR/toolbox/patches/boot_plugins/hfw/boot_init.txt","/dev_hdd0/boot_init.txt");
    filecopy("/dev_hdd0/game/PS34KPROX/USRDIR/toolbox/patches/boot_plugins/hfw/boot_plugins.txt","/dev_hdd0/boot_plugins.txt");
    filecopy("/dev_hdd0/game/PS34KPROX/USRDIR/toolbox/patches/boot_plugins/hfw/ingame.bat","/dev_hdd0/ingame.bat");
    filecopy("/dev_hdd0/game/PS34KPROX/USRDIR/toolbox/patches/boot_plugins/hfw/onxmb.bat","/dev_hdd0/onxmb.bat");
}

if(cellFsStat("/dev_hdd0/game/PS34KPROL/USRDIR/toolbox/patches/boot_plugins",&stat)!=0)
{
    filecopy("/dev_hdd0/game/PS34KPROL/USRDIR/toolbox/patches/boot_plugins/hfw/autoexec.bat","/dev_hdd0/autoexec.bat");
    filecopy("/dev_hdd0/game/PS34KPROL/USRDIR/toolbox/patches/boot_plugins/hfw/boot_init.txt","/dev_hdd0/boot_init.txt");
    filecopy("/dev_hdd0/game/PS34KPROL/USRDIR/toolbox/patches/boot_plugins/hfw/boot_plugins.txt","/dev_hdd0/boot_plugins.txt");
    filecopy("/dev_hdd0/game/PS34KPROL/USRDIR/toolbox/patches/boot_plugins/hfw/ingame.bat","/dev_hdd0/ingame.bat");
    filecopy("/dev_hdd0/game/PS34KPROL/USRDIR/toolbox/patches/boot_plugins/hfw/onxmb.bat","/dev_hdd0/onxmb.bat");
}

}`

If the destination files don't exist, both the source and destination files end up being 0 bytes. Do you have any idea why?

aldostools commented 1 month ago

I think the issue is the while. Try this code:

if(cellFsOpen(src, CELL_FS_O_RDONLY, &fd_src, 0, 0) == CELL_FS_SUCCEEDED)
{
    if(cellFsOpen(dst, CELL_FS_O_CREAT | CELL_FS_O_TRUNC | CELL_FS_O_RDWR, &fd_dst, 0, 0) == CELL_FS_SUCCEEDED)
    {
        ret = CELL_FS_SUCCEEDED;
        while (ret == CELL_FS_SUCCEEDED)
        {
             ret = cellFsRead(fd_src, buffer, sizeof(buffer), &nread);
             if(ret != CELL_FS_SUCCEEDED || !nread) break;
             ret = cellFsWrite(fd_dst, buffer, nread, &nrw);
         }
         cellFsClose(fd_src);
         cellFsClose(fd_dst);
         cellFsChmod(dst, 0777);
    }
    else
         cellFsClose(fd_src);
}
LuanTeles commented 1 month ago

Thank you Aldo

Looks like it's working properly now :)

LuanTeles commented 1 month ago

Tested again and the same thing happens: they copy correctly, but on the next rebootS, both source and destination gets 0KB . It seems the error occurs when the file already exists.

I don't want to check if they exist because I've seen packages that may include some of the files. So, I want to ensure mine are copied.

Do you have a solution in mind? or may i need to delete them before copying it on everyboot?

image image

aldostools commented 1 month ago

As you're copying the files from hdd0 to hdd0 you can use syscall 810 => sysLv2FsLink(file1, file2);

static int sysLv2FsLink(const char *oldpath, const char *newpath)
{
    system_call_2(810, (u64)(u32)oldpath, (u64)(u32)newpath);
    return_to_user_prog(int);
}

It's faster, links don't take much disk space. The unique downside is that if you modify the copy, the original is modified too.

LuanTeles commented 1 month ago

I was just about to ask you about the symbolic links as I was thinking of adding in the XMBM+ team installer.

Thank you, Aldo. It's working, and the issue is gone.