diff --git a/SabreTools.IO.Extensions/IOExtensions.cs b/SabreTools.IO.Extensions/IOExtensions.cs index db99dba..fa31586 100644 --- a/SabreTools.IO.Extensions/IOExtensions.cs +++ b/SabreTools.IO.Extensions/IOExtensions.cs @@ -1103,78 +1103,6 @@ namespace SabreTools.IO.Extensions return result; } - /// - /// Read the sysfs "removable" flag for a block device - /// - /// Path to the device directory under the sysfs block root - /// True when the device reports itself as removable, false otherwise - public static bool ReadUnixRemovableFlag(string sysBlockEntry) - { - string removablePath = Path.Combine(sysBlockEntry, "removable"); - try - { - if (!File.Exists(removablePath)) - return false; - - string removableString = File.ReadAllText(removablePath).Trim(); - return removableString == "1"; - } - catch - { - return false; - } - } - - /// - /// Read the device size from sysfs (reported in 512-byte sectors) and convert to bytes - /// - /// Path to the device directory under the sysfs block root - /// The device size in bytes, 0 on error - public static long ReadUnixBlockDeviceSize(string sysBlockEntry) - { - string sizePath = Path.Combine(sysBlockEntry, "size"); - try - { - if (!File.Exists(sizePath)) - return 0; - - string sizeString = File.ReadAllText(sizePath).Trim(); - if (long.TryParse(sizeString, out long sectors) && sectors > 0) - return sectors * 512; - } - catch - { - // Unreadable size; report it as unknown - } - - return 0; - } - - /// - /// Read the device size from sysfs (reported in 512-byte sectors) and convert to bytes - /// - /// Path to the device directory under the sysfs block root - /// The device size in bytes, 0 on error - public static int ReadUnixBlockDeviceType(string sysGenericEntry) - { - string typePath = Path.Combine(Path.Combine(sysGenericEntry, "device"), "type"); - try - { - if (!File.Exists(typePath)) - return 0; - - string typeString = File.ReadAllText(typePath).Trim(); - if (int.TryParse(typeString, out int scsiType)) - return scsiType; - } - catch - { - // Unreadable type; report it as unknown - } - - return 0; - } - /// /// Check that a device node name is the given prefix followed by one or more digits /// (e.g. "sr0", "sg12"), rejecting names with trailing or embedded non-digit characters. @@ -1202,6 +1130,78 @@ namespace SabreTools.IO.Extensions return true; } + /// + /// Read the sysfs "removable" flag for a block device + /// + /// Path to the device directory under the sysfs block root + /// True when the device reports itself as removable, false otherwise + private static bool ReadUnixRemovableFlag(string sysBlockEntry) + { + string removablePath = Path.Combine(sysBlockEntry, "removable"); + try + { + if (!File.Exists(removablePath)) + return false; + + string removableString = File.ReadAllText(removablePath).Trim(); + return removableString == "1"; + } + catch + { + return false; + } + } + + /// + /// Read the device size from sysfs (reported in 512-byte sectors) and convert to bytes + /// + /// Path to the device directory under the sysfs block root + /// The device size in bytes, 0 on error + private static long ReadUnixBlockDeviceSize(string sysBlockEntry) + { + string sizePath = Path.Combine(sysBlockEntry, "size"); + try + { + if (!File.Exists(sizePath)) + return 0; + + string sizeString = File.ReadAllText(sizePath).Trim(); + if (long.TryParse(sizeString, out long sectors) && sectors > 0) + return sectors * 512; + } + catch + { + // Unreadable size; report it as unknown + } + + return 0; + } + + /// + /// Read the device size from sysfs (reported in 512-byte sectors) and convert to bytes + /// + /// Path to the device directory under the sysfs block root + /// The device size in bytes, 0 on error + private static int ReadUnixBlockDeviceType(string sysGenericEntry) + { + string typePath = Path.Combine(Path.Combine(sysGenericEntry, "device"), "type"); + try + { + if (!File.Exists(typePath)) + return 0; + + string typeString = File.ReadAllText(typePath).Trim(); + if (int.TryParse(typeString, out int scsiType)) + return scsiType; + } + catch + { + // Unreadable type; report it as unknown + } + + return 0; + } + #endregion } }