implement /dev/null
This commit is contained in:
		
							parent
							
								
									54243c543a
								
							
						
					
					
						commit
						9c9d1eed3a
					
				| @ -14,6 +14,7 @@ use self::inode_file::OpenOptions; | |||||||
| pub use self::pipe::Pipe; | pub use self::pipe::Pipe; | ||||||
| pub use self::io_multiplexing::*; | pub use self::io_multiplexing::*; | ||||||
| pub use self::access::{AccessModes, AccessFlags, AT_FDCWD, do_access, do_faccessat}; | pub use self::access::{AccessModes, AccessFlags, AT_FDCWD, do_access, do_faccessat}; | ||||||
|  | use self::null::NullFile; | ||||||
| use std::mem::uninitialized; | use std::mem::uninitialized; | ||||||
| 
 | 
 | ||||||
| mod file; | mod file; | ||||||
| @ -24,6 +25,7 @@ mod pipe; | |||||||
| mod sgx_impl; | mod sgx_impl; | ||||||
| mod io_multiplexing; | mod io_multiplexing; | ||||||
| mod access; | mod access; | ||||||
|  | mod null; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| pub fn do_open(path: &str, flags: u32, mode: u32) -> Result<FileDesc, Error> { | pub fn do_open(path: &str, flags: u32, mode: u32) -> Result<FileDesc, Error> { | ||||||
| @ -37,7 +39,7 @@ pub fn do_open(path: &str, flags: u32, mode: u32) -> Result<FileDesc, Error> { | |||||||
|     let mut proc = current_ref.lock().unwrap(); |     let mut proc = current_ref.lock().unwrap(); | ||||||
| 
 | 
 | ||||||
|     let file = proc.open_file(path, flags, mode)?; |     let file = proc.open_file(path, flags, mode)?; | ||||||
|     let file_ref: Arc<Box<File>> = Arc::new(Box::new(file)); |     let file_ref: Arc<Box<File>> = Arc::new(file); | ||||||
| 
 | 
 | ||||||
|     let fd = { |     let fd = { | ||||||
|         let close_on_spawn = flags.contains(OpenFlags::CLOEXEC); |         let close_on_spawn = flags.contains(OpenFlags::CLOEXEC); | ||||||
| @ -399,7 +401,10 @@ extern "C" { | |||||||
| 
 | 
 | ||||||
| impl Process { | impl Process { | ||||||
|     /// Open a file on the process. But DO NOT add it to file table.
 |     /// Open a file on the process. But DO NOT add it to file table.
 | ||||||
|     pub fn open_file(&self, path: &str, flags: OpenFlags, mode: u32) -> Result<INodeFile, Error> { |     pub fn open_file(&self, path: &str, flags: OpenFlags, mode: u32) -> Result<Box<File>, Error> { | ||||||
|  |         if path == "/dev/null" { | ||||||
|  |             return Ok(Box::new(NullFile)); | ||||||
|  |         } | ||||||
|         let inode = if flags.contains(OpenFlags::CREATE) { |         let inode = if flags.contains(OpenFlags::CREATE) { | ||||||
|             let (dir_path, file_name) = split_path(&path); |             let (dir_path, file_name) = split_path(&path); | ||||||
|             let dir_inode = self.lookup_inode(dir_path)?; |             let dir_inode = self.lookup_inode(dir_path)?; | ||||||
| @ -416,7 +421,7 @@ impl Process { | |||||||
|         } else { |         } else { | ||||||
|             self.lookup_inode(&path)? |             self.lookup_inode(&path)? | ||||||
|         }; |         }; | ||||||
|         INodeFile::open(inode, flags.to_options()) |         Ok(Box::new(INodeFile::open(inode, flags.to_options())?)) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Lookup INode from the cwd of the process
 |     /// Lookup INode from the cwd of the process
 | ||||||
|  | |||||||
							
								
								
									
										54
									
								
								src/libos/src/fs/null.rs
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										54
									
								
								src/libos/src/fs/null.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | |||||||
|  | use super::*; | ||||||
|  | 
 | ||||||
|  | #[derive(Debug)] | ||||||
|  | pub struct NullFile; | ||||||
|  | 
 | ||||||
|  | impl File for NullFile { | ||||||
|  |     fn read(&self, _buf: &mut [u8]) -> Result<usize, Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn write(&self, _buf: &[u8]) -> Result<usize, Error> { | ||||||
|  |         Ok(0) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn read_at(&self, _offset: usize, _buf: &mut [u8]) -> Result<usize, Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn write_at(&self, _offset: usize, _buf: &[u8]) -> Result<usize, Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn readv(&self, bufs: &mut [&mut [u8]]) -> Result<usize, Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn writev(&self, bufs: &[&[u8]]) -> Result<usize, Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn seek(&self, pos: SeekFrom) -> Result<off_t, Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn metadata(&self) -> Result<Metadata, Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn set_len(&self, len: u64) -> Result<(), Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn sync_all(&self) -> Result<(), Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn sync_data(&self) -> Result<(), Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn read_entry(&self) -> Result<String, Error> { | ||||||
|  |         unimplemented!() | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -101,7 +101,7 @@ fn init_files(parent_ref: &ProcessRef, file_actions: &[FileAction]) -> Result<Fi | |||||||
|                 &FileAction::Open { ref path, mode, oflag, fd} => { |                 &FileAction::Open { ref path, mode, oflag, fd} => { | ||||||
|                     let flags = OpenFlags::from_bits_truncate(oflag); |                     let flags = OpenFlags::from_bits_truncate(oflag); | ||||||
|                     let file = parent.open_file(path.as_str(), flags, mode)?; |                     let file = parent.open_file(path.as_str(), flags, mode)?; | ||||||
|                     let file_ref: Arc<Box<File>> = Arc::new(Box::new(file)); |                     let file_ref: Arc<Box<File>> = Arc::new(file); | ||||||
| 
 | 
 | ||||||
|                     let close_on_spawn = flags.contains(OpenFlags::CLOEXEC); |                     let close_on_spawn = flags.contains(OpenFlags::CLOEXEC); | ||||||
|                     cloned_file_table.put_at(fd, file_ref, close_on_spawn); |                     cloned_file_table.put_at(fd, file_ref, close_on_spawn); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user