libctru icon indicating copy to clipboard operation
libctru copied to clipboard

osGetSystemVersionData causes file access to fail

Open svanheulen opened this issue 10 years ago • 11 comments

It appears that after using osGetSystemVersionData I can no longer open files. Here's some example code that shows the bug: https://gist.github.com/svanheulen/c02033d70f674c2a3169 The first attempt to open the file will succeed (remember to make the "test.txt" file) Then the second attempt, after osGetSystemVersionData is used, will fail.

svanheulen avatar Jan 19 '16 00:01 svanheulen

I can confirm this. errno is set to ENOSYS

mtheall avatar Jan 19 '16 00:01 mtheall

It appears that sdmc_open() is not being called for the second fopen(), even if I set the path to "sdmc:/test.txt"

mtheall avatar Jan 19 '16 00:01 mtheall

After calling osGetSystemVersionData(), FindDevice("sdmc:") returns -1.

mtheall avatar Jan 19 '16 01:01 mtheall

I can confirm that before osGetSystemVersionData(), the devoptab_list[] has the following contents: devoptab_list[1] -> con devoptab_list[2] -> con devoptab_list[3] -> sdmc

After osGetSystemVersionData(), the devoptab_list[] has the following contents: devoptab_list[1] -> con devoptab_list[2] -> con devoptab_list[3] -> dotab_stdnull devoptab_list[4] -> romfs

mtheall avatar Jan 19 '16 01:01 mtheall

osGetSystemVersionData() calls __read_versionbin() __read_versionbin() calls romfsInitFromFile()/romfsExit() but after romfsExit() the sdmc dev is gone but romfs dev is still there. problem in newlib or libctru?

mtheall avatar Jan 19 '16 01:01 mtheall

I noticed in __read_versionbin() it calls FSUSER_OpenFileDirectly but never calls FSFILE_Close on that handle. Could that be an issue?

svanheulen avatar Jan 19 '16 01:01 svanheulen

Fixed with 07f0fe7e6

mtheall avatar Jan 19 '16 01:01 mtheall

It probably is a bug that the file handle isn't closed, but that wasn't the cause of this issue.

mtheall avatar Jan 19 '16 01:01 mtheall

I noticed in __read_versionbin() it calls FSUSER_OpenFileDirectly but never calls FSFILE_Close on that handle. Could that be an issue?

Nope, the file is closed by romfsExit() here https://github.com/smealum/ctrulib/blob/master/libctru/source/romfs_dev.c#L228

Lectem avatar Jan 19 '16 01:01 Lectem

Awesome! Thanks for fixing that so fast!

svanheulen avatar Jan 19 '16 01:01 svanheulen

No problem, I'm glad it wasn't something harder to debug.

mtheall avatar Jan 19 '16 01:01 mtheall