Get a list of mounted paths in a memory handle
(context_ptr: *mut Context)
| 837 | |
| 838 | /// Get a list of mounted paths in a memory handle |
| 839 | fn sys_listmounts(context_ptr: *mut Context) { |
| 840 | if let Some(mut thread) = process::take_current_thread() { |
| 841 | thread.set_context(context_ptr); |
| 842 | let context = unsafe {&mut (*context_ptr)}; |
| 843 | |
| 844 | // Get a JSON string containing VFS mounts |
| 845 | let json = thread.vfs().to_json(); |
| 846 | |
| 847 | // No longer need thread, needed |
| 848 | // by process::new_memory_chunk |
| 849 | process::set_current_thread(thread); |
| 850 | |
| 851 | // Allocate memory chunk to hold the data |
| 852 | let num_bytes = json.len() as u64; |
| 853 | let num_pages = (num_bytes >> 12) + |
| 854 | if (num_bytes & 4095) != 0 {1} else {0}; |
| 855 | |
| 856 | match process::new_memory_chunk( |
| 857 | num_pages, |
| 858 | 0xFFFF_FFFF_FFFF_FFFF) { |
| 859 | Ok((virtaddr, _physaddr)) => { |
| 860 | // Copy string into memory chunk |
| 861 | unsafe { |
| 862 | ptr::copy_nonoverlapping(json.as_ptr(), |
| 863 | virtaddr.as_u64() as *mut u8, |
| 864 | json.len()); |
| 865 | } |
| 866 | |
| 867 | context.rax = 0; // No error |
| 868 | context.rdi = virtaddr.as_u64() as usize; |
| 869 | context.rsi = json.len(); |
| 870 | } |
| 871 | Err(code) => { |
| 872 | context.rax = code; |
| 873 | context.rdi = 0; |
| 874 | context.rsi = 0; |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | /// Remove a mount point. |
| 881 | /// Most of this code is the same as `sys_mount` |
no test coverage detected