VolumeInfo.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (C) 2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using DiskAccessLibrary;
  11. using DiskAccessLibrary.LogicalDiskManager;
  12. namespace ISCSIConsole
  13. {
  14. public class VolumeInfo
  15. {
  16. public static bool IsOffline(Volume volume)
  17. {
  18. IList<PhysicalDisk> disks = GetVolumeDisks(volume);
  19. foreach (PhysicalDisk disk in disks)
  20. {
  21. bool isOnline = disk.GetOnlineStatus(out _) ?? false;
  22. if (isOnline)
  23. {
  24. return false;
  25. }
  26. }
  27. return true;
  28. }
  29. private static IList<PhysicalDisk> GetVolumeDisks(Volume volume)
  30. {
  31. SortedList<int, PhysicalDisk> disks = new SortedList<int, PhysicalDisk>();
  32. if (volume is DynamicVolume)
  33. {
  34. foreach (DiskExtent extent in ((DynamicVolume)volume).Extents)
  35. {
  36. if (extent.Disk is PhysicalDisk)
  37. {
  38. PhysicalDisk disk = (PhysicalDisk)extent.Disk;
  39. if (!disks.ContainsKey(disk.PhysicalDiskIndex))
  40. {
  41. disks.Add(disk.PhysicalDiskIndex, disk);
  42. }
  43. }
  44. }
  45. }
  46. else if (volume is Partition)
  47. {
  48. Partition partition = (Partition)volume;
  49. if (partition.Disk is PhysicalDisk)
  50. {
  51. PhysicalDisk disk = (PhysicalDisk)partition.Disk;
  52. disks.Add(disk.PhysicalDiskIndex, (PhysicalDisk)disk);
  53. }
  54. }
  55. return disks.Values;
  56. }
  57. }
  58. }