internal static FileSystem[] NativeGet(Sigar sigar) { System.Type typeFromHandle = typeof(FileSystemList); System.IntPtr intPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(typeFromHandle)); int num = FileSystemList.sigar_file_system_list_get(sigar.sigar.Handle, intPtr); if (num != 0) { System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr); throw Sigar.FindException(sigar, num); } FileSystemList fileSystemList = (FileSystemList)System.Runtime.InteropServices.Marshal.PtrToStructure(intPtr, typeFromHandle); FileSystem[] array = new FileSystem[fileSystemList.Number]; System.IntPtr ptr = fileSystemList.data; int num2 = System.Runtime.InteropServices.Marshal.SizeOf(array[0]); int num3 = 0; while ((long)num3 < (long)((ulong)fileSystemList.Number)) { array[num3] = (FileSystem)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr, typeof(FileSystem)); ptr = Sigar.incrementIntPtr(ptr, num2); num3++; } FileSystemList.sigar_file_system_list_destroy(sigar.sigar.Handle, intPtr); System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr); return(array); }
internal static FileSystem[] NativeGet(Sigar sigar) { Type type = typeof(FileSystemList); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_file_system_list_get(sigar.sigar.Handle, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } FileSystemList fsPtr = (FileSystemList)Marshal.PtrToStructure(ptr, type); FileSystem[] fs = new FileSystem[fsPtr.Number]; IntPtr fptr = fsPtr.data; int size = Marshal.SizeOf(fs[0]); for (int i = 0; i < fsPtr.Number; i++) { fs[i] = (FileSystem)Marshal.PtrToStructure(fptr, typeof(FileSystem)); //fptr += sizeof(sigar_fs_t); fptr = Sigar.incrementIntPtr(fptr, size); } sigar_file_system_list_destroy(sigar.sigar.Handle, ptr); Marshal.FreeHGlobal(ptr); return(fs); }