Skip to content

Commit 8cd06a4

Browse files
Tropix126max-niederman
authored andcommitted
remove test code and document filesystem quirks
1 parent 50333f7 commit 8cd06a4

File tree

3 files changed

+18
-51
lines changed

3 files changed

+18
-51
lines changed

library/std/src/sys/pal/vexos/fs.rs

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub struct File {
1313
fd: FileDesc,
1414
}
1515

16-
//TODO: We may be able to get some of this info
1716
#[derive(Clone)]
1817
pub struct FileAttr {
1918
size: u64,
@@ -72,7 +71,6 @@ impl FileAttr {
7271

7372
let file_type = unsafe { vex_sdk::vexFileStatus(c_path.as_ptr()) };
7473
let is_dir = file_type == 3;
75-
println!("{is_dir}");
7674

7775
// We can't get the size if its a directory because we cant open it as a file
7876
if is_dir {
@@ -342,7 +340,7 @@ impl File {
342340
map_fresult(vex_sdk::vexFileSeek(self.fd.0, try_convert_offset(offset)?, SEEK_SET))?
343341
},
344342

345-
// The VEX SDK does not allow seeking with negative offsets.
343+
// vexOS does not allow seeking with negative offsets.
346344
// That means we need to calculate the offset from the start for both of these.
347345
SeekFrom::End(offset) => unsafe {
348346
// If our offset is positive, everything is easy
@@ -429,52 +427,15 @@ impl Drop for File {
429427
}
430428
}
431429

432-
pub fn readdir(p: &Path) -> io::Result<ReadDir> {
433-
// getting directory entries does not work with trailing slashes
434-
let p = Path::new(
435-
p.to_str()
436-
.ok_or(io::Error::new(
437-
io::ErrorKind::InvalidInput,
438-
"Path contained invalid characters",
439-
))?
440-
.trim_end_matches("/"),
441-
);
442-
443-
if !stat(p)?.file_type().is_dir() {
444-
return Err(io::Error::new(io::ErrorKind::InvalidInput, "Given directory was not a path"));
445-
}
446-
447-
let path = CString::new(p.as_os_str().as_encoded_bytes())
448-
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "Path contained a null byte"))?;
449-
450-
//TODO: Figure out if there is any way to check the number of entries in a directory/the needed length
451-
let mut filenames_buffer = [0u8; 1000];
452-
unsafe {
453-
vex_sdk::vexFileDirectoryGet(
454-
path.as_ptr(),
455-
filenames_buffer.as_mut_ptr().cast(),
456-
filenames_buffer.len() as _,
457-
);
458-
}
459-
let filenames_buffer = filenames_buffer.to_vec();
460-
// stop at null-terminator
461-
let filenames = match filenames_buffer.split(|&e| e == 0).next() {
462-
Some(filenames) => filenames,
463-
None => &filenames_buffer,
464-
};
465-
let filenames = String::from_utf8(filenames.to_vec())
466-
.map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "Path contained a null byte"))?;
467-
let paths = filenames
468-
.split('\n')
469-
.map(|filename| {
470-
let mut path = PathBuf::new();
471-
path.push(p);
472-
path.push(filename);
473-
DirEntry { path }
474-
})
475-
.collect::<Vec<_>>();
476-
477-
Ok(ReadDir { entries: paths })
430+
pub fn readdir(_p: &Path) -> io::Result<ReadDir> {
431+
// While there *is* a userspace function for reading file directories,
432+
// the necessary implementation cannot currently be done cleanly, as
433+
// vexOS does not expose directory length to user programs.
434+
//
435+
// This means that we would need to create a large fixed-length buffer
436+
// and hope that the folder's contents didn't exceed that buffer's length,
437+
// which obviously isn't behavior we want to rely on in the standard library.
438+
unsupported()
478439
}
479440

480441
pub fn unlink(_p: &Path) -> io::Result<()> {
@@ -522,7 +483,7 @@ pub fn stat(p: &Path) -> io::Result<FileAttr> {
522483
}
523484

524485
pub fn lstat(p: &Path) -> io::Result<FileAttr> {
525-
// Symlinks aren't supported in our filesystem
486+
// Symlinks aren't supported in this filesystem
526487
stat(p)
527488
}
528489

library/std/src/sys/pal/vexos/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ pub unsafe extern "C" fn _start() -> ! {
3434
fn main() -> i32;
3535
}
3636

37+
// Setup the stack
3738
asm!("ldr sp, =__stack_top", options(nostack));
3839

40+
// vexOS doesn't explicitly clean out .bss, so as a sanity
41+
// check we'll fill it with zeroes.
3942
ptr::slice_from_raw_parts_mut(
4043
addr_of_mut!(__bss_start),
4144
addr_of_mut!(__bss_end).offset_from(addr_of_mut!(__bss_start)) as usize,

library/std/src/sys/pal/vexos/stdio.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ impl io::Write for Stdout {
4444
unsafe { vex_sdk::vexSerialWriteBuffer(STDIO_CHANNEL, buf.as_ptr(), buf.len() as u32) };
4545

4646
if written < 0 {
47-
return Err(io::Error::new(io::ErrorKind::Other, "Internal write error occurred."));
47+
return Err(io::Error::new(
48+
io::ErrorKind::Uncategorized,
49+
"Internal write error occurred.",
50+
));
4851
}
4952

5053
Ok(written as usize)

0 commit comments

Comments
 (0)