-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't read files using fs::read
and fs::read_to_string
#96
Comments
Example: use c_str_macro::c_str;
fn init_partition(path: &CStr, label: &CStr, max_files: usize) {
let storage_conf = esp_vfs_spiffs_conf_t {
base_path: path.as_ptr(),
partition_label: label.as_ptr(),
max_files,
format_if_mount_failed: true,
};
unsafe { esp_vfs_spiffs_register(&storage_conf) };
}
fn test_fs() {
init_partition(c_str!("/storage"), c_str!("storage"), 3);
std::fs::write("/storage/test_file", "hello");
let str = std::fs::read_to_string("/storage/test_file").unwrap();
println!("String is: {:?}", str);
assert_eq!("hello", str);
} Output:
|
Hello @bugadani, I've been looking into the file system related issues, starting with this one. It seems in idf v4.4 (native) I can't reproduce your error, and with idf 4.3 (platformio) doesn't compile. Here is my test repo, https://github.com/MabezDev/esp-fs-test-suite, please point out anything I might have missed. |
Interesting, I still have this issue with idf v4.4. My project was set up based on https://github.com/ivmarkov/rust-esp32-example so it's possible something went wrong here. |
So interestingly, compiling for Xtensa in this case the esp32, I can reproduce your error on v4.4.
In this case the first three bytes seem to be missing (seems this has also been reported in esp-rs/esp-idf-sys#65) |
Looks like a miscompilation issue. If I set |
Ran this test case on Xtensa (esp32), with all opt-levels, here are the results. opt-level = 1Compilation failure:
opt-level = 2Runtime failure: String is: ""
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `"hello"`,
right: `""`', src/main.rs:42:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
abort() was called at PC 0x400f282e on core 0
Backtrace:0x40081a5a:0x3ffb63900x40085a31:0x3ffb63b0 0x4008aeb2:0x3ffb63d0 0x400f282e:0x3ffb6440 0x400f2822:0x3ffb6460 0x400dda31:0x3ffb6480 0x400dda12:0x3ffb64f0 0x400d4fe7:0x3ffb6550 0x400d4bc5:0x3ffb6580 0x400dd611:0x3ffb65b0 0x4010063f:0x3ffb65e0 0x401006fe:0x3ffb6610 0x400d35b1:0x3ffb66a0 0x400d34ba:0x3ffb66f0 0x4011a99f:0x3ffb6750 0x400d3210:0x3ffb6770 0x400d5805:0x3ffb6790 0x400d3575:0x3ffb67c0 0x400d38df:0x3ffb67f0 0x4011bb01:0x3ffb6810 0x40088399:0x3ffb6830 opt-level = 3Runtime failure: String is: ""
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `"hello"`,
right: `""`', src/main.rs:42:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
abort() was called at PC 0x400f5172 on core 0
Backtrace:0x40081a5a:0x3ffb63800x40085a31:0x3ffb63a0 0x4008aeb2:0x3ffb63c0 0x400f5172:0x3ffb6430 0x400f5166:0x3ffb6450 0x400de2bd:0x3ffb6470 0x400de298:0x3ffb64f0 0x400d4f71:0x3ffb6560 0x400d4a48:0x3ffb6590 0x400ddd85:0x3ffb65b0 0x40105ff7:0x3ffb65e0 0x401060bd:0x3ffb6610 0x400d305d:0x3ffb66a0 0x400d3341:0x3ffb66f0 0x4012084b:0x3ffb6750 0x400d30b8:0x3ffb6770 0x400d5949:0x3ffb6790 0x400d3415:0x3ffb67c0 0x400d372b:0x3ffb67f0 0x40121aa1:0x3ffb6810 0x40088399:0x3ffb6830 opt-level = 's'Runtime failure: String is: ""
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `"hello"`,
right: `""`', src/main.rs:42:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
abort() was called at PC 0x400f3162 on core 0
Backtrace:0x40081a5e:0x3ffb61800x40085305:0x3ffb61a0 0x40089b52:0x3ffb61c0 0x400f3162:0x3ffb6230 0x400f3156:0x3ffb6250 0x400e27d1:0x3ffb6270 0x400e2769:0x3ffb62f0 0x400d9507:0x3ffb6360 0x400d9225:0x3ffb6390 0x400e24e5:0x3ffb63c0 0x401009b3:0x3ffb63f0 0x40100af8:0x3ffb6420 0x400d3e13:0x3ffb64b0 0x400d3d8e:0x3ffb6500 0x401195ff:0x3ffb6570 0x400d3de0:0x3ffb6590 0x400f0859:0x3ffb65b0 0x400d3dc1:0x3ffb65d0 0x400d4123:0x3ffb6600 0x4011a5a4:0x3ffb6620 opt-level = 'z'Runtime failure: String is: "lo"
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `"hello"`,
right: `"lo"`', src/main.rs:42:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
abort() was called at PC 0x400f3826 on core 0
Backtrace:0x40081a5e:0x3ffb61700x40085305:0x3ffb6190 0x40089b52:0x3ffb61b0 0x400f3826:0x3ffb6220 0x400f381a:0x3ffb6240 0x400e32a1:0x3ffb6260 0x400e328b:0x3ffb62e0 0x400d9db3:0x3ffb6340 0x400d9a0d:0x3ffb6370 0x400e30b8:0x3ffb63a0 0x4010194b:0x3ffb63d0 0x40101a90:0x3ffb6400 0x400d4bc7:0x3ffb6490 0x400d4afe:0x3ffb64e0 0x4011a50b:0x3ffb6550 0x400d4c04:0x3ffb6570 0x400f13f5:0x3ffb6590 0x400d4bf2:0x3ffb65b0 0x400d4b55:0x3ffb65e0 0x400d4f5f:0x3ffb6600 0x4011b7b0:0x3ffb6620 |
I’ve run into this problem too. Writing seems to work. The files get created, but reading them, they are empty (not just missing 3 characters). In my case, I can’t seem to work around it with opt-level = 0. I think that makes my firmware too large to fit into ram or something and it locks up while booting. |
If you're using a chip with 2MB of flash, this might be the case. When testing I was using an esp32 with 4MB of flash. |
Would you guys mind trying the 1.60.0.0 branch of the compiler? It seems this has been fixed by updating libc, which is sort of surprising. Would be great if either of you could confirm :). |
|
This is still an issue with the esp32c3, with the built-in compiler, I am getting a core dump:
Code is:
|
I am using an esp32c3 with 4MB of flash and esp-idf master (5.1) |
@axos88 Sorry to hear you're having issues. esp-idf v5 is not yet officially supported, so there is still some work to do. With that said, this should be fixable by upgrading libc in the standard library to a version which includes this PR: rust-lang/libc#2913. Then you will also need to pass Feel free to open a new issues if it persists :). |
Ah gotcha. Does that mean if I update to latest nightly, and include the RUSTFLAG, it should work? |
Shouldn't adding a dependency and patch to My rustflags are: |
Unfortunately not, because cargo patch does not patch std dependencies. |
@MabezDev, so do you have any pointers on how to do what you are suggesting? upgrading libc in the standard library to a version which includes rust-lang/libc#2913? |
I tried reading files using the fs helper functions
read
andread_to_string
. I was lazy to verify the actual return value, but the length of the returned data was considerably shorter (< 4 bytes) than the contents of the files.Reading the files using
File::open().read()
worked as expected. Writing the files using eitherio::Write
orstd::fs::write
works.The text was updated successfully, but these errors were encountered: