11use winapi:: ctypes:: c_ulong;
22use winapi:: shared:: minwindef:: FALSE ;
3- use winapi:: um:: fileapi:: { GetDiskFreeSpaceExW , GetLogicalDriveStringsW , GetVolumeInformationW , GetDriveTypeW } ;
3+ use winapi:: um:: fileapi:: {
4+ GetDiskFreeSpaceExW , GetDriveTypeW , GetLogicalDriveStringsW , GetVolumeInformationW ,
5+ } ;
46use winapi:: um:: winnt:: ULARGE_INTEGER ;
57
68use super :: { last_os_error, u16_array_to_string} ;
79use crate :: data:: * ;
810
911use std:: char:: { decode_utf16, REPLACEMENT_CHARACTER } ;
10- use std:: { io, ptr} ;
1112use std:: mem:: MaybeUninit ;
13+ use std:: { io, ptr} ;
1214
1315pub fn drives ( ) -> io:: Result < Vec < Filesystem > > {
1416 let logical_drives = unsafe { GetLogicalDriveStringsW ( 0 , ptr:: null_mut ( ) ) } ;
@@ -48,7 +50,7 @@ pub fn drives() -> io::Result<Vec<Filesystem>> {
4850 free : ByteSize :: b ( 0 ) ,
4951 files : 0 ,
5052 files_total : 0 ,
51- files_avail : 0
53+ files_avail : 0 ,
5254 }
5355 } else {
5456 let ( total, avail, free) = get_disk_space_ext ( us) ?;
@@ -89,35 +91,35 @@ fn get_volume_information(name: &[u16]) -> io::Result<(c_ulong, String, String)>
8991 let mut max_component_length: c_ulong = 0 ;
9092 let mut fs_flags: c_ulong = 0 ;
9193
92- if FALSE == unsafe {
93- GetVolumeInformationW (
94- p_name,
95- p_volume_name,
96- 255 ,
97- p_volume_serial,
98- & mut max_component_length as * mut _ ,
99- & mut fs_flags as * mut _ ,
100- p_fs_name,
101- 255 ,
102- )
103- } {
104- match unsafe { GetDriveTypeW ( p_name) } {
105- 2 => { // REMOVABLE DRIVE (Floppy, USB, etc)
106- return Ok ( (
107- max_component_length,
108- String :: from ( "REM" ) ,
109- u16_array_to_string ( p_volume_name)
110- ) )
111- } ,
112- 5 => { // DRIVE_CDROM
113- return Ok ( (
114- max_component_length,
115- String :: from ( "CDROM" ) ,
116- u16_array_to_string ( p_volume_name)
117- ) )
118- } ,
119- _ => last_os_error ( ) ?
94+ if FALSE
95+ == unsafe {
96+ GetVolumeInformationW (
97+ p_name,
98+ p_volume_name,
99+ 255 ,
100+ p_volume_serial,
101+ & mut max_component_length as * mut _ ,
102+ & mut fs_flags as * mut _ ,
103+ p_fs_name,
104+ 255 ,
105+ )
106+ }
107+ {
108+ // Let's not cause the entire query to fail due to just one filesystem..
109+ let fs_name = match unsafe { GetDriveTypeW ( p_name) } {
110+ 1 => "NO_ROOT_DIR" ,
111+ 2 => "REMOVABLE" ,
112+ 3 => "FIXED" ,
113+ 4 => "REMOTE" ,
114+ 5 => "CDROM" ,
115+ 6 => "RAMDISK" ,
116+ _ => "UNKNOWN" ,
120117 } ;
118+ return Ok ( (
119+ max_component_length,
120+ String :: from ( fs_name) ,
121+ u16_array_to_string ( p_volume_name) ,
122+ ) ) ;
121123 }
122124
123125 Ok ( (
@@ -134,14 +136,16 @@ fn get_disk_space_ext(name: &[u16]) -> io::Result<(u64, u64, u64)> {
134136 let mut total: MaybeUninit < ULARGE_INTEGER > = MaybeUninit :: uninit ( ) ;
135137 let mut free: MaybeUninit < ULARGE_INTEGER > = MaybeUninit :: uninit ( ) ;
136138
137- if FALSE == unsafe {
138- GetDiskFreeSpaceExW (
139- p_name,
140- avail. as_mut_ptr ( ) ,
141- total. as_mut_ptr ( ) ,
142- free. as_mut_ptr ( ) ,
143- )
144- } {
139+ if FALSE
140+ == unsafe {
141+ GetDiskFreeSpaceExW (
142+ p_name,
143+ avail. as_mut_ptr ( ) ,
144+ total. as_mut_ptr ( ) ,
145+ free. as_mut_ptr ( ) ,
146+ )
147+ }
148+ {
145149 last_os_error ( ) ?;
146150 }
147151
0 commit comments