(vm: &VirtualMachine)
| 1848 | |
| 1849 | #[pyfunction] |
| 1850 | fn listvolumes(vm: &VirtualMachine) -> PyResult<PyListRef> { |
| 1851 | use windows_sys::Win32::Foundation::ERROR_NO_MORE_FILES; |
| 1852 | |
| 1853 | let mut result = Vec::new(); |
| 1854 | let mut buffer = [0u16; Foundation::MAX_PATH as usize + 1]; |
| 1855 | |
| 1856 | let find = unsafe { FileSystem::FindFirstVolumeW(buffer.as_mut_ptr(), buffer.len() as _) }; |
| 1857 | if find == INVALID_HANDLE_VALUE { |
| 1858 | return Err(vm.new_last_os_error()); |
| 1859 | } |
| 1860 | |
| 1861 | loop { |
| 1862 | // Find the null terminator |
| 1863 | let len = buffer.iter().position(|&c| c == 0).unwrap_or(buffer.len()); |
| 1864 | let volume = String::from_utf16_lossy(&buffer[..len]); |
| 1865 | result.push(vm.new_pyobj(volume)); |
| 1866 | |
| 1867 | let ret = unsafe { |
| 1868 | FileSystem::FindNextVolumeW(find, buffer.as_mut_ptr(), buffer.len() as _) |
| 1869 | }; |
| 1870 | if ret == 0 { |
| 1871 | let err = io::Error::last_os_error(); |
| 1872 | unsafe { FileSystem::FindVolumeClose(find) }; |
| 1873 | if err.raw_os_error() == Some(ERROR_NO_MORE_FILES as i32) { |
| 1874 | break; |
| 1875 | } |
| 1876 | return Err(err.to_pyexception(vm)); |
| 1877 | } |
| 1878 | } |
| 1879 | |
| 1880 | Ok(vm.ctx.new_list(result)) |
| 1881 | } |
| 1882 | |
| 1883 | #[pyfunction] |
| 1884 | fn listmounts(volume: OsPath, vm: &VirtualMachine) -> PyResult<PyListRef> { |
nothing calls this directly
no test coverage detected