1. blawar

    blawar Developer
    Developer

    Joined:
    Nov 21, 2016
    Messages:
    1,665
    Country:
    United States
    Are there a lot of people who use external hard drives formatted to EXT*?

    I uploaded snippets of the MBR/GPT code I wrote for Tinfoil, I hope it saves you some time if you intend to parse the MBR/GPT manually: https://gist.github.com/blawar/98635098baa9ae8ba502dfd62a5c8417

    note that EXFAT and NTFS both share the same partition code (annoying). The only way to differentiate them is to actually read from the partition itself ti try to figure out the file system.
     
    Last edited by blawar, Nov 24, 2020
    Helidwarf, peteruk and DarkMatterCore like this.
  2. DarkMatterCore

    OP DarkMatterCore I like turtles.
    Developer

    Joined:
    May 30, 2009
    Messages:
    1,204
    Country:
    Venezuela
    @blawar Thanks! I'll check that out in a minute. :)

    Not a whole lot of people uses EXT in their external drives, I reckon that. But I want to offer that option anyway. Some developers running a Linux distro most likely do, as well as some end users (I know a few who do) - and since this is aimed at developers in the first place, I just feel like it may be a good thing in the long run.

    I've been around since the Wii era, and EXT support was something big back then. I see no reason to, at least, not try to surpass what people achieved back then.
     
    Last edited by DarkMatterCore, Nov 24, 2020
  3. ploggy

    ploggy WAKA! WAKA!
    Member

    Joined:
    Aug 29, 2007
    Messages:
    3,654
    Country:
    United Kingdom
    Where were you during the WiiU days ? :P I still don't think we have proper WiiU hdd support for HB lol
     
    I pwned U!, Cylent1, ber71 and 2 others like this.
  4. DarkMatterCore

    OP DarkMatterCore I like turtles.
    Developer

    Joined:
    May 30, 2009
    Messages:
    1,204
    Country:
    Venezuela
    In college. I always wanted to get a Wii U, but I just couldn't back then. And the total obliteration of my country's economical system didn't make things easier (still doesn't).
     
    I pwned U!, ploggy and cucholix like this.
  5. ploggy

    ploggy WAKA! WAKA!
    Member

    Joined:
    Aug 29, 2007
    Messages:
    3,654
    Country:
    United Kingdom
    oof yeah that'll do it :P but if you ever do find yourself with a WiiU we could really use your talents ;) heh
     
  6. peteruk

    peteruk GBAtemp Addict
    Member

    Joined:
    Jun 26, 2015
    Messages:
    2,629
    Country:
    United Kingdom
    Love you DKM - sending positive vibes to you <3
     
    DarkMatterCore likes this.
  7. DarkMatterCore

    OP DarkMatterCore I like turtles.
    Developer

    Joined:
    May 30, 2009
    Messages:
    1,204
    Country:
    Venezuela
    I'll get on it if I ever get one, for sure. :)
     
    I pwned U!, Ghost92, peteruk and 2 others like this.
  8. blawar

    blawar Developer
    Developer

    Joined:
    Nov 21, 2016
    Messages:
    1,665
    Country:
    United States
    Could you please implement SX's USB api on the backend, so developers who use this library will automatically work on both atmosphere and sxos with no code changes? The relevant code is here: https://github.com/blawar/tinleaf/blob/master/source/nx/usbhdd.cpp

    It is not currently working in SXOS though because the code in Tinleaf is low quality, and I do not believe their API supports relative paths.
     
    kickmeh, ber71, Cylent1 and 1 other person like this.
  9. DarkMatterCore

    OP DarkMatterCore I like turtles.
    Developer

    Joined:
    May 30, 2009
    Messages:
    1,204
    Country:
    Venezuela
    Sure. If it can be done, I'll look into it. Doesn't really matter if they support relative paths or not, because I reimplemented that in a way similar to how libnx handles it - which is allocating a cwd buffer per mounted volume and just pass a full, absolute path to the destination filesystem library. Check the dev branch - those funny public functions for (un)setting a default device are no more.

    I'm currently working on MBR / GPT / SFD (VBR) parsing + fixing some issues with the BOT driver (someone broke usb:hs using a Vita in UMS mode, somehow). lol

    — Posts automatically merged - Please don't double post! —

    @blawar Would you give permission to license the SX service init code under ISC? Nevermind, the license left by TX is permissive enough.
     
    Last edited by DarkMatterCore, Nov 27, 2020
    I pwned U!, ber71 and nWo like this.
  10. blawar

    blawar Developer
    Developer

    Joined:
    Nov 21, 2016
    Messages:
    1,665
    Country:
    United States
    I was gong to say, their license is pretty permissive. So I downloaded those files from the website years ago, and then I ported them to the latest libnx when they did that big service api rewrite. However any code that I wrote in that tinleaf repo you are free to use and re-license in any way you see fit.

    — Posts automatically merged - Please don't double post! —

    Also, ensure it is actually SXOS and not reinx or AMS before you try to initialize TX services or it will crash the user's switch. The code used for detecting SXOS on that file I linked works.
     
    DarkMatterCore likes this.
  11. DarkMatterCore

    OP DarkMatterCore I like turtles.
    Developer

    Joined:
    May 30, 2009
    Messages:
    1,204
    Country:
    Venezuela
    @blawar Is it absolutely necessary to initialize a handle to the tx service beforehand?
     
  12. blawar

    blawar Developer
    Developer

    Joined:
    Nov 21, 2016
    Messages:
    1,665
    Country:
    United States
    I just tested it, and no, tx.h, tx.c, txInitialize(), and txExit() do not appear to be needed.
     
    DarkMatterCore likes this.
  13. DarkMatterCore

    OP DarkMatterCore I like turtles.
    Developer

    Joined:
    May 30, 2009
    Messages:
    1,204
    Country:
    Venezuela
    https://github.com/DarkMatterCore/libusbhsfs/commit/75f53bf707053f6b070ec3c8fca53b9ef9ccece5

    There you go. It's still untested (no Switch, no SX OS). Feel free to build it and try it.

    It should work exactly like it does under Atmosphère. If successful, usbHsFsGetMountedDeviceCount() should always return 1 after the user event is signaled, though.
     
    Last edited by DarkMatterCore, Nov 27, 2020
    ber71 and kickmeh like this.
  14. blawar

    blawar Developer
    Developer

    Joined:
    Nov 21, 2016
    Messages:
    1,665
    Country:
    United States
    I compiled it and ran your example app in SXOS with USBHDD attached and got this:

    USB MAss Storage status change event triggered!
    Mounted USB Mass Storage device count: 1
    Failed to list mounted USB Mass Storage devices!
     
  15. blawar

    blawar Developer
    Developer

    Joined:
    Nov 21, 2016
    Messages:
    1,665
    Country:
    United States
    This fixes the error, there was a logic error

    Code:
    u32 usbHsFsListMountedDevices(UsbHsFsDevice *out, u32 max_count)
    {
        mutexLock(&g_managerMutex);
     
        u32 device_count = 0, ret = 0;
     
        if (g_isSXOS)
        {
            if(g_sxOSDeviceAvailable)
            {
                /* Copy device data, update return value and jump to the end. */
                memcpy(out, &g_sxOSDevice, sizeof(UsbHsFsDevice));
                ret = 1;
            }
            goto end;
        }
     
        if (!g_usbHsFsInitialized || !g_driveCount || !g_driveContexts || (!g_isSXOS && !(device_count = usbHsFsMountGetDevoptabDeviceCount())) || !out || !max_count)
        {
            USBHSFS_LOG("Invalid parameters!");
            goto end;
        }
     
        for(u32 i = 0; i < g_driveCount; i++)
        {
            UsbHsFsDriveContext *drive_ctx = &(g_driveContexts);
        
            for(u8 j = 0; j < drive_ctx->lun_count; j++)
            {
                UsbHsFsDriveLogicalUnitContext *lun_ctx = &(drive_ctx->lun_ctx[j]);
            
                for(u32 k = 0; k < lun_ctx->fs_count; k++)
                {
                    UsbHsFsDriveLogicalUnitFileSystemContext *fs_ctx = &(lun_ctx->fs_ctx[k]);
                
                    /* Fill device element. */
                    UsbHsFsDevice *device = &(out[ret++]);  /* Increase return value. */
                    usbHsFsFillDeviceElement(drive_ctx, lun_ctx, fs_ctx, device);
                
                    /* Jump out of the loops if we have reached a limit */
                    if (ret >= max_count || ret >= device_count) goto end;
                }
            }
        }
     
    end:
        mutexUnlock(&g_managerMutex);
     
        return ret;
    }
    — Posts automatically merged - Please don't double post! —

    This is the output from your test program on SXOS. IIRC SX's api does not support renaming files on the hard drive which may be the cause of that error.
     

    Attached Files:

    nWo and DarkMatterCore like this.
  16. DarkMatterCore

    OP DarkMatterCore I like turtles.
    Developer

    Joined:
    May 30, 2009
    Messages:
    1,204
    Country:
    Venezuela
    Yeah. Errors like that were to be expected. I stubbed certain calls from its devoptab device interface (chdir, rename, dirreset, utimes and others).

    — Posts automatically merged - Please don't double post! —

    Hmm, gotta take another good look at statvfs(). It is supported.
     
    ber71 likes this.
  17. blawar

    blawar Developer
    Developer

    Joined:
    Nov 21, 2016
    Messages:
    1,665
    Country:
    United States
    I updated Tinleaf to use use your dev branch, and released a binary: https://github.com/blawar/tinleaf/releases/tag/1.4.1

    I tested it on both SXOS and AMS, works great.
     
    lordelan, ber71 and DarkMatterCore like this.
  18. DarkMatterCore

    OP DarkMatterCore I like turtles.
    Developer

    Joined:
    May 30, 2009
    Messages:
    1,204
    Country:
    Venezuela
    Nice! I'm looking into the statvfs() issue atm, but I fail to see what could have gone wrong here:

    Ah, the return value. lol I should get some sleep.
     
    Last edited by DarkMatterCore, Nov 27, 2020
  19. blawar

    blawar Developer
    Developer

    Joined:
    Nov 21, 2016
    Messages:
    1,665
    Country:
    United States
    It might be a bug with SXOS's driver. I remember when they first released the homebrew library, I had a graph at the top for hdd free space but it was very buggy and locked up my app for like 30 seconds so I removed it.

    Perhaps a further down the road thing (since it is 99% there already), however SXOS' server lets you read and write directly from the storage. It is possible for you to just issue raw storage read/write commands and unify the code even more. Then you could implement the things you stubbed.

    Thanks for the quick work. This is a really great thing that there is a standard interface for accessing HDD's on all CFW's.
     
    ber71 likes this.
  20. DarkMatterCore

    OP DarkMatterCore I like turtles.
    Developer

    Joined:
    May 30, 2009
    Messages:
    1,204
    Country:
    Venezuela
    I wouldn't have done it if you didn't give me permission to relicense the code I needed, so thank you.

    About the raw logical block commands, I did consider it but I only saw "ReadRaw" - no "WriteRaw" available as part of the IPC command list.

    — Posts automatically merged - Please don't double post! —

    There's also no command to retrieve the logical block size and the total logical block count.
     
    peteruk likes this.
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - libusbhsfs, Filesystem, Storage