From def861510944e13b99570d0d4cae5342ee729d2f Mon Sep 17 00:00:00 2001 From: WangRunji Date: Tue, 5 Mar 2019 18:01:22 +0800 Subject: [PATCH] fix opening file in SGX --- rcore-fs-sefs/src/dev/sgx_impl.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/rcore-fs-sefs/src/dev/sgx_impl.rs b/rcore-fs-sefs/src/dev/sgx_impl.rs index fcd056a..2fdd6dc 100644 --- a/rcore-fs-sefs/src/dev/sgx_impl.rs +++ b/rcore-fs-sefs/src/dev/sgx_impl.rs @@ -28,14 +28,18 @@ impl super::Storage for SgxStorage { fn open(&self, file_id: usize) -> DevResult> { let mut path = self.path.to_path_buf(); path.push(format!("{}", file_id)); - let file = OpenOptions::new().read(true).write(true).open(path)?; + // TODO: key + let key = [0u8; 16]; + let file = OpenOptions::new().read(true).update(true).open_ex(path, &key)?; Ok(Box::new(LockedFile(Mutex::new(file)))) } fn create(&self, file_id: usize) -> DevResult> { let mut path = self.path.to_path_buf(); path.push(format!("{}", file_id)); - let file = OpenOptions::new().read(true).write(true).open(path)?; + // TODO: key + let key = [0u8; 16]; + let file = OpenOptions::new().write(true).update(true).open_ex(path, &key)?; Ok(Box::new(LockedFile(Mutex::new(file)))) } @@ -49,6 +53,7 @@ impl super::Storage for SgxStorage { impl From for DeviceError { fn from(e: std::io::Error) -> Self { + println!("{:?}", e); panic!("{:?}", e); DeviceError } @@ -64,10 +69,7 @@ impl super::File for LockedFile { fn read_at(&self, buf: &mut [u8], offset: usize) -> DevResult { let mut file = self.0.lock().unwrap(); let offset = offset as u64; - let real_offset = file.seek(SeekFrom::Start(offset))?; - if real_offset != offset { - return Err(DeviceError); - } + file.seek(SeekFrom::Start(offset))?; let len = file.read(buf)?; Ok(len) } @@ -75,10 +77,7 @@ impl super::File for LockedFile { fn write_at(&self, buf: &[u8], offset: usize) -> DevResult { let mut file = self.0.lock().unwrap(); let offset = offset as u64; - let real_offset = file.seek(SeekFrom::Start(offset))?; - if real_offset != offset { - return Err(DeviceError); - } + file.seek(SeekFrom::Start(offset))?; let len = file.write(buf)?; Ok(len) }