add comment and reduce code in pre-open loading section

This commit is contained in:
Mark McCaskey
2019-04-19 13:24:41 -07:00
parent 5e504b77cd
commit 52279afbe2
2 changed files with 5 additions and 29 deletions

View File

@ -36,6 +36,7 @@ impl<T: Copy + ValueType> WasmPtr<T, Item> {
return Err(__WASI_EFAULT);
}
unsafe {
// clears bits below aligment amount (assumes power of 2) to align pointer
let aligner = |ptr: usize, align: usize| ptr & !(align - 1);
let cell_ptr = aligner(
memory.view::<u8>().as_ptr().add(self.offset as usize) as usize,

View File

@ -218,35 +218,10 @@ impl WasiFs {
file
));
};
let inode_val = InodeVal {
stat: __wasi_filestat_t {
st_filetype: __WASI_FILETYPE_DIRECTORY,
st_size: cur_file_metadata.len(),
st_atim: cur_file_metadata
.accessed()
.ok()
.and_then(|sys_time| sys_time.duration_since(SystemTime::UNIX_EPOCH).ok())
.map(|duration| duration.as_nanos() as u64)
.unwrap_or(0),
st_ctim: cur_file_metadata
.created()
.ok()
.and_then(|sys_time| sys_time.duration_since(SystemTime::UNIX_EPOCH).ok())
.map(|duration| duration.as_nanos() as u64)
.unwrap_or(0),
st_mtim: cur_file_metadata
.modified()
.ok()
.and_then(|sys_time| sys_time.duration_since(SystemTime::UNIX_EPOCH).ok())
.map(|duration| duration.as_nanos() as u64)
.unwrap_or(0),
..__wasi_filestat_t::default()
},
is_preopened: true,
// TODO: handle nested paths
name: file.clone(),
kind,
};
// TODO: handle nested pats in `file`
let inode_val =
InodeVal::from_file_metadata(cur_file_metadata, file.clone(), true, kind);
let inode = wasi_fs.inodes.insert(inode_val);
wasi_fs.inodes[inode].stat.st_ino = wasi_fs.inode_counter.get();
wasi_fs